From 83e901d8d7c5780113455d1ddacdf3b0c475efd0 Mon Sep 17 00:00:00 2001 From: Shan Huang Date: Mon, 28 Mar 2022 21:25:03 +0000 Subject: [PATCH] Fix back taking multiple swipes. Bug: 226417634 Bug: 226723586 Test: Try swiping back on multiple devices. It seems it's easier to repro on bluechip devices. A good test case for me was to bring up and dismiss all apps folder repeatedly on a p22 device. Change-Id: I4dc5f5ee1f67822206a5e0442f26a52114cf63f0 --- .../src/com/android/wm/shell/back/BackAnimation.java | 9 ++++++++- .../android/wm/shell/back/BackAnimationController.java | 9 +++++---- .../wm/shell/back/BackAnimationControllerTest.java | 6 ++++++ .../navigationbar/gestural/NavigationBarEdgePanel.java | 4 +++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java index 7cf359729ee88..e71a59d267405 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimation.java @@ -16,6 +16,7 @@ package com.android.wm.shell.back; +import android.view.KeyEvent; import android.view.MotionEvent; import android.window.BackEvent; @@ -29,8 +30,14 @@ public interface BackAnimation { /** * Called when a {@link MotionEvent} is generated by a back gesture. + * + * @param event the original {@link MotionEvent} + * @param action the original {@link KeyEvent#getAction()} when the event was dispatched to + * the process. This is forwarded separately because the input pipeline may mutate + * the {#event} action state later. + * @param swipeEdge the edge from which the swipe begins. */ - void onBackMotion(MotionEvent event, @BackEvent.SwipeEdge int swipeEdge); + void onBackMotion(MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge); /** * Sets whether the back gesture is past the trigger threshold or not. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index 08cb252cdf432..93ee3f5378e8f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -138,8 +138,9 @@ public class BackAnimationController implements RemoteCallable onMotionEvent(event, swipeEdge)); + public void onBackMotion( + MotionEvent event, int action, @BackEvent.SwipeEdge int swipeEdge) { + mShellExecutor.execute(() -> onMotionEvent(event, action, swipeEdge)); } @Override @@ -209,13 +210,13 @@ public class BackAnimationController implements RemoteCallable backEventCaptor = ArgumentCaptor.forClass(BackEvent.class); verify(mIOnBackInvokedCallback).onBackProgressed(backEventCaptor.capture()); @@ -166,6 +171,7 @@ public class BackAnimationControllerTest { mController.setTriggerBack(true); // Fake trigger back mController.onMotionEvent( MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0), + MotionEvent.ACTION_UP, BackEvent.EDGE_LEFT); verify(mIOnBackInvokedCallback).onBackInvoked(); } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java index a1258df7a12c1..03652412c129c 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java @@ -480,7 +480,9 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl public void onMotionEvent(MotionEvent event) { if (mBackAnimation != null) { mBackAnimation.onBackMotion( - event, mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT); + event, + event.getActionMasked(), + mIsLeftPanel ? BackEvent.EDGE_LEFT : BackEvent.EDGE_RIGHT); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain();