summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src
diff options
context:
space:
mode:
author Ebru Kurnaz <ebrukurnaz@google.com> 2025-02-17 03:15:03 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-02-17 03:15:03 -0800
commitbe2e1be658580da6ad639c75a6f08e626cebeca7 (patch)
treeec43e9fb16ad3b706ee76171c2113ac3ca87c67a /packages/SettingsLib/src
parent6633d0a79ab3b8f10194962629e0995584a05ad1 (diff)
parentff6cc5c4cbb5c62a9d311834432d054d704829ac (diff)
Merge "Update density util to allow calling the util for external displays." into main
Diffstat (limited to 'packages/SettingsLib/src')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java50
1 files changed, 31 insertions, 19 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java b/packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java
index 58e9355800d7..985599c952d1 100644
--- a/packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java
@@ -57,7 +57,7 @@ public class DisplayDensityUtils {
* Summaries for scales smaller than "default" in order of smallest to
* largest.
*/
- private static final int[] SUMMARIES_SMALLER = new int[] {
+ private static final int[] SUMMARIES_SMALLER = new int[]{
R.string.screen_zoom_summary_small
};
@@ -65,7 +65,7 @@ public class DisplayDensityUtils {
* Summaries for scales larger than "default" in order of smallest to
* largest.
*/
- private static final int[] SUMMARIES_LARGER = new int[] {
+ private static final int[] SUMMARIES_LARGER = new int[]{
R.string.screen_zoom_summary_large,
R.string.screen_zoom_summary_very_large,
R.string.screen_zoom_summary_extremely_large,
@@ -108,7 +108,8 @@ public class DisplayDensityUtils {
* Creates an instance that stores the density values for the smallest display that satisfies
* the predicate. It is enough to store the values for one display because the same density
* should be set to all the displays that satisfy the predicate.
- * @param context The context
+ *
+ * @param context The context
* @param predicate Determines what displays the density should be set for. The default display
* must satisfy this predicate.
*/
@@ -127,14 +128,10 @@ public class DisplayDensityUtils {
mCurrentIndex = -1;
return;
}
- if (!mPredicate.test(defaultDisplayInfo)) {
- throw new IllegalArgumentException(
- "Predicate must not filter out the default display.");
- }
- int idOfSmallestDisplay = Display.DEFAULT_DISPLAY;
- int minDimensionPx = Math.min(defaultDisplayInfo.logicalWidth,
- defaultDisplayInfo.logicalHeight);
+ int idOfSmallestDisplay = Display.INVALID_DISPLAY;
+ int minDimensionPx = Integer.MAX_VALUE;
+ DisplayInfo smallestDisplayInfo = null;
for (Display display : mDisplayManager.getDisplays(
DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED)) {
DisplayInfo info = new DisplayInfo();
@@ -149,9 +146,19 @@ public class DisplayDensityUtils {
if (minDimension < minDimensionPx) {
minDimensionPx = minDimension;
idOfSmallestDisplay = display.getDisplayId();
+ smallestDisplayInfo = info;
}
}
+ if (smallestDisplayInfo == null) {
+ Log.w(LOG_TAG, "No display satisfies the predicate");
+ mEntries = null;
+ mValues = null;
+ mDefaultDensity = 0;
+ mCurrentIndex = -1;
+ return;
+ }
+
final int defaultDensity =
DisplayDensityUtils.getDefaultDensityForDisplay(idOfSmallestDisplay);
if (defaultDensity <= 0) {
@@ -165,7 +172,12 @@ public class DisplayDensityUtils {
final Resources res = context.getResources();
- final int currentDensity = defaultDisplayInfo.logicalDensityDpi;
+ int currentDensity;
+ if (mPredicate.test(defaultDisplayInfo)) {
+ currentDensity = defaultDisplayInfo.logicalDensityDpi;
+ } else {
+ currentDensity = smallestDisplayInfo.logicalDensityDpi;
+ }
int currentDensityIndex = -1;
// Compute number of "larger" and "smaller" scales for this display.
@@ -266,16 +278,16 @@ public class DisplayDensityUtils {
* Returns the default density for the specified display.
*
* @param displayId the identifier of the display
- * @return the default density of the specified display, or {@code -1} if
- * the display does not exist or the density could not be obtained
+ * @return the default density of the specified display, or {@code -1} if the display does not
+ * exist or the density could not be obtained
*/
private static int getDefaultDensityForDisplay(int displayId) {
- try {
- final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
- return wm.getInitialDisplayDensity(displayId);
- } catch (RemoteException exc) {
- return -1;
- }
+ try {
+ final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
+ return wm.getInitialDisplayDensity(displayId);
+ } catch (RemoteException exc) {
+ return -1;
+ }
}
/**