Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4bc4fb1 authored by Roman Kiryanov's avatar Roman Kiryanov Committed by Gerrit Code Review
Browse files

Merge "Emulator cleanup in ClipboardService.java (send/receive)"

parents 6b925930 20a418ed
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -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) {
        mHostClipboardCallback = cb;
    }
@@ -131,10 +143,8 @@ class HostClipboardMonitor implements Runnable {
                while ((mPipe == null) && !openPipe()) {
                    Thread.sleep(100);
                }
                int size = mPipe.readInt();
                size = Integer.reverseBytes(size);
                byte[] receivedData = new byte[size];
                mPipe.readFully(receivedData);

                final byte[] receivedData = receiveMessage();
                mHostClipboardCallback.onHostClipboardUpdated(
                    new String(receivedData));
            } catch (IOException e) {
@@ -146,8 +156,7 @@ class HostClipboardMonitor implements Runnable {
    public void setHostClipboard(String content) {
        try {
            if (mPipe != null) {
                mPipe.writeInt(Integer.reverseBytes(content.getBytes().length));
                mPipe.write(content.getBytes());
                sendMessage(content.getBytes());
            }
        } catch(IOException e) {
            Slog.e("HostClipboardMonitor",