Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68189076 authored by Marzia Favaro's avatar Marzia Favaro
Browse files

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
parent e5a17396
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -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>
+0 −3
Original line number Diff line number Diff line
@@ -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" />

+2 −0
Original line number Diff line number Diff line
@@ -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",
+46 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
+20 −3
Original line number Diff line number Diff line
@@ -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);
    }

    /**
@@ -243,6 +249,17 @@ public class DesktopModeStatus {
        return !enforceDeviceRestrictions() || isDesktopModeSupported(context);
    }

    /**
     * @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));
    }
}