Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2acdea2e authored by Miranda Kephart's avatar Miranda Kephart Committed by Android (Google) Code Review
Browse files

Merge "Send ACTION_UP event when aborting a key gesture" into sc-dev

parents 45dbeea3 867b29f8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -436,6 +436,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;
+18 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);