Merge "Allow BAL from explicit start methods." into udc-dev

This commit is contained in:
Achim Thesmann
2023-04-14 01:21:18 +00:00
committed by Android (Google) Code Review

View File

@@ -1503,7 +1503,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
.setCallingPid(callingPid)
.setCallingPackage(intent.getPackage())
.setActivityInfo(a)
.setActivityOptions(options.toBundle())
.setActivityOptions(createSafeActivityOptionsWithBalAllowed(options))
// To start the dream from background, we need to start it from a persistent
// system process. Here we set the real calling uid to the system server uid
.setRealCallingUid(Binder.getCallingUid())
@@ -1651,7 +1651,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
.setResultWho(resultWho)
.setRequestCode(requestCode)
.setStartFlags(startFlags)
.setActivityOptions(bOptions)
.setActivityOptions(createSafeActivityOptionsWithBalAllowed(bOptions))
.setUserId(userId)
.setIgnoreTargetSecurity(ignoreTargetSecurity)
.setFilterCallingUid(isResolver ? 0 /* system */ : targetUid)
@@ -1701,7 +1701,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
.setVoiceInteractor(interactor)
.setStartFlags(startFlags)
.setProfilerInfo(profilerInfo)
.setActivityOptions(bOptions)
.setActivityOptions(createSafeActivityOptionsWithBalAllowed(bOptions))
.setUserId(userId)
.setBackgroundStartPrivileges(BackgroundStartPrivileges.ALLOW_BAL)
.execute();
@@ -1728,7 +1728,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
.setCallingPackage(callingPackage)
.setCallingFeatureId(callingFeatureId)
.setResolvedType(resolvedType)
.setActivityOptions(bOptions)
.setActivityOptions(createSafeActivityOptionsWithBalAllowed(bOptions))
.setUserId(userId)
.setBackgroundStartPrivileges(BackgroundStartPrivileges.ALLOW_BAL)
.execute();
@@ -5507,6 +5507,31 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
return checkPermission(permission, -1, sourceUid) == PackageManager.PERMISSION_GRANTED;
}
/**
* Wrap the {@link ActivityOptions} in {@link SafeActivityOptions} and attach caller options
* that allow using the callers permissions to start background activities.
*/
private SafeActivityOptions createSafeActivityOptionsWithBalAllowed(
@Nullable ActivityOptions options) {
if (options == null) {
options = ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);
} else if (options.getPendingIntentBackgroundActivityStartMode()
== ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED) {
options.setPendingIntentBackgroundActivityStartMode(
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED);
}
return new SafeActivityOptions(options);
}
/**
* Wrap the options {@link Bundle} in {@link SafeActivityOptions} and attach caller options
* that allow using the callers permissions to start background activities.
*/
private SafeActivityOptions createSafeActivityOptionsWithBalAllowed(@Nullable Bundle bOptions) {
return createSafeActivityOptionsWithBalAllowed(ActivityOptions.fromBundle(bOptions));
}
final class H extends Handler {
static final int REPORT_TIME_TRACKER_MSG = 1;
static final int UPDATE_PROCESS_ANIMATING_STATE = 2;