Merge "Use the reason code from standby bucketing in bg restriction if needed" into tm-dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.android.server.usage;
|
package com.android.server.usage;
|
||||||
|
|
||||||
import android.annotation.CurrentTimeMillisLong;
|
import android.annotation.CurrentTimeMillisLong;
|
||||||
|
import android.annotation.ElapsedRealtimeLong;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
@@ -149,6 +150,12 @@ public interface AppStandbyInternal {
|
|||||||
int getAppMinStandbyBucket(String packageName, int appId, int userId,
|
int getAppMinStandbyBucket(String packageName, int appId, int userId,
|
||||||
boolean shouldObfuscateInstantApps);
|
boolean shouldObfuscateInstantApps);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the bucketing reason code of the given app.
|
||||||
|
*/
|
||||||
|
int getAppStandbyBucketReason(@NonNull String packageName, @UserIdInt int userId,
|
||||||
|
@ElapsedRealtimeLong long elapsedRealtime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the specified app in the
|
* Put the specified app in the
|
||||||
* {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
|
* {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
|
||||||
|
|||||||
@@ -1436,8 +1436,8 @@ public class AppStandbyController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@Override
|
||||||
int getAppStandbyBucketReason(String packageName, int userId, long elapsedRealtime) {
|
public int getAppStandbyBucketReason(String packageName, int userId, long elapsedRealtime) {
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
return mAppIdleHistory.getAppStandbyReason(packageName, userId, elapsedRealtime);
|
return mAppIdleHistory.getAppStandbyReason(packageName, userId, elapsedRealtime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1086,6 +1086,12 @@ public final class AppRestrictionController {
|
|||||||
}
|
}
|
||||||
final @RestrictionLevel int level = calcAppRestrictionLevel(
|
final @RestrictionLevel int level = calcAppRestrictionLevel(
|
||||||
userId, uid, info.mPackageName, info.mStandbyBucket, false, false);
|
userId, uid, info.mPackageName, info.mStandbyBucket, false, false);
|
||||||
|
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
||||||
|
Slog.i(TAG, "Proposed restriction level of " + info.mPackageName + "/"
|
||||||
|
+ UserHandle.formatUid(uid) + ": "
|
||||||
|
+ ActivityManager.restrictionLevelToName(level)
|
||||||
|
+ " " + info.mStandbyBucket);
|
||||||
|
}
|
||||||
applyRestrictionLevel(info.mPackageName, uid, level,
|
applyRestrictionLevel(info.mPackageName, uid, level,
|
||||||
info.mStandbyBucket, true, reason, subReason);
|
info.mStandbyBucket, true, reason, subReason);
|
||||||
}
|
}
|
||||||
@@ -1185,6 +1191,25 @@ public final class AppRestrictionController {
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @RestrictionLevel int standbyBucketToRestrictionLevel(
|
||||||
|
@UsageStatsManager.StandbyBuckets int standbyBucket) {
|
||||||
|
switch (standbyBucket) {
|
||||||
|
case STANDBY_BUCKET_EXEMPTED:
|
||||||
|
return RESTRICTION_LEVEL_EXEMPTED;
|
||||||
|
case STANDBY_BUCKET_NEVER:
|
||||||
|
return RESTRICTION_LEVEL_BACKGROUND_RESTRICTED;
|
||||||
|
case STANDBY_BUCKET_ACTIVE:
|
||||||
|
case STANDBY_BUCKET_WORKING_SET:
|
||||||
|
case STANDBY_BUCKET_FREQUENT:
|
||||||
|
case STANDBY_BUCKET_RARE:
|
||||||
|
return RESTRICTION_LEVEL_ADAPTIVE_BUCKET;
|
||||||
|
case STANDBY_BUCKET_RESTRICTED:
|
||||||
|
return RESTRICTION_LEVEL_RESTRICTED_BUCKET;
|
||||||
|
default:
|
||||||
|
return RESTRICTION_LEVEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the restriction level of the given UID, if it hosts multiple packages,
|
* Get the restriction level of the given UID, if it hosts multiple packages,
|
||||||
* return least restricted one (or if any of them is exempted).
|
* return least restricted one (or if any of them is exempted).
|
||||||
@@ -1380,12 +1405,23 @@ public final class AppRestrictionController {
|
|||||||
int curBucket, boolean allowUpdateBucket, int reason, int subReason) {
|
int curBucket, boolean allowUpdateBucket, int reason, int subReason) {
|
||||||
int curLevel;
|
int curLevel;
|
||||||
int prevReason;
|
int prevReason;
|
||||||
|
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
|
||||||
synchronized (mSettingsLock) {
|
synchronized (mSettingsLock) {
|
||||||
curLevel = getRestrictionLevel(uid, pkgName);
|
curLevel = getRestrictionLevel(uid, pkgName);
|
||||||
if (curLevel == level) {
|
if (curLevel == level) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final int levelOfBucket = standbyBucketToRestrictionLevel(curBucket);
|
||||||
|
if (levelOfBucket == level) {
|
||||||
|
// If the standby bucket yield the same level, use the reason from standby bucket.
|
||||||
|
final int bucketReason = appStandbyInternal.getAppStandbyBucketReason(
|
||||||
|
pkgName, UserHandle.getUserId(uid), SystemClock.elapsedRealtime());
|
||||||
|
if (bucketReason != 0) {
|
||||||
|
reason = bucketReason & REASON_MAIN_MASK;
|
||||||
|
subReason = bucketReason & REASON_SUB_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
||||||
Slog.i(TAG, "Updating the restriction level of " + pkgName + "/"
|
Slog.i(TAG, "Updating the restriction level of " + pkgName + "/"
|
||||||
+ UserHandle.formatUid(uid) + " from "
|
+ UserHandle.formatUid(uid) + " from "
|
||||||
@@ -1393,7 +1429,6 @@ public final class AppRestrictionController {
|
|||||||
+ ActivityManager.restrictionLevelToName(level)
|
+ ActivityManager.restrictionLevelToName(level)
|
||||||
+ " reason=" + reason + ", subReason=" + subReason);
|
+ " reason=" + reason + ", subReason=" + subReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevReason = mRestrictionSettings.getReason(pkgName, uid);
|
prevReason = mRestrictionSettings.getReason(pkgName, uid);
|
||||||
mRestrictionSettings.update(pkgName, uid, level, reason, subReason);
|
mRestrictionSettings.update(pkgName, uid, level, reason, subReason);
|
||||||
}
|
}
|
||||||
@@ -1401,7 +1436,6 @@ public final class AppRestrictionController {
|
|||||||
if (!allowUpdateBucket || curBucket == STANDBY_BUCKET_EXEMPTED) {
|
if (!allowUpdateBucket || curBucket == STANDBY_BUCKET_EXEMPTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
|
|
||||||
if (level >= RESTRICTION_LEVEL_RESTRICTED_BUCKET
|
if (level >= RESTRICTION_LEVEL_RESTRICTED_BUCKET
|
||||||
&& curLevel < RESTRICTION_LEVEL_RESTRICTED_BUCKET) {
|
&& curLevel < RESTRICTION_LEVEL_RESTRICTED_BUCKET) {
|
||||||
if (!mConstantsObserver.mRestrictedBucketEnabled) {
|
if (!mConstantsObserver.mRestrictedBucketEnabled) {
|
||||||
@@ -1422,8 +1456,10 @@ public final class AppRestrictionController {
|
|||||||
final int index = mActiveUids.indexOfKey(uid, pkgName);
|
final int index = mActiveUids.indexOfKey(uid, pkgName);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
// It's currently active, enqueue it.
|
// It's currently active, enqueue it.
|
||||||
|
final int localReason = reason;
|
||||||
|
final int localSubReason = subReason;
|
||||||
mActiveUids.add(uid, pkgName, () -> appStandbyInternal.restrictApp(
|
mActiveUids.add(uid, pkgName, () -> appStandbyInternal.restrictApp(
|
||||||
pkgName, UserHandle.getUserId(uid), reason, subReason));
|
pkgName, UserHandle.getUserId(uid), localReason, localSubReason));
|
||||||
doIt = false;
|
doIt = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1841,9 +1877,6 @@ public final class AppRestrictionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleUidInactive(int uid, boolean disabled) {
|
void handleUidInactive(int uid, boolean disabled) {
|
||||||
if (!mConstantsObserver.mBgAutoRestrictedBucket) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final ArrayList<Runnable> pendingTasks = mTmpRunnables;
|
final ArrayList<Runnable> pendingTasks = mTmpRunnables;
|
||||||
synchronized (mSettingsLock) {
|
synchronized (mSettingsLock) {
|
||||||
final int index = mActiveUids.indexOfKey(uid);
|
final int index = mActiveUids.indexOfKey(uid);
|
||||||
@@ -1866,14 +1899,12 @@ public final class AppRestrictionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleUidActive(int uid) {
|
void handleUidActive(int uid) {
|
||||||
if (!mConstantsObserver.mBgAutoRestrictedBucket) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
synchronized (mSettingsLock) {
|
synchronized (mSettingsLock) {
|
||||||
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
|
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
|
||||||
final int userId = UserHandle.getUserId(uid);
|
final int userId = UserHandle.getUserId(uid);
|
||||||
mRestrictionSettings.forEachPackageInUidLocked(uid, (pkgName, level, reason) -> {
|
mRestrictionSettings.forEachPackageInUidLocked(uid, (pkgName, level, reason) -> {
|
||||||
if (level == RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) {
|
if (mConstantsObserver.mBgAutoRestrictedBucket
|
||||||
|
&& level == RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) {
|
||||||
mActiveUids.add(uid, pkgName, () -> appStandbyInternal.restrictApp(pkgName,
|
mActiveUids.add(uid, pkgName, () -> appStandbyInternal.restrictApp(pkgName,
|
||||||
userId, reason & REASON_MAIN_MASK, reason & REASON_SUB_MASK));
|
userId, reason & REASON_MAIN_MASK, reason & REASON_SUB_MASK));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user