OSDN Git Service

Fix: Affiliated tasks not showing when history is enabled.
authorWinson Chung <winsonc@google.com>
Fri, 11 Dec 2015 15:23:59 +0000 (10:23 -0500)
committerWinson Chung <winsonc@google.com>
Mon, 14 Dec 2015 15:15:57 +0000 (15:15 +0000)
- Because these tasks may not have valid
  last-active times (they can be launched in the
  background), the historical state should reflect
  the task that they are affiliated with.

Bug: 26043228
Change-Id: I04db9effc371783a80bea80bd0a45b666269ead1

packages/SystemUI/src/com/android/systemui/recents/model/Task.java
packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java

index 60bedae..512effa 100644 (file)
@@ -93,7 +93,8 @@ public class Task {
 
     public TaskKey key;
     public TaskGrouping group;
-    public int taskAffiliation;
+    // The taskAffiliationId is the task id of the parent task or itself if it is not affiliated with any task
+    public int taskAffiliationId;
     public int taskAffiliationColor;
     public boolean isLaunchTarget;
     public Drawable applicationIcon;
@@ -123,7 +124,7 @@ public class Task {
         boolean isInAffiliationGroup = (taskAffiliation != key.id);
         boolean hasAffiliationGroupColor = isInAffiliationGroup && (taskAffiliationColor != 0);
         this.key = key;
-        this.taskAffiliation = taskAffiliation;
+        this.taskAffiliationId = taskAffiliation;
         this.taskAffiliationColor = taskAffiliationColor;
         this.activityLabel = activityTitle;
         this.contentDescription = contentDescription;
@@ -142,7 +143,7 @@ public class Task {
     /** Copies the other task. */
     public void copyFrom(Task o) {
         this.key = o.key;
-        this.taskAffiliation = o.taskAffiliation;
+        this.taskAffiliationId = o.taskAffiliationId;
         this.taskAffiliationColor = o.taskAffiliationColor;
         this.activityLabel = o.activityLabel;
         this.contentDescription = o.contentDescription;
@@ -206,6 +207,13 @@ public class Task {
         }
     }
 
+    /**
+     * Returns whether this task is affiliated with another task.
+     */
+    public boolean isAffiliatedTask() {
+        return key.id != taskAffiliationId;
+    }
+
     @Override
     public boolean equals(Object o) {
         // Check that the id matches
index 7a98393..13ab392 100644 (file)
@@ -23,6 +23,7 @@ import android.graphics.Color;
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.graphics.drawable.ColorDrawable;
+import android.util.SparseArray;
 import com.android.systemui.R;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.RecentsDebugFlags;
@@ -50,7 +51,7 @@ import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
  */
 interface TaskFilter {
     /** Returns whether the filter accepts the specified task */
-    public boolean acceptTask(Task t, int index);
+    public boolean acceptTask(SparseArray<Task> taskIdMap, Task t, int index);
 }
 
 /**
@@ -157,10 +158,17 @@ class FilteredTaskList {
     private void updateFilteredTasks() {
         mFilteredTasks.clear();
         if (mFilter != null) {
+            // Create a sparse array from task id to Task
+            SparseArray<Task> taskIdMap = new SparseArray<>();
             int taskCount = mTasks.size();
             for (int i = 0; i < taskCount; i++) {
                 Task t = mTasks.get(i);
-                if (mFilter.acceptTask(t, i)) {
+                taskIdMap.put(t.key.id, t);
+            }
+
+            for (int i = 0; i < taskCount; i++) {
+                Task t = mTasks.get(i);
+                if (mFilter.acceptTask(taskIdMap, t, i)) {
                     mFilteredTasks.add(t);
                 }
             }
@@ -318,13 +326,29 @@ public class TaskStack {
         // Ensure that we only show non-docked tasks
         mStackTaskList.setFilter(new TaskFilter() {
             @Override
-            public boolean acceptTask(Task t, int index) {
+            public boolean acceptTask(SparseArray<Task> taskIdMap, Task t, int index) {
+                if (t.isAffiliatedTask()) {
+                    // If this task is affiliated with another parent in the stack, then the historical state of this
+                    // task depends on the state of the parent task
+                    Task parentTask = taskIdMap.get(t.taskAffiliationId);
+                    if (parentTask != null) {
+                        t = parentTask;
+                    }
+                }
                 return !t.isHistorical && !SystemServicesProxy.isDockedStack(t.key.stackId);
             }
         });
         mHistoryTaskList.setFilter(new TaskFilter() {
             @Override
-            public boolean acceptTask(Task t, int index) {
+            public boolean acceptTask(SparseArray<Task> taskIdMap, Task t, int index) {
+                if (t.isAffiliatedTask()) {
+                    // If this task is affiliated with another parent in the stack, then the historical state of this
+                    // task depends on the state of the parent task
+                    Task parentTask = taskIdMap.get(t.taskAffiliationId);
+                    if (parentTask != null) {
+                        t = parentTask;
+                    }
+                }
                 return t.isHistorical && !SystemServicesProxy.isDockedStack(t.key.stackId);
             }
         });
@@ -585,8 +609,8 @@ public class TaskStack {
                             taskGrouping2.latestActiveTimeInGroup);
                 }
             });
-            // Sort group tasks by increasing firstActiveTime of the task, and also build a new list of
-            // tasks
+            // Sort group tasks by increasing firstActiveTime of the task, and also build a new list
+            // of tasks
             int taskIndex = 0;
             int groupCount = mGroups.size();
             for (int i = 0; i < groupCount; i++) {
@@ -607,13 +631,13 @@ public class TaskStack {
             mStackTaskList.set(tasks);
         } else {
             // Create the task groups
-            HashMap<Task.TaskKey, Task> tasksMap = new HashMap<Task.TaskKey, Task>();
+            HashMap<Task.TaskKey, Task> tasksMap = new HashMap<>();
             ArrayList<Task> tasks = mStackTaskList.getTasks();
             int taskCount = tasks.size();
             for (int i = 0; i < taskCount; i++) {
                 Task t = tasks.get(i);
                 TaskGrouping group;
-                int affiliation = t.taskAffiliation > 0 ? t.taskAffiliation :
+                int affiliation = t.taskAffiliationId > 0 ? t.taskAffiliationId :
                         IndividualTaskIdOffset + t.key.id;
                 if (mAffinitiesGroups.containsKey(affiliation)) {
                     group = getGroupWithAffiliation(affiliation);