Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 634f6969 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Use write_buffer_to_statsd within StatsLog_write"

parents 472f9b15 bc1002d5
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -224,12 +224,25 @@ 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);

    private static void enforceDumpCallingPermission(Context context) {
        context.enforceCallingPermission(android.Manifest.permission.DUMP, "Need DUMP permission.");
+6 −12
Original line number Diff line number Diff line
@@ -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)