diff options
| author | Mathew Inwood <mathewi@google.com> | 2018-04-04 14:48:03 +0100 |
|---|---|---|
| committer | Mathew Inwood <mathewi@google.com> | 2018-04-10 16:57:07 +0100 |
| commit | 04194fef78ecd75ea09cb9c75c211f5170e6f91d (patch) | |
| tree | 8691616153963ae822ecf84d4c85dfc847738744 /core/java/android | |
| parent | 2bb1d2644212c4abd4f0200dd5118ab463af6ae0 (diff) | |
Configurable sampling rate for hidden API access log events.
To reduce log spam, we do not log all hidden API accesses. This CL allows
configuration of the sampling rate of the log events so it can be tweaked
later if necessary.
Test: m
Test: $ adb shell settings put global hidden_api_access_log_sampling_rate 65536
Bug: 64382372
Bug: 77517571
Change-Id: I659c22bd504564da58d972f94b774a9af4039386
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/ZygoteProcess.java | 45 | ||||
| -rw-r--r-- | core/java/android/provider/Settings.java | 9 |
2 files changed, 54 insertions, 0 deletions
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index d1d5d8e460e8..673da507788f 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/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; @@ -478,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()) { @@ -505,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. @@ -520,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; @@ -533,6 +577,7 @@ public class ZygoteProcess { throw new ZygoteStartFailedEx("Error connecting to secondary zygote", ioe); } maybeSetApiBlacklistExemptions(secondaryZygoteState, false); + maybeSetHiddenApiAccessLogSampleRate(secondaryZygoteState); } if (secondaryZygoteState.matches(abi)) { diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 60bbb10de014..cbc1e3b9f8bd 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -11749,6 +11749,15 @@ public final class Settings { "hidden_api_blacklist_exemptions"; /** + * Sampling rate for hidden API access event logs, as an integer in the range 0 to 0x10000 + * inclusive. + * + * @hide + */ + public static final String HIDDEN_API_ACCESS_LOG_SAMPLING_RATE = + "hidden_api_access_log_sampling_rate"; + + /** * Hidden API enforcement policy for apps targeting SDK versions prior to the latest * version. * |
