Merge "Allow BAL from explicit start methods." into udc-dev am: 1cae945226

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22471866

Change-Id: I6b6ebe586f3d3d6921729bcb40c74c0277bfcbae
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Achim Thesmann
2023-04-14 01:55:55 +00:00
committed by Automerger Merge Worker

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;