Merge "Update taskAffinity with application uid." into rvc-dev am: 7f1ad4d34a am: 999b9558aa
Change-Id: I07ce4e5f104bd8d15ecf65e55d241ac868e38d72
This commit is contained in:
@@ -1583,13 +1583,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
|||||||
hasBeenLaunched = false;
|
hasBeenLaunched = false;
|
||||||
mStackSupervisor = supervisor;
|
mStackSupervisor = supervisor;
|
||||||
|
|
||||||
// b/35954083: Limit task affinity to uid to avoid various issues associated with sharing
|
info.taskAffinity = getTaskAffinityWithUid(info.taskAffinity, info.applicationInfo.uid);
|
||||||
// affinity across uids.
|
|
||||||
final String uid = Integer.toString(info.applicationInfo.uid);
|
|
||||||
if (info.taskAffinity != null && !info.taskAffinity.startsWith(uid)) {
|
|
||||||
info.taskAffinity = uid + ":" + info.taskAffinity;
|
|
||||||
}
|
|
||||||
taskAffinity = info.taskAffinity;
|
taskAffinity = info.taskAffinity;
|
||||||
|
final String uid = Integer.toString(info.applicationInfo.uid);
|
||||||
if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
|
if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
|
||||||
&& !info.windowLayout.windowLayoutAffinity.startsWith(uid)) {
|
&& !info.windowLayout.windowLayoutAffinity.startsWith(uid)) {
|
||||||
info.windowLayout.windowLayoutAffinity =
|
info.windowLayout.windowLayoutAffinity =
|
||||||
@@ -1647,6 +1643,22 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the task affinity with uid. For b/35954083, Limit task affinity to uid to avoid
|
||||||
|
* issues associated with sharing affinity across uids.
|
||||||
|
*
|
||||||
|
* @param affinity The affinity of the activity.
|
||||||
|
* @param uid The user-ID that has been assigned to this application.
|
||||||
|
* @return The task affinity with uid.
|
||||||
|
*/
|
||||||
|
static String getTaskAffinityWithUid(String affinity, int uid) {
|
||||||
|
final String uidStr = Integer.toString(uid);
|
||||||
|
if (affinity != null && !affinity.startsWith(uidStr)) {
|
||||||
|
affinity = uidStr + ":" + affinity;
|
||||||
|
}
|
||||||
|
return affinity;
|
||||||
|
}
|
||||||
|
|
||||||
static int getLockTaskLaunchMode(ActivityInfo aInfo, @Nullable ActivityOptions options) {
|
static int getLockTaskLaunchMode(ActivityInfo aInfo, @Nullable ActivityOptions options) {
|
||||||
int lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
|
int lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
|
||||||
if (aInfo.applicationInfo.isPrivilegedApp()
|
if (aInfo.applicationInfo.isPrivilegedApp()
|
||||||
|
|||||||
@@ -2376,8 +2376,10 @@ class ActivityStack extends Task {
|
|||||||
boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) {
|
boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) {
|
||||||
// Basic case: for simple app-centric recents, we need to recreate
|
// Basic case: for simple app-centric recents, we need to recreate
|
||||||
// the task if the affinity has changed.
|
// the task if the affinity has changed.
|
||||||
|
|
||||||
|
final String affinity = ActivityRecord.getTaskAffinityWithUid(destAffinity, srec.getUid());
|
||||||
if (srec == null || srec.getTask().affinity == null
|
if (srec == null || srec.getTask().affinity == null
|
||||||
|| !srec.getTask().affinity.equals(destAffinity)) {
|
|| !srec.getTask().affinity.equals(affinity)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Document-centric case: an app may be split in to multiple documents;
|
// Document-centric case: an app may be split in to multiple documents;
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import android.app.ActivityManager;
|
|||||||
import android.app.IApplicationThread;
|
import android.app.IApplicationThread;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
|
|
||||||
@@ -1290,6 +1291,27 @@ public class ActivityStackTests extends ActivityTestsBase {
|
|||||||
assertEquals(starter.mRequest.callingUid, secondActivity.getUid());
|
assertEquals(starter.mRequest.callingUid, secondActivity.getUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldUpRecreateTaskLockedWithCorrectAffinityFormat() {
|
||||||
|
final String affinity = "affinity";
|
||||||
|
final ActivityRecord activity = new ActivityBuilder(mService).setAffinity(affinity)
|
||||||
|
.setUid(Binder.getCallingUid()).setCreateTask(true).build();
|
||||||
|
activity.getTask().affinity = activity.taskAffinity;
|
||||||
|
|
||||||
|
assertFalse(mStack.shouldUpRecreateTaskLocked(activity, affinity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldUpRecreateTaskLockedWithWrongAffinityFormat() {
|
||||||
|
final String affinity = "affinity";
|
||||||
|
final ActivityRecord activity = new ActivityBuilder(mService).setAffinity(affinity)
|
||||||
|
.setUid(Binder.getCallingUid()).setCreateTask(true).build();
|
||||||
|
activity.getTask().affinity = activity.taskAffinity;
|
||||||
|
final String fakeAffinity = activity.getUid() + activity.taskAffinity;
|
||||||
|
|
||||||
|
assertTrue(mStack.shouldUpRecreateTaskLocked(activity, fakeAffinity));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResetTaskWithFinishingActivities() {
|
public void testResetTaskWithFinishingActivities() {
|
||||||
final ActivityRecord taskTop =
|
final ActivityRecord taskTop =
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
|||||||
private String mTargetActivity;
|
private String mTargetActivity;
|
||||||
private Task mTask;
|
private Task mTask;
|
||||||
private String mProcessName = "name";
|
private String mProcessName = "name";
|
||||||
|
private String mAffinity;
|
||||||
private int mUid = 12345;
|
private int mUid = 12345;
|
||||||
private boolean mCreateTask;
|
private boolean mCreateTask;
|
||||||
private ActivityStack mStack;
|
private ActivityStack mStack;
|
||||||
@@ -223,6 +224,11 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActivityBuilder setAffinity(String affinity) {
|
||||||
|
mAffinity = affinity;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
ActivityRecord build() {
|
ActivityRecord build() {
|
||||||
try {
|
try {
|
||||||
mService.deferWindowLayout();
|
mService.deferWindowLayout();
|
||||||
@@ -271,6 +277,7 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
|||||||
aInfo.maxAspectRatio = mMaxAspectRatio;
|
aInfo.maxAspectRatio = mMaxAspectRatio;
|
||||||
aInfo.screenOrientation = mScreenOrientation;
|
aInfo.screenOrientation = mScreenOrientation;
|
||||||
aInfo.configChanges |= mConfigChanges;
|
aInfo.configChanges |= mConfigChanges;
|
||||||
|
aInfo.taskAffinity = mAffinity;
|
||||||
|
|
||||||
ActivityOptions options = null;
|
ActivityOptions options = null;
|
||||||
if (mLaunchTaskBehind) {
|
if (mLaunchTaskBehind) {
|
||||||
|
|||||||
Reference in New Issue
Block a user