自启动和管理启动管理介绍

自启动管理用于管理应用的开机自启动/后台自启动/关联自启动。应用自启动的管理,以包名(应
用名)进行限制,不区分 user(用户)。

(1)自启动
指开机自启动和后台自启动。应用可以监听系统的一些开机广播,从而在系统开机后自动进行启动。
同时应用也可以监听系统的任何广播,如网络连接的广播,从而在网络连接上的时候,进行自启动。
(2)关联启动
关联启动指不同的应用之间进行互起。这里指的是,该应用被其他应用后台启动。

流程分析

1)自启动reason

    private static final String REASON_START_SERVICE = "start-service";private static final String REASON_BIND_SERVICE = "bind-service";private static final String REASON_CONTENT_PROVIDER = "contentprovider";private static final String REASON_BROADCAST = "send-broadcast";private static final String REASON_START_ACTIVITY = "start-activity";

1.1 start-activity

在ActivityStarter.java-->startActivity()判断是否是异常启动

    private int startActivity(IApplicationThread caller, Intent intent, Intent ephemeralIntent,String resolvedType, ActivityInfo aInfo, ResolveInfo rInfo,IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid,String callingPackage, int realCallingPid, int realCallingUid, int startFlags,ActivityOptions options, boolean ignoreTargetSecurity, boolean componentSpecified,ActivityRecord[] outActivity, TaskRecord inTask) {.......String targetPkg = null;int targetUid = aInfo != null ? aInfo.applicationInfo.uid : 0;if (intent.getComponent() != null) targetPkg = intent.getComponent().getPackageName();if(!mService.judgeStartAllowLocked(intent, targetPkg, targetUid, callingUid, callingPackage, "start-activity")){return ActivityManager.START_INTENT_NOT_RESOLVED;}.......
}

1.2 start-service

在ActiveServices.java-->startServiceLocked()

    ComponentName startServiceLocked(IApplicationThread caller, Intent service, String resolvedType,int callingPid, int callingUid, boolean fgRequired, String callingPackage, final int userId)throws TransactionTooLargeException {......int targetUid = r.appInfo != null ? r.appInfo.uid : 0 ;if(!mAm.judgeStartAllowLocked(service, r.packageName, targetUid, callingUid, callingPackage,"start-service")) {return null;}......

1.3 bind-service

在ActiveServices.java-->bindServiceLocked()

    int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service,String resolvedType, final IServiceConnection connection, int flags,String callingPackage, final int userId) throws TransactionTooLargeException {......String targetPkg = s != null ? s.packageName : null;int targetUid = (s != null && s.appInfo != null) ? s.appInfo.uid : 0;int callingUid = (callerApp != null && callerApp.info != null) ? callerApp.info.uid : 0;if(!mAm.judgeStartAllowLocked(service, targetPkg, targetUid, callingUid, callingPackage,"bind-service")) {return 0;}......

1.4 send-broadcast

final void processNextBroadcast(boolean fromMsg) {......skip = skip || !mService.judgeStartAllowLocked(r.intent, info.activityInfo.applicationInfo.packageName,info.activityInfo.applicationInfo.uid, r.callingUid, r.callerPackage,"send-broadcast");......
}

1.5 contentprovider

ActivityManagerService.java -->getContentProviderImpl()

private ContentProviderHolder getContentProviderImpl(IApplicationThread caller,String name, IBinder token, boolean stable, int userId) {ContentProviderRecord cpr;......String targetPkg = (cpr != null && cpr.appInfo != null) ? cpr.appInfo.packageName : null;int targetUid = (cpr != null && cpr.appInfo != null) ? cpr.appInfo.uid : 0;if (r != null && r.info != null) {String callingPackage = r.info.packageName;int callerUid = r.info.uid;if(!judgeStartAllowLocked(null, targetPkg, targetUid, callerUid, callingPackage,"contentprovider")) {return null;}}......

可以看出自启动的拦截,就是在四大组件启动流程中进行的

2)judgeStartAllowLocked()流程分析

ActivityManagerServerEx.java-->judgeStartAllowLocked()

    protected boolean judgeStartAllowLocked(Intent intent, String targetPkg, int targetUid,int callingUid, String callingPackage, String reason) {boolean allowed = true;if (allowed && mPowerControllerInternal != null) {try {allowed = mPowerControllerInternal.judgeAppLaunchAllowed(intent, targetPkg, targetUid, callingUid, callingPackage, reason);} catch (Exception e) {}}

BackgroundCleanHelper.java-->judgeAppLaunchAllowed()

     boolean judgeAppLaunchAllowed(Intent intent, String targetApp, int targetUid,int callerUid, String callerApp, String reason) {mPowerHintSceneForGts.noteAppLaunched(targetApp, callerApp, callerUid);boolean ret = judgeAppLaunchAllowedInternal(intent, targetApp, targetUid, callerUid, callerApp, reason);if (mCurrentUserId == 0 && ret && targetApp != null) {if (!targetApp.equals(callerApp) && !mFirstCallerAppList.containsKey(targetApp)&& isInstalledApp(targetApp, 0)) {mFirstCallerAppList.put(targetApp, new CallerAppInfo(callerApp, callerUid, reason));}}return ret;

BackgroundCleanHelper.java-->judgeAppLaunchAllowedInternal()

/** Third app can not self started:* 1. not allow system broadcast from "systemserver" or "com.android.systemui"* 2. not allow start service from ""com.android.shell"* 3. not allow background app to launch other third party app* 4. not allow self started third party app to start other third party app* 5. not allow third party app to start other third party app during standby** Note: This api is call from AMS in other threads and may be in variable calling context*  SO BE CAREFULL : avoid call other system API that may hold lock. Otherwise, a deadlock may HAPPEN*/boolean judgeAppLaunchAllowedInternal(Intent intent, String targetApp, int targetUid,int callerUid, String callerApp, String reason) {// if this function is disabled, just return trueif (!mEnabled) return true;if (DEBUG_MORE) Slog.d(TAG,"judgeAppLaunchAllowed : "+targetApp+"(uid:" + targetUid+ "), callingPackage = "+callerApp+"(uid:" + callerUid + "), reason = "+reason);if (DEBUG_MORE && intent != null) Slog.d(TAG,"judgeAppLaunchAllowed : intent action:" + intent);if (targetApp == null) return true;// bug#768670if (handleStartServiceStartAction(intent, targetApp, targetUid, callerApp, callerUid, reason)) {return true;}if (handleBindServiceStartAction(intent, targetApp, targetUid, callerApp, callerUid, reason)) {return true;}if (handleContentProviderStartAction(intent, targetApp, targetUid, callerApp, callerUid, reason)) {return true;}//handle inputmethodif (isLaunchingIMEApp(intent, targetApp, targetUid, callerApp, reason)) {return true;}if (handleBroadcastAction(intent, targetApp, targetUid, callerApp, callerUid, reason)) {return true;}//handle speech recognitionif (isRecognizerIntent(intent, targetApp, targetUid, callerApp, callerUid, reason)) {return true;}// allow cts app to start any other app// allow autotest appif (Util.isCts(callerApp) || isAutoTest(callerUid, callerApp, targetApp)) {return true;}// check deny for ultra saving mode//if (denyBecauseOfUltraSavingMode(intent, targetApp, targetUid, callerApp, callerUid, reason)) {//    return false;//}int targetUserId = UserHandle.getUserId(targetUid);int callUserId = UserHandle.getUserId(callerUid);AppState callerAppState = mAppStateInfoCollector.getAppState(callerApp, callUserId);AppState targetAppState = mAppStateInfoCollector.getAppState(targetApp, targetUserId);// if target app already exist/*if (targetAppState != null&& targetAppState.mProcState < ActivityManager.PROCESS_STATE_CACHED_EMPTY&& targetAppState.mProcState != ActivityManager.PROCESS_STATE_NONEXISTENT) {*/if (isAlreadyStarted(targetAppState)) {if (DEBUG_MORE) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": already started!!"+ " (ProcState:" +  Util.ProcState2Str(targetAppState.mProcState)+ " mState:" + Util.AppState2Str(targetAppState.mState)+ ")");return true;}// check system app// allow to launch system appint launchState = checkLaunchStateByPreset(intent, targetApp, targetUid, callerApp, callerUid, reason);if (launchState == LAUNCH_STATE_ALLOW)return true;else if (launchState == LAUNCH_STATE_DENY)return false;// check user setting for third-party app(重点)launchState = checkLaunchStateByUserSetting(intent, targetApp, targetUid, callerApp, callerUid, reason);if (DEBUG_MORE) Slog.d(TAG, "launchState: " + launchState);if (launchState == LAUNCH_STATE_ALLOW)return true;else if (launchState == LAUNCH_STATE_DENY)return false;// not allow third party app that has been force stopped during standby// to be started againif (mStandbyStartTime > 0 && isForceStoppedAppDuringStandby(targetApp, targetUid)) {if (DEBUG) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": denyed (has been force stopped)!!");return false;}// not allow system broadcast to launch third party appif ((callerAppState == null ||(callerApp != null && callerApp.equals("android")))&& REASON_BROADCAST.equals(reason)) {if (DEBUG) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": denyed!!");return false;}// not allow "com.android.systemui" broadcast to launch third party appif (callerApp != null && callerApp.equals("com.android.systemui")&& REASON_BROADCAST.equals(reason)) {if (DEBUG) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": denyed!!");return false;}// allow app to launch itselfif (targetApp.equals(callerApp)) {return true;}// not allow non-top app to launch other app, except launched by UserActivityif (!launchedByUserActivity(intent, targetApp, targetUid, callerApp, callerUid, reason, true)) {if (DEBUG) {Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+ " (ProcState:" + (callerAppState != null ? Util.ProcState2Str(callerAppState.mProcState):"none")+"), reason = "+reason+ ": non-UserActivity denyed!!");}return false;}// not allow background app to launch other third party appif (callerAppState != null && callerAppState.mProcState > ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE&& !REASON_START_ACTIVITY.equals(reason)) {if (DEBUG) {Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+ " (ProcState:" + (callerAppState != null ? Util.ProcState2Str(callerAppState.mProcState):"none")+"), reason = "+reason+ ": denyed!!");}return false;}// not allow self started third party app to start other third party appif (callerAppState != null && callerAppState.mLaunchCount == 0 && !isSystemApp(callerAppState)&& !REASON_START_ACTIVITY.equals(reason)) {if (DEBUG) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": denyed!!");return false;}// not allow long idle third party app to start other third party appif (callerAppState != null && !isSystemApp(callerAppState)&& callerAppState.mState != Event.MOVE_TO_FOREGROUND&& callerAppState.mProcState != ActivityManager.PROCESS_STATE_TOP&& !REASON_START_ACTIVITY.equals(reason)) {long nowELAPSED = SystemClock.elapsedRealtime();long idleDuration = 0;idleDuration = (callerAppState.mLastTimeUsed > 0 ? (nowELAPSED -callerAppState.mLastTimeUsed) : -1);if (idleDuration > DENY_START_APP_THRESHOLD) {if (DEBUG) Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+", reason = "+reason + ": denyed!! long idle");return false;}}// not allow third party app to start other third party app during standbyif (mStandbyStartTime > 0&& !REASON_START_ACTIVITY.equals(reason)) {if (DEBUG) {Slog.d(TAG,"Start Proc : "+targetApp+", callingPackage = "+callerApp+ " (ProcState:" + (callerAppState != null ? Util.ProcState2Str(callerAppState.mProcState):"none")+"), reason = "+reason+ ": denyed during standby!!");}return false;}return true;}

BackgroundCleanHelper.java-->checkLaunchStateByUserSetting()

private int checkLaunchStateByUserSetting(Intent intent, String targetApp, int targetUid,String callerApp, int callerUid, String reason) {if (targetApp == null || targetApp.equals(callerApp))return LAUNCH_STATE_AUTO;boolean launchByOther = autoLaunchByOtherApp(targetApp, targetUid, callerApp, callerUid, reason);// allow app in whitelistif (inSelfStartWhiteAppList(targetApp)) {return LAUNCH_STATE_ALLOW;}// if in ultrasaving mode, don't allow autostart except apps in ultrasve applistif (!launchByOther && (PowerManagerEx.MODE_ULTRASAVING == mPowerSaveMode)&& (PowerManagerEx.MODE_ULTRASAVING == mNextPowerSaveMode)) {List<String> appList = mPowerControllerInternal.getAppList_UltraMode();if (!appList.contains(targetApp)) {if (DEBUG) Slog.d(TAG, "app: " + targetApp + " in applist of ultramode, refuse to autostart, denyed");return LAUNCH_STATE_DENY;}}int autoLaunch = mPowerControllerInternal.getAppPowerSaveConfgWithTypeInternal(targetApp,AppPowerSaveConfig.ConfigType.TYPE_AUTOLAUNCH.value);int secondLaunch = mPowerControllerInternal.getAppPowerSaveConfgWithTypeInternal(targetApp,AppPowerSaveConfig.ConfigType.TYPE_SECONDARYLAUNCH.value);if (((autoLaunch == AppPowerSaveConfig.VALUE_NO_OPTIMIZE) && !launchByOther)|| ((secondLaunch == AppPowerSaveConfig.VALUE_NO_OPTIMIZE) && launchByOther)) {if (DEBUG) Slog.d(TAG, "bgclean judgeAppLaunchAllowed: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+reason +" in my whitelist");return LAUNCH_STATE_ALLOW;}//check whether app is in black listboolean bInBlackList = false;if ((autoLaunch == AppPowerSaveConfig.VALUE_OPTIMIZE) && !launchByOther) {if (DEBUG_MORE) Slog.d(TAG, "in apppowerconfig autolaunch black list: " + targetApp);bInBlackList = true;}if ((secondLaunch == AppPowerSaveConfig.VALUE_OPTIMIZE) && launchByOther) {if (DEBUG_MORE) Slog.d(TAG, "in apppowerconfig 2ndlaunch black list: " + targetApp);bInBlackList = true;}// check whether blacklist app is in exceptionif (bInBlackList) {// not allow auto start app that in auto start black list// 1. in mAutoLaunch_BlackList AND is not launched by other app (that is launched by system broadcast etc)// 2. NOTE: Exception://     1) Start reason is REASON_START_ACTIVITY  (this is alway happened in case of//         app use another app to do something, including launcher to launch a app)//     2) Self start self ( that is this app is alreadby started, and is start some activity internal)if (!launchByOther && !REASON_START_ACTIVITY.equals(reason)) {if (DEBUG) Slog.d(TAG, "in autolaunch black list: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+reason +" denyed!");return LAUNCH_STATE_DENY;}// not allow auto start by other app that in secondary start black list// 1. in m2ndLaunch_BlackList AND is launched by other app// 2. NOTE: Exception://     1) when callerApp is top AND Start reason is REASON_START_ACTIVITY  (this is alway happened in case of//         app use another app to do something, including launcher to launch a app)//     2) Self start self ( that is this app is alreadby started, and is start some activity internal)//     3) when callerApp is top AND targetApp is in AssociateLaunchExceptionAppListif (launchByOther && !launchedByUserActivity(intent, targetApp, targetUid, callerApp, callerUid, reason, true)) {if (DEBUG) Slog.d(TAG, "in 2ndlaunch black list: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+ reason + " intent:" + intent + " denyed!");return LAUNCH_STATE_DENY;}// Although it is black list, but it start by user, so allowed to startreturn LAUNCH_STATE_ALLOW;}return LAUNCH_STATE_AUTO;}

BackgroundCleanHelper.java-->checkLaunchStateByUserSetting()

这个方法就是根据用户的设置,来判断是否拦截自启

private int checkLaunchStateByUserSetting(Intent intent, String targetApp, int targetUid,String callerApp, int callerUid, String reason) {if (targetApp == null || targetApp.equals(callerApp))return LAUNCH_STATE_AUTO;boolean launchByOther = autoLaunchByOtherApp(targetApp, targetUid, callerApp, callerUid, reason);// allow app in whitelistif (inSelfStartWhiteAppList(targetApp)) {return LAUNCH_STATE_ALLOW;}// if in ultrasaving mode, don't allow autostart except apps in ultrasve applistif (!launchByOther && (PowerManagerEx.MODE_ULTRASAVING == mPowerSaveMode)&& (PowerManagerEx.MODE_ULTRASAVING == mNextPowerSaveMode)) {List<String> appList = mPowerControllerInternal.getAppList_UltraMode();if (!appList.contains(targetApp)) {if (DEBUG) Slog.d(TAG, "app: " + targetApp + " in applist of ultramode, refuse to autostart, denyed");return LAUNCH_STATE_DENY;}}int autoLaunch = mPowerControllerInternal.getAppPowerSaveConfgWithTypeInternal(targetApp,AppPowerSaveConfig.ConfigType.TYPE_AUTOLAUNCH.value);int secondLaunch = mPowerControllerInternal.getAppPowerSaveConfgWithTypeInternal(targetApp,AppPowerSaveConfig.ConfigType.TYPE_SECONDARYLAUNCH.value);if (((autoLaunch == AppPowerSaveConfig.VALUE_NO_OPTIMIZE) && !launchByOther)|| ((secondLaunch == AppPowerSaveConfig.VALUE_NO_OPTIMIZE) && launchByOther)) {if (DEBUG) Slog.d(TAG, "bgclean judgeAppLaunchAllowed: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+reason +" in my whitelist");return LAUNCH_STATE_ALLOW;}//check whether app is in black listboolean bInBlackList = false;if ((autoLaunch == AppPowerSaveConfig.VALUE_OPTIMIZE) && !launchByOther) {if (DEBUG_MORE) Slog.d(TAG, "in apppowerconfig autolaunch black list: " + targetApp);bInBlackList = true;}if ((secondLaunch == AppPowerSaveConfig.VALUE_OPTIMIZE) && launchByOther) {if (DEBUG_MORE) Slog.d(TAG, "in apppowerconfig 2ndlaunch black list: " + targetApp);bInBlackList = true;}// check whether blacklist app is in exceptionif (bInBlackList) {// not allow auto start app that in auto start black list// 1. in mAutoLaunch_BlackList AND is not launched by other app (that is launched by system broadcast etc)// 2. NOTE: Exception://     1) Start reason is REASON_START_ACTIVITY  (this is alway happened in case of//         app use another app to do something, including launcher to launch a app)//     2) Self start self ( that is this app is alreadby started, and is start some activity internal)if (!launchByOther && !REASON_START_ACTIVITY.equals(reason)) {if (DEBUG) Slog.d(TAG, "in autolaunch black list: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+reason +" denyed!");return LAUNCH_STATE_DENY;}// not allow auto start by other app that in secondary start black list// 1. in m2ndLaunch_BlackList AND is launched by other app// 2. NOTE: Exception://     1) when callerApp is top AND Start reason is REASON_START_ACTIVITY  (this is alway happened in case of//         app use another app to do something, including launcher to launch a app)//     2) Self start self ( that is this app is alreadby started, and is start some activity internal)//     3) when callerApp is top AND targetApp is in AssociateLaunchExceptionAppListif (launchByOther && !launchedByUserActivity(intent, targetApp, targetUid, callerApp, callerUid, reason, true)) {if (DEBUG) Slog.d(TAG, "in 2ndlaunch black list: "+targetApp+ ", callingPackage = "+callerApp+", reason = "+ reason + " intent:" + intent + " denyed!");return LAUNCH_STATE_DENY;}// Although it is black list, but it start by user, so allowed to startreturn LAUNCH_STATE_ALLOW;}return LAUNCH_STATE_AUTO;}

继续逐个分析涉及到的主要方法

BackgroundCleanHelper.java-->checkLaunchStateByUserSetting()-->autoLaunchByOtherApp()

    // return true, if app is start by system broadcastprivate boolean autoLaunchByOtherApp(String targetApp, int targetUid,String callerApp, int callerUid, String reason) {if (callerApp == null||callerApp.equals("android")|| callerApp.equals("com.android.systemui"))return false;AppState callerAppState = mAppStateInfoCollector.getAppState(callerApp, UserHandle.getUserId(callerUid));if (callerAppState != null && callerAppState.mUid < Process.FIRST_APPLICATION_UID)return false;return true;}

BackgroundCleanHelper.java-->checkLaunchStateByUserSetting()-->launchedByUserActivity()

 private boolean launchedByUserActivity(Intent intent, String targetApp, int targetUid,String callerApp, int callerUid, String reason, boolean ignoreTouchTime) {boolean userLaunched = false;long now = SystemClock.elapsedRealtime();long lastTouchTime = 0;AppState callerAppState = mAppStateInfoCollector.getAppState(callerApp, UserHandle.getUserId(callerUid));if (mPowerControllerInternal != null) {lastTouchTime = mPowerControllerInternal.getLastTouchEventTimeStamp();}boolean isCallerTopApp  =  false;if (callerAppState != null&&((callerAppState.mProcState == ActivityManager.PROCESS_STATE_TOP)|| (callerAppState.mProcState == ActivityManager.PROCESS_STATE_HOME)|| (callerAppState.mState == Event.MOVE_TO_FOREGROUND)|| (now - callerAppState.mLastTimeUsed) < 1000|| isLauncherApp(callerApp)) // for Bug#712736) {isCallerTopApp = true;}// check the associated-starting because of third party push serviceif (isCallerTopApp &&REASON_START_ACTIVITY.equals(reason)&& !isLauncherAction(intent)&& intent != null&& ThirdpartyPush.isAssociatedComponent(intent.getComponent())) {if (DEBUG) Slog.d(TAG,"launchedByUserActivity : Start Proc : "+targetApp+", callingPackage = "+callerApp+ " (ProcState:" + (callerAppState != null ? Util.ProcState2Str(callerAppState.mProcState):"none")+"), reason = "+reason+ " Associated-Starting ThirdParty Push Service");isCallerTopApp = false;}// see the caller of a launcher action as top app// add for bug#776461if (!isCallerTopApp && intent != null && isLauncherAction(intent)) {isCallerTopApp = true;}if (DEBUG_MORE) {Slog.d(TAG,"launchedByUserActivity : Start Proc : "+targetApp+", callingPackage = "+callerApp+ " (ProcState:" + (callerAppState != null ? Util.ProcState2Str(callerAppState.mProcState):"none")+"), reason = "+reason);}long lastTouchElasedTime = now - lastTouchTime;if (DEBUG) Slog.d(TAG, "lastTouchElasedTime: "+lastTouchElasedTime);if (isCallerTopApp&& (REASON_START_ACTIVITY.equals(reason)|| (!ignoreTouchTime && lastTouchElasedTime <= (1*1000)))) {userLaunched = true;}// check if this call from "android"if (!isCallerTopApp && REASON_START_ACTIVITY.equals(reason) && lastTouchElasedTime <= (1*1000)) {AppState androidState = mAppStateInfoCollector.getAppState("android", UserHandle.USER_SYSTEM);if (androidState != null&& (androidState.mState == Event.MOVE_TO_FOREGROUND)|| (now - androidState.mLastTimeUsed) < 1000) {userLaunched = true;}}// Bug#707888 setting monkey fail --> BEG// for callerApp is system app, and use "start-activity", then allowif ((callerAppState == null || callerAppState.mUid < Process.FIRST_APPLICATION_UID)&& REASON_START_ACTIVITY.equals(reason)) {userLaunched = true;}// Bug#707888 setting monkey fail <-- ENDreturn userLaunched;}

BackgroundCleanHelper.java-->checkLaunchStateByUserSetting()-->launchedByUserActivity()-->isLauncherApp()

    private boolean isLauncherApp(String pkgName) {int index = mLauncherAppList.indexOf(pkgName);if (index >= 0) {return true;}return false;}

isLauncherApp主要是通过是否有CATEGORY_HOME属性判断的

private void loadLauncherApps() {try {Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_HOME);final List<UserInfo> users = mUserManager.getUsers();for (int ui = users.size() - 1; ui >= 0; ui--) {UserInfo user = users.get(ui);if (DEBUG) Slog.d(TAG, "- loadLauncherApps() for user: " + user.id);List<ResolveInfo> resolves =mContext.getPackageManager().queryIntentActivitiesAsUser(intent, PackageManager.MATCH_DISABLED_COMPONENTS, user.id);// Look for the original activity in the list...final int N = resolves != null ? resolves.size() : 0;for (int i=0; i<N; i++) {final ResolveInfo candidate = resolves.get(i);final ActivityInfo info = candidate.activityInfo;if (info != null && info.packageName != null&& !mLauncherAppList.contains(info.packageName)) {....../*check if contains the default launcher*/for(String s : mDefaultLauncherAppList) {if(!mLauncherAppList.contains(s)) {mLauncherAppList.add(s);}}......}
    // default launcher app listprivate String[] mDefaultLauncherAppList = new String[] {"com.android.launcher3","com.android.settings"};

这一篇就分析到这里!

Android Sprd省电管理(四)自启动和关联启动管理相关推荐

  1. Android Sprd省电管理(二)应用省电模式设置流程

    在Android Sprd省电管理(一)appPowerSaveConfig.xml,我们介绍了appPowerSaveConfig.xml的主要参数的意义,这一篇我们介绍下,怎么设置应用的各种省电模 ...

  2. android进程自启动、关联启动

    检测机构报告,说我们app在杀死app有自启动和关联启动行为 情况一 排查中发现一种情况是AlarmManager定时任务导致的 @kotlin.jvm.JvmStaticfun startBDAla ...

  3. APP安卓应用市场上架隐私政策问题、自启动和关联启动说明

    问题来源 app应用宝上线.(隐私政策问题)检测到APP/SDK存在监听安卓系统广播进行自启动.请在基础信息-隐私政策文本中补充[自启动]关键字描述规则.然后保存基础信息并提交安装包审核. 解决案例 ...

  4. Android 浏览器的研究(四)--- Apk的启动和主页的加载过程

    当我们在Launcher中点击浏览器的图标时,浏览器的窗口会打开并显示主页(HomePage).这里我们对这一场景进行分析,研究浏览器如何启动,取得缺省主页并将它布局和显示的. 根据前边对WebVie ...

  5. android应用的自启动 和 相互关联启动

    Android手机APP常见后台服务  2015年1月26日  小恐龙  应用技巧 前言简述 Android生态系统原本提供了类似于Apple iOS推送服务APNS的GCM(Google Cloud ...

  6. 三十四、段页式管理方式

    一.知识总览 二.分页.分段的优缺点分析 分页管理: 优点:内存空间利用率高,不会产生外部碎片,只会有少量的页内碎片. 缺点:不方便按照逻辑模块实现信息的共享和保护 分段管理: 优点:很方便按照逻辑模 ...

  7. 时间管理四象限法怎么运用?这款待办工具来帮你

    在现代职场中,时间就是金钱,而大多数企业对员工的要求也是在规定的工作时间内完成尽可能多的工作任务.这就表示对于上班族来说,时间管理是非常重要的,而谈到时间管理就不得不提到一个重要的时间管理法则了,它就 ...

  8. 华为手机怎么设置APP开机启动管理将自动管理修改成手动管理?

    华为手机APP启动管理为分自动管理和手动管理,开启自动管理后将采用智能方式开启或关闭手机APP应用是否随手机启动自启或后台自启,采用手动管理模式可以最大可能的保证指定的手机APP应用开机或后台中自启动 ...

  9. windows启动管理器怎么修复计算机,如果启动管理器丢失怎么办

    在微软的Windows系统中,都有一个启动管理器,如果这个启动管理器被损坏或者丢失,那么将会造成电脑无法启动,有位用户就遇到这样的问题,这该怎么办呢?不要惊慌,下面小编和大家分享电脑启动管理器丢失的解 ...

  10. Android性能优化 ---(6)自启动管理

    自启动管理简介 Android手机上安装的很多应用都会自启动,占用资源越来越多,造成系统卡顿等现象.良好的自启动管理方案管理后台自启动和开机自启动,这样就可以节约内存.优化系统流畅性等. 自启动管理流 ...

最新文章

  1. Andrew Ng 深度学习课后测试记录-01-week2-答案
  2. AOE网上的关键路径
  3. 今日代码(20210225)--数据处理
  4. pythonchar中的拟合方法_在python中利用numpy求解多项式以及多项式拟合的方法
  5. CSS样式:覆盖规则
  6. 信息学奥赛C++语言:约瑟夫问题
  7. Python+psutil获取本机所有联网的应用程序信息
  8. HDU 4607 Park Visit(树的直径)
  9. [置顶] Oracle数据操作和控制语言详解
  10. cas客户端登陆状态不同步_Java并发——同步组件
  11. Joomla源代码解析(十九) JController
  12. Tuxedo中间件 配置维护记录
  13. K3CLOUD新增用户
  14. fso 拒绝访问_CTBS问题及解决.docx
  15. c# Socket Udp通讯示例源码
  16. Xshell 5 注册码
  17. 【OSPF基础(链路状态路由协议、ospf基础术语、ospf协议报文类型、ospf三大表项、邻居和邻接关系、ospf网络类型、DR与BDR、ospf基本配置)】-20211210、13、14
  18. 使用selenium和chromedriver实现12306抢票
  19. 【Excel】Excel无序数据模糊查询
  20. python解法:【PAT520砖石争霸赛】7-2真的恭喜你(10)

热门文章

  1. 互联网时代,站对了风口,猪都能飞起来
  2. D - Power Tower欧拉降幂公式
  3. Spring Boot 2.0.6 整合 Spring Clod Bus + Kafka
  4. spring cloud搭建教程
  5. 乐2 乐视X520_官方线刷包_救砖包_解账户锁
  6. Tivoli Storage Manager安装配置
  7. Springboot读取excel
  8. 小草 李白 《菩萨蛮》
  9. 什么是京东自营商品?京东自营是什么意思?京东自营?
  10. Oracle启动监听错误TNS-12555: TNS:permission denied