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

Commit 9aac6450 authored by Achim Thesmann's avatar Achim Thesmann
Browse files

Split hasRealCaller from isPendingIntent

Having a real caller does not imply starting a PendingIntent (but every
PendingIntent has a real caller). This CL splits the logic for these two
cases to reduce unnecessary logs and to prevent overblocking when we
start to enforce BAL hardening.

Test: atest BackgroundActivityLaunchTest
Bug: 306059525
Change-Id: I01ef73b41799fc25196d586f5d9f5f8303221571
parent 1d6c6f99
Loading
Loading
Loading
Loading
+28 −11
Original line number Diff line number Diff line
@@ -256,13 +256,24 @@ public class BackgroundActivityStartController {
            mOriginatingPendingIntent = originatingPendingIntent;
            mIntent = intent;
            mRealCallingPackage = mService.getPackageNameIfUnique(realCallingUid, realCallingPid);
            mBalAllowedByPiSender =
                    PendingIntentRecord.getBackgroundStartPrivilegesAllowedByCaller(checkedOptions,
                            realCallingUid, mRealCallingPackage);
            if (originatingPendingIntent == null) {
                // grant creator BAL privileges unless explicitly opted out
                mBalAllowedByPiCreator =
                        checkedOptions.getPendingIntentCreatorBackgroundActivityStartMode()
                                == ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_DENIED
                                ? BackgroundStartPrivileges.NONE
                                : BackgroundStartPrivileges.ALLOW_BAL;
            } else {
                // for PendingIntents we restrict creator BAL based on target_sdk
                mBalAllowedByPiCreator =
                        checkedOptions.getPendingIntentCreatorBackgroundActivityStartMode()
                                == ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_DENIED
                            ? BackgroundStartPrivileges.NONE : BackgroundStartPrivileges.ALLOW_BAL;
                                ? BackgroundStartPrivileges.NONE
                                : BackgroundStartPrivileges.ALLOW_BAL;
            }
            mBalAllowedByPiSender =
                    PendingIntentRecord.getBackgroundStartPrivilegesAllowedByCaller(
                            checkedOptions, realCallingUid, mRealCallingPackage);
            mAppSwitchState = mService.getBalAppSwitchesState();
            mCallingUidProcState = mService.mActiveUids.getUidState(callingUid);
            mIsCallingUidPersistentSystemProcess =
@@ -306,10 +317,14 @@ public class BackgroundActivityStartController {
            return name + "[debugOnly]";
        }

        private boolean isPendingIntent() {
        private boolean hasRealCaller() {
            return mRealCallingUid != NO_PROCESS_UID;
        }

        private boolean isPendingIntent() {
            return mOriginatingPendingIntent != null;
        }

        private String dump(BalVerdict resultIfPiCreatorAllowsBal) {
            Preconditions.checkState(!isPendingIntent());
            return dump(resultIfPiCreatorAllowsBal, null);
@@ -334,7 +349,9 @@ public class BackgroundActivityStartController {
            sb.append("; isCallingUidPersistentSystemProcess: ")
                    .append(mIsCallingUidPersistentSystemProcess);
            sb.append("; balAllowedByPiCreator: ").append(mBalAllowedByPiCreator);
            if (isPendingIntent()) {
            sb.append("; hasRealCaller: ").append(hasRealCaller());
            sb.append("; isPendingIntent: ").append(isPendingIntent());
            if (hasRealCaller()) {
                sb.append("; balAllowedByPiSender: ").append(mBalAllowedByPiSender);
                sb.append("; realCallingPackage: ")
                        .append(getDebugPackageName(mRealCallingPackage, mRealCallingUid));
@@ -351,13 +368,13 @@ public class BackgroundActivityStartController {
            sb.append("; mForcedBalByPiSender: ").append(mForcedBalByPiSender);
            sb.append("; intent: ").append(mIntent);
            sb.append("; callerApp: ").append(mCallerApp);
            if (isPendingIntent()) {
            if (hasRealCaller()) {
                sb.append("; realCallerApp: ").append(mRealCallerApp);
            }
            if (mCallerApp != null) {
                sb.append("; inVisibleTask: ").append(mCallerApp.hasActivityInVisibleTask());
            }
            if (isPendingIntent()) {
            if (hasRealCaller()) {
                if (mRealCallerApp != null) {
                    sb.append("; realInVisibleTask: ")
                            .append(mRealCallerApp.hasActivityInVisibleTask());
@@ -484,7 +501,7 @@ public class BackgroundActivityStartController {

        BalVerdict resultForCaller = checkBackgroundActivityStartAllowedByCaller(state);

        if (!state.isPendingIntent()) {
        if (!state.hasRealCaller()) {
            if (resultForCaller.allows()) {
                if (DEBUG_ACTIVITY_STARTS) {
                    Slog.d(TAG, "Background activity start allowed. "