Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
106.35k stars 10.3k forks source link

Copy-paste broken on Honor Magic5 with Android 14 (getPrimaryClip NoSuchMethodException) #5073

Closed puwei7788 closed 2 weeks ago

puwei7788 commented 2 weeks ago

Please read the prerequisites to run scrcpy.

Also read the FAQ and check if your issue already exists.

Environment

Describe the bug

[server] ERROR: Could not invoke method java.lang.NoSuchMethodException: android.content.IClipboard$Stub$Proxy.getPrimaryClip [class java.lang.String, class java.lang.String, class java.lang.String, class java.lang.String, int, int, boolean] at java.lang.Class.getMethod(Class.java:2937) at java.lang.Class.getMethod(Class.java:2449) at com.genymobile.scrcpy.wrappers.ClipboardManager.getGetPrimaryClipMethod(ClipboardManager.java:64) at com.genymobile.scrcpy.wrappers.ClipboardManager.getText(ClipboardManager.java:152) at com.genymobile.scrcpy.Device.getClipboardText(Device.java:290) at com.genymobile.scrcpy.Device$3.dispatchPrimaryClipChanged(Device.java:143) at android.content.IOnPrimaryClipChangedListener$Stub.onTransact(IOnPrimaryClipChangedListener.java:84) at android.os.Binder.execTransactInternal(Binder.java:1371) at android.os.Binder.execTransact(Binder.java:1310)

——The above issues that occur during the use of Scrcpy prevent the copied content on the phone from being transmitted to the computer

rom1v commented 2 weeks ago

Which scrcpy version?

puwei7788 commented 2 weeks ago

Which scrcpy version? 哪个版本的pk10 scrcpy v2.5 Latest,scrcpy-win64-v2.5.zip

puwei7788 commented 2 weeks ago

framework.zip 微信图片_20240710223542

rom1v commented 2 weeks ago

Please replace this binary in the scrcpy 2.5 release folder and test:

diff ```diff diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java index bdbba21df..f8b5ec6ef 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java @@ -82,9 +82,16 @@ public final class ClipboardManager { // fall-through } - getPrimaryClipMethod = manager.getClass() - .getMethod("getPrimaryClip", String.class, String.class, String.class, String.class, int.class, int.class, boolean.class); - getMethodVersion = 5; + try { + getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, String.class, String.class, int.class, int.class, boolean.class); + getMethodVersion = 5; + return getPrimaryClipMethod; + } catch (NoSuchMethodException e) { + // fall-through + } + + getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, int.class, int.class, String.class); + getMethodVersion = 6; } return getPrimaryClipMethod; } @@ -145,8 +152,10 @@ public final class ClipboardManager { case 4: // The last boolean parameter is "userOperate" return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, null, FakeContext.ROOT_UID, 0, true); - default: + case 5: return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, null, null, null, FakeContext.ROOT_UID, 0, true); + default: + return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME, null, FakeContext.ROOT_UID, 0, null); } } ```
puwei7788 commented 2 weeks ago

Thank you very much, the problem with the clipboard was solved perfectly:

[server] INFO: Device clipboard set INFO: Device clipboard copied

But there is still a problem, I wonder if it can also be solved: Pressing MOD+o or MOD+Shift+o will not turn off or on the device screen, but will crash the program~

[server] INFO: Device: [HONOR] HONOR PGT-AN00 (Android 14) INFO: Renderer: direct3d INFO: Texture: 1224x2688 Native registration unable to find class 'com/android/server/TrustedUIService'; aborting... Aborted ERROR: Controller error

rom1v commented 2 weeks ago

Pressing MOD+o or MOD+Shift+o will not turn off or on the device screen, but will crash the program

Yes: #4943

puwei7788 commented 2 weeks ago

Pressing MOD+o or MOD+Shift+o will not turn off or on the device screen, but will crash the program按MOD+o或MOD+Shift+o不会关闭或打开设备屏幕,但会使程序崩溃

Yes: #4943 是: #4943

That means we can't solve it for a while, so let's forget about it. It won't affect the use too much. Thank you very much

rom1v commented 2 weeks ago

Merged: 79242957a0ddba1c326f414cf5eafff6cc7b39c1

eiyooooo commented 1 week ago

@rom1v Seems that you forgot my PR #4822. 😂

rom1v commented 1 week ago

@eiyooooo Oh, I'm sorry! Too late, it's merged and there are also newer commits.

Btw, when I wrote fe7494c4922b2dd9a8af18842d82af1e5ebf8897, I was sure I already did it, and it was on branch pr4822: https://github.com/Genymobile/scrcpy/commit/d1a0f9b054fadde16b0d591d14f931b7b04d6656