#####笔记##### Android P新特性---应用待机群组( 二 )


void reportContentProviderUsage(String authority, String providerPkgName, int userId) {...mAppIdleHistory.reportUsage(packageName, userId,STANDBY_BUCKET_ACTIVE,REASON_SUB_USAGE_SYNC_ADAPTER,0,elapsedRealtime + mSyncAdapterTimeoutMillis);...}
片段4(F):
void reportExemptedSyncScheduled(String packageName, int userId) {...AppUsageHistory appUsage = mAppIdleHistory.reportUsage(packageName, userId,bucketToPromote, usageReason,0,elapsedRealtime + durationMillis);maybeInformListeners(packageName, userId, elapsedRealtime,appUsage.currentBucket, appUsage.bucketingReason, false);}}
2.下调
A> 延迟检查,即当上调事件发生并影响应用优先级时,根据事件类型,设定,在时会对此应用做出对应的下调动作,简单理解为上调的有效期;
/** Minimum time a strong usage event should keep the bucket elevated. */long mStrongUsageTimeoutMillis; //1 小时/** Minimum time a notification seen event should keep the bucket elevated. */long mNotificationSeenTimeoutMillis; //12小时/** Minimum time a system update event should keep the buckets elevated. */long mSystemUpdateUsageTimeoutMillis; //2 小时/** Maximum time to wait for a prediction before using simple timeouts to downgrade buckets. */long mPredictionTimeoutMillis; //12 小时
B>轮询,开机时由服务注册的广播接收器监听用户启动,当用户启动会对该用户下所有的应用的分组情况执行一次检查更新,后每隔3H小时检查更新一次 。
private class UserActionsReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {...} else if (Intent.ACTION_USER_STARTED.equals(action)) {if (userId >=0) {mAppStandby.postCheckIdleStates(userId);}
case MSG_CHECK_IDLE_STATES:if (checkIdleStates(msg.arg1) && mAppIdleEnabled) {mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES, msg.arg1, 0),mCheckIdleIntervalMillis);}break;
llis=+
C> Usage Stats回归检查(防止长时间数据无法更新),在
e. ->
e. ->
e. ->
. ->
. ->
.
case MSG_ONE_TIME_CHECK_IDLE_STATES:mHandler.removeMessages(MSG_ONE_TIME_CHECK_IDLE_STATES);waitForAdminData();checkIdleStates(UserHandle.USER_ALL);break;
3.主动调整
主动调整会在的日志文件中被载入为”p”,原因扩展为D,即预测 。目前此类调整只在通过调用Usgae Stats服务提供的公开API才能实现 。应该是留给GMS应用做AI引入的接口 。

#####笔记#####  Android P新特性---应用待机群组

文章插图
. ->
. ->
.
注:
1,主动调整不能降低有效期内的和 Set优先级;
2.主动调整不能调入或调出组;
3.不能设置高于E优先级的群组
关于分组后的资源限制
资源限制在谷歌官网上解释如下:
#####笔记#####  Android P新特性---应用待机群组

文章插图
代码均以实现ernal.接口的方式完成监听,维护应用分组状态列表,实现控制 。
1.关于Jobs
根据取回的状态,选择推迟Jobs的开始时间,这一部分跟我们关于Jobs限制方式一致 。
private boolean isReadyToBeExecutedLocked(JobStatus job) {...if (!mInParole&& !job.uidActive&& !job.getJob().isExemptedFromAppStandby()) {final int bucket = job.getStandbyBucket();if (bucket >= mConstants.STANDBY_BEATS.length|| (mHeartbeat > appLastRan&& mHeartbeat < appLastRan + mConstants.STANDBY_BEATS[bucket])) {return false;...}