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

Commit f7df9bd7 authored by Vova Sharaienko's avatar Vova Sharaienko Committed by Automerger Merge Worker
Browse files

Merge "[TeX] Introduced Telemetry Express Logging APIs" am: 42bf7a98 am:...

Merge "[TeX] Introduced Telemetry Express Logging APIs" am: 42bf7a98 am: 05c39124 am: 6e800811

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2272886



Change-Id: Ib1933ab27fb42cb200059f7f0d655e2716741686
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7c1c1472 6e800811
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.expresslog;

import android.annotation.NonNull;

import com.android.internal.util.FrameworkStatsLog;

/** Counter encapsulates StatsD write API calls */
public final class Counter {

    // Not instantiable.
    private Counter() {}

    /**
     * Increments Telemetry Express Counter metric by 1
     * @hide
     */
    public static void logIncrement(@NonNull String metricId) {
        logIncrement(metricId, 1);
    }

    /**
     * Increments Telemetry Express Counter metric by arbitrary value
     * @hide
     */
    public static void logIncrement(@NonNull String metricId, long amount) {
        final long metricIdHash = hashString(metricId);
        FrameworkStatsLog.write(FrameworkStatsLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount);
    }

    private static native long hashString(String stringToHash);
}
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ cc_library_shared {
        "-Wno-error=deprecated-declarations",
        "-Wunused",
        "-Wunreachable-code",

        "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
    ],

    cppflags: ["-Wno-conversion-null"],
@@ -212,6 +214,7 @@ cc_library_shared {
                "android_content_res_ResourceTimer.cpp",
                "android_security_Scrypt.cpp",
                "com_android_internal_content_om_OverlayConfig.cpp",
                "com_android_internal_expresslog_Counter.cpp",
                "com_android_internal_net_NetworkUtilsInternal.cpp",
                "com_android_internal_os_ClassLoaderFactory.cpp",
                "com_android_internal_os_FuseAppLoop.cpp",
@@ -247,6 +250,7 @@ cc_library_shared {
                "libscrypt_static",
                "libstatssocket_lazy",
                "libskia",
                "libtextclassifier_hash_static",
            ],

            shared_libs: [
@@ -329,6 +333,7 @@ cc_library_shared {
            header_libs: [
                "bionic_libc_platform_headers",
                "dnsproxyd_protocol_headers",
                "libtextclassifier_hash_headers",
            ],
        },
        host: {
+2 −0
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ extern int register_android_security_Scrypt(JNIEnv *env);
extern int register_com_android_internal_content_F2fsUtils(JNIEnv* env);
extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
extern int register_com_android_internal_content_om_OverlayConfig(JNIEnv *env);
extern int register_com_android_internal_expresslog_Counter(JNIEnv* env);
extern int register_com_android_internal_net_NetworkUtilsInternal(JNIEnv* env);
extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
@@ -1575,6 +1576,7 @@ static const RegJNIRec gRegJNI[] = {
        REG_JNI(register_android_os_SharedMemory),
        REG_JNI(register_android_os_incremental_IncrementalManager),
        REG_JNI(register_com_android_internal_content_om_OverlayConfig),
        REG_JNI(register_com_android_internal_expresslog_Counter),
        REG_JNI(register_com_android_internal_net_NetworkUtilsInternal),
        REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
        REG_JNI(register_com_android_internal_os_LongArrayMultiStateCounter),
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <nativehelper/JNIHelp.h>
#include <utils/hash/farmhash.h>

#include "core_jni_helpers.h"

// ----------------------------------------------------------------------------
// JNI Glue
// ----------------------------------------------------------------------------

static jclass g_stringClass = nullptr;

/**
 * Class:     com_android_internal_expresslog_Counter
 * Method:    hashString
 * Signature: (Ljava/lang/String;)J
 */
static jlong hashString(JNIEnv* env, jclass /*class*/, jstring metricNameObj) {
    ScopedUtfChars name(env, metricNameObj);
    if (name.c_str() == nullptr) {
        return 0;
    }

    return static_cast<jlong>(farmhash::Fingerprint64(name.c_str(), name.size()));
}

static const JNINativeMethod g_methods[] = {
        {"hashString", "(Ljava/lang/String;)J", (void*)hashString},
};

static const char* const kCounterPathName = "com/android/internal/expresslog/Counter";

namespace android {

int register_com_android_internal_expresslog_Counter(JNIEnv* env) {
    jclass stringClass = FindClassOrDie(env, "java/lang/String");
    g_stringClass = MakeGlobalRefOrDie(env, stringClass);

    return RegisterMethodsOrDie(env, kCounterPathName, g_methods, NELEM(g_methods));
}

} // namespace android