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

Commit 2cdf859c authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Introduce Forward Override Options for the stable config

This change introduced a forward overriding flag when the stable
configuration behavior is not by default applied to an app. The device
owners can override the flag for apps that are ready for the stable
configuration behavior to provide a better user experience.

This will apply if the system overall stable configuration is not
enabled, or it is enabled but the app is not targeting SDK level 35+
yet.

Bug: 327313645
Test: Change the override the flag value and check the config
Test: ActivityRecordTests
Change-Id: I9f4bbc23b07f63cb40070c6240b0b37660963860
parent ff603f83
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1528,6 +1528,26 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    public static final long INSETS_DECOUPLED_CONFIGURATION_ENFORCED = 151861875L;

    /**
     * When enabled, the activity will receive configuration decoupled from system bar insets.
     *
     * <p>This will only apply if the activity is targeting SDK level 34 or earlier versions.
     *
     * <p>This will only in effect if the device is trying to provide a different value by default
     * other than the legacy value, i.e., the
     * {@code Flags.allowsScreenSizeDecoupledFromStatusBarAndCutout()} is set to true.
     *
     * <p>If the {@code Flags.insetsDecoupledConfiguration()} is also set to true, all apps
     * targeting SDK level 35 or later, and apps with this override flag will receive the insets
     * decoupled configuration.
     *
     * @hide
     */
    @ChangeId
    @Disabled
    @Overridable
    public static final long OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION = 327313645L;

    /**
     * Optional set of a certificates identifying apps that are allowed to embed this activity. From
     * the "knownActivityEmbeddingCerts" attribute.
+20 −9
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import static android.content.pm.ActivityInfo.FLAG_NO_HISTORY;
import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
import static android.content.pm.ActivityInfo.FLAG_STATE_NOT_NEEDED;
import static android.content.pm.ActivityInfo.FLAG_TURN_SCREEN_ON;
import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION;
import static android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED;
import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
@@ -2119,9 +2120,19 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mCameraCompatControlEnabled = mWmService.mContext.getResources()
                .getBoolean(R.bool.config_isCameraCompatControlForStretchedIssuesEnabled);
        mResolveConfigHint = new TaskFragment.ConfigOverrideHint();
        mResolveConfigHint.mUseLegacyInsetsForStableBounds =
                mWmService.mFlags.mInsetsDecoupledConfiguration
                        && !info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED);
        if (mWmService.mFlags.mInsetsDecoupledConfiguration) {
            // When the stable configuration is the default behavior, override for the legacy apps
            // without forward override flag.
            mResolveConfigHint.mUseOverrideInsetsForStableBounds =
                    !info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED)
                            && !info.isChangeEnabled(
                                    OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION);
        } else {
            // When the stable configuration is not the default behavior, forward overriding the
            // listed apps.
            mResolveConfigHint.mUseOverrideInsetsForStableBounds =
                    info.isChangeEnabled(OVERRIDE_ENABLE_INSETS_DECOUPLED_CONFIGURATION);
        }

        mTargetSdk = info.applicationInfo.targetSdkVersion;

@@ -8425,7 +8436,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mCompatDisplayInsets =
                new CompatDisplayInsets(
                        mDisplayContent, this, letterboxedContainerBounds,
                        mResolveConfigHint.mUseLegacyInsetsForStableBounds);
                        mResolveConfigHint.mUseOverrideInsetsForStableBounds);
    }

    private void clearSizeCompatModeAttributes() {
@@ -8628,7 +8639,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (rotation == ROTATION_UNDEFINED && !isFixedRotationTransforming()) {
            rotation = mDisplayContent.getRotation();
        }
        if (!mResolveConfigHint.mUseLegacyInsetsForStableBounds
        if (!mResolveConfigHint.mUseOverrideInsetsForStableBounds
                || getCompatDisplayInsets() != null
                || isFloating(parentWindowingMode) || parentAppBounds == null
                || parentAppBounds.isEmpty() || rotation == ROTATION_UNDEFINED) {
@@ -8945,7 +8956,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (mDisplayContent == null) {
            return true;
        }
        if (!mResolveConfigHint.mUseLegacyInsetsForStableBounds) {
        if (!mResolveConfigHint.mUseOverrideInsetsForStableBounds) {
            // No insets should be considered any more.
            return true;
        }
@@ -8964,7 +8975,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final Task task = getTask();
        task.calculateInsetFrames(outNonDecorBounds /* outNonDecorBounds */,
                outStableBounds /* outStableBounds */, parentBounds /* bounds */, di,
                mResolveConfigHint.mUseLegacyInsetsForStableBounds);
                mResolveConfigHint.mUseOverrideInsetsForStableBounds);
        final int orientationWithInsets = outStableBounds.height() >= outStableBounds.width()
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        // If orientation does not match the orientation with insets applied, then a
@@ -9021,7 +9032,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                getResolvedOverrideConfiguration().windowConfiguration.getBounds();
        final int stableBoundsOrientation = stableBounds.width() > stableBounds.height()
                ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
        final int parentOrientation = mResolveConfigHint.mUseLegacyInsetsForStableBounds
        final int parentOrientation = mResolveConfigHint.mUseOverrideInsetsForStableBounds
                ? stableBoundsOrientation : newParentConfig.orientation;

        // If the activity requires a different orientation (either by override or activityInfo),
@@ -9046,7 +9057,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return;
        }

        final Rect parentAppBounds = mResolveConfigHint.mUseLegacyInsetsForStableBounds
        final Rect parentAppBounds = mResolveConfigHint.mUseOverrideInsetsForStableBounds
                ? outNonDecorBounds : newParentConfig.windowConfiguration.getAppBounds();
        // TODO(b/182268157): Explore using only one type of parentBoundsWithInsets, either app
        // bounds or stable bounds to unify aspect ratio logic.
+4 −4
Original line number Diff line number Diff line
@@ -2213,7 +2213,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    static class ConfigOverrideHint {
        @Nullable DisplayInfo mTmpOverrideDisplayInfo;
        @Nullable ActivityRecord.CompatDisplayInsets mTmpCompatInsets;
        boolean mUseLegacyInsetsForStableBounds;
        boolean mUseOverrideInsetsForStableBounds;
    }

    void computeConfigResourceOverrides(@NonNull Configuration inOutConfig,
@@ -2246,11 +2246,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            @NonNull Configuration parentConfig, @Nullable ConfigOverrideHint overrideHint) {
        DisplayInfo overrideDisplayInfo = null;
        ActivityRecord.CompatDisplayInsets compatInsets = null;
        boolean useLegacyInsetsForStableBounds = false;
        boolean useOverrideInsetsForStableBounds = false;
        if (overrideHint != null) {
            overrideDisplayInfo = overrideHint.mTmpOverrideDisplayInfo;
            compatInsets = overrideHint.mTmpCompatInsets;
            useLegacyInsetsForStableBounds = overrideHint.mUseLegacyInsetsForStableBounds;
            useOverrideInsetsForStableBounds = overrideHint.mUseOverrideInsetsForStableBounds;
            if (overrideDisplayInfo != null) {
                // Make sure the screen related configs can be computed by the provided
                // display info.
@@ -2330,7 +2330,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                // The non decor inset are areas that could never be removed in Honeycomb. See
                // {@link WindowManagerPolicy#getNonDecorInsetsLw}.
                calculateInsetFrames(mTmpNonDecorBounds, mTmpStableBounds, mTmpFullBounds, di,
                        useLegacyInsetsForStableBounds);
                        useOverrideInsetsForStableBounds);
            } else {
                // Apply the given non-decor and stable insets to calculate the corresponding bounds
                // for screen size of configuration.