From b3aa88c7515778bf9c0614df20a6562545073311 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 1 Jun 2020 15:35:43 +0200 Subject: [PATCH] Set device clipboard only if necessary Do not explicitly set the clipboard text if it already contains the expected content. This avoids possible copy-paste loops between the computer and the device. --- server/src/main/java/com/genymobile/scrcpy/Device.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index 349486c3..7a3a4d56 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -207,6 +207,14 @@ public final class Device { } public boolean setClipboardText(String text) { + String currentClipboard = getClipboardText(); + if (currentClipboard == null || currentClipboard.equals(text)) { + // The clipboard already contains the requested text. + // Since pasting text from the computer involves setting the device clipboard, it could be set twice on a copy-paste. This would cause + // the clipboard listeners to be notified twice, and that would flood the Android keyboard clipboard history. To workaround this + // problem, do not explicitly set the clipboard text if it already contains the expected content. + return false; + } isSettingClipboard.set(true); boolean ok = serviceManager.getClipboardManager().setText(text); isSettingClipboard.set(false);