Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ebc9cd5 authored by Hui Yu's avatar Hui Yu
Browse files

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
parent 209aec58
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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) {
+2 −1
Original line number Diff line number Diff line
@@ -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);
+7 −10
Original line number Diff line number Diff line
@@ -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) {
                    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);
                }