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

Commit 9fb37191 authored by Tony Wickham's avatar Tony Wickham Committed by Android Build Coastguard Worker
Browse files

Add onKeyEvent, to support KEYCODE_HOME

- Also added displayId to onBackEvent

Bug: 381339822
Flag: com.android.launcher3.home_button_uses_keycode_home
Test: Manual, OverviewCommandHelperTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:622a882e1f17d108a336ecfd3e4eb7aa9707f1e6)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:0f46d701bb4d6d81106e9a5a0a13e7237d311efa
Merged-In: I55e2ee7adfa40c9d8f289a2b4c76aa12f80e78c3
Change-Id: I55e2ee7adfa40c9d8f289a2b4c76aa12f80e78c3
parent 70ab82c4
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -103,9 +103,10 @@ interface ISystemUiProxy {
    oneway void expandNotificationPanel() = 29;

    /**
     * Notifies SystemUI of a back KeyEvent.
     * Notifies SystemUI of KEYCODE_BACK. If the passed KeyEvent is not null, SystemUI may use it to
     * show a predictive back animation, otherwise it will send a ACTION_DOWN followed by ACTION_UP.
     */
    oneway void onBackEvent(in KeyEvent keyEvent) = 44;
    oneway void onBackEvent(in KeyEvent keyEvent, int displayId) = 44;

    /** Sets home rotation enabled. */
    oneway void setHomeRotationEnabled(boolean enabled) = 45;
@@ -178,5 +179,10 @@ interface ISystemUiProxy {
     */
    oneway void updateContextualEduStats(boolean isTrackpadGesture, String gestureType) = 58;

    // Next id = 59
    /**
     * Notifies SystemUI of a KeyEvent of the specified type (e.g. KEYCODE_BACK, KEYCODE_HOME).
     */
    oneway void onKeyEvent(int keycode, int displayId) = 60;

    // Next id = 61
}
+14 −7
Original line number Diff line number Diff line
@@ -302,18 +302,25 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
        }

        @Override
        public void onBackEvent(@Nullable KeyEvent keyEvent) throws RemoteException {
        public void onBackEvent(@Nullable KeyEvent keyEvent, int displayId) throws RemoteException {
            if (predictiveBackThreeButtonNav() && predictiveBackSwipeEdgeNoneApi()
                    && mBackAnimation != null && keyEvent != null) {
                mBackAnimation.setTriggerBack(!keyEvent.isCanceled());
                mBackAnimation.onBackMotion(/* touchX */ 0, /* touchY */ 0, keyEvent.getAction(),
                        EDGE_NONE);
            } else {
                verifyCallerAndClearCallingIdentityPostMain("onBackPressed", () -> {
                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
                });
                onKeyEvent(KeyEvent.KEYCODE_BACK, displayId);
            }
        }

        @Override
        public void onKeyEvent(int keycode, int displayId) {
            verifyCallerAndClearCallingIdentityPostMain(
                    "onKeyEvent " + KeyEvent.keyCodeToString(keycode) + " displayId=" + displayId,
                    () -> {
                        sendEvent(KeyEvent.ACTION_DOWN, keycode, displayId);
                        sendEvent(KeyEvent.ACTION_UP, keycode, displayId);
                    });
        }

        @Override
@@ -370,14 +377,14 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
                    onTaskbarAutohideSuspend(suspend));
        }

        private boolean sendEvent(int action, int code) {
        private boolean sendEvent(int action, int code, int displayId) {
            long when = SystemClock.uptimeMillis();
            final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */,
                    0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */,
                    KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                    InputDevice.SOURCE_KEYBOARD);

            ev.setDisplayId(mContext.getDisplay().getDisplayId());
            ev.setDisplayId(displayId);
            return InputManagerGlobal.getInstance()
                    .injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
        }