diff options
| author | 2022-09-17 00:35:11 +0000 | |
|---|---|---|
| committer | 2022-09-17 00:35:11 +0000 | |
| commit | 124782dc033c083fd918d295b5435f9d16d369bc (patch) | |
| tree | ffee6180791cdc9428c4b7272e90e9a87d762c52 | |
| parent | 0a0969af1caa3f7911491a810b84437c77088d39 (diff) | |
| parent | 61f1075626ba914261bb425e3fa8c1fc15b888cc (diff) | |
Merge "Migrate AuthContainerView to predictive back" into tm-qpr-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java | 20 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt | 16 |
2 files changed, 34 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java index 436b756ea0cb..8f5cbb76222f 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java @@ -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); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt index bf3788e4c76a..4a5b23c02e40 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt @@ -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 @@ -92,6 +93,21 @@ class AuthContainerViewTest : SysuiTestCase() { } @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) container.dismissFromSystemServer() |