diff options
Diffstat (limited to 'services/inputflinger/dispatcher/InputDispatcher.cpp')
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index dd0082c09e..95704f2527 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -3291,6 +3291,8 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec if (hasInjectionPermission(injectorPid, injectorUid)) { policyFlags |= POLICY_FLAG_TRUSTED; } + // Override device ID if the injected event is not an unmodified real input. + bool forceVirtualKeyboardId = !(policyFlags & POLICY_FLAGS_INJECTED_IS_UNCHANGED); std::queue<EventEntry*> injectedEntries; switch (event->getType()) { @@ -3303,11 +3305,14 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec int32_t flags = incomingKey.getFlags(); int32_t keyCode = incomingKey.getKeyCode(); + int32_t deviceId = forceVirtualKeyboardId + ? VIRTUAL_KEYBOARD_ID + : incomingKey.getDeviceId(); int32_t metaState = incomingKey.getMetaState(); - accelerateMetaShortcuts(VIRTUAL_KEYBOARD_ID, action, + accelerateMetaShortcuts(deviceId, action, /*byref*/ keyCode, /*byref*/ metaState); KeyEvent keyEvent; - keyEvent.initialize(incomingKey.getId(), VIRTUAL_KEYBOARD_ID, incomingKey.getSource(), + keyEvent.initialize(incomingKey.getId(), deviceId, incomingKey.getSource(), incomingKey.getDisplayId(), INVALID_HMAC, action, flags, keyCode, incomingKey.getScanCode(), metaState, incomingKey.getRepeatCount(), incomingKey.getDownTime(), incomingKey.getEventTime()); @@ -3328,7 +3333,7 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec mLock.lock(); KeyEntry* injectedEntry = new KeyEntry(incomingKey.getId(), incomingKey.getEventTime(), - VIRTUAL_KEYBOARD_ID, incomingKey.getSource(), + deviceId, incomingKey.getSource(), incomingKey.getDisplayId(), policyFlags, action, flags, keyCode, incomingKey.getScanCode(), metaState, incomingKey.getRepeatCount(), incomingKey.getDownTime()); @@ -3346,6 +3351,9 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec if (!validateMotionEvent(action, actionButton, pointerCount, pointerProperties)) { return INPUT_EVENT_INJECTION_FAILED; } + int32_t deviceId = forceVirtualKeyboardId + ? VIRTUAL_KEYBOARD_ID + : motionEvent->getDeviceId(); if (!(policyFlags & POLICY_FLAG_FILTERED)) { nsecs_t eventTime = motionEvent->getEventTime(); @@ -3361,7 +3369,7 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec const nsecs_t* sampleEventTimes = motionEvent->getSampleEventTimes(); const PointerCoords* samplePointerCoords = motionEvent->getSamplePointerCoords(); MotionEntry* injectedEntry = - new MotionEntry(motionEvent->getId(), *sampleEventTimes, VIRTUAL_KEYBOARD_ID, + new MotionEntry(motionEvent->getId(), *sampleEventTimes, deviceId, motionEvent->getSource(), motionEvent->getDisplayId(), policyFlags, action, actionButton, motionEvent->getFlags(), motionEvent->getMetaState(), motionEvent->getButtonState(), @@ -3378,7 +3386,7 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t injec samplePointerCoords += pointerCount; MotionEntry* nextInjectedEntry = new MotionEntry(motionEvent->getId(), *sampleEventTimes, - VIRTUAL_KEYBOARD_ID, motionEvent->getSource(), + deviceId, motionEvent->getSource(), motionEvent->getDisplayId(), policyFlags, action, actionButton, motionEvent->getFlags(), motionEvent->getMetaState(), motionEvent->getButtonState(), |