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

Commit 8106795f authored by Annie Lin's avatar Annie Lin Committed by Android (Google) Code Review
Browse files

Merge "Check for app bubble in shouldShowSizeCompatRestartButton." into main

parents 10f6ba73 10a34aae
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.compatui;

import static android.view.WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;

import android.annotation.NonNull;
import android.app.TaskInfo;

/**
 * Utility class for Compat UI.
 */
final class CompatUIUtils {
    /**
     * Return whether or not to show size compat mode restart button if the display is phone sized.
     * @param taskInfo The info about the task to apply SCM.
     */
    public static boolean shouldShowSizeCompatRestartForPhoneScreen(@NonNull TaskInfo taskInfo) {
        // The Task's smallest screen width can't represent display smallest width for a Bubble
        // Task, so we should skip the check for Bubble.
        // TODO(b/384610402): Clean this up once Bubble Anything is launched and re-check logic
        // for other multi-window modes.
        boolean shouldCheckForPhoneScreenWidth = true;
        if (com.android.wm.shell.Flags.enableCreateAnyBubble()
                && com.android.wm.shell.Flags.enableBubbleAppCompatFixes()) {
            if (taskInfo.isAppBubble) {
                shouldCheckForPhoneScreenWidth = false;
            }
        }
        final int taskSmallestScreenWidthDp = taskInfo.configuration.smallestScreenWidthDp;
        return shouldCheckForPhoneScreenWidth &&
                taskSmallestScreenWidthDp < LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;
    }

    private CompatUIUtils() {}
}
+1 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.wm.shell.compatui;

import static android.view.WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;
import static android.window.TaskConstants.TASK_CHILD_LAYER_COMPAT_UI;

import android.annotation.NonNull;
@@ -200,7 +199,7 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {
    @VisibleForTesting
    boolean shouldShowSizeCompatRestartButton(@NonNull TaskInfo taskInfo) {
        // Always show button if display is phone sized.
        if (taskInfo.configuration.smallestScreenWidthDp < LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP) {
        if (CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo)) {
            return true;
        }

+105 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.compatui;

import static android.view.WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.app.ActivityManager;
import android.app.TaskInfo;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;

import androidx.test.filters.SmallTest;

import com.android.wm.shell.Flags;
import com.android.wm.shell.ShellTestCase;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests for {@link CompatUIUtils}.
 *
 * Build/Install/Run:
 *  atest WMShellUnitTests:CompatUIUtilsTest
 */
@RunWith(AndroidTestingRunner.class)
@SmallTest
public class CompatUIUtilsTest extends ShellTestCase {

    private static final int SMALL_SCREEN_WIDTH_DP = LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP - 1;
    private static final int LARGE_SCREEN_WIDTH_DP = LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP + 1;
    private static final int THRESHOLD_SCREEN_WIDTH_DP = LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;

    private static final int TASK_ID = 1;

    @Test
    @DisableFlags({Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES})
    public void shouldShowSizeCompatForPhoneSizedDisplay_NonBubbleSmallScreenWidth() {
        TaskInfo taskInfo =
                createTaskInfo(
                        /* isAppBubble= */ false,
                        /* smallestScreenWidthDp= */ SMALL_SCREEN_WIDTH_DP);
        assertTrue(CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo));
    }

    @Test
    @DisableFlags({Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES})
    public void shouldShowSizeCompatForPhoneSizedDisplay_NonBubbleLargeScreenWidth() {
        TaskInfo taskInfo =
                createTaskInfo(
                        /* isAppBubble= */ false,
                        /* smallestScreenWidthDp= */ LARGE_SCREEN_WIDTH_DP);
        assertFalse(CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo));
    }

    @Test
    @DisableFlags({Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES})
    public void shouldShowSizeCompatForPhoneSizedDisplay_NonBubbleThresholdScreenWidth() {
        TaskInfo taskInfo =
                createTaskInfo(
                        /* isAppBubble= */ false,
                        /* smallestScreenWidthDp= */ THRESHOLD_SCREEN_WIDTH_DP);
        assertFalse(CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES})
    public void shouldShowSizeCompatForPhoneSizedDisplay_BubbleSmallScreenWidth() {
        TaskInfo taskInfo =
                createTaskInfo(
                        /* isAppBubble= */ true,
                        /* smallestScreenWidthDp= */ SMALL_SCREEN_WIDTH_DP);
        assertFalse(CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo));
    }

    private static TaskInfo createTaskInfo(boolean isAppBubble, int smallestScreenWidthDp) {
        ActivityManager.RunningTaskInfo taskInfo = new ActivityManager.RunningTaskInfo();
        taskInfo.taskId = TASK_ID;
        taskInfo.isAppBubble = isAppBubble;
        taskInfo.configuration.smallestScreenWidthDp = smallestScreenWidthDp;
        return taskInfo;
    }
}