From 30607ce49dbb59383cb7ddac3fa78e77bad46d8f Mon Sep 17 00:00:00 2001 From: Kevin Chyn Date: Fri, 11 Jan 2019 18:00:45 -0800 Subject: [PATCH 1/2] Keep task stack listener around as long as dialog is showing Fixes: 122473133 Test: Fail authentication 5 times, then press home button immediately Dialog is dismissed immediately Change-Id: I41d3726d107319586943e72f79dc6a95148b7a00 --- .../server/biometrics/BiometricService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java index 24f2ef9ef9796..41fedc5fab45b 100644 --- a/services/core/java/com/android/server/biometrics/BiometricService.java +++ b/services/core/java/com/android/server/biometrics/BiometricService.java @@ -351,10 +351,7 @@ public class BiometricService extends SystemService { if (!runningTasks.isEmpty()) { final String topPackage = runningTasks.get(0).topActivity.getPackageName(); if (mCurrentAuthSession != null - && !topPackage.contentEquals(mCurrentAuthSession.mOpPackageName) - && mCurrentAuthSession.mState != STATE_AUTH_STARTED) { - // We only care about this state, since Service will - // cancel any client that's still in STATE_AUTH_STARTED + && !topPackage.contentEquals(mCurrentAuthSession.mOpPackageName)) { mStatusBarService.hideBiometricDialog(); mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener); mCurrentAuthSession.mClientReceiver.onError( @@ -464,8 +461,9 @@ public class BiometricService extends SystemService { if (mCurrentAuthSession != null && mCurrentAuthSession.containsCookie(cookie)) { if (mCurrentAuthSession.mState == STATE_AUTH_STARTED) { mStatusBarService.onBiometricError(message); - mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener); if (error == BiometricConstants.BIOMETRIC_ERROR_CANCELED) { + mActivityTaskManager.unregisterTaskStackListener( + mTaskStackListener); mCurrentAuthSession.mClientReceiver.onError(error, message); mCurrentAuthSession.mState = STATE_AUTH_IDLE; mCurrentAuthSession = null; @@ -475,6 +473,8 @@ public class BiometricService extends SystemService { mHandler.postDelayed(() -> { try { if (mCurrentAuthSession != null) { + mActivityTaskManager.unregisterTaskStackListener( + mTaskStackListener); mCurrentAuthSession.mClientReceiver.onError(error, message); mCurrentAuthSession.mState = STATE_AUTH_IDLE; @@ -543,6 +543,11 @@ public class BiometricService extends SystemService { @Override public void onDialogDismissed(int reason) throws RemoteException { + if (mCurrentAuthSession == null) { + Slog.e(TAG, "onDialogDismissed: " + reason + ", auth session null"); + return; + } + if (reason != BiometricPrompt.DISMISSED_REASON_POSITIVE) { // Positive button is used by passive modalities as a "confirm" button, // do not send to client From c9744aceb2a23178bf38a39d64531530b9777704 Mon Sep 17 00:00:00 2001 From: Kevin Chyn Date: Fri, 11 Jan 2019 18:49:50 -0800 Subject: [PATCH 2/2] Only show try again button for fingerprint Change-Id: Idb985b00808f0aeb82f9f67515becf7bf017d7a1 Fixes: 122748115 Test: Try again button is only shown on fingerprint devices --- .../biometrics/BiometricDialogView.java | 23 +++---------------- .../systemui/biometrics/FaceDialogView.java | 22 +++++++++++++++++- .../biometrics/FingerprintDialogView.java | 8 +++++++ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/BiometricDialogView.java b/packages/SystemUI/src/com/android/systemui/biometrics/BiometricDialogView.java index b8c69c8003c40..c92767763cb44 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/BiometricDialogView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/BiometricDialogView.java @@ -77,7 +77,6 @@ public abstract class BiometricDialogView extends LinearLayout { private final DevicePolicyManager mDevicePolicyManager; private final float mAnimationTranslationOffset; private final int mErrorColor; - private final int mTextColor; private final float mDialogWidth; private final DialogViewCallback mCallback; @@ -92,6 +91,8 @@ public abstract class BiometricDialogView extends LinearLayout { protected final Button mNegativeButton; protected final Button mTryAgainButton; + protected final int mTextColor; + private Bundle mBundle; private int mLastState; @@ -108,6 +109,7 @@ public abstract class BiometricDialogView extends LinearLayout { protected abstract boolean shouldAnimateForTransition(int oldState, int newState); protected abstract int getDelayAfterAuthenticatedDurationMs(); protected abstract boolean shouldGrayAreaDismissDialog(); + protected abstract void handleClearMessage(boolean requireTryAgain); private final Runnable mShowAnimationRunnable = new Runnable() { @Override @@ -421,20 +423,6 @@ public abstract class BiometricDialogView extends LinearLayout { return mLayout; } - // Clears the temporary message and shows the help message. If requireTryAgain is true, - // we will start the authenticating state again. - private void handleClearMessage(boolean requireTryAgain) { - if (!requireTryAgain) { - updateState(STATE_AUTHENTICATING); - mErrorText.setText(getHintStringResourceId()); - mErrorText.setTextColor(mTextColor); - mErrorText.setVisibility(View.VISIBLE); - } else { - updateState(STATE_IDLE); - mErrorText.setVisibility(View.INVISIBLE); - } - } - // Shows an error/help message private void showTemporaryMessage(String message, boolean requireTryAgain) { mHandler.removeMessages(MSG_CLEAR_MESSAGE); @@ -475,11 +463,6 @@ public abstract class BiometricDialogView extends LinearLayout { } public void showTryAgainButton(boolean show) { - if (show) { - mTryAgainButton.setVisibility(View.VISIBLE); - } else { - mTryAgainButton.setVisibility(View.GONE); - } } public void restoreState(Bundle bundle) { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/FaceDialogView.java b/packages/SystemUI/src/com/android/systemui/biometrics/FaceDialogView.java index 359cb047c84de..9fba44b768630 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/FaceDialogView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/FaceDialogView.java @@ -210,6 +210,22 @@ public class FaceDialogView extends BiometricDialogView { bundle.putInt(KEY_DIALOG_SIZE, mSize); } + + @Override + protected void handleClearMessage(boolean requireTryAgain) { + // Clears the temporary message and shows the help message. If requireTryAgain is true, + // we will start the authenticating state again. + if (!requireTryAgain) { + updateState(STATE_AUTHENTICATING); + mErrorText.setText(getHintStringResourceId()); + mErrorText.setTextColor(mTextColor); + mErrorText.setVisibility(View.VISIBLE); + } else { + updateState(STATE_IDLE); + mErrorText.setVisibility(View.INVISIBLE); + } + } + @Override public void restoreState(Bundle bundle) { super.restoreState(bundle); @@ -271,7 +287,11 @@ public class FaceDialogView extends BiometricDialogView { // of the elements in here. updateSize(SIZE_BIG); } else { - super.showTryAgainButton(show); + if (show) { + mTryAgainButton.setVisibility(View.VISIBLE); + } else { + mTryAgainButton.setVisibility(View.GONE); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/FingerprintDialogView.java b/packages/SystemUI/src/com/android/systemui/biometrics/FingerprintDialogView.java index d63836b2207e9..c9b30ba3ce8db 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/FingerprintDialogView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/FingerprintDialogView.java @@ -32,6 +32,14 @@ public class FingerprintDialogView extends BiometricDialogView { DialogViewCallback callback) { super(context, callback); } + + @Override + protected void handleClearMessage(boolean requireTryAgain) { + updateState(STATE_AUTHENTICATING); + mErrorText.setText(getHintStringResourceId()); + mErrorText.setTextColor(mTextColor); + } + @Override protected int getHintStringResourceId() { return R.string.fingerprint_dialog_touch_sensor;