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

Commit 6ab08687 authored by Hui Yu's avatar Hui Yu
Browse files

Document the allowed FGS while-in-use permission cases.

Bug: 277819458
Test: Treehugger.
Change-Id: I0c04f94679f66462e71180c4c96ec247ad0c3285
parent 9d1c9281
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -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;