Private strand flush not complete 说明

本文解析了Oracle数据库中出现的Private strand flush not complete错误信息的原因及解决方案,涉及redo日志缓冲区的并行机制和私有strand的概念。

前几天一个朋友问了我一个问题。说她在alert log里面看到了如下信息:

Thread 1 cannot allocate new log,sequence 415

Private strand flush not complete

Current log# 4 seq# 414 mem# 0: /dev/rora_redotb04

Thread 1 advanced to log sequence 415

Current log# 5 seq# 415 mem# 0: /dev/rora_redotb05

Thu Nov 11 16:01:51 2010

我遇到的是:Checkpoint not complete。有关这方面的解释参考我的Blog:

Redo Log和Checkpoint not complete

http://blog.youkuaiyun.com/xujinyang/article/details/6832719

在oracle官网搜了一下:

Alert Log Messages: Private Strand Flush Not Complete [ID 372557.1]


Modified01-SEP-2010TypePROBLEMStatusMODERATED

In this Document
Symptoms
Cause
Solution
References


Platforms: 1-914CU;

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

Applies to:

Oracle Server - Enterprise Edition - Version: 10.2.0.1 to 11.1.0.7 - Release: 10.2 to 11.1
Information in this document applies to any platform.
"Checked for relevance on 04-Dec-2007"


Private strand flush not complete

Symptoms

"Private strand flush not complete" messages are being populated to the alert log for unknown
reasons.

ALERT LOG EXAMPLE:
>>>
Fri May 19 12:47:29 2006
Thread 1 cannot allocate new log, sequence 18358
Private strand flush not complete
Current log# 7 seq# 18357 mem# 0: /u03/oradata/bitst/redo07.log
Thread 1 advanced to log sequence 18358
Current log# 8 seq# 18358 mem# 0: /u03/oradata/bitst/redo08.log
<<<


>>

Cause

The message means that we haven't completed writing all the redo information to the log when we are trying to switch.It is similar in nature to a "checkpoint not complete"except that is only involves the redo being written to the log.The log switch can not occur until all of the redo has been written.

A "strand" is new terminology for 10g and it deals with latches for redo .

Strands are a mechanism to allow multiple allocation latches for processes to write redo more efficiently in the redo buffer and is related to the log_parallelism parameter present in 9i.

The concept of a strand is to ensure that the redo generation rate for an instance is optimal and that when there is some kind of redo contention then the number of strands is dynamically adjusted to compensate.

The initial allocation for the number of strands depends on the number of CPU's and is started with 2strands with one strand for active redo generation.

For large scale enterprise systems the amount of redo generation is large and hence these strands are *made active* as and when the foregrounds encounter this redo contention (allocated latch related contention) when this concept of dynamic strands comes into play.

There is always shared strands and a number of private strands .

Oracle 10g has some major changes in the mechanisms for redo (and undo), which seem to be aimed at reducing contention.

Instead of redo being recorded in real time, it can be recorded 'privately' and pumped into the redo log buffer on commit.

Similary the undo can be generated as 'in memory undo' and applied in bulk.

This affect the memory used for redo management and the possibility to flush it in pieces.

The message you get is related to internal Cache Redo File management.

You can disregard these messages as normal messages.

When you switch logs all private strands have to be flushed to the current log before the switch is allowed to proceed.

Solution

These messages are not a cause for concern unless there is a significant gap in seq# between the "cannot allocate new log" message and the "advanced to log sequence" message.


This issue is infact not a bug and is expected behavior.

In some cases, this message can be resolved by increasing db_writer_process value.

这里面涉及到一些Redo的机制问题。具体参考Blog:

Oracle Redo并行机制

http://blog.youkuaiyun.com/xujinyang/article/details/6831357

一个redo条目包含了相应操作导致的数据库变化的所有信息,所有redo条目最终都要被写入redo文件中去。Redo log buffer是为了避免Redo文件IO导致性能瓶颈而在sga中分配出的一块内存。一个redo条目首先在用户内存(PGA)中产生,然后由oracle服务进程拷贝到log buffer中,当满足一定条件时,再由LGWR进程写入redo文件。

由于log buffer是一块“共享”内存,为了避免冲突,它是受到redo allocation latch保护的,每个服务进程需要先获取到该latch才能分配redo buffer。因此在高并发且数据修改频繁的oltp系统中,我们通常可以观察到redo allocation latch的等待。

为了减少redo allocation latch等待,在oracle 9.2中,引入了log buffer的并行机制。其基本原理就是,将log buffer划分为多个小的buffer,这些小的buffer被成为Shared Strand。每一个strand受到一个单独redo allocation latch的保护。多个shared strand的出现,使原来序列化的redo buffer分配变成了并行的过程,从而减少了redo allocation latch等待。

为了进一步降低redo buffer冲突,在10g中引入了新的strand机制——Private strand。Private strand不是从log buffer中划分的,而是在shared pool中分配的一块内存空间。

Private strand的引入为Oracle的Redo/Undo机制带来很大的变化。每一个Private strand受到一个单独的redo allocation latch保护,每个Private strand作为“私有的”strand只会服务于一个活动事务。获取到了Private strand的用户事务不是在PGA中而是在Private strand生成Redo,当flush private strand或者commit时,Private strand被批量写入log文件中。如果新事务申请不到Private strand的redo allocation latch,则会继续遵循旧的redo buffer机制,申请写入shared strand中。事务是否使用Private strand,可以由x$ktcxb的字段ktcxbflg的新增的第13位鉴定:

对于使用Private strand的事务,无需先申请Redo Copy Latch,也无需申请Shared Strand的redo allocation latch,而是flush或commit是批量写入磁盘,因此减少了Redo Copy Latch和redo allocation latch申请/释放次数、也减少了这些latch的等待,从而降低了CPU的负荷。

看了这些理论知识,我们在来看一下之前的错误:

Private strand flush not complete

当我们flush或者commit的时候,必须先将buffer中的内容写入到redo中,才能去接收新的记录。这个错误就是发生在这个过程中。Oracle对这个问题提了2个方法:

(1)忽略,在使用之前,必须要等待buffer的信息flush完成。这时候进程是会短暂的hang住。

(2)增加db_writer_process的数据。

------------------------------------------------------------------------------

/******************************************************************************** ** Copyright (C), 2021-2121, Oplus Mobile Comm Corp., Ltd ** All rights reserved. ** ** File: - OplusNewFeaturesDisplayingManager.java ** Description: ** Implementation of new system features displaying manager. ** ** This service is used to: ** 1. display new system features if Android major version upgraded, e.g. R -> S ** 2. display new policies for lite boot reg requirement if OS version upgraded, ** e.g. OS V12.0 -> OS V12.1, OS V12.1 -> OS V13. See feature 3142150. ** ** Therefore, there are totally 4 cases as below: ** 1. Both Android major version and OS version upgraded: show new system features and ** new policies in boot reg. ** 2. Android major version upgraded only: show new system features. E.g. R+12 -> S+12 ** 3. OS version upgraded only: show new policies. ** 4. Neither of them are upgraded: show nothing, i.e. launch home directly. ** ** Version: 2.0 ** Date: 2022-02-24 ** Author: matt.yu@ANDROID.PMS ** TAG: OPLUS_FEATURE_NEW_FEATURES_DISPLAYING_MANAGER ** ** ------------------------------- Revision History: ---------------------------- ** <author> <date> <version> <desc> ** ------------------------------------------------------------------------------ ** matt.yu@ANDROID.PMS 2021-07-21 1.0 Create this module ** matt.yu@ANDROID.PMS 2022-02-24 2.0 Support lite boot reg requirement ********************************************************************************/ package com.android.server.oplus.nfdm; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; import static android.server.pm.OplusPackageTransformHelper.PKG_BOOTREG; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.ActivityManager; import com.android.server.am.ProcessRecord; import android.annotation.NonNull; import android.app.WallpaperInfo; import android.app.WallpaperManager; import android.common.OplusFeatureCache; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.ResolveInfoFlags; import android.content.pm.ResolveInfo; import android.database.ContentObserver; import android.os.Binder; import android.os.Build; import android.os.FileUtils; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.Parcelable; import android.os.Process; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; import android.util.Slog; import com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import android.util.Xml; import com.android.internal.util.XmlUtils; import com.android.server.ServiceThread; import com.android.server.content.IOplusFeatureConfigManagerInternal; import com.android.server.pm.IOplusPackageManagerServiceEx; import com.android.server.pm.IOplusPmsSupportedFunctionManager; import com.android.server.pm.PackageManagerService; import com.android.server.OplusBackgroundThread; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; import com.google.android.collect.Sets; import com.oplus.ota.OplusSystemUpdateInfo; import org.json.JSONException; import org.json.JSONObject; public class OplusNewFeaturesDisplayingManager implements IOplusNewFeaturesDisplayingManager { private static final String TAG = "OplusNewFeaturesDisplayingManager"; public static final String PROC_MEMINFO_PATH = "/proc/meminfo"; public static final String LABEL_MEMTOTAL = "MemTotal:"; private static final String OTA_SWITCH_RECORD_FILE_PATH = "/data/oplus/os/ota_switch_record.xml"; private static final String PROP_MARK_LAST_UPGRADED_VERSION = "persist.sys.mark_last_upgraded_version"; private static final String EXTRA_OTA_SWITCH_LIST_FROM_SYSTEM = "extra_ota_switch_list_from_system"; private static final String PROP_OTA_VERSION = "ro.build.version.ota"; private static final List<Integer> DEF_RAM_SIZE = Arrays.asList(2, 3, 4, 6, 8, 12, 16, 18, 24); private static final List<Integer> SUPPORTED_OTA_SWITCH_TARGET_SDKS = Arrays.asList( Build.VERSION_CODES.S, Build.VERSION_CODES.TIRAMISU, Build.VERSION_CODES.UPSIDE_DOWN_CAKE ); private static final long MB_IN_KB = 1024L; private static final long GB_IN_KB = MB_IN_KB * 1024L; private static final int EIGHT_GB = 8; private static int sTotalProcMemInfoGB = -1; private static int sTotalProcMemInfoKB = -1; private static final String FEATURE_TABLET = "oplus.hardware.type.tablet"; private static final String FEATURE_SCREEN_FOLDABLE = "oplus.hardware.type.fold"; private static final String FEATURE_FOLD_REMAP_DISPLAY_DISABLED = "oplus.software.fold_remap_display_disabled"; private static final List<Integer> SUPPORTED_TARGET_SDKS = Arrays.asList( Build.VERSION_CODES.S, Build.VERSION_CODES.TIRAMISU, Build.VERSION_CODES.UPSIDE_DOWN_CAKE, Build.VERSION_CODES.VANILLA_ICE_CREAM, Build.VERSION_CODES.BAKLAVA ); private static final List<Integer> SUPPORTED_WALLPAPER_TARGET_SDKS = Arrays.asList( Build.VERSION_CODES.VANILLA_ICE_CREAM ); private static final Set<String> NOT_MARKET_LIVE_WALLPAPER = Sets.newHashSet( "default_live_wp_package_name" ); private static final String PKG_NAME_BOOT_REG = PKG_BOOTREG; private static final String ACTION_WELCOME_PAGE = "com.oplus.bootreg.activity.WelcomePage"; private static final String PKG_NAME_WALLPAPER = "com.oplus.wallpapers"; private static final String ACTION_WALLPAPER_GUIDE_PAGE = "android.intent.action.THEME_INSPIRATION_BOOT"; private static final String PKG_NAME_UPGRADE_GUIDE = "com.oplus.upgradeguide"; private static final String ACTION_UPGRADE_SERVICE = "oplus.intent.upgrade.UNZIP_RESOURCE"; private static final String EXTRA_START_FROM_SYSTEM = "extra_start_from_system"; private static final String PKG_NAME_OPPO_DEFAULT_LAUNCHER = "com.android.launcher"; private static final String LAUNCHER_ACTION = "android.intent.action.MAIN"; private static final String LAUNCHER_CATEGORY = "android.intent.category.HOME"; private static final long THIRD_FLAG = 0x01; private static final int CUSTOM_THEME_FLAG = 0x100; private static final String CLS_NAME_OTA_GUIDE_PAGE = "com.oplus.upgrade.ota.ui.OtaGuidePage"; private static final String PROP_RO_SEPARATE_SOFT = "ro.separate.soft"; /** * @deprecated * Use action intent filter instead, see {@link #getBootRegWelcomePageComponentName()} */ private static final String CLS_NAME_WELCOME_PAGE = PKG_BOOTREG.concat(".settings.activity.WelcomePage"); private static final ComponentName COMPONENT_WELCOME_PAGE = new ComponentName(PKG_NAME_BOOT_REG, CLS_NAME_WELCOME_PAGE); /** * Deprecated for what's new 2.0 requirement. */ private static final String CLS_NAME_NEW_FEATURE_PAGE = PKG_NAME_BOOT_REG.concat(".activity.NewFeaturePage"); private static final ComponentName COMPONENT_NEW_FEATURE_PAGE = new ComponentName( PKG_NAME_BOOT_REG, CLS_NAME_NEW_FEATURE_PAGE); private static final String EXTRA_MAJOR_VERSION_UPGRADED = "extra_major_version_upgraded"; private static final String EXTRA_MAJOR_WALLPAPER_CHANGED = "extra_major_wallpaper_changed"; private static final String PROP_FORCE_TO_DISPLAY_NEW_FEATURES = "persist.sys.force_to_display_new_features"; private static final String PROP_MARK_TO_DISPLAY_NEW_FEATURES = "persist.sys.mark_to_display_new_features"; private static final String EXTRA_OS_VERSION_UPGRADED = "extra_os_version_upgraded"; private static final String PROP_FORCE_TO_DISPLAY_NEW_POLICIES = "persist.sys.force_to_display_new_policies"; private static final String PROP_MARK_TO_DISPLAY_NEW_POLICIES = "persist.sys.mark_to_display_new_policies"; private static final String PROP_FORCE_TO_DISPLAY_BOOTREG = "persist.sys.force_to_display_bootreg"; private static final String PROP_FORCE_TO_CHANGE_WALLPAPER = "persist.sys.force_to_change_wallpaper"; private static final String OS_VERSION_INFO_FILE_PATH = "/data/oplus/os/os_version_info.xml"; private static final String PROP_CUR_OS_VERSION = "ro.build.version.oplusrom"; private static final String PROP_STOCK_TYPE = "ro.oplus.image.my_stock.type"; private static final String PROP_CARRRIER = "ro.oplus.pipeline.carrier"; private static final String PROP_THEME_UUID = "persist.sys.oppo.theme_uuid"; private static final String PROP_COMPANY_TYPE = "ro.oplus.image.my_company.type"; private static final String PROP_CHANNEL = "persist.sys.channel.info"; private static final String DELIMITER = "_"; private static final String KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP = "oplus_upgrade_ota_step"; private static final String TAG_OS_VERSION = "os-version"; private static final String TAG_PREV_OS_VERSION = "prev-os-version"; private static final String ATTR_VALUE = "value"; private static final int S_OS_VERSION_LENGTH = 2; private static final int T_OS_VERSION_LENGTH = 3; private static final int MSG_WSN_WRITEOS = 120; private static final int MSG_WSN_EXCEPTION_NEWFEATURE = 121; private static final int MSG_WSN_STARTHOME = 122; private static final int DELAY_EXCEPTION_NEWFEATURE_SENDING_MSEC = 5000; private static final int MSG_DELAY_TO_CHECK_IF_OTA_GUIDE_ABNORMAL = 123; private static final int MSG_DELAY_TO_CHECK_STATUS_WHEN_OTA_GUIDE_EXIT = 124; private static final int DELAY_EXCEPTION_OTA_GUIDE_MSEC = 30000; private static final int DELAY_CHECK_IF_OTA_GUIDE_NORMAL_EXIT_MSEC = 2000; private static final int VALUE_OTA_GUIDE_DEFAULT = -1; private static final int VALUE_OTA_GUIDE_OVERTIME_WAIT = 0; private static final int VALUE_OTA_GUIDE_ENTER = 1; private static final int VALUE_OTA_GUIDE_EXIT = 2; private static final int TYPE_SAU_UPDATE = 2; private static final String PROP_OPLUS_CLOSE_OTA_GUIDE_PAGE = "persist.sys.oplus_close_ota_guide"; private ComponentName mComponentOtaGuidePage = null; private ContentObserver mOtaGuideContentObserver = null; private ComponentName mComponentNameWelcomePage = null; private ComponentName mComponentNameWallPaperGuidPage = null; private boolean mInitializedSuccessfully; private Context mContext; private PackageManagerService mPms; private Handler mHandler; private RunningAppProcessInfo mWsnInfo = null; private String mStockType; private boolean mIsDomesticBuild; private boolean mIsBrandSupported; private boolean mIsDeviceTablet; private boolean mIsScreenFoldable; private boolean mIsFlipDevice; private boolean mIsFirstBoot; private boolean mOtaUpgraded; private boolean mIsBootFromOTA; private int mPrevSdkVersion; private int mCurSdkVersion; private boolean mMajorVersionUpgraded; private String mProjectNumber; private List<OtaGuideBean> mOtaGuideBeans; private String mPrevOsVersion; private String mCurOsVersion; private boolean mOsVersionUpgraded; private boolean mTopIsWsn; private boolean mTopIsLauncher; private boolean mPictorialAuto; private boolean mKeKeMarketTheme; private boolean mChangeWallPaper; private boolean mIsNeedDisplayWallpaper; private boolean mIsNeedDisplaySwitchPage; private boolean mDebug = SystemProperties.getBoolean("persist.sys.assert.panic", false); private static final class InstanceHolder { private static final OplusNewFeaturesDisplayingManager INSTANCE = new OplusNewFeaturesDisplayingManager(); } public static OplusNewFeaturesDisplayingManager getInstance() { return OplusNewFeaturesDisplayingManager.InstanceHolder.INSTANCE; } private OplusNewFeaturesDisplayingManager() { // hidden constructor } @Override public void init(IOplusPackageManagerServiceEx pmsEx) { if (pmsEx == null || pmsEx.getPackageManagerService() == null) { Slog.e(TAG, "Init failed due to null pms reference"); return; } mContext = pmsEx.getContext(); mPms = pmsEx.getPackageManagerService(); mInitializedSuccessfully = true; mTopIsWsn = false ; mTopIsLauncher = false ; mIsNeedDisplayWallpaper = false; mIsNeedDisplaySwitchPage = false; initBuildTypes(); readPrevOsVersionFromXml(); mCurOsVersion = SystemProperties.get(PROP_CUR_OS_VERSION, ""); Slog.i(TAG, "prevOsVersion=" + mPrevOsVersion + ", curOsVersion=" + mCurOsVersion); HandlerThread thread = new ServiceThread(TAG, Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/); thread.start(); mHandler = new Handler(thread.getLooper()) { @Override public void handleMessage(@NonNull Message msg) { switch (msg.what) { case MSG_WSN_WRITEOS: writeOsVersionToXmlSync(); break ; case MSG_WSN_EXCEPTION_NEWFEATURE: if (!mTopIsWsn) { Slog.i(TAG, "upgradeguide can not start so direct go to home"); startHome(); ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE); am.killBackgroundProcesses(PKG_NAME_UPGRADE_GUIDE); } break ; case MSG_WSN_STARTHOME: startHome(); break ; case MSG_DELAY_TO_CHECK_IF_OTA_GUIDE_ABNORMAL: ContentResolver resolver = mContext.getContentResolver(); int otaGuideStatusFlag = Settings.System.getInt(resolver, KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP, VALUE_OTA_GUIDE_DEFAULT); Slog.d(TAG, "ota guide page launch timeout! otaGuideStatusFlag = " + otaGuideStatusFlag); if ((otaGuideStatusFlag == VALUE_OTA_GUIDE_DEFAULT) || (otaGuideStatusFlag == VALUE_OTA_GUIDE_OVERTIME_WAIT)) { dealOtaGuideException(); } break; case MSG_DELAY_TO_CHECK_STATUS_WHEN_OTA_GUIDE_EXIT: Slog.d(TAG, "ota guide exit! "); if (isOtaGuidePageEnable()) { disableOtaGuidePage(); } if (mOtaGuideContentObserver != null) { mContext.getContentResolver().unregisterContentObserver(mOtaGuideContentObserver); } break; default: break ; } } }; } private void initBuildTypes() { mStockType = SystemProperties.get(PROP_STOCK_TYPE); if (isValidStockType(mStockType)) { final String[] typeArr = mStockType.split(DELIMITER); final String region = typeArr[0]; mIsDomesticBuild = "domestic".equalsIgnoreCase(region); final String brand = typeArr[1]; mIsBrandSupported = ("OPPO".equalsIgnoreCase(brand) || "OnePlus".equalsIgnoreCase(brand)); } } private boolean isValidStockType(String type) { final String regex = "^[A-Za-z]+_[A-Za-z]+$"; return (type != null) && (type.matches(regex)); } private void readPrevOsVersionFromXml() { final File file = new File(OS_VERSION_INFO_FILE_PATH); if (!file.exists() || !file.canRead()) { Slog.w(TAG, "Os version info file doesn't exist or can't read"); return; } try (FileInputStream str = new FileInputStream(file)) { final TypedXmlPullParser parser = Xml.resolvePullParser(str); int type; while (((type = parser.next()) != XmlPullParser.START_TAG) && (type != XmlPullParser.END_DOCUMENT)) { ; } if (type != XmlPullParser.START_TAG) { Slog.wtf(TAG, "No start tag found in os version info file"); return; } if (!parser.getName().equals(TAG_OS_VERSION)) { throw new XmlPullParserException("Unexpected start tag in " + file + ": found " + parser.getName() + ", expected 'os_version'"); } int outerDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_DOCUMENT) && ((type != XmlPullParser.END_TAG) || (parser.getDepth() > outerDepth))) { if ((type == XmlPullParser.END_TAG) || (type == XmlPullParser.TEXT)) { continue; } String tagName = parser.getName(); if (tagName.equals(TAG_PREV_OS_VERSION)) { mPrevOsVersion = parser.getAttributeValue(null, ATTR_VALUE); } else { Slog.w(TAG, "Unknown element: " + tagName); XmlUtils.skipCurrentTag(parser); } } } catch (IOException | XmlPullParserException e) { Slog.e(TAG, "Error reading os version info file: " + e.toString()); } } private void writeOsVersionToXmlAsync() { Message message = mHandler.obtainMessage(); message.what = MSG_WSN_WRITEOS; mHandler.sendMessage(message); } private void writeOsVersionToXmlSync() { final File file = new File(OS_VERSION_INFO_FILE_PATH); if (file.exists()) { Slog.i(TAG, "Os version info file already exists, replacing..."); file.delete(); } try (FileOutputStream str = new FileOutputStream(file)) { final TypedXmlSerializer serializer = Xml.resolveSerializer(str); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, TAG_OS_VERSION); // previous os version info serializer.startTag(null, TAG_PREV_OS_VERSION); serializer.attribute(null, ATTR_VALUE, mCurOsVersion); serializer.endTag(null, TAG_PREV_OS_VERSION); serializer.endTag(null, TAG_OS_VERSION); serializer.endDocument(); str.flush(); FileUtils.sync(str); FileUtils.setPermissions(file.toString(), // rw-rw---- FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IWGRP, -1, -1); } catch (IOException e) { Slog.e(TAG, "Error writing os version info file: " + e.toString()); } } private boolean isOsVersionUpgraded() { String prevOsVersion = mPrevOsVersion; String curOsVersion = mCurOsVersion; if (isValidOsVersion(prevOsVersion) && isValidOsVersion(curOsVersion)) { if (prevOsVersion.indexOf(".") == -1) { prevOsVersion = prevOsVersion.concat(".0"); } if (curOsVersion.indexOf(".") == -1) { curOsVersion = curOsVersion.concat(".0"); } try { prevOsVersion = prevOsVersion.substring(1); curOsVersion = curOsVersion.substring(1); String[] prevOsVersionArr = prevOsVersion.split("\\."); String[] curOsVersionArr = curOsVersion.split("\\."); if (((prevOsVersionArr.length == S_OS_VERSION_LENGTH) || (prevOsVersionArr.length == T_OS_VERSION_LENGTH)) && (curOsVersionArr.length == T_OS_VERSION_LENGTH)) { final int prevOsVersionMajor = Integer.parseInt(prevOsVersionArr[0]); final int curOsVersionMajor = Integer.parseInt(curOsVersionArr[0]); if (curOsVersionMajor > prevOsVersionMajor) { return true; } else if (curOsVersionMajor == prevOsVersionMajor) { final int prevOsVersionMinor = Integer.parseInt(prevOsVersionArr[1]); final int curOsVersionMinor = Integer.parseInt(curOsVersionArr[1]); if (curOsVersionMinor > prevOsVersionMinor) { return true; } } } } catch (Exception e) { Slog.e(TAG, "Error parsing os version: " + e.toString()); return false; } } return false; } private boolean isValidOsVersion(String osVersion) { final String regex = "^V\\d+(\\.\\d+)?$"; final String regexForT = "^V\\d+(\\.\\d+\\.\\d+)?$"; return (osVersion != null) && ((osVersion.matches(regex)) || (osVersion.matches(regexForT))); } @Override public void setValues(boolean isFirstBoot, boolean isUpgrade, boolean isBootFromOTA, int curSdkVersion, int lastSdkVersion) { /* * isUpgrade is true when: 1. Fingerprint changes;2. COTA upgrade;3. OTA upgrade (including sau system upgrade);4. opex-apk upgrade; * isBootFromOTA is true: only when OTA upgrade (including sau system upgrade) */ Slog.d(TAG, String.format("firstBoot=%s, upgrade=%s, isBootFromOTA=%s, curSdkVersion=%s, lastSdkVersion=%s", isFirstBoot, isUpgrade, isBootFromOTA, curSdkVersion, lastSdkVersion)); mIsFirstBoot = isFirstBoot; mOtaUpgraded = isUpgrade; mIsBootFromOTA = isBootFromOTA; mPrevSdkVersion = lastSdkVersion; mCurSdkVersion = curSdkVersion; mMajorVersionUpgraded = isUpgrade && lastSdkVersion < curSdkVersion && SUPPORTED_TARGET_SDKS.contains(curSdkVersion); mOsVersionUpgraded = isUpgrade && isOsVersionUpgraded(); mProjectNumber = SystemProperties.get(PROP_RO_SEPARATE_SOFT, ""); } @Override public void enableBootRegIfNeededForDisplayingNewFeatures() { if (!mInitializedSuccessfully) { Slog.w(TAG, "Failed to initialize, skip to enable boot reg"); return; } mIsDeviceTablet = hasOplusFeature(FEATURE_TABLET); mIsScreenFoldable = hasOplusFeature(FEATURE_SCREEN_FOLDABLE); mIsFlipDevice = hasOplusFeature(FEATURE_FOLD_REMAP_DISPLAY_DISABLED); mComponentNameWelcomePage = getBootRegWelcomePageComponentName(); mComponentNameWallPaperGuidPage = getWallPaperGuidComponentName(); Slog.i(TAG, "welcomePage=" + mComponentNameWelcomePage + " mComponentNameWallPaperPage=" + mComponentNameWallPaperGuidPage); final boolean newFeaturesDisplayingEnabled = mIsDomesticBuild && mIsBrandSupported; final boolean forcedToDisplayNewFeatures = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_NEW_FEATURES, false); final boolean newPoliciesDisplayingEnabled = mIsDomesticBuild; final boolean forcedToDisplayNewPolicies = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_NEW_POLICIES, false); final boolean forcedToDisplayBootReg = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_BOOTREG, false); final boolean doesBootRegWelcomePageExist = mComponentNameWelcomePage != null; Slog.d(TAG, "deviceTablet=" + mIsDeviceTablet + ", screenFoldable=" + mIsScreenFoldable + ", flipDevice=" + mIsFlipDevice + ", newFeaturesDisplayingEnabled=" + newFeaturesDisplayingEnabled + ", majorVersionUpgraded=" + mMajorVersionUpgraded + ", forcedToDisplayNewFeatures=" + forcedToDisplayNewFeatures + ", newPoliciesDisplayingEnabled=" + newPoliciesDisplayingEnabled + ", osVersionUpgraded=" + mOsVersionUpgraded + ", forcedToDisplayNewPolicies=" + forcedToDisplayNewPolicies + ", welcomePageExist=" + doesBootRegWelcomePageExist); final boolean shouldDisplayNewFeatures = forcedToDisplayNewFeatures || (newFeaturesDisplayingEnabled && mMajorVersionUpgraded); final boolean shouldDisplayNewPolicies = forcedToDisplayNewPolicies || (newPoliciesDisplayingEnabled && mOsVersionUpgraded); if ((shouldDisplayNewFeatures || shouldDisplayNewPolicies || forcedToDisplayBootReg) && doesBootRegWelcomePageExist) { int oldState = mContext.getPackageManager().getComponentEnabledSetting(mComponentNameWelcomePage); Slog.d(TAG, "Old state of " + mComponentNameWelcomePage + " is " + parseComponentState(oldState)); //When the user disables the boot wizard, the WSN will not be available, so no longer configured try { boolean isEnabled = mContext.getPackageManager().getPackageInfo(PKG_NAME_BOOT_REG, 0).applicationInfo.enabled; if (!isEnabled) { return; } } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "get bootreg applicationInfo enabled state fail ", e); } if (shouldDisplayNewFeatures) { // Marked that we should display new features later SystemProperties.set(PROP_MARK_TO_DISPLAY_NEW_FEATURES, String.valueOf(true)); } if (shouldDisplayNewPolicies) { // Marked that we should display new policies later SystemProperties.set(PROP_MARK_TO_DISPLAY_NEW_POLICIES, String.valueOf(true)); } if (!((oldState == COMPONENT_ENABLED_STATE_DEFAULT) || (oldState == COMPONENT_ENABLED_STATE_ENABLED))) { Slog.i(TAG, "Enable boot reg again"); mContext.getPackageManager().setComponentEnabledSetting(mComponentNameWelcomePage, COMPONENT_ENABLED_STATE_ENABLED, 0 /* flags */); Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_SYSTEM); } } else { displayOtaGuidePageIfNeed(); } final ContentResolver resolver = mContext.getContentResolver(); ContentObserver co = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { final boolean userSystemSetupComplete = Settings.Secure.getIntForUser(resolver, Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_SYSTEM) == 1; Slog.d(TAG, "userSystemSetupComplete=" + userSystemSetupComplete); if (userSystemSetupComplete) { // Reset props if user system setup completed SystemProperties.set(PROP_FORCE_TO_DISPLAY_NEW_FEATURES, String.valueOf(false)); SystemProperties.set(PROP_MARK_TO_DISPLAY_NEW_FEATURES, String.valueOf(false)); SystemProperties.set(PROP_FORCE_TO_DISPLAY_NEW_POLICIES, String.valueOf(false)); SystemProperties.set(PROP_MARK_TO_DISPLAY_NEW_POLICIES, String.valueOf(false)); SystemProperties.set(PROP_FORCE_TO_DISPLAY_BOOTREG, String.valueOf(false)); if ((shouldDisplayNewFeatures || shouldDisplayNewPolicies) && !mTopIsLauncher) { Message message = mHandler.obtainMessage(); message.what = MSG_WSN_EXCEPTION_NEWFEATURE; mHandler.sendMessageDelayed(message,DELAY_EXCEPTION_NEWFEATURE_SENDING_MSEC); } // Write back new os version. writeOsVersionToXmlAsync(); if (mIsBootFromOTA) { String otaVersion = SystemProperties.get(PROP_OTA_VERSION, ""); SystemProperties.set(PROP_MARK_LAST_UPGRADED_VERSION, otaVersion); } } } }; mContext.getContentResolver().registerContentObserver(Settings.Secure .getUriFor( Settings.Secure.USER_SETUP_COMPLETE), false, co, UserHandle.USER_SYSTEM); co.onChange(true); } private boolean isNeedDisplayOtaGuide() { mIsNeedDisplayWallpaper = isNeedDisplayWallpaper(); mIsNeedDisplaySwitchPage = isNeedDisplaySwitchPage(); return mIsNeedDisplayWallpaper || mIsNeedDisplaySwitchPage; } private boolean isNeedDisplaySwitchPage() { if (!SUPPORTED_OTA_SWITCH_TARGET_SDKS.contains(mCurSdkVersion)) { Slog.w(TAG, "isNeedDisplaySwitchPage: current sdk not support ota switch, no need to go on"); return false; } if (!mIsBootFromOTA) { Slog.w(TAG, "isNeedDisplaySwitchPage: current boot is not boot from ota, just normal boot, no need to go on"); return false; } if (mIsDomesticBuild) { Slog.w(TAG, "isNeedDisplaySwitchPage: current boot is domestic build, no need to go on"); return false; } if (isSauSystemUpdate()) { Slog.w(TAG, "isNeedDisplaySwitchPage: current update is SAU system update, no need to go on"); return false; } if (mOsVersionUpgraded || mMajorVersionUpgraded) { Slog.d(TAG, "isNeedDisplaySwitchPage: is osUpgrade or magorUpgrade, no need to go on"); return false; } if (isUpgradeFailed()) { Slog.d(TAG, "isNeedDisplaySwitchPage: is isUpgradeFailed, no need to go on"); return false; } mOtaGuideBeans = OtaLogicManager.getOtaApplications(mContext); if (mOtaGuideBeans == null || mOtaGuideBeans.isEmpty()) { Slog.d(TAG, "no application need start OtaGuidePage."); return false; } return true; } private boolean isNeedDisplayWallpaper() { if (!SUPPORTED_WALLPAPER_TARGET_SDKS.contains(mCurSdkVersion)) { Slog.w(TAG, "isNeedDisplayWallpaper: current sdk not support wallpager change, no need to go on"); return false; } if (!mIsBootFromOTA) { Slog.w(TAG, "isNeedDisplayWallpaper: current boot is not boot from ota, just normal boot, no need to go on"); return false; } if (mIsDeviceTablet || mIsScreenFoldable) { return false; } if (isMemoryForbid()) { Slog.w(TAG, "isNeedDisplayWallpaper: current memInfo is less than 8G, no need to go on"); return false; } if (mComponentNameWallPaperGuidPage == null) { Slog.w(TAG, "isNeedDisplayWallpaper: mComponentNameWallPaperGuidPage is null, no need to go on"); return false; } if (!mMajorVersionUpgraded && SystemProperties.getBoolean(PROP_FORCE_TO_CHANGE_WALLPAPER, true)) { Slog.w(TAG, "isNeedDisplayWallpaper: current boot is not mMajorVersionUpgraded, no need to go on"); return false; } mPictorialAuto = Settings.System.getInt(mContext.getContentResolver(), "oplus_customize_pictorial_auto_play", 0) == 1; boolean isTheme = (mPictorialAuto || isThirdTheme(0) || checkMarketTheme()); boolean needDisplayWallpaper = !(isTheme || isCarrrierOrChannal() || checkCompanyType()); if (!needDisplayWallpaper) { Slog.w(TAG, "isNeedDisplayWallpaper: no needDisplayWallpaper, no need to go on"); return false; } if (mIsDomesticBuild) { Slog.w(TAG, "isNeedDisplayWallpaper: current boot is domestic build, no need to go on"); return false; } if (isSauSystemUpdate()) { Slog.w(TAG, "isNeedDisplayWallpaper: current update is SAU system update, no need to go on"); return false; } return true; } private void displayOtaGuidePageIfNeed () { if (SystemProperties.getBoolean(PROP_OPLUS_CLOSE_OTA_GUIDE_PAGE, false)) { Slog.w(TAG, "otaGuidePage has been closed!!!, no need to go on"); return; } mComponentOtaGuidePage = getOtaGuideComponentName(); if (mComponentOtaGuidePage == null) { Slog.i(TAG, "the component: " + CLS_NAME_OTA_GUIDE_PAGE + " is not exit, do not need to go on, return"); return; } try { boolean isEnabled = mContext.getPackageManager().getPackageInfo(PKG_NAME_UPGRADE_GUIDE, 0).applicationInfo.enabled; if (!isEnabled) { Slog.w(TAG, "get upgradeguide applicationInfo is not enable, return"); disableOtaGuidePage(); return; } } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "get UpgradeGuide applicationInfo enabled state fail name not found,return"); return; } if (isOtaGuidePageEnable()) { Slog.i(TAG, "the component: " + CLS_NAME_OTA_GUIDE_PAGE + " is enable, so disable it first"); disableOtaGuidePage(); } if (!isNeedDisplayOtaGuide()) { return; } enableOtaGuidePage(); } private void enableOtaGuidePage () { Slog.d(TAG, "enableOtaGuidePage now!!!"); final ContentResolver resolver = mContext.getContentResolver(); long id = Binder.clearCallingIdentity(); try { Settings.System.putInt(resolver, KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP, VALUE_OTA_GUIDE_OVERTIME_WAIT); mContext.getPackageManager().setComponentEnabledSetting(mComponentOtaGuidePage, COMPONENT_ENABLED_STATE_ENABLED, 0 /* flags */); } catch (IllegalArgumentException e) { Slog.e(TAG, "get IllegalArgumentException, so return"); return; } finally { Binder.restoreCallingIdentity(id); } mHandler.sendEmptyMessageDelayed(MSG_DELAY_TO_CHECK_IF_OTA_GUIDE_ABNORMAL, DELAY_EXCEPTION_OTA_GUIDE_MSEC); mOtaGuideContentObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { int otaGuideStatusFlag = Settings.System.getInt(resolver, KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP, VALUE_OTA_GUIDE_DEFAULT); if (otaGuideStatusFlag == VALUE_OTA_GUIDE_ENTER) { Slog.i(TAG, "the otaGuide StatusFlag is 1, enter normal"); if (mHandler.hasMessages(MSG_DELAY_TO_CHECK_IF_OTA_GUIDE_ABNORMAL)) { mHandler.removeMessages(MSG_DELAY_TO_CHECK_IF_OTA_GUIDE_ABNORMAL); } } else if (otaGuideStatusFlag == VALUE_OTA_GUIDE_EXIT) { Slog.i(TAG, "the otaGuide StatusFlag is 2, exit normal, so unregister Observer"); mHandler.sendEmptyMessageDelayed(MSG_DELAY_TO_CHECK_STATUS_WHEN_OTA_GUIDE_EXIT, DELAY_CHECK_IF_OTA_GUIDE_NORMAL_EXIT_MSEC); } } }; mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP), false, mOtaGuideContentObserver, UserHandle.USER_SYSTEM); } private ComponentName getOtaGuideComponentName() { final Intent intent = new Intent(); intent.setClassName(PKG_NAME_UPGRADE_GUIDE, CLS_NAME_OTA_GUIDE_PAGE); final ResolveInfoFlags flags = ResolveInfoFlags.of(PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DISABLED_COMPONENTS); final ResolveInfo ri = mContext.getPackageManager().resolveActivityAsUser(intent, flags, UserHandle.USER_SYSTEM); if ((ri != null) && (ri.activityInfo != null)) { return new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name); } Slog.w(TAG,"get ota GuidePage activity null "); return null; } private boolean isOtaGuidePageEnable() { int componentState = mContext.getPackageManager().getComponentEnabledSetting(getOtaGuideComponentName()); Slog.i(TAG, "componentState state of " + getOtaGuideComponentName() + " is " + parseComponentState(componentState)); return componentState == COMPONENT_ENABLED_STATE_ENABLED; } private void disableOtaGuidePage() { long id = Binder.clearCallingIdentity(); try { Slog.i(TAG, "start to disable mComponentOtaGuidePage"); mContext.getPackageManager().setComponentEnabledSetting(getOtaGuideComponentName(), COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP /* flags */); } catch (IllegalArgumentException e) { Slog.e(TAG, "setComponentEnabledSetting disable mComponentOtaGuidePage get IllegalArgumentException"); } finally { Binder.restoreCallingIdentity(id); } } private void dealOtaGuideException() { Slog.i(TAG, "dealOtaGuideException, disable ota guide and start home."); if (isOtaGuidePageEnable()) { disableOtaGuidePage(); } if (!mTopIsLauncher) { Slog.i(TAG, "current top is not launcher, so start launcher"); startHome(); } if (mOtaGuideContentObserver != null) { mContext.getContentResolver().unregisterContentObserver(mOtaGuideContentObserver); } Settings.System.putInt(mContext.getContentResolver(), KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP, VALUE_OTA_GUIDE_EXIT); } private boolean isSauSystemUpdate() { OplusSystemUpdateInfo oplusSystemUpdateInfo = OplusFeatureCache.get(IOplusPmsSupportedFunctionManager.DEFAULT).getSystemUpdateInfo(); if ((oplusSystemUpdateInfo != null) && oplusSystemUpdateInfo.getUpdateType() == TYPE_SAU_UPDATE) { return true; } else { return false; } } private boolean isUpgradeFailed() { String currOtaVersion = SystemProperties.get(PROP_OTA_VERSION, ""); String lastUpgradedVersion = SystemProperties.get(PROP_MARK_LAST_UPGRADED_VERSION, ""); if (!TextUtils.isEmpty(currOtaVersion) && !TextUtils.isEmpty(lastUpgradedVersion)) { if (currOtaVersion.equals(lastUpgradedVersion)) { return true; } } return false; } @Override public void putExtraIfNeededForDisplayingNewFeatures(String reason, Intent homeIntent, int userId) { if (!mInitializedSuccessfully) { Slog.w(TAG, "Failed to initialize, skip to put extra into intent"); return; } // Start upgrade service if first boot for new features displaying. final boolean newFeaturesDisplayingEnabled = mIsDomesticBuild && mIsBrandSupported; final boolean forcedToDisplayNewFeatures = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_NEW_FEATURES, false); final boolean shouldDisplayNewFeatures = forcedToDisplayNewFeatures || newFeaturesDisplayingEnabled; final boolean doesBootRegWelcomePageExist = mComponentNameWelcomePage != null; if ("systemReady".equals(reason) && shouldDisplayNewFeatures && mIsFirstBoot && doesBootRegWelcomePageExist) { startUpgradeGuide("first boot"); } final boolean markedToDisplayNewFeatures = SystemProperties.getBoolean(PROP_MARK_TO_DISPLAY_NEW_FEATURES, false); final boolean markedToDisplayNewPolicies = SystemProperties.getBoolean(PROP_MARK_TO_DISPLAY_NEW_POLICIES, false); Slog.d(TAG, "markedToDisplayNewFeatures=" + markedToDisplayNewFeatures + ", markedToDisplayNewPolicies=" + markedToDisplayNewPolicies + ", welcomePageExists=" + doesBootRegWelcomePageExist); if ((markedToDisplayNewFeatures || markedToDisplayNewPolicies) && doesBootRegWelcomePageExist) { Slog.d(TAG, String.format("reason=%s, component=%s, user=%s", reason, homeIntent.getComponent(), userId)); mPictorialAuto = Settings.System.getInt(mContext.getContentResolver(), "oplus_customize_pictorial_auto_play", 0) == 1; mChangeWallPaper = !(isMemoryForbid() || mPictorialAuto || isThirdTheme(userId) || isCarrrierOrChannal() || checkMarketTheme() || checkCompanyType()); if (("systemReady".equals(reason) || "noMoreActivities resumeHomeActivity".equals(reason)) && homeIntent.getComponent() != null && PKG_NAME_BOOT_REG.equals(homeIntent.getComponent().getPackageName()) && (userId == UserHandle.USER_SYSTEM)) { if (markedToDisplayNewFeatures) { Slog.i(TAG, "Put extra sdk version '" + mCurSdkVersion + "' into home intent doesChangeWallPaper :" + mChangeWallPaper); if (mComponentNameWallPaperGuidPage != null && SUPPORTED_WALLPAPER_TARGET_SDKS.contains(mCurSdkVersion) && (!(mIsDeviceTablet || mIsScreenFoldable))) { homeIntent.putExtra(EXTRA_MAJOR_WALLPAPER_CHANGED, mChangeWallPaper); } homeIntent.putExtra(EXTRA_MAJOR_VERSION_UPGRADED, mCurSdkVersion); // Start upgrade service if re-launching boot reg. startUpgradeGuide("relaunching boot reg"); } if (markedToDisplayNewPolicies) { homeIntent.putExtra(EXTRA_OS_VERSION_UPGRADED, mCurOsVersion); } } } else if (homeIntent.getComponent() != null && PKG_NAME_UPGRADE_GUIDE.equals(homeIntent.getComponent().getPackageName()) && (userId == UserHandle.USER_SYSTEM)) { if (mIsNeedDisplayWallpaper) { Slog.i(TAG, "Put extra_major_wallpaper_changed into home intent"); homeIntent.putExtra("extra_major_wallpaper_changed", String.valueOf(mCurSdkVersion)); } if (mIsNeedDisplaySwitchPage) { if ((mOtaGuideBeans != null) && (mOtaGuideBeans.size() != 0)) { Slog.i(TAG, "Put extra_ota_switch_list_from_system " + mOtaGuideBeans.toString() + " into home intent"); homeIntent.putParcelableArrayListExtra(EXTRA_OTA_SWITCH_LIST_FROM_SYSTEM, (ArrayList<? extends Parcelable>) mOtaGuideBeans); OtaLogicManager.saveSwitchRecordList(mOtaGuideBeans); } } } else { if (isOtaGuidePageEnable()) { disableOtaGuidePage(); } } } @Override public void handleProcessDied(ProcessRecord app) { final boolean markedToDisplayNewFeatures = SystemProperties.getBoolean(PROP_MARK_TO_DISPLAY_NEW_FEATURES, false); final boolean markedToDisplayNewPolicies = SystemProperties.getBoolean(PROP_MARK_TO_DISPLAY_NEW_POLICIES, false); String pkgName = app.info.packageName; if (markedToDisplayNewFeatures || markedToDisplayNewPolicies) { if (PKG_NAME_UPGRADE_GUIDE.equalsIgnoreCase(pkgName) && mTopIsWsn) { Slog.i(TAG, "upgradeguide crash so direct go to home"); Message message = mHandler.obtainMessage(); message.what = MSG_WSN_STARTHOME; mHandler.sendMessage(message); } } ContentResolver resolver = mContext.getContentResolver(); int otaGuideStatusFlag = Settings.System.getInt(resolver, KEY_OPLUS_CUSTOMIZE_OTA_GUIDE_STEP, VALUE_OTA_GUIDE_DEFAULT); if (PKG_NAME_UPGRADE_GUIDE.equalsIgnoreCase(pkgName) && PKG_NAME_UPGRADE_GUIDE.equalsIgnoreCase(app.info.processName)) { if ((otaGuideStatusFlag == VALUE_OTA_GUIDE_ENTER) || (otaGuideStatusFlag == VALUE_OTA_GUIDE_OVERTIME_WAIT)) { Slog.i(TAG, "handleProcessDied, the otaGuideStatusFlag is " + otaGuideStatusFlag); dealOtaGuideException(); } } } @Override public void notifyActivityResume(String curPkg) { if (PKG_NAME_UPGRADE_GUIDE.equals(curPkg)) { Slog.i(TAG, "notifyActivityResume : " + curPkg + " mTopIsWsn :" + mTopIsWsn); mTopIsWsn = true ; mHandler.removeMessages(MSG_WSN_EXCEPTION_NEWFEATURE); } else if (PKG_NAME_OPPO_DEFAULT_LAUNCHER.equals(curPkg)) { mTopIsLauncher = true ; } } private void startHome() { Intent homeIntent = new Intent(); homeIntent.setAction(LAUNCHER_ACTION); homeIntent.setPackage(PKG_NAME_OPPO_DEFAULT_LAUNCHER); homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); homeIntent.addCategory(LAUNCHER_CATEGORY); mContext.startActivity(homeIntent); } private String parseComponentState(int state) { switch (state) { case COMPONENT_ENABLED_STATE_DEFAULT: return "default"; case COMPONENT_ENABLED_STATE_ENABLED: return "enabled"; case COMPONENT_ENABLED_STATE_DISABLED: return "disabled"; case COMPONENT_ENABLED_STATE_DISABLED_USER: return "disabled-user"; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: return "disabled-until-used"; default: return "unknown"; } } private ComponentName getBootRegWelcomePageComponentName() { final Intent intent = new Intent(ACTION_WELCOME_PAGE); intent.setPackage(PKG_NAME_BOOT_REG); final ResolveInfoFlags flags = ResolveInfoFlags.of(PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DISABLED_COMPONENTS); final ResolveInfo ri = mContext.getPackageManager().resolveActivityAsUser(intent, flags, UserHandle.USER_SYSTEM); if ((ri != null) && (ri.activityInfo != null)) { return new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name); } return null; } private ComponentName getWallPaperGuidComponentName() { try { boolean isEnabled = mContext.getPackageManager().getPackageInfo(PKG_NAME_WALLPAPER, 0).applicationInfo.enabled; if (!isEnabled) { Slog.w(TAG, "get WallPaper applicationInfo is not enable, return"); disableOtaGuidePage(); return null; } } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "get WallPaper applicationInfo enabled state fail name not found,return"); return null; } final Intent intent = new Intent(ACTION_WALLPAPER_GUIDE_PAGE); intent.setPackage(PKG_NAME_WALLPAPER); final ResolveInfoFlags flags = ResolveInfoFlags.of(PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DISABLED_COMPONENTS); final ResolveInfo ri = mContext.getPackageManager().resolveActivityAsUser(intent, flags, UserHandle.USER_SYSTEM); if ((ri != null) && (ri.activityInfo != null)) { return new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name); } return null; } private boolean hasOplusFeature(@NonNull String featureName) { return OplusFeatureCache.getOrCreate(IOplusFeatureConfigManagerInternal.DEFAULT) .hasFeature(featureName); } // Start upgrade guide to unzip some resources. private void startUpgradeGuide(String reason) { Slog.i(TAG, "Start upgrade guide due to " + reason); Intent upgradeServiceIntent = new Intent(ACTION_UPGRADE_SERVICE); upgradeServiceIntent.putExtra(EXTRA_START_FROM_SYSTEM, 1); upgradeServiceIntent.setPackage(PKG_NAME_UPGRADE_GUIDE); try { OplusBackgroundThread.get().getThreadHandler().post(() -> mContext.startServiceAsUser(upgradeServiceIntent, UserHandle.SYSTEM)); } catch (Exception e) { Slog.e(TAG, "Upgrade service " + upgradeServiceIntent + " failed to start!", e); } } /** * @deprecated * Use action intent filter instead, see {@link #getBootRegWelcomePageComponentName()} */ private boolean doesBootRegWelcomePageExist() { ActivityInfo ai = null; try { ai = mContext.getPackageManager().getActivityInfo(COMPONENT_WELCOME_PAGE, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DISABLED_COMPONENTS); } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "doesBootRegWelcomePageExist package not found", e); } return ai != null; } private boolean isThirdTheme(int userId) { String key = "persist.sys.themeflag"; if (userId > 0) { key = key + "." + userId; } long themeFlag = android.os.SystemProperties.getLong(key, 0); if (getInstance().mDebug) { Slog.e(TAG, "themeFlag " + themeFlag); } return ((THIRD_FLAG & themeFlag) != 0) || ((CUSTOM_THEME_FLAG & themeFlag) != 0); } private boolean isCarrrierOrChannal() { String isCarrrier = SystemProperties.get(PROP_CARRRIER); String isChannel = SystemProperties.get(PROP_CHANNEL); if (getInstance().mDebug) { Slog.e(TAG, "isCarrrier " + TextUtils.isEmpty(isCarrrier) + " isChannel :" + TextUtils.isEmpty(isChannel)); } return (!TextUtils.isEmpty(isCarrrier) || !TextUtils.isEmpty(isChannel)) && !mIsDomesticBuild; } private boolean checkMarketTheme() { //kekemarket online resource check String isMarketThem = SystemProperties.get(PROP_THEME_UUID); int type = 0; if (!TextUtils.isEmpty(isMarketThem) && !("-1".equals(isMarketThem))) { mKeKeMarketTheme = true; Slog.e(TAG, "is kekemartket source"); return true; } //kekemarket online aod check String aodjson = Settings.Secure.getString(mContext.getContentResolver(), "Setting_AodStyleInfo"); if (!TextUtils.isEmpty(aodjson)) { Slog.e(TAG, "aodjson aod" + aodjson); JSONObject jsonObject = null; try { jsonObject = new JSONObject(aodjson); type = jsonObject.getInt("type"); } catch (JSONException e) { Slog.e(TAG, "Reason parse to jsonObject failed !" + e); } if (type == 1) { Slog.e(TAG, "is kekemartket aod"); mKeKeMarketTheme = true; return true; } } // kekemarket online live paper check String isMarketLivePaper = Settings.System.getString(mContext.getContentResolver(), "persist.sys.oppo.live_wp_uuid"); if (!TextUtils.isEmpty(isMarketLivePaper) && !NOT_MARKET_LIVE_WALLPAPER.contains(isMarketLivePaper)) { Slog.e(TAG, "is kekemartket livepaper"); mKeKeMarketTheme = true; return true; } return false; } private boolean checkCompanyType() { String isCompanyType = SystemProperties.get(PROP_COMPANY_TYPE, ""); if (TextUtils.isEmpty(isCompanyType)) { if (mDebug) { Slog.e(TAG, "checkCompanyType is null"); } return false; } if ("empty".equals(isCompanyType)) { if (mDebug) { Slog.e(TAG, "checkCompanyType true"); } return false; } return true; } /** * Deprecated for what's new 2.0 requirement. */ private boolean doesBootRegNewFeaturePageExist() { ActivityInfo ai = null; try { ai = mContext.getPackageManager().getActivityInfo(COMPONENT_NEW_FEATURE_PAGE, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "doesBootRegNewFeaturePageExist package not found", e); } return ai != null; } private boolean isMemoryForbid() { int currentMem = getTotalProcMemInfoGB(); Slog.i(TAG, "current Mem is " + currentMem); if (currentMem > EIGHT_GB) { return false; } return true; } private static long getProcMemInfoKB(String label) { long[] values = new long[1]; values[0] = -1; String[] labels = new String[] {label}; try { android.os.Process.readProcLines(PROC_MEMINFO_PATH, labels, values); } catch (IllegalArgumentException e) { Slog.e(TAG, "getProcMemInfoKB IllegalArgumentException"); } return values[0]; } public static int getTotalProcMemInfoKB() { if (sTotalProcMemInfoKB == -1) { sTotalProcMemInfoKB = (int) getProcMemInfoKB(LABEL_MEMTOTAL); } return sTotalProcMemInfoKB; } public static int getTotalProcMemInfoGB() { if (sTotalProcMemInfoGB == -1) { double tempValue = (getTotalProcMemInfoKB() * 1.0) / GB_IN_KB; sTotalProcMemInfoGB = DEF_RAM_SIZE.stream() .filter(i -> (i >= tempValue)) .min(Integer::compareTo) .orElse(DEF_RAM_SIZE.get(DEF_RAM_SIZE.size() - 1)); } return sTotalProcMemInfoGB; } @Override public void dump(PrintWriter pw, String[] args) { final boolean newFeaturesDisplayingEnabled = mIsDomesticBuild && mIsBrandSupported; final boolean forcedToDisplayNewFeatures = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_NEW_FEATURES, false); final boolean newPoliciesDisplayingEnabled = mIsDomesticBuild; final boolean forcedToDisplayNewPolicies = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_NEW_POLICIES, false); final boolean forcedToDisplayBootReg = SystemProperties.getBoolean(PROP_FORCE_TO_DISPLAY_BOOTREG, false); pw.println("DUMP OF NFDM:"); pw.println(" firstBoot=" + mIsFirstBoot); pw.println(" otaUpgraded=" + mOtaUpgraded); pw.println(" mIsBootFromOTA=" + mIsBootFromOTA); pw.println(" stockType=" + mStockType); pw.println(" deviceTablet=" + mIsDeviceTablet); pw.println(" screenFoldable=" + mIsScreenFoldable); pw.println(" flipDevice=" + mIsFlipDevice); pw.println(); pw.println(" newFeatures={"); pw.println(" featureEnabled=" + newFeaturesDisplayingEnabled + " ["); pw.println(" domestic=" + mIsDomesticBuild); pw.println(" brandSupported=" + mIsBrandSupported); pw.println(" ]"); pw.println(" forced=" + forcedToDisplayNewFeatures); pw.println(" majorVerUpgraded=" + mMajorVersionUpgraded + " ["); pw.println(" prevSdkVer=" + mPrevSdkVersion); pw.println(" curSdkVer=" + mCurSdkVersion); pw.println(" ]"); pw.println(" }"); pw.println(); pw.println(" newPolicies={"); pw.println(" featureEnabled=" + newPoliciesDisplayingEnabled + " ["); pw.println(" domestic=" + mIsDomesticBuild); pw.println(" ]"); pw.println(" forced=" + forcedToDisplayNewPolicies); pw.println(" forcedBootReg=" + forcedToDisplayBootReg); pw.println(" osVerUpgraded=" + mOsVersionUpgraded + " ["); pw.println(" prevOsVer=" + mPrevOsVersion); pw.println(" curOsVer=" + mCurOsVersion); pw.println(" ]"); pw.println(" wsn variable={"); pw.println(" topIsWsn=" + mTopIsWsn); pw.println(" mTopIsLauncher=" + mTopIsLauncher); pw.println(" mIsNeedDisplayWallpaper=" + mIsNeedDisplayWallpaper); pw.println(" mIsNeedDisplaySwitchPage=" + mIsNeedDisplaySwitchPage); pw.println(" ]"); pw.println(" wallpaper variable={"); pw.println(" mPictorialAuto=" + mPictorialAuto); pw.println(" mKeKeMarketTheme=" + mKeKeMarketTheme); pw.println(" doChangeWallPaper=" + mChangeWallPaper); pw.println(" ]"); pw.println(" }"); } } 结合方法分析为什么会出现ota压测出现进开机向导的情况,两个版本都是16版本
最新发布
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值