Merge "Emulator cleanup in ClipboardService.java (send/receive)" am: c4bc4fb144
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1634489 Change-Id: Ibbd5312c876b93d612060c919498926c05702f35
This commit is contained in:
@@ -117,6 +117,18 @@ class HostClipboardMonitor implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] receiveMessage() throws IOException {
|
||||||
|
final int size = Integer.reverseBytes(mPipe.readInt());
|
||||||
|
final byte[] receivedData = new byte[size];
|
||||||
|
mPipe.readFully(receivedData);
|
||||||
|
return receivedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessage(byte[] message) throws IOException {
|
||||||
|
mPipe.writeInt(Integer.reverseBytes(message.length));
|
||||||
|
mPipe.write(message);
|
||||||
|
}
|
||||||
|
|
||||||
public HostClipboardMonitor(HostClipboardCallback cb) {
|
public HostClipboardMonitor(HostClipboardCallback cb) {
|
||||||
mHostClipboardCallback = cb;
|
mHostClipboardCallback = cb;
|
||||||
}
|
}
|
||||||
@@ -131,10 +143,8 @@ class HostClipboardMonitor implements Runnable {
|
|||||||
while ((mPipe == null) && !openPipe()) {
|
while ((mPipe == null) && !openPipe()) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
int size = mPipe.readInt();
|
|
||||||
size = Integer.reverseBytes(size);
|
final byte[] receivedData = receiveMessage();
|
||||||
byte[] receivedData = new byte[size];
|
|
||||||
mPipe.readFully(receivedData);
|
|
||||||
mHostClipboardCallback.onHostClipboardUpdated(
|
mHostClipboardCallback.onHostClipboardUpdated(
|
||||||
new String(receivedData));
|
new String(receivedData));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -146,8 +156,7 @@ class HostClipboardMonitor implements Runnable {
|
|||||||
public void setHostClipboard(String content) {
|
public void setHostClipboard(String content) {
|
||||||
try {
|
try {
|
||||||
if (mPipe != null) {
|
if (mPipe != null) {
|
||||||
mPipe.writeInt(Integer.reverseBytes(content.getBytes().length));
|
sendMessage(content.getBytes());
|
||||||
mPipe.write(content.getBytes());
|
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
Slog.e("HostClipboardMonitor",
|
Slog.e("HostClipboardMonitor",
|
||||||
|
|||||||
Reference in New Issue
Block a user