0322Private strand flush not complete

本文针对Oracle数据库中出现的Private strand flush not complete告警进行详细分析,通过一系列命令统计该告警出现的频率及其时间分布,并结合系统优化前后的变化情况探讨其原因。

[20170322]Private strand flush not complete.txt

--//探究一下生产系统出现alert大量出现Private strand flush not complete.这台服务去年4,5月我做了优化,前面设置sga太小,导致数
--//据缓存很小.

SYS@xxxxxx> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

$ grep   "^Private strand flush not complete" alert_xxxxxx.log |wc
    931    4655   31654

--//总共出现931次.

$ grep -B1  "^Private strand flush not complete" alert_xxxxxx.log| grep ^Thread|wc
    931    7448   44201
--//次数也是一样.

--//还可以发现同时出现Thread 1 cannot allocate new log, sequence NNN次数一致.说明主要产生日志量很大,在线日志文件小导致切
--//换频繁来不及归档.

$ grep -B2  "^Private strand flush not complete" alert_xxxxxx.log| grep "[0-5][0-9] 201[567]$"|wc
    581    2905   14525

-//可以发现Private strand flush not complete的前面第2行出现时间测试是581次.

--//取出时间.
$ grep -B2  "^Private strand flush not complete" alert_xxxxxx.log | grep -A1 "^--"  | grep "[0-5][0-9] 201[567]$" >> aa.txt

$ wc aa.txt
  580  2900 14500 aa.txt

--//差1.主要问题第一个输出前面没有--.不影响计算.

$ cut -d" " -f5,2  aa.txt |  uniq -c
     14 Jan 2015
     25 Feb 2015
     34 Mar 2015
     34 Apr 2015
     29 May 2015
     37 Jun 2015
     39 Jul 2015
     42 Aug 2015
     36 Sep 2015
     41 Oct 2015
     40 Nov 2015
     41 Dec 2015
     42 Jan 2016
     40 Feb 2016
     23 Mar 2016
     10 Apr 2016
      4 May 2016
      5 Jun 2016
      1 Jul 2016
      7 Aug 2016
      6 Sep 2016
      3 Oct 2016
      8 Nov 2016
      7 Dec 2016
      6 Jan 2017
      2 Feb 2017
      4 Mar 2017

--//大部分出现在2015-2016年4月之前.而链接http://blog.itpub.net/267265/viewspace-2102914/提示我2016年3月7号开始介入优化.
--//从这里也可以看出优化是有效果的.

$ grep -B3  "^Private strand flush not complete" alert_xxxxxx.log | grep -A1 "^--"  | grep ":[0-5][0-9] 201[567]$"
Tue Mar 31 08:06:22 2015
Mon Apr 13 08:20:57 2015
Tue May 05 08:15:36 2015
--//忽略

$ grep -B4  "^Private strand flush not complete" alert_xxxxxx.log | grep -A1 "^--"  | grep ":[0-5][0-9] 201[567]$"|wc
    447    2235   11175

$ cut -d" " -f5,2  ab.txt |  uniq -c
     12 Jan 2015
     17 Feb 2015
     25 Mar 2015
     20 Apr 2015
     17 May 2015
     25 Jun 2015
     28 Jul 2015
     30 Aug 2015
     27 Sep 2015
     35 Oct 2015
     35 Nov 2015
     33 Dec 2015
     35 Jan 2016
     30 Feb 2016
     18 Mar 2016
      9 Apr 2016
      4 May 2016
      4 Jun 2016
      1 Jul 2016
      7 Aug 2016
      6 Sep 2016
      2 Oct 2016
      8 Nov 2016
      7 Dec 2016
      6 Jan 2017
      2 Feb 2017
      4 Mar 2017

--//出现次数多的基本在2016年4月之前,而这个时候数据缓存很小.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2135830/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-2135830/

/******************************************************************************** ** 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
<think> 根据用户的问题描述,用户遇到了一个错误信息"FLUSH:NOT YET CREAT",并希望找到解决方案。这个错误信息看起来与缓冲区刷新(flush)相关,但并不是一个常见的标准错误信息。 结合站内引用[1]提到的内容:STDOUT是行缓冲的,如果不及时刷新可能会出现问题。引用[2]则展示了在程序退出时通过注册退出处理函数来刷新缓冲区的例子。但是,这两个引用都没有直接提到"FLUSH:NOT YET CREAT"错误。 考虑到错误信息中的"NOT YET CREAT"(应该是"NOT YET CREATED"的拼写错误),这暗示了某个资源尚未创建就被尝试刷新(flush)。可能的场景包括: 1. 在文件打开之前就尝试刷新该文件。 2. 在流(stream)尚未建立时就尝试刷新。 因此,我们可以推测用户可能在程序中尝试刷新了一个尚未创建或初始化的流(例如文件流、标准输出流等)。 解决步骤: 1. 检查代码中调用flush的地方,确保在刷新之前已经正确创建并打开了目标流。 2. 如果刷新的是文件流,确保文件已经成功打开(检查文件指针是否为NULL)。 3. 如果是标准输出(stdout),通常不会出现未创建的情况,但如果是重定向了标准输出,则要注意重定向是否成功。 示例代码(C语言)中可能的问题: ```c FILE *fp; // 忘记打开文件,就直接刷新 fflush(fp); // 此时fp未初始化或未指向打开的文件 ``` 修正后的代码: ```c FILE *fp = fopen("file.txt", "w"); if (fp == NULL) { // 错误处理 } // 写入数据 fprintf(fp, "some data"); fflush(fp); // 此时fp已经指向打开的文件 ``` 另外,在一些编程语言中,如果使用了类似缓冲区的对象,也需要确保在刷新之前已经创建了该对象。 因此,解决方案的核心是:确保在调用刷新操作(如fflushflush等)之前,目标流已经被正确初始化并打开。 如果用户能提供具体的代码片段,可以更准确地定位问题。但基于现有信息,我们只能给出一般性建议。 §§相关问题§§ 1. 如何在不同编程语言中正确刷新输出缓冲区? 2. 文件操作中常见的错误处理有哪些? 3. 如何调试未初始化的文件指针问题? </think> 根据错误信息“FLUSH:NOT YET CREAT”,这通常与**缓冲区刷新机制**和**资源初始化顺序**相关。以下是系统性的解决方案: ### 解决方法 1. **检查资源初始化顺序** 确保在使用`flush()`操作前,目标资源(如文件、网络套接字、缓冲区对象)已正确创建和初始化。典型错误示例: ```python # 错误:未创建文件就尝试刷新 file = None file.flush() # 触发 FLUSH:NOT YET CREAT # 正确:先创建资源再刷新 file = open("data.txt", "w") file.write("Hello") file.flush() # 资源已存在 ``` 2. **验证缓冲区状态** 在刷新前检查资源是否有效: ```python if file and not file.closed: # 确保文件已打开 file.flush() else: print("错误:资源未创建", file=sys.stderr) ``` 3. **显式刷新标准输出** 若涉及`STDOUT`(如引用[1]所述),需确保及时刷新: ```python import sys print("Prompt:", end="", flush=True) # 强制刷新行缓冲 ``` 4. **使用上下文管理器**(推荐) 通过`with`语句自动管理资源生命周期: ```python with open("output.log", "w") as f: # 退出时自动刷新并关闭 f.write("Data") # 无需手动flush ``` 5. **检查第三方库文档** 若错误来自库(如数据库驱动),确认: - 连接是否在`flush()`前已建立 - 是否需调用`.connect()`或`.open()`方法 ### 根本原因分析 此错误通常源于: 1. **对象未初始化**:尝试操作未实例化的对象引用 2. **生命周期管理错误**:资源提前释放后调用`flush()` 3. **异步操作未完成**:在资源就绪前触发刷新(常见于网络I/O) > 提示:引用[2]中的`atexit`清理机制可借鉴,但需确保资源在注册时已存在[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值