Skip to content

Commit

Permalink
Fix could not rotate secondary display
Browse files Browse the repository at this point in the history
The version of the methods with the display id parameter must be tried
first, otherwise they will never be used (since the old versions without
the display id are still present).

Regression introduced by ee6620d.

Refs #4740 <#4740>
PR #4841 <#4841>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
eiyooooo authored and rom1v committed Apr 12, 2024
1 parent 7011dd1 commit a73bf93
Showing 1 changed file with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ private Method getGetRotationMethod() throws NoSuchMethodException {
private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
if (freezeDisplayRotationMethod == null) {
try {
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeRotation", int.class);
// Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class, String.class);
freezeDisplayRotationMethodVersion = 0;
} catch (NoSuchMethodException e) {
try {
Expand All @@ -58,9 +60,7 @@ private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
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:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class, String.class);
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeRotation", int.class);
freezeDisplayRotationMethodVersion = 2;
}
}
Expand All @@ -71,12 +71,12 @@ private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException {
if (isDisplayRotationFrozenMethod == null) {
try {
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen");
isDisplayRotationFrozenMethodVersion = 0;
} catch (NoSuchMethodException e) {
// New method added by this commit:
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isDisplayRotationFrozen", int.class);
isDisplayRotationFrozenMethodVersion = 0;
} catch (NoSuchMethodException e) {
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen");
isDisplayRotationFrozenMethodVersion = 1;
}
}
Expand All @@ -86,7 +86,9 @@ private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException {
private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
if (thawDisplayRotationMethod == null) {
try {
thawDisplayRotationMethod = manager.getClass().getMethod("thawRotation");
// Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class, String.class);
thawDisplayRotationMethodVersion = 0;
} catch (NoSuchMethodException e) {
try {
Expand All @@ -95,9 +97,7 @@ private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
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:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class, String.class);
thawDisplayRotationMethod = manager.getClass().getMethod("thawRotation");
thawDisplayRotationMethodVersion = 2;
}
}
Expand All @@ -120,17 +120,17 @@ public void freezeRotation(int displayId, int rotation) {
Method method = getFreezeDisplayRotationMethod();
switch (freezeDisplayRotationMethodVersion) {
case 0:
if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager, rotation);
method.invoke(manager, displayId, rotation, "scrcpy#freezeRotation");
break;
case 1:
method.invoke(manager, displayId, rotation);
break;
default:
method.invoke(manager, displayId, rotation, "scrcpy#freezeRotation");
if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager, rotation);
break;
}
} catch (ReflectiveOperationException e) {
Expand All @@ -143,13 +143,13 @@ public boolean isRotationFrozen(int displayId) {
Method method = getIsDisplayRotationFrozenMethod();
switch (isDisplayRotationFrozenMethodVersion) {
case 0:
return (boolean) method.invoke(manager, displayId);
default:
if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device");
return false;
}
return (boolean) method.invoke(manager);
default:
return (boolean) method.invoke(manager, displayId);
}
} catch (ReflectiveOperationException e) {
Ln.e("Could not invoke method", e);
Expand All @@ -162,17 +162,17 @@ public void thawRotation(int displayId) {
Method method = getThawDisplayRotationMethod();
switch (thawDisplayRotationMethodVersion) {
case 0:
if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager);
method.invoke(manager, displayId, "scrcpy#thawRotation");
break;
case 1:
method.invoke(manager, displayId);
break;
default:
method.invoke(manager, displayId, "scrcpy#thawRotation");
if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager);
break;
}
} catch (ReflectiveOperationException e) {
Expand Down

0 comments on commit a73bf93

Please sign in to comment.