Bug 1346061 part 3 - Trigger a sync/email-verification-check on empty FxA push message. r?grisha, nalexander draft
authorEdouard Oger <eoger@fastmail.com>
Wed, 22 Mar 2017 13:10:09 -0400
changeset 552540 a843bc051ed89bdcdee19702b466ffeea5e981c0
parent 552539 d49ddc1568ccd4f5d9079ecdd532c80cf6d190a6
child 621840 5eb5dfb164975e7debd52dec03acaff459fde8d0
push id51379
push userbmo:eoger@fastmail.com
push dateTue, 28 Mar 2017 16:39:50 +0000
reviewersgrisha, nalexander
bugs1346061
milestone55.0a1
Bug 1346061 part 3 - Trigger a sync/email-verification-check on empty FxA push message. r?grisha, nalexander MozReview-Commit-ID: ABUm6LZij4M
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
@@ -33,18 +33,18 @@ public class FxAccountPushHandler {
             } catch (JSONException e) {
                 Log.e(LOG_TAG, "Could not parse JSON", e);
                 return;
             }
         }
         if (message == null) {
             // An empty body means we should check the verification state of the account (FxA sends this
             // when the account email is verified for example).
-            // TODO: We're only registering the push endpoint when we are in the Married state, that's why we're skipping the message :(
-            Log.d(LOG_TAG, "Skipping empty message");
+            // See notifyUpdate in https://github.com/mozilla/fxa-auth-server/blob/master/lib/push.js
+            handleVerification(context);
             return;
         }
         try {
             String command = message.getString("command");
             JSONObject data = message.getJSONObject("data");
             switch (command) {
                 case COMMAND_DEVICE_DISCONNECTED:
                     handleDeviceDisconnection(context, data);
@@ -56,16 +56,27 @@ public class FxAccountPushHandler {
                     Log.d(LOG_TAG, "No handler defined for FxA Push command " + command);
                     break;
             }
         } catch (JSONException e) {
             Log.e(LOG_TAG, "Error while handling FxA push notification", e);
         }
     }
 
+    private static void handleVerification(Context context) {
+        AndroidFxAccount fxAccount = AndroidFxAccount.fromContext(context);
+        if (fxAccount == null) {
+            Log.e(LOG_TAG, "The Android account does not exist anymore");
+            return;
+        }
+        Log.i(LOG_TAG, "Received 'accountVerified' push event, requesting immediate sync");
+        // This will trigger an email verification check and a sync.
+        fxAccount.requestImmediateSync(null, null);
+    }
+
     private static void handleCollectionChanged(Context context, JSONObject data) throws JSONException {
         JSONArray collections = data.getJSONArray("collections");
         int len = collections.length();
         for (int i = 0; i < len; i++) {
             if (collections.getString(i).equals(CLIENTS_COLLECTION)) {
                 final Account account = FirefoxAccounts.getFirefoxAccount(context);
                 if (account == null) {
                     Log.e(LOG_TAG, "The account does not exist anymore");