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

Commit e98b86e5 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android (Google) Code Review
Browse files

Merge "Add RecentTasks class to house recent tasks functionality."

parents 93e6d6ed c82f2f5f
Loading
Loading
Loading
Loading
+19 −545

File changed.

Preview size limit exceeded, changes collapsed.

+7 −4
Original line number Original line Diff line number Diff line
@@ -146,6 +146,7 @@ final class ActivityStack {


    final ActivityManagerService mService;
    final ActivityManagerService mService;
    final WindowManagerService mWindowManager;
    final WindowManagerService mWindowManager;
    private final RecentTasks mRecentTasks;


    /**
    /**
     * The back history of all previous (and possibly still
     * The back history of all previous (and possibly still
@@ -337,7 +338,8 @@ final class ActivityStack {
        return count;
        return count;
    }
    }


    ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer) {
    ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer,
            RecentTasks recentTasks) {
        mActivityContainer = activityContainer;
        mActivityContainer = activityContainer;
        mStackSupervisor = activityContainer.getOuter();
        mStackSupervisor = activityContainer.getOuter();
        mService = mStackSupervisor.mService;
        mService = mStackSupervisor.mService;
@@ -345,6 +347,7 @@ final class ActivityStack {
        mWindowManager = mService.mWindowManager;
        mWindowManager = mService.mWindowManager;
        mStackId = activityContainer.mStackId;
        mStackId = activityContainer.mStackId;
        mCurrentUser = mService.mCurrentUserId;
        mCurrentUser = mService.mCurrentUserId;
        mRecentTasks = recentTasks;
    }
    }


    /**
    /**
@@ -643,7 +646,7 @@ final class ActivityStack {
        r.stopped = false;
        r.stopped = false;
        mResumedActivity = r;
        mResumedActivity = r;
        r.task.touchActiveTime();
        r.task.touchActiveTime();
        mService.addRecentTaskLocked(r.task);
        mRecentTasks.addLocked(r.task);
        completeResumeLocked(r);
        completeResumeLocked(r);
        mStackSupervisor.checkReadyForSleepLocked();
        mStackSupervisor.checkReadyForSleepLocked();
        setLaunchTime(r);
        setLaunchTime(r);
@@ -1760,7 +1763,7 @@ final class ActivityStack {
            next.state = ActivityState.RESUMED;
            next.state = ActivityState.RESUMED;
            mResumedActivity = next;
            mResumedActivity = next;
            next.task.touchActiveTime();
            next.task.touchActiveTime();
            mService.addRecentTaskLocked(next.task);
            mRecentTasks.addLocked(next.task);
            mService.updateLruProcessLocked(next.app, true, null);
            mService.updateLruProcessLocked(next.app, true, null);
            updateLRUListLocked(next);
            updateLRUListLocked(next);
            mService.updateOomAdjLocked();
            mService.updateOomAdjLocked();
@@ -4075,7 +4078,7 @@ final class ActivityStack {
            if (task.autoRemoveFromRecents() || isVoiceSession) {
            if (task.autoRemoveFromRecents() || isVoiceSession) {
                // Task creator asked to remove this when done, or this task was a voice
                // Task creator asked to remove this when done, or this task was a voice
                // interaction, so it should not remain on the recent tasks list.
                // interaction, so it should not remain on the recent tasks list.
                mService.mRecentTasks.remove(task);
                mRecentTasks.remove(task);
                task.removedFromRecents();
                task.removedFromRecents();
            }
            }
        }
        }
+7 −4
Original line number Original line Diff line number Diff line
@@ -166,6 +166,8 @@ public final class ActivityStackSupervisor implements DisplayListener {


    final ActivityManagerService mService;
    final ActivityManagerService mService;


    private final RecentTasks mRecentTasks;

    final ActivityStackSupervisorHandler mHandler;
    final ActivityStackSupervisorHandler mHandler;


    /** Short cut */
    /** Short cut */
@@ -298,8 +300,9 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
        }
    }
    }


    public ActivityStackSupervisor(ActivityManagerService service) {
    public ActivityStackSupervisor(ActivityManagerService service, RecentTasks recentTasks) {
        mService = service;
        mService = service;
        mRecentTasks = recentTasks;
        mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper());
        mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper());
    }
    }


@@ -464,7 +467,7 @@ public final class ActivityStackSupervisor implements DisplayListener {


        // Don't give up! Look in recents.
        // Don't give up! Look in recents.
        if (DEBUG_RECENTS) Slog.v(TAG, "Looking for task id=" + id + " in recents");
        if (DEBUG_RECENTS) Slog.v(TAG, "Looking for task id=" + id + " in recents");
        TaskRecord task = mService.recentTaskForIdLocked(id);
        TaskRecord task = mRecentTasks.taskForIdLocked(id);
        if (task == null) {
        if (task == null) {
            if (DEBUG_RECENTS) Slog.d(TAG, "\tDidn't find task id=" + id + " in recents");
            if (DEBUG_RECENTS) Slog.d(TAG, "\tDidn't find task id=" + id + " in recents");
            return null;
            return null;
@@ -2912,7 +2915,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        r.mLaunchTaskBehind = false;
        r.mLaunchTaskBehind = false;
        final TaskRecord task = r.task;
        final TaskRecord task = r.task;
        task.setLastThumbnail(task.stack.screenshotActivities(r));
        task.setLastThumbnail(task.stack.screenshotActivities(r));
        mService.addRecentTaskLocked(task);
        mRecentTasks.addLocked(task);
        mService.notifyTaskStackChangedLocked();
        mService.notifyTaskStackChangedLocked();
        mWindowManager.setAppVisibility(r.appToken, false);
        mWindowManager.setAppVisibility(r.appToken, false);
    }
    }
@@ -3675,7 +3678,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        ActivityContainer(int stackId) {
        ActivityContainer(int stackId) {
            synchronized (mService) {
            synchronized (mService) {
                mStackId = stackId;
                mStackId = stackId;
                mStack = new ActivityStack(this);
                mStack = new ActivityStack(this, mRecentTasks);
                mIdString = "ActivtyContainer{" + mStackId + "}";
                mIdString = "ActivtyContainer{" + mStackId + "}";
                if (DEBUG_STACK) Slog.d(TAG, "Creating " + this);
                if (DEBUG_STACK) Slog.d(TAG, "Creating " + this);
            }
            }
+577 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −10
Original line number Original line Diff line number Diff line
@@ -99,6 +99,7 @@ public class TaskPersister {


    private final ActivityManagerService mService;
    private final ActivityManagerService mService;
    private final ActivityStackSupervisor mStackSupervisor;
    private final ActivityStackSupervisor mStackSupervisor;
    private final RecentTasks mRecentTasks;


    /** Value determines write delay mode as follows:
    /** Value determines write delay mode as follows:
     *    < 0 We are Flushing. No delays between writes until the image queue is drained and all
     *    < 0 We are Flushing. No delays between writes until the image queue is drained and all
@@ -138,7 +139,8 @@ public class TaskPersister {
    // tasks.
    // tasks.
    private long mExpiredTasksCleanupTime = Long.MAX_VALUE;
    private long mExpiredTasksCleanupTime = Long.MAX_VALUE;


    TaskPersister(File systemDir, ActivityStackSupervisor stackSupervisor) {
    TaskPersister(File systemDir, ActivityStackSupervisor stackSupervisor,
            RecentTasks recentTasks) {
        sTasksDir = new File(systemDir, TASKS_DIRNAME);
        sTasksDir = new File(systemDir, TASKS_DIRNAME);
        if (!sTasksDir.exists()) {
        if (!sTasksDir.exists()) {
            if (DEBUG_PERSISTER) Slog.d(TAG, "Creating tasks directory " + sTasksDir);
            if (DEBUG_PERSISTER) Slog.d(TAG, "Creating tasks directory " + sTasksDir);
@@ -159,13 +161,15 @@ public class TaskPersister {


        mStackSupervisor = stackSupervisor;
        mStackSupervisor = stackSupervisor;
        mService = stackSupervisor.mService;
        mService = stackSupervisor.mService;

        mRecentTasks = recentTasks;
        mLazyTaskWriterThread = new LazyTaskWriterThread("LazyTaskWriterThread");
        mLazyTaskWriterThread = new LazyTaskWriterThread("LazyTaskWriterThread");
    }
    }


    void startPersisting() {
    void startPersisting() {
        if (!mLazyTaskWriterThread.isAlive()) {
            mLazyTaskWriterThread.start();
            mLazyTaskWriterThread.start();
        }
        }
    }


    private void removeThumbnails(TaskRecord task) {
    private void removeThumbnails(TaskRecord task) {
        final String taskString = Integer.toString(task.taskId);
        final String taskString = Integer.toString(task.taskId);
@@ -704,10 +708,9 @@ public class TaskPersister {
                    // {@link TaskRecord.mLastTimeMoved} and drop the oldest recent's vs. just
                    // {@link TaskRecord.mLastTimeMoved} and drop the oldest recent's vs. just
                    // adding to the back of the list.
                    // adding to the back of the list.
                    int spaceLeft =
                    int spaceLeft =
                            ActivityManager.getMaxRecentTasksStatic()
                            ActivityManager.getMaxRecentTasksStatic() - mRecentTasks.size();
                            - mService.mRecentTasks.size();
                    if (spaceLeft >= tasks.size()) {
                    if (spaceLeft >= tasks.size()) {
                        mService.mRecentTasks.addAll(mService.mRecentTasks.size(), tasks);
                        mRecentTasks.addAll(mRecentTasks.size(), tasks);
                        for (int k = tasks.size() - 1; k >= 0; k--) {
                        for (int k = tasks.size() - 1; k >= 0; k--) {
                            // Persist new tasks.
                            // Persist new tasks.
                            wakeup(tasks.get(k), false);
                            wakeup(tasks.get(k), false);
@@ -860,10 +863,9 @@ public class TaskPersister {
                    if (DEBUG_PERSISTER) Slog.d(TAG, "Looking for obsolete files.");
                    if (DEBUG_PERSISTER) Slog.d(TAG, "Looking for obsolete files.");
                    persistentTaskIds.clear();
                    persistentTaskIds.clear();
                    synchronized (mService) {
                    synchronized (mService) {
                        final ArrayList<TaskRecord> tasks = mService.mRecentTasks;
                        if (DEBUG_PERSISTER) Slog.d(TAG, "mRecents=" + mRecentTasks);
                        if (DEBUG_PERSISTER) Slog.d(TAG, "mRecents=" + tasks);
                        for (int taskNdx = mRecentTasks.size() - 1; taskNdx >= 0; --taskNdx) {
                        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
                            final TaskRecord task = mRecentTasks.get(taskNdx);
                            final TaskRecord task = tasks.get(taskNdx);
                            if (DEBUG_PERSISTER) Slog.d(TAG, "LazyTaskWriter: task=" + task +
                            if (DEBUG_PERSISTER) Slog.d(TAG, "LazyTaskWriter: task=" + task +
                                    " persistable=" + task.isPersistable);
                                    " persistable=" + task.isPersistable);
                            if ((task.isPersistable || task.inRecents)
                            if ((task.isPersistable || task.inRecents)