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

Fails on android 12 when use --stay-awake #2671

Closed
2 tasks done
binlly opened this issue Sep 28, 2021 · 15 comments · Fixed by #2802
Closed
2 tasks done

Fails on android 12 when use --stay-awake #2671

binlly opened this issue Sep 28, 2021 · 15 comments · Fixed by #2802

Comments

@binlly
Copy link

binlly commented Sep 28, 2021

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

Environment

  • OS: macOS BigSur 11.6
  • scrcpy version: 1.19
  • installation method: brew
  • device model: Xiaomi 11 Ultra
  • Android version: 12

Describe the bug

run: scrcpy --stay-awake

2021-09-28 17:49:19.443 scrcpy[48746:3478246] INFO: scrcpy 1.19 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 30.8 MB/s (37442 bytes in 0.001s)
[server] INFO: Device: Xiaomi (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:39)
	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:363)
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:39)
	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:363)
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
@rom1v
Copy link
Collaborator

rom1v commented Sep 28, 2021

Is your device rooted?

For some reasons, some features do not work if scrcpy is run as root on the device.

@binlly
Copy link
Author

binlly commented Sep 28, 2021

It seems to pass when I set USER_ID:2000
But the followed message printed:

2021-09-28 18:22:21.975 scrcpy[50024:3495623] INFO: scrcpy 1.19 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 33.2 MB/s (37490 bytes in 0.001s)
[server] INFO: Device: Xiaomi (Android 12)
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.genymobile.scrcpy.wrappers.ContentProvider.getAndPutValue(java.lang.String, java.lang.String, java.lang.String)' on a null object reference
	at com.genymobile.scrcpy.Server.scrcpy(Server.java:39)
	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:363)

@rom1v
Copy link
Collaborator

rom1v commented Sep 28, 2021

It seems to pass when I set USER_ID:2000

Where do you set this?

@binlly
Copy link
Author

binlly commented Sep 28, 2021

Is your device rooted?

For some reasons, some features do not work if scrcpy is run as root on the device.

Not root

@binlly
Copy link
Author

binlly commented Sep 28, 2021

It seems to pass when I set USER_ID:2000

Where do you set this?

I try modified the source code and ran it locally

@binlly
Copy link
Author

binlly commented Sep 28, 2021

I think I know what's going on here. Maybe it really has something to do with android system permissions.

@rom1v
Copy link
Collaborator

rom1v commented Sep 28, 2021

I try modified the source code and ran it locally

What change did you do exactly?

@binlly
Copy link
Author

binlly commented Sep 28, 2021

I probably realized the problem (my system MIUI is dev channel), but some attempt ended in failure. Maybe xiaomi did something to cause it.
It might be a good idea to temporarily close this issue. Thank you.

@randodude123
Copy link

I'm having the same issue on a Linux computer using a Pixel phone running Android 12. ADB connects but scrcpy fails to start: java.lang.IllegalArgumentException: displayToken must not be null
at android.view.SurfaceControl$Transaction.setDisplaySurface(SurfaceControl.java:3145)
at android.view.SurfaceControl.setDisplaySurface(SurfaceControl.java:2214)

@rom1v
Copy link
Collaborator

rom1v commented Oct 25, 2021

@randodude123 You must use scrcpy >= 1.18 (the latest is 1.19).

@randodude123
Copy link

It works, I forgot to update from git. @rom1v

@Tyf0x
Copy link

Tyf0x commented Oct 28, 2021

I updated to android 12 and that message started appearing too.

I can confirm the stack is only displayed when using the --stay-awake arguments.

OS: windows 10
scrcpy version: 1.19 (unmodified - from github)
installation method: manual - zip
device model: Google Pixel 3 XL
Android version: 12
INFO: scrcpy 1.19 <https://github.com/Genymobile/scrcpy>
D:\softs\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 84.2 MB/s (37330 bytes in 0.000s)
[server] INFO: Device: Google Pixel 3 XL (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:39)
        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:39)
        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: opengl
INFO: OpenGL version: 4.6.0 NVIDIA 496.49
INFO: Trilinear filtering enabled
INFO: Initial texture: 800x392
[server] INFO: Device screen turned off

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.

@Tyf0x
Copy link

Tyf0x commented Nov 17, 2021

This is working, thanks @rom1v 🎉

INFO: scrcpy 1.20 <https://github.com/Genymobile/scrcpy>
* daemon not running; starting now at tcp:5037
* daemon started successfully
D:\softs\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 14.1 MB/s (38647 bytes in 0.003s)
[server] INFO: Device: Google Pixel 3 XL (Android 12)
[server] INFO: Device screen turned off
INFO: Renderer: opengl
INFO: OpenGL version: 4.6.0 NVIDIA 496.76
INFO: Trilinear filtering enabled
INFO: Initial texture: 800x392

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.

4 participants