OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ | 5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ |
6 #define BASE_ANDROID_JNI_ANDROID_H_ | 6 #define BASE_ANDROID_JNI_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 |
11 namespace base { | 13 namespace base { |
12 namespace android { | 14 namespace android { |
13 | 15 |
14 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. | 16 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. |
15 JNIEnv* AttachCurrentThread(); | 17 JNIEnv* AttachCurrentThread(); |
16 | 18 |
17 // Detach the current thread from VM if it is attached. | 19 // Detach the current thread from VM if it is attached. |
18 void DetachFromVM(); | 20 void DetachFromVM(); |
19 | 21 |
20 // Initializes the global JVM. It is not necessarily called before | 22 // Initializes the global JVM. It is not necessarily called before |
21 // InitApplicationContext(). | 23 // InitApplicationContext(). |
22 void InitVM(JavaVM* vm); | 24 void InitVM(JavaVM* vm); |
23 | 25 |
24 // Initializes the global application context object. The |context| should be | 26 // Initializes the global application context object. The |context| should be |
25 // the global reference of application context object. It is not necessarily | 27 // the global reference of application context object. It is not necessarily |
26 // called after InitVM(). | 28 // called after InitVM(). |
27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. | 29 // TODO: We might combine InitVM() and InitApplicationContext() into one method. |
28 void InitApplicationContext(jobject context); | 30 void InitApplicationContext(jobject context); |
29 | 31 |
30 // Returns the application context assigned by InitApplicationContext(). | 32 // Returns the application context assigned by InitApplicationContext(). |
31 jobject GetApplicationContext(); | 33 jobject GetApplicationContext(); |
32 | 34 |
| 35 // Get the method ID for a method, from the class name. Will clear the pending |
| 36 // Java exception and return 0 if the method is not found. Note that |
| 37 // GetMethodID() below avoids a class lookup, so should be used in preference |
| 38 // when possible. |
| 39 jmethodID GetMethodIDFromClassName(JNIEnv* env, |
| 40 const char* const class_name, |
| 41 const char* const method, |
| 42 const char* const jni_signature); |
| 43 |
33 // Get the method ID for a method. Will clear the pending Java | 44 // Get the method ID for a method. Will clear the pending Java |
34 // exception and return 0 if the method is not found. | 45 // exception and return 0 if the method is not found. |
35 jmethodID GetMethodID(JNIEnv* env, | 46 jmethodID GetMethodID(JNIEnv* env, |
36 jclass clazz, | 47 jclass clazz, |
37 const char* const method, | 48 const char* const method, |
38 const char* const jni_signature); | 49 const char* const jni_signature); |
39 | 50 |
40 // Get the method ID for a class static method. Will clear the pending Java | 51 // Get the method ID for a class static method. Will clear the pending Java |
41 // exception and return 0 if the method is not found. | 52 // exception and return 0 if the method is not found. |
42 jmethodID GetStaticMethodID(JNIEnv* env, | 53 jmethodID GetStaticMethodID(JNIEnv* env, |
43 jclass clazz, | 54 jclass clazz, |
44 const char* const method, | 55 const char* const method, |
45 const char* const jni_signature); | 56 const char* const jni_signature); |
46 | 57 |
| 58 // Get the field ID for a class field. Will clear the pending Java |
| 59 // exception and return 0 if the field is not found. |
| 60 jfieldID GetFieldID(JNIEnv* env, |
| 61 jclass clazz, |
| 62 const char* const field, |
| 63 const char* const jni_signature); |
| 64 |
47 // Returns true if an exception is pending in the provided JNIEnv*. | 65 // Returns true if an exception is pending in the provided JNIEnv*. |
48 // If an exception is pending, it is printed. | 66 // If an exception is pending, it is printed and cleared. |
49 bool CheckException(JNIEnv* env); | 67 bool CheckException(JNIEnv* env); |
50 | 68 |
51 } // namespace android | 69 } // namespace android |
52 } // namespace base | 70 } // namespace base |
53 | 71 |
54 #endif // BASE_ANDROID_JNI_ANDROID_H_ | 72 #endif // BASE_ANDROID_JNI_ANDROID_H_ |
OLD | NEW |