Bug 1280446 - Create PushService if needed; r=snorp, a=gchang
authorJim Chen <nchen@mozilla.com>
Tue, 05 Jul 2016 14:34:57 -0400
changeset 339904 0ad38f4e2b4d6bb798fdb13b1fa53cfc8aebe2c7
parent 339903 3366b3cde4918ef217a57293f1cc9bd9a6656bcb
child 339905 193762e3a279d424023b85b0ac86f9bb0e0e1687
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, gchang
bugs1280446
milestone49.0a2
Bug 1280446 - Create PushService if needed; r=snorp, a=gchang If PushService has not been created when getInstance is called, create the PushService instead of throwing an error. This fixes a possible race condition between initializing PushService and receiving a push message, where we can receive a push message first.
mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
mobile/android/base/java/org/mozilla/gecko/push/PushService.java
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmInstanceIDListenerService.java
@@ -23,13 +23,13 @@ public class GcmInstanceIDListenerServic
      * InstanceID provider.
      */
     @Override
     public void onTokenRefresh() {
         Log.d("GeckoPushGCM", "Token refresh request received.  Processing on background thread.");
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                PushService.getInstance().onRefresh();
+                PushService.getInstance(GcmInstanceIDListenerService.this).onRefresh();
             }
         });
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
@@ -25,14 +25,14 @@ public class GcmMessageListenerService e
      * @param bundle Data bundle containing message data as key/value pairs.
      */
     @Override
     public void onMessageReceived(final String from, final Bundle bundle) {
         Log.d("GeckoPushGCM", "Message received.  Processing on background thread.");
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
-                PushService.getInstance().onMessageReceived(
+                PushService.getInstance(GcmMessageListenerService.this).onMessageReceived(
                         GcmMessageListenerService.this, bundle);
             }
         });
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/push/PushService.java
@@ -61,19 +61,19 @@ public class PushService implements Bund
             "PushServiceAndroidGCM:Uninitialized",
             "PushServiceAndroidGCM:RegisterUserAgent",
             "PushServiceAndroidGCM:UnregisterUserAgent",
             "PushServiceAndroidGCM:SubscribeChannel",
             "PushServiceAndroidGCM:UnsubscribeChannel",
             "History:GetPrePathLastVisitedTimeMilliseconds",
     };
 
-    public static synchronized PushService getInstance() {
+    public static synchronized PushService getInstance(Context context) {
         if (sInstance == null) {
-            throw new IllegalStateException("PushService not yet created!");
+            onCreate(context);
         }
         return sInstance;
     }
 
     @ReflectionTarget
     public static synchronized void onCreate(Context context) {
         if (sInstance != null) {
             throw new IllegalStateException("PushService already created!");