Respect the virtual device recents policy.
Virtual devices can request that all activities launched on
displays owned by that device should not appear in recents.
Currently this is respected only while the display exists.
As soon as it is removed, the activities there show in the
host device recents.
This change automatically removes such activities.
Fix: 291045570
Test: atest android.virtualdevice.cts.RecentTasksTest
Change-Id: I0303b66a57f15bb23069ab441fc84684750e12e1
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 43430dd..f9bbc68 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -725,7 +725,7 @@
} catch (RemoteException e) {
}
}
- if (autoRemoveFromRecents(oldParent.asTaskFragment()) || isVoiceSession) {
+ if (shouldAutoRemoveFromRecents(oldParent.asTaskFragment()) || isVoiceSession) {
// Task creator asked to remove this when done, or this task was a voice
// interaction, so it should not remain on the recent tasks list.
mTaskSupervisor.mRecentTasks.remove(this);
@@ -1558,12 +1558,14 @@
return count > 0;
}
- private boolean autoRemoveFromRecents(TaskFragment oldParentFragment) {
+ private boolean shouldAutoRemoveFromRecents(TaskFragment oldParentFragment) {
// We will automatically remove the task either if it has explicitly asked for
// this, or it is empty and has never contained an activity that got shown to
- // the user, or it was being embedded in another Task.
- return autoRemoveRecents || (!hasChild() && !getHasBeenVisible()
- || (oldParentFragment != null && oldParentFragment.isEmbedded()));
+ // the user, or it was being embedded in another Task, or the display policy
+ // doesn't allow recents,
+ return autoRemoveRecents || (!hasChild() && !getHasBeenVisible())
+ || (oldParentFragment != null && oldParentFragment.isEmbedded())
+ || (mDisplayContent != null && !mDisplayContent.canShowTasksInHostDeviceRecents());
}
private void clearPinnedTaskIfNeed() {