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

Commit 3a2fc02c 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
Change-Id: Ic9d1203cc72240f2fdcd5df3f2cab8e5af8e4a4b
parent 3b2bbe61
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.transition.Transitions;

import java.io.PrintWriter;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
@@ -120,6 +121,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
     */
    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 SyncTransactionQueue mSyncTransactionQueue;
    private final PipBoundsState mPipBoundsState;
@@ -327,6 +330,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    @Nullable
    SurfaceControl mSwipePipToHomeOverlay;

    private Runnable mRemoveStaledPinnedTaskRunnable;

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

@@ -728,6 +741,30 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
                    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);

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