PROCESS_STATE_TOP_SLEEPING状态变化

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的保护程度降低。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值