blob: 2d102fe4a22ed6e0d7a1c76b7ce02e3d668c7c8f [file] [log] [blame]
Sami Kalliomäki82f96e62018-01-29 13:18:57 +01001/*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// Android's FindClass() is tricky because the app-specific ClassLoader is not
12// consulted when there is no app-specific frame on the stack (i.e. when called
13// from a thread created from native C++ code). These helper functions provide a
14// workaround for this.
15// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
16
17#ifndef SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
18#define SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
19
20#include <jni.h>
21
22#include "sdk/android/native_api/jni/scoped_java_ref.h"
23
24namespace webrtc {
25
26// This method should be called from JNI_OnLoad and before any calls to
27// FindClass. This is normally called by InitAndroid.
28void InitClassLoader(JNIEnv* env);
29
30// This function is identical to JNIEnv::FindClass except that it works from any
31// thread. This function loads and returns a local reference to the class with
32// the given name. The name argument is a fully-qualified class name. For
33// example, the fully-qualified class name for the java.lang.String class is:
34// "java/lang/String". This function will be used from the JNI generated code
35// and should rarely be used manually.
36ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* name);
37
38} // namespace webrtc
39
40#endif // SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_