diff options
| author | 2023-11-08 18:50:13 +0000 | |
|---|---|---|
| committer | 2023-11-08 18:50:13 +0000 | |
| commit | 2f0a4a538496381a129cbb4647b1b9bd0aaed4f9 (patch) | |
| tree | be032e78081a5c5988edc6978ba8b54402150a11 | |
| parent | 3064d2808711626d839c675d1a8439ca1847e898 (diff) | |
| parent | 2fe80cbc458c12a418e438f9c7dc576942abb561 (diff) | |
Merge "Rename backgroundStartPrivileges parameter." into main
5 files changed, 97 insertions, 37 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityStartController.java b/services/core/java/com/android/server/wm/ActivityStartController.java index 4a5311b14397..2c492035140b 100644 --- a/services/core/java/com/android/server/wm/ActivityStartController.java +++ b/services/core/java/com/android/server/wm/ActivityStartController.java @@ -269,12 +269,27 @@ public class ActivityStartController { } } + /** + * Start intent as a package. + * + * @param uid Make a call as if this UID did. + * @param callingPackage Make a call as if this package did. + * @param callingFeatureId Make a call as if this feature in the package did. + * @param intent Intent to start. + * @param userId Start the intents on this user. + * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. + * @param originatingPendingIntent PendingIntentRecord that originated this activity start or + * null if not originated by PendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. + */ final int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { userId = checkTargetUser(userId, validateIncomingUser, realCallingPid, realCallingUid, reason); @@ -295,7 +310,7 @@ public class ActivityStartController { .setUserId(userId) .setInTask(inTask) .setOriginatingPendingIntent(originatingPendingIntent) - .setBackgroundStartPrivileges(backgroundStartPrivileges) + .setBackgroundStartPrivileges(forcedBalByPiSender) .execute(); } @@ -310,15 +325,18 @@ public class ActivityStartController { * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. * @param originatingPendingIntent PendingIntentRecord that originated this activity start or * null if not originated by PendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. */ final int startActivitiesInPackage(int uid, String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { return startActivitiesInPackage(uid, 0 /* realCallingPid */, -1 /* realCallingUid */, callingPackage, callingFeatureId, intents, resolvedTypes, resultTo, options, userId, - validateIncomingUser, originatingPendingIntent, backgroundStartPrivileges); + validateIncomingUser, originatingPendingIntent, forcedBalByPiSender); } /** @@ -333,12 +351,15 @@ public class ActivityStartController { * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. * @param originatingPendingIntent PendingIntentRecord that originated this activity start or * null if not originated by PendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. */ final int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { final String reason = "startActivityInPackage"; @@ -348,14 +369,14 @@ public class ActivityStartController { // TODO: Switch to user app stacks here. return startActivities(null, uid, realCallingPid, realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, resultTo, options, userId, reason, - originatingPendingIntent, backgroundStartPrivileges); + originatingPendingIntent, forcedBalByPiSender); } int startActivities(IApplicationThread caller, int callingUid, int incomingRealCallingPid, int incomingRealCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, String reason, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { if (intents == null) { throw new NullPointerException("intents is null"); } @@ -463,7 +484,7 @@ public class ActivityStartController { // top one as otherwise an activity below might consume it. .setAllowPendingRemoteAnimationRegistryLookup(top /* allowLookup*/) .setOriginatingPendingIntent(originatingPendingIntent) - .setBackgroundStartPrivileges(backgroundStartPrivileges); + .setBackgroundStartPrivileges(forcedBalByPiSender); } // Log if the activities to be started have different uids. if (startingUidPkgs.size() > 1) { diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index 34bf8edc148f..009b8e048840 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -388,7 +388,7 @@ class ActivityStarter { WaitResult waitResult; int filterCallingUid; PendingIntentRecord originatingPendingIntent; - BackgroundStartPrivileges backgroundStartPrivileges; + BackgroundStartPrivileges forcedBalByPiSender; final StringBuilder logMessage = new StringBuilder(); @@ -451,7 +451,7 @@ class ActivityStarter { allowPendingRemoteAnimationRegistryLookup = true; filterCallingUid = UserHandle.USER_NULL; originatingPendingIntent = null; - backgroundStartPrivileges = BackgroundStartPrivileges.NONE; + forcedBalByPiSender = BackgroundStartPrivileges.NONE; errorCallbackToken = null; } @@ -494,7 +494,7 @@ class ActivityStarter { = request.allowPendingRemoteAnimationRegistryLookup; filterCallingUid = request.filterCallingUid; originatingPendingIntent = request.originatingPendingIntent; - backgroundStartPrivileges = request.backgroundStartPrivileges; + forcedBalByPiSender = request.forcedBalByPiSender; errorCallbackToken = request.errorCallbackToken; } @@ -1106,7 +1106,7 @@ class ActivityStarter { realCallingPid, callerApp, request.originatingPendingIntent, - request.backgroundStartPrivileges, + request.forcedBalByPiSender, intent, checkedOptions); balCode = balVerdict.getCode(); @@ -3167,9 +3167,8 @@ class ActivityStarter { return this; } - ActivityStarter setBackgroundStartPrivileges( - BackgroundStartPrivileges backgroundStartPrivileges) { - mRequest.backgroundStartPrivileges = backgroundStartPrivileges; + ActivityStarter setBackgroundStartPrivileges(BackgroundStartPrivileges forcedBalByPiSender) { + mRequest.forcedBalByPiSender = forcedBalByPiSender; return this; } diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java index a2547fd437d1..5604b1a6aa39 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java @@ -215,21 +215,39 @@ public abstract class ActivityTaskManagerInternal { * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. * @param originatingPendingIntent PendingIntentRecord that originated this activity start or * null if not originated by PendingIntent - * @param allowBackgroundActivityStart Whether the background activity start should be allowed - * from originatingPendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. */ public abstract int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges); + BackgroundStartPrivileges forcedBalByPiSender); + /** + * Start intent as a package. + * + * @param uid Make a call as if this UID did. + * @param realCallingPid PID of the real caller. + * @param realCallingUid UID of the real caller. + * @param callingPackage Make a call as if this package did. + * @param callingFeatureId Make a call as if this feature in the package did. + * @param intent Intent to start. + * @param userId Start the intents on this user. + * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. + * @param originatingPendingIntent PendingIntentRecord that originated this activity start or + * null if not originated by PendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. + */ public abstract int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, - String callingPackage, @Nullable String callingFeaturId, Intent intent, + String callingPackage, @Nullable String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges); + BackgroundStartPrivileges forcedBalByPiSender); /** * Callback to be called on certain activity start scenarios. diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index f462efc00ce6..a76fe287f313 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -5911,12 +5911,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { assertPackageMatchesCallingUid(callingPackage); return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, resultTo, options, userId, validateIncomingUser, originatingPendingIntent, - backgroundStartPrivileges); + forcedBalByPiSender); } @Override @@ -5925,13 +5925,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges) { + BackgroundStartPrivileges forcedBalByPiSender) { assertPackageMatchesCallingUid(callingPackage); return getActivityStartController().startActivityInPackage(uid, realCallingPid, realCallingUid, callingPackage, callingFeatureId, intent, resolvedType, resultTo, resultWho, requestCode, startFlags, options, userId, inTask, reason, validateIncomingUser, originatingPendingIntent, - backgroundStartPrivileges); + forcedBalByPiSender); } @Override diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java index 2f9ef50297bf..1b5631f59a3e 100644 --- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java +++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java @@ -195,6 +195,10 @@ public class BackgroundActivityStartController { return activity != null && packageName.equals(activity.getPackageName()); } + /** + * @see #checkBackgroundActivityStart(int, int, String, int, int, WindowProcessController, + * PendingIntentRecord, BackgroundStartPrivileges, Intent, ActivityOptions) + */ boolean shouldAbortBackgroundActivityStart( int callingUid, int callingPid, @@ -203,13 +207,13 @@ public class BackgroundActivityStartController { int realCallingPid, WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges, + BackgroundStartPrivileges forcedBalByPiSender, Intent intent, ActivityOptions checkedOptions) { return checkBackgroundActivityStart(callingUid, callingPid, callingPackage, realCallingUid, realCallingPid, callerApp, originatingPendingIntent, - backgroundStartPrivileges, intent, checkedOptions).blocks(); + forcedBalByPiSender, intent, checkedOptions).blocks(); } private class BalState { @@ -230,7 +234,7 @@ public class BackgroundActivityStartController { private final @ActivityManager.ProcessState int mRealCallingUidProcState; private final boolean mIsRealCallingUidPersistentSystemProcess; private final PendingIntentRecord mOriginatingPendingIntent; - private final BackgroundStartPrivileges mBackgroundStartPrivileges; + private final BackgroundStartPrivileges mForcedBalByPiSender; private final Intent mIntent; private final WindowProcessController mCallerApp; private final WindowProcessController mRealCallerApp; @@ -239,7 +243,7 @@ public class BackgroundActivityStartController { int realCallingUid, int realCallingPid, WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges, + BackgroundStartPrivileges forcedBalByPiSender, Intent intent, ActivityOptions checkedOptions) { this.mCallingPackage = callingPackage; @@ -248,7 +252,7 @@ public class BackgroundActivityStartController { mRealCallingUid = realCallingUid; mRealCallingPid = realCallingPid; mCallerApp = callerApp; - mBackgroundStartPrivileges = backgroundStartPrivileges; + mForcedBalByPiSender = forcedBalByPiSender; mOriginatingPendingIntent = originatingPendingIntent; mIntent = intent; mRealCallingPackage = mService.getPackageNameIfUnique(realCallingUid, realCallingPid); @@ -344,7 +348,7 @@ public class BackgroundActivityStartController { .append(mIsRealCallingUidPersistentSystemProcess); sb.append("; originatingPendingIntent: ").append(mOriginatingPendingIntent); } - sb.append("; backgroundStartPrivileges: ").append(mBackgroundStartPrivileges); + sb.append("; mForcedBalByPiSender: ").append(mForcedBalByPiSender); sb.append("; intent: ").append(mIntent); sb.append("; callerApp: ").append(mCallerApp); if (isPendingIntent()) { @@ -422,8 +426,26 @@ public class BackgroundActivityStartController { } /** - * @return A code denoting which BAL rule allows an activity to be started, - * or {@link #BAL_BLOCK} if the launch should be blocked + * Check if a (background) activity start is allowed. + * + * @param callingUid The UID that wants to start the activity. + * @param callingPid The PID that wants to start the activity. + * @param callingPackage The package name that wants to start the activity. + * @param realCallingUid The UID that actually calls this method (only if this handles a + * PendingIntent, otherwise -1) + * @param realCallingPid The PID that actually calls this method (only if this handles a + * * PendingIntent, otherwise -1) + * @param callerApp The process that calls this method (only if not a PendingIntent) + * @param originatingPendingIntent PendingIntentRecord that originated this activity start or + * null if not originated by PendingIntent + * @param forcedBalByPiSender If set to allow, the + * PendingIntent's sender will try to force allow background activity starts. + * This is only possible if the sender of the PendingIntent is a system process. + * @param intent Intent that should be started. + * @param checkedOptions ActivityOptions to allow specific opt-ins/opt outs. + * + * @return A verdict denoting which BAL rule allows an activity to be started, + * or if the launch should be blocked. */ BalVerdict checkBackgroundActivityStart( int callingUid, @@ -433,7 +455,7 @@ public class BackgroundActivityStartController { int realCallingPid, WindowProcessController callerApp, PendingIntentRecord originatingPendingIntent, - BackgroundStartPrivileges backgroundStartPrivileges, + BackgroundStartPrivileges forcedBalByPiSender, Intent intent, ActivityOptions checkedOptions) { @@ -444,7 +466,7 @@ public class BackgroundActivityStartController { BalState state = new BalState(callingUid, callingPid, callingPackage, realCallingUid, realCallingPid, callerApp, originatingPendingIntent, - backgroundStartPrivileges, intent, checkedOptions); + forcedBalByPiSender, intent, checkedOptions); // In the case of an SDK sandbox calling uid, check if the corresponding app uid has a // visible window. @@ -708,12 +730,12 @@ public class BackgroundActivityStartController { } // if the realCallingUid is a persistent system process, abort if the IntentSender // wasn't allowed to start an activity - if (state.mIsRealCallingUidPersistentSystemProcess - && state.mBackgroundStartPrivileges.allowsBackgroundActivityStarts()) { + if (state.mForcedBalByPiSender.allowsBackgroundActivityStarts() + && state.mIsRealCallingUidPersistentSystemProcess) { return new BalVerdict(BAL_ALLOW_PENDING_INTENT, /*background*/ false, "realCallingUid is persistent system process AND intent " - + "sender allowed (allowBackgroundActivityStart = true)."); + + "sender forced to allow."); } // don't abort if the realCallingUid is an associated companion app if (mService.isAssociatedCompanionApp( |