You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 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. #include "pc/test/android_test_initializer.h"
  11. #include <pthread.h>
  12. #include "rtc_base/ignore_wundef.h"
  13. // Note: this dependency is dangerous since it reaches into Chromium's base.
  14. // There's a risk of e.g. macro clashes. This file may only be used in tests.
  15. // Since we use Chromes build system for creating the gtest binary, this should
  16. // be fine.
  17. RTC_PUSH_IGNORING_WUNDEF()
  18. #include "base/android/jni_android.h"
  19. RTC_POP_IGNORING_WUNDEF()
  20. #include "modules/utility/include/jvm_android.h"
  21. #include "rtc_base/checks.h"
  22. // TODO(phoglund): This include is also to a target we can't really depend on.
  23. // We need to either break it out into a smaller target or find some way to
  24. // not use it.
  25. #include "rtc_base/ssl_adapter.h"
  26. namespace webrtc {
  27. namespace {
  28. static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
  29. // There can only be one JNI_OnLoad in each binary. So since this is a GTEST
  30. // C++ runner binary, we want to initialize the same global objects we normally
  31. // do if this had been a Java binary.
  32. void EnsureInitializedOnce() {
  33. RTC_CHECK(::base::android::IsVMInitialized());
  34. JNIEnv* jni = ::base::android::AttachCurrentThread();
  35. JavaVM* jvm = NULL;
  36. RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
  37. RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
  38. webrtc::JVM::Initialize(jvm);
  39. }
  40. } // anonymous namespace
  41. void InitializeAndroidObjects() {
  42. RTC_CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce));
  43. }
  44. } // namespace webrtc