Fix issue #5139085: Some Recents items can't be killed
Change-Id: Ib4fa413266c4aa2223576ce0299be743358fdc26
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 57bfaed..d6d3b9d 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -5159,6 +5159,29 @@
cleanUpRemovedTaskLocked(r,
(flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0);
return true;
+ } else {
+ TaskRecord tr = null;
+ int i=0;
+ while (i < mRecentTasks.size()) {
+ TaskRecord t = mRecentTasks.get(i);
+ if (t.taskId == taskId) {
+ tr = t;
+ break;
+ }
+ i++;
+ }
+ if (tr != null) {
+ if (tr.numActivities <= 0) {
+ // Caller is just removing a recent task that is
+ // not actively running. That is easy!
+ mRecentTasks.remove(i);
+ } else {
+ Slog.w(TAG, "removeTask: task " + taskId
+ + " does not have activities to remove, "
+ + " but numActivities=" + tr.numActivities
+ + ": " + tr);
+ }
+ }
}
} finally {
Binder.restoreCallingIdentity(ident);