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

Commit 6195f0a6 authored by Thomas Leu's avatar Thomas Leu Committed by Automerger Merge Worker
Browse files

Merge "Add the DPAD device flag when injecting accessibility DPAD events."...

Merge "Add the DPAD device flag when injecting accessibility DPAD events." into udc-dev am: 08fdc875

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22290228



Change-Id: Ie1bd77aa8cc136486c1a77c1323538e4331a7cc9
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7aa02088 08fdc875
Loading
Loading
Loading
Loading
+21 −14
Original line number Original line Diff line number Diff line
@@ -266,11 +266,11 @@ public class SystemActionPerformer {
            // actions.
            // actions.
            switch (actionId) {
            switch (actionId) {
                case AccessibilityService.GLOBAL_ACTION_BACK: {
                case AccessibilityService.GLOBAL_ACTION_BACK: {
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_BACK);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_BACK, InputDevice.SOURCE_KEYBOARD);
                    return true;
                    return true;
                }
                }
                case AccessibilityService.GLOBAL_ACTION_HOME: {
                case AccessibilityService.GLOBAL_ACTION_HOME: {
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME, InputDevice.SOURCE_KEYBOARD);
                    return true;
                    return true;
                }
                }
                case AccessibilityService.GLOBAL_ACTION_RECENTS:
                case AccessibilityService.GLOBAL_ACTION_RECENTS:
@@ -292,22 +292,28 @@ public class SystemActionPerformer {
                case AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT:
                case AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT:
                    return takeScreenshot();
                    return takeScreenshot();
                case AccessibilityService.GLOBAL_ACTION_KEYCODE_HEADSETHOOK:
                case AccessibilityService.GLOBAL_ACTION_KEYCODE_HEADSETHOOK:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HEADSETHOOK);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HEADSETHOOK,
                            InputDevice.SOURCE_KEYBOARD);
                    return true;
                    return true;
                case AccessibilityService.GLOBAL_ACTION_DPAD_UP:
                case AccessibilityService.GLOBAL_ACTION_DPAD_UP:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP,
                            InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD);
                    return true;
                    return true;
                case AccessibilityService.GLOBAL_ACTION_DPAD_DOWN:
                case AccessibilityService.GLOBAL_ACTION_DPAD_DOWN:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN,
                            InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD);
                    return true;
                    return true;
                case AccessibilityService.GLOBAL_ACTION_DPAD_LEFT:
                case AccessibilityService.GLOBAL_ACTION_DPAD_LEFT:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT,
                            InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD);
                    return true;
                    return true;
                case AccessibilityService.GLOBAL_ACTION_DPAD_RIGHT:
                case AccessibilityService.GLOBAL_ACTION_DPAD_RIGHT:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT,
                            InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD);
                    return true;
                    return true;
                case AccessibilityService.GLOBAL_ACTION_DPAD_CENTER:
                case AccessibilityService.GLOBAL_ACTION_DPAD_CENTER:
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER,
                            InputDevice.SOURCE_KEYBOARD | InputDevice.SOURCE_DPAD);
                    return true;
                    return true;
                default:
                default:
                    Slog.e(TAG, "Invalid action id: " + actionId);
                    Slog.e(TAG, "Invalid action id: " + actionId);
@@ -318,23 +324,24 @@ public class SystemActionPerformer {
        }
        }
    }
    }


    private void sendDownAndUpKeyEvents(int keyCode) {
    private void sendDownAndUpKeyEvents(int keyCode, int source) {
        final long token = Binder.clearCallingIdentity();
        final long token = Binder.clearCallingIdentity();
        try {
        try {
            // Inject down.
            // Inject down.
            final long downTime = SystemClock.uptimeMillis();
            final long downTime = SystemClock.uptimeMillis();
            sendKeyEventIdentityCleared(keyCode, KeyEvent.ACTION_DOWN, downTime, downTime);
            sendKeyEventIdentityCleared(keyCode, KeyEvent.ACTION_DOWN, downTime, downTime, source);
            sendKeyEventIdentityCleared(
            sendKeyEventIdentityCleared(
                    keyCode, KeyEvent.ACTION_UP, downTime, SystemClock.uptimeMillis());
                    keyCode, KeyEvent.ACTION_UP, downTime, SystemClock.uptimeMillis(), source);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(token);
            Binder.restoreCallingIdentity(token);
        }
        }
    }
    }


    private void sendKeyEventIdentityCleared(int keyCode, int action, long downTime, long time) {
    private void sendKeyEventIdentityCleared(int keyCode, int action, long downTime, long time,
            int source) {
        KeyEvent event = KeyEvent.obtain(downTime, time, action, keyCode, 0, 0,
        KeyEvent event = KeyEvent.obtain(downTime, time, action, keyCode, 0, 0,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM,
                InputDevice.SOURCE_KEYBOARD, null);
                source, null);
        mContext.getSystemService(InputManager.class)
        mContext.getSystemService(InputManager.class)
                .injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
                .injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
        event.recycle();
        event.recycle();