Loading core/java/android/os/ZygoteProcess.java +29 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,35 @@ public class ZygoteProcess { } } /** * Attempt to retrieve the PID of the zygote serving the given abi. */ public int getZygotePid(String abi) { try { synchronized (mLock) { ZygoteState state = openZygoteSocketIfNeeded(abi); // Each query starts with the argument count (1 in this case) state.writer.write("1"); // ... followed by a new-line. state.writer.newLine(); // ... followed by our only argument. state.writer.write("--get-pid"); state.writer.newLine(); state.writer.flush(); // The response is a length prefixed stream of ASCII bytes. int numBytes = state.inputStream.readInt(); byte[] bytes = new byte[numBytes]; state.inputStream.readFully(bytes); return Integer.parseInt(new String(bytes, StandardCharsets.US_ASCII)); } } catch (Exception ex) { throw new RuntimeException("Failure retrieving pid", ex); } } /** * Push hidden API blacklisting exemptions into the zygote process(es). * Loading core/java/com/android/internal/os/ZygoteConnection.java +24 −1 Original line number Diff line number Diff line Loading @@ -150,6 +150,11 @@ class ZygoteConnection { return null; } if (parsedArgs.pidQuery) { handlePidQuery(); return null; } if (parsedArgs.preloadDefault) { handlePreload(); return null; Loading Loading @@ -266,6 +271,17 @@ class ZygoteConnection { } } private void handlePidQuery() { try { String pidString = String.valueOf(Process.myPid()); final byte[] pidStringBytes = pidString.getBytes(StandardCharsets.US_ASCII); mSocketOutStream.writeInt(pidStringBytes.length); mSocketOutStream.write(pidStringBytes); } catch (IOException ioe) { throw new IllegalStateException("Error writing to command socket", ioe); } } /** * Preloads resources if the zygote is in lazily preload mode. Writes the result of the * preload operation; {@code 0} when a preload was initiated due to this request and {@code 1} Loading Loading @@ -439,6 +455,11 @@ class ZygoteConnection { */ boolean startChildZygote; /** * Whether the current arguments constitute a request for the zygote's PID. */ boolean pidQuery; /** * Exemptions from API blacklisting. These are sent to the pre-forked zygote at boot time, * or when they change, via --set-api-blacklist-exemptions. Loading Loading @@ -586,6 +607,8 @@ class ZygoteConnection { mountExternal = Zygote.MOUNT_EXTERNAL_WRITE; } else if (arg.equals("--query-abi-list")) { abiListQuery = true; } else if (arg.equals("--get-pid")) { pidQuery = true; } else if (arg.startsWith("--instruction-set=")) { instructionSet = arg.substring(arg.indexOf('=') + 1); } else if (arg.startsWith("--app-data-dir=")) { Loading @@ -608,7 +631,7 @@ class ZygoteConnection { } } if (abiListQuery) { if (abiListQuery || pidQuery) { if (args.length - curArg > 0) { throw new IllegalArgumentException("Unexpected arguments after --query-abi-list."); } Loading Loading
core/java/android/os/ZygoteProcess.java +29 −0 Original line number Diff line number Diff line Loading @@ -461,6 +461,35 @@ public class ZygoteProcess { } } /** * Attempt to retrieve the PID of the zygote serving the given abi. */ public int getZygotePid(String abi) { try { synchronized (mLock) { ZygoteState state = openZygoteSocketIfNeeded(abi); // Each query starts with the argument count (1 in this case) state.writer.write("1"); // ... followed by a new-line. state.writer.newLine(); // ... followed by our only argument. state.writer.write("--get-pid"); state.writer.newLine(); state.writer.flush(); // The response is a length prefixed stream of ASCII bytes. int numBytes = state.inputStream.readInt(); byte[] bytes = new byte[numBytes]; state.inputStream.readFully(bytes); return Integer.parseInt(new String(bytes, StandardCharsets.US_ASCII)); } } catch (Exception ex) { throw new RuntimeException("Failure retrieving pid", ex); } } /** * Push hidden API blacklisting exemptions into the zygote process(es). * Loading
core/java/com/android/internal/os/ZygoteConnection.java +24 −1 Original line number Diff line number Diff line Loading @@ -150,6 +150,11 @@ class ZygoteConnection { return null; } if (parsedArgs.pidQuery) { handlePidQuery(); return null; } if (parsedArgs.preloadDefault) { handlePreload(); return null; Loading Loading @@ -266,6 +271,17 @@ class ZygoteConnection { } } private void handlePidQuery() { try { String pidString = String.valueOf(Process.myPid()); final byte[] pidStringBytes = pidString.getBytes(StandardCharsets.US_ASCII); mSocketOutStream.writeInt(pidStringBytes.length); mSocketOutStream.write(pidStringBytes); } catch (IOException ioe) { throw new IllegalStateException("Error writing to command socket", ioe); } } /** * Preloads resources if the zygote is in lazily preload mode. Writes the result of the * preload operation; {@code 0} when a preload was initiated due to this request and {@code 1} Loading Loading @@ -439,6 +455,11 @@ class ZygoteConnection { */ boolean startChildZygote; /** * Whether the current arguments constitute a request for the zygote's PID. */ boolean pidQuery; /** * Exemptions from API blacklisting. These are sent to the pre-forked zygote at boot time, * or when they change, via --set-api-blacklist-exemptions. Loading Loading @@ -586,6 +607,8 @@ class ZygoteConnection { mountExternal = Zygote.MOUNT_EXTERNAL_WRITE; } else if (arg.equals("--query-abi-list")) { abiListQuery = true; } else if (arg.equals("--get-pid")) { pidQuery = true; } else if (arg.startsWith("--instruction-set=")) { instructionSet = arg.substring(arg.indexOf('=') + 1); } else if (arg.startsWith("--app-data-dir=")) { Loading @@ -608,7 +631,7 @@ class ZygoteConnection { } } if (abiListQuery) { if (abiListQuery || pidQuery) { if (args.length - curArg > 0) { throw new IllegalArgumentException("Unexpected arguments after --query-abi-list."); } Loading