Merge "Only allow system to apply relinquishTaskIdentity" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-09-10 10:55:13 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 12 deletions

View File

@@ -165,6 +165,7 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Trace; import android.os.Trace;
@@ -570,7 +571,9 @@ class Task extends TaskFragment {
mRoot = r; mRoot = r;
// Only end search if we are ignore relinquishing identity or we are not relinquishing. // 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) { private void setIntent(Intent _intent, ActivityInfo info) {
if (!isLeafTask()) return; if (!isLeafTask()) return;
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; mNeverRelinquishIdentity = (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
} else {
mNeverRelinquishIdentity = true;
}
affinity = info.taskAffinity; affinity = info.taskAffinity;
if (intent == null) { if (intent == null) {
// If this task already has an intent associated with it, don't set the root // If this task already has an intent associated with it, don't set the root

View File

@@ -898,7 +898,8 @@ public class TaskTests extends WindowTestsBase {
/** /**
* Test that root activity index is reported correctly when looking for the 'effective root' in * 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 @Test
public void testFindRootIndex_effectiveRoot_finishingAndRelinquishing() { public void testFindRootIndex_effectiveRoot_finishingAndRelinquishing() {
@@ -912,7 +913,7 @@ public class TaskTests extends WindowTestsBase {
new ActivityBuilder(mAtm).setTask(task).build(); new ActivityBuilder(mAtm).setTask(task).build();
assertEquals("The first non-finishing activity and non-relinquishing task identity " 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*/)); 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 * Test that the root activity index is reported correctly when looking for the
* 'effective root' for the case when all activities have relinquishTaskIdentity set. * 'effective root' for the case when all non-system activities have relinquishTaskIdentity set.
*/ */
@Test @Test
public void testFindRootIndex_effectiveRoot_relinquishingMultipleActivities() { public void testFindRootIndex_effectiveRoot_relinquishingMultipleActivities() {
@@ -944,9 +945,9 @@ public class TaskTests extends WindowTestsBase {
final ActivityRecord activity1 = new ActivityBuilder(mAtm).setTask(task).build(); final ActivityRecord activity1 = new ActivityBuilder(mAtm).setTask(task).build();
activity1.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY; activity1.info.flags |= FLAG_RELINQUISH_TASK_IDENTITY;
assertEquals("The topmost activity in the task must be reported.", assertEquals("The topmost activity in the task must be reported.", task.getChildAt(0),
task.getChildAt(task.getChildCount() - 1), task.getRootActivity( task.getRootActivity(false /*ignoreRelinquishIdentity*/,
false /*ignoreRelinquishIdentity*/, true /*setToBottomIfNone*/)); true /*setToBottomIfNone*/));
} }
/** Test that bottom-most activity is reported in {@link Task#getRootActivity()}. */ /** 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 * Test {@link ActivityRecord#getTaskForActivityLocked(IBinder, boolean)} with non-system
* relinquishes task identity. * activity that relinquishes task identity.
*/ */
@Test @Test
public void testGetTaskForActivity_onlyRoot_relinquishTaskIdentity() { public void testGetTaskForActivity_onlyRoot_relinquishTaskIdentity() {
@@ -1100,7 +1101,7 @@ public class TaskTests extends WindowTestsBase {
assertEquals(task.mTaskId, assertEquals(task.mTaskId,
ActivityRecord.getTaskForActivityLocked(activity0.appToken, true /* onlyRoot */)); 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 */)); ActivityRecord.getTaskForActivityLocked(activity1.appToken, true /* onlyRoot */));
assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID, assertEquals("No task must be reported for activity that is above root", INVALID_TASK_ID,
ActivityRecord.getTaskForActivityLocked(activity2.appToken, true /* onlyRoot */)); ActivityRecord.getTaskForActivityLocked(activity2.appToken, true /* onlyRoot */));