From 8fc60dd7fa46ccb87725d646d889dcdaadf629cd Mon Sep 17 00:00:00 2001 From: Marzia Favaro Date: Thu, 21 Nov 2024 16:34:28 +0000 Subject: Enable app handle on foldables (reland) The resource config_enableAppHandle that was supposed to be used before was not very practical. Since there wasn't an overlay config common to all large screens (or at least foldble devices), it was impractial to override the resource on all the required devices, especially non-pixels. This change enables the app handle for devices that have at least one built-in large screen. Bug: 377689543 Test: WMShellUnitTests Test: Manual, app handle shows on foldable Flag: com.android.window.flags.universal_resizable_by_default Change-Id: Idf4438d288d5644c607af98f121a03c24302c9be --- core/java/android/view/Display.java | 15 +++++++ core/res/res/values/config.xml | 4 -- core/res/res/values/symbols.xml | 3 -- libs/WindowManager/Shell/shared/Android.bp | 2 + .../src/com/android/wm/shell/shared/Utils.java | 46 ++++++++++++++++++++++ .../shared/desktopmode/DesktopModeStatus.java | 28 +++++++++++-- 6 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/Utils.java 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; @@ -1047,6 +1049,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. */ 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. --> false - - false - 102 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. --> - - - 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 type of object to get + */ + public static class Lazy { + 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 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 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); @@ -243,6 +251,18 @@ public class DesktopModeStatus { return !enforceDeviceRestrictions() || isDesktopModeSupported(context); } + /** + * @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)); } } -- cgit v1.2.3-59-g8ed1b