Skip to content

Commit 4ee94cb

Browse files
rom1vyume-chan
andcommitted
Workaround clipboard issue on Samsung devices
Fixes #6224 <#6224> Co-authored-by: Simon Chan <[email protected]>
1 parent afaca80 commit 4ee94cb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/src/main/java/com/genymobile/scrcpy/FakeContext.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.annotation.SuppressLint;
66
import android.annotation.TargetApi;
77
import android.content.AttributionSource;
8-
import android.content.ClipboardManager;
98
import android.content.ContentResolver;
109
import android.content.Context;
1110
import android.content.ContextWrapper;
@@ -91,6 +90,11 @@ public Context getApplicationContext() {
9190
return this;
9291
}
9392

93+
@Override
94+
public Context createPackageContext(String packageName, int flags) {
95+
return this;
96+
}
97+
9498
@Override
9599
public ContentResolver getContentResolver() {
96100
return contentResolver;
@@ -104,9 +108,11 @@ public Object getSystemService(String name) {
104108
return null;
105109
}
106110

107-
if (Context.CLIPBOARD_SERVICE.equals(name)) {
111+
// "semclipboard" is a Samsung-internal service
112+
// See <https://github.com/Genymobile/scrcpy/issues/6224>
113+
if (Context.CLIPBOARD_SERVICE.equals(name) || "semclipboard".equals(name)) {
108114
try {
109-
Field field = ClipboardManager.class.getDeclaredField("mContext");
115+
Field field = service.getClass().getDeclaredField("mContext");
110116
field.setAccessible(true);
111117
field.set(service, this);
112118
} catch (ReflectiveOperationException e) {

0 commit comments

Comments
 (0)