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

Commit 49dae10b authored by Garfield Tan's avatar Garfield Tan
Browse files

Only letterbox when display never rotates for app.

This change effectively reverts
edac10a1. And uses a different approach
to fix the other issue.

Bug: 122640019
Bug: 122849394
Bug: 123431170
Test: Manual tests.
atest WmTests:WindowContainerTests
atest WmTests:TaskRecordTests
atest CtsViewTestCases:PixelCopyTest#testWindowProducerCropCenter
GtsMediaTestCases:WidevineDashPolicyTests#testL10SLicense40SPlayback
doesn't fail for released surface.

Change-Id: I33be05248c981cd2bf9274512ef82727f12f8b17
parent bdda90fc
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -31,14 +31,11 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.FLAG_PRIVATE;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.InsetsState.TYPE_IME;
import static android.view.InsetsState.TYPE_NAVIGATION_BAR;
import static android.view.InsetsState.TYPE_TOP_BAR;
import static android.view.Surface.ROTATION_0;
import static android.view.Surface.ROTATION_180;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.View.GONE;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
import static android.view.WindowManager.DOCKED_BOTTOM;
import static android.view.WindowManager.DOCKED_INVALID;
import static android.view.WindowManager.DOCKED_TOP;
@@ -173,7 +170,6 @@ import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;
import android.view.SurfaceSession;
import android.view.View;
import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.view.WindowManagerPolicyConstants.PointerEventListener;

@@ -1160,14 +1156,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    @Override
    boolean onDescendantOrientationChanged(IBinder freezeDisplayToken,
            ConfigurationContainer requestingContainer) {
        final int previousRotation = mRotation;
        final Configuration config = updateOrientationFromAppTokens(
                getRequestedOverrideConfiguration(), freezeDisplayToken, false);
        // This event is considered handled iff a configuration propagation is triggered, because
        // that's the only place lower level containers check if they need to do something to this
        // request. The only guaranteed signal is that the display is rotated to a different
        // orientation (i.e. rotating 180 degrees doesn't count).
        final boolean handled = (mRotation - previousRotation) % 2 != 0;
        // If display rotation class tells us that it doesn't consider app requested orientation,
        // this display won't rotate just because of an app changes its requested orientation. Thus
        // it indicates that this display chooses not to handle this request.
        final boolean handled = getDisplayRotation().respectAppRequestedOrientation();
        if (config == null) {
            return handled;
        }
@@ -1189,6 +1183,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return handled;
    }

    @Override
    boolean handlesOrientationChangeFromDescendant() {
        return getDisplayRotation().respectAppRequestedOrientation();
    }

    /**
     * Determine the new desired orientation of this display.
     *
@@ -1369,8 +1368,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
                + " selected orientation " + lastOrientation
                + ", got rotation " + rotation + " which has "
                + " metrics");
                + ", got rotation " + rotation);

        if (oldRotation == rotation) {
            // No change.
+9 −0
Original line number Diff line number Diff line
@@ -329,6 +329,15 @@ public class DisplayRotation {
        return mFixedToUserRotation;
    }

    /**
     * Returns {@code true} if this display rotation takes app requested orientation into
     * consideration; {@code false} otherwise. For the time being the only case where this is {@code
     * false} is when {@link #isFixedToUserRotation()} is {@code true}.
     */
    boolean respectAppRequestedOrientation() {
        return !mFixedToUserRotation;
    }

    public int getLandscapeRotation() {
        return mLandscapeRotation;
    }
+5 −1
Original line number Diff line number Diff line
@@ -2197,11 +2197,15 @@ class TaskRecord extends ConfigurationContainer {
            // In FULLSCREEN mode, always start with empty bounds to indicate "fill parent"
            outOverrideBounds.setEmpty();

            final boolean parentHandlesOrientationChange = mTask != null
                    && mTask.getParent() != null
                    && mTask.getParent().handlesOrientationChangeFromDescendant();
            // If the task or its top activity requires a different orientation, make it fit the
            // available bounds by scaling down its bounds.
            int forcedOrientation = getTopActivityRequestedOrientation();
            if (forcedOrientation != ORIENTATION_UNDEFINED
                    && forcedOrientation != newParentConfig.orientation) {
                    && forcedOrientation != newParentConfig.orientation
                    && !parentHandlesOrientationChange) {
                final Rect parentBounds = newParentConfig.windowConfiguration.getBounds();
                final int parentWidth = parentBounds.width();
                final int parentHeight = parentBounds.height();
+15 −0
Original line number Diff line number Diff line
@@ -713,6 +713,21 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                requestingContainer);
    }

    /**
     * Check if this container or its parent will handle orientation changes from descendants. It's
     * different from the return value of {@link #onDescendantOrientationChanged(IBinder,
     * ConfigurationContainer)} in the sense that the return value of this method tells if this
     * container or its parent will handle the request eventually, while the return value of the
     * other method is if it handled the request synchronously.
     *
     * @return {@code true} if it handles or will handle orientation change in the future; {@code
     *         false} if it won't handle the change at anytime.
     */
    boolean handlesOrientationChangeFromDescendant() {
        final WindowContainer parent = getParent();
        return parent != null && parent.handlesOrientationChangeFromDescendant();
    }

    /**
     * Calls {@link #setOrientation(int, IBinder, ActivityRecord)} with {@code null} to the last 2
     * parameters.
+11 −15
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.DisplayMetrics;
import android.view.DisplayCutout;
import android.view.DisplayInfo;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.Surface;
@@ -585,17 +584,15 @@ public class DisplayContentTests extends WindowTestsBase {

    @Test
    public void testOnDescendantOrientationRequestChanged() {
        final DisplayInfo info = new DisplayInfo();
        info.logicalWidth = 1080;
        info.logicalHeight = 1920;
        info.logicalDensityDpi = 240;
        final DisplayContent dc = createNewDisplay(info);
        dc.configureDisplayPolicy();
        final DisplayContent dc = createNewDisplay();
        mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class);
        final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE
                ? SCREEN_ORIENTATION_PORTRAIT
                : SCREEN_ORIENTATION_LANDSCAPE;

        final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
        window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS);
        window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE;
        window.mAppToken.setOrientation(newOrientation);

        ActivityRecord activityRecord = mock(ActivityRecord.class);

@@ -606,22 +603,21 @@ public class DisplayContentTests extends WindowTestsBase {
        verify(mWm.mAtmService).updateDisplayOverrideConfigurationLocked(captor.capture(),
                same(activityRecord), anyBoolean(), eq(dc.getDisplayId()));
        final Configuration newDisplayConfig = captor.getValue();
        assertEquals(Configuration.ORIENTATION_LANDSCAPE, newDisplayConfig.orientation);
        assertEquals(Configuration.ORIENTATION_PORTRAIT, newDisplayConfig.orientation);
    }

    @Test
    public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() {
        final DisplayInfo info = new DisplayInfo();
        info.logicalWidth = 1080;
        info.logicalHeight = 1920;
        info.logicalDensityDpi = 240;
        final DisplayContent dc = createNewDisplay(info);
        final DisplayContent dc = createNewDisplay();
        dc.getDisplayRotation().setFixedToUserRotation(true);
        mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class);
        final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE
                ? SCREEN_ORIENTATION_PORTRAIT
                : SCREEN_ORIENTATION_LANDSCAPE;

        final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
        window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS);
        window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE;
        window.mAppToken.setOrientation(newOrientation);

        ActivityRecord activityRecord = mock(ActivityRecord.class);

Loading