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

Commit 55d1ddee authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Gerrit Code Review
Browse files

systemui: never show excluded recent task in recents view



Actually, when there there isn't recent tasks to show, the systemui forces to show
task with the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, but only the first one.
This create an non-consistent behaviour when the user remove all recent task and
then there is a new recent task in the recents view, kill that and a new one
appears, an so on, until no task are available.

This patch changes that behaviour to:
- Never show tasks in recents view with the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- Clear recents button kill all the tasks (included the ones with FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)

Change-Id: I8dc2859ca9dcde7229d5fdb502da313b1ae0dccb
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent 86c508be
Loading
Loading
Loading
Loading
+26 −23
Original line number Diff line number Diff line
@@ -173,40 +173,19 @@ public class SystemServicesProxy {
            return tasks;
        }

        // Remove home/recents/excluded tasks
        // Remove home/recents
        int minNumTasksToQuery = 10;
        int numTasksToQuery = Math.max(minNumTasksToQuery, numLatestTasks);
        List<ActivityManager.RecentTaskInfo> tasks = mAm.getRecentTasksForUser(numTasksToQuery,
                ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS |
                ActivityManager.RECENT_IGNORE_UNAVAILABLE |
                ActivityManager.RECENT_INCLUDE_PROFILES |
                ActivityManager.RECENT_WITH_EXCLUDED, userId);
                ActivityManager.RECENT_INCLUDE_PROFILES, userId);

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

        boolean isFirstValidTask = true;
        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

            // Check the first non-recents task, include this task even if it is marked as excluded
            // from recents if we are currently in the app.  In other words, only remove excluded
            // tasks if it is not the first active task.
            boolean isExcluded = (t.baseIntent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                    == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
            if (isExcluded && (isTopTaskHome || !isFirstValidTask)) {
                iter.remove();
                continue;
            }
            isFirstValidTask = false;
        }

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

@@ -300,6 +279,30 @@ public class SystemServicesProxy {
        mAm.removeTask(taskId, isDocument ? 0 : ActivityManager.REMOVE_TASK_KILL_PROCESS);
    }

    /** Removes all the user task and kills its processes **/
    public void removeAllUserTask(int userId) {
        // Exclude home/recents tasks
        List<ActivityManager.RecentTaskInfo> tasks = mAm.getRecentTasksForUser(
                ActivityManager.getMaxRecentTasksStatic(),
                ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS |
                ActivityManager.RECENT_IGNORE_UNAVAILABLE |
                ActivityManager.RECENT_INCLUDE_PROFILES |
                ActivityManager.RECENT_WITH_EXCLUDED, userId);
        if (tasks == null) {
            return;
        }
        Iterator<ActivityManager.RecentTaskInfo> iter = tasks.iterator();
        while (iter.hasNext()) {
            ActivityManager.RecentTaskInfo t = iter.next();
            if (t.persistentId > 0) {
                // Only if is running
                boolean isDocument = Utilities.isDocument(t.baseIntent);
                mAm.removeTask(t.persistentId,
                        isDocument ? 0 : ActivityManager.REMOVE_TASK_KILL_PROCESS);
            }
        }
    }

    /**
     * Returns the activity info for a given component name.
     * 
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.pm.PackageManager;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -37,6 +38,7 @@ import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import android.widget.PopupMenu;

import com.android.systemui.R;
import com.android.systemui.recents.Constants;
import com.android.systemui.recents.RecentsConfiguration;
@@ -517,6 +519,10 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
                        mStack.removeTask(t);
                    }
                }

                // And remove all the excluded or all the other tasks
                SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
                ssp.removeAllUserTask(UserHandle.myUserId());
            }
        });
    }