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

Commit e643910a authored by Winson Chung's avatar Winson Chung
Browse files

Expose method to clear all visible recent tasks

- Atomically remove all the visible tasks so that SysUI doesn't need to
  remove each task individually.

Bug: 80471073
Test: atest FrameworksServicesTests:RecentTasksTest#testRemoveAllVisibleTasks
Change-Id: I23a6e152e94d5462948ab40adc9d7baf593847e1
parent a81d7074
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -203,6 +203,19 @@ public class ActivityTaskManager {
        }
    }

    /**
     * Removes all visible recent tasks from the system.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.REMOVE_TASKS)
    public void removeAllVisibleRecentTasks() {
        try {
            getService().removeAllVisibleRecentTasks();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Return the maximum number of recents entries that we will maintain and show.
     * @hide
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ interface IActivityTaskManager {
    ComponentName getCallingActivity(in IBinder token);
    void setFocusedTask(int taskId);
    boolean removeTask(int taskId);
    void removeAllVisibleRecentTasks();
    List<ActivityManager.RunningTaskInfo> getTasks(int maxNum);
    List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, int ignoreActivityType,
            int ignoreWindowingMode);
+16 −0
Original line number Diff line number Diff line
@@ -393,6 +393,22 @@ public class ActivityManagerWrapper {
        });
    }

    /**
     * Removes all the recent tasks.
     */
    public void removeAllRecentTasks() {
        mBackgroundExecutor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    ActivityTaskManager.getService().removeAllVisibleRecentTasks();
                } catch (RemoteException e) {
                    Log.w(TAG, "Failed to remove all tasks", e);
                }
            }
        });
    }

    /**
     * Cancels the current window transtion to/from Recents for the given task id.
     */
+3 −3
Original line number Diff line number Diff line
@@ -3230,12 +3230,12 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    }

    @Override
    public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) {
    public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed, boolean killProcess) {
        if (wasTrimmed) {
            // Task was trimmed from the recent tasks list -- remove the active task record as well
            // since the user won't really be able to go back to it
            removeTaskByIdLocked(task.taskId, false /* killProcess */,
                    false /* removeFromRecents */, !PAUSE_IMMEDIATELY, "recent-task-trimmed");
            removeTaskByIdLocked(task.taskId, killProcess, false /* removeFromRecents */,
                    !PAUSE_IMMEDIATELY, "recent-task-trimmed");
        }
        task.removedFromRecents();
    }
+13 −0
Original line number Diff line number Diff line
@@ -1667,6 +1667,19 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    @Override
    public void removeAllVisibleRecentTasks() {
        enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()");
        synchronized (mGlobalLock) {
            final long ident = Binder.clearCallingIdentity();
            try {
                getRecentTasks().removeAllVisibleTasks();
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

    @Override
    public boolean shouldUpRecreateTask(IBinder token, String destAffinity) {
        synchronized (mGlobalLock) {
Loading