Hide services in Device

Expose useful methods directly in Device, without exposing the service
managers.
This commit is contained in:
Romain Vimont 2018-02-02 16:31:11 +01:00
parent 06333e1e08
commit 1ac37c4291
2 changed files with 7 additions and 13 deletions

View file

@ -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) {

View file

@ -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) {