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

Commit a493df4e authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Remove from DesktopModeStatus methods not used anymore.

Also removed DesktopModeStatus usages in some e2e tests.

Bug: 395863348
Flag: EXEMPT (refactor)
Test: atest WMShellUnitTests
Test: atest ExitDesktopWithDragToTopDragZoneTest
Test: atest MaximizeAppWindowWithDragToTopDragZoneTest
Change-Id: If4e8804489c094f9aa507335e0615da30d73d350
parent c15a5ff8
Loading
Loading
Loading
Loading
+1 −195
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper.enabl

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.TaskInfo;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.SystemProperties;
@@ -37,7 +36,6 @@ import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.Arrays;

/**
@@ -48,37 +46,9 @@ import java.util.Arrays;
@Deprecated(forRemoval = true)
public class DesktopModeStatus {

    private static final String TAG = "DesktopModeStatus";

    @Nullable
    private static Boolean sIsLargeScreenDevice = null;

    /**
     * Flag to indicate whether task resizing is veiled.
     */
    private static final boolean IS_VEILED_RESIZE_ENABLED = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_veiled_resizing", true);

    /**
     * Flag to indicate is moving task to another display is enabled.
     */
    public static final boolean IS_DISPLAY_CHANGE_ENABLED = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_change_display", false);

    /**
     * Flag to indicate whether to apply shadows to windows in desktop mode.
     */
    private static final boolean USE_WINDOW_SHADOWS = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_use_window_shadows", true);

    /**
     * Flag to indicate whether to apply shadows to the focused window in desktop mode.
     *
     * Note: this flag is only relevant if USE_WINDOW_SHADOWS is false.
     */
    private static final boolean USE_WINDOW_SHADOWS_FOCUSED_WINDOW = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_use_window_shadows_focused_window", false);

    /**
     * Flag to indicate whether to use rounded corners for windows in desktop mode.
     */
@@ -91,27 +61,6 @@ public class DesktopModeStatus {
    private static final boolean ENFORCE_DEVICE_RESTRICTIONS = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_mode_enforce_device_restrictions", true);

    private static final boolean USE_APP_TO_WEB_BUILD_TIME_GENERIC_LINKS =
            SystemProperties.getBoolean(
                    "persist.wm.debug.use_app_to_web_build_time_generic_links", true);

    /** Whether the desktop density override is enabled. */
    public static final boolean DESKTOP_DENSITY_OVERRIDE_ENABLED =
            SystemProperties.getBoolean("persist.wm.debug.desktop_mode_density_enabled", false);

    /** Override density for tasks when they're inside the desktop. */
    public static final int DESKTOP_DENSITY_OVERRIDE =
            SystemProperties.getInt("persist.wm.debug.desktop_mode_density", 284);

    /** The minimum override density allowed for tasks inside the desktop. */
    private static final int DESKTOP_DENSITY_MIN = 100;

    /** The maximum override density allowed for tasks inside the desktop. */
    private static final int DESKTOP_DENSITY_MAX = 1000;

    /** The number of [WindowDecorViewHost] instances to warm up on system start. */
    private static final int WINDOW_DECOR_PRE_WARM_SIZE = 2;

    /**
     * Sysprop declaring whether to enters desktop mode by default when the windowing mode of the
     * display's root TaskDisplayArea is set to WINDOWING_MODE_FREEFORM.
@@ -122,51 +71,6 @@ public class DesktopModeStatus {
    public static final String ENTER_DESKTOP_BY_DEFAULT_ON_FREEFORM_DISPLAY_SYS_PROP =
            "persist.wm.debug.enter_desktop_by_default_on_freeform_display";

    /**
     * Sysprop declaring whether to enable drag-to-maximize for desktop windows.
     *
     * <p>If it is not defined, then {@code R.integer.config_dragToMaximizeInDesktopMode}
     * is used.
     */
    public static final String ENABLE_DRAG_TO_MAXIMIZE_SYS_PROP =
            "persist.wm.debug.enable_drag_to_maximize";

    /**
     * Sysprop declaring the maximum number of Tasks to show in Desktop Mode at any one time.
     *
     * <p>If it is not defined, then {@code R.integer.config_maxDesktopWindowingActiveTasks} is
     * used.
     *
     * <p>The limit does NOT affect Picture-in-Picture, Bubbles, or System Modals (like a screen
     * recording window, or Bluetooth pairing window).
     */
    private static final String MAX_TASK_LIMIT_SYS_PROP = "persist.wm.debug.desktop_max_task_limit";

    /**
     * Sysprop declaring the number of [WindowDecorViewHost] instances to warm up on system start.
     *
     * <p>If it is not defined, then [WINDOW_DECOR_PRE_WARM_SIZE] is used.
     */
    private static final String WINDOW_DECOR_PRE_WARM_SIZE_SYS_PROP =
            "persist.wm.debug.desktop_window_decor_pre_warm_size";

    /**
     * Return {@code true} if veiled resizing is active. If false, fluid resizing is used.
     */
    public static boolean isVeiledResizeEnabled() {
        return IS_VEILED_RESIZE_ENABLED;
    }

    /**
     * Return whether to use window shadows.
     *
     * @param isFocusedWindow whether the window to apply shadows to is focused
     */
    public static boolean useWindowShadow(boolean isFocusedWindow) {
        return USE_WINDOW_SHADOWS
                || (USE_WINDOW_SHADOWS_FOCUSED_WINDOW && isFocusedWindow);
    }

    /**
     * Return whether to use rounded corners for windows.
     */
@@ -182,35 +86,6 @@ public class DesktopModeStatus {
        return ENFORCE_DEVICE_RESTRICTIONS;
    }

    /**
     * Return the maximum limit on the number of Tasks to show in Desktop Mode at any one time.
     */
    public static int getMaxTaskLimit(@NonNull Context context) {
        return SystemProperties.getInt(MAX_TASK_LIMIT_SYS_PROP,
                context.getResources().getInteger(R.integer.config_maxDesktopWindowingActiveTasks));
    }

    /**
     * Return the maximum size of the window decoration surface control view host pool, or zero if
     * there should be no pooling.
     */
    public static int getWindowDecorScvhPoolSize(@NonNull Context context) {
        if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_SCVH_CACHE.isTrue()) return 0;
        final int maxTaskLimit = getMaxTaskLimit(context);
        if (maxTaskLimit > 0) {
            return maxTaskLimit;
        }
        // TODO: b/368032552 - task limit equal to 0 means unlimited. Figure out what the pool
        //  size should be in that case.
        return 0;
    }

    /** The number of [WindowDecorViewHost] instances to warm up on system start. */
    public static int getWindowDecorPreWarmSize() {
        return SystemProperties.getInt(WINDOW_DECOR_PRE_WARM_SIZE_SYS_PROP,
                WINDOW_DECOR_PRE_WARM_SIZE);
    }

    /**
     * Return {@code true} if the current device supports desktop mode.
     */
@@ -317,16 +192,6 @@ public class DesktopModeStatus {
                && deviceHasLargeScreen(context);
    }

    /**
     * @return If {@code true} we set opaque background for all freeform tasks to prevent freeform
     * tasks below from being visible if freeform task window above is translucent.
     * Otherwise if fluid resize is enabled, add a background to freeform tasks.
     */
    public static boolean shouldSetBackground(@NonNull TaskInfo taskInfo) {
        return taskInfo.isFreeform() && (!DesktopModeStatus.isVeiledResizeEnabled()
                || DesktopModeFlags.ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS.isTrue());
    }

    /**
     * @return {@code true} if the app handle should be shown because desktop mode is enabled or
     * the device has a large screen
@@ -335,35 +200,6 @@ public class DesktopModeStatus {
        return canEnterDesktopMode(context) || overridesShowAppHandle(context);
    }

    /**
     * Return {@code true} if the override desktop density is enabled and valid.
     */
    public static boolean useDesktopOverrideDensity() {
        return isDesktopDensityOverrideEnabled() && isValidDesktopDensityOverrideSet();
    }

    /**
     * Returns {@code true} if the app-to-web feature is using the build-time generic links list.
     */
    public static boolean useAppToWebBuildTimeGenericLinks() {
        return USE_APP_TO_WEB_BUILD_TIME_GENERIC_LINKS;
    }

    /**
     * Return {@code true} if the override desktop density is enabled.
     */
    private static boolean isDesktopDensityOverrideEnabled() {
        return DESKTOP_DENSITY_OVERRIDE_ENABLED;
    }

    /**
     * Return {@code true} if the override desktop density is set and within a valid range.
     */
    private static boolean isValidDesktopDensityOverrideSet() {
        return DESKTOP_DENSITY_OVERRIDE >= DESKTOP_DENSITY_MIN
                && DESKTOP_DENSITY_OVERRIDE <= DESKTOP_DENSITY_MAX;
    }

   /**
     * Return {@code true} if desktop mode is unrestricted and is supported on the device.
     */
@@ -425,34 +261,4 @@ public class DesktopModeStatus {
                context.getResources().getBoolean(
                        R.bool.config_enterDesktopByDefaultOnFreeformDisplay));
    }

    /**
     * Return {@code true} if a window should be maximized when it's dragged to the top edge of the
     * screen.
     */
    public static boolean shouldMaximizeWhenDragToTopEdge(@NonNull Context context) {
        if (!DesktopExperienceFlags.ENABLE_DRAG_TO_MAXIMIZE.isTrue()) {
            return false;
        }
        return SystemProperties.getBoolean(ENABLE_DRAG_TO_MAXIMIZE_SYS_PROP,
                context.getResources().getBoolean(R.bool.config_dragToMaximizeInDesktopMode));
    }

    /** Dumps DesktopModeStatus flags and configs. */
    public static void dump(PrintWriter pw, String prefix, Context context) {
        String innerPrefix = prefix + "  ";
        pw.print(prefix); pw.println(TAG);
        pw.print(innerPrefix); pw.print("maxTaskLimit="); pw.println(getMaxTaskLimit(context));

        pw.print(innerPrefix); pw.print("maxTaskLimit config override=");
        pw.println(context.getResources().getInteger(
                R.integer.config_maxDesktopWindowingActiveTasks));

        SystemProperties.Handle maxTaskLimitHandle = SystemProperties.find(MAX_TASK_LIMIT_SYS_PROP);
        pw.print(innerPrefix); pw.print("maxTaskLimit sysprop=");
        pw.println(maxTaskLimitHandle == null ? "null" : maxTaskLimitHandle.getInt(/* def= */ -1));

        pw.print(innerPrefix); pw.print("showAppHandle config override=");
        pw.println(overridesShowAppHandle(context));
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.tools.NavBar
import android.tools.Rotation
import com.android.window.flags.Flags
import com.android.wm.shell.Utils
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopConfig
import org.junit.After
import org.junit.Assume
import org.junit.Before
@@ -29,8 +29,7 @@ import org.junit.Rule
import org.junit.Test

@Ignore("Test Base Class")
abstract class ExitDesktopWithDragToTopDragZone
constructor(
abstract class ExitDesktopWithDragToTopDragZone(
    val rotation: Rotation = Rotation.ROTATION_0,
    isResizeable: Boolean = true,
    isLandscapeApp: Boolean = true,
@@ -40,10 +39,10 @@ constructor(

    @Before
    fun setup() {
        val desktopConfig = DesktopConfig.fromContext(instrumentation.context)
        Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet)
        // Skip the test when the drag-to-maximize is enabled on this device.
        Assume.assumeFalse(
            DesktopModeStatus.shouldMaximizeWhenDragToTopEdge(instrumentation.context))
        Assume.assumeFalse(desktopConfig.shouldMaximizeWhenDragToTopEdge)
        tapl.setEnableRotation(true)
        tapl.setExpectedRotation(rotation.value)
        testApp.enterDesktopMode(wmHelper, device)
+6 −5
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.window.flags.Flags
import com.android.wm.shell.Utils
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopConfig
import org.junit.After
import org.junit.Assume
import org.junit.Before
@@ -40,8 +40,9 @@ import org.junit.Test
 * Base scenario test for maximizing a desktop app window by dragging it to the top drag zone.
 */
@Ignore("Test Base Class")
abstract class MaximizeAppWindowWithDragToTopDragZone
constructor(private val rotation: Rotation = Rotation.ROTATION_0) : TestScenarioBase() {
abstract class MaximizeAppWindowWithDragToTopDragZone(
    private val rotation: Rotation = Rotation.ROTATION_0
) : TestScenarioBase() {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
@@ -52,10 +53,10 @@ constructor(private val rotation: Rotation = Rotation.ROTATION_0) : TestScenario

    @Before
    fun setup() {
        val desktopConfig = DesktopConfig.fromContext(instrumentation.context)
        Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet)
        // Skip the test when the drag-to-maximize is disabled on this device.
        Assume.assumeTrue(
            DesktopModeStatus.shouldMaximizeWhenDragToTopEdge(instrumentation.context))
        Assume.assumeTrue(desktopConfig.shouldMaximizeWhenDragToTopEdge)
        tapl.setEnableRotation(true)
        tapl.setExpectedRotation(rotation.value)
        ChangeDisplayOrientationRule.setRotation(rotation)
+0 −66
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.wm.shell.shared.desktopmode

import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.Context
import android.content.res.Resources
import android.platform.test.annotations.DisableFlags
@@ -28,7 +27,6 @@ import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.window.flags.Flags
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.util.createTaskInfo
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
@@ -154,70 +152,6 @@ class DesktopModeStatusTest : ShellTestCase() {
        assertThat(DesktopModeStatus.canEnterDesktopMode(mockContext)).isTrue()
    }

    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
        Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS,
    )
    @Test
    fun shouldSetBackground_BTWFlagEnabled_freeformTask_returnsTrue() {
        val freeFormTaskInfo = createTaskInfo(deviceWindowingMode = WINDOWING_MODE_FREEFORM)
        assertThat(DesktopModeStatus.shouldSetBackground(freeFormTaskInfo)).isTrue()
    }

    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
        Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS,
    )
    @Test
    fun shouldSetBackground_BTWFlagEnabled_notFreeformTask_returnsFalse() {
        val notFreeFormTaskInfo = createTaskInfo()
        assertThat(DesktopModeStatus.shouldSetBackground(notFreeFormTaskInfo)).isFalse()
    }

    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS)
    @Test
    fun shouldSetBackground_BTWFlagDisabled_freeformTaskAndFluid_returnsTrue() {
        val freeFormTaskInfo = createTaskInfo(deviceWindowingMode = WINDOWING_MODE_FREEFORM)

        setIsVeiledResizeEnabled(false)
        assertThat(DesktopModeStatus.shouldSetBackground(freeFormTaskInfo)).isTrue()
    }

    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS)
    @Test
    fun shouldSetBackground_BTWFlagDisabled_freeformTaskAndVeiled_returnsFalse() {
        val freeFormTaskInfo = createTaskInfo(deviceWindowingMode = WINDOWING_MODE_FREEFORM)

        setIsVeiledResizeEnabled(true)
        assertThat(DesktopModeStatus.shouldSetBackground(freeFormTaskInfo)).isFalse()
    }

    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
        Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS,
    )
    @Test
    fun shouldSetBackground_BTWFlagEnabled_freeformTaskAndFluid_returnsTrue() {
        val freeFormTaskInfo = createTaskInfo(deviceWindowingMode = WINDOWING_MODE_FREEFORM)

        setIsVeiledResizeEnabled(false)
        assertThat(DesktopModeStatus.shouldSetBackground(freeFormTaskInfo)).isTrue()
    }

    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
        Flags.FLAG_ENABLE_OPAQUE_BACKGROUND_FOR_TRANSPARENT_WINDOWS,
    )
    @Test
    fun shouldSetBackground_BTWFlagEnabled_windowModesTask_freeformTaskAndVeiled_returnsTrue() {
        val freeFormTaskInfo = createTaskInfo(deviceWindowingMode = WINDOWING_MODE_FREEFORM)

        setIsVeiledResizeEnabled(true)
        assertThat(DesktopModeStatus.shouldSetBackground(freeFormTaskInfo)).isTrue()
    }

    @Test
    fun isDeviceEligibleForDesktopMode_configDEModeOnAndIntDispHostsDesktop_returnsTrue() {
        doReturn(true).whenever(mockResources).getBoolean(eq(R.bool.config_isDesktopModeSupported))