RecentsTaskLoadPlanpublic class RecentsTaskLoadPlan extends Object This class stores the loading state as it goes through multiple stages of loading:
- preloadRawTasks() will load the raw set of recents tasks from the system
- preloadPlan() will construct a new task stack with all metadata and only icons and thumbnails
that are currently in the cache
- executePlan() will actually load and fill in the icons and thumbnails according to the load
options specified, such that we can transition into the Recents activity seamlessly |
Fields Summary |
---|
static String | TAG | static boolean | DEBUG | android.content.Context | mContext | com.android.systemui.recents.RecentsConfiguration | mConfig | com.android.systemui.recents.misc.SystemServicesProxy | mSystemServicesProxy | List | mRawTasks | TaskStack | mStack | HashMap | mActivityInfoCache |
Methods Summary |
---|
synchronized void | executePlan(com.android.systemui.recents.model.RecentsTaskLoadPlan$Options opts, RecentsTaskLoader loader, TaskResourceLoadQueue loadQueue)Called to apply the actual loading based on the specified conditions.
if (DEBUG) Log.d(TAG, "executePlan, # tasks: " + opts.numVisibleTasks +
", # thumbnails: " + opts.numVisibleTaskThumbnails +
", running task id: " + opts.runningTaskId);
Resources res = mContext.getResources();
// Iterate through each of the tasks and load them according to the load conditions.
ArrayList<Task> tasks = mStack.getTasks();
int taskCount = tasks.size();
for (int i = 0; i < taskCount; i++) {
ActivityManager.RecentTaskInfo t = mRawTasks.get(i);
Task task = tasks.get(i);
Task.TaskKey taskKey = task.key;
// Get an existing activity info handle if possible
Task.ComponentNameKey cnKey = taskKey.getComponentNameKey();
ActivityInfoHandle infoHandle;
boolean hadCachedActivityInfo = false;
if (mActivityInfoCache.containsKey(cnKey)) {
infoHandle = mActivityInfoCache.get(cnKey);
hadCachedActivityInfo = true;
} else {
infoHandle = new ActivityInfoHandle();
}
boolean isRunningTask = (task.key.id == opts.runningTaskId);
boolean isVisibleTask = i >= (taskCount - opts.numVisibleTasks);
boolean isVisibleThumbnail = i >= (taskCount - opts.numVisibleTaskThumbnails);
// If requested, skip the running task
if (opts.onlyLoadPausedActivities && isRunningTask) {
continue;
}
if (opts.loadIcons && (isRunningTask || isVisibleTask)) {
if (task.activityIcon == null) {
if (DEBUG) Log.d(TAG, "\tLoading icon: " + taskKey);
task.activityIcon = loader.getAndUpdateActivityIcon(taskKey, t.taskDescription,
mSystemServicesProxy, res, infoHandle, true);
}
}
if (opts.loadThumbnails && (isRunningTask || isVisibleThumbnail)) {
if (task.thumbnail == null || isRunningTask) {
if (DEBUG) Log.d(TAG, "\tLoading thumbnail: " + taskKey);
if (mConfig.svelteLevel <= RecentsConfiguration.SVELTE_LIMIT_CACHE) {
task.thumbnail = loader.getAndUpdateThumbnail(taskKey, mSystemServicesProxy,
true);
} else if (mConfig.svelteLevel == RecentsConfiguration.SVELTE_DISABLE_CACHE) {
loadQueue.addTask(task);
}
}
}
// Update the activity info cache
if (!hadCachedActivityInfo && infoHandle.info != null) {
mActivityInfoCache.put(cnKey, infoHandle);
}
}
| public SpaceNode | getSpaceNode()Composes and returns a SpaceNode from the preloaded list of recent tasks.
SpaceNode node = new SpaceNode();
node.setStack(mStack);
return node;
| public TaskStack | getTaskStack()Composes and returns a TaskStack from the preloaded list of recent tasks.
return mStack;
| synchronized void | preloadPlan(RecentsTaskLoader loader, boolean isTopTaskHome)Preloads the list of recent tasks from the system. After this call, the TaskStack will
have a list of all the recent tasks with their metadata, not including icons or
thumbnails which were not cached and have to be loaded.
if (DEBUG) Log.d(TAG, "preloadPlan");
mActivityInfoCache.clear();
mStack = new TaskStack();
Resources res = mContext.getResources();
ArrayList<Task> loadedTasks = new ArrayList<Task>();
if (mRawTasks == null) {
preloadRawTasks(isTopTaskHome);
}
int taskCount = mRawTasks.size();
for (int i = 0; i < taskCount; i++) {
ActivityManager.RecentTaskInfo t = mRawTasks.get(i);
// Compose the task key
Task.TaskKey taskKey = new Task.TaskKey(t.persistentId, t.baseIntent, t.userId,
t.firstActiveTime, t.lastActiveTime);
// Get an existing activity info handle if possible
Task.ComponentNameKey cnKey = taskKey.getComponentNameKey();
ActivityInfoHandle infoHandle;
boolean hadCachedActivityInfo = false;
if (mActivityInfoCache.containsKey(cnKey)) {
infoHandle = mActivityInfoCache.get(cnKey);
hadCachedActivityInfo = true;
} else {
infoHandle = new ActivityInfoHandle();
}
// Load the label, icon, and color
String activityLabel = loader.getAndUpdateActivityLabel(taskKey, t.taskDescription,
mSystemServicesProxy, infoHandle);
Drawable activityIcon = loader.getAndUpdateActivityIcon(taskKey, t.taskDescription,
mSystemServicesProxy, res, infoHandle, false);
int activityColor = loader.getActivityPrimaryColor(t.taskDescription, mConfig);
// Update the activity info cache
if (!hadCachedActivityInfo && infoHandle.info != null) {
mActivityInfoCache.put(cnKey, infoHandle);
}
Bitmap icon = t.taskDescription != null
? t.taskDescription.getInMemoryIcon()
: null;
String iconFilename = t.taskDescription != null
? t.taskDescription.getIconFilename()
: null;
// Add the task to the stack
Task task = new Task(taskKey, (t.id != RecentsTaskLoader.INVALID_TASK_ID),
t.affiliatedTaskId, t.affiliatedTaskColor, activityLabel, activityIcon,
activityColor, (i == (taskCount - 1)), mConfig.lockToAppEnabled, icon,
iconFilename);
task.thumbnail = loader.getAndUpdateThumbnail(taskKey, mSystemServicesProxy, false);
if (DEBUG) Log.d(TAG, "\tthumbnail: " + taskKey + ", " + task.thumbnail);
loadedTasks.add(task);
}
mStack.setTasks(loadedTasks);
mStack.createAffiliatedGroupings(mConfig);
// Assertion
if (mStack.getTaskCount() != mRawTasks.size()) {
throw new RuntimeException("Loading failed");
}
| public synchronized void | preloadRawTasks(boolean isTopTaskHome)An optimization to preload the raw list of tasks.
mRawTasks = mSystemServicesProxy.getRecentTasks(mConfig.maxNumTasksToLoad,
UserHandle.CURRENT.getIdentifier(), isTopTaskHome);
Collections.reverse(mRawTasks);
if (DEBUG) Log.d(TAG, "preloadRawTasks, tasks: " + mRawTasks.size());
|
|