From c7a33fac36576817f092188f54b140e71edd8412 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 25 May 2020 02:23:32 +0200 Subject: [PATCH] Log actions on the caller side Some actions are exposed by the Device class, but logging success should be done by the caller. --- .../java/com/genymobile/scrcpy/Controller.java | 11 +++++++++-- .../main/java/com/genymobile/scrcpy/Device.java | 16 +++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java index eb5a0805..4442188c 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java @@ -110,11 +110,18 @@ public class Controller { sender.pushClipboardText(clipboardText); break; case ControlMessage.TYPE_SET_CLIPBOARD: - device.setClipboardText(msg.getText()); + boolean setClipboardOk = device.setClipboardText(msg.getText()); + if (setClipboardOk) { + Ln.i("Device clipboard set"); + } break; case ControlMessage.TYPE_SET_SCREEN_POWER_MODE: if (device.supportsInputEvents()) { - device.setScreenPowerMode(msg.getAction()); + int mode = msg.getAction(); + boolean setPowerModeOk = device.setScreenPowerMode(mode); + if (setPowerModeOk) { + Ln.i("Device screen turned " + (mode == Device.POWER_MODE_OFF ? "off" : "on")); + } } break; case ControlMessage.TYPE_ROTATE_DEVICE: diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index 6e788928..1a851b15 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -180,26 +180,20 @@ public final class Device { return s.toString(); } - public void setClipboardText(String text) { - boolean ok = serviceManager.getClipboardManager().setText(text); - if (ok) { - Ln.i("Device clipboard set"); - } + public boolean setClipboardText(String text) { + return serviceManager.getClipboardManager().setText(text); } /** * @param mode one of the {@code SCREEN_POWER_MODE_*} constants */ - public void setScreenPowerMode(int mode) { + public boolean setScreenPowerMode(int mode) { IBinder d = SurfaceControl.getBuiltInDisplay(); if (d == null) { Ln.e("Could not get built-in display"); - return; - } - boolean ok = SurfaceControl.setDisplayPowerMode(d, mode); - if (ok) { - Ln.i("Device screen turned " + (mode == Device.POWER_MODE_OFF ? "off" : "on")); + return false; } + return SurfaceControl.setDisplayPowerMode(d, mode); } /**