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

Commit 2c6b9c60 authored by Orhan Uysal's avatar Orhan Uysal Committed by Automerger Merge Worker
Browse files

Merge "Add a way to reset persistent letterbox positions." into udc-qpr-dev am: e8c4f268

parents 225a2b20 e8c4f268
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -880,6 +880,58 @@ final class LetterboxConfiguration {
                        false /* forTabletopMode */);
    }

    /**
     * Overrides persistent horizontal position of the letterboxed app window when horizontal
     * reachability is enabled.
     */
    void setPersistentLetterboxPositionForHorizontalReachability(boolean forBookMode,
            @LetterboxHorizontalReachabilityPosition int position) {
        mLetterboxConfigurationPersister.setLetterboxPositionForHorizontalReachability(
                forBookMode, position);
    }

    /**
     * Overrides persistent vertical position of the letterboxed app window when vertical
     * reachability is enabled.
     */
    void setPersistentLetterboxPositionForVerticalReachability(boolean forTabletopMode,
            @LetterboxVerticalReachabilityPosition int position) {
        mLetterboxConfigurationPersister.setLetterboxPositionForVerticalReachability(
                forTabletopMode, position);
    }

    /**
     * Resets persistent horizontal position of the letterboxed app window when horizontal
     * reachability
     * is enabled to default position.
     */
    void resetPersistentLetterboxPositionForHorizontalReachability() {
        mLetterboxConfigurationPersister.setLetterboxPositionForHorizontalReachability(
                false /* forBookMode */,
                readLetterboxHorizontalReachabilityPositionFromConfig(mContext,
                        false /* forBookMode */));
        mLetterboxConfigurationPersister.setLetterboxPositionForHorizontalReachability(
                true /* forBookMode */,
                readLetterboxHorizontalReachabilityPositionFromConfig(mContext,
                        true /* forBookMode */));
    }

    /**
     * Resets persistent vertical position of the letterboxed app window when vertical reachability
     * is
     * enabled to default position.
     */
    void resetPersistentLetterboxPositionForVerticalReachability() {
        mLetterboxConfigurationPersister.setLetterboxPositionForVerticalReachability(
                false /* forTabletopMode */,
                readLetterboxVerticalReachabilityPositionFromConfig(mContext,
                        false /* forTabletopMode */));
        mLetterboxConfigurationPersister.setLetterboxPositionForVerticalReachability(
                true /* forTabletopMode */,
                readLetterboxVerticalReachabilityPositionFromConfig(mContext,
                        true /* forTabletopMode */));
    }

    @LetterboxHorizontalReachabilityPosition
    private static int readLetterboxHorizontalReachabilityPositionFromConfig(Context context,
            boolean forBookMode) {
+95 −1
Original line number Diff line number Diff line
@@ -911,6 +911,70 @@ public class WindowManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runSetPersistentLetterboxPositionForHorizontalReachability(PrintWriter pw)
            throws RemoteException {
        @LetterboxHorizontalReachabilityPosition final int position;
        try {
            String arg = getNextArgRequired();
            switch (arg) {
                case "left":
                    position = LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT;
                    break;
                case "center":
                    position = LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_CENTER;
                    break;
                case "right":
                    position = LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_RIGHT;
                    break;
                default:
                    getErrPrintWriter().println(
                            "Error: 'left', 'center' or 'right' are expected as an argument");
                    return -1;
            }
        } catch (IllegalArgumentException e) {
            getErrPrintWriter().println(
                    "Error: 'left', 'center' or 'right' are expected as an argument" + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
            mLetterboxConfiguration.setPersistentLetterboxPositionForHorizontalReachability(
                    false /* IsInBookMode */, position);
        }
        return 0;
    }

    private int runSetPersistentLetterboxPositionForVerticalReachability(PrintWriter pw)
            throws RemoteException {
        @LetterboxVerticalReachabilityPosition final int position;
        try {
            String arg = getNextArgRequired();
            switch (arg) {
                case "top":
                    position = LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP;
                    break;
                case "center":
                    position = LETTERBOX_VERTICAL_REACHABILITY_POSITION_CENTER;
                    break;
                case "bottom":
                    position = LETTERBOX_VERTICAL_REACHABILITY_POSITION_BOTTOM;
                    break;
                default:
                    getErrPrintWriter().println(
                            "Error: 'top', 'center' or 'bottom' are expected as an argument");
                    return -1;
            }
        } catch (IllegalArgumentException e) {
            getErrPrintWriter().println(
                    "Error: 'top', 'center' or 'bottom' are expected as an argument" + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
            mLetterboxConfiguration.setPersistentLetterboxPositionForVerticalReachability(
                    false /* forTabletopMode */, position);
        }
        return 0;
    }

    private int runSetBooleanFlag(PrintWriter pw, Consumer<Boolean> setter)
            throws RemoteException {
        String arg = getNextArg();
@@ -994,6 +1058,12 @@ public class WindowManagerShellCommand extends ShellCommand {
                case "--defaultPositionForVerticalReachability":
                    runSetLetterboxDefaultPositionForVerticalReachability(pw);
                    break;
                case "--persistentPositionForHorizontalReachability":
                    runSetPersistentLetterboxPositionForHorizontalReachability(pw);
                    break;
                case "--persistentPositionForVerticalReachability":
                    runSetPersistentLetterboxPositionForVerticalReachability(pw);
                    break;
                case "--isEducationEnabled":
                    runSetBooleanFlag(pw, mLetterboxConfiguration::setIsEducationEnabled);
                    break;
@@ -1080,6 +1150,14 @@ public class WindowManagerShellCommand extends ShellCommand {
                    case "defaultPositionForVerticalReachability":
                        mLetterboxConfiguration.resetDefaultPositionForVerticalReachability();
                        break;
                    case "persistentPositionForHorizontalReachability":
                        mLetterboxConfiguration
                                .resetPersistentLetterboxPositionForHorizontalReachability();
                        break;
                    case "persistentPositionForVerticalReachability":
                        mLetterboxConfiguration
                                .resetPersistentLetterboxPositionForVerticalReachability();
                        break;
                    case "isEducationEnabled":
                        mLetterboxConfiguration.resetIsEducationEnabled();
                        break;
@@ -1206,6 +1284,8 @@ public class WindowManagerShellCommand extends ShellCommand {
            mLetterboxConfiguration.resetEnabledAutomaticReachabilityInBookMode();
            mLetterboxConfiguration.resetDefaultPositionForHorizontalReachability();
            mLetterboxConfiguration.resetDefaultPositionForVerticalReachability();
            mLetterboxConfiguration.resetPersistentLetterboxPositionForHorizontalReachability();
            mLetterboxConfiguration.resetPersistentLetterboxPositionForVerticalReachability();
            mLetterboxConfiguration.resetIsEducationEnabled();
            mLetterboxConfiguration.resetIsSplitScreenAspectRatioForUnresizableAppsEnabled();
            mLetterboxConfiguration.resetIsDisplayAspectRatioEnabledForFixedOrientationLetterbox();
@@ -1233,6 +1313,12 @@ public class WindowManagerShellCommand extends ShellCommand {
            pw.println("Vertical position multiplier (tabletop mode): "
                    + mLetterboxConfiguration.getLetterboxVerticalPositionMultiplier(
                            true /* isInTabletopMode */));
            pw.println("Horizontal position multiplier for reachability: "
                    + mLetterboxConfiguration.getHorizontalMultiplierForReachability(
                            false /* isInBookMode */));
            pw.println("Vertical position multiplier for reachability: "
                    + mLetterboxConfiguration.getVerticalMultiplierForReachability(
                            false /* isInTabletopMode */));
            pw.println("Aspect ratio: "
                    + mLetterboxConfiguration.getFixedOrientationLetterboxAspectRatio());
            pw.println("Default min aspect ratio for unresizable apps: "
@@ -1472,6 +1558,12 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("      --defaultPositionForVerticalReachability [top|center|bottom]");
        pw.println("        Default position of app window when vertical reachability is.");
        pw.println("        enabled.");
        pw.println("      --persistentPositionForHorizontalReachability [left|center|right]");
        pw.println("        Persistent position of app window when horizontal reachability is.");
        pw.println("        enabled.");
        pw.println("      --persistentPositionForVerticalReachability [top|center|bottom]");
        pw.println("        Persistent position of app window when vertical reachability is.");
        pw.println("        enabled.");
        pw.println("      --isEducationEnabled [true|1|false|0]");
        pw.println("        Whether education is allowed for letterboxed fullscreen apps.");
        pw.println("      --isSplitScreenAspectRatioForUnresizableAppsEnabled [true|1|false|0]");
@@ -1493,8 +1585,10 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("      |backgroundColor|wallpaperBlurRadius|wallpaperDarkScrimAlpha");
        pw.println("      |horizontalPositionMultiplier|verticalPositionMultiplier");
        pw.println("      |isHorizontalReachabilityEnabled|isVerticalReachabilityEnabled");
        pw.println("      |isEducationEnabled||defaultPositionMultiplierForHorizontalReachability");
        pw.println("      |isEducationEnabled|defaultPositionMultiplierForHorizontalReachability");
        pw.println("      |isTranslucentLetterboxingEnabled|isUserAppAspectRatioSettingsEnabled");
        pw.println("      |persistentPositionMultiplierForHorizontalReachability");
        pw.println("      |persistentPositionMultiplierForVerticalReachability");
        pw.println("      |defaultPositionMultiplierForVerticalReachability]");
        pw.println("    Resets overrides to default values for specified properties separated");
        pw.println("    by space, e.g. 'reset-letterbox-style aspectRatio cornerRadius'.");
+38 −0
Original line number Diff line number Diff line
@@ -250,4 +250,42 @@ public class LetterboxConfigurationTest {
                times(expectedTime)).setLetterboxPositionForVerticalReachability(halfFoldPose,
                expected);
    }

    @Test
    public void test_letterboxPositionWhenReachabilityEnabledIsReset() {
        // Check that horizontal reachability is set with correct arguments
        mLetterboxConfiguration.resetPersistentLetterboxPositionForHorizontalReachability();
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForHorizontalReachability(
                false /* forBookMode */,
                LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_CENTER);
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForHorizontalReachability(
                true /* forBookMode */,
                LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT);

        // Check that vertical reachability is set with correct arguments
        mLetterboxConfiguration.resetPersistentLetterboxPositionForVerticalReachability();
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForVerticalReachability(
                false /* forTabletopMode */,
                LETTERBOX_VERTICAL_REACHABILITY_POSITION_CENTER);
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForVerticalReachability(
                true /* forTabletopMode */,
                LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP);
    }

    @Test
    public void test_lettterboxPositionWhenReachabilityEnabledIsSet() {
        // Check that horizontal reachability is set with correct arguments
        mLetterboxConfiguration.setPersistentLetterboxPositionForHorizontalReachability(
                false /* forBookMode */, LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT);
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForHorizontalReachability(
                false /* forBookMode */,
                LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_LEFT);

        // Check that vertical reachability is set with correct arguments
        mLetterboxConfiguration.setPersistentLetterboxPositionForVerticalReachability(
                false /* forTabletopMode */, LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP);
        verify(mLetterboxConfigurationPersister).setLetterboxPositionForVerticalReachability(
                false /* forTabletopMode */,
                LETTERBOX_VERTICAL_REACHABILITY_POSITION_TOP);
    }
}