From 95e4038bb127fdd41bd3b11373a6d2328facb850 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Wed, 16 Sep 2015 15:53:42 -0700 Subject: [PATCH] Start fingerprint authentication in onStartedGoingToSleep We used to start fingerprint authentication in onFinishedGoingToSleep. This was a UX issue because then users couldn't place the finger on the sensor immediately after pressing the power button because onFinishedGoingToSleep is significantly delayed (around 900ms after pressing the power button). Bug: 23570959 Change-Id: I0bf557ebd10e6a8b033ab98a78aa338bf6538dcc --- .../android/keyguard/KeyguardUpdateMonitor.java | 35 +++++++++++++++++++--- .../keyguard/KeyguardUpdateMonitorCallback.java | 6 ++++ .../systemui/keyguard/KeyguardViewMediator.java | 1 + .../phone/FingerprintUnlockController.java | 26 ++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java index 47d8e283257b..e34286572cb6 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -129,6 +129,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; private static final int MSG_STARTED_WAKING_UP = 319; private static final int MSG_FINISHED_GOING_TO_SLEEP = 320; + private static final int MSG_STARTED_GOING_TO_SLEEP = 321; private static final int MSG_KEYGUARD_BOUNCER_CHANGED = 322; private static final int MSG_FACE_UNLOCK_STATE_CHANGED = 327; private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328; @@ -170,6 +171,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { * until the Keyguard has been dismissed. */ private boolean mFingerprintAlreadyAuthenticated; + private boolean mGoingToSleep; private boolean mBouncer; private boolean mBootCompleted; @@ -249,6 +251,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { case MSG_REPORT_EMERGENCY_CALL_ACTION: handleReportEmergencyCallAction(); break; + case MSG_STARTED_GOING_TO_SLEEP: + handleStartedGoingToSleep(msg.arg1); + break; case MSG_FINISHED_GOING_TO_SLEEP: handleFinishedGoingToSleep(msg.arg1); break; @@ -884,19 +889,32 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } - protected void handleFinishedGoingToSleep(int arg1) { + protected void handleStartedGoingToSleep(int arg1) { clearFingerprintRecognized(); final int count = mCallbacks.size(); for (int i = 0; i < count; i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { - cb.onFinishedGoingToSleep(arg1); + cb.onStartedGoingToSleep(arg1); } } + mGoingToSleep = true; mFingerprintAlreadyAuthenticated = false; updateFingerprintListeningState(); } + protected void handleFinishedGoingToSleep(int arg1) { + mGoingToSleep = false; + final int count = mCallbacks.size(); + for (int i = 0; i < count; i++) { + KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); + if (cb != null) { + cb.onFinishedGoingToSleep(arg1); + } + } + updateFingerprintListeningState(); + } + private void handleScreenTurnedOn() { final int count = mCallbacks.size(); for (int i = 0; i < count; i++) { @@ -1032,8 +1050,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } private boolean shouldListenForFingerprint() { - return (mKeyguardIsVisible || !mDeviceInteractive || mBouncer) && !mSwitchingUser - && !mFingerprintAlreadyAuthenticated && !isFingerprintDisabled(getCurrentUser()); + return (mKeyguardIsVisible || !mDeviceInteractive || mBouncer || mGoingToSleep) + && !mSwitchingUser && !mFingerprintAlreadyAuthenticated + && !isFingerprintDisabled(getCurrentUser()); } private void startListeningForFingerprint() { @@ -1605,6 +1624,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { mHandler.sendEmptyMessage(MSG_STARTED_WAKING_UP); } + public void dispatchStartedGoingToSleep(int why) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0)); + } + public void dispatchFinishedGoingToSleep(int why) { synchronized(this) { mDeviceInteractive = false; @@ -1630,6 +1653,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { return mDeviceInteractive; } + public boolean isGoingToSleep() { + return mGoingToSleep; + } + /** * Find the next SubscriptionId for a SIM in the given state, favoring lower slot numbers first. * @param state diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java index 15ffe9f5ca7e..bd6c51c3b89c 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java @@ -153,6 +153,12 @@ public class KeyguardUpdateMonitorCallback { public void onStartedWakingUp() { } /** + * Called when the device has started going to sleep. + * @param why see {@link #onFinishedGoingToSleep(int)} + */ + public void onStartedGoingToSleep(int why) { } + + /** * Called when the device has finished going to sleep. * @param why either {@link WindowManagerPolicy#OFF_BECAUSE_OF_ADMIN}, * {@link WindowManagerPolicy#OFF_BECAUSE_OF_USER}, or diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 33c59f85f133..eca6b1c4d7ad 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -677,6 +677,7 @@ public class KeyguardViewMediator extends SystemUI { playSounds(true); } } + KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why); notifyStartedGoingToSleep(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/FingerprintUnlockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/FingerprintUnlockController.java index 84082dbe0d12..29129638fc6c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/FingerprintUnlockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/FingerprintUnlockController.java @@ -93,6 +93,8 @@ public class FingerprintUnlockController extends KeyguardUpdateMonitorCallback { private KeyguardViewMediator mKeyguardViewMediator; private ScrimController mScrimController; private PhoneStatusBar mPhoneStatusBar; + private boolean mGoingToSleep; + private int mPendingAuthenticatedUserId = -1; public FingerprintUnlockController(Context context, StatusBarWindowManager statusBarWindowManager, @@ -161,6 +163,10 @@ public class FingerprintUnlockController extends KeyguardUpdateMonitorCallback { @Override public void onFingerprintAuthenticated(int userId) { + if (mUpdateMonitor.isGoingToSleep()) { + mPendingAuthenticatedUserId = userId; + return; + } boolean wasDeviceInteractive = mUpdateMonitor.isDeviceInteractive(); mMode = calculateMode(); if (!wasDeviceInteractive) { @@ -205,6 +211,26 @@ public class FingerprintUnlockController extends KeyguardUpdateMonitorCallback { mPhoneStatusBar.notifyFpAuthModeChanged(); } + @Override + public void onStartedGoingToSleep(int why) { + mPendingAuthenticatedUserId = -1; + } + + @Override + public void onFinishedGoingToSleep(int why) { + if (mPendingAuthenticatedUserId != -1) { + + // Post this to make sure it's executed after the device is fully locked. + mHandler.post(new Runnable() { + @Override + public void run() { + onFingerprintAuthenticated(mPendingAuthenticatedUserId); + } + }); + } + mPendingAuthenticatedUserId = -1; + } + public int getMode() { return mMode; } -- 2.11.0