summaryrefslogtreecommitdiff
path: root/core/java/android/util/StatsLog.java
diff options
context:
space:
mode:
authorMuhammad Qureshi <muhammadq@google.com>2019-11-06 15:26:08 -0800
committerMuhammad Qureshi <muhammadq@google.com>2019-12-02 23:25:47 -0800
commitf11130cfa0486a54c6f30f98bfd0d093de48f4eb (patch)
treee53fd151b7a6735471385683660a1d7a8b813b8f /core/java/android/util/StatsLog.java
parent15c81edf433484fdb99ee0bd1369dafd30d33259 (diff)
Add JNI call for writing StatsEvent to statsd.
Bug: 143978873 Test: m -j Test: flashes successfully Test: DocumentsUI(a Mainline module) is able to successfully log to statsd Change-Id: I9cdc6151d8feb29a712532e50f143af9d52c8d94
Diffstat (limited to 'core/java/android/util/StatsLog.java')
-rw-r--r--core/java/android/util/StatsLog.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/core/java/android/util/StatsLog.java b/core/java/android/util/StatsLog.java
index f7077bb2a418..64e15cfb7948 100644
--- a/core/java/android/util/StatsLog.java
+++ b/core/java/android/util/StatsLog.java
@@ -224,12 +224,35 @@ public final class StatsLog extends StatsLogInternal {
/**
* Write an event to stats log using the raw format.
*
- * @param buffer The encoded buffer of data to write..
+ * @param buffer The encoded buffer of data to write.
* @param size The number of bytes from the buffer to write.
* @hide
*/
+ // TODO(b/144935988): Mark deprecated.
@SystemApi
- public static native void writeRaw(@NonNull byte[] buffer, int size);
+ public static void writeRaw(@NonNull byte[] buffer, int size) {
+ // TODO(b/144935988): make this no-op once clients have migrated to StatsEvent.
+ writeImpl(buffer, size, 0);
+ }
+
+ /**
+ * Write an event to stats log using the raw format.
+ *
+ * @param buffer The encoded buffer of data to write.
+ * @param size The number of bytes from the buffer to write.
+ * @param atomId The id of the atom to which the event belongs.
+ */
+ private static native void writeImpl(@NonNull byte[] buffer, int size, int atomId);
+
+ /**
+ * Write an event to stats log using the raw format encapsulated in StatsEvent.
+ *
+ * @param statsEvent The StatsEvent object containing the encoded buffer of data to write.
+ * @hide
+ */
+ public static void write(@NonNull final StatsEvent statsEvent) {
+ writeImpl(statsEvent.getBytes(), statsEvent.getNumBytes(), statsEvent.getAtomId());
+ }
private static void enforceDumpCallingPermission(Context context) {
context.enforceCallingPermission(android.Manifest.permission.DUMP, "Need DUMP permission.");