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

Commit 4a6372d1 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Cleanup the content overlay

Cleanup the content overlay forcefully in case it's littering due to
unhandled shell transition. This serves as a last resort to make sure no
visual impact to the user, i.e. not a root fix.

Before: http://recall/-/aaaaaabFQoRHlzixHdtY/bU2hzKgIriCrKrkLdGRO2P
After: http://recall/-/aaaaaabFQoRHlzixHdtY/cN5M30IaQzbuxajy7PBqIH
Bug: 330488822
Test: manully, follow the reproduce path. see also videos
Change-Id: I60c4482fc8783e70f38fe2a7f693d7a14f937541
parent 6b003be2
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.transition.Transitions;

import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
@@ -522,9 +523,27 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            mTaskOrganizer.reparentChildSurfaceToTask(taskId, overlay, t);
            t.setLayer(overlay, Integer.MAX_VALUE);
            t.apply();
            // This serves as a last resort in case the Shell Transition is not handled properly.
            // We want to make sure the overlay passed from Launcher gets removed eventually.
            mayRemoveContentOverlay(overlay);
        }
    }

    private void mayRemoveContentOverlay(SurfaceControl overlay) {
        final WeakReference<SurfaceControl> overlayRef = new WeakReference<>(overlay);
        final long timeoutDuration = (mEnterAnimationDuration
                + CONTENT_OVERLAY_FADE_OUT_DELAY_MS
                + EXTRA_CONTENT_OVERLAY_FADE_OUT_DELAY_MS) * 2L;
        mMainExecutor.executeDelayed(() -> {
            final SurfaceControl overlayLeash = overlayRef.get();
            if (overlayLeash != null && overlayLeash.isValid() && overlayLeash == mPipOverlay) {
                ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "Cleanup the overlay(%s) as a last resort.", overlayLeash);
                removeContentOverlay(overlayLeash, null /* callback */);
            }
        }, timeoutDuration);
    }

    /**
     * Callback when launcher aborts swipe-pip-to-home operation.
     */