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

Commit 9f788d73 authored by Jorge Gil's avatar Jorge Gil
Browse files

Disable task override density in desktop windowing

Changing task density on enter/exit desktop mode causes some app compat
issues with apps that can't handle the configuration change or don't
handle it at all.
Hides the feature behind an adb flag that's disabled by default.

Flag: EXEMPT bugfix
Bug: 344599474
Test: manual - change Display Size in settings and verify desktop tasks
and their window decor change sizes
Test: atest DesktopTasksControllerTest DesktopModeWindowDecorationTests

Change-Id: Ibef0c9c60b84c84f20bc1294fb0f16f09e6199cc
parent 736591ce
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ public class DesktopModeStatus {
    private static final boolean ENFORCE_DEVICE_RESTRICTIONS = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_mode_enforce_device_restrictions", 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);
@@ -157,9 +161,23 @@ public class DesktopModeStatus {
    }

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

    /**
     * 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.
     */
    public static boolean isDesktopDensityOverrideSet() {
    private static boolean isValidDesktopDensityOverrideSet() {
        return DESKTOP_DENSITY_OVERRIDE >= DESKTOP_DENSITY_MIN
                && DESKTOP_DENSITY_OVERRIDE <= DESKTOP_DENSITY_MAX;
    }
+5 −5
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.shared.DesktopModeStatus
import com.android.wm.shell.shared.DesktopModeStatus.DESKTOP_DENSITY_OVERRIDE
import com.android.wm.shell.shared.DesktopModeStatus.isDesktopDensityOverrideSet
import com.android.wm.shell.shared.DesktopModeStatus.useDesktopOverrideDensity
import com.android.wm.shell.shared.annotations.ExternalThread
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.splitscreen.SplitScreenController
@@ -961,8 +961,8 @@ class DesktopTasksController(
            }
        }
        val wct = WindowContainerTransaction()
        if (isDesktopDensityOverrideSet()) {
            // TODO(344599474) reintroduce density changes behind a disabled flag
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(task.token, DESKTOP_DENSITY_OVERRIDE)
        }
        // Desktop Mode is showing and we're launching a new Task - we might need to minimize
        // a Task.
@@ -1036,7 +1036,7 @@ class DesktopTasksController(
        }
        wct.setWindowingMode(taskInfo.token, targetWindowingMode)
        wct.reorder(taskInfo.token, true /* onTop */)
        if (isDesktopDensityOverrideSet()) {
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(taskInfo.token, DESKTOP_DENSITY_OVERRIDE)
        }
    }
@@ -1056,7 +1056,7 @@ class DesktopTasksController(
            }
        wct.setWindowingMode(taskInfo.token, targetWindowingMode)
        wct.setBounds(taskInfo.token, Rect())
        if (isDesktopDensityOverrideSet()) {
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -385,7 +385,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            // Should match the density of the task. The task may have had its density overridden
            // to be different that SysUI's.
            windowDecorConfig.setTo(taskInfo.configuration);
        } else if (DesktopModeStatus.isDesktopDensityOverrideSet()) {
        } else if (DesktopModeStatus.useDesktopOverrideDensity()) {
            // The task has had its density overridden, but keep using the system's density to
            // layout the header.
            windowDecorConfig.setTo(context.getResources().getConfiguration());
+2 −6
Original line number Diff line number Diff line
@@ -1113,10 +1113,8 @@ class DesktopTasksControllerTest : ShellTestCase() {

  @Test
  fun handleRequest_freeformTask_alreadyInDesktop_noOverrideDensity_noConfigDensityChange() {
    // TODO(344599474) enable the test once the density change is behind a flag
    assumeTrue(false)
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    whenever(DesktopModeStatus.isDesktopDensityOverrideSet()).thenReturn(false)
    whenever(DesktopModeStatus.useDesktopOverrideDensity()).thenReturn(false)

    val freeformTask1 = setUpFreeformTask()
    markTaskVisible(freeformTask1)
@@ -1129,10 +1127,8 @@ class DesktopTasksControllerTest : ShellTestCase() {

  @Test
  fun handleRequest_freeformTask_alreadyInDesktop_overrideDensity_hasConfigDensityChange() {
    // TODO(344599474) enable the test once the density change is behind a flag
    assumeTrue(false)
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    whenever(DesktopModeStatus.isDesktopDensityOverrideSet()).thenReturn(true)
    whenever(DesktopModeStatus.useDesktopOverrideDensity()).thenReturn(true)

    val freeformTask1 = setUpFreeformTask()
    markTaskVisible(freeformTask1)
+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
import static android.view.WindowInsetsController.APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.any;
@@ -54,6 +56,7 @@ import android.window.WindowContainerTransaction;

import androidx.test.filters.SmallTest;

import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.internal.R;
import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
@@ -62,14 +65,17 @@ import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestRunningTaskInfoBuilder;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.shared.DesktopModeStatus;
import com.android.wm.shell.windowdecor.WindowDecoration.RelayoutParams;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.quality.Strictness;

import java.util.function.Supplier;

@@ -118,6 +124,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    private final Configuration mConfiguration = new Configuration();

    private StaticMockitoSession mMockitoSession;
    private TestableContext mTestableContext;

    /** Set up run before test class. */
@@ -131,6 +138,11 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    @Before
    public void setUp() {
        mMockitoSession = mockitoSession()
                .strictness(Strictness.LENIENT)
                .spyStatic(DesktopModeStatus.class)
                .startMocking();
        when(DesktopModeStatus.useDesktopOverrideDensity()).thenReturn(false);
        doReturn(mMockSurfaceControlViewHost).when(mMockSurfaceControlViewHostFactory).create(
                any(), any(), any());
        doReturn(mMockTransaction).when(mMockTransactionSupplier).get();
@@ -138,6 +150,11 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        mTestableContext.ensureTestableResources();
    }

    @After
    public void tearDown() {
        mMockitoSession.finishMocking();
    }

    @Test
    public void testMenusClosedWhenTaskIsInvisible() {
        doReturn(mMockTransaction).when(mMockTransaction).hide(any());
@@ -206,6 +223,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    @Test
    @DisableFlags(Flags.FLAG_ENABLE_APP_HEADER_WITH_TASK_DENSITY)
    public void updateRelayoutParams_appHeader_usesSystemDensity() {
        when(DesktopModeStatus.useDesktopOverrideDensity()).thenReturn(true);
        final int systemDensity = mTestableContext.getOrCreateTestableResources().getResources()
                .getConfiguration().densityDpi;
        final int customTaskDensity = systemDensity + 300;