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

Commit e8fe0394 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Only aware activities should start in direct boot

Bug: 256956043
Test: atest WmTests:ActivityStartInterceptorTest
Change-Id: Ibec4eec5ca6c0bf35805846f772b90416dcce446
parent 6b5d003f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -399,8 +399,11 @@ class ActivityStartInterceptor {
     * @return The intercepting intent if needed.
     */
    private Intent interceptWithConfirmCredentialsIfNeeded(ActivityInfo aInfo, int userId) {
        if (!mService.mAmInternal.shouldConfirmCredentials(userId)) {
            return null;
        }
        if ((aInfo.flags & ActivityInfo.FLAG_SHOW_WHEN_LOCKED) != 0
                || !mService.mAmInternal.shouldConfirmCredentials(userId)) {
                && (mUserManager.isUserUnlocked(userId) || aInfo.directBootAware)) {
            return null;
        }
        final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
+51 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
@@ -275,10 +276,59 @@ public class ActivityStartInterceptorTest {
        // THEN calling intercept returns true
        mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null);

        // THEN the returned intent is the quiet mode intent
        // THEN the returned intent is the confirm credentials intent
        assertTrue(CONFIRM_CREDENTIALS_INTENT.filterEquals(mInterceptor.mIntent));
    }

    @Test
    public void testLockedManagedProfileShowWhenLocked() {
        Intent originalIntent = new Intent();
        // GIVEN that the user is locked but its storage is unlocked and the activity has
        // showWhenLocked flag
        when(mAmInternal.shouldConfirmCredentials(TEST_USER_ID)).thenReturn(true);
        when(mUserManager.isUserUnlocked(eq(TEST_USER_ID))).thenReturn(true);
        mAInfo.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED;

        // THEN calling intercept returns true
        mInterceptor.intercept(originalIntent, null, mAInfo, null, null, null, 0, 0, null);

        // THEN the returned intent is original intent
        assertSame(originalIntent, mInterceptor.mIntent);
    }

    @Test
    public void testLockedManagedProfileShowWhenLockedEncryptedStorage() {
        // GIVEN that the user storage is locked, activity has showWhenLocked flag but no
        // directBootAware flag
        when(mAmInternal.shouldConfirmCredentials(TEST_USER_ID)).thenReturn(true);
        when(mUserManager.isUserUnlocked(eq(TEST_USER_ID))).thenReturn(false);
        mAInfo.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
        mAInfo.directBootAware = false;

        // THEN calling intercept returns true
        mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null);

        // THEN the returned intent is the confirm credentials intent
        assertTrue(CONFIRM_CREDENTIALS_INTENT.filterEquals(mInterceptor.mIntent));
    }

    @Test
    public void testLockedManagedProfileShowWhenLockedEncryptedStorageDirectBootAware() {
        Intent originalIntent = new Intent();
        // GIVEN that the user storage is locked, activity has showWhenLocked flag and
        // directBootAware flag
        when(mAmInternal.shouldConfirmCredentials(TEST_USER_ID)).thenReturn(true);
        when(mUserManager.isUserUnlocked(eq(TEST_USER_ID))).thenReturn(false);
        mAInfo.flags |= ActivityInfo.FLAG_SHOW_WHEN_LOCKED;
        mAInfo.directBootAware = true;

        // THEN calling intercept returns true
        mInterceptor.intercept(originalIntent, null, mAInfo, null, null, null, 0, 0, null);

        // THEN the returned intent is original intent
        assertSame(originalIntent, mInterceptor.mIntent);
    }

    @Test
    public void testHarmfulAppWarning() throws RemoteException {
        // GIVEN the package we're about to launch has a harmful app warning set