Display and control your Android device
Try new methods before legacy ones
Romain Vimont525d6d4a758a
diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.javaindex 52096461..b0e44278 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java@@ -14,11 +14,12 @@ public final class WindowManager {try {Class<?> cls = manager.getClass();try {- return (Integer) cls.getMethod("getRotation").invoke(manager);- } catch (NoSuchMethodException e) {// method changed since this commit:// https://android.googlesource.com/platform/frameworks/base/+/8ee7285128c3843401d4c4d0412cd66e86ba49e3%5E%21/#F2return (Integer) cls.getMethod("getDefaultDisplayRotation").invoke(manager);+ } catch (NoSuchMethodException e) {+ // old version+ return (Integer) cls.getMethod("getRotation").invoke(manager);}} catch (Exception e) {throw new AssertionError(e);@@ -29,11 +30,12 @@ public final class WindowManager {try {Class<?> cls = manager.getClass();try {- cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);- } catch (NoSuchMethodException e) {// display parameter added since this commit:// https://android.googlesource.com/platform/frameworks/base/+/35fa3c26adcb5f6577849fd0df5228b1f67cf2c6%5E%21/#F1cls.getMethod("watchRotation", IRotationWatcher.class, int.class).invoke(manager, rotationWatcher, 0);+ } catch (NoSuchMethodException e) {+ // old version+ cls.getMethod("watchRotation", IRotationWatcher.class).invoke(manager, rotationWatcher);}} catch (Exception e) {throw new AssertionError(e);