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

Commit 8c18ee77 authored by Massimo Carli's avatar Massimo Carli Committed by Automerger Merge Worker
Browse files

Merge "[1/n] Disable reachability for thin letterboxing" into 24D1-dev am: 2951eba4

parents 9cd6f2a9 2951eba4
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -6093,6 +6093,18 @@
    <!-- Whether displaying letterbox education is enabled for letterboxed fullscreen apps. -->
    <!-- Whether displaying letterbox education is enabled for letterboxed fullscreen apps. -->
    <bool name="config_letterboxIsEducationEnabled">false</bool>
    <bool name="config_letterboxIsEducationEnabled">false</bool>


    <!-- The width in dp to use to detect vertical thin letterboxing.
         If W is the available width and w is the letterbox width, an app
         is thin letterboxed if the value here is < (W - w) / 2
         If the value is < 0 the thin letterboxing policy is disabled -->
    <dimen name="config_letterboxThinLetterboxWidthDp">-1dp</dimen>

    <!-- The height in dp to use to detect horizontal thin letterboxing
         If H is the available height and h is the letterbox height, an app
         is thin letterboxed if the value here is < (H - h) / 2
         If the value is < 0 the thin letterboxing policy is disabled -->
    <dimen name="config_letterboxThinLetterboxHeightDp">-1dp</dimen>

    <!-- Default min aspect ratio for unresizable apps which are eligible for size compat mode.
    <!-- Default min aspect ratio for unresizable apps which are eligible for size compat mode.
         Values <= 1.0 will be ignored. Activity min/max aspect ratio restrictions will still be
         Values <= 1.0 will be ignored. Activity min/max aspect ratio restrictions will still be
         espected so this override can control the maximum screen area that can be occupied by
         espected so this override can control the maximum screen area that can be occupied by
+2 −0
Original line number Original line Diff line number Diff line
@@ -4717,6 +4717,8 @@
  <java-symbol type="integer" name="config_letterboxDefaultPositionForTabletopModeReachability" />
  <java-symbol type="integer" name="config_letterboxDefaultPositionForTabletopModeReachability" />
  <java-symbol type="bool" name="config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled" />
  <java-symbol type="bool" name="config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled" />
  <java-symbol type="bool" name="config_letterboxIsEducationEnabled" />
  <java-symbol type="bool" name="config_letterboxIsEducationEnabled" />
  <java-symbol type="dimen" name="config_letterboxThinLetterboxWidthDp" />
  <java-symbol type="dimen" name="config_letterboxThinLetterboxHeightDp" />
  <java-symbol type="dimen" name="config_letterboxDefaultMinAspectRatioForUnresizableApps" />
  <java-symbol type="dimen" name="config_letterboxDefaultMinAspectRatioForUnresizableApps" />
  <java-symbol type="bool" name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled" />
  <java-symbol type="bool" name="config_letterboxIsSplitScreenAspectRatioForUnresizableAppsEnabled" />
  <java-symbol type="bool" name="config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled" />
  <java-symbol type="bool" name="config_letterboxIsDisplayAspectRatioForFixedOrientationLetterboxEnabled" />
+29 −1
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Color;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig;
import android.util.Slog;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -33,6 +32,7 @@ import com.android.internal.annotations.VisibleForTesting;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Function;
import java.util.function.Function;
import java.util.function.IntSupplier;


/** Reads letterbox configs from resources and controls their overrides at runtime. */
/** Reads letterbox configs from resources and controls their overrides at runtime. */
final class LetterboxConfiguration {
final class LetterboxConfiguration {
@@ -265,6 +265,12 @@ final class LetterboxConfiguration {
    // unresizable apps
    // unresizable apps
    private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;
    private boolean mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;


    // Supplier for the value in pixel to consider when detecting vertical thin letterboxing
    private final IntSupplier mThinLetterboxWidthFn;

    // Supplier for the value in pixel to consider when detecting horizontal thin letterboxing
    private final IntSupplier mThinLetterboxHeightFn;

    // Allows to enable letterboxing strategy for translucent activities ignoring flags.
    // Allows to enable letterboxing strategy for translucent activities ignoring flags.
    private boolean mTranslucentLetterboxingOverrideEnabled;
    private boolean mTranslucentLetterboxingOverrideEnabled;


@@ -358,6 +364,10 @@ final class LetterboxConfiguration {
                R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled);
                R.bool.config_isWindowManagerCameraCompatSplitScreenAspectRatioEnabled);
        mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean(
        mIsPolicyForIgnoringRequestedOrientationEnabled = mContext.getResources().getBoolean(
                R.bool.config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled);
                R.bool.config_letterboxIsPolicyForIgnoringRequestedOrientationEnabled);
        mThinLetterboxWidthFn = () ->  mContext.getResources().getDimensionPixelSize(
                R.dimen.config_letterboxThinLetterboxWidthDp);
        mThinLetterboxHeightFn = () -> mContext.getResources().getDimensionPixelSize(
                R.dimen.config_letterboxThinLetterboxHeightDp);


        mLetterboxConfigurationPersister = letterboxConfigurationPersister;
        mLetterboxConfigurationPersister = letterboxConfigurationPersister;
        mLetterboxConfigurationPersister.start();
        mLetterboxConfigurationPersister.start();
@@ -1128,6 +1138,24 @@ final class LetterboxConfiguration {
        return mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;
        return mIsDisplayAspectRatioEnabledForFixedOrientationLetterbox;
    }
    }


    /**
     * @return Width in pixel about the padding to use to understand if the letterbox for an
     *         activity is thin. If the available space has width W and the app has width w, this
     *         is the maximum value for (W - w) / 2 to be considered for a thin letterboxed app.
     */
    int getThinLetterboxWidthPx() {
        return mThinLetterboxWidthFn.getAsInt();
    }

    /**
     * @return Height in pixel about the padding to use to understand if a letterbox is thin.
     *         If the available space has height H and the app has height h, this is the maximum
     *         value for (H - h) / 2 to be considered for a thin letterboxed app.
     */
    int getThinLetterboxHeightPx() {
        return mThinLetterboxHeightFn.getAsInt();
    }

    /**
    /**
     * Overrides whether using split screen aspect ratio as a default aspect ratio for unresizable
     * Overrides whether using split screen aspect ratio as a default aspect ratio for unresizable
     * apps.
     * apps.
+69 −0
Original line number Original line Diff line number Diff line
@@ -1024,6 +1024,67 @@ final class LetterboxUiController {
        return getSplitScreenAspectRatio();
        return getSplitScreenAspectRatio();
    }
    }


    /**
     * @return {@value true} if the resulting app is letterboxed in a way defined as thin.
     */
    boolean isVerticalThinLetterboxed() {
        final int thinHeight = mLetterboxConfiguration.getThinLetterboxHeightPx();
        if (thinHeight < 0) {
            return false;
        }
        final Task task = mActivityRecord.getTask();
        if (task == null) {
            return false;
        }
        final int padding = Math.abs(
                task.getBounds().height() - mActivityRecord.getBounds().height()) / 2;
        return padding <= thinHeight;
    }

    /**
     * @return {@value true} if the resulting app is pillarboxed in a way defined as thin.
     */
    boolean isHorizontalThinLetterboxed() {
        final int thinWidth = mLetterboxConfiguration.getThinLetterboxWidthPx();
        if (thinWidth < 0) {
            return false;
        }
        final Task task = mActivityRecord.getTask();
        if (task == null) {
            return false;
        }
        final int padding = Math.abs(
                task.getBounds().width() - mActivityRecord.getBounds().width()) / 2;
        return padding <= thinWidth;
    }


    /**
     * @return {@value true} if the vertical reachability should be allowed in case of
     * thin letteboxing
     */
    boolean allowVerticalReachabilityForThinLetterbox() {
        if (!Flags.disableThinLetterboxingReachability()) {
            return true;
        }
        // When the flag is enabled we allow vertical reachability only if the
        // app is not thin letterboxed vertically.
        return !isVerticalThinLetterboxed();
    }

    /**
     * @return {@value true} if the vertical reachability should be enabled in case of
     * thin letteboxing
     */
    boolean allowHorizontalReachabilityForThinLetterbox() {
        if (!Flags.disableThinLetterboxingReachability()) {
            return true;
        }
        // When the flag is enabled we allow horizontal reachability only if the
        // app is not thin pillarboxed.
        return !isHorizontalThinLetterboxed();
    }

    float getSplitScreenAspectRatio() {
    float getSplitScreenAspectRatio() {
        // Getting the same aspect ratio that apps get in split screen.
        // Getting the same aspect ratio that apps get in split screen.
        final DisplayArea displayArea = mActivityRecord.getDisplayArea();
        final DisplayArea displayArea = mActivityRecord.getDisplayArea();
@@ -1263,6 +1324,9 @@ final class LetterboxUiController {
     * </ul>
     * </ul>
     */
     */
    private boolean isHorizontalReachabilityEnabled(Configuration parentConfiguration) {
    private boolean isHorizontalReachabilityEnabled(Configuration parentConfiguration) {
        if (!allowHorizontalReachabilityForThinLetterbox()) {
            return false;
        }
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // as activity bounds can sometimes be empty
        // as activity bounds can sometimes be empty
        final Rect opaqueActivityBounds = hasInheritedLetterboxBehavior()
        final Rect opaqueActivityBounds = hasInheritedLetterboxBehavior()
@@ -1298,6 +1362,9 @@ final class LetterboxUiController {
     * </ul>
     * </ul>
     */
     */
    private boolean isVerticalReachabilityEnabled(Configuration parentConfiguration) {
    private boolean isVerticalReachabilityEnabled(Configuration parentConfiguration) {
        if (!allowVerticalReachabilityForThinLetterbox()) {
            return false;
        }
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // Use screen resolved bounds which uses resolved bounds or size compat bounds
        // as activity bounds can sometimes be empty
        // as activity bounds can sometimes be empty
        final Rect opaqueActivityBounds = hasInheritedLetterboxBehavior()
        final Rect opaqueActivityBounds = hasInheritedLetterboxBehavior()
@@ -1566,6 +1633,8 @@ final class LetterboxUiController {
        if (!shouldShowLetterboxUi) {
        if (!shouldShowLetterboxUi) {
            return;
            return;
        }
        }
        pw.println(prefix + "  isVerticalThinLetterboxed=" + isVerticalThinLetterboxed());
        pw.println(prefix + "  isHorizontalThinLetterboxed=" + isHorizontalThinLetterboxed());
        pw.println(prefix + "  letterboxBackgroundColor=" + Integer.toHexString(
        pw.println(prefix + "  letterboxBackgroundColor=" + Integer.toHexString(
                getLetterboxBackgroundColor().toArgb()));
                getLetterboxBackgroundColor().toArgb()));
        pw.println(prefix + "  letterboxBackgroundType="
        pw.println(prefix + "  letterboxBackgroundType="
+20 −8
Original line number Original line Diff line number Diff line
@@ -3462,8 +3462,6 @@ class Task extends TaskFragment {
        info.isVisibleRequested = isVisibleRequested();
        info.isVisibleRequested = isVisibleRequested();
        info.isSleeping = shouldSleepActivities();
        info.isSleeping = shouldSleepActivities();
        info.isTopActivityTransparent = top != null && !top.fillsParent();
        info.isTopActivityTransparent = top != null && !top.fillsParent();
        appCompatTaskInfo.isLetterboxDoubleTapEnabled = top != null
                && top.mLetterboxUiController.isLetterboxDoubleTapEducationEnabled();
        appCompatTaskInfo.topActivityLetterboxVerticalPosition = TaskInfo.PROPERTY_VALUE_UNSET;
        appCompatTaskInfo.topActivityLetterboxVerticalPosition = TaskInfo.PROPERTY_VALUE_UNSET;
        appCompatTaskInfo.topActivityLetterboxHorizontalPosition = TaskInfo.PROPERTY_VALUE_UNSET;
        appCompatTaskInfo.topActivityLetterboxHorizontalPosition = TaskInfo.PROPERTY_VALUE_UNSET;
        appCompatTaskInfo.topActivityLetterboxWidth = TaskInfo.PROPERTY_VALUE_UNSET;
        appCompatTaskInfo.topActivityLetterboxWidth = TaskInfo.PROPERTY_VALUE_UNSET;
@@ -3478,15 +3476,29 @@ class Task extends TaskFragment {
            appCompatTaskInfo.topActivityLetterboxWidth = top.getBounds().width();
            appCompatTaskInfo.topActivityLetterboxWidth = top.getBounds().width();
            appCompatTaskInfo.topActivityLetterboxHeight = top.getBounds().height();
            appCompatTaskInfo.topActivityLetterboxHeight = top.getBounds().height();
        }
        }
        // We need to consider if letterboxed or pillarboxed
        // TODO(b/336807329) Encapsulate reachability logic
        appCompatTaskInfo.isLetterboxDoubleTapEnabled = top != null
                && top.mLetterboxUiController.isLetterboxDoubleTapEducationEnabled();
        if (appCompatTaskInfo.isLetterboxDoubleTapEnabled) {
        if (appCompatTaskInfo.isLetterboxDoubleTapEnabled) {
            if (appCompatTaskInfo.isTopActivityPillarboxed()) {
            if (appCompatTaskInfo.isTopActivityPillarboxed()) {
                if (top.mLetterboxUiController.allowHorizontalReachabilityForThinLetterbox()) {
                    // Pillarboxed
                    // Pillarboxed
                    appCompatTaskInfo.topActivityLetterboxHorizontalPosition =
                    appCompatTaskInfo.topActivityLetterboxHorizontalPosition =
                        top.mLetterboxUiController.getLetterboxPositionForHorizontalReachability();
                            top.mLetterboxUiController
                                    .getLetterboxPositionForHorizontalReachability();
                } else {
                } else {
                    appCompatTaskInfo.isLetterboxDoubleTapEnabled = false;
                }
            } else {
                if (top.mLetterboxUiController.allowVerticalReachabilityForThinLetterbox()) {
                    // Letterboxed
                    // Letterboxed
                    appCompatTaskInfo.topActivityLetterboxVerticalPosition =
                    appCompatTaskInfo.topActivityLetterboxVerticalPosition =
                        top.mLetterboxUiController.getLetterboxPositionForVerticalReachability();
                            top.mLetterboxUiController
                                    .getLetterboxPositionForVerticalReachability();
                } else {
                    appCompatTaskInfo.isLetterboxDoubleTapEnabled = false;
                }
            }
            }
        }
        }
        appCompatTaskInfo.topActivityEligibleForUserAspectRatioButton = top != null
        appCompatTaskInfo.topActivityEligibleForUserAspectRatioButton = top != null
Loading