Fix issue #7209355, #7214271.

Issue #7209355: Intent on the secondary user results in an intent picker
in the Primary user.
Issue #7214271: Crash in system UI

Also fix a bug where I recently broke the removeTask() operation in the
activity manager where it would remove the wrong task.

Change-Id: I448c73a0e83a78d9d8d96b4629658c169888d275
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 05ff379..81c67a3 100755
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -4387,6 +4387,8 @@
         while (j < NA) {
             ActivityRecord ar = mHistory.get(j);
             if (!ar.finishing && ar.task.taskId == taskId) {
+                thumbs.root = ar;
+                thumbs.rootIndex = j;
                 holder = ar.thumbHolder;
                 if (holder != null) {
                     thumbs.mainThumbnail = holder.lastThumbnail;
@@ -4401,9 +4403,6 @@
             return thumbs;
         }
 
-        thumbs.root = mHistory.get(j);
-        thumbs.rootIndex = j;
-
         ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>();
         thumbs.subtasks = subtasks;
         while (j < NA) {