Flutter Engine
jni_util.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FML_PLATFORM_ANDROID_JNI_UTIL_H_
6 #define FLUTTER_FML_PLATFORM_ANDROID_JNI_UTIL_H_
7 
8 #include <jni.h>
9 
10 #include <vector>
11 
12 #include "flutter/fml/macros.h"
13 #include "flutter/fml/platform/android/scoped_java_ref.h"
14 
15 namespace fml {
16 namespace jni {
17 
18 void InitJavaVM(JavaVM* vm);
19 
20 // Returns a JNI environment for the current thread.
21 // Attaches the thread to JNI if needed.
22 JNIEnv* AttachCurrentThread();
23 
24 void DetachFromVM();
25 
26 std::string JavaStringToString(JNIEnv* env, jstring string);
27 
28 ScopedJavaLocalRef<jstring> StringToJavaString(JNIEnv* env,
29  const std::string& str);
30 
31 std::vector<std::string> StringArrayToVector(JNIEnv* env, jobjectArray jargs);
32 
33 ScopedJavaLocalRef<jobjectArray> VectorToStringArray(
34  JNIEnv* env,
35  const std::vector<std::string>& vector);
36 
37 ScopedJavaLocalRef<jobjectArray> VectorToBufferArray(
38  JNIEnv* env,
39  const std::vector<std::vector<uint8_t>>& vector);
40 
41 bool HasException(JNIEnv* env);
42 
43 bool ClearException(JNIEnv* env);
44 
45 bool CheckException(JNIEnv* env);
46 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable);
47 
48 } // namespace jni
49 } // namespace fml
50 
51 #endif // FLUTTER_FML_PLATFORM_ANDROID_JNI_UTIL_H_
bool HasException(JNIEnv *env)
Definition: jni_util.cc:164
bool ClearException(JNIEnv *env)
Definition: jni_util.cc:168
ScopedJavaLocalRef< jobjectArray > VectorToStringArray(JNIEnv *env, const std::vector< std::string > &vector)
Definition: jni_util.cc:128
ScopedJavaLocalRef< jstring > StringToJavaString(JNIEnv *env, const std::string &u8_string)
Definition: jni_util.cc:96
void InitJavaVM(JavaVM *vm)
Definition: jni_util.cc:29
ScopedJavaLocalRef< jobjectArray > VectorToBufferArray(JNIEnv *env, const std::vector< std::vector< uint8_t >> &vector)
Definition: jni_util.cc:145
Definition: ascii_trie.cc:9
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
std::string GetJavaExceptionInfo(JNIEnv *env, jthrowable java_throwable)
Definition: jni_util.cc:187
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34
void DetachFromVM()
Definition: jni_util.cc:64
std::string JavaStringToString(JNIEnv *env, jstring str)
Definition: jni_util.cc:76
std::vector< std::string > StringArrayToVector(JNIEnv *env, jobjectArray array)
Definition: jni_util.cc:106