summaryrefslogtreecommitdiffstats
path: root/base/android/jni_android.h
blob: 66b3134e35d2b271760c2d9a19952c6affb15b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_ANDROID_JNI_ANDROID_H_
#define BASE_ANDROID_JNI_ANDROID_H_

#include <jni.h>
#include <sys/types.h>

namespace base {
namespace android {

// Attach the current thread to the VM (if necessary) and return the JNIEnv*.
JNIEnv* AttachCurrentThread();

// Detach the current thread from VM if it is attached.
void DetachFromVM();

// Initializes the global JVM. It is not necessarily called before
// InitApplicationContext().
void InitVM(JavaVM* vm);

// Initializes the global application context object. The |context| should be
// the global reference of application context object.  It is not necessarily
// called after InitVM().
// TODO: We might combine InitVM() and InitApplicationContext() into one method.
void InitApplicationContext(jobject context);

// Returns the application context assigned by InitApplicationContext().
jobject GetApplicationContext();

// Get the method ID for a method. Will clear the pending Java
// exception and return 0 if the method is not found.
jmethodID GetMethodID(JNIEnv* env,
                      jclass clazz,
                      const char* const method,
                      const char* const jni_signature);

// Get the method ID for a class static method. Will clear the pending Java
// exception and return 0 if the method is not found.
jmethodID GetStaticMethodID(JNIEnv* env,
                            jclass clazz,
                            const char* const method,
                            const char* const jni_signature);

// Returns true if an exception is pending in the provided JNIEnv*.
// If an exception is pending, it is printed.
bool CheckException(JNIEnv* env);

}  // namespace android
}  // namespace base

#endif  // BASE_ANDROID_JNI_ANDROID_H_