Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2283b707 authored by Martijn Coenen's avatar Martijn Coenen Committed by Android (Google) Code Review
Browse files

Merge changes I39c351f1,Ida90829a,I02aaaa1c

* changes:
  Make ProcessRecord.isolated more robust.
  Rename ServiceRecord.isolatedProc to isolationHostProc.
  Add a new UID range for supplemental processes.
parents e0b59d46 a42d1cf2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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();
+3 −0
Original line number Diff line number Diff line
@@ -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
  }
+60 −0
Original line number Diff line number Diff line
@@ -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
+8 −8
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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;
                }
Loading