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

Commit f33d3c52 authored by Austin Delgado's avatar Austin Delgado Committed by Android (Google) Code Review
Browse files

Merge "Move keyguard lock callback listener to AuthController" into main

parents 60e010d8 aca4ecdc
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.KeyguardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -182,6 +183,8 @@ public class AuthControllerTest extends SysuiTestCase {
    @Captor
    private ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback> mFaceAuthenticatorsRegisteredCaptor;
    @Captor
    private ArgumentCaptor<KeyguardManager.KeyguardLockedStateListener> mKeyguardLockedStateCaptor;
    @Captor
    private ArgumentCaptor<BiometricStateListener> mBiometricStateCaptor;
    @Captor
    private ArgumentCaptor<Integer> mModalityCaptor;
@@ -192,6 +195,8 @@ public class AuthControllerTest extends SysuiTestCase {
    @Mock
    private VibratorHelper mVibratorHelper;
    @Mock
    private KeyguardManager mKeyguardManager;
    @Mock
    private MSDLPlayer mMSDLPlayer;

    private TestableContext mContextSpy;
@@ -272,6 +277,9 @@ public class AuthControllerTest extends SysuiTestCase {
        mFpAuthenticatorsRegisteredCaptor.getValue().onAllAuthenticatorsRegistered(fpProps);
        mFaceAuthenticatorsRegisteredCaptor.getValue().onAllAuthenticatorsRegistered(faceProps);

        verify(mKeyguardManager).addKeyguardLockedStateListener(any(),
                mKeyguardLockedStateCaptor.capture());

        // Ensures that the operations posted on the handler get executed.
        waitForIdleSync();
    }
@@ -976,6 +984,18 @@ public class AuthControllerTest extends SysuiTestCase {
                eq(null) /* credentialAttestation */);
    }

    @Test
    public void testCloseDialog_whenDeviceLocks() throws Exception {
        showDialog(new int[]{1} /* sensorIds */, false /* credentialAllowed */);

        mKeyguardLockedStateCaptor.getValue().onKeyguardLockedStateChanged(
                true /* isKeyguardLocked */);

        verify(mReceiver).onDialogDismissed(
                eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL),
                eq(null) /* credentialAttestation */);
    }

    @Test
    public void testShowDialog_whenOwnerNotInForeground() {
        PromptInfo promptInfo = createTestPromptInfo();
@@ -1193,7 +1213,7 @@ public class AuthControllerTest extends SysuiTestCase {
                    mWakefulnessLifecycle, mUserManager, mLockPatternUtils, () -> mUdfpsLogger,
                    () -> mLogContextInteractor, () -> mPromptSelectionInteractor,
                    () -> mCredentialViewModel, () -> mPromptViewModel, mInteractionJankMonitor,
                    mHandler, mBackgroundExecutor, mUdfpsUtils, mVibratorHelper,
                    mHandler, mBackgroundExecutor, mUdfpsUtils, mVibratorHelper, mKeyguardManager,
                    mLazyViewCapture, mMSDLPlayer);
        }

+0 −11
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AlertDialog;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
@@ -320,16 +319,6 @@ public class AuthContainerView extends LinearLayout
        mBiometricCallback = new BiometricCallback();
        mMSDLPlayer = msdlPlayer;

        // Listener for when device locks from adaptive auth, dismiss prompt
        getContext().getSystemService(KeyguardManager.class).addKeyguardLockedStateListener(
                getContext().getMainExecutor(),
                isKeyguardLocked -> {
                    if (isKeyguardLocked) {
                        onStartedGoingToSleep();
                    }
                }
        );

        final BiometricModalities biometricModalities = new BiometricModalities(
                Utils.findFirstSensorProperties(fpProps, mConfig.mSensorIds),
                Utils.findFirstSensorProperties(faceProps, mConfig.mSensorIds));
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.systemui.util.ConvenienceExtensionsKt.toKotlinLazy;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityTaskManager;
import android.app.KeyguardManager;
import android.app.TaskStackListener;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -737,6 +738,7 @@ public class AuthController implements
            @Background DelayableExecutor bgExecutor,
            @NonNull UdfpsUtils udfpsUtils,
            @NonNull VibratorHelper vibratorHelper,
            @NonNull KeyguardManager keyguardManager,
            Lazy<ViewCapture> daggerLazyViewCapture,
            @NonNull MSDLPlayer msdlPlayer) {
        mContext = context;
@@ -768,6 +770,15 @@ public class AuthController implements
        mPromptViewModelProvider = promptViewModelProvider;
        mCredentialViewModelProvider = credentialViewModelProvider;

        keyguardManager.addKeyguardLockedStateListener(
                context.getMainExecutor(),
                isKeyguardLocked -> {
                    if (isKeyguardLocked) {
                        closeDialog("Device lock");
                    }
                }
        );

        mOrientationListener = new BiometricDisplayListener(
                context,
                mDisplayManager,