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

Commit b19b3f1a authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Pass the packageName to zygote when starting a new process."

parents a81d7074 154fe3f6
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -492,10 +492,11 @@ public class Process {
                                  String instructionSet,
                                  String appDataDir,
                                  String invokeWith,
                                  String packageName,
                                  String[] zygoteArgs) {
        return zygoteProcess.start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
                    abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
    }

    /** @hide */
@@ -509,10 +510,11 @@ public class Process {
                                  String instructionSet,
                                  String appDataDir,
                                  String invokeWith,
                                  String packageName,
                                  String[] zygoteArgs) {
        return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
                    abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
    }

    /**
+8 −2
Original line number Diff line number Diff line
@@ -227,12 +227,13 @@ public class ZygoteProcess {
                                                  String instructionSet,
                                                  String appDataDir,
                                                  String invokeWith,
                                                  String packageName,
                                                  String[] zygoteArgs) {
        try {
            return startViaZygote(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, false /* startChildZygote */,
                    zygoteArgs);
                    packageName, zygoteArgs);
        } catch (ZygoteStartFailedEx ex) {
            Log.e(LOG_TAG,
                    "Starting VM process through Zygote failed");
@@ -366,6 +367,7 @@ public class ZygoteProcess {
                                                      String appDataDir,
                                                      String invokeWith,
                                                      boolean startChildZygote,
                                                      String packageName,
                                                      String[] extraArgs)
                                                      throws ZygoteStartFailedEx {
        ArrayList<String> argsForZygote = new ArrayList<String>();
@@ -426,6 +428,10 @@ public class ZygoteProcess {
            argsForZygote.add("--start-child-zygote");
        }

        if (packageName != null) {
            argsForZygote.add("--package-name=" + packageName);
        }

        argsForZygote.add(processClass);

        if (extraArgs != null) {
@@ -733,7 +739,7 @@ public class ZygoteProcess {
            result = startViaZygote(processClass, niceName, uid, gid,
                    gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
                    abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
                    true /* startChildZygote */, extraArgs);
                    true /* startChildZygote */, null /* packageName */, extraArgs);
        } catch (ZygoteStartFailedEx ex) {
            throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
        }
+5 −3
Original line number Diff line number Diff line
@@ -132,13 +132,14 @@ public final class Zygote {
     */
    public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
          int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
          int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir) {
          int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
          String packageName) {
        VM_HOOKS.preFork();
        // Resets nice priority for zygote process.
        resetNicePriority();
        int pid = nativeForkAndSpecialize(
                  uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                  fdsToIgnore, startChildZygote, instructionSet, appDataDir);
                  fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName);
        // Enable tracing as soon as possible for the child process.
        if (pid == 0) {
            Trace.setTracingEnabled(true, runtimeFlags);
@@ -152,7 +153,8 @@ public final class Zygote {

    native private static int nativeForkAndSpecialize(int uid, int gid, int[] gids,int runtimeFlags,
          int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
          int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir);
          int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
          String packageName);

    /**
     * Called to do any initialization before starting an application.
+6 −1
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ class ZygoteConnection {
        pid = Zygote.forkAndSpecialize(parsedArgs.uid, parsedArgs.gid, parsedArgs.gids,
                parsedArgs.runtimeFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
                parsedArgs.niceName, fdsToClose, fdsToIgnore, parsedArgs.startChildZygote,
                parsedArgs.instructionSet, parsedArgs.appDataDir);
                parsedArgs.instructionSet, parsedArgs.appDataDir, parsedArgs.packageName);

        try {
            if (pid == 0) {
@@ -426,6 +426,9 @@ class ZygoteConnection {
        /** from --invoke-with */
        String invokeWith;

        /** from --package-name */
        String packageName;

        /**
         * Any args after and including the first non-option arg
         * (or after a '--')
@@ -674,6 +677,8 @@ class ZygoteConnection {
                                "Invalid log sampling rate: " + rateStr, nfe);
                    }
                    expectRuntimeArgs = false;
                } else if (arg.startsWith("--package-name=")) {
                    packageName = arg.substring(arg.indexOf('=') + 1);
                } else {
                    break;
                }
+18 −7
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ static int UnmountTree(const char* path) {
// Create a private mount namespace and bind mount appropriate emulated
// storage for the given user.
static bool MountEmulatedStorage(uid_t uid, jint mount_mode,
        bool force_mount_namespace, std::string* error_msg) {
        bool force_mount_namespace, std::string* error_msg, const char* package_name) {
    // See storage config details at http://source.android.com/tech/storage/

    String8 storageSource;
@@ -544,7 +544,7 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGi
                             jlong permittedCapabilities, jlong effectiveCapabilities,
                             jint mount_external, jstring java_se_info, jstring java_se_name,
                             bool is_system_server, bool is_child_zygote, jstring instructionSet,
                             jstring dataDir) {
                             jstring dataDir, jstring packageName) {
  std::string error_msg;

  auto fail_fn = [env, java_se_name, is_system_server](const std::string& msg)
@@ -594,7 +594,18 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGi
    ALOGW("Native bridge will not be used because dataDir == NULL.");
  }

  if (!MountEmulatedStorage(uid, mount_external, use_native_bridge, &error_msg)) {
  ScopedUtfChars* package_name = nullptr;
  const char* package_name_c_str = nullptr;
  if (packageName != nullptr) {
    package_name = new ScopedUtfChars(env, packageName);
    package_name_c_str = package_name->c_str();
  } else if (is_system_server) {
    package_name_c_str = "android";
  }
  bool success = MountEmulatedStorage(uid, mount_external, use_native_bridge, &error_msg,
      package_name_c_str);
  delete package_name;
  if (!success) {
    ALOGW("Failed to mount emulated storage: %s (%s)", error_msg.c_str(), strerror(errno));
    if (errno == ENOTCONN || errno == EROFS) {
      // When device is actively encrypting, we get ENOTCONN here
@@ -858,7 +869,7 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
        jint runtime_flags, jobjectArray rlimits,
        jint mount_external, jstring se_info, jstring se_name,
        jintArray fdsToClose, jintArray fdsToIgnore, jboolean is_child_zygote,
        jstring instructionSet, jstring appDataDir) {
        jstring instructionSet, jstring appDataDir, jstring packageName) {
    jlong capabilities = 0;

    // Grant CAP_WAKE_ALARM to the Bluetooth process.
@@ -911,7 +922,7 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
      SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits,
                       capabilities, capabilities,
                       mount_external, se_info, se_name, false,
                       is_child_zygote == JNI_TRUE, instructionSet, appDataDir);
                       is_child_zygote == JNI_TRUE, instructionSet, appDataDir, packageName);
    }
    return pid;
}
@@ -925,7 +936,7 @@ static jint com_android_internal_os_Zygote_nativeForkSystemServer(
      SpecializeCommon(env, uid, gid, gids, runtime_flags, rlimits,
                       permittedCapabilities, effectiveCapabilities,
                       MOUNT_EXTERNAL_DEFAULT, NULL, NULL, true,
                       false, NULL, NULL);
                       false, NULL, NULL, nullptr);
  } else if (pid > 0) {
      // The zygote process checks whether the child process has died or not.
      ALOGI("System server process %d has been created", pid);
@@ -1006,7 +1017,7 @@ static const JNINativeMethod gMethods[] = {
    { "nativeSecurityInit", "()V",
      (void *) com_android_internal_os_Zygote_nativeSecurityInit },
    { "nativeForkAndSpecialize",
      "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I",
      "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
      (void *) com_android_internal_os_Zygote_nativeForkAndSpecialize },
    { "nativeForkSystemServer", "(II[II[[IJJ)I",
      (void *) com_android_internal_os_Zygote_nativeForkSystemServer },
Loading