Intercept quiet profile prior to suspended package

SuspendedAppActivity was intercepted while starting activity of a
suspended package, but it failed due to user had turned off the
belonging profile.

We should examine quiet profile before intercepting suspended app.

Bug: 144842610
Test: ActivityStartInterceptorTest
Change-Id: Ib6656198d1ae44de7252c99c3cf49ee50374d8b6
This commit is contained in:
Louis Chang
2019-11-26 13:03:10 +08:00
parent 3ef13e045c
commit 97f743f333
2 changed files with 33 additions and 14 deletions

View File

@@ -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.

View File

@@ -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