Merge "Migrate AuthContainerView to predictive back" into tm-qpr-dev

This commit is contained in:
Shan Huang
2022-09-17 00:35:11 +00:00
committed by Android (Google) Code Review
2 changed files with 34 additions and 2 deletions

View File

@@ -54,6 +54,8 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
@@ -127,6 +129,7 @@ public class AuthContainerView extends LinearLayout
private final float mTranslationY;
@ContainerState private int mContainerState = STATE_UNKNOWN;
private final Set<Integer> mFailedModalities = new HashSet<Integer>();
private final OnBackInvokedCallback mBackCallback = this::onBackInvoked;
private final @Background DelayableExecutor mBackgroundExecutor;
private int mOrientation;
@@ -362,8 +365,7 @@ public class AuthContainerView extends LinearLayout
return false;
}
if (event.getAction() == KeyEvent.ACTION_UP) {
sendEarlyUserCanceled();
animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED);
onBackInvoked();
}
return true;
});
@@ -373,6 +375,11 @@ public class AuthContainerView extends LinearLayout
requestFocus();
}
private void onBackInvoked() {
sendEarlyUserCanceled();
animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED);
}
void sendEarlyUserCanceled() {
mConfig.mCallback.onSystemEvent(
BiometricConstants.BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL, getRequestId());
@@ -520,6 +527,11 @@ public class AuthContainerView extends LinearLayout
.start();
});
}
OnBackInvokedDispatcher dispatcher = findOnBackInvokedDispatcher();
if (dispatcher != null) {
dispatcher.registerOnBackInvokedCallback(
OnBackInvokedDispatcher.PRIORITY_DEFAULT, mBackCallback);
}
}
private Animator.AnimatorListener getJankListener(View v, String type, long timeout) {
@@ -618,6 +630,10 @@ public class AuthContainerView extends LinearLayout
@Override
public void onDetachedFromWindow() {
OnBackInvokedDispatcher dispatcher = findOnBackInvokedDispatcher();
if (dispatcher != null) {
findOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mBackCallback);
}
super.onDetachedFromWindow();
mWakefulnessLifecycle.removeObserver(this);
}

View File

@@ -29,6 +29,7 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper
import android.testing.ViewUtils
import android.view.KeyEvent
import android.view.View
import android.view.WindowInsets
import android.view.WindowManager
@@ -91,6 +92,21 @@ class AuthContainerViewTest : SysuiTestCase() {
verify(callback).onDialogAnimatedIn(authContainer?.requestId ?: 0L)
}
@Test
fun testDismissesOnBack() {
val container = initializeFingerprintContainer(addToView = true)
assertThat(container.parent).isNotNull()
val root = container.rootView
// Simulate back invocation
container.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK))
container.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK))
waitForIdleSync()
assertThat(container.parent).isNull()
assertThat(root.isAttachedToWindow).isFalse()
}
@Test
fun testIgnoresAnimatedInWhenDismissed() {
val container = initializeFingerprintContainer(addToView = false)