From af823de299fd202da632848a1bb019e4b49215fa Mon Sep 17 00:00:00 2001 From: Vova Sharaienko Date: Sat, 21 Jan 2023 04:31:16 +0000 Subject: [TeX] Extracted Utils API for Telemetry Express Logging APIs - hashString API moved to utils to be used by Histogram metric APIs Bug: 262791652 Test: m Change-Id: Ic049083c6e19c045e6f743e3bc96e1fc15ed4533 Merged-In: Ic049083c6e19c045e6f743e3bc96e1fc15ed4533 --- .../com/android/internal/expresslog/Counter.java | 6 +-- .../com/android/internal/expresslog/Utils.java | 21 ++++++++ core/jni/Android.bp | 2 +- core/jni/AndroidRuntime.cpp | 4 +- .../com_android_internal_expresslog_Counter.cpp | 57 ---------------------- core/jni/com_android_internal_expresslog_Utils.cpp | 57 ++++++++++++++++++++++ 6 files changed, 83 insertions(+), 64 deletions(-) create mode 100644 core/java/com/android/internal/expresslog/Utils.java delete mode 100644 core/jni/com_android_internal_expresslog_Counter.cpp create mode 100644 core/jni/com_android_internal_expresslog_Utils.cpp diff --git a/core/java/com/android/internal/expresslog/Counter.java b/core/java/com/android/internal/expresslog/Counter.java index 7571073a9822..cc37c698271f 100644 --- a/core/java/com/android/internal/expresslog/Counter.java +++ b/core/java/com/android/internal/expresslog/Counter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * Copyright (C) 2023 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. @@ -39,9 +39,7 @@ public final class Counter { * @hide */ public static void logIncrement(@NonNull String metricId, long amount) { - final long metricIdHash = hashString(metricId); + final long metricIdHash = Utils.hashString(metricId); FrameworkStatsLog.write(FrameworkStatsLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount); } - - private static native long hashString(String stringToHash); } diff --git a/core/java/com/android/internal/expresslog/Utils.java b/core/java/com/android/internal/expresslog/Utils.java new file mode 100644 index 000000000000..d82192f51662 --- /dev/null +++ b/core/java/com/android/internal/expresslog/Utils.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 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; + +final class Utils { + static native long hashString(String stringToHash); +} diff --git a/core/jni/Android.bp b/core/jni/Android.bp index 681f194d3bd3..e4738fbd9a37 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -215,7 +215,7 @@ cc_library_shared { "android_content_res_Configuration.cpp", "android_security_Scrypt.cpp", "com_android_internal_content_om_OverlayConfig.cpp", - "com_android_internal_expresslog_Counter.cpp", + "com_android_internal_expresslog_Utils.cpp", "com_android_internal_net_NetworkUtilsInternal.cpp", "com_android_internal_os_ClassLoaderFactory.cpp", "com_android_internal_os_FuseAppLoop.cpp", diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 7dd46a607569..9c7f0a8b613d 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -196,7 +196,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_expresslog_Utils(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); @@ -1591,7 +1591,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_expresslog_Utils), REG_JNI(register_com_android_internal_net_NetworkUtilsInternal), REG_JNI(register_com_android_internal_os_ClassLoaderFactory), REG_JNI(register_com_android_internal_os_LongArrayMultiStateCounter), diff --git a/core/jni/com_android_internal_expresslog_Counter.cpp b/core/jni/com_android_internal_expresslog_Counter.cpp deleted file mode 100644 index d4a8c23b8343..000000000000 --- a/core/jni/com_android_internal_expresslog_Counter.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 -#include - -#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(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 diff --git a/core/jni/com_android_internal_expresslog_Utils.cpp b/core/jni/com_android_internal_expresslog_Utils.cpp new file mode 100644 index 000000000000..d33a7bda27f7 --- /dev/null +++ b/core/jni/com_android_internal_expresslog_Utils.cpp @@ -0,0 +1,57 @@ +/* + * 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 +#include + +#include "core_jni_helpers.h" + +// ---------------------------------------------------------------------------- +// JNI Glue +// ---------------------------------------------------------------------------- + +static jclass g_stringClass = nullptr; + +/** + * Class: com_android_internal_expresslog_Utils + * 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(farmhash::Fingerprint64(name.c_str(), name.size())); +} + +static const JNINativeMethod g_methods[] = { + {"hashString", "(Ljava/lang/String;)J", (void*)hashString}, +}; + +static const char* const kUtilsPathName = "com/android/internal/expresslog/Utils"; + +namespace android { + +int register_com_android_internal_expresslog_Utils(JNIEnv* env) { + jclass stringClass = FindClassOrDie(env, "java/lang/String"); + g_stringClass = MakeGlobalRefOrDie(env, stringClass); + + return RegisterMethodsOrDie(env, kUtilsPathName, g_methods, NELEM(g_methods)); +} + +} // namespace android -- cgit v1.2.3-59-g8ed1b