Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix freeze and thaw rotation for Android 15 preview #4740

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
return freezeDisplayRotationMethod;
}

// Android 15 preview and 14 QPR3 Beta introduces a new signature for freeze and thaw rotation
// methods which includes a String caller parameter for debugging:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
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");
Expand Down Expand Up @@ -91,6 +101,16 @@ private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
return thawDisplayRotationMethod;
}

// Android 15 preview and 14 QPR3 Beta introduces a new signature for freeze and thaw rotation
// methods which includes a String caller parameter for debugging:
// <https://android.googlesource.com/platform/frameworks/base/+/670fb7f5c0d23cf51ead25538bcb017e03ed73ac%5E%21/>
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();
Expand All @@ -104,8 +124,13 @@ public int getRotation() {
public void freezeRotation(int displayId, int rotation) {
try {
try {
Method method = getFreezeDisplayRotationMethod();
method.invoke(manager, displayId, rotation);
try {
Method method = getFreezeDisplayRotationStringMethod();
method.invoke(manager, displayId, rotation, "scrcpy#freezeRotation");
} catch (ReflectiveOperationException e) {
Method method = getFreezeDisplayRotationMethod();
method.invoke(manager, displayId, rotation);
}
} catch (ReflectiveOperationException e) {
if (displayId == 0) {
Method method = getFreezeRotationMethod();
Expand Down Expand Up @@ -142,8 +167,13 @@ public boolean isRotationFrozen(int displayId) {
public void thawRotation(int displayId) {
try {
try {
Method method = getThawDisplayRotationMethod();
method.invoke(manager, displayId);
try {
Method method = getThawDisplayRotationStringMethod();
method.invoke(manager, displayId, "scrcpy#thawRotation");
} catch (ReflectiveOperationException e) {
Method method = getThawDisplayRotationMethod();
method.invoke(manager, displayId);
}
} catch (ReflectiveOperationException e) {
if (displayId == 0) {
Method method = getThawRotationMethod();
Expand Down