summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martijn Coenen <maco@google.com> 2022-02-03 15:43:32 +0100
committer Martijn Coenen <maco@google.com> 2022-02-09 18:06:03 +0100
commitccfec2282243e041d8f576648edceb28cc2b1dbc (patch)
tree857ef6a62d4d49aea755d624b5baac6558f46237
parent10aa9fd06f491c3d3dbeabfd5040b08cf9f0767c (diff)
Start supplemental processes in new UID range.
When we start a supplemental process on behalf of an app, we want to start it in its designated UID range. To do that, modify ServiceRecord to keep track of which app we started the supplemental process for; then, modify the various startProcess calls to recognize supplemental processes and assign the correct UID. Bug: 215012578 Test: atest SupplementalProcessTests Change-Id: I6338666eaeb39f8775f38878e1db4221c1a0def0
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java27
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java31
-rw-r--r--services/core/java/com/android/server/am/ProcessList.java10
-rw-r--r--services/core/java/com/android/server/am/ServiceRecord.java8
4 files changed, 57 insertions, 19 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index dc64d800c8c0..092172a15861 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -2721,8 +2721,8 @@ public final class ActiveServices {
int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service,
String resolvedType, final IServiceConnection connection, int flags,
- String instanceName, boolean isSupplementalProcessService, String callingPackage,
- final int userId)
+ String instanceName, boolean isSupplementalProcessService, int supplementedAppUid,
+ String callingPackage, final int userId)
throws TransactionTooLargeException {
if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "bindService: " + service
+ " type=" + resolvedType + " conn=" + connection.asBinder()
@@ -2807,8 +2807,8 @@ public final class ActiveServices {
final boolean allowInstant = (flags & Context.BIND_ALLOW_INSTANT) != 0;
ServiceLookupResult res = retrieveServiceLocked(service, instanceName,
- isSupplementalProcessService, resolvedType, callingPackage, callingPid, callingUid,
- userId, true, callerFg, isBindExternal, allowInstant);
+ isSupplementalProcessService, supplementedAppUid, resolvedType, callingPackage,
+ callingPid, callingUid, userId, true, callerFg, isBindExternal, allowInstant);
if (res == null) {
return 0;
}
@@ -3228,13 +3228,14 @@ public final class ActiveServices {
int callingPid, int callingUid, int userId,
boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal,
boolean allowInstant) {
- return retrieveServiceLocked(service, instanceName, false, resolvedType, callingPackage,
+ return retrieveServiceLocked(service, instanceName, false, 0, resolvedType, callingPackage,
callingPid, callingUid, userId, createIfNeeded, callingFromFg, isBindExternal,
allowInstant);
}
private ServiceLookupResult retrieveServiceLocked(Intent service,
- String instanceName, boolean isSupplementalProcessService, String resolvedType,
+ String instanceName, boolean isSupplementalProcessService, int supplementedAppUid,
+ String resolvedType,
String callingPackage, int callingPid, int callingUid, int userId,
boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal,
boolean allowInstant) {
@@ -3415,7 +3416,7 @@ public final class ActiveServices {
: null;
r = new ServiceRecord(mAm, className, name, definingPackageName,
definingUid, filter, sInfo, callingFromFg, res,
- supplementalProcessName);
+ supplementalProcessName, supplementedAppUid);
res.setService(r);
smap.mServicesByInstanceName.put(name, r);
smap.mServicesByIntent.put(filter, r);
@@ -4189,8 +4190,16 @@ public final class ActiveServices {
if (app == null && !permissionsReviewRequired && !packageFrozen) {
// TODO (chriswailes): Change the Zygote policy flags based on if the launch-for-service
// was initiated from a notification tap or not.
- if ((app = mAm.startProcessLocked(procName, r.appInfo, true, intentFlags,
- hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, false, isolated)) == null) {
+ if (r.supplemental) {
+ final int uid = Process.toSupplementalUid(r.supplementedAppUid);
+ app = mAm.startSupplementalProcessLocked(procName, r.appInfo, true, intentFlags,
+ hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, uid);
+ r.isolationHostProc = app;
+ } else {
+ app = mAm.startProcessLocked(procName, r.appInfo, true, intentFlags,
+ hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, false, isolated);
+ }
+ if (app == null) {
String msg = "Unable to launch app "
+ r.appInfo.packageName + "/"
+ r.appInfo.uid + " for service "
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 54f462aa8ae0..a478c3115139 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1892,6 +1892,8 @@ public class ActivityManagerService extends IActivityManager.Stub
ProcessRecord app = mProcessList.newProcessRecordLocked(info, info.processName,
false,
0,
+ false,
+ 0,
new HostingRecord("system"));
app.setPersistent(true);
app.setPid(MY_PID);
@@ -2780,18 +2782,32 @@ public class ActivityManagerService extends IActivityManager.Stub
false /* knownToBeDead */, 0 /* intentFlags */,
sNullHostingRecord /* hostingRecord */, ZYGOTE_POLICY_FLAG_EMPTY,
true /* allowWhileBooting */, true /* isolated */,
- uid, abiOverride, entryPoint, entryPointArgs, crashHandler);
+ uid, false /* supplemental */, 0 /* supplementalUid */,
+ abiOverride, entryPoint, entryPointArgs, crashHandler);
return proc != null;
}
}
@GuardedBy("this")
+ final ProcessRecord startSupplementalProcessLocked(String processName,
+ ApplicationInfo info, boolean knownToBeDead, int intentFlags,
+ HostingRecord hostingRecord, int zygotePolicyFlags, int supplementalUid) {
+ return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
+ hostingRecord, zygotePolicyFlags, false /* allowWhileBooting */,
+ false /* isolated */, 0 /* isolatedUid */,
+ true /* supplemental */, supplementalUid,
+ null /* ABI override */, null /* entryPoint */,
+ null /* entryPointArgs */, null /* crashHandler */);
+ }
+
+ @GuardedBy("this")
final ProcessRecord startProcessLocked(String processName,
ApplicationInfo info, boolean knownToBeDead, int intentFlags,
HostingRecord hostingRecord, int zygotePolicyFlags, boolean allowWhileBooting,
boolean isolated) {
return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
hostingRecord, zygotePolicyFlags, allowWhileBooting, isolated, 0 /* isolatedUid */,
+ false /* supplemental */, 0 /* supplementalUid */,
null /* ABI override */, null /* entryPoint */,
null /* entryPointArgs */, null /* crashHandler */);
}
@@ -6521,6 +6537,7 @@ public class ActivityManagerService extends IActivityManager.Stub
if (app == null) {
app = mProcessList.newProcessRecordLocked(info, customProcess, isolated, 0,
+ false, 0,
new HostingRecord("added application",
customProcess != null ? customProcess : info.processName));
updateLruProcessLocked(app, false, null);
@@ -12346,12 +12363,13 @@ public class ActivityManagerService extends IActivityManager.Stub
String resolvedType, IServiceConnection connection, int flags, String instanceName,
String callingPackage, int userId) throws TransactionTooLargeException {
return bindServiceInstance(caller, token, service, resolvedType, connection, flags,
- instanceName, false, callingPackage, userId);
+ instanceName, false, 0, callingPackage, userId);
}
private int bindServiceInstance(IApplicationThread caller, IBinder token, Intent service,
String resolvedType, IServiceConnection connection, int flags, String instanceName,
- boolean isSupplementalProcessService, String callingPackage, int userId)
+ boolean isSupplementalProcessService, int supplementedAppUid, String callingPackage,
+ int userId)
throws TransactionTooLargeException {
enforceNotIsolatedCaller("bindService");
@@ -12382,7 +12400,8 @@ public class ActivityManagerService extends IActivityManager.Stub
synchronized(this) {
return mServices.bindServiceLocked(caller, token, service, resolvedType, connection,
- flags, instanceName, isSupplementalProcessService, callingPackage, userId);
+ flags, instanceName, isSupplementalProcessService, supplementedAppUid,
+ callingPackage, userId);
}
}
@@ -15976,8 +15995,8 @@ public class ActivityManagerService extends IActivityManager.Stub
return ActivityManagerService.this.bindServiceInstance(
mContext.getIApplicationThread(), mContext.getActivityToken(), service,
service.resolveTypeIfNeeded(mContext.getContentResolver()), sd, flags,
- processName, /*isSupplementalProcessService*/ true, mContext.getOpPackageName(),
- UserHandle.getUserId(userAppUid)) != 0;
+ processName, /*isSupplementalProcessService*/ true, userAppUid,
+ mContext.getOpPackageName(), UserHandle.getUserId(userAppUid)) != 0;
}
@Override
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 1ad0bcea711c..4539cc8e05a2 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -2525,6 +2525,7 @@ public final class ProcessList {
ProcessRecord startProcessLocked(String processName, ApplicationInfo info,
boolean knownToBeDead, int intentFlags, HostingRecord hostingRecord,
int zygotePolicyFlags, boolean allowWhileBooting, boolean isolated, int isolatedUid,
+ boolean supplemental, int supplementalUid,
String abiOverride, String entryPoint, String[] entryPointArgs, Runnable crashHandler) {
long startTime = SystemClock.uptimeMillis();
ProcessRecord app;
@@ -2618,7 +2619,8 @@ public final class ProcessList {
if (app == null) {
checkSlow(startTime, "startProcess: creating new process record");
- app = newProcessRecordLocked(info, processName, isolated, isolatedUid, hostingRecord);
+ app = newProcessRecordLocked(info, processName, isolated, isolatedUid, supplemental,
+ supplementalUid, hostingRecord);
if (app == null) {
Slog.w(TAG, "Failed making new process record for "
+ processName + "/" + info.uid + " isolated=" + isolated);
@@ -3113,10 +3115,14 @@ public final class ProcessList {
@GuardedBy("mService")
ProcessRecord newProcessRecordLocked(ApplicationInfo info, String customProcess,
- boolean isolated, int isolatedUid, HostingRecord hostingRecord) {
+ boolean isolated, int isolatedUid, boolean supplemental, int supplementalUid,
+ HostingRecord hostingRecord) {
String proc = customProcess != null ? customProcess : info.processName;
final int userId = UserHandle.getUserId(info.uid);
int uid = info.uid;
+ if (supplemental) {
+ uid = supplementalUid;
+ }
if (isolated) {
if (isolatedUid == 0) {
IsolatedUidRange uidRange = getOrCreateIsolatedUidRangeLocked(info, hostingRecord);
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index d3b57529834a..711c57669fd6 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -94,6 +94,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
final boolean exported; // from ServiceInfo.exported
final Runnable restarter; // used to schedule retries of starting the service
final long createRealTime; // when this service was created
+ final boolean supplemental; // whether this is a supplemental service
+ final int supplementedAppUid; // the app uid for which this supplemental service is running
final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
= new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
// All active bindings to the service.
@@ -571,13 +573,13 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
Runnable restarter) {
this(ams, name, instanceName, definingPackageName, definingUid, intent, sInfo, callerIsFg,
- restarter, null);
+ restarter, null, 0);
}
ServiceRecord(ActivityManagerService ams, ComponentName name,
ComponentName instanceName, String definingPackageName, int definingUid,
Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
- Runnable restarter, String supplementalProcessName) {
+ Runnable restarter, String supplementalProcessName, int supplementedAppUid) {
this.ams = ams;
this.name = name;
this.instanceName = instanceName;
@@ -588,6 +590,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
serviceInfo = sInfo;
appInfo = sInfo.applicationInfo;
packageName = sInfo.applicationInfo.packageName;
+ supplemental = supplementalProcessName != null;
+ this.supplementedAppUid = supplementedAppUid;
if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
processName = sInfo.processName + ":" + instanceName.getClassName();
} else if (supplementalProcessName != null) {