mirror of https://github.com/Genymobile/scrcpy
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
Java
40 lines
1.5 KiB
Java
package com.genymobile.scrcpy.wrappers;
|
|
|
|
import com.genymobile.scrcpy.DisplayInfo;
|
|
import com.genymobile.scrcpy.Size;
|
|
|
|
public final class DisplayManager {
|
|
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
|
|
|
public DisplayManager(Object manager) {
|
|
this.manager = manager;
|
|
}
|
|
|
|
public DisplayInfo getDisplayInfo(int displayId) {
|
|
try {
|
|
Object displayInfo = manager.getClass().getMethod("getDisplayInfo", int.class).invoke(manager, displayId);
|
|
if (displayInfo == null) {
|
|
return null;
|
|
}
|
|
Class<?> cls = displayInfo.getClass();
|
|
// width and height already take the rotation into account
|
|
int width = cls.getDeclaredField("logicalWidth").getInt(displayInfo);
|
|
int height = cls.getDeclaredField("logicalHeight").getInt(displayInfo);
|
|
int rotation = cls.getDeclaredField("rotation").getInt(displayInfo);
|
|
int layerStack = cls.getDeclaredField("layerStack").getInt(displayInfo);
|
|
int flags = cls.getDeclaredField("flags").getInt(displayInfo);
|
|
return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags);
|
|
} catch (Exception e) {
|
|
throw new AssertionError(e);
|
|
}
|
|
}
|
|
|
|
public int[] getDisplayIds() {
|
|
try {
|
|
return (int[]) manager.getClass().getMethod("getDisplayIds").invoke(manager);
|
|
} catch (Exception e) {
|
|
throw new AssertionError(e);
|
|
}
|
|
}
|
|
}
|