Merge "RESTRICT AUTOMERGE Use consistent calling uid and package in navigateUpTo" into oc-dev

This commit is contained in:
TreeHugger Robot
2020-03-11 08:53:52 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 5 deletions

View File

@@ -6722,7 +6722,7 @@ public class ActivityManagerService extends IActivityManager.Stub
} }
} }
private final boolean attachApplicationLocked(IApplicationThread thread, private boolean attachApplicationLocked(@NonNull IApplicationThread thread,
int pid) { int pid) {
// Find the application record that is being attached... either via // Find the application record that is being attached... either via
@@ -7027,6 +7027,9 @@ public class ActivityManagerService extends IActivityManager.Stub
@Override @Override
public final void attachApplication(IApplicationThread thread) { public final void attachApplication(IApplicationThread thread) {
if (thread == null) {
throw new SecurityException("Invalid application interface");
}
synchronized (this) { synchronized (this) {
int callingPid = Binder.getCallingPid(); int callingPid = Binder.getCallingPid();
final long origId = Binder.clearCallingIdentity(); final long origId = Binder.clearCallingIdentity();

View File

@@ -3853,6 +3853,11 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode,
Intent resultData) { Intent resultData) {
if (srec.app == null || srec.app.thread == null) {
// Nothing to do if the caller is not attached, because this method should be called
// from an alive activity.
return false;
}
final TaskRecord task = srec.getTask(); final TaskRecord task = srec.getTask();
final ArrayList<ActivityRecord> activities = task.mActivities; final ArrayList<ActivityRecord> activities = task.mActivities;
final int start = activities.indexOf(srec); final int start = activities.indexOf(srec);
@@ -3904,22 +3909,22 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
} }
if (parent != null && foundParentInTask) { if (parent != null && foundParentInTask) {
final int callingUid = srec.info.applicationInfo.uid;
final int parentLaunchMode = parent.info.launchMode; final int parentLaunchMode = parent.info.launchMode;
final int destIntentFlags = destIntent.getFlags(); final int destIntentFlags = destIntent.getFlags();
if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE ||
parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK ||
parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP ||
(destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, parent.deliverNewIntentLocked(callingUid, destIntent, srec.packageName);
srec.packageName);
} else { } else {
try { try {
ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
destIntent.getComponent(), 0, srec.userId); destIntent.getComponent(), 0, srec.userId);
int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, int res = mService.mActivityStarter.startActivityLocked(srec.app.thread,
destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null,
null, parent.appToken, null, 0, -1, parent.launchedFromUid, null, parent.appToken, null, 0, -1, callingUid,
parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, srec.packageName, -1, callingUid, 0, null,
false, true, null, null, null, "navigateUpTo"); false, true, null, null, null, "navigateUpTo");
foundParentInTask = res == ActivityManager.START_SUCCESS; foundParentInTask = res == ActivityManager.START_SUCCESS;
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@@ -17,6 +17,7 @@
package com.android.server.am; package com.android.server.am;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -119,4 +120,17 @@ public class ActivityStackTests extends ActivityTestsBase {
assertEquals(ActivityStack.STACK_VISIBLE_ACTIVITY_BEHIND, assertEquals(ActivityStack.STACK_VISIBLE_ACTIVITY_BEHIND,
fullscreenWorkspaceStackId.shouldBeVisible(null /*starting*/)); fullscreenWorkspaceStackId.shouldBeVisible(null /*starting*/));
} }
@Test
public void testNavigateUpTo() {
final ActivityManagerService service = createActivityManagerService();
final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
activityRecord.app = new ProcessRecord(null, activityRecord.appInfo,
activityRecord.processName, activityRecord.getUid());
final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
// No-op if the source activity record doesn't have attached process (app.thread == null).
assertFalse(testStack.navigateUpToLocked(activityRecord, activityRecord.intent,
0 /* resultCode */, null /* resultData */));
}
} }