class_loader.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  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. // Android's FindClass() is tricky because the app-specific ClassLoader is not
  11. // consulted when there is no app-specific frame on the stack (i.e. when called
  12. // from a thread created from native C++ code). These helper functions provide a
  13. // workaround for this.
  14. // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
  15. #ifndef SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
  16. #define SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
  17. #include <jni.h>
  18. #include "sdk/android/native_api/jni/scoped_java_ref.h"
  19. namespace webrtc {
  20. // This method should be called from JNI_OnLoad and before any calls to
  21. // FindClass. This is normally called by InitAndroid.
  22. void InitClassLoader(JNIEnv* env);
  23. // This function is identical to JNIEnv::FindClass except that it works from any
  24. // thread. This function loads and returns a local reference to the class with
  25. // the given name. The name argument is a fully-qualified class name. For
  26. // example, the fully-qualified class name for the java.lang.String class is:
  27. // "java/lang/String". This function will be used from the JNI generated code
  28. // and should rarely be used manually.
  29. ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* name);
  30. } // namespace webrtc
  31. #endif // SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_