Merge changes I39c351f1,Ida90829a,I02aaaa1c

* changes:
  Make ProcessRecord.isolated more robust.
  Rename ServiceRecord.isolatedProc to isolationHostProc.
  Add a new UID range for supplemental processes.
This commit is contained in:
Martijn Coenen
2022-01-21 13:49:54 +00:00
committed by Android (Google) Code Review
7 changed files with 80 additions and 15 deletions

View File

@@ -32516,6 +32516,7 @@ package android.os {
method public static final boolean is64Bit();
method public static boolean isApplicationUid(int);
method public static final boolean isIsolated();
method public static final boolean isSupplemental();
method public static final void killProcess(int);
method public static final int myPid();
method @NonNull public static String myProcessName();

View File

@@ -389,6 +389,9 @@ package android.os {
}
public class Process {
method public static final boolean isSupplemental(int);
method public static final int toAppUid(int);
method public static final int toSupplementalUid(int);
field public static final int NFC_UID = 1027; // 0x403
field public static final int VPN_UID = 1016; // 0x3f8
}

View File

@@ -279,6 +279,26 @@ public class Process {
*/
public static final int LAST_APPLICATION_UID = 19999;
/**
* Defines the start of a range of UIDs going from this number to
* {@link #LAST_SUPPLEMENTAL_UID} that are reserved for assigning to
* supplemental processes. There is a 1-1 mapping between a supplemental
* process UID and the app that it belongs to, which can be computed by
* subtracting (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID) from the
* uid of a supplemental process.
*
* Note that there are no GIDs associated with these processes; storage
* attribution for them will be done using project IDs.
* @hide
*/
public static final int FIRST_SUPPLEMENTAL_UID = 20000;
/**
* Last UID that is used for supplemental processes.
* @hide
*/
public static final int LAST_SUPPLEMENTAL_UID = 29999;
/**
* First uid used for fully isolated sandboxed processes spawned from an app zygote
* @hide
@@ -880,6 +900,46 @@ public class Process {
|| (uid >= FIRST_APP_ZYGOTE_ISOLATED_UID && uid <= LAST_APP_ZYGOTE_ISOLATED_UID);
}
/**
* Returns whether the provided UID belongs to a supplemental process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
public static final boolean isSupplemental(int uid) {
uid = UserHandle.getAppId(uid);
return (uid >= FIRST_SUPPLEMENTAL_UID && uid <= LAST_SUPPLEMENTAL_UID);
}
/**
*
* Returns the app process corresponding to a supplemental process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
public static final int toAppUid(int uid) {
return uid - (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID);
}
/**
*
* Returns the supplemental process corresponding to an app process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
public static final int toSupplementalUid(int uid) {
return uid + (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID);
}
/**
* Returns whether the current process is a supplemental process.
*/
public static final boolean isSupplemental() {
return isSupplemental(myUid());
}
/**
* Returns the UID assigned to a particular user name, or -1 if there is
* none. If the given string consists of only numbers, it is converted

View File

@@ -4138,7 +4138,7 @@ public final class ActiveServices {
// for a previous process to come up. To deal with this, we store
// in the service any current isolated process it is running in or
// waiting to have come up.
app = r.isolatedProc;
app = r.isolationHostProc;
if (WebViewZygote.isMultiprocessEnabled()
&& r.serviceInfo.packageName.equals(WebViewZygote.getPackageName())) {
hostingRecord = HostingRecord.byWebviewZygote(r.instanceName);
@@ -4165,7 +4165,7 @@ public final class ActiveServices {
return msg;
}
if (isolated) {
r.isolatedProc = app;
r.isolationHostProc = app;
}
}
@@ -4976,7 +4976,7 @@ public final class ActiveServices {
try {
for (int i=0; i<mPendingServices.size(); i++) {
sr = mPendingServices.get(i);
if (proc != sr.isolatedProc && (proc.uid != sr.appInfo.uid
if (proc != sr.isolationHostProc && (proc.uid != sr.appInfo.uid
|| !processName.equals(sr.processName))) {
continue;
}
@@ -5016,7 +5016,7 @@ public final class ActiveServices {
boolean didImmediateRestart = false;
for (int i=0; i<mRestartingServices.size(); i++) {
sr = mRestartingServices.get(i);
if (proc != sr.isolatedProc && (proc.uid != sr.appInfo.uid
if (proc != sr.isolationHostProc && (proc.uid != sr.appInfo.uid
|| !processName.equals(sr.processName))) {
continue;
}
@@ -5048,9 +5048,9 @@ public final class ActiveServices {
ServiceRecord sr = mPendingServices.get(i);
if ((proc.uid == sr.appInfo.uid
&& proc.processName.equals(sr.processName))
|| sr.isolatedProc == proc) {
|| sr.isolationHostProc == proc) {
Slog.w(TAG, "Forcing bringing down service: " + sr);
sr.isolatedProc = null;
sr.isolationHostProc = null;
mPendingServices.remove(i);
size = mPendingServices.size();
i--;
@@ -5083,7 +5083,7 @@ public final class ActiveServices {
stopServiceAndUpdateAllowlistManagerLocked(service);
}
service.setProcess(null, null, 0, null);
service.isolatedProc = null;
service.isolationHostProc = null;
if (mTmpCollectionResults == null) {
mTmpCollectionResults = new ArrayList<>();
}
@@ -5321,7 +5321,7 @@ public final class ActiveServices {
sr.app.mServices.updateBoundClientUids();
}
sr.setProcess(null, null, 0, null);
sr.isolatedProc = null;
sr.isolationHostProc = null;
sr.executeNesting = 0;
synchronized (mAm.mProcessStats.mLock) {
sr.forceClearTracker();

View File

@@ -598,7 +598,7 @@ public class OomAdjuster {
for (int i = psr.numberOfConnections() - 1; i >= 0; i--) {
ConnectionRecord cr = psr.getConnectionAt(i);
ProcessRecord service = (cr.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0
? cr.binding.service.isolatedProc : cr.binding.service.app;
? cr.binding.service.isolationHostProc : cr.binding.service.app;
if (service == null || service == pr) {
continue;
}

View File

@@ -513,7 +513,7 @@ class ProcessRecord implements WindowProcessListener {
}
}
processInfo = procInfo;
isolated = _info.uid != _uid;
isolated = Process.isIsolated(_uid);
appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
&& UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
uid = _uid;

View File

@@ -102,7 +102,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
// IBinder -> ConnectionRecord of all bound clients
ProcessRecord app; // where this service is running or null.
ProcessRecord isolatedProc; // keep track of isolated process, if requested
ProcessRecord isolationHostProc; // process which we've started for this service (used for
// isolated and supplemental processes)
ServiceState tracker; // tracking service execution, may be null
ServiceState restartTracker; // tracking service restart
boolean allowlistManager; // any bindings to this service have BIND_ALLOW_WHITELIST_MANAGEMENT?
@@ -352,8 +353,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
if (app != null) {
app.dumpDebug(proto, ServiceRecordProto.APP);
}
if (isolatedProc != null) {
isolatedProc.dumpDebug(proto, ServiceRecordProto.ISOLATED_PROC);
if (isolationHostProc != null) {
isolationHostProc.dumpDebug(proto, ServiceRecordProto.ISOLATED_PROC);
}
proto.write(ServiceRecordProto.WHITELIST_MANAGER, allowlistManager);
proto.write(ServiceRecordProto.DELAYED, delayed);
@@ -455,8 +456,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
pw.print(prefix); pw.print("dataDir="); pw.println(appInfo.dataDir);
}
pw.print(prefix); pw.print("app="); pw.println(app);
if (isolatedProc != null) {
pw.print(prefix); pw.print("isolatedProc="); pw.println(isolatedProc);
if (isolationHostProc != null) {
pw.print(prefix); pw.print("isolationHostProc="); pw.println(isolationHostProc);
}
if (allowlistManager) {
pw.print(prefix); pw.print("allowlistManager="); pw.println(allowlistManager);