diff options
5 files changed, 46 insertions, 14 deletions
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/DesktopModeStatus.java b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/DesktopModeStatus.java index 8d8655addc65..4876f327a650 100644 --- a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/DesktopModeStatus.java +++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/DesktopModeStatus.java @@ -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; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index 83a8d4c20340..46cb8f7b5852 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -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()) } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index 644fd4ba5a54..a37c3150a2a2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -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()); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt index b526838c2598..748ad3182393 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt @@ -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) diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java index a731e5394bdf..1b223cf2bd59 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java @@ -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; |