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

Commit c38e7078 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

[RESTRICT AUTOMERGE] Remove staled pinned Task upon SystemUI reboot

Added a timeout callback in PipTaskOrganizer#onTaskAppeared, remove the
staled pinned task if there is no transition state change follows.

Flag: EXEMPT bugfix
Bug: 376048041
Test: Run the PoC app and make sure no background Activity launch
Test: atest PinnedStackTests
Merged-In: Ic9d1203cc72240f2fdcd5df3f2cab8e5af8e4a4b
Change-Id: Ic9d1203cc72240f2fdcd5df3f2cab8e5af8e4a4b
parent 205413a8
Loading
Loading
Loading
Loading
+37 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,7 @@ import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.transition.Transitions;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.Optional;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Consumer;
@@ -116,6 +117,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
     */
     */
    private static final int CONTENT_OVERLAY_FADE_OUT_DELAY_MS = 500;
    private static final int CONTENT_OVERLAY_FADE_OUT_DELAY_MS = 500;


    private static final int CRASH_RECOVERY_CHECK_DELAY_MS = 3000;

    private final Context mContext;
    private final Context mContext;
    private final SyncTransactionQueue mSyncTransactionQueue;
    private final SyncTransactionQueue mSyncTransactionQueue;
    private final PipBoundsState mPipBoundsState;
    private final PipBoundsState mPipBoundsState;
@@ -323,6 +326,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    @Nullable
    @Nullable
    SurfaceControl mSwipePipToHomeOverlay;
    SurfaceControl mSwipePipToHomeOverlay;


    private Runnable mRemoveStaledPinnedTaskRunnable;

    public PipTaskOrganizer(Context context,
    public PipTaskOrganizer(Context context,
            @NonNull SyncTransactionQueue syncTransactionQueue,
            @NonNull SyncTransactionQueue syncTransactionQueue,
            @NonNull PipTransitionState pipTransitionState,
            @NonNull PipTransitionState pipTransitionState,
@@ -371,6 +376,14 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        mPipTransitionController.setPipOrganizer(this);
        mPipTransitionController.setPipOrganizer(this);
        displayController.addDisplayWindowListener(this);
        displayController.addDisplayWindowListener(this);
        pipTransitionController.registerPipTransitionCallback(mPipTransitionCallback);
        pipTransitionController.registerPipTransitionCallback(mPipTransitionCallback);
        mPipTransitionState.addOnPipTransitionStateChangedListener(
                (oldState, newState) -> {
                    if (mPipTransitionState.isEnteringPip()
                            && mRemoveStaledPinnedTaskRunnable != null) {
                        mMainExecutor.removeCallbacks(mRemoveStaledPinnedTaskRunnable);
                        mRemoveStaledPinnedTaskRunnable = null;
                    }
                });
    }
    }


    public PipTransitionController getTransitionController() {
    public PipTransitionController getTransitionController() {
@@ -721,6 +734,30 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
                    mPictureInPictureParams.getSubtitle());
                    mPictureInPictureParams.getSubtitle());
        }
        }


        mRemoveStaledPinnedTaskRunnable = () -> {
            ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "SystemUI reboot detected, remove staled PiP task");
            // Remove the staled Task by matching component name.
            final ComponentName toRemove = info.topActivity;
            try {
                List<ActivityManager.RunningTaskInfo> tasks = ActivityTaskManager.getService()
                        .getTasks(10 /* maxNum */,
                                false /* filterOnlyVisibleRecents */,
                                false /* keepIntentExtra */,
                                Display.DEFAULT_DISPLAY);
                for (ActivityManager.RunningTaskInfo task : tasks) {
                    if (toRemove.equals(task.topActivity)) {
                        ActivityTaskManager.getService().removeTask(task.taskId);
                    }
                }
            } catch (RemoteException e) {
                ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "%s: Failed to remove PiP, %s", TAG, e);
            }
        };
        mMainExecutor.executeDelayed(mRemoveStaledPinnedTaskRunnable,
                CRASH_RECOVERY_CHECK_DELAY_MS);

        mPipUiEventLoggerLogger.setTaskInfo(mTaskInfo);
        mPipUiEventLoggerLogger.setTaskInfo(mTaskInfo);


        // If the displayId of the task is different than what PipBoundsHandler has, then update
        // If the displayId of the task is different than what PipBoundsHandler has, then update