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

Commit 030001ce authored by Annie Lin's avatar Annie Lin
Browse files

Skip applying legacy insets for app bubbles behind flags.

For apps targeting SDK earlier than 35, legacy insets would be added if they are bubble'd. This triggers a bug with size compat mode where the restart button won't be able to correctly scale least one side of the activity to its parent.

Fix: 384610304
Before: screenshot/C8xTxrSoWsdhTUk
After: screenshot/8LqLJnaQKuDV6UC
Test: wm presubmit
Flag: com.android.wm.shell.enable_create_any_bubble
Flag: com.android.wm.shell.enable_bubble_app_compat_fixes
Change-Id: I2e66a101d3e60bfaaea52d79f9b955534811dd0d
parent 61a7063d
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.activityTypeToString;
import static android.app.WindowConfiguration.isFloating;
import static android.content.Context.CONTEXT_RESTRICTED;
import static android.content.Intent.ACTION_MAIN;
import static android.content.Intent.CATEGORY_HOME;
@@ -7533,8 +7534,21 @@ final class ActivityRecord extends WindowToken {
        final AppCompatSafeRegionPolicy safeRegionPolicy =
                mAppCompatController.getSafeRegionPolicy();
        mAppCompatController.getLetterboxPolicy().resetFixedOrientationLetterboxEligibility();

        boolean shouldApplyLegacyInsets =
                !isFloating(newParentConfiguration.windowConfiguration.getWindowingMode());
        if (com.android.wm.shell.Flags.enableCreateAnyBubble()
                && com.android.wm.shell.Flags.enableBubbleAppCompatFixes()) {
            final Task task = getTask();
            if (task != null) {
                // Similar to floating windows, an app bubble should not apply legacy insets.
                // TODO(b/407669465): Update isAppBubble usage once migrated to the new approach.
                shouldApplyLegacyInsets &= !task.getTaskInfo().isAppBubble;
            }
        }
        mResolveConfigHint.resolveTmpOverrides(mDisplayContent, newParentConfiguration,
                isFixedRotationTransforming(), safeRegionPolicy.getLatestSafeRegionBounds());
                isFixedRotationTransforming(), safeRegionPolicy.getLatestSafeRegionBounds(),
                shouldApplyLegacyInsets);

        // Can't use resolvedConfig.windowConfiguration.getWindowingMode() because it can be
        // different from windowing mode of the task (PiP) during transition from fullscreen to PiP
+3 −3
Original line number Diff line number Diff line
@@ -2314,7 +2314,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        boolean mUseOverrideInsetsForConfig;

        void resolveTmpOverrides(DisplayContent dc, Configuration parentConfig,
                boolean isFixedRotationTransforming, @Nullable Rect safeRegionBounds) {
                boolean isFixedRotationTransforming, @Nullable Rect safeRegionBounds,
                boolean shouldApplyLegacyInsets) {
            mParentAppBoundsOverride = safeRegionBounds != null ? safeRegionBounds : new Rect(
                    parentConfig.windowConfiguration.getAppBounds());
            mParentBoundsOverride = safeRegionBounds != null ? safeRegionBounds : new Rect(
@@ -2326,8 +2327,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                mTmpOverrideConfigOrientation =
                        mParentAppBoundsOverride.height() >= mParentAppBoundsOverride.width()
                                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
            } else if (mUseOverrideInsetsForConfig && dc != null
                    && !isFloating(parentConfig.windowConfiguration.getWindowingMode())) {
            } else if (shouldApplyLegacyInsets && mUseOverrideInsetsForConfig && dc != null) {
                // Insets are decoupled from configuration by default from V+, use legacy
                // compatibility behaviour for apps targeting SDK earlier than 35
                // (see applySizeOverrideIfNeeded).
+29 −0
Original line number Diff line number Diff line
@@ -751,6 +751,35 @@ public class SizeCompatTests extends WindowTestsBase {
        assertFalse(mActivity.areBoundsLetterboxed());
    }

    @Test
    @EnableFlags({com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_APP_COMPAT_FIXES})
    // Enable to prevent any non-legacy override insets from being added.
    @EnableCompatChanges({ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED})
    public void testLegacyInsetOverride_isAppBubble_notApplied() {
        // Set up app.
        final int notchHeight = 100;
        final DisplayContent display =
                new TestDisplayContent.Builder(mAtm, 1000, 2800)
                        .setNotch(notchHeight)
                        .build();
        setUpApp(display);

        // Simulate inset override for legacy app bound behaviour.
        mActivity.mResolveConfigHint.mUseOverrideInsetsForConfig = true;

        // Set up activity task to be in app bubble.
        mTask.mLaunchNextToBubble = true;
        mTask.setWindowingMode(WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW);
        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);

        Rect bounds = new Rect(mActivity.getWindowConfiguration().getBounds());
        Rect appBounds = new Rect(mActivity.getWindowConfiguration().getAppBounds());
        // App bounds should not include insets and should match bounds.
        assertEquals(new Rect(0, 0, 1000, 2800), appBounds);
        assertEquals(new Rect(0, 0, 1000, 2800), bounds);
    }

    @Test
    public void testAspectRatioMatchParentBoundsAndImeAttachable() {
        setUpApp(new TestDisplayContent.Builder(mAtm, 1000, 2000).build());