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

Commit 5fa39753 authored by Winson Chung's avatar Winson Chung
Browse files

4/Clean up use of hidden recent task flags

- Remove flags to control which recent tasks are returned -- they are now
  trimmed with the expected behaviour when the task list is modified.
- Remove unused logic related to force-resetting a task based on inactive
  time.
- Remove SysUI logic related to excluded recent tasks since it is already
  handled
- Clean up task list subsetting now that returned list is guaranteed to
  only be visible tasks
- Only use AM interface to fetch recent tasks instead of through AM

Bug: 34270611
Test: runtest --path frameworks/base/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
Change-Id: I3f60ce507563152b5704c63985af621b02d0e7c8
parent fb44d212
Loading
Loading
Loading
Loading
+1 −52
Original line number Diff line number Diff line
@@ -1501,31 +1501,6 @@ public class ActivityManager {
     */
    public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;

    /**
     * Provides a list that contains recent tasks for all
     * profiles of a user.
     * @hide
     */
    public static final int RECENT_INCLUDE_PROFILES = 0x0004;

    /**
     * Ignores all tasks that are on the home stack.
     * @hide
     */
    public static final int RECENT_IGNORE_HOME_AND_RECENTS_STACK_TASKS = 0x0008;

    /**
     * Ignores the top task in the docked stack.
     * @hide
     */
    public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;

    /**
     * Ignores all tasks that are on the pinned stack.
     * @hide
     */
    public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;

    /**
     * <p></p>Return a list of the tasks that the user has recently launched, with
     * the most recent being first and older ones after in order.
@@ -1561,33 +1536,7 @@ public class ActivityManager {
    public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
            throws SecurityException {
        try {
            return getService().getRecentTasks(maxNum,
                    flags, UserHandle.myUserId()).getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
     * specific user. It requires holding
     * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
     * @param maxNum The maximum number of entries to return in the list.  The
     * actual number returned may be smaller, depending on how many tasks the
     * user has started and the maximum number the system can remember.
     * @param flags Information about what to return.  May be any combination
     * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
     *
     * @return Returns a list of RecentTaskInfo records describing each of
     * the recent tasks. Most recently activated tasks go first.
     *
     * @hide
     */
    public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
            throws SecurityException {
        try {
            return getService().getRecentTasks(maxNum,
                    flags, userId).getList();
            return getService().getRecentTasks(maxNum, flags, UserHandle.myUserId()).getList();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+2 −2
Original line number Diff line number Diff line
@@ -178,8 +178,8 @@ interface IActivityManager {
     * SIGUSR1 is delivered. All others are ignored.
     */
    void signalPersistentProcesses(int signal);
    ParceledListSlice getRecentTasks(int maxNum,
            int flags, int userId);

    ParceledListSlice getRecentTasks(int maxNum, int flags, int userId);
    oneway void serviceDoneExecuting(in IBinder token, int type, int startId, int res);
    oneway void activityDestroyed(in IBinder token);
    IIntentSender getIntentSender(int type, in String packageName, in IBinder token,
+2 −4
Original line number Diff line number Diff line
@@ -431,8 +431,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        RecentsConfiguration config = Recents.getConfiguration();
        RecentsActivityLaunchState launchState = config.getLaunchState();
        if (!loadPlan.hasTasks()) {
            loader.preloadTasks(loadPlan, launchState.launchedToTaskId,
                    !launchState.launchedFromHome && !launchState.launchedViaDockGesture);
            loader.preloadTasks(loadPlan, launchState.launchedToTaskId);
        }

        RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
@@ -853,8 +852,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        RecentsActivityLaunchState launchState = config.getLaunchState();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
        loader.preloadTasks(loadPlan, -1 /* runningTaskId */,
                false /* includeFrontMostExcludedTask */);
        loader.preloadTasks(loadPlan, -1 /* runningTaskId */);

        RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
        loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
+7 −8
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
                ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getRunningTask();
                RecentsTaskLoader loader = Recents.getTaskLoader();
                RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
                loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */);
                loader.preloadTasks(plan, -1);
                TaskStack stack = plan.getTaskStack();
                RecentsActivityLaunchState launchState = new RecentsActivityLaunchState();
                RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();
@@ -283,7 +283,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        // We can use a new plan since the caches will be the same.
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
        loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */);
        loader.preloadTasks(plan, -1);
        RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();
        launchOpts.numVisibleTasks = loader.getIconCacheSize();
        launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize();
@@ -473,8 +473,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        // RecentsActivity) only if there is a task to animate to.  Post this to ensure that we
        // don't block the touch feedback on the nav bar button which triggers this.
        mHandler.post(() -> {
            MutableBoolean isHomeStackVisible = new MutableBoolean(true);
            if (!ssp.isRecentsActivityVisible(isHomeStackVisible)) {
            if (!ssp.isRecentsActivityVisible(null)) {
                ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
                if (runningTask == null) {
                    return;
@@ -482,7 +481,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

                RecentsTaskLoader loader = Recents.getTaskLoader();
                sInstanceLoadPlan = loader.createLoadPlan(mContext);
                loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible.value);
                loader.preloadTasks(sInstanceLoadPlan, runningTask.id);
                TaskStack stack = sInstanceLoadPlan.getTaskStack();
                if (stack.getTaskCount() > 0) {
                    // Only preload the icon (but not the thumbnail since it may not have been taken
@@ -522,7 +521,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        SystemServicesProxy ssp = Recents.getSystemServices();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
        loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */);
        loader.preloadTasks(plan, -1);
        TaskStack focusedStack = plan.getTaskStack();

        // Return early if there are no tasks in the focused stack
@@ -577,7 +576,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        SystemServicesProxy ssp = Recents.getSystemServices();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
        loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */);
        loader.preloadTasks(plan, -1);
        TaskStack focusedStack = plan.getTaskStack();

        // Return early if there are no tasks in the focused stack
@@ -1012,7 +1011,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
            sInstanceLoadPlan = loader.createLoadPlan(mContext);
        }
        if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) {
            loader.preloadTasks(sInstanceLoadPlan, runningTaskId, !isHomeStackVisible);
            loader.preloadTasks(sInstanceLoadPlan, runningTaskId);
        }

        TaskStack stack = sInstanceLoadPlan.getTaskStack();
+16 −52
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.recents.misc;

import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
@@ -384,20 +385,15 @@ public class SystemServicesProxy {

    /**
     * Returns a list of the recents tasks.
     *
     * @param includeFrontMostExcludedTask if set, will ensure that the front most excluded task
     *                                     will be visible, otherwise no excluded tasks will be
     *                                     visible.
     */
    public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numLatestTasks, int userId,
            boolean includeFrontMostExcludedTask) {
    public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numTasks, int userId) {
        if (mAm == null) return null;

        // If we are mocking, then create some recent tasks
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            ArrayList<ActivityManager.RecentTaskInfo> tasks =
                    new ArrayList<ActivityManager.RecentTaskInfo>();
            int count = Math.min(numLatestTasks, RecentsDebugFlags.Static.MockTaskCount);
            int count = Math.min(numTasks, RecentsDebugFlags.Static.MockTaskCount);
            for (int i = 0; i < count; i++) {
                // Create a dummy component name
                int packageIndex = i % RecentsDebugFlags.Static.MockTasksPackageCount;
@@ -426,56 +422,24 @@ public class SystemServicesProxy {
            return tasks;
        }

        // Remove home/recents/excluded tasks
        int minNumTasksToQuery = 10;
        int numTasksToQuery = Math.max(minNumTasksToQuery, numLatestTasks);
        int flags = ActivityManager.RECENT_IGNORE_HOME_AND_RECENTS_STACK_TASKS |
                ActivityManager.RECENT_INGORE_DOCKED_STACK_TOP_TASK |
                ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS |
                ActivityManager.RECENT_IGNORE_UNAVAILABLE |
                ActivityManager.RECENT_INCLUDE_PROFILES;
        if (includeFrontMostExcludedTask) {
            flags |= ActivityManager.RECENT_WITH_EXCLUDED;
        }
        List<ActivityManager.RecentTaskInfo> tasks = null;
        try {
            tasks = mAm.getRecentTasksForUser(numTasksToQuery, flags, userId);
        } catch (Exception e) {
            Log.e(TAG, "Failed to get recent tasks", e);
        }

        // Break early if we can't get a valid set of tasks
        if (tasks == null) {
            return new ArrayList<>();
        }

        boolean isFirstValidTask = true;
            List<ActivityManager.RecentTaskInfo> tasks = mIam.getRecentTasks(numTasks,
                    RECENT_IGNORE_UNAVAILABLE, userId).getList();
            Iterator<ActivityManager.RecentTaskInfo> iter = tasks.iterator();
            while (iter.hasNext()) {
                ActivityManager.RecentTaskInfo t = iter.next();

            // NOTE: The order of these checks happens in the expected order of the traversal of the
            // tasks

                // Remove the task if it or it's package are blacklsited
                if (sRecentsBlacklist.contains(t.realActivity.getClassName()) ||
                        sRecentsBlacklist.contains(t.realActivity.getPackageName())) {
                    iter.remove();
                continue;
                }

            // Remove the task if it is marked as excluded, unless it is the first most task and we
            // are requested to include it
            boolean isExcluded = (t.baseIntent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                    == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
            if (isExcluded && (!isFirstValidTask || !includeFrontMostExcludedTask)) {
                iter.remove();
            }

            isFirstValidTask = false;
            return tasks;
        } catch (Exception e) {
            Log.e(TAG, "Failed to get recent tasks", e);
            return new ArrayList<>();
        }

        return tasks.subList(0, Math.min(tasks.size(), numLatestTasks));
    }

    /**
Loading