Bug 1505897 - Initialize GeckoSystemStateListener in child process r=agi
authorJames Willcox <snorp@snorp.net>
Fri, 16 Nov 2018 14:34:48 +0000
changeset 503217 766dc4a5e8f0a70985c1dc6fe781c17c8587602f
parent 503216 624e45ad97c89acc0b916c3c7c53b95cdb1f5014
child 503218 d1cbe1578a464515dadc6e66a107d55b55ab0e2b
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagi
bugs1505897
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505897 - Initialize GeckoSystemStateListener in child process r=agi Differential Revision: https://phabricator.services.mozilla.com/D11517
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
widget/android/nsAppShell.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
@@ -6,16 +6,17 @@
 package org.mozilla.gecko;
 
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.hardware.input.InputManager;
 import android.net.Uri;
 import android.os.Handler;
+import android.os.Looper;
 import android.provider.Settings;
 import android.util.Log;
 import android.view.InputDevice;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.util.InputDeviceUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 public class GeckoSystemStateListener
@@ -43,17 +44,17 @@ public class GeckoSystemStateListener
         }
         mInputManager = (InputManager)
             context.getSystemService(Context.INPUT_SERVICE);
         mInputManager.registerInputDeviceListener(listenerInstance, ThreadUtils.getUiHandler());
 
         sApplicationContext = context;
         ContentResolver contentResolver = sApplicationContext.getContentResolver();
         Uri animationSetting = Settings.System.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
-        mContentObserver = new ContentObserver(new Handler()) {
+        mContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
             @Override
             public void onChange(boolean selfChange) {
                 onDeviceChanged();
             }
         };
         contentResolver.registerContentObserver(animationSetting, false, mContentObserver);
 
         initialized = true;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
@@ -277,16 +277,18 @@ public class GeckoThread extends Thread 
         if (locale.toString().equalsIgnoreCase("zh_hk")) {
             final Locale mappedLocale = Locale.TRADITIONAL_CHINESE;
             Locale.setDefault(mappedLocale);
             Configuration config = res.getConfiguration();
             config.locale = mappedLocale;
             res.updateConfiguration(config, null);
         }
 
+        GeckoSystemStateListener.getInstance().initialize(context);
+
         final String resourcePath = context.getPackageResourcePath();
 
         try {
             loadGeckoLibs(context, resourcePath);
             return;
         } catch (final Exception e) {
             // Cannot load libs; try clearing the cached files.
             Log.w(LOGTAG, "Clearing cache after load libs exception", e);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
@@ -227,18 +227,16 @@ public final class GeckoRuntime implemen
         // Bug 1453062 -- the EventDispatcher should really live here (or in GeckoThread)
         EventDispatcher.getInstance().registerUiThreadListener(mEventListener, "Gecko:Exited");
 
         mSettings.runtime = this;
         mSettings.flush();
 
         // Initialize the system ClipboardManager by accessing it on the main thread.
         GeckoAppShell.getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
-
-        GeckoSystemStateListener.getInstance().initialize(context);
         return true;
     }
 
     /* package */ void setDefaultPrefs(GeckoBundle prefs) {
         EventDispatcher.getInstance().dispatch("GeckoView:SetDefaultPrefs", prefs);
     }
 
     /**
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -407,16 +407,17 @@ nsAppShell::nsAppShell()
     }
 
     hal::Init();
 
     if (!XRE_IsParentProcess()) {
         if (jni::IsAvailable()) {
             GeckoThreadSupport::Init();
             GeckoAppShellSupport::Init();
+            mozilla::GeckoSystemStateListener::Init();
             mozilla::widget::Telemetry::Init();
 
             // Set the corresponding state in GeckoThread.
             java::GeckoThread::SetState(java::GeckoThread::State::RUNNING());
         }
         return;
     }