Move InitClassLoader from JNI_OnLoad to LoadGlobalClassReferenceHolder

This fixes clients with custom JNI_OnLoad code. This is basically a
reland of https://webrtc-review.googlesource.com/21281, but called from
LoadGlobalClassReferenceHolder instead of InitGlobalJniVariables. The
problem it solves is that some clients call InitGlobalJniVariables
from a strange thread and without using the rest of our Java API.

TBR=lliuu@@webrtc.org,sakal@webrtc.org

Bug: webrtc:8278
Change-Id: I664e50920bcd7e087ec2d8bb5be13569e8ff3088
Reviewed-on: https://webrtc-review.googlesource.com/22801
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20663}
This commit is contained in:
Magnus Jedvert
2017-11-13 22:31:47 +01:00
committed by Commit Bot
parent 8c316c1a89
commit 620d9c9195
2 changed files with 6 additions and 4 deletions

View File

@ -9,6 +9,7 @@
*/
#include "sdk/android/src/jni/classreferenceholder.h"
#include "sdk/android/src/jni/class_loader.h"
#include "sdk/android/src/jni/jni_helpers.h"
namespace webrtc {
@ -34,8 +35,12 @@ class ClassReferenceHolder {
static ClassReferenceHolder* g_class_reference_holder = nullptr;
void LoadGlobalClassReferenceHolder() {
JNIEnv* env = GetEnv();
RTC_CHECK(g_class_reference_holder == nullptr);
g_class_reference_holder = new ClassReferenceHolder(GetEnv());
g_class_reference_holder = new ClassReferenceHolder(env);
// TODO(magjed): This is a weird place to call the other class loader from,
// but the only place that will keep backwards compatibility.
InitClassLoader(env);
}
void FreeGlobalClassReferenceHolder() {

View File

@ -13,7 +13,6 @@
#define JNIEXPORT __attribute__((visibility("default")))
#include "rtc_base/ssladapter.h"
#include "sdk/android/src/jni/class_loader.h"
#include "sdk/android/src/jni/classreferenceholder.h"
#include "sdk/android/src/jni/jni_helpers.h"
@ -28,8 +27,6 @@ extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
LoadGlobalClassReferenceHolder();
JNIEnv* env = AttachCurrentThreadIfNeeded();
InitClassLoader(env);
return ret;
}