diff --git a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java index 8420695bbdd6e..b2fb93d1e98e1 100644 --- a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java +++ b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java @@ -156,16 +156,16 @@ class ActivityStartInterceptor { mInTask = inTask; mActivityOptions = activityOptions; - if (interceptSuspendedPackageIfNeeded()) { - // Skip the rest of interceptions as the package is suspended by device admin so - // no user action can undo this. - return true; - } if (interceptQuietProfileIfNeeded()) { // If work profile is turned off, skip the work challenge since the profile can only // be unlocked when profile's user is running. return true; } + if (interceptSuspendedPackageIfNeeded()) { + // Skip the rest of interceptions as the package is suspended by device admin so + // no user action can undo this. + return true; + } if (interceptHarmfulAppIfNeeded()) { // If the app has a "harmful app" warning associated with it, we should ask to uninstall // before issuing the work challenge. diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java index 4165052fa675f..d78e3af85e963 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java @@ -167,16 +167,8 @@ public class ActivityStartInterceptorTest { @Test public void testSuspendedPackage() { - mAInfo.applicationInfo.flags = FLAG_SUSPENDED; final String suspendingPackage = "com.test.suspending.package"; - final SuspendDialogInfo dialogInfo = new SuspendDialogInfo.Builder() - .setMessage("Test Message") - .setIcon(0x11110001) - .build(); - when(mPackageManagerInternal.getSuspendingPackage(TEST_PACKAGE_NAME, TEST_USER_ID)) - .thenReturn(suspendingPackage); - when(mPackageManagerInternal.getSuspendedDialogInfo(TEST_PACKAGE_NAME, suspendingPackage, - TEST_USER_ID)).thenReturn(dialogInfo); + final SuspendDialogInfo dialogInfo = suspendPackage(suspendingPackage); // THEN calling intercept returns true assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); @@ -190,6 +182,19 @@ public class ActivityStartInterceptorTest { assertEquals(TEST_USER_ID, mInterceptor.mIntent.getIntExtra(Intent.EXTRA_USER_ID, -1000)); } + private SuspendDialogInfo suspendPackage(String suspendingPackage) { + mAInfo.applicationInfo.flags = FLAG_SUSPENDED; + final SuspendDialogInfo dialogInfo = new SuspendDialogInfo.Builder() + .setMessage("Test Message") + .setIcon(0x11110001) + .build(); + when(mPackageManagerInternal.getSuspendingPackage(TEST_PACKAGE_NAME, TEST_USER_ID)) + .thenReturn(suspendingPackage); + when(mPackageManagerInternal.getSuspendedDialogInfo(TEST_PACKAGE_NAME, suspendingPackage, + TEST_USER_ID)).thenReturn(dialogInfo); + return dialogInfo; + } + @Test public void testInterceptQuietProfile() { // GIVEN that the user the activity is starting as is currently in quiet mode @@ -203,6 +208,20 @@ public class ActivityStartInterceptorTest { .filterEquals(mInterceptor.mIntent)); } + @Test + public void testInterceptQuietProfileWhenPackageSuspended() { + suspendPackage("com.test.suspending.package"); + // GIVEN that the user the activity is starting as is currently in quiet mode + when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true); + + // THEN calling intercept returns true + assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null)); + + // THEN the returned intent is the quiet mode intent + assertTrue(UnlaunchableAppActivity.createInQuietModeDialogIntent(TEST_USER_ID) + .filterEquals(mInterceptor.mIntent)); + } + @Test public void testWorkChallenge() { // GIVEN that the user the activity is starting as is currently locked