|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
|
|
|
|
|
|
import com.genymobile.scrcpy.wrappers.ClipboardManager;
|
|
|
|
|
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
|
|
|
|
import com.genymobile.scrcpy.wrappers.InputManager;
|
|
|
|
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
|
|
|
|
@ -80,23 +81,28 @@ public final class Device {
|
|
|
|
|
|
|
|
|
|
if (options.getControl()) {
|
|
|
|
|
// If control is enabled, synchronize Android clipboard to the computer automatically
|
|
|
|
|
serviceManager.getClipboardManager().addPrimaryClipChangedListener(new IOnPrimaryClipChangedListener.Stub() {
|
|
|
|
|
@Override
|
|
|
|
|
public void dispatchPrimaryClipChanged() {
|
|
|
|
|
if (isSettingClipboard.get()) {
|
|
|
|
|
// This is a notification for the change we are currently applying, ignore it
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
synchronized (Device.this) {
|
|
|
|
|
if (clipboardListener != null) {
|
|
|
|
|
String text = getClipboardText();
|
|
|
|
|
if (text != null) {
|
|
|
|
|
clipboardListener.onClipboardTextChanged(text);
|
|
|
|
|
ClipboardManager clipboardManager = serviceManager.getClipboardManager();
|
|
|
|
|
if (clipboardManager != null) {
|
|
|
|
|
clipboardManager.addPrimaryClipChangedListener(new IOnPrimaryClipChangedListener.Stub() {
|
|
|
|
|
@Override
|
|
|
|
|
public void dispatchPrimaryClipChanged() {
|
|
|
|
|
if (isSettingClipboard.get()) {
|
|
|
|
|
// This is a notification for the change we are currently applying, ignore it
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
synchronized (Device.this) {
|
|
|
|
|
if (clipboardListener != null) {
|
|
|
|
|
String text = getClipboardText();
|
|
|
|
|
if (text != null) {
|
|
|
|
|
clipboardListener.onClipboardTextChanged(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Ln.w("No clipboard manager, copy-paste between device and computer will not work");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((displayInfoFlags & DisplayInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) == 0) {
|
|
|
|
|
@ -199,7 +205,11 @@ public final class Device {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getClipboardText() {
|
|
|
|
|
CharSequence s = serviceManager.getClipboardManager().getText();
|
|
|
|
|
ClipboardManager clipboardManager = serviceManager.getClipboardManager();
|
|
|
|
|
if (clipboardManager == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
CharSequence s = clipboardManager.getText();
|
|
|
|
|
if (s == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@ -207,8 +217,12 @@ public final class Device {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean setClipboardText(String text) {
|
|
|
|
|
ClipboardManager clipboardManager = serviceManager.getClipboardManager();
|
|
|
|
|
if (clipboardManager == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
isSettingClipboard.set(true);
|
|
|
|
|
boolean ok = serviceManager.getClipboardManager().setText(text);
|
|
|
|
|
boolean ok = clipboardManager.setText(text);
|
|
|
|
|
isSettingClipboard.set(false);
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|