Skip to content
Snippets Groups Projects
Commit 513f7d83 authored by Roman Kiryanov's avatar Roman Kiryanov Committed by Gerrit Code Review
Browse files

Merge "Cleanup in EmulatorClipboardMonitor (4)"

parents 306e3bb8 cfe2796f
No related branches found
No related tags found
No related merge requests found
......@@ -169,34 +169,43 @@ class EmulatorClipboardMonitor implements Consumer<ClipData> {
@Override
public void accept(final @Nullable ClipData clip) {
if (clip == null) {
setHostClipboardImpl("");
} else if (clip.getItemCount() > 0) {
final CharSequence text = clip.getItemAt(0).getText();
if (text != null) {
setHostClipboardImpl(text.toString());
}
final FileDescriptor fd = getPipeFD();
if (fd != null) {
setHostClipboard(fd, getClipString(clip));
}
}
private void setHostClipboardImpl(final String value) {
final FileDescriptor pipeFD = getPipeFD();
private String getClipString(final @Nullable ClipData clip) {
if (clip == null) {
return "";
}
if (pipeFD != null) {
Thread t = new Thread(() -> {
if (LOG_CLIBOARD_ACCESS) {
Slog.i(TAG, "Setting the host clipboard to '" + value + "'");
}
if (clip.getItemCount() == 0) {
return "";
}
try {
sendMessage(pipeFD, value.getBytes());
} catch (ErrnoException | InterruptedIOException e) {
Slog.e(TAG, "Failed to set host clipboard " + e.getMessage());
} catch (IllegalArgumentException e) {
}
});
t.start();
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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment