From 867b29f8d004511513438f32e364c3e47588e9eb Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Tue, 30 Mar 2021 13:05:29 -0400 Subject: [PATCH] Send ACTION_UP event when aborting a key gesture Currently, if a KeyButtonView gesture is aborted, no further events are sent. This means that there is an ACTION_DOWN event with no corresponding ACTION_UP, which causes problems with the KeyCombinationManager. Specifically, if the home button is long-pressed, it registers the initial DOWN event but never gets the UP event, preventing it from registering keychords correctly (since it looks for keychords including the home button) until either the home button is tapped (which does send the ACTION_UP event) or the phone is rebooted. While in this state, screenshots cannot be successfully recognized and taken with the keychord. Bug: 181178545 Fix: 181178545 Test: manual -- repro case: in 2 or 3-button mode, long-press the home button to trigger the assistant. Without tapping the home button again, attempt to take a screenshot with power+vol_down. At HEAD, this fails; after this change, it works correctly. Added tests to KeyButtonViewTest.java to verify behavior on abortCurrentGesture: atest KeyButtonViewTest Change-Id: Ib82b855a3eefeb6baf09ea7ac107e0f8ce46ee1c --- .../navigationbar/buttons/KeyButtonView.java | 3 +++ .../buttons/KeyButtonViewTest.java | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/KeyButtonView.java index f0e4cce299eef..9e2bac785938e 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/KeyButtonView.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/KeyButtonView.java @@ -434,6 +434,9 @@ public class KeyButtonView extends ImageView implements ButtonInterface { @Override public void abortCurrentGesture() { Log.d("b/63783866", "KeyButtonView.abortCurrentGesture"); + if (mCode != KeyEvent.KEYCODE_UNKNOWN) { + sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED); + } setPressed(false); mRipple.abortDelayedRipple(); mGestureAborted = true; diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/buttons/KeyButtonViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/buttons/KeyButtonViewTest.java index fa29fd4f94ae3..853684ab8dfcf 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/buttons/KeyButtonViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/buttons/KeyButtonViewTest.java @@ -24,6 +24,7 @@ import static android.view.KeyEvent.KEYCODE_0; import static android.view.KeyEvent.KEYCODE_APP_SWITCH; import static android.view.KeyEvent.KEYCODE_BACK; import static android.view.KeyEvent.KEYCODE_HOME; +import static android.view.KeyEvent.KEYCODE_UNKNOWN; import static com.android.systemui.navigationbar.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_BACK_BUTTON_LONGPRESS; import static com.android.systemui.navigationbar.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_BACK_BUTTON_TAP; @@ -88,7 +89,7 @@ public class KeyButtonViewTest extends SysuiTestCase { } @Test - public void testLogOverviewPress() { + public void testLogOverviewPress() { checkmetrics(KEYCODE_APP_SWITCH, ACTION_UP, 0, NAVBAR_OVERVIEW_BUTTON_TAP); } @@ -134,6 +135,22 @@ public class KeyButtonViewTest extends SysuiTestCase { checkmetrics(KEYCODE_0, ACTION_UP, 0, null); } + @Test + public void testEventInjectedOnAbortGesture() { + mKeyButtonView.setCode(KEYCODE_HOME); + mKeyButtonView.abortCurrentGesture(); + verify(mInputManager, times(1)) + .injectInputEvent(any(KeyEvent.class), any(Integer.class)); + } + + @Test + public void testNoEventInjectedOnAbortUnknownGesture() { + mKeyButtonView.setCode(KEYCODE_UNKNOWN); + mKeyButtonView.abortCurrentGesture(); + verify(mInputManager, never()) + .injectInputEvent(any(KeyEvent.class), any(Integer.class)); + } + private void checkmetrics(int code, int action, int flag, KeyButtonView.NavBarButtonEvent expected) { mKeyButtonView.setCode(code);