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

Commit 3cc6d0f9 authored by Eric Chiang's avatar Eric Chiang Committed by Android (Google) Code Review
Browse files

Merge "Add config for size compat restart button" into main

parents 00d47d0a a9076544
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -177,6 +177,9 @@
    <!-- Whether CompatUIController is enabled -->
    <bool name="config_enableCompatUIController">true</bool>

    <!-- Whether the size compat restart button should be enabled -->
    <bool name="config_isSizeCompatRestartButtonEnabled">true</bool>

    <!-- Whether pointer pilfer is required to start back animation. -->
    <bool name="config_backAnimationRequiresPointerPilfer">true</bool>

+12 −0
Original line number Diff line number Diff line
@@ -93,6 +93,9 @@ public class CompatUIConfiguration implements DeviceConfig.OnPropertiesChangedLi
    // Whether the extended restart dialog is enabled
    private boolean mIsRestartDialogEnabled;

    // Whether the restart button is enabled
    private boolean mIsRestartButtonConfigEnabled;

    // Whether the additional education about reachability is enabled
    private boolean mIsReachabilityEducationEnabled;

@@ -112,6 +115,8 @@ public class CompatUIConfiguration implements DeviceConfig.OnPropertiesChangedLi
    public CompatUIConfiguration(Context context, @ShellMainThread ShellExecutor mainExecutor) {
        mIsRestartDialogEnabled = context.getResources().getBoolean(
                R.bool.config_letterboxIsRestartDialogEnabled);
        mIsRestartButtonConfigEnabled = context.getResources().getBoolean(
                R.bool.config_isSizeCompatRestartButtonEnabled);
        mIsReachabilityEducationEnabled = context.getResources().getBoolean(
                R.bool.config_letterboxIsReachabilityEducationEnabled);
        final int tolerance = context.getResources().getInteger(
@@ -146,6 +151,13 @@ public class CompatUIConfiguration implements DeviceConfig.OnPropertiesChangedLi
        mIsRestartDialogOverrideEnabled = enabled;
    }

    /**
     * @return whether the restart button is enabled
     */
    boolean isRestartButtonConfigEnabled() {
        return mIsRestartButtonConfigEnabled;
    }

    /**
     * Enables/Disables the reachability education
     */
+3 −0
Original line number Diff line number Diff line
@@ -198,6 +198,9 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {

    @VisibleForTesting
    boolean shouldShowSizeCompatRestartButton(@NonNull TaskInfo taskInfo) {
        if (!mCompatUIConfiguration.isRestartButtonConfigEnabled()) {
            return false;
        }
        // Always show button if display is phone sized.
        if (CompatUIUtils.shouldShowSizeCompatRestartForPhoneScreen(taskInfo)) {
            return true;
+40 −2
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.app.ActivityManager;
import android.app.TaskInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.testing.AndroidTestingRunner;
import android.util.Pair;
@@ -51,7 +50,6 @@ import android.view.View;

import androidx.test.filters.SmallTest;

import com.android.window.flags.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.common.DisplayLayout;
@@ -103,6 +101,7 @@ public class CompatUIWindowManagerTest extends ShellTestCase {
        MockitoAnnotations.initMocks(this);
        mDesktopState = new FakeDesktopState();
        doReturn(100).when(mCompatUIConfiguration).getHideSizeCompatRestartButtonTolerance();
        doReturn(true).when(mCompatUIConfiguration).isRestartButtonConfigEnabled();
        mTaskInfo = createTaskInfo(/* hasSizeCompat= */ false);

        final DisplayInfo displayInfo = new DisplayInfo();
@@ -435,6 +434,45 @@ public class CompatUIWindowManagerTest extends ShellTestCase {
        assertTrue(mWindowManager.shouldShowSizeCompatRestartButton(taskInfo));
    }

    @Test
    @RequiresFlagsDisabled(FLAG_APP_COMPAT_UI_FRAMEWORK)
    public void testRestartButtonDisabledShouldNotShowSizeCompatRestartButton() {
        doReturn(85).when(mCompatUIConfiguration).getHideSizeCompatRestartButtonTolerance();
        doReturn(false).when(mCompatUIConfiguration).isRestartButtonConfigEnabled();
        mWindowManager = new CompatUIWindowManager(mContext, mTaskInfo, mSyncTransactionQueue,
                mCallback, mTaskListener, mDisplayLayout, new CompatUIHintsState(),
                mCompatUIConfiguration, mOnRestartButtonClicked, mDesktopState);

        // Simulate rotation of activity in square display
        TaskInfo taskInfo = createTaskInfo(true);
        taskInfo.appCompatTaskInfo.topActivityLetterboxHeight = TASK_HEIGHT;
        taskInfo.appCompatTaskInfo.topActivityLetterboxWidth = 1850;

        assertFalse(mWindowManager.shouldShowSizeCompatRestartButton(taskInfo));

        // Simulate exiting split screen/folding
        taskInfo.appCompatTaskInfo.topActivityLetterboxWidth = 1000;
        assertFalse(mWindowManager.shouldShowSizeCompatRestartButton(taskInfo));

        // Simulate folding
        final InsetsState insetsState = new InsetsState();
        insetsState.setDisplayFrame(new Rect(0, 0, 1000, TASK_HEIGHT));
        final InsetsSource insetsSource = new InsetsSource(
                InsetsSource.createId(null, 0, navigationBars()), navigationBars());
        insetsSource.setFrame(0, TASK_HEIGHT - 200, 1000, TASK_HEIGHT);
        insetsState.addSource(insetsSource);
        mDisplayLayout.setInsets(mContext.getResources(), insetsState);
        mWindowManager.updateDisplayLayout(mDisplayLayout);
        taskInfo.configuration.smallestScreenWidthDp = LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP - 100;
        assertFalse(mWindowManager.shouldShowSizeCompatRestartButton(taskInfo));

        // Simulate floating app with 90& area, more than tolerance
        taskInfo.configuration.smallestScreenWidthDp = LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP;
        taskInfo.appCompatTaskInfo.topActivityLetterboxWidth = 950;
        taskInfo.appCompatTaskInfo.topActivityLetterboxHeight = 1900;
        assertFalse(mWindowManager.shouldShowSizeCompatRestartButton(taskInfo));
    }

    private static TaskInfo createTaskInfo(boolean hasSizeCompat) {
        ActivityManager.RunningTaskInfo taskInfo = new ActivityManager.RunningTaskInfo();
        taskInfo.taskId = TASK_ID;