Bug 1346061 part 3 - Trigger a sync/email-verification-check on empty FxA push message. r?grisha, nalexander
MozReview-Commit-ID: ABUm6LZij4M
--- 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");