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

Commit 03738673 authored by Kweku Adams's avatar Kweku Adams Committed by Automerger Merge Worker
Browse files

Merge "Avoid incorrectly overriding while-in-use reason." into udc-dev am:...

Merge "Avoid incorrectly overriding while-in-use reason." into udc-dev am: 76039598 am: a43597c6 am: 620f397c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23519522



Change-Id: Iad14a8e494858ace7f8d04dd0b256c6a6702442a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5ea715b5 620f397c
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import static android.os.PowerExemptionManager.REASON_INSTR_BACKGROUND_FGS_PERMI
import static android.os.PowerExemptionManager.REASON_OPT_OUT_REQUESTED;
import static android.os.PowerExemptionManager.REASON_OP_ACTIVATE_PLATFORM_VPN;
import static android.os.PowerExemptionManager.REASON_OP_ACTIVATE_VPN;
import static android.os.PowerExemptionManager.REASON_OTHER;
import static android.os.PowerExemptionManager.REASON_PACKAGE_INSTALLER;
import static android.os.PowerExemptionManager.REASON_PROC_STATE_PERSISTENT;
import static android.os.PowerExemptionManager.REASON_PROC_STATE_PERSISTENT_UI;
@@ -85,7 +86,6 @@ import static android.os.PowerExemptionManager.REASON_SYSTEM_MODULE;
import static android.os.PowerExemptionManager.REASON_SYSTEM_UID;
import static android.os.PowerExemptionManager.REASON_TEMP_ALLOWED_WHILE_IN_USE;
import static android.os.PowerExemptionManager.REASON_UID_VISIBLE;
import static android.os.PowerExemptionManager.REASON_UNKNOWN;
import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
import static android.os.PowerExemptionManager.getReasonCodeFromProcState;
import static android.os.PowerExemptionManager.reasonCodeToString;
@@ -7428,33 +7428,34 @@ public final class ActiveServices {
            boolean isStartService) {
        // Check DeviceConfig flag.
        if (!mAm.mConstants.mFlagBackgroundFgsStartRestrictionEnabled) {
            if (!r.mAllowWhileInUsePermissionInFgs) {
                // BGFGS start restrictions are disabled. We're allowing while-in-use permissions.
                // Note REASON_OTHER since there's no other suitable reason.
                r.mAllowWhileInUsePermissionInFgsReason = REASON_OTHER;
            }
            r.mAllowWhileInUsePermissionInFgs = true;
        }

        final @ReasonCode int allowWhileInUse;

        // Either (or both) mAllowWhileInUsePermissionInFgs or mAllowStartForeground is
        // newly allowed?
        boolean newlyAllowed = false;
        if (!r.mAllowWhileInUsePermissionInFgs
                || (r.mAllowStartForeground == REASON_DENIED)) {
            allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked(
            @ReasonCode final int allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked(
                    callingPackage, callingPid, callingUid, r.app, backgroundStartPrivileges,
                    isBindService);
            // We store them to compare the old and new while-in-use logics to each other.
            // (They're not used for any other purposes.)
            if (!r.mAllowWhileInUsePermissionInFgs) {
                r.mAllowWhileInUsePermissionInFgs = (allowWhileInUse != REASON_DENIED);
                r.mAllowWhileInUsePermissionInFgsReason = allowWhileInUse;
            }
            if (r.mAllowStartForeground == REASON_DENIED) {
                r.mAllowStartForeground = shouldAllowFgsStartForegroundWithBindingCheckLocked(
                        allowWhileInUse, callingPackage, callingPid, callingUid, intent, r,
                        backgroundStartPrivileges, isBindService);
            }
        } else {
            allowWhileInUse = REASON_UNKNOWN;
        }
        r.mAllowWhileInUsePermissionInFgsReason = allowWhileInUse;
    }

    /**