1 package com.genymobile.scrcpy.wrappers;
2 
3 import com.genymobile.scrcpy.DisplayInfo;
4 import com.genymobile.scrcpy.Size;
5 
6 import android.os.IInterface;
7 
8 public final class DisplayManager {
9     private final IInterface manager;
10 
DisplayManager(IInterface manager)11     public DisplayManager(IInterface manager) {
12         this.manager = manager;
13     }
14 
getDisplayInfo()15     public DisplayInfo getDisplayInfo() {
16         try {
17             Object displayInfo = manager.getClass().getMethod("getDisplayInfo", int.class).invoke(manager, 0);
18             Class<?> cls = displayInfo.getClass();
19             // width and height already take the rotation into account
20             int width = cls.getDeclaredField("logicalWidth").getInt(displayInfo);
21             int height = cls.getDeclaredField("logicalHeight").getInt(displayInfo);
22             int rotation = cls.getDeclaredField("rotation").getInt(displayInfo);
23             return new DisplayInfo(new Size(width, height), rotation);
24         } catch (Exception e) {
25             throw new AssertionError(e);
26         }
27     }
28 }
29