Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adbb019a authored by Ebru Kurnaz's avatar Ebru Kurnaz Committed by Android (Google) Code Review
Browse files

Merge "Use a bigger range for display size slider if xDpi and yDpi is missing...

Merge "Use a bigger range for display size slider if xDpi and yDpi  is missing for external displays." into main
parents 682bfc3e d7e8292a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -89,6 +89,14 @@
    <fraction name="display_density_max_scale">150%</fraction>
    <!-- Minimum density scale. This is available on all devices. -->
    <fraction name="display_density_min_scale">85%</fraction>
    <!-- Maximum density scale for external displays. -->
    <fraction name="external_display_density_max_scale">150%</fraction>
    <!-- Minimum density scale for external displays. -->
    <fraction name="external_display_density_min_scale">80%</fraction>
    <!-- Maximum density scale for external displays for 9 stops. -->
    <fraction name="external_display_density_max_scale_extended">200%</fraction>
    <!-- Minimum density scale for external displays for 9 stops. -->
    <fraction name="external_display_density_min_scale_extended">50%</fraction>

    <!-- Broadcast dialog -->
    <dimen name="broadcast_dialog_title_img_margin_top">18dp</dimen>
+11 −3
Original line number Diff line number Diff line
@@ -1308,6 +1308,10 @@
    <!-- HTTP proxy settings. The hint text field for the hostname. -->
    <string name="proxy_hostname_hint" translatable="false">proxy.example.com</string>

    <!-- Description for the screen zoom level that makes interface elements smallest. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_smallest">Smallest</string>
    <!-- Description for the screen zoom level that makes interface elements smaller. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_smaller">Smaller</string>
    <!-- Description for the screen zoom level that makes interface elements small. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_small">Small</string>
    <!-- Description for the device's default screen zoom level. [CHAR LIMIT=24] -->
@@ -1315,9 +1319,13 @@
    <!-- Description for the screen zoom level that makes interface elements large. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_large">Large</string>
    <!-- Description for the screen zoom level that makes interface elements larger. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_very_large">Larger</string>
    <!-- Description for the screen zoom level that makes interface elements largest. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_extremely_large">Largest</string>
    <string name="screen_zoom_summary_larger">Larger</string>
    <!-- Description for the screen zoom level that makes interface elements very large. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_very_large">Very Large</string>
    <!-- Description for the screen zoom level that makes interface elements extra large. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_extra_large">Extra Large</string>
    <!-- Description for the screen zoom level that makes interface elements max. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_largest">Largest</string>
    <!-- Description for a custom screen zoom level. This shows the requested display
         density in raw pixels per inch rather than using a relative description. [CHAR LIMIT=24] -->
    <string name="screen_zoom_summary_custom">Custom (<xliff:g id="densityDpi" example="160">%d</xliff:g>)</string>
+50 −10
Original line number Diff line number Diff line
@@ -61,14 +61,28 @@ public class DisplayDensityUtils {
            R.string.screen_zoom_summary_small
    };

    private static final int[] SUMMARIES_SMALLER_EXTENDED = new int[]{
            R.string.screen_zoom_summary_smallest,
            R.string.screen_zoom_summary_smaller,
            R.string.screen_zoom_summary_small
    };

    /**
     * Summaries for scales larger than "default" in order of smallest to
     * largest.
     */
    private static final int[] SUMMARIES_LARGER = new int[]{
            R.string.screen_zoom_summary_large,
            R.string.screen_zoom_summary_larger,
            R.string.screen_zoom_summary_largest,
    };

    private static final int[] SUMMARIES_LARGER_EXTENDED = new int[]{
            R.string.screen_zoom_summary_large,
            R.string.screen_zoom_summary_larger,
            R.string.screen_zoom_summary_very_large,
            R.string.screen_zoom_summary_extremely_large,
            R.string.screen_zoom_summary_extra_large,
            R.string.screen_zoom_summary_largest,
    };

    /**
@@ -181,28 +195,54 @@ public class DisplayDensityUtils {

        final Resources res = context.getResources();

        int currentDensity;
        DisplayInfo currentDisplayInfo;
        if (mPredicate.test(defaultDisplayInfo)) {
            currentDensity = defaultDisplayInfo.logicalDensityDpi;
            currentDisplayInfo = defaultDisplayInfo;
        } else {
            currentDensity = smallestDisplayInfo.logicalDensityDpi;
            currentDisplayInfo = smallestDisplayInfo;
        }
        final int currentDensity = currentDisplayInfo.logicalDensityDpi;
        int currentDensityIndex = -1;

        final int maxScaleFraction;
        final int minScaleFraction;
        final int[] summariesSmaller;
        final int[] summariesLarger;

        if (currentDisplayInfo.type == Display.TYPE_INTERNAL) {
            maxScaleFraction = R.fraction.display_density_max_scale;
            minScaleFraction = R.fraction.display_density_min_scale;
            summariesSmaller = SUMMARIES_SMALLER;
            summariesLarger = SUMMARIES_LARGER;
        } else {
            if (currentDisplayInfo.physicalXDpi > 0 && currentDisplayInfo.physicalYDpi > 0) {
                maxScaleFraction = R.fraction.external_display_density_max_scale;
                minScaleFraction = R.fraction.external_display_density_min_scale;
                summariesSmaller = SUMMARIES_SMALLER;
                summariesLarger = SUMMARIES_LARGER;
            } else {
                // Use bigger range if the display xDPI or yDPI is missing.
                maxScaleFraction = R.fraction.external_display_density_max_scale_extended;
                minScaleFraction = R.fraction.external_display_density_min_scale_extended;
                summariesSmaller = SUMMARIES_SMALLER_EXTENDED;
                summariesLarger = SUMMARIES_LARGER_EXTENDED;
            }
        }

        // Compute number of "larger" and "smaller" scales for this display.
        final int maxDensity =
                DisplayMetrics.DENSITY_MEDIUM * minDimensionPx / MIN_DIMENSION_DP;
        final float maxScaleDimen = context.getResources().getFraction(
                R.fraction.display_density_max_scale, 1, 1);
                maxScaleFraction, 1, 1);
        final float maxScale = Math.min(maxScaleDimen, maxDensity / (float) defaultDensity);
        final float minScale = context.getResources().getFraction(
                R.fraction.display_density_min_scale, 1, 1);
                minScaleFraction, 1, 1);
        final float minScaleInterval = context.getResources().getFraction(
                R.fraction.display_density_min_scale_interval, 1, 1);
        final int numLarger = (int) MathUtils.constrain((maxScale - 1) / minScaleInterval,
                0, SUMMARIES_LARGER.length);
                0, summariesLarger.length);
        final int numSmaller = (int) MathUtils.constrain((1 - minScale) / minScaleInterval,
                0, SUMMARIES_SMALLER.length);
                0, summariesSmaller.length);

        String[] entries = new String[1 + numSmaller + numLarger];
        int[] values = new int[entries.length];
@@ -224,7 +264,7 @@ public class DisplayDensityUtils {
                }
                values[curIndex] = density;
                valuesFloat[curIndex] = densityFloat;
                entries[curIndex] = res.getString(SUMMARIES_SMALLER[i]);
                entries[curIndex] = res.getString(summariesSmaller[i]);
                curIndex++;
            }
        }
@@ -252,7 +292,7 @@ public class DisplayDensityUtils {
                }
                values[curIndex] = density;
                valuesFloat[curIndex] = densityFloat;
                entries[curIndex] = res.getString(SUMMARIES_LARGER[i]);
                entries[curIndex] = res.getString(summariesLarger[i]);
                curIndex++;
            }
        }
+107 −15
Original line number Diff line number Diff line
@@ -49,9 +49,14 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class DisplayDensityUtilsTest {

    private static final float MAX_SCALE = 1.33f;
    private static final float MIN_SCALE = 0.85f;
    private static final float MAX_SCALE_INTERNAL = 1.33f;
    private static final float MIN_SCALE_INTERNAL = 0.85f;
    private static final float MIN_INTERVAL = 0.09f;

    private static final float MAX_SCALE_EXTERNAL = 1.5f;
    private static final float MIN_SCALE_EXTERNAL = 0.8f;
    private static final float MAX_SCALE_EXTERNAL_EXTENDED = 2f;
    private static final float MIN_SCALE_EXTERNAL_EXTENDED = 0.5f;
    @Mock
    private Context mContext;
    @Mock
@@ -72,10 +77,10 @@ public class DisplayDensityUtilsTest {
        mWindowManagerToRestore = WindowManagerGlobal.getWindowManagerService();
        WindowManagerGlobal.setWindowManagerServiceForSystemProcess(mIWindowManager);
        when(mContext.getResources()).thenReturn(mResources);
        when(mResources.getFraction(R.fraction.display_density_max_scale, 1, 1)).thenReturn(
                MAX_SCALE);
        when(mResources.getFraction(R.fraction.display_density_min_scale, 1, 1)).thenReturn(
                MIN_SCALE);
        when(mResources.getFraction(R.fraction.display_density_max_scale, 1, 1))
                .thenReturn(MAX_SCALE_INTERNAL);
        when(mResources.getFraction(R.fraction.display_density_min_scale, 1, 1))
                .thenReturn(MIN_SCALE_INTERNAL);
        when(mResources.getFraction(R.fraction.display_density_min_scale_interval, 1,
                1)).thenReturn(MIN_INTERVAL);
        when(mResources.getString(anyInt())).thenReturn("summary");
@@ -88,8 +93,8 @@ public class DisplayDensityUtilsTest {

    @Test
    public void createDisplayDensityUtil_onlyDefaultDisplay() throws RemoteException {
        var info = createDisplayInfoForDisplay(
                Display.DEFAULT_DISPLAY, Display.TYPE_INTERNAL, 2560, 1600, 320);
        var info = createDisplayInfoForDisplay(Display.DEFAULT_DISPLAY, Display.TYPE_INTERNAL,
                2560, 1600, 320, /* isSizeMissing= */ false);
        var display = new Display(mDisplayManagerGlobal, info.displayId, info,
                (DisplayAdjustments) null);
        doReturn(new Display[]{display}).when(mDisplayManager).getDisplays(any());
@@ -104,7 +109,7 @@ public class DisplayDensityUtilsTest {
    public void createDisplayDensityUtil_multipleInternalDisplays() throws RemoteException {
        // Default display
        var defaultDisplayInfo = createDisplayInfoForDisplay(Display.DEFAULT_DISPLAY,
                Display.TYPE_INTERNAL, 2000, 2000, 390);
                Display.TYPE_INTERNAL, 2000, 2000, 390, false);
        var defaultDisplay = new Display(mDisplayManagerGlobal, defaultDisplayInfo.displayId,
                defaultDisplayInfo,
                (DisplayAdjustments) null);
@@ -112,7 +117,7 @@ public class DisplayDensityUtilsTest {

        // Create another internal display
        var internalDisplayInfo = createDisplayInfoForDisplay(1, Display.TYPE_INTERNAL,
                2000, 1000, 390);
                2000, 1000, 390, /* isSizeMissing= */ false);
        var internalDisplay = new Display(mDisplayManagerGlobal, internalDisplayInfo.displayId,
                internalDisplayInfo,
                (DisplayAdjustments) null);
@@ -128,17 +133,96 @@ public class DisplayDensityUtilsTest {

    @Test
    public void createDisplayDensityUtil_forExternalDisplay() throws RemoteException {
        // Configure resources
        when(mResources.getFraction(R.fraction.external_display_density_max_scale,
                1, 1)).thenReturn(MAX_SCALE_EXTERNAL);
        when(mResources.getFraction(R.fraction.external_display_density_min_scale,
                1, 1)).thenReturn(MIN_SCALE_EXTERNAL);
        // Default display
        var defaultDisplayInfo = createDisplayInfoForDisplay(Display.DEFAULT_DISPLAY,
                Display.TYPE_INTERNAL, 2000, 2000, 390);
        var defaultDisplayInfo = createDisplayInfoForDisplay(
                Display.DEFAULT_DISPLAY, Display.TYPE_INTERNAL, 2000, 2000,
                390, /* isSizeMissing= */ false);
        var defaultDisplay = new Display(mDisplayManagerGlobal, defaultDisplayInfo.displayId,
                defaultDisplayInfo,
                (DisplayAdjustments) null);
        doReturn(defaultDisplay).when(mDisplayManager).getDisplay(defaultDisplayInfo.displayId);

        // Create external display
        var externalDisplayInfo = createDisplayInfoForDisplay(
                /* displayId= */ 2, Display.TYPE_EXTERNAL, 1920, 1080,
                85, /* isSizeMissing= */ false);
        var externalDisplay = new Display(mDisplayManagerGlobal, externalDisplayInfo.displayId,
                externalDisplayInfo,
                (DisplayAdjustments) null);

        doReturn(new Display[]{externalDisplay, defaultDisplay}).when(mDisplayManager).getDisplays(
                any());
        doReturn(externalDisplay).when(mDisplayManager).getDisplay(externalDisplayInfo.displayId);

        mDisplayDensityUtils = new DisplayDensityUtils(mContext,
                (info) -> info.displayId == externalDisplayInfo.displayId);

        assertThat(mDisplayDensityUtils.getValues()).isEqualTo(new int[]{68, 85, 98, 112, 126});
    }

    @Test
    public void createDisplayDensityUtil_forExternalDisplay_displaySizeMissing()
            throws RemoteException {
        // Configure resources
        when(mResources.getFraction(R.fraction.external_display_density_max_scale_extended,
                1, 1)).thenReturn(MAX_SCALE_EXTERNAL_EXTENDED);
        when(mResources.getFraction(R.fraction.external_display_density_min_scale_extended,
                1, 1)).thenReturn(MIN_SCALE_EXTERNAL_EXTENDED);
        // Default display
        var defaultDisplayInfo = createDisplayInfoForDisplay(
                Display.DEFAULT_DISPLAY, Display.TYPE_INTERNAL, 2000, 2000,
                390, /* isSizeMissing= */ false);
        var defaultDisplay = new Display(mDisplayManagerGlobal, defaultDisplayInfo.displayId,
                defaultDisplayInfo,
                (DisplayAdjustments) null);
        doReturn(defaultDisplay).when(mDisplayManager).getDisplay(defaultDisplayInfo.displayId);

        // Create external display
        var externalDisplayInfo = createDisplayInfoForDisplay(
                /* displayId= */ 2, Display.TYPE_EXTERNAL, 1920, 1080,
                85, /* isSizeMissing= */true);
        var externalDisplay = new Display(mDisplayManagerGlobal, externalDisplayInfo.displayId,
                externalDisplayInfo,
                (DisplayAdjustments) null);

        doReturn(new Display[]{externalDisplay, defaultDisplay}).when(mDisplayManager).getDisplays(
                any());
        doReturn(externalDisplay).when(mDisplayManager).getDisplay(externalDisplayInfo.displayId);

        mDisplayDensityUtils = new DisplayDensityUtils(mContext,
                (info) -> info.displayId == externalDisplayInfo.displayId);

        assertThat(mDisplayDensityUtils.getValues())
                .isEqualTo(new int[]{42, 56, 70, 85, 102, 118, 136, 152, 170});
    }


    @Test
    public void createDisplayDensityUtil_forExternalDisplay_lowerMaxScale()
            throws RemoteException {
        // Configure resources
        when(mResources.getFraction(R.fraction.external_display_density_max_scale_extended,
                1, 1)).thenReturn(MAX_SCALE_EXTERNAL_EXTENDED);
        when(mResources.getFraction(R.fraction.external_display_density_min_scale_extended,
                1, 1)).thenReturn(MIN_SCALE_EXTERNAL_EXTENDED);
        // Default display
        var defaultDisplayInfo = createDisplayInfoForDisplay(
                Display.DEFAULT_DISPLAY, Display.TYPE_INTERNAL, 2000, 2000,
                390, /* isSizeMissing= */ false);
        var defaultDisplay = new Display(mDisplayManagerGlobal, defaultDisplayInfo.displayId,
                defaultDisplayInfo,
                (DisplayAdjustments) null);
        doReturn(defaultDisplay).when(mDisplayManager).getDisplay(defaultDisplayInfo.displayId);

        // Create external display with low resolution to test the case where max scale value is
        // calculated from the maxDensity / defaultDensity instead of the fraction constant.
        var externalDisplayInfo = createDisplayInfoForDisplay(/* displayId= */ 2,
                Display.TYPE_EXTERNAL, 1920, 1080, 85);
                Display.TYPE_EXTERNAL, 240, 240, 85, /* isSizeMissing= */ true);
        var externalDisplay = new Display(mDisplayManagerGlobal, externalDisplayInfo.displayId,
                externalDisplayInfo,
                (DisplayAdjustments) null);
@@ -150,17 +234,25 @@ public class DisplayDensityUtilsTest {
        mDisplayDensityUtils = new DisplayDensityUtils(mContext,
                (info) -> info.displayId == externalDisplayInfo.displayId);

        assertThat(mDisplayDensityUtils.getValues()).isEqualTo(new int[]{72, 85, 94, 102, 112});
        assertThat(mDisplayDensityUtils.getValues())
                .isEqualTo(new int[]{42, 56, 70, 85, 92, 102, 110, 120});
    }

    private DisplayInfo createDisplayInfoForDisplay(int displayId, int displayType,
            int width, int height, int density) throws RemoteException {
            int width, int height, int density, boolean isSizeMissing) throws RemoteException {
        var displayInfo = new DisplayInfo();
        displayInfo.displayId = displayId;
        displayInfo.type = displayType;
        displayInfo.logicalWidth = width;
        displayInfo.logicalHeight = height;
        displayInfo.logicalDensityDpi = density;
        if (isSizeMissing) {
            displayInfo.physicalYDpi = 0;
            displayInfo.physicalXDpi = 0;
        } else {
            displayInfo.physicalXDpi = 100;
            displayInfo.physicalYDpi = 100;
        }

        doReturn(displayInfo).when(mDisplayManagerGlobal).getDisplayInfo(displayInfo.displayId);
        doReturn(displayInfo.logicalDensityDpi).when(mIWindowManager).getInitialDisplayDensity(
+5 −0
Original line number Diff line number Diff line
# Default reviewers for this and subdirectories.
pbdr@google.com
ebrukurnaz@google.com
lihongyu@google.com
wilczynskip@google.com