diff options
author | Roman Kiryanov <rkir@google.com> | 2021-03-12 16:38:14 -0800 |
---|---|---|
committer | Roman Kiryanov <rkir@google.com> | 2021-03-19 19:41:08 -0700 |
commit | 62ecd75d5aea27b878335d3cb3574d3f2a68656b (patch) | |
tree | 51ad42ce14e9f346f631bf8077f2344bd5a142ea /services/core/java | |
parent | 4dfa5f8db4dfe13591c76c1526277c8a2ef08a8d (diff) |
Emulator cleanup in ClipboardService.java (openPipe)
Bug: 182436079
Test: presubmit
Signed-off-by: Roman Kiryanov <rkir@google.com>
Change-Id: If19859b04d6c5ed27249c31ea55e273f303b3ec4
Diffstat (limited to 'services/core/java')
-rw-r--r-- | services/core/java/com/android/server/clipboard/ClipboardService.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java index b355730c6450..6776f49b7d8f 100644 --- a/services/core/java/com/android/server/clipboard/ClipboardService.java +++ b/services/core/java/com/android/server/clipboard/ClipboardService.java @@ -91,16 +91,19 @@ class HostClipboardMonitor implements Runnable { return bits; } - private void openPipe() { + private boolean openPipe() { try { - mPipe = new RandomAccessFile(PIPE_DEVICE, "rw"); - mPipe.write(createOpenHandshake()); - } catch (IOException e) { + final RandomAccessFile pipe = new RandomAccessFile(PIPE_DEVICE, "rw"); try { - if (mPipe != null) mPipe.close(); - } catch (IOException ee) {} - mPipe = null; + pipe.write(createOpenHandshake()); + mPipe = pipe; + return true; + } catch (IOException ignore) { + pipe.close(); + } + } catch (IOException ignore) { } + return false; } public HostClipboardMonitor(HostClipboardCallback cb) { @@ -114,8 +117,7 @@ class HostClipboardMonitor implements Runnable { // There's no guarantee that QEMU pipes will be ready at the moment // this method is invoked. We simply try to get the pipe open and // retry on failure indefinitely. - while (mPipe == null) { - openPipe(); + while ((mPipe == null) && !openPipe()) { Thread.sleep(100); } int size = mPipe.readInt(); |