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

Commit 7c3ba804 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

[Divider] Fix two bugs in interactive divider

1. Removed the isResumed() check for getting the background color. It
   cause the background color to be incorrect when secondary container
   is fully expanded and the user drags back to the split state (cannot
   get the background color of the primary container because it is
   paused at the beginning). We should rely on the signal from wm core
   to determine the trusted/untrusted state of the container instead
   (b/340239159)

2. Only the veil visibility changes should be applied in sync with the
   WCT. Other changes such as position changes should be applied
   in the app process to avoid race conditions with other local surface
   updates such as dragging.

Bug: 327067596
Test: Manual
Change-Id: Ie4406f25d133e3c6f563e5809f36744ecee142de
parent 057d218e
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -256,8 +256,10 @@ class DividerPresenter implements View.OnTouchListener {
    static Color getContainerBackgroundColor(
            @NonNull TaskFragmentContainer container, @NonNull Color defaultColor) {
        final Activity activity = container.getTopNonFinishingActivity();
        if (activity == null || !activity.isResumed()) {
            // This can happen when the top activity in the container is from a different process.
        if (activity == null) {
            // This can happen when the activities in the container are from a different process.
            // TODO(b/340984203) Report whether the top activity is in the same process. Use default
            // color if not.
            return defaultColor;
        }

@@ -515,8 +517,11 @@ class DividerPresenter implements View.OnTouchListener {
    private void onStartDragging() {
        mRenderer.mIsDragging = true;
        mRenderer.mDragHandle.setPressed(mRenderer.mIsDragging);
        mRenderer.updateSurface();

        // Veil visibility change should be applied together with the surface boost transaction in
        // the wct.
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mRenderer.updateSurface(t);
        mRenderer.showVeils(t);

        // Callbacks must be executed on the executor to release mLock and prevent deadlocks.
@@ -532,18 +537,18 @@ class DividerPresenter implements View.OnTouchListener {

    @GuardedBy("mLock")
    private void onDrag() {
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mRenderer.updateSurface(t);
        t.apply();
        mRenderer.updateSurface();
    }

    @GuardedBy("mLock")
    private void onFinishDragging() {
        mDividerPosition = adjustDividerPositionForSnapPoints(mDividerPosition);
        mRenderer.setDividerPosition(mDividerPosition);
        mRenderer.updateSurface();

        // Veil visibility change should be applied together with the surface boost transaction in
        // the wct.
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mRenderer.updateSurface(t);
        mRenderer.hideVeils(t);

        // Callbacks must be executed on the executor to release mLock and prevent deadlocks.
@@ -994,6 +999,22 @@ class DividerPresenter implements View.OnTouchListener {
         * Updates the positions and crops of the divider surface and veil surfaces. This method
         * should be called when {@link #mProperties} is changed or while dragging to update the
         * position of the divider surface and the veil surfaces.
         *
         * This method applies the changes in a stand-alone surface transaction immediately.
         */
        private void updateSurface() {
            final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
            updateSurface(t);
            t.apply();
        }

        /**
         * Updates the positions and crops of the divider surface and veil surfaces. This method
         * should be called when {@link #mProperties} is changed or while dragging to update the
         * position of the divider surface and the veil surfaces.
         *
         * This method applies the changes in the provided surface transaction and can be synced
         * with other changes.
         */
        private void updateSurface(@NonNull SurfaceControl.Transaction t) {
            final Rect taskBounds = mProperties.mConfiguration.windowConfiguration.getBounds();
+1 −8
Original line number Diff line number Diff line
@@ -631,15 +631,8 @@ public class DividerPresenterTest {
        assertEquals(defaultColor,
                DividerPresenter.getContainerBackgroundColor(container, defaultColor));

        // When the top non-finishing activity is not resumed, the default color should be returned.
        // When the top non-finishing activity is non-null, its background color should be returned.
        when(container.getTopNonFinishingActivity()).thenReturn(activity);
        when(activity.isResumed()).thenReturn(false);
        assertEquals(defaultColor,
                DividerPresenter.getContainerBackgroundColor(container, defaultColor));

        // When the top non-finishing activity is resumed, its background color should be returned.
        when(container.getTopNonFinishingActivity()).thenReturn(activity);
        when(activity.isResumed()).thenReturn(true);
        assertEquals(activityBackgroundColor,
                DividerPresenter.getContainerBackgroundColor(container, defaultColor));
    }