Loading services/core/java/com/android/server/display/LocalDisplayAdapter.java +17 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,8 @@ final class LocalDisplayAdapter extends DisplayAdapter { private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.boot.emulator.circular"; private static final double DEFAULT_DISPLAY_SIZE = 24.0; private final LongSparseArray<LocalDisplayDevice> mDevices = new LongSparseArray<>(); private final Injector mInjector; Loading Loading @@ -526,6 +528,21 @@ final class LocalDisplayAdapter extends DisplayAdapter { private int getLogicalDensity() { DensityMapping densityMapping = getDisplayDeviceConfig().getDensityMapping(); if (densityMapping == null) { if (getFeatureFlags().isBaseDensityForExternalDisplaysEnabled() && !mStaticDisplayInfo.isInternal) { double dpi; if (mActiveSfDisplayMode.xDpi > 0 && mActiveSfDisplayMode.yDpi > 0) { dpi = Math.sqrt((Math.pow(mActiveSfDisplayMode.xDpi, 2) + Math.pow(mActiveSfDisplayMode.yDpi, 2)) / 2); } else { // xDPI and yDPI is missing, calculate DPI from display resolution and // default display size dpi = Math.sqrt(Math.pow(mInfo.width, 2) + Math.pow(mInfo.height, 2)) / DEFAULT_DISPLAY_SIZE; } return (int) (dpi + 0.5); } return (int) (mStaticDisplayInfo.density * 160 + 0.5); } Loading services/tests/displayservicetests/src/com/android/server/display/LocalDisplayAdapterTest.java +21 −1 Original line number Diff line number Diff line Loading @@ -455,8 +455,9 @@ public class LocalDisplayAdapterTest { * Confirm that external display uses physical density. */ @Test public void testDpiValues() throws Exception { public void testDpiValues_baseDensityForExternalDisplaysDisabled() throws Exception { // needs default one always doReturn(false).when(mFlags).isBaseDensityForExternalDisplaysEnabled(); setUpDisplay(new FakeDisplay(PORT_A)); setUpDisplay(new FakeDisplay(PORT_B)); updateAvailableDisplays(); Loading @@ -472,6 +473,25 @@ public class LocalDisplayAdapterTest { 16000); } @Test public void testDpiValues_baseDensityForExternalDisplaysEnabled() throws Exception { // needs default one always doReturn(true).when(mFlags).isBaseDensityForExternalDisplaysEnabled(); setUpDisplay(new FakeDisplay(PORT_A)); setUpDisplay(new FakeDisplay(PORT_B)); updateAvailableDisplays(); mAdapter.registerLocked(); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); assertDisplayDpi( mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, 100, 100, 100); assertDisplayDpi( mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, 100, 100, 100); } private static class DisplayModeWrapper { public SurfaceControl.DisplayMode mode; public float[] expectedAlternativeRefreshRates; Loading Loading
services/core/java/com/android/server/display/LocalDisplayAdapter.java +17 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,8 @@ final class LocalDisplayAdapter extends DisplayAdapter { private static final String PROPERTY_EMULATOR_CIRCULAR = "ro.boot.emulator.circular"; private static final double DEFAULT_DISPLAY_SIZE = 24.0; private final LongSparseArray<LocalDisplayDevice> mDevices = new LongSparseArray<>(); private final Injector mInjector; Loading Loading @@ -526,6 +528,21 @@ final class LocalDisplayAdapter extends DisplayAdapter { private int getLogicalDensity() { DensityMapping densityMapping = getDisplayDeviceConfig().getDensityMapping(); if (densityMapping == null) { if (getFeatureFlags().isBaseDensityForExternalDisplaysEnabled() && !mStaticDisplayInfo.isInternal) { double dpi; if (mActiveSfDisplayMode.xDpi > 0 && mActiveSfDisplayMode.yDpi > 0) { dpi = Math.sqrt((Math.pow(mActiveSfDisplayMode.xDpi, 2) + Math.pow(mActiveSfDisplayMode.yDpi, 2)) / 2); } else { // xDPI and yDPI is missing, calculate DPI from display resolution and // default display size dpi = Math.sqrt(Math.pow(mInfo.width, 2) + Math.pow(mInfo.height, 2)) / DEFAULT_DISPLAY_SIZE; } return (int) (dpi + 0.5); } return (int) (mStaticDisplayInfo.density * 160 + 0.5); } Loading
services/tests/displayservicetests/src/com/android/server/display/LocalDisplayAdapterTest.java +21 −1 Original line number Diff line number Diff line Loading @@ -455,8 +455,9 @@ public class LocalDisplayAdapterTest { * Confirm that external display uses physical density. */ @Test public void testDpiValues() throws Exception { public void testDpiValues_baseDensityForExternalDisplaysDisabled() throws Exception { // needs default one always doReturn(false).when(mFlags).isBaseDensityForExternalDisplaysEnabled(); setUpDisplay(new FakeDisplay(PORT_A)); setUpDisplay(new FakeDisplay(PORT_B)); updateAvailableDisplays(); Loading @@ -472,6 +473,25 @@ public class LocalDisplayAdapterTest { 16000); } @Test public void testDpiValues_baseDensityForExternalDisplaysEnabled() throws Exception { // needs default one always doReturn(true).when(mFlags).isBaseDensityForExternalDisplaysEnabled(); setUpDisplay(new FakeDisplay(PORT_A)); setUpDisplay(new FakeDisplay(PORT_B)); updateAvailableDisplays(); mAdapter.registerLocked(); waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); assertDisplayDpi( mListener.addedDisplays.get(0).getDisplayDeviceInfoLocked(), PORT_A, 100, 100, 100); assertDisplayDpi( mListener.addedDisplays.get(1).getDisplayDeviceInfoLocked(), PORT_B, 100, 100, 100); } private static class DisplayModeWrapper { public SurfaceControl.DisplayMode mode; public float[] expectedAlternativeRefreshRates; Loading