Hide suspended apps from recents
* Introduce a new boolean realActivitySuspended in TaskRecord to
keep track of the suspended state (this also makes sure the
information is persisted across reboots).
* Introduce a new method onPackagesSuspendedChanged
in RecentTasks which flips the realActivitySuspended for each
TaskRecord for the desired user and packages sent
* Register a new broadcast receiver (for SUSPEND/UNSUSPEND)
in ActivityManager#finishBooting which calls
RecentTasks#markPackagesSuspendedStateForUser
* In ActivityManagerService#getRecentTasks filter out
Taskrecords for suspended apps by checking realActivitySuspended
Bug: 22776761
Change-Id: I52e3593ccb2dae223d1ea11d017a6b1626646639
diff --git a/services/core/java/com/android/server/am/RecentTasks.java b/services/core/java/com/android/server/am/RecentTasks.java
index 3f0674d..9c139d5 100644
--- a/services/core/java/com/android/server/am/RecentTasks.java
+++ b/services/core/java/com/android/server/am/RecentTasks.java
@@ -24,6 +24,8 @@
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
+import com.google.android.collect.Sets;
+
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.content.ComponentName;
@@ -45,6 +47,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Set;
/**
* Class for managing the recent tasks list.
@@ -188,6 +191,21 @@
}
}
+ void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) {
+ final Set<String> packageNames = Sets.newHashSet(packages);
+ for (int i = size() - 1; i >= 0; --i) {
+ final TaskRecord tr = get(i);
+ if (tr.realActivity != null
+ && packageNames.contains(tr.realActivity.getPackageName())
+ && tr.userId == userId
+ && tr.realActivitySuspended != suspended) {
+ tr.realActivitySuspended = suspended;
+ notifyTaskPersisterLocked(tr, false);
+ }
+ }
+
+ }
+
/**
* Update the recent tasks lists: make sure tasks should still be here (their
* applications / activities still exist), update their availability, fix-up ordering
@@ -683,5 +701,4 @@
// Let the caller know where we left off.
return start + tmpSize;
}
-
}