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

Commit 395b8884 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge changes I4f888f64,I3a0d8de4 into sc-dev

* changes:
  Fully wake screen after udfps auth attempt from AOD
  CancelAodInterrupt in KeyguardUpdateMonitor
parents be3ac1a0 bf3916b1
Loading
Loading
Loading
Loading
+29 −0
Original line number Original line Diff line number Diff line
@@ -66,8 +66,10 @@ import android.os.Handler;
import android.os.IRemoteCallback;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.Trace;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
@@ -241,8 +243,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private final boolean mIsPrimaryUser;
    private final boolean mIsPrimaryUser;
    private final boolean mIsAutomotive;
    private final boolean mIsAutomotive;
    private final AuthController mAuthController;
    private final AuthController mAuthController;
    private final PowerManager mPowerManager;
    private final StatusBarStateController mStatusBarStateController;
    private final StatusBarStateController mStatusBarStateController;
    private int mStatusBarState;
    private int mStatusBarState;
    private boolean mDozing;
    private final StatusBarStateController.StateListener mStatusBarStateControllerListener =
    private final StatusBarStateController.StateListener mStatusBarStateControllerListener =
            new StatusBarStateController.StateListener() {
            new StatusBarStateController.StateListener() {
        @Override
        @Override
@@ -250,6 +254,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            mStatusBarState = newState;
            mStatusBarState = newState;
            updateBiometricListeningState();
            updateBiometricListeningState();
        }
        }

        @Override
        public void onDozingChanged(boolean dozing) {
            mDozing = dozing;
        }
    };
    };


    HashMap<Integer, SimData> mSimDatas = new HashMap<>();
    HashMap<Integer, SimData> mSimDatas = new HashMap<>();
@@ -1294,16 +1303,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab


    private final FingerprintManager.AuthenticationCallback mFingerprintAuthenticationCallback
    private final FingerprintManager.AuthenticationCallback mFingerprintAuthenticationCallback
            = new AuthenticationCallback() {
            = new AuthenticationCallback() {
        private boolean mIsUdfpsRunningWhileDozing;


        @Override
        @Override
        public void onAuthenticationFailed() {
        public void onAuthenticationFailed() {
            handleFingerprintAuthFailed();
            handleFingerprintAuthFailed();
            cancelAodInterrupt();
        }
        }


        @Override
        @Override
        public void onAuthenticationSucceeded(AuthenticationResult result) {
        public void onAuthenticationSucceeded(AuthenticationResult result) {
            Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded");
            Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded");
            handleFingerprintAuthenticated(result.getUserId(), result.isStrongBiometric());
            handleFingerprintAuthenticated(result.getUserId(), result.isStrongBiometric());
            cancelAodInterrupt();
            Trace.endSection();
            Trace.endSection();
        }
        }


@@ -1315,6 +1327,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        @Override
        @Override
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
            handleFingerprintError(errMsgId, errString.toString());
            handleFingerprintError(errMsgId, errString.toString());
            cancelAodInterrupt();
        }
        }


        @Override
        @Override
@@ -1325,12 +1338,25 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        @Override
        @Override
        public void onUdfpsPointerDown(int sensorId) {
        public void onUdfpsPointerDown(int sensorId) {
            Log.d(TAG, "onUdfpsPointerDown, sensorId: " + sensorId);
            Log.d(TAG, "onUdfpsPointerDown, sensorId: " + sensorId);

            if (mDozing) {
                mIsUdfpsRunningWhileDozing = true;
            }
        }
        }


        @Override
        @Override
        public void onUdfpsPointerUp(int sensorId) {
        public void onUdfpsPointerUp(int sensorId) {
            Log.d(TAG, "onUdfpsPointerUp, sensorId: " + sensorId);
            Log.d(TAG, "onUdfpsPointerUp, sensorId: " + sensorId);
        }
        }

        private void cancelAodInterrupt() {
            if (mIsUdfpsRunningWhileDozing) {
                mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
                        "com.android.systemui:AOD_INTERRUPT_END");
            }
            mAuthController.onCancelAodInterrupt();
            mIsUdfpsRunningWhileDozing = false;
        }
    };
    };


    private final FaceManager.FaceDetectionCallback mFaceDetectionCallback
    private final FaceManager.FaceDetectionCallback mFaceDetectionCallback
@@ -1617,6 +1643,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            LockPatternUtils lockPatternUtils,
            LockPatternUtils lockPatternUtils,
            AuthController authController,
            AuthController authController,
            TelephonyListenerManager telephonyListenerManager,
            TelephonyListenerManager telephonyListenerManager,
            PowerManager powerManager,
            FeatureFlags featureFlags) {
            FeatureFlags featureFlags) {
        mContext = context;
        mContext = context;
        mSubscriptionManager = SubscriptionManager.from(context);
        mSubscriptionManager = SubscriptionManager.from(context);
@@ -1629,8 +1656,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mStatusBarStateController = statusBarStateController;
        mStatusBarStateController = statusBarStateController;
        mStatusBarStateController.addCallback(mStatusBarStateControllerListener);
        mStatusBarStateController.addCallback(mStatusBarStateControllerListener);
        mStatusBarState = mStatusBarStateController.getState();
        mStatusBarState = mStatusBarStateController.getState();
        mDozing = mStatusBarStateController.isDozing();
        mLockPatternUtils = lockPatternUtils;
        mLockPatternUtils = lockPatternUtils;
        mAuthController = authController;
        mAuthController = authController;
        mPowerManager = powerManager;
        dumpManager.registerDumpable(getClass().getName(), this);
        dumpManager.registerDumpable(getClass().getName(), this);


        mHandler = new Handler(mainLooper) {
        mHandler = new Handler(mainLooper) {
+11 −3
Original line number Original line Diff line number Diff line
@@ -290,7 +290,7 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
     * called when authentication either succeeds or fails. Failing to cancel the scan will leave
     * called when authentication either succeeds or fails. Failing to cancel the scan will leave
     * the screen in high brightness mode.
     * the screen in high brightness mode.
     */
     */
    private void onCancelAodInterrupt() {
    public void onCancelAodInterrupt() {
        if (mUdfpsController == null) {
        if (mUdfpsController == null) {
            return;
            return;
        }
        }
@@ -397,10 +397,14 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
        showDialog(args, skipAnimation, null /* savedState */);
        showDialog(args, skipAnimation, null /* savedState */);
    }
    }


    /**
     * Only called via BiometricService for the biometric prompt. Will not be called for
     * authentication directly requested through FingerprintManager. For
     * example, KeyguardUpdateMonitor has its own {@link FingerprintManager.AuthenticationCallback}.
     */
    @Override
    @Override
    public void onBiometricAuthenticated() {
    public void onBiometricAuthenticated() {
        mCurrentDialog.onAuthenticationSucceeded();
        mCurrentDialog.onAuthenticationSucceeded();
        onCancelAodInterrupt();
    }
    }


    @Override
    @Override
@@ -428,6 +432,11 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
        }
        }
    }
    }


    /**
     * Only called via BiometricService for the biometric prompt. Will not be called for
     * authentication directly requested through FingerprintManager. For
     * example, KeyguardUpdateMonitor has its own {@link FingerprintManager.AuthenticationCallback}.
     */
    @Override
    @Override
    public void onBiometricError(int modality, int error, int vendorCode) {
    public void onBiometricError(int modality, int error, int vendorCode) {
        if (DEBUG) {
        if (DEBUG) {
@@ -455,7 +464,6 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
            if (DEBUG) Log.d(TAG, "onBiometricError, hard error: " + errorMessage);
            if (DEBUG) Log.d(TAG, "onBiometricError, hard error: " + errorMessage);
            mCurrentDialog.onError(errorMessage);
            mCurrentDialog.onError(errorMessage);
        }
        }
        onCancelAodInterrupt();
    }
    }


    @Override
    @Override
+44 −1
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.IRemoteCallback;
import android.os.IRemoteCallback;
import android.os.PowerManager;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
@@ -164,6 +165,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    @Mock
    @Mock
    private AuthController mAuthController;
    private AuthController mAuthController;
    @Mock
    @Mock
    private PowerManager mPowerManager;
    @Mock
    private TelephonyListenerManager mTelephonyListenerManager;
    private TelephonyListenerManager mTelephonyListenerManager;
    @Mock
    @Mock
    private FeatureFlags mFeatureFlags;
    private FeatureFlags mFeatureFlags;
@@ -517,6 +520,46 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt());
        verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt());
    }
    }


    @Test
    public void testFingerprintCancelAodInterrupt_onAuthenticationFailed() {
        // GIVEN on keyguard and listening for fingerprint authentication
        mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */);
        mTestableLooper.processAllMessages();

        ArgumentCaptor<FingerprintManager.AuthenticationCallback> fingerprintCallbackCaptor =
                ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
        verify(mFingerprintManager).authenticate(any(), any(), fingerprintCallbackCaptor.capture(),
                any(), anyInt(), anyInt());
        FingerprintManager.AuthenticationCallback authCallback =
                fingerprintCallbackCaptor.getValue();

        // WHEN authentication fails
        authCallback.onAuthenticationFailed();

        // THEN aod interrupt is cancelled
        verify(mAuthController).onCancelAodInterrupt();
    }

    @Test
    public void testFingerprintCancelAodInterrupt_onAuthenticationError() {
        // GIVEN on keyguard and listening for fingerprint authentication
        mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */);
        mTestableLooper.processAllMessages();

        ArgumentCaptor<FingerprintManager.AuthenticationCallback> fingerprintCallbackCaptor =
                ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
        verify(mFingerprintManager).authenticate(any(), any(), fingerprintCallbackCaptor.capture(),
                any(), anyInt(), anyInt());
        FingerprintManager.AuthenticationCallback authCallback =
                fingerprintCallbackCaptor.getValue();

        // WHEN authentication errors
        authCallback.onAuthenticationError(0, "");

        // THEN aod interrupt is cancelled
        verify(mAuthController).onCancelAodInterrupt();
    }

    @Test
    @Test
    public void skipsAuthentication_whenStatusBarShadeLocked() {
    public void skipsAuthentication_whenStatusBarShadeLocked() {
        mStatusBarStateListener.onStateChanged(StatusBarState.SHADE_LOCKED);
        mStatusBarStateListener.onStateChanged(StatusBarState.SHADE_LOCKED);
@@ -886,7 +929,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
                    mBroadcastDispatcher, mDumpManager,
                    mBroadcastDispatcher, mDumpManager,
                    mRingerModeTracker, mBackgroundExecutor,
                    mRingerModeTracker, mBackgroundExecutor,
                    mStatusBarStateController, mLockPatternUtils,
                    mStatusBarStateController, mLockPatternUtils,
                    mAuthController, mTelephonyListenerManager, mFeatureFlags);
                    mAuthController, mTelephonyListenerManager, mPowerManager, mFeatureFlags);
            setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
            setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
        }
        }


+0 −14
Original line number Original line Diff line number Diff line
@@ -509,20 +509,6 @@ public class AuthControllerTest extends SysuiTestCase {
        verify(mUdfpsController).onAodInterrupt(eq(pos), eq(pos), eq(majorMinor), eq(majorMinor));
        verify(mUdfpsController).onAodInterrupt(eq(pos), eq(pos), eq(majorMinor), eq(majorMinor));
    }
    }


    @Test
    public void testOnBiometricAuthenticated_OnCancelAodInterrupt() {
        showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
        mAuthController.onBiometricAuthenticated();
        verify(mUdfpsController).onCancelAodInterrupt();
    }

    @Test
    public void testOnBiometricError_OnCancelAodInterrupt() {
        showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
        mAuthController.onBiometricError(0, 0, 0);
        verify(mUdfpsController).onCancelAodInterrupt();
    }

    // Helpers
    // Helpers


    private void showDialog(int[] sensorIds, boolean credentialAllowed) {
    private void showDialog(int[] sensorIds, boolean credentialAllowed) {