Add a new UID range for supplemental processes.

These are processes that are spawned alongside regular app processes.
They have their own UID range, such that they can be properly isolated
from applications.

Add some APIs in Process that allows the system and mainline
modules to verify that a particular UID belongs to a supplemental
process, and to map between the supplemental process and the
corresponding app process.

Bug: 215012578
Test: N/A
Change-Id: I02aaaa1c2bcf9d141ddc97747eb6d7edd52d7b92
This commit is contained in:
Martijn Coenen
2022-01-12 14:27:25 +01:00
committed by Nikita Ioffe
parent b46b145d77
commit 9c9045241a
3 changed files with 64 additions and 0 deletions

View File

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

View File

@@ -376,6 +376,9 @@ package android.os {
} }
public class Process { 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 NFC_UID = 1027; // 0x403
field public static final int VPN_UID = 1016; // 0x3f8 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; 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 * First uid used for fully isolated sandboxed processes spawned from an app zygote
* @hide * @hide
@@ -880,6 +900,46 @@ public class Process {
|| (uid >= FIRST_APP_ZYGOTE_ISOLATED_UID && uid <= LAST_APP_ZYGOTE_ISOLATED_UID); || (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 * 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 * none. If the given string consists of only numbers, it is converted