Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Thu, 02 Mar 2017 11:27:02 -0600
changeset 552478 d59f2627562afb95f2a50815c68343600b4f9bea
parent 503779 2e95b7e18fcf2b24844e484776c050e0d0c51e70
child 552479 e3860a4ae165205cd6f02c7755f6bc31c424180d
push id51353
push userbmo:snorp@snorp.net
push dateTue, 28 Mar 2017 13:31:07 +0000
reviewerssnorp
bugs1343075
milestone55.0a1
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r?snorp Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is the only Android-specific entry point for child processes, so I think it's the most logical place to initialize JNI.
widget/android/nsAppShell.cpp
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -389,17 +389,17 @@ nsAppShell::nsAppShell()
         if (jni::IsAvailable()) {
             // Set the corresponding state in GeckoThread.
             java::GeckoThread::SetState(java::GeckoThread::State::RUNNING());
         }
         return;
     }
 
     if (jni::IsAvailable()) {
-        // Initialize JNI and Set the corresponding state in GeckoThread.
+        // Initialize JNI.
         AndroidBridge::ConstructBridge();
         GeckoAppShellSupport::Init();
         GeckoThreadSupport::Init();
         mozilla::GeckoBatteryManager::Init();
         mozilla::GeckoNetworkManager::Init();
         mozilla::GeckoProcessManager::Init();
         mozilla::GeckoScreenOrientation::Init();
         mozilla::PrefsHelper::Init();
@@ -407,19 +407,26 @@ nsAppShell::nsAppShell()
 
         if (jni::IsFennec()) {
             mozilla::ANRReporter::Init();
             mozilla::MemoryMonitor::Init();
             mozilla::widget::Telemetry::Init();
             mozilla::ThumbnailHelper::Init();
         }
 
-        java::GeckoThread::SetState(java::GeckoThread::State::JNI_READY());
+        CreateAndroidUiThread();
+    }
 
-        CreateAndroidUiThread();
+    if (jni::IsAvailable()) {
+        // Set the corresponding state in GeckoThread.
+        java::GeckoThread::SetState(java::GeckoThread::State::JNI_READY());
+    }
+
+    if (!XRE_IsParentProcess()) {
+        return;
     }
 
     sPowerManagerService = do_GetService(POWERMANAGERSERVICE_CONTRACTID);
 
     if (sPowerManagerService) {
         sWakeLockListener = new WakeLockListener();
     } else {
         NS_WARNING("Failed to retrieve PowerManagerService, wakelocks will be broken!");