diff options
author | Hui Yu <huiyu@google.com> | 2021-09-16 21:16:12 -0700 |
---|---|---|
committer | Hui Yu <huiyu@google.com> | 2021-09-20 21:14:23 +0000 |
commit | 0ebc9cd55b5c7f04c21dc77b058b5a6bb97941bd (patch) | |
tree | 93e4324f2dfe8454b0d458c9f3e0754e9471b27e | |
parent | 209aec5829988219876b5b3a84a25dd7e02ba70d (diff) |
tempAllowList duration can be updated if an UID is already temp
allowlisted.
Previously when PowerExemptionManager.addToTemporaryAllowList() is
called for a second time before the first time call's duration expires, the
second call does not update ActivityManagerService's
FgsTempAllowList for the new duration. This CL fixes this problem.
Bug: 199801023
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
Change-Id: Ibb8c6f41740a9b7468b50a4cdabe526ae58550ec
3 files changed, 16 insertions, 11 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java index 9eb7bb7149ef..84d05c8b4144 100644 --- a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java +++ b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java @@ -2918,6 +2918,13 @@ public class DeviceIdleController extends SystemService reasonCode, reason).sendToTarget(); } reportTempWhitelistChangedLocked(uid, true); + } else { + // The uid is already temp allowlisted, only need to update AMS for temp allowlist + // duration. + if (mLocalActivityManager != null) { + mLocalActivityManager.updateDeviceIdleTempAllowlist(null, uid, true, + duration, tempAllowListType, reasonCode, reason, callingUid); + } } } if (informWhitelistChanged) { diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java index 0d68df48c316..4e8480c4e113 100644 --- a/core/java/android/app/ActivityManagerInternal.java +++ b/core/java/android/app/ActivityManagerInternal.java @@ -156,6 +156,7 @@ public abstract class ActivityManagerInternal { /** * Update information about which app IDs are on the temp allowlist. * @param appids the updated list of appIds in temp allowlist. + * If null, it is to update only changingUid. * @param changingUid uid to add or remove to temp allowlist. * @param adding true to add to temp allowlist, false to remove from temp allowlist. * @param durationMs when adding is true, the duration to be in temp allowlist. @@ -165,7 +166,7 @@ public abstract class ActivityManagerInternal { * @param callingUid the callingUid that setup this temp allowlist, only valid when param adding * is true. */ - public abstract void updateDeviceIdleTempAllowlist(int[] appids, int changingUid, + public abstract void updateDeviceIdleTempAllowlist(@Nullable int[] appids, int changingUid, boolean adding, long durationMs, @TempAllowListType int type, @ReasonCode int reasonCode, @Nullable String reason, int callingUid); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 953e6e24236f..8f2afdba5251 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -15404,12 +15404,14 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void updateDeviceIdleTempAllowlist(int[] appids, int changingUid, boolean adding, - long durationMs, @TempAllowListType int type, @ReasonCode int reasonCode, - @Nullable String reason, int callingUid) { + public void updateDeviceIdleTempAllowlist(@Nullable int[] appids, int changingUid, + boolean adding, long durationMs, @TempAllowListType int type, + @ReasonCode int reasonCode, @Nullable String reason, int callingUid) { synchronized (ActivityManagerService.this) { synchronized (mProcLock) { - mDeviceIdleTempAllowlist = appids; + if (appids != null) { + mDeviceIdleTempAllowlist = appids; + } if (adding) { if (type == TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED) { // Note, the device idle temp-allowlist are by app-ids, but here @@ -15419,12 +15421,7 @@ public class ActivityManagerService extends IActivityManager.Stub callingUid)); } } else { - // Note in the removing case, we need to remove all the UIDs matching - // the appId, because DeviceIdle's temp-allowlist are based on AppIds, - // not UIDs. - // For eacmple, "cmd deviceidle tempallowlist -r PACKAGE" will - // not only remove this app for user 0, but for all users. - mFgsStartTempAllowList.removeAppId(UserHandle.getAppId(changingUid)); + mFgsStartTempAllowList.removeUid(changingUid); } setAppIdTempAllowlistStateLSP(changingUid, adding); } |