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-paste broken on Honor Magic5 with Android 14 (getPrimaryClip NoSuchMethodException) #5073

Closed
puwei7788 opened this issue Jul 9, 2024 · 10 comments

Comments

@puwei7788
Copy link

Please read the prerequisites to run scrcpy.

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

Environment

  • OS: [Windows11 23H2]
  • Scrcpy version: [2.5]
  • Installation method: [Windows release...]
  • **Device model:Honor Magic5 PGT-AN00
  • Android version: [14]

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
Copy link
Collaborator

rom1v commented Jul 9, 2024

Which scrcpy version?

@puwei7788
Copy link
Author

puwei7788 commented Jul 10, 2024

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

@puwei7788
Copy link
Author

framework.zip
微信图片_20240710223542

@rom1v
Copy link
Collaborator

rom1v commented Jul 10, 2024

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

  • scrcpy-server SHA-256: 4623d80c83457ce2f4ac10199defe550354339d8972bdc1b67bee41b1ec2df7
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);
         }
     }
 

@rom1v rom1v changed the title The problem with using Scrcpy is that the copied content on the phone cannot be transferred to the computer and cannot be pasted on the computer Copy-paste broken on Honor Magic5 with Android 14 (getPrimaryClip NoSuchMethodException) Jul 10, 2024
@puwei7788
Copy link
Author

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
Copy link
Collaborator

rom1v commented Jul 11, 2024

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

Yes: #4943

@puwei7788
Copy link
Author

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 added a commit that referenced this issue Jul 11, 2024
@rom1v
Copy link
Collaborator

rom1v commented Jul 11, 2024

Merged: 7924295

@eiyooooo
Copy link
Contributor

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

@rom1v
Copy link
Collaborator

rom1v commented Jul 17, 2024

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

Btw, when I wrote fe7494c, I was sure I already did it, and it was on branch pr4822: d1a0f9b

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

No branches or pull requests

3 participants