|
|
@ -1,54 +1,30 @@
|
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
|
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
|
|
|
|
|
|
|
|
|
public final class DeviceMessageSender {
|
|
|
|
public final class DeviceMessageSender {
|
|
|
|
|
|
|
|
|
|
|
|
private final ControlChannel controlChannel;
|
|
|
|
private final ControlChannel controlChannel;
|
|
|
|
|
|
|
|
|
|
|
|
private Thread thread;
|
|
|
|
private Thread thread;
|
|
|
|
|
|
|
|
private final BlockingQueue<DeviceMessage> queue = new ArrayBlockingQueue<>(16);
|
|
|
|
private String clipboardText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long ack;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceMessageSender(ControlChannel controlChannel) {
|
|
|
|
public DeviceMessageSender(ControlChannel controlChannel) {
|
|
|
|
this.controlChannel = controlChannel;
|
|
|
|
this.controlChannel = controlChannel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized void pushClipboardText(String text) {
|
|
|
|
public void send(DeviceMessage msg) {
|
|
|
|
clipboardText = text;
|
|
|
|
if (!queue.offer(msg)) {
|
|
|
|
notify();
|
|
|
|
Ln.w("Device message dropped: " + msg.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized void pushAckClipboard(long sequence) {
|
|
|
|
|
|
|
|
ack = sequence;
|
|
|
|
|
|
|
|
notify();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void loop() throws IOException, InterruptedException {
|
|
|
|
private void loop() throws IOException, InterruptedException {
|
|
|
|
while (!Thread.currentThread().isInterrupted()) {
|
|
|
|
while (!Thread.currentThread().isInterrupted()) {
|
|
|
|
String text;
|
|
|
|
DeviceMessage msg = queue.take();
|
|
|
|
long sequence;
|
|
|
|
controlChannel.send(msg);
|
|
|
|
synchronized (this) {
|
|
|
|
|
|
|
|
while (ack == DeviceMessage.SEQUENCE_INVALID && clipboardText == null) {
|
|
|
|
|
|
|
|
wait();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
text = clipboardText;
|
|
|
|
|
|
|
|
clipboardText = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sequence = ack;
|
|
|
|
|
|
|
|
ack = DeviceMessage.SEQUENCE_INVALID;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sequence != DeviceMessage.SEQUENCE_INVALID) {
|
|
|
|
|
|
|
|
DeviceMessage event = DeviceMessage.createAckClipboard(sequence);
|
|
|
|
|
|
|
|
controlChannel.send(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text != null) {
|
|
|
|
|
|
|
|
DeviceMessage event = DeviceMessage.createClipboard(text);
|
|
|
|
|
|
|
|
controlChannel.send(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|