This commit is contained in:
Romain Vimont 2024-10-06 19:05:03 +02:00
parent 6ddcc98663
commit 9434718970
2 changed files with 13 additions and 5 deletions

View File

@ -6,15 +6,17 @@ public final class DisplayInfo {
private final int rotation; private final int rotation;
private final int layerStack; private final int layerStack;
private final int flags; private final int flags;
private final int logicalDensityDpi;
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 0x00000001; 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 logicalDensityDpi) {
this.displayId = displayId; this.displayId = displayId;
this.size = size; this.size = size;
this.rotation = rotation; this.rotation = rotation;
this.layerStack = layerStack; this.layerStack = layerStack;
this.flags = flags; this.flags = flags;
this.logicalDensityDpi = logicalDensityDpi;
} }
public int getDisplayId() { public int getDisplayId() {
@ -36,5 +38,9 @@ public final class DisplayInfo {
public int getFlags() { public int getFlags() {
return flags; return flags;
} }
public int getLogicalDensityDpi() {
return logicalDensityDpi;
}
} }

View File

@ -39,7 +39,7 @@ public final class DisplayManager {
public static DisplayInfo parseDisplayInfo(String dumpsysDisplayOutput, int displayId) { public static DisplayInfo parseDisplayInfo(String dumpsysDisplayOutput, int displayId) {
Pattern regex = Pattern.compile( Pattern regex = Pattern.compile(
"^ mOverrideDisplayInfo=DisplayInfo\\{\".*?, displayId " + displayId + ".*?(, FLAG_.*)?, real ([0-9]+) x ([0-9]+).*?, " "^ 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); Pattern.MULTILINE);
Matcher m = regex.matcher(dumpsysDisplayOutput); Matcher m = regex.matcher(dumpsysDisplayOutput);
if (!m.find()) { if (!m.find()) {
@ -49,9 +49,10 @@ public final class DisplayManager {
int width = Integer.parseInt(m.group(2)); int width = Integer.parseInt(m.group(2));
int height = Integer.parseInt(m.group(3)); int height = Integer.parseInt(m.group(3));
int rotation = Integer.parseInt(m.group(4)); 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) { private static DisplayInfo getDisplayInfoFromDumpsysDisplay(int displayId) {
@ -98,7 +99,8 @@ public final class DisplayManager {
int rotation = cls.getDeclaredField("rotation").getInt(displayInfo); int rotation = cls.getDeclaredField("rotation").getInt(displayInfo);
int layerStack = cls.getDeclaredField("layerStack").getInt(displayInfo); int layerStack = cls.getDeclaredField("layerStack").getInt(displayInfo);
int flags = cls.getDeclaredField("flags").getInt(displayInfo); int flags = cls.getDeclaredField("flags").getInt(displayInfo);
return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags); int logicalDensityDpi = cls.getDeclaredField("logicalDensityDpi").getInt(displayInfo);
return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags, logicalDensityDpi);
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }