From 70beba044e665053db7a3c75cb15e66a98054904 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Fri, 12 Apr 2024 08:34:45 +0000 Subject: [PATCH] Attemp handle back key when enable onBackInvoked callback. Unlike normal activity, recents would receive key event from input consumer instead of go throught ViewRootImpl, so when adapt to predictive back API, recents should try to handle back key when receive key event. Flag: ACONFIG launcher.enable_predictive_back_gesture ENABLED Bug: 333428882 Test: switch to 3-button mode, go to live tile, verify back key can dismiss recents. Change-Id: Ibe6d9b2475a0b89b12dc4b34251a2a92926b5a4e --- quickstep/AndroidManifest.xml | 1 + .../uioverrides/QuickstepLauncher.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml index e75812a173..2d2fb97358 100644 --- a/quickstep/AndroidManifest.xml +++ b/quickstep/AndroidManifest.xml @@ -83,6 +83,7 @@ android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize" android:resizeableActivity="true" android:resumeWhilePausing="true" + android:enableOnBackInvokedCallback="false" android:taskAffinity=""/> diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 6c05bfe752..9125254697 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -87,6 +87,7 @@ import android.os.Trace; import android.util.AttributeSet; import android.view.Display; import android.view.HapticFeedbackConstants; +import android.view.KeyEvent; import android.view.View; import android.widget.AnalogClock; import android.widget.TextClock; @@ -839,6 +840,28 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer } } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + return tryHandleBackKey(event) || super.dispatchKeyEvent(event); + } + + // TODO (b/267248420) Once the recents input consumer has been removed, there is no need to + // handle the back key specially. + private boolean tryHandleBackKey(KeyEvent event) { + // Unlike normal activity, recents can receive input event from InputConsumer, so the input + // event won't go through ViewRootImpl#InputStage#onProcess. + // So when receive back key, try to do the same check thing in + // ViewRootImpl#NativePreImeInputStage#onProcess + if (!Utilities.ATLEAST_U || !enablePredictiveBackGesture() + || event.getKeyCode() != KeyEvent.KEYCODE_BACK + || event.getAction() != KeyEvent.ACTION_UP || event.isCanceled()) { + return false; + } + + getOnBackAnimationCallback().onBackInvoked(); + return true; + } + @Override protected void registerBackDispatcher() { if (!enablePredictiveBackGesture()) {