From 501df846c41c4e2a431c01c67b9cc33aad134ebe Mon Sep 17 00:00:00 2001 From: Ana Salazar Date: Thu, 23 Jan 2025 00:23:36 +0000 Subject: [PATCH] Support desktop device category in grid options Adds desktop enum value to grid option deviceCategory attribute type. The device type is used for devices that have `R.bool.desktop_form_factor` config value set. Bug: 30153091 Flag: com.android.launcher3.enable_scalability_for_desktop_experience Test: Manual Change-Id: Ie4747b5bae3e124e914af51445778c9b6285ff66 --- res/values/attrs.xml | 2 ++ src/com/android/launcher3/InvariantDeviceProfile.java | 10 ++++++++-- src/com/android/launcher3/util/DisplayController.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 6a37816504..14a12a0534 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -296,6 +296,8 @@ + + diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index c0e8b1c800..18821c7cb9 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -106,13 +106,14 @@ public class InvariantDeviceProfile { "idp_non_fixed_landscape_grid_name"; @Retention(RetentionPolicy.SOURCE) - @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) + @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET, TYPE_DESKTOP}) public @interface DeviceType { } public static final int TYPE_PHONE = 0; public static final int TYPE_MULTI_DISPLAY = 1; public static final int TYPE_TABLET = 2; + public static final int TYPE_DESKTOP = 3; private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; @@ -1008,8 +1009,10 @@ public class InvariantDeviceProfile { private static final int DEVICE_CATEGORY_PHONE = 1 << 0; private static final int DEVICE_CATEGORY_TABLET = 1 << 1; private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2; + private static final int DEVICE_CATEGORY_DESKTOP = 1 << 3; private static final int DEVICE_CATEGORY_ANY = - DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY; + DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY + | DEVICE_CATEGORY_DESKTOP; private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0; private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1; @@ -1234,6 +1237,9 @@ public class InvariantDeviceProfile { case TYPE_MULTI_DISPLAY: return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY) == DEVICE_CATEGORY_MULTI_DISPLAY; + case TYPE_DESKTOP: + return (deviceCategory & DEVICE_CATEGORY_DESKTOP) + == DEVICE_CATEGORY_DESKTOP; default: return false; } diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 8e7933f78a..aee895a396 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -18,6 +18,8 @@ package com.android.launcher3.util; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; +import static com.android.launcher3.Flags.enableScalabilityForDesktopExperience; +import static com.android.launcher3.InvariantDeviceProfile.TYPE_DESKTOP; 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; @@ -53,6 +55,7 @@ import androidx.annotation.VisibleForTesting; import com.android.launcher3.InvariantDeviceProfile.DeviceType; import com.android.launcher3.LauncherPrefChangeListener; import com.android.launcher3.LauncherPrefs; +import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dagger.ApplicationContext; import com.android.launcher3.dagger.LauncherAppComponent; @@ -507,6 +510,7 @@ public class DisplayController implements DesktopVisibilityListener { private final boolean mShowLockedTaskbarOnHome; private final boolean mIsHomeVisible; + private final boolean mIsDesktopFormFactor; private final boolean mShowDesktopTaskbarForFreeformDisplay; @@ -573,6 +577,8 @@ public class DisplayController implements DesktopVisibilityListener { mShowDesktopTaskbarForFreeformDisplay = wmProxy.showDesktopTaskbarForFreeformDisplay( displayInfoContext); mIsHomeVisible = wmProxy.isHomeVisible(); + mIsDesktopFormFactor = enableScalabilityForDesktopExperience() + && displayInfoContext.getResources().getBoolean(R.bool.desktop_form_factor); } /** @@ -657,6 +663,10 @@ public class DisplayController implements DesktopVisibilityListener { } public @DeviceType int getDeviceType() { + if (mIsDesktopFormFactor) { + return TYPE_DESKTOP; + } + int flagPhone = 1 << 0; int flagTablet = 1 << 1;