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

Commit 2126a326 authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge "Only update lastFocusedTaskDisplayArea if it handles orientation request"

parents 7f452dbf 6d2ef5a0
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
@@ -489,8 +489,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.
@@ -3326,7 +3331,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;
@@ -3340,16 +3345,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