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

Commit b7d7662f authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge "Check windowing mode in CompatUIController#isInDesktopMode()" into main

parents 041966af fe1f82e2
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.wm.shell.compatui;

import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.window.DesktopExperienceFlags.ENABLE_COMPAT_UI_DESKTOP_MODE_SYNCHRONIZATION_BUGFIX;

import static com.android.wm.shell.compatui.impl.CompatUIRequestsKt.DISPLAY_COMPAT_SHOW_RESTART_DIALOG;

@@ -921,12 +923,26 @@ public class CompatUIController implements OnDisplaysChangedListener,
        boolean mHasShownUserAspectRatioSettingsButtonHint;
    }

    /**
     * Returns {@code true} if the given task is considered to be in desktop mode for the purpose
     * of showing compat UI.
     */
    private boolean isInDesktopMode(@Nullable TaskInfo taskInfo) {
        if (mDesktopUserRepositories.isEmpty() || taskInfo == null) {
        if (taskInfo == null) {
            return false;
        }
        boolean isDesktopModeShowing = mDesktopUserRepositories.get().getCurrent()
        final boolean isDesktopModeShowing;
        if (ENABLE_COMPAT_UI_DESKTOP_MODE_SYNCHRONIZATION_BUGFIX.isTrue()) {
            // CompatUI is based on TaskListener and may not be synchronized with shell
            // transitions. Checking the windowing mode in addition to desktop eligibility
            // provides a more reliable state.
            isDesktopModeShowing = taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM
                    && mDesktopState.isDesktopModeSupportedOnDisplay(taskInfo.displayId);
        } else {
            isDesktopModeShowing = mDesktopUserRepositories.isPresent()
                    && mDesktopUserRepositories.get().getCurrent()
                    .isAnyDeskActive(taskInfo.displayId);
        }
        return DesktopModeFlags.ENABLE_DESKTOP_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE_BUGFIX
                .isTrue() && isDesktopModeShowing;
    }
+10 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.compatui;

import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.view.WindowInsets.Type.navigationBars;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
@@ -30,7 +31,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.ActivityManager.RunningTaskInfo;
import android.app.TaskInfo;
@@ -146,6 +146,7 @@ public class CompatUIControllerTest extends ShellTestCase {
        MockitoAnnotations.initMocks(this);

        mDesktopState = new FakeDesktopState();
        mDesktopState.getOverrideDesktopModeSupportPerDisplay().put(DISPLAY_ID, true);
        doReturn(mMockDisplayLayout).when(mMockDisplayController).getDisplayLayout(anyInt());
        doReturn(DISPLAY_ID).when(mMockCompatLayout).getDisplayId();
        doReturn(TASK_ID).when(mMockCompatLayout).getTaskId();
@@ -712,16 +713,16 @@ public class CompatUIControllerTest extends ShellTestCase {

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_APP_COMPAT_UI_FRAMEWORK)
    @EnableFlags(Flags.FLAG_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE)
    @EnableFlags({Flags.FLAG_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE,
            Flags.FLAG_ENABLE_COMPAT_UI_DESKTOP_MODE_SYNCHRONIZATION_BUGFIX})
    public void testUpdateActiveTaskInfo_removeAllComponentWhenInDesktopModeFlagEnabled() {
        TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true);
        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(false);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));

        verify(mController, never()).removeLayouts(taskInfo.taskId);

        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));

@@ -730,14 +731,13 @@ public class CompatUIControllerTest extends ShellTestCase {

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_APP_COMPAT_UI_FRAMEWORK)
    @EnableFlags(Flags.FLAG_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE)
    @EnableFlags({Flags.FLAG_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE,
            Flags.FLAG_ENABLE_COMPAT_UI_DESKTOP_MODE_SYNCHRONIZATION_BUGFIX})
    public void testUpdateActiveTaskInfo_alwaysRemoveLetterboxEdu() {
        TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true);

        // When not in Desktop Mode the LetterboxEdu is removed only if the taskId is the one used
        // when created.
        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(false);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));
        mController.removeLetterboxEdu(TASK_ID_2);
        verify(mMockLetterboxEduLayout, never()).release();
@@ -747,7 +747,7 @@ public class CompatUIControllerTest extends ShellTestCase {
        verify(mMockLetterboxEduLayout).release();

        // When in Desktop Mode the LetterboxEdu is always removed
        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));
        mController.removeLetterboxEdu(TASK_ID);
@@ -761,15 +761,15 @@ public class CompatUIControllerTest extends ShellTestCase {
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_APP_COMPAT_UI_FRAMEWORK)
    @DisableFlags(Flags.FLAG_SKIP_COMPAT_UI_EDUCATION_IN_DESKTOP_MODE)
    @EnableFlags(Flags.FLAG_ENABLE_COMPAT_UI_DESKTOP_MODE_SYNCHRONIZATION_BUGFIX)
    public void testUpdateActiveTaskInfo_removeAllComponentWhenInDesktopModeFlagDisabled() {
        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(false);
        TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));

        verify(mController, never()).removeLayouts(taskInfo.taskId);

        when(mDesktopUserRepositories.getCurrent().isAnyDeskActive(DISPLAY_ID)).thenReturn(true);
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);

        mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener));