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

Copy from mobile to compute doesn't work #1606

Open
2 tasks done
SunicYosen opened this issue Jul 20, 2020 · 12 comments
Open
2 tasks done

Copy from mobile to compute doesn't work #1606

SunicYosen opened this issue Jul 20, 2020 · 12 comments

Comments

@SunicYosen
Copy link

SunicYosen commented Jul 20, 2020

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

Environment

  • OS: Ubuntu20.04
  • scrcpy version: 1.14
  • installation method: Manual Build with prebuild server
  • device model: Xiaomi 4 Cancro
  • Android version: 10

Describe the bug
Copy from mobile to compute doesn't work. I copy texts with long press on mobile device, while nothing copied when I would like to paste to compute with Ctrl+v.

On errors, please provide the output of the console (and adb logcat if relevant).

[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Method.invoke(Native Method)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getPrimaryClip(ClipboardManager.java:49)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getText(ClipboardManager.java:64)
	at com.genymobile.scrcpy.Device.getClipboardText(Device.java:202)
	at com.genymobile.scrcpy.Device$2.dispatchPrimaryClipChanged(Device.java:92)
	at android.content.IOnPrimaryClipChangedListener$Stub.onTransact(IOnPrimaryClipChangedListener.java:82)
	at android.os.Binder.execTransactInternal(Binder.java:1021)
	at android.os.Binder.execTransact(Binder.java:994)
Caused by: java.lang.SecurityException: Calling uid 0 does not own package com.android.shell
	at android.os.Parcel.createException(Parcel.java:2071)
	at android.os.Parcel.readException(Parcel.java:2039)
	at android.os.Parcel.readException(Parcel.java:1987)
	at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:333)
	... 8 more
Caused by: android.os.RemoteException: Remote stack trace:
	at com.android.server.clipboard.ClipboardService.addActiveOwnerLocked(ClipboardService.java:688)
	at com.android.server.clipboard.ClipboardService.access$700(ClipboardService.java:157)
	at com.android.server.clipboard.ClipboardService$ClipboardImpl.getPrimaryClip(ClipboardService.java:391)
	at android.content.IClipboard$Stub.onTransact(IClipboard.java:173)
	at com.android.server.clipboard.ClipboardService$ClipboardImpl.onTransact(ClipboardService.java:341)

Thanks for your help.

@SunicYosen
Copy link
Author

After I recompile the server with private static final int USER_ID = 2000; I got follow error in terminal:

[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Method.invoke(Native Method)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getPrimaryClip(ClipboardManager.java:51)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getText(ClipboardManager.java:66)
	at com.genymobile.scrcpy.Device.getClipboardText(Device.java:202)
	at com.genymobile.scrcpy.Controller.handleEvent(Controller.java:107)
	at com.genymobile.scrcpy.Controller.control(Controller.java:64)
	at com.genymobile.scrcpy.Server$2.run(Server.java:89)
	at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.SecurityException: com.android.shell from uid 200000000 not allowed to perform READ_CLIPBOARD
	at android.os.Parcel.createException(Parcel.java:2071)
	at android.os.Parcel.readException(Parcel.java:2039)
	at android.os.Parcel.readException(Parcel.java:1987)
	at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:333)
	... 8 more
Caused by: android.os.RemoteException: Remote stack trace:
	at android.app.AppOpsManager.noteOp(AppOpsManager.java:5249)
	at com.android.server.clipboard.ClipboardService.clipboardAccessAllowed(ClipboardService.java:744)
	at com.android.server.clipboard.ClipboardService.access$400(ClipboardService.java:157)
	at com.android.server.clipboard.ClipboardService$ClipboardImpl.getPrimaryClip(ClipboardService.java:386)
	at android.content.IClipboard$Stub.onTransact(IClipboard.java:173)

What should i do?

@rom1v
Copy link
Collaborator

rom1v commented Jul 20, 2020

What is the result of adb shell id?

@rom1v
Copy link
Collaborator

rom1v commented Jul 20, 2020

The ROM is probably modified by the vendor and shell has no rights to read clioboards 😕

@SunicYosen
Copy link
Author

What is the result of adb shell id?

uid=0(root) gid=0(root) groups=0(root),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:su:s0

@SunicYosen
Copy link
Author

shell has no rights to

And is there any ways to make the shell have rights to read clipboard?

@SunicYosen
Copy link
Author

And after i change the parameters in /system/default.prop

ro.secure=0
ro.adb.secure=0

To:

ro.secure=1
ro.adb.secure=1

The adb shell would not get root by default. And the return info of adb shell id is:

uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:shell:s0

And the copy function works well.

However, the same uid=2000, why the later have the rights to read clipboard?

@rom1v
Copy link
Collaborator

rom1v commented Jul 20, 2020

I guess the package name must match the user id.

Maybe try keep user id 0 and change the package name ("root", null...):

public static final String PACKAGE_NAME = "com.android.shell";

@SunicYosen
Copy link
Author

I guess the package name must match the user id.

Maybe try keep user id 0 and change the package name ("root", null...):

I have no idea to change the package name in code.

After change to

    public static final String PACKAGE_NAME = null;

, no response when copy text on mobile.

And I dont know the name of "com.android.shell" in root model.

@DRSDavidSoft
Copy link

DRSDavidSoft commented Oct 29, 2021

Using rooted LineageOS device, I have the same issue:

[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.genymobile.scrcpy.wrappers.ClipboardManager.getPrimaryClip(ClipboardManager.java:47)
        at com.genymobile.scrcpy.wrappers.ClipboardManager.getText(ClipboardManager.java:64)
        at com.genymobile.scrcpy.Device.getClipboardText(Device.java:231)
        at com.genymobile.scrcpy.Device$2.dispatchPrimaryClipChanged(Device.java:98)
        at android.content.IOnPrimaryClipChangedListener$Stub.onTransact(IOnPrimaryClipChangedListener.java:51)
        at android.os.Binder.execTransact(Binder.java:565)
Caused by: java.lang.SecurityException: Calling uid 0 does not own package com.android.shell
        at android.os.Parcel.readException(Parcel.java:1684)
        at android.os.Parcel.readException(Parcel.java:1637)
        at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:187)

Here's the output of adb shell uname -a and adb shell id:

ja3gxx / # uname -a
Linux localhost 3.4.67-g9d55dec #1 SMP PREEMPT Fri Oct 12 18:42:26 CEST 2018 armv7l
ja3gxx / # id
uid=0(root) gid=0(root) groups=0(root),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc) context=u:r:su:s0
ja3gxx / # whoami
root
ja3gxx / # getprop ro.build.flavor
lineage_ja3gxx-userdebug

@yume-chan
Copy link
Contributor

Meet this problem when testing my implementation, it prints INFO: Device clipboard copied but the clipboard is always empty (len of DEVICE_MSG_TYPE_CLIPBOARD message is 0)

  • OS: macOS 11.6
  • scrcpy version: 1.21
  • installation method: homebrew
  • device model: Xiaomi Mi 11
  • Android version: 11

Found this from logcat

I ClipboardServiceI: MIUILOG- Permission Denied when system app read clipboard, caller 2000

This reminded me that MIUI has a privacy protection feature that prevents apps from reading clipboard (In Settings -> Privacy protection -> Protection tab -> Privacy protection lab -> Protect clipboard)

image

If I turned it off, clipboard synchronization will work.

It doesn't show any notifications when Scrcpy tries to read the clipboard, just returns empty string. Maybe it only handles "real" Android Apps, not sure if it's possible to workaround it.

@mergerly
Copy link

Ran adb as non-root can fix this issues.

adb unroot
Then run scrcpy
Scrcpy
now you can copy text from phone, get:
INFO: Device clipboard copied

@DRSDavidSoft
Copy link

@rom1v If the shell has root access, can't it grant the required permissions to itself?

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

No branches or pull requests

5 participants