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

Commit d6aede92 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Do not update TFParentInfo while invisible" into main

parents d4d476e1 451d65cd
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
@@ -1619,6 +1619,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);