diff options
author | 2024-11-21 16:34:28 +0000 | |
---|---|---|
committer | 2024-12-02 14:08:25 +0000 | |
commit | 681890767d1c570b4e7aec460b6593274e1bb26b (patch) | |
tree | 5a3e083ca55c59a7eeb1088ac7c7b9618c4ce9f8 | |
parent | e5a17396b2a72333f418fe5c173f1d5321efa73e (diff) |
Enable app handle on foldables
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 ensures that the feature reaches all foldable devices.
Bug: 377689543
Test: Manual, app handle shows on foldable
Flag: com.android.window.flags.universal_resizable_by_default
Change-Id: Idb52cb3b0e0f7c6b5a3a222dbe5fd637d406b145
5 files changed, 68 insertions, 10 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 0d13ca83ec59..2caa058522c8 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -7195,10 +7195,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 4f029cdcacc9..de1f85475a72 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -5737,9 +5737,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..f5e6ddd9774d --- /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 that defines the return value if not defined already + * @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..4c6ef9329314 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,14 +16,19 @@ package com.android.wm.shell.shared.desktopmode; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY; + import android.annotation.NonNull; import android.content.Context; +import android.hardware.devicestate.DeviceStateManager; import android.os.SystemProperties; 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; @@ -35,6 +40,8 @@ public class DesktopModeStatus { private static final String TAG = "DesktopModeStatus"; + private static Lazy<Boolean> sIsFoldableDevice = new Lazy<>(); + /** * Flag to indicate whether task resizing is veiled. */ @@ -195,8 +202,7 @@ 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() && isDeviceFoldable(context); } /** @@ -244,6 +250,17 @@ public class DesktopModeStatus { } /** + * @return {@code true} if this is a foldable device + */ + private static boolean isDeviceFoldable(@NonNull Context context) { + return sIsFoldableDevice.get(() -> context.getSystemService(DeviceStateManager.class) + .getSupportedDeviceStates().stream().anyMatch(state -> + state.hasProperty(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY) + || state.hasProperty( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))); + } + + /** * 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 +300,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)); } } |