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

Commit 6d2ef5a0 authored by Chris Li's avatar Chris Li
Browse files

Only update lastFocusedTaskDisplayArea if it handles orientation request

Before, when there are two DAGs, where one respects orientation request,
and one doesn't, the orientation request from the former DAG may be
ignored if the later DAG gets the focus.

Now, when the focus changed, we should only update to the new TDA if it
handles orientation change, otherwise we should still use the
orientation from the previous focused TDA.

Bug: 155431879
Test: manual: test with dual display where only one DAG respect request
Test: atest WmTests:TaskDisplayAreaTests
Test: atest WmTests:DisplayAreaTest
Change-Id: I1d38980347e65b5b729acd3457035e4d4b7cd1c0
parent a86113f6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -174,6 +174,13 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
            return false;
        }

        if (mDisplayContent.mFocusedApp != null) {
            // We record the last focused TDA that respects orientation request, check if this
            // change may affect it.
            mDisplayContent.onLastFocusedTaskDisplayAreaChanged(
                    mDisplayContent.mFocusedApp.getDisplayArea());
        }

        // The orientation request from this DA may now be respected.
        if (!ignoreOrientationRequest) {
            return mDisplayContent.updateOrientation();
+26 −10
Original line number Diff line number Diff line
@@ -488,8 +488,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    ActivityRecord mFocusedApp = null;

    /** The last focused {@link TaskDisplayArea} on this display. */
    private TaskDisplayArea mLastFocusedTaskDisplayArea = null;
    /**
     * We only respect the orientation request from apps below this {@link TaskDisplayArea}.
     * It is the last focused {@link TaskDisplayArea} on this display that handles orientation
     * request.
     */
    @Nullable
    private TaskDisplayArea mOrientationRequestingTaskDisplayArea = null;

    /**
     * The launching activity which is using fixed rotation transformation.
@@ -3325,7 +3330,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

            // Called even if the focused app is not changed in case the app is moved to a different
            // TaskDisplayArea.
            setLastFocusedTaskDisplayArea(newFocus.getDisplayArea());
            onLastFocusedTaskDisplayAreaChanged(newFocus.getDisplayArea());
        }
        if (mFocusedApp == newFocus) {
            return false;
@@ -3339,16 +3344,27 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    /** Called when the focused {@link TaskDisplayArea} on this display may have changed. */
    @VisibleForTesting
    void setLastFocusedTaskDisplayArea(@Nullable TaskDisplayArea taskDisplayArea) {
        if (taskDisplayArea != null) {
            mLastFocusedTaskDisplayArea = taskDisplayArea;
    void onLastFocusedTaskDisplayAreaChanged(@Nullable TaskDisplayArea taskDisplayArea) {
        // Only record the TaskDisplayArea that handles orientation request.
        if (taskDisplayArea != null && taskDisplayArea.handlesOrientationChangeFromDescendant()) {
            mOrientationRequestingTaskDisplayArea = taskDisplayArea;
            return;
        }

        // If the previous TDA no longer handles orientation request, clear it.
        if (mOrientationRequestingTaskDisplayArea != null
                && !mOrientationRequestingTaskDisplayArea
                .handlesOrientationChangeFromDescendant()) {
            mOrientationRequestingTaskDisplayArea = null;
        }
    }

    /** Gets the last focused {@link TaskDisplayArea} on this display. */
    TaskDisplayArea getLastFocusedTaskDisplayArea() {
        return mLastFocusedTaskDisplayArea;
    /**
     * Gets the {@link TaskDisplayArea} that we respect orientation requests from apps below it.
     */
    @Nullable
    TaskDisplayArea getOrientationRequestingTaskDisplayArea() {
        return mOrientationRequestingTaskDisplayArea;
    }

    /** Updates the layer assignment of windows on this display. */
+8 −6
Original line number Diff line number Diff line
@@ -641,9 +641,7 @@ final class TaskDisplayArea extends DisplayArea<Task> {
    @Override
    int getOrientation(int candidate) {
        mLastOrientationSource = null;
        // Only allow to specify orientation if this TDA is not set to ignore orientation request,
        // and it has the focus.
        if (mIgnoreOrientationRequest || !isLastFocused()) {
        if (!canSpecifyOrientation()) {
            return SCREEN_ORIENTATION_UNSET;
        }

@@ -1918,10 +1916,14 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        return lastReparentedStack;
    }

    /** Whether this task display area is the last focused one on this logical display. */
    /** Whether this task display area can request orientation. */
    @VisibleForTesting
    boolean isLastFocused() {
        return mDisplayContent.getLastFocusedTaskDisplayArea() == this;
    boolean canSpecifyOrientation() {
        // Only allow to specify orientation if this TDA is not set to ignore orientation request,
        // and it is the last focused one on this logical display that can request orientation
        // request.
        return !mIgnoreOrientationRequest
                && mDisplayContent.getOrientationRequestingTaskDisplayArea() == this;
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ public class DisplayAreaGroupTest extends WindowTestsBase {
        mTaskDisplayArea = new TaskDisplayArea(
                mDisplayContent, mWm, "TDA1", FEATURE_VENDOR_FIRST + 1);
        mDisplayAreaGroup.addChild(mTaskDisplayArea, POSITION_TOP);
        mDisplayContent.setLastFocusedTaskDisplayArea(mTaskDisplayArea);
        mDisplayContent.onLastFocusedTaskDisplayAreaChanged(mTaskDisplayArea);
    }

    @Test
+22 −2
Original line number Diff line number Diff line
@@ -458,8 +458,7 @@ public class DisplayAreaTest extends WindowTestsBase {

    @Test
    public void testSetIgnoreOrientationRequest_notCallSuperOnDescendantOrientationChanged() {
        final TaskDisplayArea tda =
                mDisplayContent.getDefaultTaskDisplayArea();
        final TaskDisplayArea tda = mDisplayContent.getDefaultTaskDisplayArea();
        final Task stack =
                new TaskBuilder(mSupervisor).setOnTop(!ON_TOP).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getTopNonFinishingActivity();
@@ -478,6 +477,27 @@ public class DisplayAreaTest extends WindowTestsBase {
        verify(mDisplayContent).onDescendantOrientationChanged(any());
    }

    @Test
    public void testSetIgnoreOrientationRequest_updateOrientationRequestingTaskDisplayArea() {
        final TaskDisplayArea tda = mDisplayContent.getDefaultTaskDisplayArea();
        final Task stack =
                new TaskBuilder(mSupervisor).setOnTop(!ON_TOP).setCreateActivity(true).build();
        final ActivityRecord activity = stack.getTopNonFinishingActivity();

        mDisplayContent.setFocusedApp(activity);
        assertThat(mDisplayContent.getOrientationRequestingTaskDisplayArea()).isEqualTo(tda);

        // TDA is no longer handling orientation request, clear the last focused TDA.
        tda.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);

        assertThat(mDisplayContent.getOrientationRequestingTaskDisplayArea()).isNull();

        // TDA now handles orientation request, update last focused TDA based on the focused app.
        tda.setIgnoreOrientationRequest(false /* ignoreOrientationRequest */);

        assertThat(mDisplayContent.getOrientationRequestingTaskDisplayArea()).isEqualTo(tda);
    }

    private static class TestDisplayArea<T extends WindowContainer> extends DisplayArea<T> {
        private TestDisplayArea(WindowManagerService wms, Rect bounds) {
            super(wms, ANY, "half display area");
Loading