#ifndef BASE_ANDROID_JNI_ANDROID_H_
#define BASE_ANDROID_JNI_ANDROID_H_
#include <jni.h>
#include <sys/types.h>
#include <atomic>
#include <string>
#include "base/android/scoped_java_ref.h"
#include "base/auto_reset.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/debug/debugging_buildflags.h"
#include "base/debug/stack_trace.h"
#include "third_party/jni_zero/jni_zero.h"
namespace base {
namespace android {
#define JNI_EXPORT __attribute__((visibility("default")))
struct RegistrationMethod {
const char* name;
bool (*func)(JNIEnv* env);
};
using LogFatalCallback = void (*)(const char* message);
BASE_EXPORT extern LogFatalCallback g_log_fatal_callback_for_testing;
BASE_EXPORT extern const char kUnableToGetStackTraceMessage[];
BASE_EXPORT extern const char kReetrantOutOfMemoryMessage[];
BASE_EXPORT extern const char kReetrantExceptionMessage[];
BASE_EXPORT extern const char kUncaughtExceptionMessage[];
BASE_EXPORT extern const char kUncaughtExceptionHandlerFailedMessage[];
BASE_EXPORT extern const char kOomInGetJavaExceptionInfoMessage[];
inline JNIEnv* AttachCurrentThread() {
return jni_zero::AttachCurrentThread();
}
inline JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) {
return jni_zero::AttachCurrentThreadWithName(thread_name);
}
inline void DetachFromVM() {
jni_zero::DetachFromVM();
}
BASE_EXPORT void InitVM(JavaVM* vm);
inline bool IsJavaAvailable() {
return jni_zero::IsVMInitialized();
}
inline JavaVM* GetVM() {
return jni_zero::GetVM();
}
inline void DisableJvmForTesting() {
return jni_zero::DisableJvmForTesting();
}
inline ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env,
const char* class_name) {
return jni_zero::GetClass(env, class_name);
}
inline bool HasException(JNIEnv* env) {
return jni_zero::HasException(env);
}
inline bool ClearException(JNIEnv* env) {
return jni_zero::ClearException(env);
}
BASE_EXPORT void CheckException(JNIEnv* env);
BASE_EXPORT std::string GetJavaExceptionInfo(
JNIEnv* env,
const JavaRef<jthrowable>& throwable);
BASE_EXPORT std::string GetJavaStackTraceIfPresent();
using MethodID = jni_zero::MethodID;
}
}
#endif