diff options
4 files changed, 35 insertions, 32 deletions
diff --git a/services/core/java/com/android/server/am/PendingIntentController.java b/services/core/java/com/android/server/am/PendingIntentController.java index f3361203c44a..3b0147cb665d 100644 --- a/services/core/java/com/android/server/am/PendingIntentController.java +++ b/services/core/java/com/android/server/am/PendingIntentController.java @@ -149,21 +149,6 @@ public class PendingIntentController { ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED); } - if (opts != null && opts.isPendingIntentBackgroundActivityLaunchAllowedByPermission()) { - Slog.wtf(TAG, - "Resetting option pendingIntentBackgroundActivityLaunchAllowedByPermission" - + " which is set by the pending intent creator (" - + packageName - + ") because this option is meant for the pending intent sender"); - if (CompatChanges.isChangeEnabled(PendingIntent.PENDING_INTENT_OPTIONS_CHECK, - callingUid)) { - throw new IllegalArgumentException( - "pendingIntentBackgroundActivityLaunchAllowedByPermission " - + "can not be set by creator of a PendingIntent"); - } - opts.setPendingIntentBackgroundActivityLaunchAllowedByPermission(false); - } - final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; final boolean cancelCurrent = (flags & PendingIntent.FLAG_CANCEL_CURRENT) != 0; final boolean updateCurrent = (flags & PendingIntent.FLAG_UPDATE_CURRENT) != 0; diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java index 54024e92f95f..02c8a4999f4d 100644 --- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java +++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java @@ -20,9 +20,11 @@ import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static android.app.ActivityOptions.BackgroundActivityStartMode; import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED; +import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS; import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_COMPAT; import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_DENIED; import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; +import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE; @@ -226,6 +228,21 @@ public class BackgroundActivityStartController { }; } + static String balStartModeToString(@BackgroundActivityStartMode int startMode) { + return switch (startMode) { + case MODE_BACKGROUND_ACTIVITY_START_ALLOWED -> "MODE_BACKGROUND_ACTIVITY_START_ALLOWED"; + case MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED -> + "MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED"; + case MODE_BACKGROUND_ACTIVITY_START_COMPAT -> "MODE_BACKGROUND_ACTIVITY_START_COMPAT"; + case MODE_BACKGROUND_ACTIVITY_START_DENIED -> "MODE_BACKGROUND_ACTIVITY_START_DENIED"; + case MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS -> + "MODE_BACKGROUND_ACTIVITY_START_ALWAYS"; + case MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE -> + "MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE"; + default -> "MODE_BACKGROUND_ACTIVITY_START_ALLOWED(" + startMode + ")"; + }; + } + @GuardedBy("mService.mGlobalLock") private final HashMap<Integer, FinishedActivityEntry> mTaskIdToFinishedActivity = new HashMap<>(); @@ -464,10 +481,6 @@ public class BackgroundActivityStartController { this.mResultForRealCaller = resultForRealCaller; } - public boolean isPendingIntentBalAllowedByPermission() { - return PendingIntentRecord.isPendingIntentBalAllowedByPermission(mCheckedOptions); - } - public boolean callerExplicitOptInOrAutoOptIn() { if (mAutoOptInCaller) { return !callerExplicitOptOut(); @@ -528,6 +541,8 @@ public class BackgroundActivityStartController { sb.append("; balAllowedByPiCreatorWithHardening: ") .append(mBalAllowedByPiCreatorWithHardening); sb.append("; resultIfPiCreatorAllowsBal: ").append(mResultForCaller); + sb.append("; callerStartMode: ").append(balStartModeToString( + mCheckedOptions.getPendingIntentBackgroundActivityStartMode())); sb.append("; hasRealCaller: ").append(hasRealCaller()); sb.append("; isCallForResult: ").append(mIsCallForResult); sb.append("; isPendingIntent: ").append(isPendingIntent()); @@ -553,6 +568,8 @@ public class BackgroundActivityStartController { } sb.append("; balAllowedByPiSender: ").append(mBalAllowedByPiSender); sb.append("; resultIfPiSenderAllowsBal: ").append(mResultForRealCaller); + sb.append("; realCallerStartMode: ").append(balStartModeToString( + mCheckedOptions.getPendingIntentCreatorBackgroundActivityStartMode())); } // features sb.append("; balImproveRealCallerVisibilityCheck: ") @@ -949,7 +966,8 @@ public class BackgroundActivityStartController { } } - if (state.isPendingIntentBalAllowedByPermission() + if (state.mCheckedOptions.getPendingIntentBackgroundActivityStartMode() + == MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS && hasBalPermission(state.mRealCallingUid, state.mRealCallingPid)) { return new BalVerdict(BAL_ALLOW_PERMISSION, /*background*/ false, diff --git a/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerExemptionTests.java b/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerExemptionTests.java index 366e519fb063..6e488188eb87 100644 --- a/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerExemptionTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerExemptionTests.java @@ -16,6 +16,9 @@ package com.android.server.wm; +import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED; +import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS; + import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW; import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_ALLOWLISTED_COMPONENT; import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_FOREGROUND; @@ -23,7 +26,6 @@ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_ import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_SAW_PERMISSION; import static com.android.server.wm.BackgroundActivityStartController.BAL_ALLOW_VISIBLE_WINDOW; -import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.ArgumentMatchers.anyInt; @@ -58,7 +60,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.quality.Strictness; import java.lang.reflect.Field; @@ -134,9 +135,8 @@ public class BackgroundActivityStartControllerExemptionTests { ActivityOptions mCheckedOptions = ActivityOptions.makeBasic() .setPendingIntentCreatorBackgroundActivityStartMode( - ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED) - .setPendingIntentBackgroundActivityStartMode( - ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + MODE_BACKGROUND_ACTIVITY_START_ALLOWED) + .setPendingIntentBackgroundActivityStartMode(MODE_BACKGROUND_ACTIVITY_START_ALLOWED); class TestableBackgroundActivityStartController extends BackgroundActivityStartController { private Set<Pair<Integer, Integer>> mBalPermissionUidPidPairs = new HashSet<>(); @@ -175,7 +175,6 @@ public class BackgroundActivityStartControllerExemptionTests { when(mService.getAppOpsManager()).thenReturn(mAppOpsManager); setViaReflection(mService, "mProcessMap", mProcessMap); - //Mockito.when(mSupervisor.getBackgroundActivityLaunchController()).thenReturn(mController); setViaReflection(mSupervisor, "mRecentTasks", mRecentTasks); mController = new TestableBackgroundActivityStartController(mService, mSupervisor); @@ -397,7 +396,7 @@ public class BackgroundActivityStartControllerExemptionTests { // setup state WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); - WindowProcessController otherProcess = Mockito.mock(WindowProcessController.class); + WindowProcessController otherProcess = mock(WindowProcessController.class); mProcessMap.put(callingPid, mCallerApp); mProcessMap.put(REGULAR_PID_1_1, otherProcess); setViaReflection(mService, "mProcessMap", mProcessMap); @@ -516,14 +515,13 @@ public class BackgroundActivityStartControllerExemptionTests { BackgroundStartPrivileges forcedBalByPiSender = BackgroundStartPrivileges.NONE; Intent intent = TEST_INTENT; ActivityOptions checkedOptions = mCheckedOptions; - checkedOptions.setPendingIntentBackgroundActivityLaunchAllowedByPermission(true); + checkedOptions.setPendingIntentBackgroundActivityStartMode( + MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS); BackgroundActivityStartController.BalState balState = mController.new BalState(callingUid, callingPid, callingPackage, realCallingUid, realCallingPid, null, originatingPendingIntent, forcedBalByPiSender, mResultRecord, intent, checkedOptions); - assertThat(balState.isPendingIntentBalAllowedByPermission()).isTrue(); - // call BalVerdict realCallerVerdict = mController.checkBackgroundActivityStartAllowedBySender( balState); diff --git a/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerTests.java index f110c69b57f5..e364264fc74f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/BackgroundActivityStartControllerTests.java @@ -547,7 +547,7 @@ public class BackgroundActivityStartControllerTests { assertThat(balState.callerExplicitOptInOrOut()).isFalse(); assertThat(balState.realCallerExplicitOptInOrAutoOptIn()).isTrue(); assertThat(balState.realCallerExplicitOptInOrOut()).isFalse(); - assertThat(balState.toString()).contains( + assertThat(balState.toString()).startsWith( "[callingPackage: package.app1; " + "callingPackageTargetSdk: -1; " + "callingUid: 10001; " @@ -563,6 +563,7 @@ public class BackgroundActivityStartControllerTests { + "balAllowedByPiCreator: BSP.ALLOW_BAL; " + "balAllowedByPiCreatorWithHardening: BSP.ALLOW_BAL; " + "resultIfPiCreatorAllowsBal: null; " + + "callerStartMode: MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; " + "hasRealCaller: true; " + "isCallForResult: false; " + "isPendingIntent: false; " @@ -646,7 +647,7 @@ public class BackgroundActivityStartControllerTests { assertThat(balState.callerExplicitOptInOrOut()).isFalse(); assertThat(balState.realCallerExplicitOptInOrAutoOptIn()).isFalse(); assertThat(balState.realCallerExplicitOptInOrOut()).isFalse(); - assertThat(balState.toString()).contains( + assertThat(balState.toString()).startsWith( "[callingPackage: package.app1; " + "callingPackageTargetSdk: -1; " + "callingUid: 10001; " @@ -662,6 +663,7 @@ public class BackgroundActivityStartControllerTests { + "balAllowedByPiCreator: BSP.NONE; " + "balAllowedByPiCreatorWithHardening: BSP.NONE; " + "resultIfPiCreatorAllowsBal: null; " + + "callerStartMode: MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; " + "hasRealCaller: true; " + "isCallForResult: false; " + "isPendingIntent: true; " |