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
This commit is contained in:
@@ -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.");
|
||||
|
||||
@@ -18,18 +18,17 @@
|
||||
#define LOG_TAG "StatsLog_println"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cutils/properties.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include "utils/misc.h"
|
||||
#include "core_jni_helpers.h"
|
||||
#include "stats_event_list.h"
|
||||
#include "stats_buffer_writer.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
static void android_util_StatsLog_writeRaw(JNIEnv* env, jobject clazz, jbyteArray buf, jint size)
|
||||
{
|
||||
static void android_util_StatsLog_write(JNIEnv* env, jobject clazz, jbyteArray buf, jint size,
|
||||
jint atomId) {
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -42,13 +41,8 @@ static void android_util_StatsLog_writeRaw(JNIEnv* env, jobject clazz, jbyteArra
|
||||
if (bufferArray == NULL) {
|
||||
return;
|
||||
}
|
||||
const uint32_t statsEventTag = 1937006964;
|
||||
struct iovec vec[2];
|
||||
vec[0].iov_base = (void*) &statsEventTag;
|
||||
vec[0].iov_len = sizeof(statsEventTag);
|
||||
vec[1].iov_base = (void*) bufferArray;
|
||||
vec[1].iov_len = size;
|
||||
write_to_statsd(vec, 2);
|
||||
|
||||
write_buffer_to_statsd((void*) bufferArray, size, atomId);
|
||||
|
||||
env->ReleaseByteArrayElements(buf, bufferArray, 0);
|
||||
}
|
||||
@@ -58,7 +52,7 @@ static void android_util_StatsLog_writeRaw(JNIEnv* env, jobject clazz, jbyteArra
|
||||
*/
|
||||
static const JNINativeMethod gMethods[] = {
|
||||
/* name, signature, funcPtr */
|
||||
{ "writeRaw", "([BI)V", (void*) android_util_StatsLog_writeRaw },
|
||||
{ "writeImpl", "([BII)V", (void*) android_util_StatsLog_write },
|
||||
};
|
||||
|
||||
int register_android_util_StatsLog(JNIEnv* env)
|
||||
|
||||
Reference in New Issue
Block a user