Fix could not rotate secondary display

pull/4841/head
Kaiming Hu 2 months ago
parent 7011dd1ef0
commit 33e76f6e21

@ -49,7 +49,9 @@ public final class WindowManager {
private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException { private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
if (freezeDisplayRotationMethod == null) { if (freezeDisplayRotationMethod == null) {
try { 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; freezeDisplayRotationMethodVersion = 0;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
try { try {
@ -58,9 +60,7 @@ public final class WindowManager {
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class); freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class);
freezeDisplayRotationMethodVersion = 1; freezeDisplayRotationMethodVersion = 1;
} catch (NoSuchMethodException e1) { } catch (NoSuchMethodException e1) {
// Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging: freezeDisplayRotationMethod = manager.getClass().getMethod("freezeRotation", int.class);
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class, String.class);
freezeDisplayRotationMethodVersion = 2; freezeDisplayRotationMethodVersion = 2;
} }
} }
@ -71,12 +71,12 @@ public final class WindowManager {
private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException { private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException {
if (isDisplayRotationFrozenMethod == null) { if (isDisplayRotationFrozenMethod == null) {
try { try {
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen");
isDisplayRotationFrozenMethodVersion = 0;
} catch (NoSuchMethodException e) {
// New method added by this commit: // New method added by this commit:
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/> // <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isDisplayRotationFrozen", int.class); isDisplayRotationFrozenMethod = manager.getClass().getMethod("isDisplayRotationFrozen", int.class);
isDisplayRotationFrozenMethodVersion = 0;
} catch (NoSuchMethodException e) {
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen");
isDisplayRotationFrozenMethodVersion = 1; isDisplayRotationFrozenMethodVersion = 1;
} }
} }
@ -86,7 +86,9 @@ public final class WindowManager {
private Method getThawDisplayRotationMethod() throws NoSuchMethodException { private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
if (thawDisplayRotationMethod == null) { if (thawDisplayRotationMethod == null) {
try { 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; thawDisplayRotationMethodVersion = 0;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
try { try {
@ -95,9 +97,7 @@ public final class WindowManager {
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class); thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class);
thawDisplayRotationMethodVersion = 1; thawDisplayRotationMethodVersion = 1;
} catch (NoSuchMethodException e1) { } catch (NoSuchMethodException e1) {
// Android 15 preview and 14 QPR3 Beta added a String caller parameter for debugging: thawDisplayRotationMethod = manager.getClass().getMethod("thawRotation");
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class, String.class);
thawDisplayRotationMethodVersion = 2; thawDisplayRotationMethodVersion = 2;
} }
} }
@ -120,17 +120,17 @@ public final class WindowManager {
Method method = getFreezeDisplayRotationMethod(); Method method = getFreezeDisplayRotationMethod();
switch (freezeDisplayRotationMethodVersion) { switch (freezeDisplayRotationMethodVersion) {
case 0: case 0:
if (displayId != 0) { method.invoke(manager, displayId, rotation, "scrcpy#freezeRotation");
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager, rotation);
break; break;
case 1: case 1:
method.invoke(manager, displayId, rotation); method.invoke(manager, displayId, rotation);
break; break;
default: 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; break;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
@ -143,13 +143,13 @@ public final class WindowManager {
Method method = getIsDisplayRotationFrozenMethod(); Method method = getIsDisplayRotationFrozenMethod();
switch (isDisplayRotationFrozenMethodVersion) { switch (isDisplayRotationFrozenMethodVersion) {
case 0: case 0:
return (boolean) method.invoke(manager, displayId);
default:
if (displayId != 0) { if (displayId != 0) {
Ln.e("Secondary display rotation not supported on this device"); Ln.e("Secondary display rotation not supported on this device");
return false; return false;
} }
return (boolean) method.invoke(manager); return (boolean) method.invoke(manager);
default:
return (boolean) method.invoke(manager, displayId);
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
Ln.e("Could not invoke method", e); Ln.e("Could not invoke method", e);
@ -162,17 +162,17 @@ public final class WindowManager {
Method method = getThawDisplayRotationMethod(); Method method = getThawDisplayRotationMethod();
switch (thawDisplayRotationMethodVersion) { switch (thawDisplayRotationMethodVersion) {
case 0: case 0:
if (displayId != 0) { method.invoke(manager, displayId, "scrcpy#thawRotation");
Ln.e("Secondary display rotation not supported on this device");
return;
}
method.invoke(manager);
break; break;
case 1: case 1:
method.invoke(manager, displayId); method.invoke(manager, displayId);
break; break;
default: 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; break;
} }
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {

Loading…
Cancel
Save