Merge "Drop dependency on libnativehelper" into rvc-dev

This commit is contained in:
Orion Hodson
2020-05-30 10:05:06 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 11 deletions

View File

@@ -62,8 +62,8 @@ prebuilt_etc {
cc_library_shared { cc_library_shared {
name: "libstats_jni", name: "libstats_jni",
srcs: ["jni/**/*.cpp"], srcs: ["jni/**/*.cpp"],
header_libs: ["libnativehelper_header_only"],
shared_libs: [ shared_libs: [
"libnativehelper", // Has stable abi - should not be copied into apex.
"liblog", // Has a stable abi - should not be copied into apex. "liblog", // Has a stable abi - should not be copied into apex.
"libstatssocket", "libstatssocket",
], ],

View File

@@ -17,9 +17,9 @@
#define LOG_NAMESPACE "StatsLog.tag." #define LOG_NAMESPACE "StatsLog.tag."
#define LOG_TAG "StatsLog_println" #define LOG_TAG "StatsLog_println"
#include "jni.h" #include <jni.h>
#include <log/log.h> #include <log/log.h>
#include <nativehelper/JNIHelp.h> #include <nativehelper/scoped_local_ref.h>
#include "stats_buffer_writer.h" #include "stats_buffer_writer.h"
namespace android { namespace android {
@@ -54,8 +54,23 @@ static const JNINativeMethod gMethods[] = {
int register_android_util_StatsLog(JNIEnv* env) int register_android_util_StatsLog(JNIEnv* env)
{ {
return jniRegisterNativeMethods(env, "android/util/StatsLog", gMethods, NELEM(gMethods)); static const char* kStatsLogClass = "android/util/StatsLog";
ScopedLocalRef<jclass> cls(env, env->FindClass(kStatsLogClass));
if (cls.get() == nullptr) {
ALOGE("jni statsd registration failure, class not found '%s'", kStatsLogClass);
return JNI_ERR;
}
const jint count = sizeof(gMethods) / sizeof(gMethods[0]);
int status = env->RegisterNatives(cls.get(), gMethods, count);
if (status < 0) {
ALOGE("jni statsd registration failure, status: %d", status);
return JNI_ERR;
}
return JNI_VERSION_1_4;
} }
}; // namespace android }; // namespace android
/* /*
@@ -63,7 +78,6 @@ int register_android_util_StatsLog(JNIEnv* env)
*/ */
jint JNI_OnLoad(JavaVM* jvm, void* reserved) { jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
JNIEnv* e; JNIEnv* e;
int status;
ALOGV("statsd : loading JNI\n"); ALOGV("statsd : loading JNI\n");
// Check JNI version // Check JNI version
@@ -71,10 +85,6 @@ jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
ALOGE("JNI version mismatch error"); ALOGE("JNI version mismatch error");
return JNI_ERR; return JNI_ERR;
} }
status = android::register_android_util_StatsLog(e);
if (status < 0) { return android::register_android_util_StatsLog(e);
ALOGE("jni statsd registration failure, status: %d", status);
return JNI_ERR;
}
return JNI_VERSION_1_4;
} }