From 3ab44e4a9a415f65dc7758628157cd4100fbf8ec Mon Sep 17 00:00:00 2001 From: Derek Wu Date: Tue, 16 Aug 2022 23:52:08 +0200 Subject: [PATCH] Use DisplayManagerGlobal instance Use the client instance to communicate with the DisplayManager server. Fixes #3446 Signed-off-by: Romain Vimont --- .../com/genymobile/scrcpy/wrappers/DisplayManager.java | 6 ++---- .../com/genymobile/scrcpy/wrappers/ServiceManager.java | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java index cedb3f47ed..3f4f897dfa 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java @@ -3,12 +3,10 @@ import com.genymobile.scrcpy.DisplayInfo; import com.genymobile.scrcpy.Size; -import android.os.IInterface; - public final class DisplayManager { - private final IInterface manager; + private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal - public DisplayManager(IInterface manager) { + public DisplayManager(Object manager) { this.manager = manager; } diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java index ea2a078470..3830c4ad86 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java @@ -50,6 +50,14 @@ public WindowManager getWindowManager() { public DisplayManager getDisplayManager() { if (displayManager == null) { + try { + Class clazz = Class.forName("android.hardware.display.DisplayManagerGlobal"); + Method getInstanceMethod = clazz.getDeclaredMethod("getInstance"); + Object dmg = getInstanceMethod.invoke(null); + displayManager = new DisplayManager(dmg); + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new AssertionError(e); + } displayManager = new DisplayManager(getService("display", "android.hardware.display.IDisplayManager")); } return displayManager;