diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 7bdb1a090c1a6..319745efa7985 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -165,6 +165,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.Trace; @@ -570,7 +571,9 @@ class Task extends TaskFragment { mRoot = r; // Only end search if we are ignore relinquishing identity or we are not relinquishing. - return ignoreRelinquishIdentity || (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; + return ignoreRelinquishIdentity + || mNeverRelinquishIdentity + || (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; } } @@ -1009,7 +1012,14 @@ class Task extends TaskFragment { private void setIntent(Intent _intent, ActivityInfo info) { if (!isLeafTask()) return; - mNeverRelinquishIdentity = (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; + if (info.applicationInfo.uid == Process.SYSTEM_UID + || info.applicationInfo.isSystemApp()) { + // Only allow the apps that pre-installed on the system image to apply + // relinquishTaskIdentity + mNeverRelinquishIdentity = (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0; + } else { + mNeverRelinquishIdentity = true; + } affinity = info.taskAffinity; if (intent == null) { // If this task already has an intent associated with it, don't set the root diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java index 67e8c879a3e0d..ce568f152a5f2 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java @@ -898,7 +898,8 @@ public class TaskTests extends WindowTestsBase { /** * Test that root activity index is reported correctly when looking for the 'effective root' in - * case when bottom activities are relinquishing task identity or finishing. + * case when bottom activity is finishing. Ignore the relinquishing task identity if it's not a + * system activity even with the FLAG_RELINQUISH_TASK_IDENTITY. */ @Test public void testFindRootIndex_effectiveRoot_finishingAndRelinquishing() { @@ -912,7 +913,7 @@ public class TaskTests extends WindowTestsBase { new ActivityBuilder(mAtm).setTask(task).build(); assertEquals("The first non-finishing activity and non-relinquishing task identity " - + "must be reported.", task.getChildAt(2), task.getRootActivity( + + "must be reported.", task.getChildAt(0), task.getRootActivity( false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); } @@ -932,8 +933,8 @@ public class TaskTests extends WindowTestsBase { } /** - * Test that the topmost activity index is reported correctly when looking for the - * 'effective root' for the case when all activities have relinquishTaskIdentity set. + * Test that the root activity index is reported correctly when looking for the + * 'effective root' for the case when all non-system activities have relinquishTaskIdentity set. */ @Test public void testFindRootIndex_effectiveRoot_relinquishingMultipleActivities() { @@ -944,9 +945,9 @@ public class TaskTests extends WindowTestsBase { final ActivityRecord activity1 = new ActivityBuilder(mAtm).setTask(task).build(); activity1.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; - assertEquals("The topmost activity in the task must be reported.", - task.getChildAt(task.getChildCount() - 1), task.getRootActivity( - false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); + assertEquals("The topmost activity in the task must be reported.", task.getChildAt(0), + task.getRootActivity(false /*ignoreRelinquishIdentity*/, + true /*setToBottomIfNone*/)); } /** Test that bottom-most activity is reported in {@link Task#getRootActivity()}. */ @@ -1084,8 +1085,8 @@ public class TaskTests extends WindowTestsBase { } /** - * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} with activity that - * relinquishes task identity. + * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} with non-system + * activity that relinquishes task identity. */ @Test public void testGetTaskForActivity_onlyRoot_relinquishTaskIdentity() { @@ -1100,7 +1101,7 @@ public class TaskTests extends WindowTestsBase { assertEquals(task.mTaskId, ActivityRecord.getTaskForActivityLocked(activity0.appToken, true /* onlyRoot */)); - assertEquals(task.mTaskId, + assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID, ActivityRecord.getTaskForActivityLocked(activity1.appToken, true /* onlyRoot */)); assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID, ActivityRecord.getTaskForActivityLocked(activity2.appToken, true /* onlyRoot */));