diff options
Diffstat (limited to 'android/os/ZygoteProcess.java')
-rw-r--r-- | android/os/ZygoteProcess.java | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/android/os/ZygoteProcess.java b/android/os/ZygoteProcess.java index b9dd376f..673da507 100644 --- a/android/os/ZygoteProcess.java +++ b/android/os/ZygoteProcess.java @@ -166,6 +166,11 @@ public class ZygoteProcess { private List<String> mApiBlacklistExemptions = Collections.emptyList(); /** + * Proportion of hidden API accesses that should be logged to the event log; 0 - 0x10000. + */ + private int mHiddenApiAccessLogSampleRate; + + /** * The state of the connection to the primary zygote. */ private ZygoteState primaryZygoteState; @@ -467,7 +472,8 @@ public class ZygoteProcess { * <p>The list of exemptions will take affect for all new processes forked from the zygote after * this call. * - * @param exemptions List of hidden API exemption prefixes. + * @param exemptions List of hidden API exemption prefixes. Any matching members are treated as + * whitelisted/public APIs (i.e. allowed, no logging of usage). */ public void setApiBlacklistExemptions(List<String> exemptions) { synchronized (mLock) { @@ -477,6 +483,21 @@ public class ZygoteProcess { } } + /** + * Set the precentage of detected hidden API accesses that are logged to the event log. + * + * <p>This rate will take affect for all new processes forked from the zygote after this call. + * + * @param rate An integer between 0 and 0x10000 inclusive. 0 means no event logging. + */ + public void setHiddenApiAccessLogSampleRate(int rate) { + synchronized (mLock) { + mHiddenApiAccessLogSampleRate = rate; + maybeSetHiddenApiAccessLogSampleRate(primaryZygoteState); + maybeSetHiddenApiAccessLogSampleRate(secondaryZygoteState); + } + } + @GuardedBy("mLock") private void maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIfEmpty) { if (state == null || state.isClosed()) { @@ -504,6 +525,29 @@ public class ZygoteProcess { } } + private void maybeSetHiddenApiAccessLogSampleRate(ZygoteState state) { + if (state == null || state.isClosed()) { + return; + } + if (mHiddenApiAccessLogSampleRate == -1) { + return; + } + try { + state.writer.write(Integer.toString(1)); + state.writer.newLine(); + state.writer.write("--hidden-api-log-sampling-rate=" + + Integer.toString(mHiddenApiAccessLogSampleRate)); + state.writer.newLine(); + state.writer.flush(); + int status = state.inputStream.readInt(); + if (status != 0) { + Slog.e(LOG_TAG, "Failed to set hidden API log sampling rate; status " + status); + } + } catch (IOException ioe) { + Slog.e(LOG_TAG, "Failed to set hidden API log sampling rate", ioe); + } + } + /** * Tries to open socket to Zygote process if not already open. If * already open, does nothing. May block and retry. Requires that mLock be held. @@ -519,6 +563,7 @@ public class ZygoteProcess { throw new ZygoteStartFailedEx("Error connecting to primary zygote", ioe); } maybeSetApiBlacklistExemptions(primaryZygoteState, false); + maybeSetHiddenApiAccessLogSampleRate(primaryZygoteState); } if (primaryZygoteState.matches(abi)) { return primaryZygoteState; @@ -532,6 +577,7 @@ public class ZygoteProcess { throw new ZygoteStartFailedEx("Error connecting to secondary zygote", ioe); } maybeSetApiBlacklistExemptions(secondaryZygoteState, false); + maybeSetHiddenApiAccessLogSampleRate(secondaryZygoteState); } if (secondaryZygoteState.matches(abi)) { |