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

Commit 56730cd6 authored by Achim Thesmann's avatar Achim Thesmann
Browse files

Use same logic to check BAL permission

There are currently 2 different implementation to check the
START_ACTIVITIES_FROM_BACKGROUND permission. Reuse the same logic.

Test: atest BackgroundActivityStartControllerExemptionTests
Bug: 324950030
Change-Id: I4ad4ec7ef58c661926f6505638dec845e06a5011
parent 96808aa1
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -853,8 +853,7 @@ public class BackgroundActivityStartController {
        }

        // don't abort if the callingUid has START_ACTIVITIES_FROM_BACKGROUND permission
        if (ActivityTaskManagerService.checkPermission(START_ACTIVITIES_FROM_BACKGROUND,
                callingPid, callingUid) == PERMISSION_GRANTED) {
        if (hasBalPermission(callingUid, callingPid)) {
            return new BalVerdict(BAL_ALLOW_PERMISSION,
                    /*background*/ true,
                    "START_ACTIVITIES_FROM_BACKGROUND permission granted");
@@ -919,9 +918,7 @@ public class BackgroundActivityStartController {
    BalVerdict checkBackgroundActivityStartAllowedBySender(BalState state) {

        if (state.isPendingIntentBalAllowedByPermission()
                && ActivityManager.checkComponentPermission(
                android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
                state.mRealCallingUid, NO_PROCESS_UID, true) == PackageManager.PERMISSION_GRANTED) {
                && hasBalPermission(state.mRealCallingUid, state.mRealCallingPid)) {
            return new BalVerdict(BAL_ALLOW_PERMISSION,
                    /*background*/ false,
                    "realCallingUid has BAL permission.");
@@ -980,6 +977,11 @@ public class BackgroundActivityStartController {
        return BalVerdict.BLOCK;
    }

    @VisibleForTesting boolean hasBalPermission(int uid, int pid) {
        return ActivityTaskManagerService.checkPermission(START_ACTIVITIES_FROM_BACKGROUND,
                pid, uid) == PERMISSION_GRANTED;
    }

    /**
     * Check if the app allows BAL.
     * <p>