Fix swiping away recents to always kill processes.

This would only kill processes if there were activities associated
with the recent task; now it always kills processes.

Always fix some debug output.

Change-Id: Iccda19ba0a20823347b06c13b450587283d28284
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 6f89f6e..0c5a827 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -5443,15 +5443,16 @@
                     "removeSubTask()");
             long ident = Binder.clearCallingIdentity();
             try {
-                return mMainStack.removeTaskActivitiesLocked(taskId, subTaskIndex) != null;
+                return mMainStack.removeTaskActivitiesLocked(taskId, subTaskIndex,
+                        true) != null;
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
         }
     }
 
-    private void cleanUpRemovedTaskLocked(ActivityRecord root, boolean killProcesses) {
-        TaskRecord tr = root.task;
+    private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
+        final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
         Intent baseIntent = new Intent(
                 tr.intent != null ? tr.intent : tr.affinityIntent);
         ComponentName component = baseIntent.getComponent();
@@ -5462,7 +5463,7 @@
 
         // Find any running services associated with this app.
         ArrayList<ServiceRecord> services = new ArrayList<ServiceRecord>();
-        for (ServiceRecord sr : mServiceMap.getAllServices(root.userId)) {
+        for (ServiceRecord sr : mServiceMap.getAllServices(tr.userId)) {
             if (sr.packageName.equals(component.getPackageName())) {
                 services.add(sr);
             }
@@ -5517,11 +5518,11 @@
                     "removeTask()");
             long ident = Binder.clearCallingIdentity();
             try {
-                ActivityRecord r = mMainStack.removeTaskActivitiesLocked(taskId, -1);
+                ActivityRecord r = mMainStack.removeTaskActivitiesLocked(taskId, -1,
+                        false);
                 if (r != null) {
                     mRecentTasks.remove(r.task);
-                    cleanUpRemovedTaskLocked(r,
-                            (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0);
+                    cleanUpRemovedTaskLocked(r.task, flags);
                     return true;
                 } else {
                     TaskRecord tr = null;
@@ -5539,6 +5540,8 @@
                             // Caller is just removing a recent task that is
                             // not actively running.  That is easy!
                             mRecentTasks.remove(i);
+                            cleanUpRemovedTaskLocked(tr, flags);
+                            return true;
                         } else {
                             Slog.w(TAG, "removeTask: task " + taskId
                                     + " does not have activities to remove, "
@@ -9360,7 +9363,7 @@
 
     boolean dumpProvidersLocked(FileDescriptor fd, PrintWriter pw, String[] args,
             int opti, boolean dumpAll, String dumpPackage) {
-        boolean needSep = false;
+        boolean needSep = true;
 
         ItemMatcher matcher = new ItemMatcher();
         matcher.build(args, opti);
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index edebbac..a375d30 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -4011,10 +4011,13 @@
         return info;
     }
 
-    public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex) {
+    public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex,
+            boolean taskRequired) {
         TaskAccessInfo info = getTaskAccessInfoLocked(taskId, false);
         if (info.root == null) {
-            Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId);
+            if (taskRequired) {
+                Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId);
+            }
             return null;
         }
 
@@ -4025,7 +4028,9 @@
         }
 
         if (subTaskIndex >= info.subtasks.size()) {
-            Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex);
+            if (taskRequired) {
+                Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex);
+            }
             return null;
         }
 
diff --git a/services/java/com/android/server/am/ContentProviderRecord.java b/services/java/com/android/server/am/ContentProviderRecord.java
index f338cfc..608b09a 100644
--- a/services/java/com/android/server/am/ContentProviderRecord.java
+++ b/services/java/com/android/server/am/ContentProviderRecord.java
@@ -157,7 +157,7 @@
         sb.append("ContentProviderRecord{");
         sb.append(Integer.toHexString(System.identityHashCode(this)));
         sb.append(' ');
-        sb.append(info.name);
+        sb.append(name.flattenToShortString());
         sb.append('}');
         return stringName = sb.toString();
     }
diff --git a/services/java/com/android/server/am/ProviderMap.java b/services/java/com/android/server/am/ProviderMap.java
index 2021e0d..ccc928f 100644
--- a/services/java/com/android/server/am/ProviderMap.java
+++ b/services/java/com/android/server/am/ProviderMap.java
@@ -183,16 +183,20 @@
                 r.dump(pw, "    ");
             } else {
                 pw.print("  * ");
-                pw.print(r.name.toShortString());
-                /*
-                if (r.app != null) {
-                    pw.println(":");
-                    pw.print("      ");
-                    pw.println(r.app);
-                } else {
-                    pw.println();
+                pw.println(r);
+                if (r.proc != null) {
+                    pw.print("    proc=");
+                    pw.println(r.proc);
                 }
-                */
+                if (r.launchingApp != null) {
+                    pw.print("    launchingApp=");
+                    pw.println(r.launchingApp);
+                }
+                if (r.clients.size() > 0 || r.externalProcessNoHandleCount > 0) {
+                    pw.print("    "); pw.print(r.clients.size());
+                            pw.print(" clients, "); pw.print(r.externalProcessNoHandleCount);
+                            pw.println(" external handles");
+                }
             }
         }
     }
@@ -217,7 +221,7 @@
                 pw.println(" ");
             pw.println("  Published content providers (by class):");
             dumpProvidersByClassLocked(pw, dumpAll, mGlobalByClass);
-            pw.println(" ");
+            pw.println("");
         }
 
         if (mProvidersByClassPerUser.size() > 1) {
diff --git a/services/java/com/android/server/am/TaskRecord.java b/services/java/com/android/server/am/TaskRecord.java
index 67873cc..e3ebcc61 100644
--- a/services/java/com/android/server/am/TaskRecord.java
+++ b/services/java/com/android/server/am/TaskRecord.java
@@ -39,7 +39,7 @@
     boolean askedCompatMode;// Have asked the user about compat mode for this task.
 
     String stringName;      // caching of toString() result.
-    int userId; // user for which this task was created
+    int userId;             // user for which this task was created
     
     TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
         taskId = _taskId;