Bug 1513242 - Queue native calls in GeckoSystemStateListener r=geckoview-reviewers,esawin, a=RyanVM
authorJames Willcox <snorp@snorp.net>
Tue, 11 Dec 2018 20:33:52 +0000
changeset 506213 d48cfac9b2f00460a83549c07980769ee59c742f
parent 506212 d0e252ea5c9337f3df5e3d2a8d46582f036a86e1
child 506214 405ee85a224774b173f440cf225f37108073c0ac
push id10333
push userryanvm@gmail.com
push dateThu, 13 Dec 2018 23:22:04 +0000
treeherdermozilla-beta@aea4a31fb8bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, esawin, RyanVM
bugs1513242
milestone65.0
Bug 1513242 - Queue native calls in GeckoSystemStateListener r=geckoview-reviewers,esawin, a=RyanVM Sometimes Gecko isn't running yet when we get our first notifications. Differential Revision: https://phabricator.services.mozilla.com/D14178
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoSystemStateListener.java
@@ -97,18 +97,28 @@ public class GeckoSystemStateListener
 
     @WrapForJNI(calledFrom = "gecko")
     private static void notifyPrefersReducedMotionChangedForTest() {
         ContentResolver contentResolver = sApplicationContext.getContentResolver();
         Uri animationSetting = Settings.System.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
         contentResolver.notifyChange(animationSetting, null);
     }
 
-    @WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
-    private static native void onDeviceChanged();
+    @WrapForJNI(stubName = "OnDeviceChanged", calledFrom = "ui", dispatchTo = "gecko")
+    private static native void nativeOnDeviceChanged();
+
+    private static void onDeviceChanged() {
+        if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
+            nativeOnDeviceChanged();
+        } else {
+            GeckoThread.queueNativeCallUntil(
+                    GeckoThread.State.PROFILE_READY, GeckoSystemStateListener.class,
+                    "nativeOnDeviceChanged");
+        }
+    }
 
     private void notifyDeviceChanged(int deviceId) {
         InputDevice device = InputDevice.getDevice(deviceId);
         if (device == null ||
             !InputDeviceUtils.isPointerTypeDevice(device)) {
             return;
         }
         onDeviceChanged();