mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-21 09:49:06 +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
1 changed files with 10 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue