Use WebRTC's Java VM initialization in tests.
WebRTC should not depend on chromium's //base.
Bug: webrtc:13662
Change-Id: Ie660aa0f2477cc747830bba611aa23ed5e732385
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256364
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Xavier Lepaul <xalep@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36581}
diff --git a/pc/test/android_test_initializer.cc b/pc/test/android_test_initializer.cc
index 584aeda..963544c 100644
--- a/pc/test/android_test_initializer.cc
+++ b/pc/test/android_test_initializer.cc
@@ -10,22 +10,14 @@
#include "pc/test/android_test_initializer.h"
+#include <jni.h>
#include <pthread.h>
-
-#include "rtc_base/ignore_wundef.h"
-
-// Note: this dependency is dangerous since it reaches into Chromium's base.
-// There's a risk of e.g. macro clashes. This file may only be used in tests.
-// Since we use Chromes build system for creating the gtest binary, this should
-// be fine.
-RTC_PUSH_IGNORING_WUNDEF()
-#include "base/android/jni_android.h"
-RTC_POP_IGNORING_WUNDEF()
+#include <stddef.h>
#include "modules/utility/include/jvm_android.h"
#include "rtc_base/checks.h"
-
-// TODO(phoglund): This include is also to a target we can't really depend on.
+#include "sdk/android/src/jni/jvm.h"
+// TODO(phoglund): This include is to a target we can't really depend on.
// We need to either break it out into a smaller target or find some way to
// not use it.
#include "rtc_base/ssl_adapter.h"
@@ -40,8 +32,8 @@
// C++ runner binary, we want to initialize the same global objects we normally
// do if this had been a Java binary.
void EnsureInitializedOnce() {
- RTC_CHECK(::base::android::IsVMInitialized());
- JNIEnv* jni = ::base::android::AttachCurrentThread();
+ RTC_CHECK(::webrtc::jni::GetJVM() != nullptr);
+ JNIEnv* jni = ::webrtc::jni::AttachCurrentThreadIfNeeded();
JavaVM* jvm = NULL;
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));