Merge "Fix biometric prompt disappeared by itself after rotate 180 degrees" into tm-qpr-dev

This commit is contained in:
Vincent Wang
2022-11-10 04:08:29 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 11 deletions

View File

@@ -132,8 +132,7 @@ public class AuthContainerView extends LinearLayout
private final OnBackInvokedCallback mBackCallback = this::onBackInvoked; private final OnBackInvokedCallback mBackCallback = this::onBackInvoked;
private final @Background DelayableExecutor mBackgroundExecutor; private final @Background DelayableExecutor mBackgroundExecutor;
private int mOrientation; private boolean mIsOrientationChanged = false;
private boolean mSkipFirstLostFocus = false;
// Non-null only if the dialog is in the act of dismissing and has not sent the reason yet. // Non-null only if the dialog is in the act of dismissing and has not sent the reason yet.
@Nullable @AuthDialogCallback.DismissedReason private Integer mPendingCallbackReason; @Nullable @AuthDialogCallback.DismissedReason private Integer mPendingCallbackReason;
@@ -444,6 +443,7 @@ public class AuthContainerView extends LinearLayout
@Override @Override
public void onOrientationChanged() { public void onOrientationChanged() {
maybeUpdatePositionForUdfps(true /* invalidate */); maybeUpdatePositionForUdfps(true /* invalidate */);
mIsOrientationChanged = true;
} }
@Override @Override
@@ -452,8 +452,8 @@ public class AuthContainerView extends LinearLayout
if (!hasWindowFocus) { if (!hasWindowFocus) {
//it's a workaround to avoid closing BP incorrectly //it's a workaround to avoid closing BP incorrectly
//BP gets a onWindowFocusChanged(false) and then gets a onWindowFocusChanged(true) //BP gets a onWindowFocusChanged(false) and then gets a onWindowFocusChanged(true)
if (mSkipFirstLostFocus) { if (mIsOrientationChanged) {
mSkipFirstLostFocus = false; mIsOrientationChanged = false;
return; return;
} }
Log.v(TAG, "Lost window focus, dismissing the dialog"); Log.v(TAG, "Lost window focus, dismissing the dialog");
@@ -465,9 +465,6 @@ public class AuthContainerView extends LinearLayout
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
//save the first orientation
mOrientation = getResources().getConfiguration().orientation;
mWakefulnessLifecycle.addObserver(this); mWakefulnessLifecycle.addObserver(this);
if (Utils.isBiometricAllowed(mConfig.mPromptInfo)) { if (Utils.isBiometricAllowed(mConfig.mPromptInfo)) {
@@ -623,7 +620,7 @@ public class AuthContainerView extends LinearLayout
} }
if (savedState != null) { if (savedState != null) {
mSkipFirstLostFocus = savedState.getBoolean( mIsOrientationChanged = savedState.getBoolean(
AuthDialog.KEY_BIOMETRIC_ORIENTATION_CHANGED); AuthDialog.KEY_BIOMETRIC_ORIENTATION_CHANGED);
} }
@@ -717,9 +714,7 @@ public class AuthContainerView extends LinearLayout
mBiometricView != null && mCredentialView == null); mBiometricView != null && mCredentialView == null);
outState.putBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING, mCredentialView != null); outState.putBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING, mCredentialView != null);
if (mOrientation != getResources().getConfiguration().orientation) { outState.putBoolean(AuthDialog.KEY_BIOMETRIC_ORIENTATION_CHANGED, mIsOrientationChanged);
outState.putBoolean(AuthDialog.KEY_BIOMETRIC_ORIENTATION_CHANGED, true);
}
if (mBiometricView != null) { if (mBiometricView != null) {
mBiometricView.onSaveState(outState); mBiometricView.onSaveState(outState);

View File

@@ -160,6 +160,25 @@ class AuthContainerViewTest : SysuiTestCase() {
assertThat(container.parent).isNull() assertThat(container.parent).isNull()
} }
@Test
fun testFocusLossAfterRotating() {
val container = initializeFingerprintContainer()
waitForIdleSync()
val requestID = authContainer?.requestId ?: 0L
verify(callback).onDialogAnimatedIn(requestID)
container.onOrientationChanged()
container.onWindowFocusChanged(false)
waitForIdleSync()
verify(callback, never()).onDismissed(
eq(AuthDialogCallback.DISMISSED_USER_CANCELED),
eq<ByteArray?>(null), /* credentialAttestation */
eq(requestID)
)
}
@Test @Test
fun testDismissesOnFocusLoss_hidesKeyboardWhenVisible() { fun testDismissesOnFocusLoss_hidesKeyboardWhenVisible() {
val container = initializeFingerprintContainer( val container = initializeFingerprintContainer(