diff options
| author | Andreas Gampe <agampe@google.com> | 2018-05-24 17:47:57 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2018-05-24 17:47:57 -0700 |
| commit | 97def7a097498161eb3a14d5a96bac0de7d67644 (patch) | |
| tree | 4cb70c5edb54eb04d55ded2f2d03da9d583d4475 /core/java/android | |
| parent | 075bd6214b61a2de37d65d08198edfa4941effbb (diff) | |
| parent | 4f11d5381e82f4c6b181689e42c87edf22809a82 (diff) | |
Merge "Framework: Add API to get zygote PID" am: 1109e2333f am: 07578c786a
am: 4f11d5381e
Change-Id: I827a7df417597f17f78276052c5b17e064ebec7d
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/ZygoteProcess.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index 6994033a963a..021e72f7a082 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/android/os/ZygoteProcess.java @@ -467,6 +467,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). * * <p>The list of exemptions will take affect for all new processes forked from the zygote after |
