Merge "Revert "Collect NeededUriGrants without holding locks."" into qt-dev

am: 2aa255a746

Change-Id: Ib1b97e7a56015430a6d2599d1ed9bc77d1ef8d67
This commit is contained in:
Wale Ogunwale
2019-06-04 18:12:27 -07:00
committed by android-build-merger
12 changed files with 114 additions and 221 deletions

View File

@@ -43,14 +43,14 @@ public interface UriGrantsManagerInternal {
int callingUid, String targetPkg, Uri uri, int modeFlags, int userId);
NeededUriGrants checkGrantUriPermissionFromIntent(int callingUid,
String targetPkg, Intent intent, int mode, NeededUriGrants needed, int targetUserId);
NeededUriGrants checkGrantUriPermissionFromIntent(int callingUid,
Intent intent, String targetPkg, int targetUserId);
/**
* Grant Uri permissions from one app to another. This method only extends
* permission grants if {@code callingUid} has permission to them.
*/
void grantUriPermissionFromIntent(int callingUid,
String targetPkg, Intent intent, int targetUserId);
void grantUriPermissionFromIntent(int callingUid,
String targetPkg, Intent intent, UriPermissionOwner owner, int targetUserId);
void grantUriPermissionUncheckedFromIntent(
NeededUriGrants needed, UriPermissionOwner owner);
IBinder newUriPermissionOwner(String name);

View File

@@ -1361,16 +1361,6 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
}
}
@Override
public NeededUriGrants checkGrantUriPermissionFromIntent(int callingUid, Intent intent,
String targetPkg, int targetUserId) {
synchronized (mLock) {
final int mode = (intent != null) ? intent.getFlags() : 0;
return UriGrantsManagerService.this.checkGrantUriPermissionFromIntent(
callingUid, targetPkg, intent, mode, null, targetUserId);
}
}
@Override
public void grantUriPermissionFromIntent(int callingUid, String targetPkg, Intent intent,
int targetUserId) {
@@ -1380,6 +1370,15 @@ public class UriGrantsManagerService extends IUriGrantsManager.Stub {
}
}
@Override
public void grantUriPermissionFromIntent(int callingUid, String targetPkg, Intent intent,
UriPermissionOwner owner, int targetUserId) {
synchronized (mLock) {
UriGrantsManagerService.this.grantUriPermissionFromIntent(
callingUid, targetPkg, intent, owner, targetUserId);
}
}
@Override
public void grantUriPermissionUncheckedFromIntent(NeededUriGrants needed,
UriPermissionOwner owner) {

View File

@@ -215,7 +215,6 @@ import com.android.server.AttributeCache;
import com.android.server.AttributeCache.Entry;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.PendingIntentRecord;
import com.android.server.uri.NeededUriGrants;
import com.android.server.uri.UriPermissionOwner;
import com.android.server.wm.ActivityMetricsLogger.WindowingModeTransitionInfoSnapshot;
import com.android.server.wm.ActivityStack.ActivityState;
@@ -1600,11 +1599,10 @@ final class ActivityRecord extends ConfigurationContainer {
* Deliver a new Intent to an existing activity, so that its onNewIntent()
* method will be called at the proper time.
*/
final void deliverNewIntentLocked(int callingUid, Intent intent, NeededUriGrants intentGrants,
String referrer) {
final void deliverNewIntentLocked(int callingUid, Intent intent, String referrer) {
// The activity now gets access to the data associated with this Intent.
mAtmService.mUgmInternal.grantUriPermissionUncheckedFromIntent(intentGrants,
getUriPermissionsLocked());
mAtmService.mUgmInternal.grantUriPermissionFromIntent(callingUid, packageName,
intent, getUriPermissionsLocked(), mUserId);
final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
boolean unsent = true;
final boolean isTopActivityWhileSleeping = isTopRunningActivity() && isSleeping();

View File

@@ -163,7 +163,6 @@ import com.android.server.am.ActivityManagerService.ItemMatcher;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.EventLogTags;
import com.android.server.am.PendingIntentRecord;
import com.android.server.uri.NeededUriGrants;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -2782,7 +2781,7 @@ class ActivityStack extends ConfigurationContainer {
if (DEBUG_STATES) Slog.d(TAG_STATES,
"no-history finish of " + mLastNoHistoryActivity + " on new resume");
requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED,
null, null, "resume-no-history", false);
null, "resume-no-history", false);
mLastNoHistoryActivity = null;
}
@@ -3016,7 +3015,7 @@ class ActivityStack extends ConfigurationContainer {
// If any exception gets thrown, toss away this
// activity and try the next one.
Slog.w(TAG, "Exception thrown during resume of " + next, e);
requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, null,
requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null,
"resume-exception", true);
return true;
}
@@ -3426,7 +3425,7 @@ class ActivityStack extends ConfigurationContainer {
if (DEBUG_TASKS) Slog.w(TAG_TASKS,
"resetTaskIntendedTask: calling finishActivity on " + p);
if (finishActivityLocked(
p, Activity.RESULT_CANCELED, null, null, "reset-task", false)) {
p, Activity.RESULT_CANCELED, null, "reset-task", false)) {
end--;
srcPos--;
}
@@ -3505,7 +3504,7 @@ class ActivityStack extends ConfigurationContainer {
continue;
}
finishActivityLocked(
p, Activity.RESULT_CANCELED, null, null, "move-affinity", false);
p, Activity.RESULT_CANCELED, null, "move-affinity", false);
}
} else {
if (taskInsertionPoint < 0) {
@@ -3539,8 +3538,8 @@ class ActivityStack extends ConfigurationContainer {
if (targetNdx > 0) {
ActivityRecord p = taskActivities.get(targetNdx - 1);
if (p.intent.getComponent().equals(target.intent.getComponent())) {
finishActivityLocked(p, Activity.RESULT_CANCELED, null, null,
"replace", false);
finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace",
false);
}
}
}
@@ -3600,21 +3599,22 @@ class ActivityStack extends ConfigurationContainer {
return taskTop;
}
void sendActivityResultLocked(int callingUid, ActivityRecord r, String resultWho,
int requestCode, int resultCode, Intent resultData, NeededUriGrants resultGrants) {
void sendActivityResultLocked(int callingUid, ActivityRecord r,
String resultWho, int requestCode, int resultCode, Intent data) {
if (callingUid > 0) {
mService.mUgmInternal.grantUriPermissionUncheckedFromIntent(resultGrants,
r.getUriPermissionsLocked());
mService.mUgmInternal.grantUriPermissionFromIntent(callingUid, r.packageName,
data, r.getUriPermissionsLocked(), r.mUserId);
}
if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r
+ " : who=" + resultWho + " req=" + requestCode
+ " res=" + resultCode + " data=" + resultData);
+ " res=" + resultCode + " data=" + data);
if (mResumedActivity == r && r.attachedToProcess()) {
try {
ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
list.add(new ResultInfo(resultWho, requestCode,
resultCode, resultData));
resultCode, data));
mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken,
ActivityResultItem.obtain(list));
return;
@@ -3623,7 +3623,7 @@ class ActivityStack extends ConfigurationContainer {
}
}
r.addResultLocked(null, resultWho, requestCode, resultCode, resultData);
r.addResultLocked(null, resultWho, requestCode, resultCode, data);
}
/** Returns true if the task is one of the task finishing on-top of the top running task. */
@@ -3730,8 +3730,8 @@ class ActivityStack extends ConfigurationContainer {
if (!r.finishing) {
if (!shouldSleepActivities()) {
if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r);
if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED,
null, null, "stop-no-history", false)) {
if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
"stop-no-history", false)) {
// If {@link requestFinishActivityLocked} returns {@code true},
// {@link adjustFocusedActivityStack} would have been already called.
r.resumeKeyDispatchingLocked();
@@ -3787,7 +3787,7 @@ class ActivityStack extends ConfigurationContainer {
* some reason it is being left as-is.
*/
final boolean requestFinishActivityLocked(IBinder token, int resultCode,
Intent resultData, NeededUriGrants resultGrants, String reason, boolean oomAdj) {
Intent resultData, String reason, boolean oomAdj) {
ActivityRecord r = isInStackLocked(token);
if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES,
"Finishing activity token=" + token + " r="
@@ -3797,7 +3797,7 @@ class ActivityStack extends ConfigurationContainer {
return false;
}
finishActivityLocked(r, resultCode, resultData, resultGrants, reason, oomAdj);
finishActivityLocked(r, resultCode, resultData, reason, oomAdj);
return true;
}
@@ -3809,8 +3809,8 @@ class ActivityStack extends ConfigurationContainer {
if (r.resultTo == self && r.requestCode == requestCode) {
if ((r.resultWho == null && resultWho == null) ||
(r.resultWho != null && r.resultWho.equals(resultWho))) {
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null,
"request-sub", false);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub",
false);
}
}
}
@@ -3840,7 +3840,7 @@ class ActivityStack extends ConfigurationContainer {
int activityNdx = task.mActivities.indexOf(r);
getDisplay().mDisplayContent.prepareAppTransition(
TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null, reason, false);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false);
finishedTask = task;
// Also terminate any activities below it that aren't yet
// stopped, to avoid a situation where one will get
@@ -3861,7 +3861,7 @@ class ActivityStack extends ConfigurationContainer {
if (!r.isActivityTypeHome() || mService.mHomeProcess != r.app) {
Slog.w(TAG, " Force finishing activity "
+ r.intent.getComponent().flattenToShortString());
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null, reason, false);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false);
}
}
}
@@ -3877,8 +3877,8 @@ class ActivityStack extends ConfigurationContainer {
for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
ActivityRecord r = tr.mActivities.get(activityNdx);
if (!r.finishing) {
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null,
"finish-voice", false);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice",
false);
didOne = true;
}
}
@@ -3914,14 +3914,12 @@ class ActivityStack extends ConfigurationContainer {
if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) {
break;
}
finishActivityLocked(cur, Activity.RESULT_CANCELED, null, null,
"request-affinity", true);
finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true);
}
return true;
}
private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData,
NeededUriGrants resultGrants) {
private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) {
// send the result
ActivityRecord resultTo = r.resultTo;
if (resultTo != null) {
@@ -3934,8 +3932,9 @@ class ActivityStack extends ConfigurationContainer {
}
}
if (r.info.applicationInfo.uid > 0) {
mService.mUgmInternal.grantUriPermissionUncheckedFromIntent(resultGrants,
resultTo.getUriPermissionsLocked());
mService.mUgmInternal.grantUriPermissionFromIntent(r.info.applicationInfo.uid,
resultTo.packageName, resultData,
resultTo.getUriPermissionsLocked(), resultTo.mUserId);
}
resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, resultData);
r.resultTo = null;
@@ -3951,10 +3950,12 @@ class ActivityStack extends ConfigurationContainer {
r.icicle = null;
}
/**
* See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)}
*/
final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData,
NeededUriGrants resultGrants, String reason, boolean oomAdj) {
return finishActivityLocked(r, resultCode, resultData, resultGrants, reason, oomAdj,
!PAUSE_IMMEDIATELY);
String reason, boolean oomAdj) {
return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY);
}
/**
@@ -3962,7 +3963,7 @@ class ActivityStack extends ConfigurationContainer {
* list, or false if it is still in the list and will be removed later.
*/
final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData,
NeededUriGrants resultGrants, String reason, boolean oomAdj, boolean pauseImmediately) {
String reason, boolean oomAdj, boolean pauseImmediately) {
if (r.finishing) {
Slog.w(TAG, "Duplicate finish request for " + r);
return false;
@@ -3992,7 +3993,7 @@ class ActivityStack extends ConfigurationContainer {
adjustFocusedActivityStack(r, "finishActivity");
finishActivityResultsLocked(r, resultCode, resultData, resultGrants);
finishActivityResultsLocked(r, resultCode, resultData);
final boolean endTask = index <= 0 && !task.isClearingToReuseTask();
final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE;
@@ -4225,9 +4226,8 @@ class ActivityStack extends ConfigurationContainer {
return false;
}
final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent,
NeededUriGrants destGrants, int resultCode, Intent resultData,
NeededUriGrants resultGrants) {
final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode,
Intent resultData) {
final TaskRecord task = srec.getTaskRecord();
final ArrayList<ActivityRecord> activities = task.mActivities;
final int start = activities.indexOf(srec);
@@ -4274,8 +4274,7 @@ class ActivityStack extends ConfigurationContainer {
final long origId = Binder.clearCallingIdentity();
for (int i = start; i > finishTo; i--) {
ActivityRecord r = activities.get(i);
requestFinishActivityLocked(r.appToken, resultCode, resultData, resultGrants,
"navigate-up", true);
requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true);
// Only return the supplied result for the first activity finished
resultCode = Activity.RESULT_CANCELED;
resultData = null;
@@ -4289,7 +4288,7 @@ class ActivityStack extends ConfigurationContainer {
parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP ||
(destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent,
destGrants, srec.packageName);
srec.packageName);
} else {
try {
ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
@@ -4313,7 +4312,7 @@ class ActivityStack extends ConfigurationContainer {
foundParentInTask = false;
}
requestFinishActivityLocked(parent.appToken, resultCode,
resultData, resultGrants, "navigate-top", true);
resultData, "navigate-top", true);
}
}
Binder.restoreCallingIdentity(origId);
@@ -4398,7 +4397,7 @@ class ActivityStack extends ConfigurationContainer {
}
private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) {
finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null, null);
finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null);
r.makeFinishingLocked();
if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE,
"Removing activity " + r + " from stack callers=" + Debug.getCallers(5));
@@ -5130,8 +5129,7 @@ class ActivityStack extends ConfigurationContainer {
for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
final ActivityRecord r = activities.get(activityNdx);
if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) {
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null,
"close-sys", true);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true);
}
}
}
@@ -5175,8 +5173,8 @@ class ActivityStack extends ConfigurationContainer {
didSomething = true;
Slog.i(TAG, " Force finishing activity " + r);
lastTask = r.getTaskRecord();
finishActivityLocked(r, Activity.RESULT_CANCELED, null, null,
"force-stop", true);
finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop",
true);
}
}
}
@@ -5230,8 +5228,8 @@ class ActivityStack extends ConfigurationContainer {
final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities;
int activityTop = activities.size() - 1;
if (activityTop >= 0) {
finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED,
null, null, "unhandled-back", true);
finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null,
"unhandled-back", true);
}
}
}

View File

@@ -140,7 +140,6 @@ import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.EventLogTags;
import com.android.server.am.UserState;
import com.android.server.uri.NeededUriGrants;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -404,17 +403,14 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
final int startFlags;
final ActivityStack stack;
final WindowProcessController callerApp;
final NeededUriGrants neededGrants;
PendingActivityLaunch(ActivityRecord r, ActivityRecord sourceRecord,
int startFlags, ActivityStack stack, WindowProcessController callerApp,
NeededUriGrants neededGrants) {
this.r = r;
this.sourceRecord = sourceRecord;
this.startFlags = startFlags;
this.stack = stack;
this.callerApp = callerApp;
this.neededGrants = neededGrants;
PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord,
int _startFlags, ActivityStack _stack, WindowProcessController app) {
r = _r;
sourceRecord = _sourceRecord;
startFlags = _startFlags;
stack = _stack;
callerApp = app;
}
void sendErrorResult(String message) {
@@ -878,8 +874,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
Slog.e(TAG, "Second failure launching "
+ r.intent.getComponent().flattenToShortString() + ", giving up", e);
proc.appDied();
stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED,
null, null, "2nd-crash", false);
stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
"2nd-crash", false);
return false;
}
@@ -1024,7 +1020,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
if (resultRecord != null) {
resultStack.sendActivityResultLocked(-1,
resultRecord, resultWho, requestCode,
Activity.RESULT_CANCELED, null, null);
Activity.RESULT_CANCELED, null);
}
final String msg;
if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) {

View File

@@ -462,7 +462,7 @@ public class ActivityStartController {
"pendingActivityLaunch");
try {
starter.startResolvedActivity(pal.r, pal.sourceRecord, null, null, pal.startFlags,
resume, pal.r.pendingOptions, null, pal.neededGrants);
resume, pal.r.pendingOptions, null);
} catch (Exception e) {
Slog.e(TAG, "Exception during pending activity launch pal=" + pal, e);
pal.sendErrorResult(e.getMessage());

View File

@@ -124,7 +124,6 @@ import com.android.internal.app.IVoiceInteractor;
import com.android.server.am.EventLogTags;
import com.android.server.am.PendingIntentRecord;
import com.android.server.pm.InstantAppResolver;
import com.android.server.uri.NeededUriGrants;
import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch;
import com.android.server.wm.LaunchParamsController.LaunchParams;
@@ -547,8 +546,7 @@ class ActivityStarter {
*/
int startResolvedActivity(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,
NeededUriGrants neededGrants) {
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask) {
try {
mSupervisor.getActivityMetricsLogger().notifyActivityLaunching(r.intent);
mLastStartReason = "startResolvedActivity";
@@ -556,7 +554,7 @@ class ActivityStarter {
mLastStartActivityRecord[0] = r;
mLastStartActivityResult = startActivity(r, sourceRecord, voiceSession, voiceInteractor,
startFlags, doResume, options, inTask, mLastStartActivityRecord,
false /* restrictedBgActivity */, neededGrants);
false /* restrictedBgActivity */);
mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(mLastStartActivityResult,
mLastStartActivityRecord[0]);
return mLastStartActivityResult;
@@ -575,33 +573,6 @@ class ActivityStarter {
boolean allowPendingRemoteAnimationRegistryLookup,
PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart) {
// Carefully collect grants without holding lock
NeededUriGrants neededGrants = null;
if (aInfo != null) {
neededGrants = mService.mUgmInternal.checkGrantUriPermissionFromIntent(
resolveCallingUid(mRequest.caller), intent, aInfo.applicationInfo.packageName,
UserHandle.getUserId(aInfo.applicationInfo.uid));
}
return startActivity(caller, intent, ephemeralIntent, resolvedType, aInfo, rInfo,
voiceSession, voiceInteractor, resultTo, resultWho, requestCode, callingPid,
callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, options,
ignoreTargetSecurity, componentSpecified, outActivity, inTask, reason,
allowPendingRemoteAnimationRegistryLookup, originatingPendingIntent,
allowBackgroundActivityStart, neededGrants);
}
private int startActivity(IApplicationThread caller, Intent intent, Intent ephemeralIntent,
String resolvedType, ActivityInfo aInfo, ResolveInfo rInfo,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid,
String callingPackage, int realCallingPid, int realCallingUid, int startFlags,
SafeActivityOptions options, boolean ignoreTargetSecurity, boolean componentSpecified,
ActivityRecord[] outActivity, TaskRecord inTask, String reason,
boolean allowPendingRemoteAnimationRegistryLookup,
PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart,
NeededUriGrants neededGrants) {
if (TextUtils.isEmpty(reason)) {
throw new IllegalArgumentException("Need to specify a reason.");
}
@@ -614,7 +585,7 @@ class ActivityStarter {
callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags,
options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord,
inTask, allowPendingRemoteAnimationRegistryLookup, originatingPendingIntent,
allowBackgroundActivityStart, neededGrants);
allowBackgroundActivityStart);
if (outActivity != null) {
// mLastStartActivityRecord[0] is set in the call to startActivity above.
@@ -645,8 +616,7 @@ class ActivityStarter {
SafeActivityOptions options,
boolean ignoreTargetSecurity, boolean componentSpecified, ActivityRecord[] outActivity,
TaskRecord inTask, boolean allowPendingRemoteAnimationRegistryLookup,
PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart,
NeededUriGrants neededGrants) {
PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart) {
mSupervisor.getActivityMetricsLogger().notifyActivityLaunching(intent);
int err = ActivityManager.START_SUCCESS;
// Pull the optional Ephemeral Installer-only bundle out of the options early.
@@ -781,7 +751,7 @@ class ActivityStarter {
if (err != START_SUCCESS) {
if (resultRecord != null) {
resultStack.sendActivityResultLocked(
-1, resultRecord, resultWho, requestCode, RESULT_CANCELED, null, null);
-1, resultRecord, resultWho, requestCode, RESULT_CANCELED, null);
}
SafeActivityOptions.abort(options);
return err;
@@ -841,16 +811,12 @@ class ActivityStarter {
callingPid = mInterceptor.mCallingPid;
callingUid = mInterceptor.mCallingUid;
checkedOptions = mInterceptor.mActivityOptions;
// The interception target shouldn't get any permission grants
// intended for the original destination
neededGrants = null;
}
if (abort) {
if (resultRecord != null) {
resultStack.sendActivityResultLocked(-1, resultRecord, resultWho, requestCode,
RESULT_CANCELED, null, null);
RESULT_CANCELED, null);
}
// We pretend to the caller that it was really started, but
// they will just get a cancel result.
@@ -906,10 +872,6 @@ class ActivityStarter {
aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags,
null /*profilerInfo*/);
// The permissions review target shouldn't get any permission
// grants intended for the original destination
neededGrants = null;
if (DEBUG_PERMISSIONS_REVIEW) {
final ActivityStack focusedStack =
mRootActivityContainer.getTopDisplayFocusedStack();
@@ -932,10 +894,6 @@ class ActivityStarter {
callingPid = realCallingPid;
aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, null /*profilerInfo*/);
// The ephemeral installer shouldn't get any permission grants
// intended for the original destination
neededGrants = null;
}
ActivityRecord r = new ActivityRecord(mService, callerApp, callingPid, callingUid,
@@ -962,7 +920,7 @@ class ActivityStarter {
realCallingPid, realCallingUid, "Activity start")) {
if (!(restrictedBgActivity && handleBackgroundActivityAbort(r))) {
mController.addPendingActivityLaunch(new PendingActivityLaunch(r,
sourceRecord, startFlags, stack, callerApp, neededGrants));
sourceRecord, startFlags, stack, callerApp));
}
ActivityOptions.abort(checkedOptions);
return ActivityManager.START_SWITCHES_CANCELED;
@@ -973,8 +931,7 @@ class ActivityStarter {
mController.doPendingActivityLaunches(false);
final int res = startActivity(r, sourceRecord, voiceSession, voiceInteractor, startFlags,
true /* doResume */, checkedOptions, inTask, outActivity, restrictedBgActivity,
neededGrants);
true /* doResume */, checkedOptions, inTask, outActivity, restrictedBgActivity);
mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(res, outActivity[0]);
return res;
}
@@ -1254,15 +1211,9 @@ class ActivityStarter {
}
}
}
// Collect information about the target of the Intent.
ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo);
// Carefully collect grants without holding lock
NeededUriGrants neededGrants = mService.mUgmInternal.checkGrantUriPermissionFromIntent(
resolveCallingUid(mRequest.caller), intent, aInfo.applicationInfo.packageName,
UserHandle.getUserId(aInfo.applicationInfo.uid));
synchronized (mService.mGlobalLock) {
final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack();
stack.mConfigWillChange = globalConfig != null
@@ -1339,7 +1290,7 @@ class ActivityStarter {
callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, options,
ignoreTargetSecurity, componentSpecified, outRecord, inTask, reason,
allowPendingRemoteAnimationRegistryLookup, originatingPendingIntent,
allowBackgroundActivityStart, neededGrants);
allowBackgroundActivityStart);
Binder.restoreCallingIdentity(origId);
@@ -1434,16 +1385,14 @@ class ActivityStarter {
private int startActivity(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,
ActivityRecord[] outActivity, boolean restrictedBgActivity,
NeededUriGrants neededGrants) {
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,
ActivityRecord[] outActivity, boolean restrictedBgActivity) {
int result = START_CANCELED;
final ActivityStack startedActivityStack;
try {
mService.mWindowManager.deferSurfaceLayout();
result = startActivityUnchecked(r, sourceRecord, voiceSession, voiceInteractor,
startFlags, doResume, options, inTask, outActivity, restrictedBgActivity,
neededGrants);
startFlags, doResume, options, inTask, outActivity, restrictedBgActivity);
} finally {
final ActivityStack currentStack = r.getActivityStack();
startedActivityStack = currentStack != null ? currentStack : mTargetStack;
@@ -1468,8 +1417,7 @@ class ActivityStarter {
final ActivityStack stack = mStartActivity.getActivityStack();
if (stack != null) {
stack.finishActivityLocked(mStartActivity, RESULT_CANCELED,
null /* resultData */, null /* resultGrants */,
"startActivity", true /* oomAdj */);
null /* intentResultData */, "startActivity", true /* oomAdj */);
}
}
mService.mWindowManager.continueSurfaceLayout();
@@ -1497,7 +1445,7 @@ class ActivityStarter {
if (resultRecord != null) {
ActivityStack resultStack = resultRecord.getActivityStack();
resultStack.sendActivityResultLocked(-1, resultRecord, resultWho, requestCode,
RESULT_CANCELED, null, null);
RESULT_CANCELED, null);
}
// We pretend to the caller that it was really started to make it backward compatible, but
// they will just get a cancel result.
@@ -1509,8 +1457,7 @@ class ActivityStarter {
private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask,
ActivityRecord[] outActivity, boolean restrictedBgActivity,
NeededUriGrants neededGrants) {
ActivityRecord[] outActivity, boolean restrictedBgActivity) {
setInitialState(r, options, inTask, doResume, startFlags, sourceRecord, voiceSession,
voiceInteractor, restrictedBgActivity);
@@ -1660,7 +1607,7 @@ class ActivityStarter {
if (sourceStack != null) {
sourceStack.sendActivityResultLocked(-1 /* callingUid */, mStartActivity.resultTo,
mStartActivity.resultWho, mStartActivity.requestCode, RESULT_CANCELED,
null /* resultData */, null /* resultGrants */);
null /* data */);
}
ActivityOptions.abort(mOptions);
return START_CLASS_NOT_FOUND;
@@ -1727,8 +1674,8 @@ class ActivityStarter {
return result;
}
mService.mUgmInternal.grantUriPermissionUncheckedFromIntent(neededGrants,
mStartActivity.getUriPermissionsLocked());
mService.mUgmInternal.grantUriPermissionFromIntent(mCallingUid, mStartActivity.packageName,
mIntent, mStartActivity.getUriPermissionsLocked(), mStartActivity.mUserId);
mService.getPackageManagerInternalLocked().grantEphemeralAccess(
mStartActivity.mUserId, mIntent, UserHandle.getAppId(mStartActivity.appInfo.uid),
UserHandle.getAppId(mCallingUid));
@@ -1964,7 +1911,7 @@ class ActivityStarter {
Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result.");
sourceStack.sendActivityResultLocked(-1 /* callingUid */, mStartActivity.resultTo,
mStartActivity.resultWho, mStartActivity.requestCode, RESULT_CANCELED,
null /* resultData */, null /* resultGrants */);
null /* data */);
mStartActivity.resultTo = null;
}
}
@@ -2393,13 +2340,8 @@ class ActivityStarter {
}
ActivityStack.logStartActivity(AM_NEW_INTENT, activity, activity.getTaskRecord());
Intent intent = mStartActivity.intent;
NeededUriGrants intentGrants = mService.mUgmInternal.checkGrantUriPermissionFromIntent(
mCallingUid, intent, activity.packageName, activity.mUserId);
activity.deliverNewIntentLocked(mCallingUid, intent, intentGrants,
activity.deliverNewIntentLocked(mCallingUid, mStartActivity.intent,
mStartActivity.launchedFromPackage);
mIntentDelivered = true;
}
@@ -2778,18 +2720,6 @@ class ActivityStarter {
}
}
private int resolveCallingUid(IApplicationThread caller) {
if (caller != null) {
synchronized (mService.mGlobalLock) {
final WindowProcessController callerApp = mService.getProcessController(caller);
if (callerApp != null) {
return callerApp.mInfo.uid;
}
}
}
return -1;
}
private boolean isLaunchModeOneOf(int mode1, int mode2) {
return mode1 == mLaunchMode || mode2 == mLaunchMode;
}

View File

@@ -265,7 +265,6 @@ import com.android.server.appop.AppOpsService;
import com.android.server.firewall.IntentFirewall;
import com.android.server.pm.UserManagerService;
import com.android.server.policy.PermissionPolicyInternal;
import com.android.server.uri.NeededUriGrants;
import com.android.server.uri.UriGrantsManagerInternal;
import com.android.server.vr.VrManagerInternal;
@@ -1547,19 +1546,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
throw new IllegalArgumentException("File descriptors passed in Intent");
}
final ActivityRecord r;
synchronized (mGlobalLock) {
r = ActivityRecord.isInStackLocked(token);
ActivityRecord r = ActivityRecord.isInStackLocked(token);
if (r == null) {
return true;
}
}
// Carefully collect grants without holding lock
final NeededUriGrants resultGrants = mUgmInternal.checkGrantUriPermissionFromIntent(
Binder.getCallingUid(), resultData, r.packageName, r.mUserId);
synchronized (mGlobalLock) {
// Keep track of the root activity of the task before we finish it
final TaskRecord tr = r.getTaskRecord();
ActivityRecord rootR = tr.getRootActivity();
@@ -1621,7 +1612,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
r.mRelaunchReason = RELAUNCH_REASON_NONE;
} else {
res = tr.getStack().requestFinishActivityLocked(token, resultCode,
resultData, resultGrants, "app-request", true);
resultData, "app-request", true);
if (!res) {
Slog.i(TAG, "Failed to finish by app-request");
}
@@ -2147,23 +2138,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
@Override
public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
Intent resultData) {
final ActivityRecord r;
synchronized (mGlobalLock) {
r = ActivityRecord.isInStackLocked(token);
if (r == null) {
return false;
final ActivityRecord r = ActivityRecord.forTokenLocked(token);
if (r != null) {
return r.getActivityStack().navigateUpToLocked(
r, destIntent, resultCode, resultData);
}
}
// Carefully collect grants without holding lock
final NeededUriGrants destGrants = mUgmInternal.checkGrantUriPermissionFromIntent(
Binder.getCallingUid(), destIntent, r.packageName, r.mUserId);
final NeededUriGrants resultGrants = mUgmInternal.checkGrantUriPermissionFromIntent(
Binder.getCallingUid(), resultData, r.packageName, r.mUserId);
synchronized (mGlobalLock) {
return r.getActivityStack().navigateUpToLocked(
r, destIntent, destGrants, resultCode, resultData, resultGrants);
return false;
}
}
@@ -6617,23 +6599,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
@Override
public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho,
int requestCode, int resultCode, Intent resultData) {
final ActivityRecord r;
int requestCode, int resultCode, Intent data) {
synchronized (mGlobalLock) {
r = ActivityRecord.isInStackLocked(activityToken);
if (r == null || r.getActivityStack() == null) {
return;
final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken);
if (r != null && r.getActivityStack() != null) {
r.getActivityStack().sendActivityResultLocked(callingUid, r, resultWho,
requestCode, resultCode, data);
}
}
// Carefully collect grants without holding lock
final NeededUriGrants resultGrants = mUgmInternal.checkGrantUriPermissionFromIntent(
Binder.getCallingUid(), resultData, r.packageName, r.mUserId);
synchronized (mGlobalLock) {
r.getActivityStack().sendActivityResultLocked(callingUid, r, resultWho,
requestCode, resultCode, resultData, resultGrants);
}
}
@Override

View File

@@ -1442,7 +1442,7 @@ class TaskRecord extends ConfigurationContainer {
mActivities.remove(activityNdx);
--activityNdx;
--numActivities;
} else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, null,
} else if (mStack.finishActivityLocked(r, Activity.RESULT_CANCELED, null,
reason, false, pauseImmediately)) {
--activityNdx;
--numActivities;
@@ -1497,8 +1497,8 @@ class TaskRecord extends ConfigurationContainer {
if (opts != null) {
ret.updateOptionsLocked(opts);
}
if (mStack != null && mStack.finishActivityLocked(r, Activity.RESULT_CANCELED,
null, null, "clear-task-stack", false)) {
if (mStack != null && mStack.finishActivityLocked(
r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
--activityNdx;
--numActivities;
}
@@ -1512,8 +1512,8 @@ class TaskRecord extends ConfigurationContainer {
&& !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
if (!ret.finishing) {
if (mStack != null) {
mStack.finishActivityLocked(ret, Activity.RESULT_CANCELED,
null, null, "clear-task-top", false);
mStack.finishActivityLocked(
ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
}
return null;
}

View File

@@ -629,7 +629,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
final ActivityRecord r = activities.get(i);
if (!r.finishing && r.isInStackLocked()) {
r.getActivityStack().finishActivityLocked(r, Activity.RESULT_CANCELED,
null, null, "finish-heavy", true);
null, "finish-heavy", true);
}
}
}

View File

@@ -940,8 +940,7 @@ public class ActivityStackTests extends ActivityTestsBase {
homeStask.removeTask(homeTask, "testAdjustFocusedStack", REMOVE_TASK_MODE_DESTROYING);
// Finish the only activity.
mStack.finishActivityLocked(topActivity, 0 /* resultCode */,
null /* resultData */, null /* resultGrants */,
mStack.finishActivityLocked(topActivity, 0 /* resultCode */, null /* resultData */,
"testAdjustFocusedStack", false /* oomAdj */);
// Although home stack is empty, it should still be the focused stack.
assertEquals(homeStask, mDefaultDisplay.getFocusedStack());

View File

@@ -82,12 +82,12 @@ public class ActivityStartControllerTests extends ActivityTestsBase {
wpc.setThread(mock(IApplicationThread.class));
mController.addPendingActivityLaunch(
new PendingActivityLaunch(activity, source, startFlags, stack, wpc, null));
new PendingActivityLaunch(activity, source, startFlags, stack, wpc));
final boolean resume = random.nextBoolean();
mController.doPendingActivityLaunches(resume);
verify(mStarter, times(1)).startResolvedActivity(eq(activity), eq(source), eq(null),
eq(null), eq(startFlags), eq(resume), eq(null), eq(null), eq(null));
eq(null), eq(startFlags), eq(resume), eq(null), eq(null));
}