Merge "Fix issue with multiple recent tasks showing after restarting the device" into pi-dev am: 20ebb32825
am: 59af233fe8
Change-Id: Ie660665105d34ec7f2c1fef839174bb5945ba0ff
diff --git a/services/core/java/com/android/server/am/RecentTasks.java b/services/core/java/com/android/server/am/RecentTasks.java
index 1335ced..efd8153 100644
--- a/services/core/java/com/android/server/am/RecentTasks.java
+++ b/services/core/java/com/android/server/am/RecentTasks.java
@@ -1243,15 +1243,13 @@
*/
private int findRemoveIndexForAddTask(TaskRecord task) {
final int recentsCount = mTasks.size();
- final int taskActivityType = task.getActivityType();
final Intent intent = task.intent;
final boolean document = intent != null && intent.isDocument();
int maxRecents = task.maxRecents - 1;
for (int i = 0; i < recentsCount; i++) {
final TaskRecord tr = mTasks.get(i);
- final int trActivityType = tr.getActivityType();
if (task != tr) {
- if (taskActivityType != trActivityType || task.userId != tr.userId) {
+ if (!task.hasCompatibleActivityType(tr)) {
continue;
}
final Intent trIntent = tr.intent;
diff --git a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
index 376f5b1..7765387 100644
--- a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
@@ -42,11 +42,13 @@
import android.app.ActivityManager;
import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityManager.RunningTaskInfo;
+import android.app.WindowConfiguration;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
+import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
@@ -101,8 +103,8 @@
private TestRecentTasks mRecentTasks;
private TestRunningTasks mRunningTasks;
- private static ArrayList<TaskRecord> mTasks = new ArrayList<>();
- private static ArrayList<TaskRecord> mSameDocumentTasks = new ArrayList<>();
+ private ArrayList<TaskRecord> mTasks;
+ private ArrayList<TaskRecord> mSameDocumentTasks;
private CallbacksRecorder mCallbacksRecorder;
@@ -155,12 +157,14 @@
mRecentTasks.registerCallback(mCallbacksRecorder);
QUIET_USER_INFO.flags = UserInfo.FLAG_MANAGED_PROFILE | UserInfo.FLAG_QUIET_MODE;
+ mTasks = new ArrayList<>();
mTasks.add(createTaskBuilder(".Task1").build());
mTasks.add(createTaskBuilder(".Task2").build());
mTasks.add(createTaskBuilder(".Task3").build());
mTasks.add(createTaskBuilder(".Task4").build());
mTasks.add(createTaskBuilder(".Task5").build());
+ mSameDocumentTasks = new ArrayList<>();
mSameDocumentTasks.add(createDocumentTask(".DocumentTask1"));
mSameDocumentTasks.add(createDocumentTask(".DocumentTask1"));
}
@@ -294,7 +298,32 @@
assertTrue(mCallbacksRecorder.added.contains(task2));
assertTrue(mCallbacksRecorder.trimmed.isEmpty());
assertTrue(mCallbacksRecorder.removed.isEmpty());
+ }
+ @Test
+ public void testAddTaskCompatibleActivityType_expectRemove() throws Exception {
+ Configuration config1 = new Configuration();
+ config1.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
+ TaskRecord task1 = createTaskBuilder(".Task1")
+ .setFlags(FLAG_ACTIVITY_NEW_TASK)
+ .setStack(mStack)
+ .build();
+ task1.onConfigurationChanged(config1);
+ assertTrue(task1.getActivityType() == ACTIVITY_TYPE_UNDEFINED);
+ mRecentTasks.add(task1);
+ mCallbacksRecorder.clear();
+
+ TaskRecord task2 = createTaskBuilder(".Task1")
+ .setFlags(FLAG_ACTIVITY_NEW_TASK)
+ .setStack(mStack)
+ .build();
+ assertTrue(task2.getActivityType() == ACTIVITY_TYPE_STANDARD);
+ mRecentTasks.add(task2);
+ assertTrue(mCallbacksRecorder.added.size() == 1);
+ assertTrue(mCallbacksRecorder.added.contains(task2));
+ assertTrue(mCallbacksRecorder.trimmed.isEmpty());
+ assertTrue(mCallbacksRecorder.removed.size() == 1);
+ assertTrue(mCallbacksRecorder.removed.contains(task1));
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java b/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
index ea207f1..9e6055d 100644
--- a/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
@@ -29,6 +29,9 @@
import java.io.File;
import java.util.Random;
+/**
+ * atest FrameworksServicesTests:TaskPersisterTest
+ */
public class TaskPersisterTest extends AndroidTestCase {
private static final String TEST_USER_NAME = "AM-Test-User";