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
This commit is contained in:
Miranda Kephart
2021-03-30 13:05:29 -04:00
parent 40b4495f8e
commit 867b29f8d0
2 changed files with 21 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);