diff options
| author | 2022-05-13 08:57:32 +0000 | |
|---|---|---|
| committer | 2022-05-13 08:57:32 +0000 | |
| commit | c613e4e472d3ba9cee8db367b057cc68bb73f7cd (patch) | |
| tree | 4685d79015090c4e8d77caefe7edd188f5112d8f | |
| parent | a1ee8846444e97abcf811420afbd7bb544ed9645 (diff) | |
| parent | 3c6f225e6f687561b8c706445543afbb81b228ce (diff) | |
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>
| -rw-r--r-- | services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java index f39bdfe68b31..ab3b2506f5ac 100644 --- a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java +++ b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java @@ -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, |