Drop dependency on libnativehelper

Pending changes to libnativehelper API mean modules should not depend
on it as a stable API.

Bug: 157711673
Test: atest FrameworkStatsdTest LibStatsPullTests
Change-Id: I708a1489b5a1e30185b7e3677393c446074dc96c
This commit is contained in:
Orion Hodson
2020-05-29 13:30:34 +01:00
parent 4f5af837be
commit 1cec75dd50
2 changed files with 21 additions and 11 deletions

View File

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

View File

@@ -17,9 +17,9 @@
#define LOG_NAMESPACE "StatsLog.tag."
#define LOG_TAG "StatsLog_println"
#include "jni.h"
#include <jni.h>
#include <log/log.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/scoped_local_ref.h>
#include "stats_buffer_writer.h"
namespace android {
@@ -54,8 +54,23 @@ static const JNINativeMethod gMethods[] = {
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
/*
@@ -63,7 +78,6 @@ int register_android_util_StatsLog(JNIEnv* env)
*/
jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
JNIEnv* e;
int status;
ALOGV("statsd : loading JNI\n");
// Check JNI version
@@ -71,10 +85,6 @@ jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
ALOGE("JNI version mismatch error");
return JNI_ERR;
}
status = android::register_android_util_StatsLog(e);
if (status < 0) {
ALOGE("jni statsd registration failure, status: %d", status);
return JNI_ERR;
}
return JNI_VERSION_1_4;
return android::register_android_util_StatsLog(e);
}