summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/Display.java15
-rw-r--r--core/res/res/values/config.xml4
-rw-r--r--core/res/res/values/symbols.xml3
-rw-r--r--libs/WindowManager/Shell/shared/Android.bp2
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/Utils.java46
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/DesktopModeStatus.java28
6 files changed, 87 insertions, 11 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index c9d560c3424b..1ad990db9853 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -19,6 +19,7 @@ package android.view;
import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS;
import static android.hardware.flags.Flags.FLAG_OVERLAYPROPERTIES_CLASS_API;
+import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_GET_SUPPORTED_REFRESH_RATES;
import static com.android.server.display.feature.flags.Flags.FLAG_HIGHEST_HDR_SDR_RATIO_API;
@@ -58,6 +59,7 @@ import android.os.SystemClock;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.TypedValue;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -1048,6 +1050,19 @@ public final class Display {
}
/**
+ * Returns the smallest size of the display in dp
+ * @hide
+ */
+ public float getMinSizeDimensionDp() {
+ synchronized (mLock) {
+ updateDisplayInfoLocked();
+ mDisplayInfo.getAppMetrics(mTempMetrics);
+ return TypedValue.deriveDimension(COMPLEX_UNIT_DIP,
+ Math.min(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight), mTempMetrics);
+ }
+ }
+
+ /**
* @deprecated Use {@link WindowMetrics#getBounds#width()} instead.
*/
@Deprecated
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 13c125cb7349..3c71b0d2ebe4 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -7213,10 +7213,6 @@
screen. -->
<bool name="config_dragToMaximizeInDesktopMode">false</bool>
- <!-- Whether showing the app handle is supported on this device.
- If config_isDesktopModeSupported, then this has no effect -->
- <bool name="config_enableAppHandle">false</bool>
-
<!-- Frame rate compatibility value for Wallpaper
FRAME_RATE_COMPATIBILITY_MIN (102) is used by default for lower power consumption -->
<integer name="config_wallpaperFrameRateCompatibility">102</integer>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 2671ff90b35f..bdf579db4288 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -5764,9 +5764,6 @@
screen. -->
<java-symbol type="bool" name="config_dragToMaximizeInDesktopMode" />
- <!-- Whether showing the app handle is supported on this device -->
- <java-symbol type="bool" name="config_enableAppHandle" />
-
<!-- Frame rate compatibility value for Wallpaper -->
<java-symbol type="integer" name="config_wallpaperFrameRateCompatibility" />
diff --git a/libs/WindowManager/Shell/shared/Android.bp b/libs/WindowManager/Shell/shared/Android.bp
index 5113d980fb7d..5bbda95c466f 100644
--- a/libs/WindowManager/Shell/shared/Android.bp
+++ b/libs/WindowManager/Shell/shared/Android.bp
@@ -26,6 +26,7 @@ filegroup {
name: "wm_shell-shared-utils",
srcs: [
"src/com/android/wm/shell/shared/TransitionUtil.java",
+ "src/com/android/wm/shell/shared/Utils.java",
],
}
@@ -71,6 +72,7 @@ java_library {
srcs: [
"**/desktopmode/*.java",
"**/desktopmode/*.kt",
+ ":wm_shell-shared-utils",
],
static_libs: [
"com.android.window.flags.window-aconfig-java",
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/Utils.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/Utils.java
new file mode 100644
index 000000000000..e19027a352f7
--- /dev/null
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/Utils.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.shared;
+
+import android.annotation.NonNull;
+
+import java.util.function.Supplier;
+
+/**
+ * This class provides generic utility methods and classes for shell
+ */
+public class Utils {
+
+ /**
+ * Lazily returns object from a supplier with caching
+ * @param <T> type of object to get
+ */
+ public static class Lazy<T> {
+ private T mInstance;
+
+ /**
+ * @param supplier the supplier to use, when the instance has not yet been initialized
+ * @return the cached value or the value from the supplier
+ */
+ public final T get(@NonNull Supplier<T> supplier) {
+ if (mInstance == null) {
+ mInstance = supplier.get();
+ }
+ return mInstance;
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/DesktopModeStatus.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/DesktopModeStatus.java
index 04c17e54d11f..7a6ac4561698 100644
--- a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/DesktopModeStatus.java
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/DesktopModeStatus.java
@@ -16,16 +16,23 @@
package com.android.wm.shell.shared.desktopmode;
+import static android.hardware.display.DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED;
+
import android.annotation.NonNull;
import android.content.Context;
+import android.hardware.display.DisplayManager;
import android.os.SystemProperties;
+import android.view.Display;
+import android.view.WindowManager;
import android.window.DesktopModeFlags;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;
+import com.android.wm.shell.shared.Utils.Lazy;
import java.io.PrintWriter;
+import java.util.Arrays;
/**
* Constants for desktop mode feature
@@ -35,6 +42,8 @@ public class DesktopModeStatus {
private static final String TAG = "DesktopModeStatus";
+ private static Lazy<Boolean> sIsLargeScreenDevice = new Lazy<>();
+
/**
* Flag to indicate whether task resizing is veiled.
*/
@@ -195,13 +204,12 @@ public class DesktopModeStatus {
* necessarily enabling desktop mode
*/
public static boolean overridesShowAppHandle(@NonNull Context context) {
- return Flags.showAppHandleLargeScreens()
- && context.getResources().getBoolean(R.bool.config_enableAppHandle);
+ return Flags.showAppHandleLargeScreens() && deviceHasLargeScreen(context);
}
/**
* @return {@code true} if the app handle should be shown because desktop mode is enabled or
- * the device is overriding {@code R.bool.config_enableAppHandle}
+ * the device has a large screen
*/
public static boolean canEnterDesktopModeOrShowAppHandle(@NonNull Context context) {
return canEnterDesktopMode(context) || overridesShowAppHandle(context);
@@ -244,6 +252,18 @@ public class DesktopModeStatus {
}
/**
+ * @return {@code true} if this device has an internal large screen
+ */
+ private static boolean deviceHasLargeScreen(@NonNull Context context) {
+ return sIsLargeScreenDevice.get(() -> Arrays.stream(
+ context.getSystemService(DisplayManager.class)
+ .getDisplays(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED))
+ .filter(display -> display.getType() == Display.TYPE_INTERNAL)
+ .anyMatch(display -> display.getMinSizeDimensionDp()
+ >= WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP));
+ }
+
+ /**
* Return {@code true} if a display should enter desktop mode by default when the windowing mode
* of the display's root [TaskDisplayArea] is set to WINDOWING_MODE_FREEFORM.
*/
@@ -283,6 +303,6 @@ public class DesktopModeStatus {
pw.println(maxTaskLimitHandle == null ? "null" : maxTaskLimitHandle.getInt(/* def= */ -1));
pw.print(innerPrefix); pw.print("showAppHandle config override=");
- pw.print(context.getResources().getBoolean(R.bool.config_enableAppHandle));
+ pw.print(overridesShowAppHandle(context));
}
}