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

Commit 4a2d4d51 authored by Winson Chung's avatar Winson Chung
Browse files

Fix issue with task view task listener being disassociated

- This is a regression from ag/33196865 for existing tasks, namely when
  we are relaunching an existing task, we don't go through
  ShellTaskOrganizer.onTaskAppeared(), and don't end up migrating the
  pending cookie listener to a taskId listener, and we subsequently
  don't bind the task to the TaskViewTaskController listener

  For new tasks, the migration will continue to happen in
  onTasksAppeared(), but for existing tasks, we can also attempt to
  migrate when resolving the new task listener when the info changes

Test: atest ShellTaskOrganizerTests
Test: Launch Settings into a bubble/fullscreen repeatedly
Flag: EXEMPT bugfix
Bug: 416136909
Change-Id: I9321b02d3492eff46f12662fee6e610c62f8c2f5
parent 3bd7f0c3
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -599,7 +599,8 @@ public class ShellTaskOrganizer extends TaskOrganizer {

            final TaskAppearedInfo data = mTasks.get(taskInfo.taskId);
            final TaskListener oldListener = getTaskListener(data.getTaskInfo());
            final TaskListener newListener = getTaskListener(taskInfo);
            final TaskListener newListener = getTaskListener(taskInfo,
                    true /* removeLaunchCookieIfNeeded */);
            mTasks.put(taskInfo.taskId, new TaskAppearedInfo(taskInfo, data.getLeash()));
            final boolean updated = updateTaskListenerIfNeeded(
                    taskInfo, data.getLeash(), oldListener, newListener);
@@ -742,6 +743,8 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    private boolean updateTaskListenerIfNeeded(RunningTaskInfo taskInfo, SurfaceControl leash,
            TaskListener oldListener, TaskListener newListener) {
        if (oldListener == newListener) return false;
        ProtoLog.v(WM_SHELL_TASK_ORG, "  Migrating from listener %s to %s",
                oldListener, newListener);
        // TODO: We currently send vanished/appeared as the task moves between types, but
        //       we should consider adding a different mode-changed callback
        if (oldListener != null) {
@@ -883,6 +886,8 @@ public class ShellTaskOrganizer extends TaskOrganizer {
            if (listener == null) continue;

            if (removeLaunchCookieIfNeeded) {
                ProtoLog.v(WM_SHELL_TASK_ORG, "Migrating cookie listener to task: taskId=%d",
                        runningTaskInfo.taskId);
                // Remove the cookie and add the listener.
                mLaunchCookieToListener.remove(cookie);
                mTaskListeners.put(taskId, listener);
@@ -905,6 +910,11 @@ public class ShellTaskOrganizer extends TaskOrganizer {
        return mTaskListeners.get(taskListenerType);
    }

    @VisibleForTesting
    boolean hasTaskListener(int taskId) {
        return mTaskListeners.contains(taskId);
    }

    @VisibleForTesting
    static @TaskListenerType int taskInfoToTaskListenerType(RunningTaskInfo runningTaskInfo) {
        switch (runningTaskInfo.getWindowingMode()) {
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public enum ShellProtoLogGroup implements IProtoLogGroup {
    WM_SHELL_INIT(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
            Consts.TAG_WM_SHELL),
    WM_SHELL_TASK_ORG(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
            Consts.TAG_WM_SHELL),
            "ShellTaskOrganizer"),
    WM_SHELL_TRANSITIONS(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, true,
            Consts.TAG_WM_SHELL),
    WM_SHELL_IME_CONTROLLER(Consts.ENABLE_DEBUG, Consts.ENABLE_LOG_TO_PROTO_DEBUG, false,
+18 −0
Original line number Diff line number Diff line
@@ -322,6 +322,24 @@ public class ShellTaskOrganizerTests extends ShellTestCase {
        assertFalse(mwListener.appeared.contains(task1));
    }

    @Test
    public void testMigrateCookieToTaskOnInfoChanged() {
        RunningTaskInfo task1 = createTaskInfo(/* taskId= */ 1, WINDOWING_MODE_MULTI_WINDOW);
        mOrganizer.onTaskAppeared(task1, /* leash= */ null);

        TrackingTaskListener mwListener = new TrackingTaskListener();
        mOrganizer.addListenerForType(mwListener, TASK_LISTENER_TYPE_MULTI_WINDOW);

        TrackingTaskListener cookieListener = new TrackingTaskListener();
        IBinder cookie = new Binder();
        task1.addLaunchCookie(cookie);
        mOrganizer.setPendingLaunchCookieListener(cookie, cookieListener);

        mOrganizer.onTaskInfoChanged(task1);

        assertTrue(mOrganizer.hasTaskListener(task1.taskId));
    }

    @Test
    public void testGetTaskListener() {
        RunningTaskInfo task1 = createTaskInfo(/* taskId= */ 1, WINDOWING_MODE_MULTI_WINDOW);