Repository navigation
Closed
Labels
Description
Environment
- OS: Windows 10 x64
- scrcpy version: 1.23
- installation method: Windows release
- device model: Google Pixel 6
- Android version: Android 13 preview
Describe the bug
Inject input event is failed in Android 13, both failed in Mouse event and keyboard event.
adb logcat :
04-14 13:13:10.557 1478 1685 W InputDispatcher: Dropping injected event: Injected event targeted at uid 0 would be dispatched to window '380b0b2 NotificationShade' owned by uid 10225.
04-14 13:13:21.929 1478 1685 W InputDispatcher: Dropping injected touch event: Injected event targeted at uid 0 would be dispatched to window '97ea2a com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity' owned by uid 10205.
04-14 13:13:23.640 1478 1685 W InputDispatcher: Dropping injected touch event: Injected event targeted at uid 0 would be dispatched to window '97ea2a com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity' owned by uid 10205.
04-14 13:14:00.544 1478 1685 W InputDispatcher: Dropping injected event: Injected event targeted at uid 0 would be dispatched to window '380b0b2 NotificationShade' owned by uid 10225.
04-14 13:14:04.911 1478 1685 W InputDispatcher: Dropping injected touch event: Injected event targeted at uid 0 would be dispatched to window '380b0b2 NotificationShade' owned by uid 10225.
04-14 13:14:04.951 1478 1685 I InputDispatcher: Dropping event because there is no touched window on display 0 to receive it: MotionEvent(deviceId=-1, eventTime=2756762000000, source=TOUCHSCREEN, displayId=0, action=MOVE, actionButton=0x00000000, flags=0x00000000, metaState=0x00000000, buttonState=0x00000000, classification=NONE, edgeFlags=0x00000000, xPrecision=1.0, yPrecision=1.0, xCursorPosition=nan, yCursorPosition=nan, pointers=[0: (1100.0, 2226.0)]), policyFlags=0x6b000000
04-14 13:14:04.951 1478 1685 W InputDispatcher: Asynchronous input event injection failed.
04-14 13:14:04.959 1478 1685 I InputDispatcher: Dropping event because there is no touched window on display 0 to receive it: MotionEvent(deviceId=-1, eventTime=2756770000000, source=TOUCHSCREEN, displayId=0, action=MOVE, actionButton=0x00000000, flags=0x00000000, metaState=0x00000000, buttonState=0x00000000, classification=NONE, edgeFlags=0x00000000, xPrecision=1.0, yPrecision=1.0, xCursorPosition=nan, yCursorPosition=nan, pointers=[0: (1100.0, 2207.0)]), policyFlags=0x6b000000
04-14 13:14:04.959 1478 1685 W InputDispatcher: Asynchronous input event injection failed.
Activity
rom1v commentedon Apr 14, 2022
Oh, that's pretty bad. Thank you for the report.
Does
adb shell input keyevent A(to injecta) work?DerekWuYD commentedon Apr 14, 2022
I try following input command are working.
and the ADB toybox version of my device is
0.8.6-androidThank
rom1v commentedon Apr 14, 2022
That's good news, this means that we could find a solution to make it work (once the sources of Android 13 are published).
rom1v commentedon Apr 14, 2022
Could you please test with synchronous event injection:
diff
Here is a binary (to replace in your v1.23 release):
scrcpy-serversha256:4df13f82362063f59b6294439e9d72dcbc1690e4e6a6c6dd7a74a716981b1d00DerekWuYD commentedon Apr 14, 2022
I try it it's still failed, Input event not working.
But the
power keyseem work fine.Here is the error response
And I found the
InputManagerfrom android code base it seem no big change inadb shell inputcommand.https://cs.android.com/android/platform/superproject/+/android-t-preview-2:frameworks/base/services/core/java/com/android/server/input/InputShellCommand.java;l=138;bpv=0;bpt=1
rom1v commentedon Apr 14, 2022
Since 9a7d7dbfb55e19e56f932c8820448514837f39c6 (already in Android 12), this code run in the input manager service, so it does not run with shell permissions anymore (like scrcpy does). They probably added more checks to reject such injections from "outside".
I'm a bit afraid that the only solution will be to call
input, so we will be limited to what the shell commandinputprovides, so we could not inject all events (mouse press, mouse release, etc.) as needed 😱DerekWuYD commentedon Apr 14, 2022
Oh! it's bad news, How about get the permission in
app_process, is it possiable?Or if install an app into devices to obtain input event permission? like
vysordid.rom1v commentedon Apr 14, 2022
I think vysor use the same mechanism as scrcpy to inject input events. Could you test it on your Android 13?
DerekWuYD commentedon Apr 14, 2022
I found vysor can run well on Android 13. Maybe is a good news, but I can't figure out how it obtain the permission.
You are right vysor also use
app_process, even I force uninstall the vysor app on phone the remote control still running.rom1v commentedon Apr 14, 2022
Yes, this is good news 👍 Thank you.
Could you please post the logcat warnings when you try to inject key events with scrcpy? (the logs in the first post seems to refer to motion events only)
rom1v commentedon Apr 14, 2022
Could you also test with this change, please?
scrcpy-serversha256:8be19ab6778a5377cf9b2eb5ff61ce025d088794ceb6efd6cf8984c4777b254fDerekWuYD commentedon Apr 14, 2022
I try the new version server file. It's still not working.
But there no error message in
.\scrcpy.exe stdout streamI attach logcat here, this log is capture when I run your last version server file.
logcat.txt
DerekWuYD commentedon Apr 14, 2022
I have changed
android 13 developer preview 2 ROM buildto check this issue, it work good in scrcpy v1.23.I feel confused, maybe this issue is cause by early stage weekly build,
I will keep tracking this issue.
Thank a lot for your effort.
DerekWuYD commentedon Apr 15, 2022
I found that
adb monkeyis work good in this Android 13 devices with June, 2022 android system secuirty update.But it's failed by using
scrcpy v1.23ADB command
this is the code I tested using C#
By this method injectEvent is working.
5 remaining items
rom1v commentedon Apr 15, 2022
Awesome! Thank you very much. 🎉
I'll merge that soon, then publish a new version (1.24).
I expect many people to report the issue next year, with always the same answer "upgrade to scrcpy >= 1.24" 😄 (similar to #2129 for Android 12)
rom1v commentedon Apr 15, 2022
Could you please also test other scrcpy features (shortcuts, copy-paste,
--show-touches, etc.)? (to fix them before making a new release if necessary)DerekWuYD commentedon Apr 16, 2022
I have check major function of scrcpy, there look's good.
Thank you ^^
Adapt event injection to Android 13
Adapt event injection to Android 13
Adapt event injection to Android 13
itech-apps commentedon Jan 12, 2023
Hello @rom1v, i have a question about this part of code, when i try run in under Android 13 to injectEvent, i receive this exception : java.lang.SecurityException: Injecting input events requires the caller (or the source of the instrumentation, if any) to have the INJECT_EVENTS permission.
I'm curious how do you bypass this exception in Android 13 ?
Thanks in advance for your reply
rom1v commentedon Jan 12, 2023
@itech-apps How do you execute the code? Is it from an Android app?
itech-apps commentedon Jan 13, 2023
Thanks for your reply @rom1v.
Yes, i have take the part of InputManager as done (by method reflection ..)
and then run it on my test app :


as a result i get this exception in Android 13 (Pixel 6) :
itech-apps commentedon Jan 13, 2023
Here is the ROM version : TP1A.220624.021
[ro.build.characteristics]: [nosdcard]
[ro.build.date]: [Wed Jul 27 20:42:17 UTC 2022]
[ro.build.date.utc]: [1658954537]
[ro.build.description]: [oriole-user 13 TP1A.220624.021 8877034 release-keys]
[ro.build.display.id]: [TP1A.220624.021]
[ro.build.expect.baseband]: [g5123b-102852-220720-B-8851166]
[ro.build.expect.bootloader]: [slider-1.2-8739948]
[ro.build.fingerprint]: [google/oriole/oriole:13/TP1A.220624.021/8877034:user/release-keys]
[ro.build.flavor]: [oriole-user]
[ro.build.host]: [abfarm-release-rbe-64-00076]
[ro.build.id]: [TP1A.220624.021]
[ro.build.product]: [oriole]
[ro.build.system_root_image]: [false]
[ro.build.tags]: [release-keys]
[ro.build.type]: [user]
[ro.build.user]: [android-build]
rom1v commentedon Jan 13, 2023
You can't run this from an Android app (you could not get the permission).
That's the reason why scrcpy is not an Android app, but a java program executed from
shell: https://blog.rom1v.com/2018/03/introducing-scrcpy/#run-a-java-main-on-androiditech-apps commentedon Jan 13, 2023
Ah, oki thank you @rom1v.
So i will wait the i response of this reported issue on google about these undocumented behavior : https://issuetracker.google.com/issues/244970399
(i already posted two comments on it).
Thanks again for your time and have a good day
Merge tag 'v1.24'
Adapt event injection to Android 13