Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hardcode deviceId while inject touch event. #3758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

baker915
Copy link

@rom1v
Copy link
Collaborator

rom1v commented Feb 27, 2023

Thank you for the PR.

This is the alternative mentioned in 40febf4, 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?

@baker915
Copy link
Author

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

@yume-chan
Copy link
Contributor

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

image

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.

@baker915
Copy link
Author

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

image

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

@rom1v
Copy link
Collaborator

rom1v commented Feb 28, 2023

@baker915 Did you test that the change proposed in this MR actually works for the game you mentioned?

@baker915
Copy link
Author

@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.

@rom1v
Copy link
Collaborator

rom1v commented Feb 28, 2023

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?

@rom1v
Copy link
Collaborator

rom1v commented Feb 28, 2023

If so, I think this could be merged.

(But I'm a bit afraid that it could break other use cases…)

@yume-chan
Copy link
Contributor

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.

@baker915
Copy link
Author

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

@baker915
Copy link
Author

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.

@baker915
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants