diff options
| author | 2023-04-11 22:58:12 +0000 | |
|---|---|---|
| committer | 2023-04-12 16:32:15 +0000 | |
| commit | 6ab08687c51ba05e6226daef5bad834cbf9cbcbc (patch) | |
| tree | 6e70e878e078e85394368a6363cef8b7f0fd83c7 | |
| parent | 9d1c928132a08ffbb18341fd91563e1d7e944e56 (diff) | |
Document the allowed FGS while-in-use permission cases.
Bug: 277819458
Test: Treehugger.
Change-Id: I0c04f94679f66462e71180c4c96ec247ad0c3285
| -rw-r--r-- | services/core/java/com/android/server/am/ActiveServices.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 7b618b11bd45..c1638db9422f 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -7407,14 +7407,17 @@ public final class ActiveServices { final int uidState = mAm.getUidStateLocked(callingUid); if (ret == REASON_DENIED) { - // Is the calling UID at PROCESS_STATE_TOP or above? + // Allow FGS while-in-use if the caller's process state is PROCESS_STATE_PERSISTENT, + // PROCESS_STATE_PERSISTENT_UI or PROCESS_STATE_TOP. if (uidState <= PROCESS_STATE_TOP) { ret = getReasonCodeFromProcState(uidState); } } if (ret == REASON_DENIED) { - // Does the calling UID have any visible activity? + // Allow FGS while-in-use if the caller has visible activity. + // Here we directly check ActivityTaskManagerService, instead of checking + // PendingStartActivityUids in ActivityManagerService, which gives the same result. final boolean isCallingUidVisible = mAm.mAtmInternal.isUidForeground(callingUid); if (isCallingUidVisible) { ret = REASON_UID_VISIBLE; @@ -7422,7 +7425,8 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { - // Is the allow activity background start flag on? + // Allow FGS while-in-use if the background activity start flag is on. Because + // activity start can lead to FGS start in TOP state and obtain while-in-use. if (backgroundStartPrivileges.allowsBackgroundActivityStarts()) { ret = REASON_START_ACTIVITY_FLAG; } @@ -7431,6 +7435,7 @@ public final class ActiveServices { if (ret == REASON_DENIED) { boolean isCallerSystem = false; final int callingAppId = UserHandle.getAppId(callingUid); + // Allow FGS while-in-use for a list of special UIDs. switch (callingAppId) { case ROOT_UID: case SYSTEM_UID: @@ -7449,6 +7454,10 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { + // Allow FGS while-in-use if the WindowManager allows background activity start. + // This is mainly to get the 10 seconds grace period if any activity in the caller has + // either started or finished very recently. The binding flag + // BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS is also allowed by the check here. final Integer allowedType = mAm.mProcessList.searchEachLruProcessesLOSP(false, pr -> { if (pr.uid == callingUid) { if (pr.getWindowProcessController().areBackgroundFgsStartsAllowed()) { @@ -7463,6 +7472,12 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { + // Allow FGS while-in-use if the caller UID is in ActivityManagerService's + // mFgsWhileInUseTempAllowList. This is a temp allowlist to allow FGS while-in-use. It + // is used when MediaSessionService's bluetooth button or play/resume/stop commands are + // issued. The typical temp allowlist duration is 10 seconds. + // This temp allowlist mechanism can also be called by other system_server internal + // components such as Telephone/VOIP if they want to start a FGS and get while-in-use. if (mAm.mInternal.isTempAllowlistedForFgsWhileInUse(callingUid)) { return REASON_TEMP_ALLOWED_WHILE_IN_USE; } @@ -7470,6 +7485,8 @@ public final class ActiveServices { if (ret == REASON_DENIED) { if (targetProcess != null) { + // Allow FGS while-in-use if the caller of the instrumentation has + // START_ACTIVITIES_FROM_BACKGROUND permission. ActiveInstrumentation instr = targetProcess.getActiveInstrumentation(); if (instr != null && instr.mHasBackgroundActivityStartsPermission) { ret = REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION; @@ -7478,6 +7495,9 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { + // Allow FGS while-in-use if the caller has START_ACTIVITIES_FROM_BACKGROUND + // permission, because starting an activity can lead to starting FGS from the TOP state + // and obtain while-in-use. if (mAm.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid) == PERMISSION_GRANTED) { ret = REASON_BACKGROUND_ACTIVITY_PERMISSION; @@ -7485,6 +7505,8 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { + // Allow FGS while-in-use if the caller is in the while-in-use allowlist. Right now + // AttentionService and SystemCaptionsService packageName are in this allowlist. if (verifyPackage(callingPackage, callingUid)) { final boolean isAllowedPackage = mAllowListWhileInUsePermissionInFgs.contains(callingPackage); @@ -7499,7 +7521,7 @@ public final class ActiveServices { } if (ret == REASON_DENIED) { - // Is the calling UID a device owner app? + // Allow FGS while-in-use if the caller is the device owner. final boolean isDeviceOwner = mAm.mInternal.isDeviceOwner(callingUid); if (isDeviceOwner) { ret = REASON_DEVICE_OWNER; |