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

Commit 451d65cd authored by Louis Chang's avatar Louis Chang
Browse files

Do not update TFParentInfo while invisible

WM Core sends the TFParentInfo updates to the client whenever
a Task is visible. That not just updates the visible tasks, but
also updates the TFParentInfo of the invisible ones. Though,
the TFContainer of the invisible Tasks are not updated.

The next time the Tasks become visible. The only change of the
TFParentInfo is the visibility, while the configuration stays
unchanged (due to it was already updated while the Task was
invisible). Therefore, the TFContainers are not updated using
the latest TFParentInfo.

Bug: 338153080
Test: atest SplitControllerTest
Change-Id: Ibb719519e2ab075cc44fb7273409947f1a8aac52
parent cdf3a135
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -850,6 +850,14 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
            Log.e(TAG, "onTaskFragmentParentInfoChanged on empty Task id=" + taskId);
            return;
        }

        if (!parentInfo.isVisible()) {
            // Only making the TaskContainer invisible and drops the other info, and perform the
            // update when the next time the Task becomes visible.
            taskContainer.setIsVisible(false);
            return;
        }

        // Checks if container should be updated before apply new parentInfo.
        final boolean shouldUpdateContainer = taskContainer.shouldUpdateContainer(parentInfo);
        taskContainer.updateTaskFragmentParentInfo(parentInfo);
+13 −7
Original line number Diff line number Diff line
@@ -151,6 +151,10 @@ class TaskContainer {
        return mIsVisible;
    }

    void setIsVisible(boolean visible) {
        mIsVisible = visible;
    }

    boolean hasDirectActivity() {
        return mHasDirectActivity;
    }
@@ -185,13 +189,15 @@ class TaskContainer {
    boolean shouldUpdateContainer(@NonNull TaskFragmentParentInfo info) {
        final Configuration configuration = info.getConfiguration();

        return info.isVisible()
        if (isInPictureInPicture(configuration)) {
            // No need to update presentation in PIP until the Task exit PIP.
                && !isInPictureInPicture(configuration)
                // If the task properties equals regardless of starting position, don't need to
                // update the container.
                && (mConfiguration.diffPublicOnly(configuration) != 0
                || mDisplayId != info.getDisplayId());
            return false;
        }

        // If the task properties equals regardless of starting position, don't
        // need to update the container.
        return mConfiguration.diffPublicOnly(configuration) != 0
                || mDisplayId != info.getDisplayId();
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -580,7 +580,7 @@ public class OverlayPresentationTest {
        final TaskContainer.TaskProperties taskProperties = taskContainer.getTaskProperties();
        final TaskFragmentParentInfo parentInfo = new TaskFragmentParentInfo(
                new Configuration(taskProperties.getConfiguration()), taskProperties.getDisplayId(),
                false /* visible */, false /* hasDirectActivity */, null /* decorSurface */);
                true /* visible */, false /* hasDirectActivity */, null /* decorSurface */);

        mSplitController.onTaskFragmentParentInfoChanged(mTransaction, TASK_ID, parentInfo);

+42 −0
Original line number Diff line number Diff line
@@ -1621,6 +1621,48 @@ public class SplitControllerTest {
        verify(mEmbeddedActivityWindowInfoCallback, never()).accept(any());
    }

    @Test
    public void testTaskFragmentParentInfoChanged() {
        // Making a split
        final Activity secondaryActivity = createMockActivity();
        addSplitTaskFragments(mActivity, secondaryActivity, false /* clearTop */);

        // Updates the parent info.
        final TaskContainer taskContainer = mSplitController.getTaskContainer(TASK_ID);
        final Configuration configuration = new Configuration();
        final TaskFragmentParentInfo originalInfo = new TaskFragmentParentInfo(configuration,
                DEFAULT_DISPLAY, true /* visible */, false /* hasDirectActivity */,
                null /* decorSurface */);
        mSplitController.onTaskFragmentParentInfoChanged(mock(WindowContainerTransaction.class),
                TASK_ID, originalInfo);
        assertTrue(taskContainer.isVisible());

        // Making a public configuration change while the Task is invisible.
        configuration.densityDpi += 100;
        final TaskFragmentParentInfo invisibleInfo = new TaskFragmentParentInfo(configuration,
                DEFAULT_DISPLAY, false /* visible */, false /* hasDirectActivity */,
                null /* decorSurface */);
        mSplitController.onTaskFragmentParentInfoChanged(mock(WindowContainerTransaction.class),
                TASK_ID, invisibleInfo);

        // Ensure the TaskContainer is inivisible, but the configuration is not updated.
        assertFalse(taskContainer.isVisible());
        assertTrue(taskContainer.getTaskFragmentParentInfo().getConfiguration().diffPublicOnly(
                configuration) > 0);

        // Updates when Task to become visible
        final TaskFragmentParentInfo visibleInfo = new TaskFragmentParentInfo(configuration,
                DEFAULT_DISPLAY, true /* visible */, false /* hasDirectActivity */,
                null /* decorSurface */);
        mSplitController.onTaskFragmentParentInfoChanged(mock(WindowContainerTransaction.class),
                TASK_ID, visibleInfo);

        // Ensure the Task is visible and configuration is updated.
        assertTrue(taskContainer.isVisible());
        assertFalse(taskContainer.getTaskFragmentParentInfo().getConfiguration().diffPublicOnly(
                configuration) > 0);
    }

    /** Creates a mock activity in the organizer process. */
    private Activity createMockActivity() {
        return createMockActivity(TASK_ID);