9.0上 public static final int PROCESS_STATE_TOP_SLEEPING = 11;
8.0上 public static final int PROCESS_STATE_TOP_SLEEPING = 5;
以下是Google工程师comment:
Make TOP_SLEEPING procstate more like a cached process.
When an app is on the top of the activity stack but the screen
is not on, this doesn't really count as a top app in the normal
sense. In particular, we'd really like to apply the normal
restrictions we have on background and cached apps: no network
access, no ability to use wake locks, etc. (In other words, in
this state the app's activity is stopped, so from its perspective
it is no different than the user leaving it to go to another app.)
To do this, we change the order of the TOP_SLEEPING proc state
out from the range of foreground states down to between the
cached and background states.
Test: ActivityManagerProcessStateTest
Bug: 70808931
Change-Id: I994caba8c27553a452de75efa358be0e683d046f
进而改变了耗电统计中bg定义:
BatteryStatsImpl.java
/** Whether to consider Uid to be in the background for background timebase purposes. */
public boolean isInBackground() {
// Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is
// also considered to be 'background' for our purposes, because it's not foreground.
return mProcessState >= PROCESS_STATE_BACKGROUND;
}
BatteryStats.java 映射到ActivityManager procstate
9.0上
/**
* Maps the ActivityManager procstate into corresponding BatteryStats procstate.
*/
public static int mapToInternalProcessState(int procState) {
if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) {
return ActivityManager.PROCESS_STATE_NONEXISTENT;
} else if (procState == ActivityManager.PROCESS_STATE_TOP) {
return Uid.PROCESS_STATE_TOP;
} else if (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
// State when app has put itself in the foreground.
return Uid.PROCESS_STATE_FOREGROUND_SERVICE;
} else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
// Persistent and other foreground states go here.
return Uid.PROCESS_STATE_FOREGROUND;
} else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) {
return Uid.PROCESS_STATE_BACKGROUND;
} else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
return Uid.PROCESS_STATE_TOP_SLEEPING;
} else if (procState <= ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
return Uid.PROCESS_STATE_HEAVY_WEIGHT;
} else {
return Uid.PROCESS_STATE_CACHED;
}
}
大于 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 5; 小于等于 ActivityManager.PROCESS_STATE_RECEIVER = 10 属于 PROCESS_STATE_BACKGROUND
所以bg定义为: 大于 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 5;
Android 8.0
if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) {
uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT;
} else if (procState == ActivityManager.PROCESS_STATE_TOP) {
uidRunningState = PROCESS_STATE_TOP;
} else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
// Persistent and other foreground states go here.
uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE;
} else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
uidRunningState = PROCESS_STATE_TOP_SLEEPING;
} else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
// Persistent and other foreground states go here.
uidRunningState = PROCESS_STATE_FOREGROUND;
} else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) {
uidRunningState = PROCESS_STATE_BACKGROUND;
} else {
uidRunningState = PROCESS_STATE_CACHED;
}
大于 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6; 小于等于 ActivityManager.PROCESS_STATE_RECEIVER = 12 属于 PROCESS_STATE_BACKGROUND
所以bg定义为: 大于 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
TOP_SLEEPING的优先级被拉低了,Android的保护程度降低。