From 25c4276ba95f431c5f334484f16013149b82232e Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 16 Apr 2024 19:31:31 -0700 Subject: [PATCH] Making moving getDisplayType to DisplayController so that it can be accessed without IDP Bug: 335280439 Test: Presubmit Flag: None Change-Id: Ib1ef3c970a56044c81e36c4af67981715fe50a9e --- .../launcher3/InvariantDeviceProfile.java | 23 +++---------------- .../launcher3/util/DisplayController.java | 21 +++++++++++++++++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index bc3633660d..7087d3b1ba 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -263,7 +263,7 @@ public class InvariantDeviceProfile { // Get the display info based on default display and interpolate it to existing display Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int defaultDeviceType = getDeviceType(defaultInfo); + @DeviceType int defaultDeviceType = defaultInfo.getDeviceType(); DisplayOption defaultDisplayOption = invDistWeightedInterpolate( defaultInfo, getPredefinedDeviceProfiles(context, gridName, defaultDeviceType, @@ -272,7 +272,7 @@ public class InvariantDeviceProfile { Context displayContext = context.createDisplayContext(display); Info myInfo = new Info(displayContext); - @DeviceType int deviceType = getDeviceType(myInfo); + @DeviceType int deviceType = myInfo.getDeviceType(); DisplayOption myDisplayOption = invDistWeightedInterpolate( myInfo, getPredefinedDeviceProfiles(context, gridName, deviceType, @@ -325,30 +325,13 @@ public class InvariantDeviceProfile { } } - private static @DeviceType int getDeviceType(Info displayInfo) { - int flagPhone = 1 << 0; - int flagTablet = 1 << 1; - - int type = displayInfo.supportedBounds.stream() - .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone) - .reduce(0, (a, b) -> a | b); - if (type == (flagPhone | flagTablet)) { - // device has profiles supporting both phone and table modes - return TYPE_MULTI_DISPLAY; - } else if (type == flagTablet) { - return TYPE_TABLET; - } else { - return TYPE_PHONE; - } - } - public static String getCurrentGridName(Context context) { return LauncherPrefs.get(context).get(GRID_NAME); } private String initGrid(Context context, String gridName) { Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int deviceType = getDeviceType(displayInfo); + @DeviceType int deviceType = displayInfo.getDeviceType(); ArrayList allOptions = getPredefinedDeviceProfiles(context, gridName, deviceType, diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index ff9521282d..8806e273ae 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -19,6 +19,9 @@ import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; +import static com.android.launcher3.InvariantDeviceProfile.TYPE_MULTI_DISPLAY; +import static com.android.launcher3.InvariantDeviceProfile.TYPE_PHONE; +import static com.android.launcher3.InvariantDeviceProfile.TYPE_TABLET; import static com.android.launcher3.LauncherPrefs.TASKBAR_PINNING; import static com.android.launcher3.LauncherPrefs.TASKBAR_PINNING_KEY; import static com.android.launcher3.Utilities.dpiFromPx; @@ -47,6 +50,7 @@ import androidx.annotation.AnyThread; import androidx.annotation.UiThread; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.InvariantDeviceProfile.DeviceType; import com.android.launcher3.LauncherPrefs; import com.android.launcher3.Utilities; import com.android.launcher3.logging.FileLog; @@ -466,6 +470,23 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { public int getDensityDpi() { return densityDpi; } + + public @DeviceType int getDeviceType() { + int flagPhone = 1 << 0; + int flagTablet = 1 << 1; + + int type = supportedBounds.stream() + .mapToInt(bounds -> isTablet(bounds) ? flagTablet : flagPhone) + .reduce(0, (a, b) -> a | b); + if (type == (flagPhone | flagTablet)) { + // device has profiles supporting both phone and tablet modes + return TYPE_MULTI_DISPLAY; + } else if (type == flagTablet) { + return TYPE_TABLET; + } else { + return TYPE_PHONE; + } + } } /**