Bug 1406168 - 2. Remove AndroidJNIWrapper; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Tue, 31 Oct 2017 11:43:07 -0400
changeset 689463 62be054900379962223c845092e9e6ba5c33d2fc
parent 689462 9bb12713021d15a85987a1554b2ce4b93d865869
child 689464 a9df885501b3e53a620bb908d375746f07b4ecce
push id87029
push userbmo:nchen@mozilla.com
push dateTue, 31 Oct 2017 15:44:03 +0000
reviewerssnorp
bugs1406168
milestone58.0a1
Bug 1406168 - 2. Remove AndroidJNIWrapper; r?snorp Remove AndroidJNIWrapper. It was primarily used by JNI.jsm and WebRTC. Usages in WebRTC are replaced with equivalent uses of JNI templates. MozReview-Commit-ID: DPSeMOtH2wF
dom/media/webrtc/MediaEngineWebRTC.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
media/webrtc/trunk/webrtc/modules/audio_device/android/audio_manager.cc
media/webrtc/trunk/webrtc/modules/utility/source/jvm_android.cc
media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc
media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc
widget/android/AndroidBridge.cpp
widget/android/AndroidJNIWrapper.cpp
widget/android/AndroidJNIWrapper.h
widget/android/jni/Utils.cpp
widget/android/jni/Utils.h
widget/android/moz.build
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -20,17 +20,16 @@ static mozilla::LazyLogModule sGetUserMe
 #include "MediaEngineTabVideoSource.h"
 #include "MediaEngineRemoteVideoSource.h"
 #include "CamerasChild.h"
 #include "nsITabSource.h"
 #include "MediaTrackConstraints.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "VideoEngine.h"
-#include "AndroidJNIWrapper.h"
 #include "AndroidBridge.h"
 #endif
 
 #undef LOG
 #define LOG(args) MOZ_LOG(sGetUserMediaLog, mozilla::LogLevel::Debug, args)
 
 namespace mozilla {
 
@@ -277,23 +276,19 @@ MediaEngineWebRTC::EnumerateAudioDevices
   if (aMediaSource == dom::MediaSourceEnum::AudioCapture) {
     RefPtr<MediaEngineWebRTCAudioCaptureSource> audioCaptureSource =
       new MediaEngineWebRTCAudioCaptureSource(nullptr);
     aASources->AppendElement(audioCaptureSource);
     return;
   }
 
 #ifdef MOZ_WIDGET_ANDROID
+  JavaVM* jvm = mozilla::jni::GetVM();
   jobject context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef();
 
-  // get the JVM
-  JavaVM* jvm;
-  JNIEnv* const env = jni::GetEnvForThread();
-  MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
-
   if (webrtc::VoiceEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
     LOG(("VoiceEngine:SetAndroidObjects Failed"));
     return;
   }
 #endif
 
   if (!mVoiceEngine) {
     mVoiceEngine = webrtc::VoiceEngine::Create();
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -23,17 +23,17 @@
 
 #include "webrtc/modules/audio_processing/include/audio_processing.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
 #include "webrtc/voice_engine/include/voe_errors.h"
 #include "webrtc/voice_engine/voice_engine_impl.h"
 #include "webrtc/system_wrappers/include/clock.h"
 
 #ifdef MOZ_WIDGET_ANDROID
-#include "AndroidJNIWrapper.h"
+#include "AndroidBridge.h"
 #endif
 
 namespace mozilla {
 
 static const char* acLogTag ="WebrtcAudioSessionConduit";
 #ifdef LOGTAG
 #undef LOGTAG
 #endif
@@ -288,24 +288,23 @@ bool WebrtcAudioConduit::InsertDTMFTone(
 /*
  * WebRTCAudioConduit Implementation
  */
 MediaConduitErrorCode WebrtcAudioConduit::Init()
 {
   CSFLogDebug(LOGTAG,  "%s this=%p", __FUNCTION__, this);
 
 #ifdef MOZ_WIDGET_ANDROID
-    jobject context = jsjni_GetGlobalContextRef();
-    // get the JVM
-    JavaVM *jvm = jsjni_GetVM();
+  JavaVM* jvm = mozilla::jni::GetVM();
+  jobject context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef();
 
-    if (webrtc::VoiceEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
-      CSFLogError(LOGTAG, "%s Unable to set Android objects", __FUNCTION__);
-      return kMediaConduitSessionNotInited;
-    }
+  if (webrtc::VoiceEngine::SetAndroidObjects(jvm, (void*)context) != 0) {
+    CSFLogError(LOGTAG, "%s Unable to set Android objects", __FUNCTION__);
+    return kMediaConduitSessionNotInited;
+  }
 #endif
 
   // Per WebRTC APIs below function calls return nullptr on failure
   if(!(mVoiceEngine = webrtc::VoiceEngine::Create()))
   {
     CSFLogError(LOGTAG, "%s Unable to create voice engine", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -37,17 +37,16 @@
   (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8)
 // XXX not available in Mac 10.7 SDK
 #include "webrtc/common_video/include/corevideo_frame_buffer.h"
 #endif
 
 #include "mozilla/Unused.h"
 
 #if defined(MOZ_WIDGET_ANDROID)
-#include "AndroidJNIWrapper.h"
 #include "VideoEngine.h"
 #endif
 
 #include "GmpVideoCodec.h"
 
 #ifdef MOZ_WEBRTC_MEDIACODEC
 #include "MediaCodecVideoCodec.h"
 #endif
@@ -1154,18 +1153,17 @@ WebrtcVideoConduit::InitMain()
       }
       Unused << NS_WARN_IF(NS_FAILED(branch->GetBoolPref(
         "media.peerconnection.video.denoising", &mDenoising)));
       Unused << NS_WARN_IF(NS_FAILED(branch->GetBoolPref(
         "media.peerconnection.video.lock_scaling", &mLockScaling)));
     }
   }
 #ifdef MOZ_WIDGET_ANDROID
-  // get the JVM
-  JavaVM *jvm = jsjni_GetVM();
+  JavaVM* jvm = mozilla::jni::GetVM();
 
   if (mozilla::camera::VideoEngine::SetAndroidObjects(jvm) != 0) {
     CSFLogError(LOGTAG,  "%s: could not set Android objects", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
 #endif  //MOZ_WIDGET_ANDROID
   return kMediaConduitNoError;
 }
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
@@ -7,17 +7,16 @@
 #include <queue>
 
 #include "CSFLog.h"
 #include "nspr.h"
 
 #include "JavaCallbacksSupport.h"
 #include "MediaCodec.h"
 #include "WebrtcMediaCodecVP8VideoCodec.h"
-#include "AndroidJNIWrapper.h"
 #include "mozilla/ArrayUtils.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Monitor.h"
 #include "runnable_utils.h"
 #include "MediaResult.h"
 
 #include "AudioConduit.h"
 #include "VideoConduit.h"
@@ -438,17 +437,17 @@ public:
 
 #ifdef WEBRTC_MEDIACODEC_DEBUG
     CSFLogDebug(LOGTAG,  "%s dequeue input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
     time = PR_IntervalNow();
 #endif
 
     size_t size = inputImage._length;
 
-    JNIEnv* env = jsjni_GetJNIForThread();
+    JNIEnv* const env = jni::GetEnvForThread();
     jobject buffer = env->GetObjectArrayElement(mInputBuffers, inputIndex);
     void* directBuffer = env->GetDirectBufferAddress(buffer);
 
     PodCopy((uint8_t*)directBuffer, inputImage._buffer, size);
 
     if (inputIndex >= 0) {
       CSFLogError(LOGTAG,  "%s queue input buffer inputIndex = %d", __FUNCTION__, inputIndex);
       QueueInputBuffer(inputIndex, 0, size, renderTimeMs, 0);
@@ -515,17 +514,17 @@ public:
         aInputFrames.pop();
       }
 
       if (mEnding) {
         ReleaseOutputBuffer(outputIndex, false);
         return NS_OK;
       }
 
-      JNIEnv* env = jsjni_GetJNIForThread();
+      JNIEnv* const env = jni::GetEnvForThread();
       jobject buffer = env->GetObjectArrayElement(mOutputBuffers, outputIndex);
       if (buffer) {
         // The buffer will be null on Android L if we are decoding to a Surface
         void* directBuffer = env->GetDirectBufferAddress(buffer);
 
         int color_format = 0;
 
         CSFLogDebug(LOGTAG,  "%s generate video frame, width = %d, height = %d, timeStamp_ = %d", __FUNCTION__, frame.width_, frame.height_, frame.timeStamp_);
@@ -577,17 +576,17 @@ public:
     return outputStatus;
   }
 
   void ReleaseOutputBuffer(int32_t index, bool flag) {
     mCoder->ReleaseOutputBuffer(index, flag);
   }
 
   jobjectArray GetInputBuffers() {
-    JNIEnv* env = jsjni_GetJNIForThread();
+    JNIEnv* const env = jni::GetEnvForThread();
 
     if (mInputBuffers) {
       env->DeleteGlobalRef(mInputBuffers);
     }
 
     nsresult res;
     jni::ObjectArray::LocalRef inputBuffers;
     res = mCoder->GetInputBuffers(&inputBuffers);
@@ -597,17 +596,17 @@ public:
                   __FUNCTION__, (int)res);
       return nullptr;
     }
 
     return mInputBuffers;
   }
 
   jobjectArray GetOutputBuffers() {
-    JNIEnv* env = jsjni_GetJNIForThread();
+    JNIEnv* const env = jni::GetEnvForThread();
 
     if (mOutputBuffers) {
       env->DeleteGlobalRef(mOutputBuffers);
     }
 
     nsresult res;
     jni::ObjectArray::LocalRef outputBuffers;
     res = mCoder->GetOutputBuffers(&outputBuffers);
@@ -820,17 +819,17 @@ int32_t WebrtcMediaCodecVP8VideoEncoder:
     return inputIndex;
   }
 
 #ifdef WEBRTC_MEDIACODEC_DEBUG
   CSFLogDebug(LOGTAG,  "%s WebrtcMediaCodecVP8VideoEncoder::Encode() dequeue OMX input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
 #endif
 
   if (inputIndex >= 0) {
-    JNIEnv* env = jsjni_GetJNIForThread();
+    JNIEnv* const env = jni::GetEnvForThread();
     jobject buffer = env->GetObjectArrayElement(mInputBuffers, inputIndex);
     void* directBuffer = env->GetDirectBufferAddress(buffer);
 
     uint8_t* dstY = static_cast<uint8_t*>(directBuffer);
     uint16_t* dstUV = reinterpret_cast<uint16_t*>(dstY + sizeY);
 
     bool converted = I420toNV12(dstY, dstUV, inputImage);
     if (!converted) {
@@ -876,17 +875,17 @@ int32_t WebrtcMediaCodecVP8VideoEncoder:
       mMediaCodecEncoder->GetOutputBuffers();
     } else if (outputIndex < 0) {
       CSFLogDebug(LOGTAG,  "%s dequeue output buffer unknow error:%d", __FUNCTION__, outputIndex);
     } else {
 #ifdef WEBRTC_MEDIACODEC_DEBUG
       CSFLogDebug(LOGTAG,  "%s dequeue output buffer return status is %d took %u ms", __FUNCTION__, outputIndex, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
 #endif
 
-      JNIEnv* env = jsjni_GetJNIForThread();
+      JNIEnv* const env = jni::GetEnvForThread();
       jobject buffer = env->GetObjectArrayElement(mOutputBuffers, outputIndex);
       if (buffer) {
         int32_t offset;
         bufferInfo->Offset(&offset);
         int32_t flags;
         bufferInfo->Flags(&flags);
 
         // The buffer will be null on Android L if we are decoding to a Surface
--- a/media/webrtc/trunk/webrtc/modules/audio_device/android/audio_manager.cc
+++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/audio_manager.cc
@@ -9,18 +9,16 @@
  */
 
 #include "webrtc/modules/audio_device/android/audio_manager.h"
 
 #include <utility>
 
 #include <android/log.h>
 
-#include "AndroidJNIWrapper.h"
-
 #include "webrtc/base/arraysize.h"
 #include "webrtc/base/checks.h"
 #include "webrtc/modules/audio_device/android/audio_common.h"
 #include "webrtc/modules/utility/include/helpers_android.h"
 
 #include "OpenSLESProvider.h"
 
 #define TAG "AudioManager"
--- a/media/webrtc/trunk/webrtc/modules/utility/source/jvm_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/utility/source/jvm_android.cc
@@ -10,17 +10,22 @@
 
 #include <android/log.h>
 
 #include <memory>
 
 #include "webrtc/modules/utility/include/jvm_android.h"
 
 #include "webrtc/base/checks.h"
-#include "AndroidJNIWrapper.h"
+
+namespace mozilla {
+namespace jni {
+jclass GetClassRef(JNIEnv* aEnv, const char* aClassName);
+}
+}
 
 #define TAG "JVM"
 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
 
 namespace webrtc {
 
 JVM* g_jvm;
@@ -39,19 +44,20 @@ struct {
 // Android's FindClass() is trickier than usual because the app-specific
 // ClassLoader is not consulted when there is no app-specific frame on the
 // stack.  Consequently, we only look up all classes once in native WebRTC.
 // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
 void LoadClasses(JNIEnv* jni) {
   ALOGD("LoadClasses");
   for (auto& c : loaded_classes) {
     ALOGD("name: %s", c.name);
-    jclass globalRef = jsjni_GetGlobalClassRef(c.name);
-    RTC_CHECK(globalRef) << c.name;
-    c.clazz = globalRef;
+    jclass clsRef = mozilla::jni::GetClassRef(jni, c.name);
+    RTC_CHECK(clsRef) << c.name;
+    c.clazz = static_cast<jclass>(jni->NewGlobalRef(clsRef));
+    jni->DeleteLocalRef(clsRef);
   }
 }
 
 void FreeClassReferences(JNIEnv* jni) {
   for (auto& c : loaded_classes) {
     jni->DeleteGlobalRef(c.clazz);
     c.clazz = nullptr;
   }
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc
@@ -15,17 +15,17 @@
 #include <sstream>
 #include <vector>
 
 #include "webrtc/modules/utility/include/helpers_android.h"
 #include "webrtc/modules/video_capture/android/video_capture_android.h"
 #include "webrtc/system_wrappers/include/logging.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
-#include "AndroidJNIWrapper.h"
+#include "mozilla/jni/Utils.h"
 
 namespace webrtc {
 
 namespace videocapturemodule {
 
 // Helper for storing lists of pairs of ints.  Used e.g. for resolutions & FPS
 // ranges.
 typedef std::pair<int, int> IntPair;
@@ -108,20 +108,20 @@ void DeviceInfoAndroid::BuildDeviceList(
   if (!g_jvm_dev_info) {
     return;
   }
 
   AttachThreadScoped ats(g_jvm_dev_info);
   JNIEnv* jni = ats.env();
 
   g_camera_info = new std::vector<AndroidCameraInfo>();
-  jclass j_info_class =
-    jsjni_GetGlobalClassRef("org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid");
-  jclass j_cap_class =
-    jsjni_GetGlobalClassRef("org/webrtc/videoengine/CaptureCapabilityAndroid");
+  jclass j_info_class = mozilla::jni::GetClassRef(
+    jni, "org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid");
+  jclass j_cap_class = mozilla::jni::GetClassRef(
+    jni, "org/webrtc/videoengine/CaptureCapabilityAndroid");
   assert(j_info_class);
   jmethodID j_initialize = jni->GetStaticMethodID(
     j_info_class, "getDeviceInfo",
     "()[Lorg/webrtc/videoengine/CaptureCapabilityAndroid;");
   jarray j_camera_caps = static_cast<jarray>(
     jni->CallStaticObjectMethod(j_info_class, j_initialize));
 
   const jsize capLength = jni->GetArrayLength(j_camera_caps);
@@ -179,18 +179,18 @@ void DeviceInfoAndroid::BuildDeviceList(
 
     info.mfpsRanges.push_back(std::make_pair(min_mfps, max_mfps));
     g_camera_info->push_back(info);
 
     jni->ReleaseIntArrayElements(widthResArray, widths, JNI_ABORT);
     jni->ReleaseIntArrayElements(heightResArray, heights, JNI_ABORT);
   }
 
-  jni->DeleteGlobalRef(j_info_class);
-  jni->DeleteGlobalRef(j_cap_class);
+  jni->DeleteLocalRef(j_info_class);
+  jni->DeleteLocalRef(j_cap_class);
 }
 
 void DeviceInfoAndroid::DeInitialize() {
   if (g_camera_info) {
     delete g_camera_info;
     g_camera_info = NULL;
   }
 }
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc
@@ -13,17 +13,17 @@
 #include "webrtc/base/common.h"
 #include "webrtc/modules/utility/include/helpers_android.h"
 #include "webrtc/modules/video_capture/android/device_info_android.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/logcat_trace_context.h"
 #include "webrtc/system_wrappers/include/logging.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
-#include "AndroidJNIWrapper.h"
+#include "AndroidBridge.h"
 
 static JavaVM* g_jvm_capture = NULL;
 static jclass g_java_capturer_class = NULL;  // VideoCaptureAndroid.class.
 static jobject g_context = NULL;  // Owned android.content.Context.
 
 namespace webrtc {
 
 // Called by Java to get the global application context.
@@ -59,22 +59,25 @@ int32_t SetCaptureAndroidVM(JavaVM* java
     return 0;
   }
 
   if (javaVM) {
     assert(!g_jvm_capture);
     g_jvm_capture = javaVM;
     AttachThreadScoped ats(g_jvm_capture);
 
-    g_context = jsjni_GetGlobalContextRef();
+    g_context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef();
 
     videocapturemodule::DeviceInfoAndroid::Initialize(g_jvm_capture);
 
+    jclass clsRef = mozilla::jni::GetClassRef(
+        ats.env(), "org/webrtc/videoengine/VideoCaptureAndroid");
     g_java_capturer_class =
-      jsjni_GetGlobalClassRef("org/webrtc/videoengine/VideoCaptureAndroid");
+        static_cast<jclass>(ats.env()->NewGlobalRef(clsRef));
+    ats.env()->DeleteLocalRef(clsRef);
     assert(g_java_capturer_class);
 
     JNINativeMethod native_methods[] = {
         {"GetContext",
          "()Landroid/content/Context;",
          reinterpret_cast<void*>(&GetContext)},
         {"ProvideCameraFrame",
          "([BIIJJ)V",
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -10,17 +10,16 @@
 
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 
 #include "mozilla/Hal.h"
 #include "nsXULAppAPI.h"
 #include <prthread.h>
 #include "AndroidBridge.h"
-#include "AndroidJNIWrapper.h"
 #include "AndroidBridgeUtilities.h"
 #include "nsAlertsUtils.h"
 #include "nsAppShell.h"
 #include "nsOSHelperAppService.h"
 #include "nsWindow.h"
 #include "mozilla/Preferences.h"
 #include "nsThreadUtils.h"
 #include "nsIThreadManager.h"
deleted file mode 100644
--- a/widget/android/AndroidJNIWrapper.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <android/log.h>
-#include <dlfcn.h>
-#include <prthread.h>
-
-#include "mozilla/DebugOnly.h"
-#include "mozilla/Assertions.h"
-#include "mozilla/SyncRunnable.h"
-#include "nsThreadUtils.h"
-#include "AndroidBridge.h"
-
-extern "C" {
-  jclass __jsjni_GetGlobalClassRef(const char *className);
-}
-
-class GetGlobalClassRefRunnable : public mozilla::Runnable {
-  public:
-    GetGlobalClassRefRunnable(const char *className, jclass *foundClass) :
-        mozilla::Runnable("GetGlobalClassRefRunnable"),
-        mClassName(className), mResult(foundClass) {}
-    NS_IMETHOD Run() override {
-        *mResult = __jsjni_GetGlobalClassRef(mClassName);
-        return NS_OK;
-    }
-  private:
-    const char *mClassName;
-    jclass *mResult;
-};
-
-extern "C" {
-  __attribute__ ((visibility("default")))
-  jclass
-  jsjni_FindClass(const char *className) {
-    // FindClass outside the main thread will run into problems due
-    // to missing the classpath
-    MOZ_ASSERT(NS_IsMainThread());
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-    return env->FindClass(className);
-  }
-
-  jclass
-  __jsjni_GetGlobalClassRef(const char *className) {
-    // root class globally
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-    jclass globalRef = static_cast<jclass>(env->NewGlobalRef(env->FindClass(className)));
-    if (!globalRef)
-      return nullptr;
-
-    // return the newly create global reference
-    return globalRef;
-  }
-
-  __attribute__ ((visibility("default")))
-  jclass
-  jsjni_GetGlobalClassRef(const char *className) {
-    if (NS_IsMainThread()) {
-      return __jsjni_GetGlobalClassRef(className);
-    }
-
-    nsCOMPtr<nsIThread> mainThread;
-    mozilla::DebugOnly<nsresult> rv = NS_GetMainThread(getter_AddRefs(mainThread));
-    MOZ_ASSERT(NS_SUCCEEDED(rv));
-
-    jclass foundClass;
-    nsCOMPtr<nsIRunnable> runnable_ref(new GetGlobalClassRefRunnable(className,
-                                                                     &foundClass));
-    RefPtr<mozilla::SyncRunnable> sr = new mozilla::SyncRunnable(runnable_ref);
-    sr->DispatchToThread(mainThread);
-    if (!foundClass)
-      return nullptr;
-
-    return foundClass;
-  }
-
-  __attribute__ ((visibility("default")))
-  jmethodID
-  jsjni_GetStaticMethodID(jclass methodClass,
-                          const char *methodName,
-                          const char *signature) {
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-    return env->GetStaticMethodID(methodClass, methodName, signature);
-  }
-
-  __attribute__ ((visibility("default")))
-  bool
-  jsjni_ExceptionCheck() {
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-    return env->ExceptionCheck();
-  }
-
-  __attribute__ ((visibility("default")))
-  void
-  jsjni_CallStaticVoidMethodA(jclass cls,
-                              jmethodID method,
-                              jvalue *values) {
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-
-    mozilla::AutoLocalJNIFrame jniFrame(env);
-    env->CallStaticVoidMethodA(cls, method, values);
-  }
-
-  __attribute__ ((visibility("default")))
-  int
-  jsjni_CallStaticIntMethodA(jclass cls,
-                             jmethodID method,
-                             jvalue *values) {
-    JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
-
-    mozilla::AutoLocalJNIFrame jniFrame(env);
-    return env->CallStaticIntMethodA(cls, method, values);
-  }
-
-  __attribute__ ((visibility("default")))
-  jobject jsjni_GetGlobalContextRef() {
-    return mozilla::AndroidBridge::Bridge()->GetGlobalContextRef();
-  }
-
-  __attribute__ ((visibility("default")))
-  JavaVM* jsjni_GetVM() {
-    JavaVM* jvm;
-    JNIEnv* const env = mozilla::jni::GetGeckoThreadEnv();
-    MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
-    return jvm;
-  }
-
-  __attribute__ ((visibility("default")))
-  JNIEnv* jsjni_GetJNIForThread() {
-    return mozilla::jni::GetEnvForThread();
-  }
-
-  // For compatibility with JNI.jsm; some addons bundle their own JNI.jsm,
-  // so we cannot just change the function name used in JNI.jsm.
-  __attribute__ ((visibility("default")))
-  JNIEnv* GetJNIForThread() {
-    return mozilla::jni::GetEnvForThread();
-  }
-}
deleted file mode 100644
--- a/widget/android/AndroidJNIWrapper.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef AndroidJNIWrapper_h__
-#define AndroidJNIWrapper_h__
-
-#include "mozilla/Types.h"
-#include <jni.h>
-#include <android/log.h>
-
-extern "C" MOZ_EXPORT jclass jsjni_FindClass(const char *className);
-
-/**
- * JNIEnv::FindClass alternative.
- * Callable from any thread, including code
- * invoked via the JNI that doesn't have MOZILLA_INTERNAL_API defined.
- * The caller is responsible for ensuring that the class is not leaked by
- * calling DeleteGlobalRef at an appropriate time.
- */
-extern "C" MOZ_EXPORT jclass jsjni_GetGlobalClassRef(const char *className);
-
-extern "C" MOZ_EXPORT jmethodID jsjni_GetStaticMethodID(jclass methodClass,
-                                       const char *methodName,
-                                       const char *signature);
-extern "C" MOZ_EXPORT bool jsjni_ExceptionCheck();
-extern "C" MOZ_EXPORT void jsjni_CallStaticVoidMethodA(jclass cls, jmethodID method, jvalue *values);
-extern "C" MOZ_EXPORT int jsjni_CallStaticIntMethodA(jclass cls, jmethodID method, jvalue *values);
-extern "C" MOZ_EXPORT jobject jsjni_GetGlobalContextRef();
-extern "C" MOZ_EXPORT JavaVM* jsjni_GetVM();
-extern "C" MOZ_EXPORT JNIEnv* jsjni_GetJNIForThread();
-
-#endif /* AndroidJNIWrapper_h__ */
--- a/widget/android/jni/Utils.cpp
+++ b/widget/android/jni/Utils.cpp
@@ -67,22 +67,21 @@ template<> const char ObjectBase<TypedOb
 template<> const char ObjectBase<TypedObject<jshortArray>, jshortArray>::name[] = "[S";
 template<> const char ObjectBase<TypedObject<jintArray>, jintArray>::name[] = "[I";
 template<> const char ObjectBase<TypedObject<jlongArray>, jlongArray>::name[] = "[J";
 template<> const char ObjectBase<TypedObject<jfloatArray>, jfloatArray>::name[] = "[F";
 template<> const char ObjectBase<TypedObject<jdoubleArray>, jdoubleArray>::name[] = "[D";
 template<> const char ObjectBase<TypedObject<jobjectArray>, jobjectArray>::name[] = "[Ljava/lang/Object;";
 template<> const char ObjectBase<ByteBuffer, jobject>::name[] = "java/nio/ByteBuffer";
 
-
+JavaVM* sJavaVM;
 JNIEnv* sGeckoThreadEnv;
 
 namespace {
 
-JavaVM* sJavaVM;
 pthread_key_t sThreadEnvKey;
 jclass sOOMErrorClass;
 jobject sClassLoader;
 jmethodID sClassLoaderLoadClass;
 bool sIsFennec;
 
 void UnregisterThreadEnv(void* env)
 {
--- a/widget/android/jni/Utils.h
+++ b/widget/android/jni/Utils.h
@@ -58,23 +58,32 @@ enum class DispatchTarget
     // Call is dispatched asynchronously on the Gecko thread to the widget
     // (nsAppShell) event queue. In most cases, events in the widget event
     // queue (aka native event queue) are favored over events in the XPCOM
     // event queue. Method must return void.
     GECKO_PRIORITY,
 };
 
 
+extern JavaVM* sJavaVM;
 extern JNIEnv* sGeckoThreadEnv;
 
 inline bool IsAvailable()
 {
     return !!sGeckoThreadEnv;
 }
 
+inline JavaVM* GetVM()
+{
+#ifdef MOZ_CHECK_JNI
+    MOZ_ASSERT(sJavaVM);
+#endif
+    return sJavaVM;
+}
+
 inline JNIEnv* GetGeckoThreadEnv()
 {
 #ifdef MOZ_CHECK_JNI
     MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Must be on Gecko thread");
     MOZ_RELEASE_ASSERT(sGeckoThreadEnv, "Must have a JNIEnv");
 #endif
     return sGeckoThreadEnv;
 }
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -20,34 +20,32 @@ XPIDL_SOURCES += [
     'nsIAndroidBridge.idl',
 ]
 
 XPIDL_MODULE = 'widget_android'
 
 EXPORTS += [
     'AndroidBridge.h',
     'AndroidJavaWrappers.h',
-    'AndroidJNIWrapper.h',
     'GeneratedJNINatives.h',
     'GeneratedJNIWrappers.h',
 ]
 
 EXPORTS.mozilla.widget += [
     'AndroidCompositorWidget.h',
     'AndroidUiThread.h',
 ]
 
 UNIFIED_SOURCES += [
     'AndroidAlerts.cpp',
     'AndroidBridge.cpp',
     'AndroidCompositorWidget.cpp',
     'AndroidContentController.cpp',
     'AndroidJavaWrappers.cpp',
     'AndroidJNI.cpp',
-    'AndroidJNIWrapper.cpp',
     'AndroidUiThread.cpp',
     'ANRReporter.cpp',
     'EventDispatcher.cpp',
     'GeckoEditableSupport.cpp',
     'GeneratedJNIWrappers.cpp',
     'GfxInfo.cpp',
     'nsAndroidProtocolHandler.cpp',
     'nsAppShell.cpp',