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

Commit cdfa6ed8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use rotation to report handling for orientation."

parents 959c60e2 edac10a1
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1160,12 +1160,14 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    @Override
    boolean onDescendantOrientationChanged(IBinder freezeDisplayToken,
            ConfigurationContainer requestingContainer) {
        final int previousRotation = mRotation;
        final Configuration config = updateOrientationFromAppTokens(
                getRequestedOverrideConfiguration(), freezeDisplayToken, false);
        // 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();
        // 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 (config == null) {
            return handled;
        }
+0 −9
Original line number Diff line number Diff line
@@ -329,15 +329,6 @@ 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;
    }
+15 −11
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ 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;
@@ -584,15 +585,17 @@ public class DisplayContentTests extends WindowTestsBase {

    @Test
    public void testOnDescendantOrientationRequestChanged() {
        final DisplayContent dc = createNewDisplay();
        final DisplayInfo info = new DisplayInfo();
        info.logicalWidth = 1080;
        info.logicalHeight = 1920;
        info.logicalDensityDpi = 240;
        final DisplayContent dc = createNewDisplay(info);
        dc.configureDisplayPolicy();
        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.setOrientation(newOrientation);
        window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE;

        ActivityRecord activityRecord = mock(ActivityRecord.class);

@@ -603,21 +606,22 @@ 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_PORTRAIT, newDisplayConfig.orientation);
        assertEquals(Configuration.ORIENTATION_LANDSCAPE, newDisplayConfig.orientation);
    }

    @Test
    public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() {
        final DisplayContent dc = createNewDisplay();
        final DisplayInfo info = new DisplayInfo();
        info.logicalWidth = 1080;
        info.logicalHeight = 1920;
        info.logicalDensityDpi = 240;
        final DisplayContent dc = createNewDisplay(info);
        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.setOrientation(newOrientation);
        window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE;

        ActivityRecord activityRecord = mock(ActivityRecord.class);

+0 −18
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.content.ContentResolver;
@@ -612,23 +611,6 @@ public class DisplayRotationTests {
    // ========================
    // Non-rotation API Tests
    // ========================
    @Test
    public void testRespectsAppRequestedOrientationByDefault() throws Exception {
        mBuilder.build();

        assertTrue("Display rotation should respect app requested orientation by"
                + " default.", mTarget.respectAppRequestedOrientation());
    }

    @Test
    public void testNotRespectAppRequestedOrientation_FixedToUserRotation() throws Exception {
        mBuilder.build();
        mTarget.setFixedToUserRotation(true);

        assertFalse("Display rotation shouldn't respect app requested orientation if"
                + " fixed to user rotation.", mTarget.respectAppRequestedOrientation());
    }

    /**
     * Call {@link DisplayRotation#configure(int, int, int, int)} to configure {@link #mTarget}
     * according to given parameters.
+55 −0
Original line number Diff line number Diff line
@@ -25,6 +25,13 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.server.wm.WindowContainer.POSITION_TOP;

import static org.hamcrest.Matchers.not;
@@ -46,6 +53,7 @@ import android.platform.test.annotations.Presubmit;
import android.service.voice.IVoiceInteractionSession;
import android.util.Xml;
import android.view.DisplayInfo;
import android.view.Surface;

import androidx.test.filters.MediumTest;

@@ -276,6 +284,53 @@ public class TaskRecordTests extends ActivityTestsBase {
        assertEquals(freeformBounds, task.getBounds());
    }

    @Test
    public void testUpdatesForcedOrientationInBackground() {
        final DisplayInfo info = new DisplayInfo();
        info.logicalWidth = 1920;
        info.logicalHeight = 1080;
        final ActivityDisplay display = addNewActivityDisplayAt(info, POSITION_TOP);
        doCallRealMethod().when(display.mDisplayContent).setDisplayRotation(any());
        display.mDisplayContent.setDisplayRotation(mock(DisplayRotation.class));
        doCallRealMethod().when(display.mDisplayContent).onDescendantOrientationChanged(any(),
                any());
        doCallRealMethod().when(display.mDisplayContent).setRotation(anyInt());
        doAnswer(invocation -> {
            display.mDisplayContent.setRotation(Surface.ROTATION_0);
            return null;
        }).when(display.mDisplayContent).updateOrientationFromAppTokens(any(), any(), anyBoolean());

        final ActivityStack stack = new StackBuilder(mRootActivityContainer)
                .setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build();
        final TaskRecord task = stack.getChildAt(0);
        final ActivityRecord activity = task.getRootActivity();

        // Wire up app window token and task.
        doCallRealMethod().when(activity.mAppWindowToken).setOrientation(anyInt(), any(), any());
        doCallRealMethod().when(activity.mAppWindowToken).onDescendantOrientationChanged(any(),
                any());
        doReturn(task.mTask).when(activity.mAppWindowToken).getParent();

        // Wire up task and stack.
        task.mTask.mTaskRecord = task;
        doCallRealMethod().when(task.mTask).onDescendantOrientationChanged(any(), any());
        doReturn(stack.getWindowContainerController().mContainer).when(task.mTask).getParent();

        // Wire up stack and display content.
        doCallRealMethod().when(stack.mWindowContainerController.mContainer)
                .onDescendantOrientationChanged(any(), any());
        doReturn(display.mDisplayContent).when(stack.mWindowContainerController.mContainer)
                .getParent();

        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        assertTrue("Bounds of the task should be pillarboxed.",
                task.getBounds().width() < task.getBounds().height());

        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        assertTrue("Bounds of the task should be fullscreen.",
                task.getBounds().equals(new Rect(0, 0, 1920, 1080)));
    }

    /** Ensures that the alias intent won't have target component resolved. */
    @Test
    public void testTaskIntentActivityAlias() {