mirror of
https://github.com/Genymobile/scrcpy
synced 2025-08-22 01:47:37 +00:00
Cache getDisplayInfo method
Do not use reflection to retrieve the method for every call. PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009>
This commit is contained in:
parent
41ed40f5f9
commit
ee414231ed
@ -46,6 +46,7 @@ public final class DisplayManager {
|
||||
}
|
||||
|
||||
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
|
||||
private Method getDisplayInfoMethod;
|
||||
private Method createVirtualDisplayMethod;
|
||||
private Method requestDisplayPowerMethod;
|
||||
|
||||
@ -114,9 +115,17 @@ public final class DisplayManager {
|
||||
return flags;
|
||||
}
|
||||
|
||||
private Method getGetDisplayInfoMethod() throws NoSuchMethodException {
|
||||
if (getDisplayInfoMethod == null) {
|
||||
getDisplayInfoMethod = manager.getClass().getMethod("getDisplayInfo", int.class);
|
||||
}
|
||||
return getDisplayInfoMethod;
|
||||
}
|
||||
|
||||
public DisplayInfo getDisplayInfo(int displayId) {
|
||||
try {
|
||||
Object displayInfo = manager.getClass().getMethod("getDisplayInfo", int.class).invoke(manager, displayId);
|
||||
Method method = getGetDisplayInfoMethod();
|
||||
Object displayInfo = method.invoke(manager, displayId);
|
||||
if (displayInfo == null) {
|
||||
// fallback when displayInfo is null
|
||||
return getDisplayInfoFromDumpsysDisplay(displayId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user