summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTej Singh <singhtejinder@google.com>2019-11-18 16:19:05 -0800
committerTej Singh <singhtejinder@google.com>2019-11-19 11:55:28 -0800
commit14df99d96a20f2fa8ea39cc2251f4ce2ab4e9cf1 (patch)
tree111d74da29519a5286dc2f172c2e33d8e54e1cb2 /core/java
parente9513c5e3d0a9a2b88d701bb925a535e5cf60f44 (diff)
PullAtomMetadata for Registering Pullers
Create PullAtomMetadata for registering pullers. This will simplify the API design and allow users to not specify the metadata if they just want to use defaults. Test: builds, boots Change-Id: I6b84c02f535fc911d1dc66768413d27f342d9515
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/StatsManager.java107
1 files changed, 98 insertions, 9 deletions
diff --git a/core/java/android/app/StatsManager.java b/core/java/android/app/StatsManager.java
index 92bfee24d402..6ac0a40cfc5a 100644
--- a/core/java/android/app/StatsManager.java
+++ b/core/java/android/app/StatsManager.java
@@ -101,6 +101,9 @@ public final class StatsManager {
*/
public static final String ACTION_STATSD_STARTED = "android.app.action.STATSD_STARTED";
+ private static final long DEFAULT_COOL_DOWN_NS = 1_000_000_000L; // 1 second.
+ private static final long DEFAULT_TIMEOUT_NS = 10_000_000_000L; // 10 seconds.
+
/**
* Constructor for StatsManagerClient.
*
@@ -495,20 +498,23 @@ public final class StatsManager {
* pulled.
*
* @param atomTag The tag of the atom for this puller callback.
- * @param coolDownNs The minimum time between successive pulls. A cache of the previous
- * pull will be used if the time between pulls is less than coolDownNs.
- * @param timeoutNs The maximum time a pull should take. Statsd will wait timeoutNs for
- * the pull to complete before timing out and marking the pull as
- * failed.
- * @param additiveFields Fields that are added when mapping isolated uids to host uids.
+ * @param metadata Optional metadata specifying the timeout, cool down time, and
+ * additive fields for mapping isolated to host uids.
* @param callback The callback to be invoked when the stats service pulls the atom.
+ * @param executor The executor in which to run the callback
* @throws RemoteException if unsuccessful due to failing to connect to system server.
*
* @hide
*/
- public void registerPullAtomCallback(int atomTag, long coolDownNs, long timeoutNs,
- int[] additiveFields, @NonNull StatsPullAtomCallback callback,
- @NonNull Executor executor) throws RemoteException, SecurityException {
+ public void registerPullAtomCallback(int atomTag, @Nullable PullAtomMetadata metadata,
+ @NonNull StatsPullAtomCallback callback, @NonNull Executor executor)
+ throws RemoteException, SecurityException {
+ long coolDownNs = metadata == null ? DEFAULT_COOL_DOWN_NS : metadata.mCoolDownNs;
+ long timeoutNs = metadata == null ? DEFAULT_TIMEOUT_NS : metadata.mTimeoutNs;
+ int[] additiveFields = metadata == null ? new int[0] : metadata.mAdditiveFields;
+ if (additiveFields == null) {
+ additiveFields = new int[0];
+ }
synchronized (this) {
IStatsCompanionService service = getIStatsCompanionServiceLocked();
PullAtomCallbackInternal rec =
@@ -545,6 +551,89 @@ public final class StatsManager {
}
/**
+ * Metadata required for registering a StatsPullAtomCallback.
+ * All fields are optional, and defaults will be used for fields that are unspecified.
+ *
+ * @hide
+ */
+ public static class PullAtomMetadata {
+ private final long mCoolDownNs;
+ private final long mTimeoutNs;
+ private final int[] mAdditiveFields;
+
+ // Private Constructor for builder
+ private PullAtomMetadata(long coolDownNs, long timeoutNs, int[] additiveFields) {
+ mCoolDownNs = coolDownNs;
+ mTimeoutNs = timeoutNs;
+ mAdditiveFields = additiveFields;
+ }
+
+ /**
+ * Returns a new PullAtomMetadata.Builder object for constructing PullAtomMetadata for
+ * StatsManager#registerPullAtomCallback
+ */
+ public static PullAtomMetadata.Builder newBuilder() {
+ return new PullAtomMetadata.Builder();
+ }
+
+ /**
+ * Builder for PullAtomMetadata.
+ */
+ public static class Builder {
+ private long mCoolDownNs;
+ private long mTimeoutNs;
+ private int[] mAdditiveFields;
+
+ private Builder() {
+ mCoolDownNs = DEFAULT_COOL_DOWN_NS;
+ mTimeoutNs = DEFAULT_TIMEOUT_NS;
+ mAdditiveFields = null;
+ }
+
+ /**
+ * Set the cool down time of the pull in nanoseconds. If two successive pulls are issued
+ * within the cool down, a cached version of the first will be used for the second.
+ */
+ @NonNull
+ public Builder setCoolDownNs(long coolDownNs) {
+ mCoolDownNs = coolDownNs;
+ return this;
+ }
+
+ /**
+ * Set the maximum time the pull can take in nanoseconds.
+ */
+ @NonNull
+ public Builder setTimeoutNs(long timeoutNs) {
+ mTimeoutNs = timeoutNs;
+ return this;
+ }
+
+ /**
+ * Set the additive fields of this pulled atom.
+ *
+ * This is only applicable for atoms which have a uid field. When tasks are run in
+ * isolated processes, the data will be attributed to the host uid. Additive fields
+ * will be combined when the non-additive fields are the same.
+ */
+ @NonNull
+ public Builder setAdditiveFields(int[] additiveFields) {
+ mAdditiveFields = additiveFields;
+ return this;
+ }
+
+ /**
+ * Builds and returns a PullAtomMetadata object with the values set in the builder and
+ * defaults for unset fields.
+ */
+ @NonNull
+ public PullAtomMetadata build() {
+ return new PullAtomMetadata(mCoolDownNs, mTimeoutNs, mAdditiveFields);
+ }
+ }
+ }
+
+ /**
* Callback interface for pulling atoms requested by the stats service.
*
* @hide