Fix issue #2555171: Switching to app immediately after unmounting...
...SD card causes reboot.
Add option to not include temporarily unavailable recent tasks,
for the recent tasks UI to not display them.
Change-Id: I1495ca217b4292fd56f537459b44c0624262c292
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index b3223e5..c9096cf 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -145,6 +145,13 @@
public static final int RECENT_WITH_EXCLUDED = 0x0001;
/**
+ * @hide
+ * TODO: Make this public. Provides a list that does not contain any
+ * recent tasks that currently are not available to the user.
+ */
+ public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
+
+ /**
* Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.
*
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index bc26fa0..b6f323d 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -6867,6 +6867,8 @@
enforceCallingPermission(android.Manifest.permission.GET_TASKS,
"getRecentTasks()");
+ IPackageManager pm = ActivityThread.getPackageManager();
+
final int N = mRecentTasks.size();
ArrayList<ActivityManager.RecentTaskInfo> res
= new ArrayList<ActivityManager.RecentTaskInfo>(
@@ -6883,6 +6885,25 @@
rti.baseIntent = new Intent(
tr.intent != null ? tr.intent : tr.affinityIntent);
rti.origActivity = tr.origActivity;
+
+ if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
+ // Check whether this activity is currently available.
+ try {
+ if (rti.origActivity != null) {
+ if (pm.getActivityInfo(rti.origActivity, 0) == null) {
+ continue;
+ }
+ } else if (rti.baseIntent != null) {
+ if (pm.queryIntentActivities(rti.baseIntent,
+ null, 0) == null) {
+ continue;
+ }
+ }
+ } catch (RemoteException e) {
+ // Will never happen.
+ }
+ }
+
res.add(rti);
maxNum--;
}