Fix issue #5139085: Some Recents items can't be killed
Change-Id: Ib4fa413266c4aa2223576ce0299be743358fdc26
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index 43905dd..10e7602 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -96,11 +96,13 @@
/* package */ final class ActivityDescription {
final ActivityManager.RecentTaskInfo recentTaskInfo;
final ResolveInfo resolveInfo;
- int taskId; // application task id for curating apps
- Intent intent; // launch intent for application
+ final int taskId; // application task id for curating apps
+ final int persistentTaskId; // persistent id
+ final Intent intent; // launch intent for application
+ final String packageName; // used to override animations (see onClick())
+ final int position; // position in list
+
Matrix matrix; // arbitrary rotation matrix to correct orientation
- String packageName; // used to override animations (see onClick())
- int position; // position in list
private Bitmap mThumbnail; // generated by Activity.onCreateThumbnail()
private Drawable mIcon; // application package icon
@@ -108,11 +110,12 @@
public ActivityDescription(ActivityManager.RecentTaskInfo _recentInfo,
ResolveInfo _resolveInfo, Intent _intent,
- int _id, int _pos, String _packageName) {
+ int _pos, String _packageName) {
recentTaskInfo = _recentInfo;
resolveInfo = _resolveInfo;
intent = _intent;
- taskId = _id;
+ taskId = _recentInfo.id;
+ persistentTaskId = _recentInfo.persistentId;
position = _pos;
packageName = _packageName;
}
@@ -496,17 +499,17 @@
final String title = info.loadLabel(pm).toString();
// Drawable icon = info.loadIcon(pm);
Drawable icon = getFullResIcon(resolveInfo, pm);
- int id = recentInfo.id;
if (title != null && title.length() > 0 && icon != null) {
- if (DEBUG) Log.v(TAG, "creating activity desc for id=" + id + ", label=" + title);
+ if (DEBUG) Log.v(TAG, "creating activity desc for id="
+ + recentInfo.id + ", label=" + title);
ActivityManager.TaskThumbnails thumbs = am.getTaskThumbnails(
recentInfo.persistentId);
ActivityDescription item = new ActivityDescription(recentInfo,
- resolveInfo, intent, id, index, info.packageName);
+ resolveInfo, intent, index, info.packageName);
activityDescriptions.add(item);
++index;
} else {
- if (DEBUG) Log.v(TAG, "SKIPPING item " + id);
+ if (DEBUG) Log.v(TAG, "SKIPPING item " + recentInfo.id);
}
}
}
@@ -727,7 +730,7 @@
// the task.
final ActivityManager am = (ActivityManager)
mContext.getSystemService(Context.ACTIVITY_SERVICE);
- am.removeTask(ad.taskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
+ am.removeTask(ad.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
}
private void startApplicationDetailsActivity(String packageName) {
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);