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

Commit 65f334df authored by Massimo Carli's avatar Massimo Carli
Browse files

Handle letterbox education when disabled

When the letterbox education is disabled we should exclude it
from the initial education flow.

Bug: 335272191
Test: atest WMShellUnitTests:CompatUIControllerTest
Test: atest WmTests:LetterboxUiControllerTest

Change-Id: Iec500496045c9dd324f4a6d8dd1f35712bb0c582
parent b3b7b197
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -75,6 +75,11 @@ public class AppCompatTaskInfo implements Parcelable {
     */
    public boolean topActivityEligibleForLetterboxEducation;

    /**
     * Whether the letterbox education is enabled
     */
    public boolean isLetterboxEducationEnabled;

    /**
     * Whether the direct top activity is in size compat mode on foreground.
     */
@@ -224,6 +229,7 @@ public class AppCompatTaskInfo implements Parcelable {
                    == that.topActivityEligibleForUserAspectRatioButton
                && topActivityEligibleForLetterboxEducation
                    == that.topActivityEligibleForLetterboxEducation
                && isLetterboxEducationEnabled == that.isLetterboxEducationEnabled
                && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition
                && topActivityLetterboxHorizontalPosition
                    == that.topActivityLetterboxHorizontalPosition
@@ -238,6 +244,7 @@ public class AppCompatTaskInfo implements Parcelable {
     * Reads the TaskInfo from a parcel.
     */
    void readFromParcel(Parcel source) {
        isLetterboxEducationEnabled = source.readBoolean();
        topActivityInSizeCompat = source.readBoolean();
        topActivityEligibleForLetterboxEducation = source.readBoolean();
        cameraCompatControlState = source.readInt();
@@ -258,6 +265,7 @@ public class AppCompatTaskInfo implements Parcelable {
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBoolean(isLetterboxEducationEnabled);
        dest.writeBoolean(topActivityInSizeCompat);
        dest.writeBoolean(topActivityEligibleForLetterboxEducation);
        dest.writeInt(cameraCompatControlState);
@@ -278,6 +286,7 @@ public class AppCompatTaskInfo implements Parcelable {
        return "AppCompatTaskInfo { topActivityInSizeCompat=" + topActivityInSizeCompat
                + " topActivityEligibleForLetterboxEducation= "
                + topActivityEligibleForLetterboxEducation
                + "isLetterboxEducationEnabled= " + isLetterboxEducationEnabled
                + " isLetterboxDoubleTapEnabled= " + isLetterboxDoubleTapEnabled
                + " topActivityEligibleForUserAspectRatioButton= "
                + topActivityEligibleForUserAspectRatioButton
+34 −2
Original line number Diff line number Diff line
@@ -188,6 +188,11 @@ public class CompatUIController implements OnDisplaysChangedListener,
     */
    private boolean mHasShownUserAspectRatioSettingsButton = false;

    /**
     * This is true when the rechability education is displayed for the first time.
     */
    private boolean mIsFirstReachabilityEducationRunning;

    public CompatUIController(@NonNull Context context,
            @NonNull ShellInit shellInit,
            @NonNull ShellController shellController,
@@ -252,9 +257,35 @@ public class CompatUIController implements OnDisplaysChangedListener,
            removeLayouts(taskInfo.taskId);
            return;
        }

        createOrUpdateCompatLayout(taskInfo, taskListener);
        // We're showing the first reachability education so we ignore incoming TaskInfo
        // until the education flow has completed or we double tap.
        if (mIsFirstReachabilityEducationRunning) {
            return;
        }
        if (taskInfo.appCompatTaskInfo.topActivityBoundsLetterboxed) {
            if (taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled) {
                createOrUpdateLetterboxEduLayout(taskInfo, taskListener);
            } else if (!taskInfo.appCompatTaskInfo.isFromLetterboxDoubleTap) {
                // In this case the app is letterboxed and the letterbox education
                // is disabled. In this case we need to understand if it's the first
                // time we show the reachability education. When this is happening
                // we need to ignore all the incoming TaskInfo until the education
                // completes. If we come from a double tap we follow the normal flow.
                final boolean topActivityPillarboxed =
                        taskInfo.appCompatTaskInfo.isTopActivityPillarboxed();
                final boolean isFirstTimeHorizontalReachabilityEdu = topActivityPillarboxed
                        && !mCompatUIConfiguration.hasSeenHorizontalReachabilityEducation(taskInfo);
                final boolean isFirstTimeVerticalReachabilityEdu = !topActivityPillarboxed
                        && !mCompatUIConfiguration.hasSeenVerticalReachabilityEducation(taskInfo);
                if (isFirstTimeHorizontalReachabilityEdu || isFirstTimeVerticalReachabilityEdu) {
                    mIsFirstReachabilityEducationRunning = true;
                    mCompatUIConfiguration.setSeenLetterboxEducation(taskInfo.userId);
                    createOrUpdateReachabilityEduLayout(taskInfo, taskListener);
                    return;
                }
            }
        }
        createOrUpdateCompatLayout(taskInfo, taskListener);
        createOrUpdateRestartDialogLayout(taskInfo, taskListener);
        if (mCompatUIConfiguration.getHasSeenLetterboxEducation(taskInfo.userId)) {
            createOrUpdateReachabilityEduLayout(taskInfo, taskListener);
@@ -589,6 +620,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
    private void onInitialReachabilityEduDismissed(@NonNull TaskInfo taskInfo,
            @NonNull ShellTaskOrganizer.TaskListener taskListener) {
        // We need to update the UI otherwise it will not be shown until the user relaunches the app
        mIsFirstReachabilityEducationRunning = false;
        createOrUpdateUserAspectRatioSettingsLayout(taskInfo, taskListener);
    }

+14 −0
Original line number Diff line number Diff line
@@ -668,6 +668,18 @@ public class CompatUIControllerTest extends ShellTestCase {
        Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton());
    }

    @Test
    public void testLetterboxEduLayout_notCreatedWhenLetterboxEducationIsDisabled() {
        TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true,
                CAMERA_COMPAT_CONTROL_HIDDEN);
        taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled = false;

        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);

        verify(mController, never()).createLetterboxEduWindowManager(any(), eq(taskInfo),
                eq(mMockTaskListener));
    }

    private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
            @CameraCompatControlState int cameraCompatControlState) {
        return createTaskInfo(displayId, taskId, hasSizeCompat, cameraCompatControlState,
@@ -693,6 +705,8 @@ public class CompatUIControllerTest extends ShellTestCase {
        taskInfo.isVisible = isVisible;
        taskInfo.isFocused = isFocused;
        taskInfo.isTopActivityTransparent = isTopActivityTransparent;
        taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled = true;
        taskInfo.appCompatTaskInfo.topActivityBoundsLetterboxed = true;
        return taskInfo;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -970,6 +970,10 @@ final class LetterboxUiController {
        }
    }

    boolean isLetterboxEducationEnabled() {
        return mLetterboxConfiguration.getIsEducationEnabled();
    }

    /**
     * Whether we use split screen aspect ratio for the activity when camera compat treatment
     * is active because the corresponding config is enabled and activity supports resizing.
+2 −0
Original line number Diff line number Diff line
@@ -3532,6 +3532,8 @@ class Task extends TaskFragment {
        // Whether the direct top activity is eligible for letterbox education.
        appCompatTaskInfo.topActivityEligibleForLetterboxEducation = isTopActivityResumed
                && top.isEligibleForLetterboxEducation();
        appCompatTaskInfo.isLetterboxEducationEnabled = top != null
                && top.mLetterboxUiController.isLetterboxEducationEnabled();
        // Whether the direct top activity requested showing camera compat control.
        appCompatTaskInfo.cameraCompatControlState = isTopActivityResumed
                ? top.getCameraCompatControlState()
Loading