From 803a7e0d866e5a9605008cb1540ebc168d6c2aa2 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 Refs PR #4740 Signed-off-by: Romain Vimont --- .../scrcpy/wrappers/WindowManager.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 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 2fc7ee02..e1a3340a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java @@ -52,10 +52,17 @@ public final class WindowManager { freezeDisplayRotationMethod = manager.getClass().getMethod("freezeRotation", int.class); freezeDisplayRotationMethodVersion = 0; } catch (NoSuchMethodException e) { - // New method added by this commit: - // - freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class); - freezeDisplayRotationMethodVersion = 1; + try { + // New method added by this commit: + // + freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class); + freezeDisplayRotationMethodVersion = 1; + } catch (NoSuchMethodException e1) { + // Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging: + // + freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class, String.class); + freezeDisplayRotationMethodVersion = 2; + } } } return freezeDisplayRotationMethod; @@ -82,10 +89,17 @@ public final class WindowManager { thawDisplayRotationMethod = manager.getClass().getMethod("thawRotation"); thawDisplayRotationMethodVersion = 0; } catch (NoSuchMethodException e) { - // New method added by this commit: - // - thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class); - thawDisplayRotationMethodVersion = 1; + try { + // New method added by this commit: + // + thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class); + thawDisplayRotationMethodVersion = 1; + } catch (NoSuchMethodException e1) { + // Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging: + // + thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class, String.class); + thawDisplayRotationMethodVersion = 2; + } } } return thawDisplayRotationMethod; @@ -112,9 +126,12 @@ public final class WindowManager { } method.invoke(manager, rotation); break; - default: + case 1: method.invoke(manager, displayId, rotation); break; + default: + method.invoke(manager, displayId, rotation, "scrcpy#freezeRotation"); + break; } } catch (ReflectiveOperationException e) { Ln.e("Could not invoke method", e); @@ -151,9 +168,12 @@ public final class WindowManager { } method.invoke(manager); break; - default: + case 1: method.invoke(manager, displayId); break; + default: + method.invoke(manager, displayId, "scrcpy#thawRotation"); + break; } } catch (ReflectiveOperationException e) { Ln.e("Could not invoke method", e);