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

Using scrcpy with Show Touches switch (-t, --show-touches) throws exceptions #2788

Closed
2 tasks done
sphars opened this issue Nov 15, 2021 · 9 comments · Fixed by #2802
Closed
2 tasks done

Using scrcpy with Show Touches switch (-t, --show-touches) throws exceptions #2788

sphars opened this issue Nov 15, 2021 · 9 comments · Fixed by #2802

Comments

@sphars
Copy link

sphars commented Nov 15, 2021

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Windows 10
  • scrcpy version: 1.20
  • installation method: Windows release
  • device model: Pixel 4a
  • Android version: 12

Describe the bug
On my recently updated to Android 12 Pixel 4a, the switch to show touches (-t, --show-touches) now throws an error. Also tried manually changing the setting in phone developer options and then running scrcpy with the switch. Still throws the same error (though touches are shown).

This issue was present in the last version of scrcpy as well as the current version (1.20). Also worked fine IIRC on Android 11.

Looks like it might be a similar issue to #2671

Console output:

D:\Programs\scrcpy-win64>scrcpy -t
INFO: scrcpy 1.20 <https://github.com/Genymobile/scrcpy>
D:\Programs\scrcpy-win64\scrcpy-server: 1 file pushed, 0 skipped. 69.5 MB/s (37139 bytes in 0.001s)
[server] INFO: Device: Google Pixel 4a (Android 12)
[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.genymobile.scrcpy.wrappers.ContentProvider.call(ContentProvider.java:108)
        at com.genymobile.scrcpy.wrappers.ContentProvider.getValue(ContentProvider.java:149)
        at com.genymobile.scrcpy.wrappers.ContentProvider.getAndPutValue(ContentProvider.java:165)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:32)
        at com.genymobile.scrcpy.Server.main(Server.java:255)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355)
Caused by: java.lang.SecurityException: Calling uid: 2000 doesn't match source uid: 0
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
        at android.os.Parcel.createException(Parcel.java:2409)
        at android.os.Parcel.readException(Parcel.java:2392)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
        at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
        ... 8 more
Caused by: android.os.RemoteException: Remote stack trace:
        at android.content.AttributionSource.enforceCallingUid(AttributionSource.java:239)
        at android.content.AttributionSource.<init>(AttributionSource.java:158)
        at android.content.AttributionSource$1.createFromParcel(AttributionSource.java:454)
        at android.content.AttributionSource$1.createFromParcel(AttributionSource.java:446)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:289)

[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.genymobile.scrcpy.wrappers.ContentProvider.call(ContentProvider.java:108)
        at com.genymobile.scrcpy.wrappers.ContentProvider.putValue(ContentProvider.java:161)
        at com.genymobile.scrcpy.wrappers.ContentProvider.getAndPutValue(ContentProvider.java:167)
        at com.genymobile.scrcpy.Server.scrcpy(Server.java:32)
        at com.genymobile.scrcpy.Server.main(Server.java:255)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:355)
Caused by: java.lang.SecurityException: Calling uid: 2000 doesn't match source uid: 0
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
        at android.os.Parcel.createException(Parcel.java:2409)
        at android.os.Parcel.readException(Parcel.java:2392)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
        at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
        ... 8 more
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336
@sphars sphars changed the title Using scrcpy with Show Touches switch (-t. --show-touches) throws exceptions Using scrcpy with Show Touches switch (-t, --show-touches) throws exceptions Nov 15, 2021
@rom1v
Copy link
Collaborator

rom1v commented Nov 15, 2021

Caused by: java.lang.SecurityException: Calling uid: 2000 doesn't match source uid: 0

Is your device rooted? Try adb unroot to test.

@sphars
Copy link
Author

sphars commented Nov 15, 2021

My device is not rooted. adb unroot shows

D:\Programs\scrcpy-win64>adb unroot
adbd not running as root

@rom1v
Copy link
Collaborator

rom1v commented Nov 15, 2021

If you enable it manually like this:

adb shell settings put system show_touches 1

Does it work?

@sphars
Copy link
Author

sphars commented Nov 15, 2021

Yep, running that command does enable the show touches setting in developer options. And of course shows touches

@rom1v
Copy link
Collaborator

rom1v commented Nov 15, 2021

OK, it seems there is a change in Android 12 (like #2671).

I will try on a Pixel 4a with Android 12 as soon as I can.

@rom1v
Copy link
Collaborator

rom1v commented Nov 15, 2021

OK, I can reproduce on a Pixel 4a 🎉

I think I will need to use another way to set system settings, maybe by just calling the executable settings with arguments from the server process.

I already did the latter some time ago (before implementing the ContentProvider wrapper), but on old device executing settings runs a new Java process, so it was to slow. On Android 12 it will be ok.

It will require some work, but this is now my priority task for the next release :)

rom1v added a commit that referenced this issue Nov 17, 2021
Before Android 8, executing the "settings" command from a shell was
very slow (~1 second), because it spawned a new app_process to execute
Java code. Therefore, to access settings without performance issues,
scrcpy used private APIs to read from and write to settings.

However, since Android 12, this is not possible anymore, due to
permissions changes.

To make it work again, execute the "settings" command on Android 12 (or
on previous version if the other method failed). This method is faster
than before Android 8 (~100ms).

Fixes #2671 <#2671>
Fixes #2788 <#2788>
@rom1v
Copy link
Collaborator

rom1v commented Nov 17, 2021

Please test #2802.

@sphars
Copy link
Author

sphars commented Nov 17, 2021

Please test #2802.

Tested out the newest files, it works! No errors in the console, and touches are shown on screen.

D:\Programs\scrcpy-win64>scrcpy -t
INFO: scrcpy 1.20 <https://github.com/Genymobile/scrcpy>
D:\Programs\scrcpy-win64\scrcpy-server: 1 file pushed, 0 skipped. 44.7 MB/s (38647 bytes in 0.001s)
[server] INFO: Device: Google Pixel 4a (Android 12)
INFO: Renderer: direct3d
INFO: Initial texture: 1080x2336

Thanks for taking care of this issue!

rom1v added a commit that referenced this issue Nov 18, 2021
Before Android 8, executing the "settings" command from a shell was
very slow (~1 second), because it spawned a new app_process to execute
Java code. Therefore, to access settings without performance issues,
scrcpy used private APIs to read from and write to settings.

However, since Android 12, this is not possible anymore, due to
permissions changes.

To make it work again, execute the "settings" command on Android 12 (or
on previous version if the other method failed). This method is faster
than before Android 8 (~100ms).

Fixes #2671 <#2671>
Fixes #2788 <#2788>
PR #2802 <#2802>
@rom1v
Copy link
Collaborator

rom1v commented Nov 18, 2021

👍 Fixed by #2802.

@rom1v rom1v closed this as completed Nov 18, 2021
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 a pull request may close this issue.

2 participants