From 1e26e48e1f21f75ac7fb34b10ebee4ff347bdcbd Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich Date: Thu, 7 Mar 2024 14:13:22 -0500 Subject: [PATCH] fix freeze and thaw rotation for Android 15 preview --- .../scrcpy/wrappers/WindowManager.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java index d9654b1b..e79d6812 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java @@ -59,6 +59,16 @@ public final class WindowManager { return freezeDisplayRotationMethod; } + // Android 15 preview and 14 QPR3 Beta introduces a new signature for freeze and thaw rotation + // methods which includes a String parameters: + // public void android.view.IWindowManager$Stub$Proxy.freezeDisplayRotation(int,int,java.lang.String) throws android.os.RemoteException + private Method getFreezeDisplayRotationStringMethod() throws NoSuchMethodException { + if (freezeDisplayRotationMethod == null) { + freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class, String.class); + } + return freezeDisplayRotationMethod; + } + private Method getIsRotationFrozenMethod() throws NoSuchMethodException { if (isRotationFrozenMethod == null) { isRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen"); @@ -91,6 +101,16 @@ public final class WindowManager { return thawDisplayRotationMethod; } + // Android 15 preview and 14 QPR3 Beta introduces a new signature for freeze and thaw rotation + // methods which includes a String parameters: + // public void android.view.IWindowManager$Stub$Proxy.thawDisplayRotation(int,java.lang.String) throws android.os.RemoteException + private Method getThawDisplayRotationStringMethod() throws NoSuchMethodException { + if (thawDisplayRotationMethod == null) { + thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class, String.class); + } + return thawDisplayRotationMethod; + } + public int getRotation() { try { Method method = getGetRotationMethod(); @@ -104,8 +124,14 @@ public final class WindowManager { public void freezeRotation(int displayId, int rotation) { try { try { - Method method = getFreezeDisplayRotationMethod(); - method.invoke(manager, displayId, rotation); + try { + Method method = getFreezeDisplayRotationStringMethod(); + // TODO: specify the String param once we know what it is for + method.invoke(manager, displayId, rotation, ""); + } catch (ReflectiveOperationException e) { + Method method = getFreezeDisplayRotationMethod(); + method.invoke(manager, displayId, rotation); + } } catch (ReflectiveOperationException e) { if (displayId == 0) { Method method = getFreezeRotationMethod(); @@ -142,8 +168,14 @@ public final class WindowManager { public void thawRotation(int displayId) { try { try { - Method method = getThawDisplayRotationMethod(); - method.invoke(manager, displayId); + try { + Method method = getThawDisplayRotationStringMethod(); + // TODO: specify the String param once we know what it is for + method.invoke(manager, displayId, ""); + } catch (ReflectiveOperationException e) { + Method method = getThawDisplayRotationMethod(); + method.invoke(manager, displayId); + } } catch (ReflectiveOperationException e) { if (displayId == 0) { Method method = getThawRotationMethod();