Merge changes I9ba57f43,I236b039c into tm-dev am: 3c6f225e6f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18360038 Change-Id: Id305739bf5884f28c3d247ab49e82e0236c2e918 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -169,34 +169,43 @@ class EmulatorClipboardMonitor implements Consumer<ClipData> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(final @Nullable ClipData clip) {
|
public void accept(final @Nullable ClipData clip) {
|
||||||
if (clip == null) {
|
final FileDescriptor fd = getPipeFD();
|
||||||
setHostClipboardImpl("");
|
if (fd != null) {
|
||||||
} else if (clip.getItemCount() > 0) {
|
setHostClipboard(fd, getClipString(clip));
|
||||||
final CharSequence text = clip.getItemAt(0).getText();
|
|
||||||
if (text != null) {
|
|
||||||
setHostClipboardImpl(text.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHostClipboardImpl(final String value) {
|
private String getClipString(final @Nullable ClipData clip) {
|
||||||
final FileDescriptor pipeFD = getPipeFD();
|
if (clip == null) {
|
||||||
|
return "";
|
||||||
if (pipeFD != null) {
|
|
||||||
Thread t = new Thread(() -> {
|
|
||||||
if (LOG_CLIBOARD_ACCESS) {
|
|
||||||
Slog.i(TAG, "Setting the host clipboard to '" + value + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sendMessage(pipeFD, value.getBytes());
|
|
||||||
} catch (ErrnoException | InterruptedIOException e) {
|
|
||||||
Slog.e(TAG, "Failed to set host clipboard " + e.getMessage());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (clip.getItemCount() == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
final CharSequence text = clip.getItemAt(0).getText();
|
||||||
|
if (text == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setHostClipboard(final FileDescriptor fd, final String value) {
|
||||||
|
Thread t = new Thread(() -> {
|
||||||
|
if (LOG_CLIBOARD_ACCESS) {
|
||||||
|
Slog.i(TAG, "Setting the host clipboard to '" + value + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendMessage(fd, value.getBytes());
|
||||||
|
} catch (ErrnoException | InterruptedIOException e) {
|
||||||
|
Slog.e(TAG, "Failed to set host clipboard " + e.getMessage());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readFully(final FileDescriptor fd,
|
private static void readFully(final FileDescriptor fd,
|
||||||
|
|||||||
Reference in New Issue
Block a user