Display and control your Android device
Add DPI to DisplayInfo
Romain Vimont5d0e012a4c19
diff --git a/server/src/main/java/com/genymobile/scrcpy/device/DisplayInfo.java b/server/src/main/java/com/genymobile/scrcpy/device/DisplayInfo.javaindex 2973710d..cdd4bab9 100644--- a/server/src/main/java/com/genymobile/scrcpy/device/DisplayInfo.java+++ b/server/src/main/java/com/genymobile/scrcpy/device/DisplayInfo.java@@ -6,15 +6,17 @@ public final class DisplayInfo {private final int rotation;private final int layerStack;private final int flags;+ private final int dpi;public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 0x00000001;- public DisplayInfo(int displayId, Size size, int rotation, int layerStack, int flags) {+ public DisplayInfo(int displayId, Size size, int rotation, int layerStack, int flags, int dpi) {this.displayId = displayId;this.size = size;this.rotation = rotation;this.layerStack = layerStack;this.flags = flags;+ this.dpi = dpi;}public int getDisplayId() {@@ -36,5 +38,9 @@ public final class DisplayInfo {public int getFlags() {return flags;}++ public int getDpi() {+ return dpi;+ }}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.javaindex 00a39274..b91b7146 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java@@ -39,7 +39,7 @@ public final class DisplayManager {public static DisplayInfo parseDisplayInfo(String dumpsysDisplayOutput, int displayId) {Pattern regex = Pattern.compile("^ mOverrideDisplayInfo=DisplayInfo\\{\".*?, displayId " + displayId + ".*?(, FLAG_.*)?, real ([0-9]+) x ([0-9]+).*?, "- + "rotation ([0-9]+).*?, layerStack ([0-9]+)",+ + "rotation ([0-9]+).*?, density ([0-9]+).*?, layerStack ([0-9]+)",Pattern.MULTILINE);Matcher m = regex.matcher(dumpsysDisplayOutput);if (!m.find()) {@@ -49,9 +49,10 @@ public final class DisplayManager {int width = Integer.parseInt(m.group(2));int height = Integer.parseInt(m.group(3));int rotation = Integer.parseInt(m.group(4));- int layerStack = Integer.parseInt(m.group(5));+ int density = Integer.parseInt(m.group(5));+ int layerStack = Integer.parseInt(m.group(6));- return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags);+ return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags, density);}private static DisplayInfo getDisplayInfoFromDumpsysDisplay(int displayId) {@@ -98,7 +99,8 @@ public final class DisplayManager {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);+ int dpi = cls.getDeclaredField("logicalDensityDpi").getInt(displayInfo);+ return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags, dpi);} catch (ReflectiveOperationException e) {throw new AssertionError(e);}