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

Commit a04902b3 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

[1/n] Sandbox bounds to appBounds in freeform

In freeform, the container bounds are scaled with appBounds. UI can be
cropped if app draws below the insets and bounds extend beyond
appBounds. Sandbox window bounds to appBounds to keep app content within
the container,

Flag: EXEMPT bug fix
Test: atest SizeCompatTests
Fix: 388011462
Change-Id: I80f87f61094b649804ff3d875d9473bf60e7f1cd
parent 931fe7cc
Loading
Loading
Loading
Loading
+16 −0
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.app.admin.DevicePolicyResources.Drawables.Source.PROFILE_SWITCH_ANIMATION;
import static android.app.admin.DevicePolicyResources.Drawables.Style.OUTLINE;
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON;
@@ -8530,6 +8531,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mConfigurationSeq = Math.max(++mConfigurationSeq, 1);
        getResolvedOverrideConfiguration().seq = mConfigurationSeq;

        // TODO(b/392069771): Move to AppCompatSandboxingPolicy.
        // Sandbox max bounds by setting it to the activity bounds, if activity is letterboxed, or
        // has or will have mAppCompatDisplayInsets for size compat. Also forces an activity to be
        // sandboxed or not depending upon the configuration settings.
@@ -8558,6 +8560,20 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            resolvedConfig.windowConfiguration.setMaxBounds(mTmpBounds);
        }

        // Sandbox activity bounds in freeform to app bounds to force app to display within the
        // container. This prevents UI cropping when activities can draw below insets which are
        // normally excluded from appBounds before targetSDK < 35
        // (see ConfigurationContainer#applySizeOverrideIfNeeded).
        if (isFloating(parentWindowingMode)) {
            Rect appBounds = resolvedConfig.windowConfiguration.getAppBounds();
            if (appBounds == null || appBounds.isEmpty()) {
                // When there is no override bounds, the activity will inherit the bounds from
                // parent.
                appBounds = mResolveConfigHint.mParentAppBoundsOverride;
            }
            resolvedConfig.windowConfiguration.setBounds(appBounds);
        }

        applySizeOverrideIfNeeded(
                mDisplayContent,
                info.applicationInfo,
+39 −0
Original line number Diff line number Diff line
@@ -4461,7 +4461,46 @@ public class SizeCompatTests extends WindowTestsBase {
        // are aligned to the top of the parentAppBounds
        assertEquals(new Rect(0, notchHeight, 1000, 1200), appBounds);
        assertEquals(new Rect(0, 0, 1000, 1200), bounds);
    }

    @Test
    @DisableCompatChanges({ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED})
    public void testInFreeform_boundsSandboxedToAppBounds() {
        final int dw = 2800;
        final int dh = 1400;
        final int notchHeight = 100;
        final DisplayContent display = new TestDisplayContent.Builder(mAtm, dw, dh)
                .setNotch(notchHeight)
                .build();
        setUpApp(display);
        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);

        mTask.mDisplayContent.getDefaultTaskDisplayArea()
                .setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM);
        mTask.setWindowingMode(WINDOWING_MODE_FREEFORM);
        Rect appBounds = new Rect(0, 0, 1000, 500);
        Rect bounds = new Rect(0, 0, 1000, 600);
        mTask.getWindowConfiguration().setAppBounds(appBounds);
        mTask.getWindowConfiguration().setBounds(bounds);
        mActivity.onConfigurationChanged(mTask.getConfiguration());

        // Bounds are sandboxed to appBounds in freeform.
        assertDownScaled();
        assertEquals(mActivity.getWindowConfiguration().getAppBounds(),
                mActivity.getWindowConfiguration().getBounds());

        // Exit freeform.
        mTask.mDisplayContent.getDefaultTaskDisplayArea()
                .setWindowingMode(WindowConfiguration.WINDOWING_MODE_FULLSCREEN);
        mTask.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        mTask.getWindowConfiguration().setBounds(new Rect(0, 0, dw, dh));
        mActivity.onConfigurationChanged(mTask.getConfiguration());
        assertFitted();
        appBounds = mActivity.getWindowConfiguration().getAppBounds();
        bounds = mActivity.getWindowConfiguration().getBounds();
        // Bounds are not sandboxed to appBounds.
        assertNotEquals(appBounds, bounds);
        assertEquals(notchHeight, appBounds.top - bounds.top);
    }

    @Test