Keep DisplayManager instance across calls
Do not create a new android.hardware.display.DisplayManager for every creation of a new virtual display.
This commit is contained in:
parent
daba00a819
commit
1b5d88368a
@ -46,6 +46,7 @@ public final class DisplayManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
||||||
|
private android.hardware.display.DisplayManager displayManager;
|
||||||
private Method createVirtualDisplayMethod;
|
private Method createVirtualDisplayMethod;
|
||||||
private Method requestDisplayPowerMethod;
|
private Method requestDisplayPowerMethod;
|
||||||
|
|
||||||
@ -151,17 +152,26 @@ public final class DisplayManager {
|
|||||||
return createVirtualDisplayMethod;
|
return createVirtualDisplayMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int displayIdToMirror, Surface surface) throws Exception {
|
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int displayIdToMirror, Surface surface)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
Method method = getCreateVirtualDisplayMethod();
|
Method method = getCreateVirtualDisplayMethod();
|
||||||
return (VirtualDisplay) method.invoke(null, name, width, height, displayIdToMirror, surface);
|
return (VirtualDisplay) method.invoke(null, name, width, height, displayIdToMirror, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualDisplay createNewVirtualDisplay(String name, int width, int height, int dpi, Surface surface, int flags) throws Exception {
|
private android.hardware.display.DisplayManager getAndroidDisplayManager() throws ReflectiveOperationException {
|
||||||
Constructor<android.hardware.display.DisplayManager> ctor = android.hardware.display.DisplayManager.class.getDeclaredConstructor(
|
if (displayManager == null) {
|
||||||
Context.class);
|
Constructor<android.hardware.display.DisplayManager> ctor = android.hardware.display.DisplayManager.class.getDeclaredConstructor(
|
||||||
ctor.setAccessible(true);
|
Context.class);
|
||||||
android.hardware.display.DisplayManager dm = ctor.newInstance(FakeContext.get());
|
ctor.setAccessible(true);
|
||||||
return dm.createVirtualDisplay(name, width, height, dpi, surface, flags);
|
displayManager = ctor.newInstance(FakeContext.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return displayManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualDisplay createNewVirtualDisplay(String name, int width, int height, int dpi, Surface surface, int flags)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
return getAndroidDisplayManager().createVirtualDisplay(name, width, height, dpi, surface, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getRequestDisplayPowerMethod() throws NoSuchMethodException {
|
private Method getRequestDisplayPowerMethod() throws NoSuchMethodException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user