From 1ac37c4291925195d0b76b1ade9f1ed13d2bf7df Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 2 Feb 2018 16:31:11 +0100 Subject: [PATCH] Hide services in Device Expose useful methods directly in Device, without exposing the service managers. --- .../src/main/java/com/genymobile/scrcpy/Device.java | 11 +++++------ .../java/com/genymobile/scrcpy/EventController.java | 9 ++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index b663a0ab..c6860a10 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -4,9 +4,8 @@ import android.graphics.Point; import android.os.Build; import android.os.RemoteException; import android.view.IRotationWatcher; +import android.view.InputEvent; -import com.genymobile.scrcpy.wrappers.InputManager; -import com.genymobile.scrcpy.wrappers.PowerManager; import com.genymobile.scrcpy.wrappers.ServiceManager; public final class Device { @@ -90,12 +89,12 @@ public final class Device { return Build.MODEL; } - public InputManager getInputManager() { - return serviceManager.getInputManager(); + public boolean injectInputEvent(InputEvent inputEvent, int mode) { + return serviceManager.getInputManager().injectInputEvent(inputEvent, mode); } - public PowerManager getPowerManager() { - return serviceManager.getPowerManager(); + public boolean isScreenOn() { + return serviceManager.getPowerManager().isScreenOn(); } public void registerRotationWatcher(IRotationWatcher rotationWatcher) { diff --git a/server/src/main/java/com/genymobile/scrcpy/EventController.java b/server/src/main/java/com/genymobile/scrcpy/EventController.java index 7e429393..ee0f0313 100644 --- a/server/src/main/java/com/genymobile/scrcpy/EventController.java +++ b/server/src/main/java/com/genymobile/scrcpy/EventController.java @@ -9,15 +9,12 @@ import android.view.KeyEvent; import android.view.MotionEvent; import com.genymobile.scrcpy.wrappers.InputManager; -import com.genymobile.scrcpy.wrappers.PowerManager; import java.io.IOException; public class EventController { private final Device device; - private final InputManager inputManager; - private final PowerManager powerManager; private final DesktopConnection connection; private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); @@ -29,8 +26,6 @@ public class EventController { public EventController(Device device, DesktopConnection connection) { this.device = device; this.connection = connection; - inputManager = device.getInputManager(); - powerManager = device.getPowerManager(); initPointer(); // on start, turn screen on @@ -153,11 +148,11 @@ public class EventController { } private boolean injectEvent(InputEvent event) { - return inputManager.injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); + return device.injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); } private boolean turnScreenOn() { - return powerManager.isScreenOn() || injectKeycode(KeyEvent.KEYCODE_POWER); + return device.isScreenOn() || injectKeycode(KeyEvent.KEYCODE_POWER); } private boolean executeCommand(int action) {