|
|
@ -12,12 +12,15 @@ import java.lang.reflect.Method;
|
|
|
|
public final class WindowManager {
|
|
|
|
public final class WindowManager {
|
|
|
|
private final IInterface manager;
|
|
|
|
private final IInterface manager;
|
|
|
|
private Method getRotationMethod;
|
|
|
|
private Method getRotationMethod;
|
|
|
|
private Method freezeRotationMethod;
|
|
|
|
|
|
|
|
private Method freezeDisplayRotationMethod;
|
|
|
|
private Method freezeDisplayRotationMethod;
|
|
|
|
private Method isRotationFrozenMethod;
|
|
|
|
private int freezeDisplayRotationMethodVersion;
|
|
|
|
|
|
|
|
|
|
|
|
private Method isDisplayRotationFrozenMethod;
|
|
|
|
private Method isDisplayRotationFrozenMethod;
|
|
|
|
private Method thawRotationMethod;
|
|
|
|
private int isDisplayRotationFrozenMethodVersion;
|
|
|
|
|
|
|
|
|
|
|
|
private Method thawDisplayRotationMethod;
|
|
|
|
private Method thawDisplayRotationMethod;
|
|
|
|
|
|
|
|
private int thawDisplayRotationMethodVersion;
|
|
|
|
|
|
|
|
|
|
|
|
static WindowManager create() {
|
|
|
|
static WindowManager create() {
|
|
|
|
IInterface manager = ServiceManager.getService("window", "android.view.IWindowManager");
|
|
|
|
IInterface manager = ServiceManager.getService("window", "android.view.IWindowManager");
|
|
|
@ -43,50 +46,47 @@ public final class WindowManager {
|
|
|
|
return getRotationMethod;
|
|
|
|
return getRotationMethod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Method getFreezeRotationMethod() throws NoSuchMethodException {
|
|
|
|
|
|
|
|
if (freezeRotationMethod == null) {
|
|
|
|
|
|
|
|
freezeRotationMethod = manager.getClass().getMethod("freezeRotation", int.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return freezeRotationMethod;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// New method added by this commit:
|
|
|
|
|
|
|
|
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
|
|
|
|
|
|
|
|
private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
|
|
|
|
private Method getFreezeDisplayRotationMethod() throws NoSuchMethodException {
|
|
|
|
if (freezeDisplayRotationMethod == null) {
|
|
|
|
if (freezeDisplayRotationMethod == null) {
|
|
|
|
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class);
|
|
|
|
try {
|
|
|
|
|
|
|
|
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeRotation", int.class);
|
|
|
|
|
|
|
|
freezeDisplayRotationMethodVersion = 0;
|
|
|
|
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
|
|
|
|
// New method added by this commit:
|
|
|
|
|
|
|
|
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
|
|
|
|
|
|
|
|
freezeDisplayRotationMethod = manager.getClass().getMethod("freezeDisplayRotation", int.class, int.class);
|
|
|
|
|
|
|
|
freezeDisplayRotationMethodVersion = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return freezeDisplayRotationMethod;
|
|
|
|
return freezeDisplayRotationMethod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Method getIsRotationFrozenMethod() throws NoSuchMethodException {
|
|
|
|
|
|
|
|
if (isRotationFrozenMethod == null) {
|
|
|
|
|
|
|
|
isRotationFrozenMethod = manager.getClass().getMethod("isRotationFrozen");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return isRotationFrozenMethod;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// New method added by this commit:
|
|
|
|
|
|
|
|
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
|
|
|
|
|
|
|
|
private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException {
|
|
|
|
private Method getIsDisplayRotationFrozenMethod() throws NoSuchMethodException {
|
|
|
|
if (isDisplayRotationFrozenMethod == null) {
|
|
|
|
if (isDisplayRotationFrozenMethod == null) {
|
|
|
|
isDisplayRotationFrozenMethod = manager.getClass().getMethod("isDisplayRotationFrozen", int.class);
|
|
|
|
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 = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isDisplayRotationFrozenMethod;
|
|
|
|
return isDisplayRotationFrozenMethod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Method getThawRotationMethod() throws NoSuchMethodException {
|
|
|
|
|
|
|
|
if (thawRotationMethod == null) {
|
|
|
|
|
|
|
|
thawRotationMethod = manager.getClass().getMethod("thawRotation");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return thawRotationMethod;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// New method added by this commit:
|
|
|
|
|
|
|
|
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
|
|
|
|
|
|
|
|
private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
|
|
|
|
private Method getThawDisplayRotationMethod() throws NoSuchMethodException {
|
|
|
|
if (thawDisplayRotationMethod == null) {
|
|
|
|
if (thawDisplayRotationMethod == null) {
|
|
|
|
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class);
|
|
|
|
try {
|
|
|
|
|
|
|
|
thawDisplayRotationMethod = manager.getClass().getMethod("thawRotation");
|
|
|
|
|
|
|
|
thawDisplayRotationMethodVersion = 0;
|
|
|
|
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
|
|
|
|
// New method added by this commit:
|
|
|
|
|
|
|
|
// <https://android.googlesource.com/platform/frameworks/base/+/90c9005e687aa0f63f1ac391adc1e8878ab31759%5E%21/>
|
|
|
|
|
|
|
|
thawDisplayRotationMethod = manager.getClass().getMethod("thawDisplayRotation", int.class);
|
|
|
|
|
|
|
|
thawDisplayRotationMethodVersion = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thawDisplayRotationMethod;
|
|
|
|
return thawDisplayRotationMethod;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,16 +103,18 @@ public final class WindowManager {
|
|
|
|
|
|
|
|
|
|
|
|
public void freezeRotation(int displayId, int rotation) {
|
|
|
|
public void freezeRotation(int displayId, int rotation) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Method method = getFreezeDisplayRotationMethod();
|
|
|
|
Method method = getFreezeDisplayRotationMethod();
|
|
|
|
switch (freezeDisplayRotationMethodVersion) {
|
|
|
|
method.invoke(manager, displayId, rotation);
|
|
|
|
case 0:
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
if (displayId != 0) {
|
|
|
|
if (displayId == 0) {
|
|
|
|
Ln.e("Secondary display rotation not supported on this device");
|
|
|
|
Method method = getFreezeRotationMethod();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
method.invoke(manager, rotation);
|
|
|
|
method.invoke(manager, rotation);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
method.invoke(manager, displayId, rotation);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
@ -121,17 +123,16 @@ public final class WindowManager {
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isRotationFrozen(int displayId) {
|
|
|
|
public boolean isRotationFrozen(int displayId) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Method method = getIsDisplayRotationFrozenMethod();
|
|
|
|
Method method = getIsDisplayRotationFrozenMethod();
|
|
|
|
switch (isDisplayRotationFrozenMethodVersion) {
|
|
|
|
return (boolean) method.invoke(manager, displayId);
|
|
|
|
case 0:
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
if (displayId != 0) {
|
|
|
|
if (displayId == 0) {
|
|
|
|
Ln.e("Secondary display rotation not supported on this device");
|
|
|
|
Method method = getIsRotationFrozenMethod();
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
return (boolean) method.invoke(manager);
|
|
|
|
return (boolean) method.invoke(manager);
|
|
|
|
} else {
|
|
|
|
default:
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
return (boolean) method.invoke(manager, displayId);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
@ -141,16 +142,18 @@ public final class WindowManager {
|
|
|
|
|
|
|
|
|
|
|
|
public void thawRotation(int displayId) {
|
|
|
|
public void thawRotation(int displayId) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Method method = getThawDisplayRotationMethod();
|
|
|
|
Method method = getThawDisplayRotationMethod();
|
|
|
|
switch (thawDisplayRotationMethodVersion) {
|
|
|
|
method.invoke(manager, displayId);
|
|
|
|
case 0:
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
if (displayId != 0) {
|
|
|
|
if (displayId == 0) {
|
|
|
|
Ln.e("Secondary display rotation not supported on this device");
|
|
|
|
Method method = getThawRotationMethod();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
method.invoke(manager);
|
|
|
|
method.invoke(manager);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
method.invoke(manager, displayId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|
Ln.e("Could not invoke method", e);
|
|
|
|