Fix hardcode deviceId while inject touch event.
fix touch events not working on some unity game
Thank you for the PR.
This is the alternative mentioned in 40febf4a91f0d9c9d9e1a6390930639b3bf5a70e, so it's probably ok if it fixes the problem for some games.
Could you mention the game(s) that you tested which is (are) fixed by this change?
Thanks for you reply
This is the download link of game i've tested: https://ugame.9game.cn/game/downloadGame?pack.cooperateModelId=235099&pack.id=47093428
This is the download link of game i've tested: https://ugame.9game.cn/game/downloadGame?pack.cooperateModelId=235099&pack.id=47093428
I didn't see any issue in this game with Scrcpy 1.25.
Plus I don't think it will work. In my touch event tester app the device id is still -1

This is because Android set device id of all injected events to -1, unless the event is from InputFilter (accessibility service).
https://cs.android.com/android/platform/superproject/+/master:frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp;l=4197-4206;drc=f3f3a95030a6811f722aced141e15e29e2105d11
// For all injected events, set device id = VIRTUAL_KEYBOARD_ID. The only exception is events
// that have gone through the InputFilter. If the event passed through the InputFilter, assign
// the provided device id. If the InputFilter is accessibility, and it modifies or synthesizes
// the injected event, it is responsible for setting POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY.
// For those events, we will set FLAG_IS_ACCESSIBILITY_EVENT to allow apps to distinguish them
// from events that originate from actual hardware.
int32_t resolvedDeviceId = VIRTUAL_KEYBOARD_ID;
if (policyFlags & POLICY_FLAG_FILTERED) {
resolvedDeviceId = event->getDeviceId();
}
The only method to get real device id is using AOA HID or uinput.
This is the download link of game i've tested: https://ugame.9game.cn/game/downloadGame?pack.cooperateModelId=235099&pack.id=47093428
I didn't see any issue in this game with Scrcpy 1.25.
Plus I don't think it will work. In my touch event tester app the device id is still -1
This is because Android set device id of all injected events to -1, unless the event is from InputFilter (accessibility service).
https://cs.android.com/android/platform/superproject/+/master:frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp;l=4197-4206;drc=f3f3a95030a6811f722aced141e15e29e2105d11
// For all injected events, set device id = VIRTUAL_KEYBOARD_ID. The only exception is events // that have gone through the InputFilter. If the event passed through the InputFilter, assign // the provided device id. If the InputFilter is accessibility, and it modifies or synthesizes // the injected event, it is responsible for setting POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY. // For those events, we will set FLAG_IS_ACCESSIBILITY_EVENT to allow apps to distinguish them // from events that originate from actual hardware. int32_t resolvedDeviceId = VIRTUAL_KEYBOARD_ID; if (policyFlags & POLICY_FLAG_FILTERED) { resolvedDeviceId = event->getDeviceId(); }The only method to get real device id is using AOA HID or uinput.
Thanks.
I ran this app in a android in container,like redroid.I think maybe this is the difference
Is it possible that you provide me touch event tester app apk you metioned?. So i can test in my environment, then i can provide more information
Btw this issue only happend on main scene
@baker915 Did you test that the change proposed in this MR actually works for the game you mentioned?
@baker915 Did you test that the change proposed in this MR actually works for the game you mentioned?
I did,and i tested other apps,everything works fine.
OK so without this MR, it does not work, with this MR, it works? If so, I think this could be merged.
On which Android version?
If so, I think this could be merged.
(But I'm a bit afraid that it could break other use cases…)
Is it possible that you provide me touch event tester app apk you metioned?
Source code: https://github.com/yume-chan/android-motion-event-tester
APK: com.companyname.AndroidApp1.zip
Touch or click in the empty area, it will display properties of received events.
OK so without this MR, it does not work, with this MR, it works? If so, I think this could be merged.
On which Android version?
on Android 10
If so, I think this could be merged.
(But I'm a bit afraid that it could break other use cases…)
Agreed!I'm going to test more devices and read the source code @yume-chan metioned to figure out this MR is necessary.
Is it possible that you provide me touch event tester app apk you metioned?
Source code: https://github.com/yume-chan/android-motion-event-tester
APK: com.companyname.AndroidApp1.zip
Touch or click in the empty area, it will display properties of received events.
Thanks. I will test it in my environment.