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

Commit aca4ecdc authored by Austin Delgado's avatar Austin Delgado
Browse files

Move keyguard lock callback listener to AuthController

Test: AuthControllerTest AuthContainerViewTest
Bug: 377614813
Flag: EXEMPT bugfix

Change-Id: I27b00006bfe1877a44ad59d65094b3f5300a5186
parent 02bf9ff7
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;
@@ -181,6 +182,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;
@@ -191,6 +194,8 @@ public class AuthControllerTest extends SysuiTestCase {
    @Mock
    private VibratorHelper mVibratorHelper;
    @Mock
    private KeyguardManager mKeyguardManager;
    @Mock
    private MSDLPlayer mMSDLPlayer;

    private TestableContext mContextSpy;
@@ -271,6 +276,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();
    }
@@ -975,6 +983,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();
@@ -1191,7 +1211,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;
@@ -316,16 +315,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
@@ -26,6 +26,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;
@@ -732,6 +733,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;
@@ -762,6 +764,15 @@ public class AuthController implements
        mPromptViewModelProvider = promptViewModelProvider;
        mCredentialViewModelProvider = credentialViewModelProvider;

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

        mOrientationListener = new BiometricDisplayListener(
                context,
                mDisplayManager,