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 namespace base { | 11 namespace base { |
12 namespace android { | 12 namespace android { |
13 | 13 |
14 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. | 14 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. |
15 JNIEnv* AttachCurrentThread(); | 15 JNIEnv* AttachCurrentThread(); |
16 | 16 |
17 // Detach the current thread from VM if it is attached. | 17 // Detach the current thread from VM if it is attached. |
18 void DetachFromVM(); | 18 void DetachFromVM(); |
19 | 19 |
20 // Initializes the global JVM. It is not necessarily called before | 20 // Initializes the global JVM. It is not necessarily called before |
21 // InitApplicationContext(). | 21 // InitApplicationContext(). |
22 void InitVM(JavaVM* vm); | 22 void InitVM(JavaVM* vm); |
23 | 23 |
24 // Initializes the global application context object. The |context| should be | 24 // Initializes the global application context object. The |context| should be |
25 // the global reference of application context object. It is not necessarily | 25 // the global reference of application context object. It is not necessarily |
26 // called after InitVM(). | 26 // called after InitVM(). |
27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. | 27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. |
28 void InitApplicationContext(jobject context); | 28 void InitApplicationContext(jobject context); |
29 | 29 |
| 30 // Returns the application context assigned by InitApplicationContext(). |
30 jobject GetApplicationContext(); | 31 jobject GetApplicationContext(); |
31 | 32 |
32 // Get the method ID for a method. Will clear the pending Java | 33 // Get the method ID for a method. Will clear the pending Java |
33 // exception and return 0 if the method is not found. | 34 // exception and return 0 if the method is not found. |
34 jmethodID GetMethodID(JNIEnv* env, | 35 jmethodID GetMethodID(JNIEnv* env, |
35 jclass clazz, | 36 jclass clazz, |
36 const char* const method, | 37 const char* const method, |
37 const char* const jni_signature); | 38 const char* const jni_signature); |
38 | 39 |
39 // Returns true if an exception is pending in the provided JNIEnv*. | 40 // Returns true if an exception is pending in the provided JNIEnv*. |
40 // If an exception is pending, it is printed. | 41 // If an exception is pending, it is printed. |
41 bool CheckException(JNIEnv* env); | 42 bool CheckException(JNIEnv* env); |
42 | 43 |
43 } // namespace android | 44 } // namespace android |
44 } // namespace base | 45 } // namespace base |
45 #endif | 46 |
| 47 #endif // BASE_ANDROID_JNI_ANDROID_H_ |
OLD | NEW |