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

Unverified Commit a15c5db4 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

SystemUIProxy: Add injectLongPress()

Will be used by Trebuchet.

Change-Id: Ie060333d7166d2dc7406c3994e03f00f7d61aae3
parent 04bd9df5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ interface ISystemUiProxy {
    /** Sets home rotation enabled. */
    oneway void setHomeRotationEnabled(boolean enabled) = 45;

    /** Injects button long press. */
    oneway void injectLongPress(int keyCode) = 46;

    /** Notifies when taskbar status updated */
    oneway void notifyTaskbarStatus(boolean visible, boolean stashed) = 47;

+19 −3
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.Flags;
import android.view.inputmethod.InputMethodManager;
@@ -316,6 +317,17 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
            }
        }

        @Override
        public void injectLongPress(int keyCode) throws RemoteException {
            verifyCallerAndClearCallingIdentityPostMain("longPressInjected", () -> {
                sendEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0);
                mHandler.postDelayed(() -> {
                    sendEvent(KeyEvent.ACTION_DOWN, keyCode, 1, KeyEvent.FLAG_LONG_PRESS);
                    sendEvent(KeyEvent.ACTION_UP, keyCode, 0, KeyEvent.FLAG_CANCELED);
                }, ViewConfiguration.getLongPressTimeout());
            });
        }

        @Override
        public void onImeSwitcherPressed() {
            // TODO(b/204901476) We're intentionally using the default display for now since
@@ -370,11 +382,11 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
                    onTaskbarAutohideSuspend(suspend));
        }

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

            ev.setDisplayId(mContext.getDisplay().getDisplayId());
@@ -382,6 +394,10 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
                    .injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
        }

        private boolean sendEvent(int action, int code) {
            return sendEvent(action, code, 0, 0);
        }

        @Override
        public void onOverviewShown(boolean fromHome) {
            verifyCallerAndClearCallingIdentityPostMain("onOverviewShown", () -> {