Bug 1497977 p2 - Handle fxaccounts:password_changed push messages. r=nalexander
authorEdouard Oger <eoger@fastmail.com>
Wed, 17 Oct 2018 18:22:59 +0000
changeset 500266 e720c16aa7c6da10135d26da34cd4030b2c83713
parent 500265 3901ae585e3ae25f76b20e0fb8f44f1a9a4dfff0
child 500267 5238702906f63d95d2fae62f33aa53cb61de7e49
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1497977
milestone64.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 1497977 p2 - Handle fxaccounts:password_changed push messages. r=nalexander Depends on D8606 Differential Revision: https://phabricator.services.mozilla.com/D8607
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FirefoxAccountsUtils.java
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FirefoxAccountsUtils.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FirefoxAccountsUtils.java
@@ -91,21 +91,21 @@ public class FirefoxAccountsUtils {
             return false;
         }
 
         Logger.info(LOG_TAG, "Pickle file absent; separating the account.");
         separateAccountAndShowNotification(context, fxAccount);
         return true;
     }
 
-    private static void separateAccountAndShowNotification(final Context context, final AndroidFxAccount fxAccount) {
+    public static void separateAccountAndShowNotification(final Context context, final AndroidFxAccount fxAccount) {
         final State currentState = fxAccount.getState();
         // Avoid work if we're already in the correct state.
         if (!(currentState instanceof Separated)) {
-            fxAccount.setState(new Separated(fxAccount.getEmail(), currentState.uid, currentState.verified));
+            fxAccount.setState(currentState.makeSeparatedState());
         }
         final FxAccountNotificationManager notificationManager = new FxAccountNotificationManager(
                 FxAccountSyncAdapter.NOTIFICATION_ID);
         notificationManager.update(context, fxAccount);
     }
 
     private static PickleFileState queryPickleFileState(final Context context) {
         final CountDownLatch latch = new CountDownLatch(1);
--- 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
@@ -1,29 +1,29 @@
 package org.mozilla.gecko.fxa;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.content.Context;
-import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import android.util.Log;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.fxa.devices.FxAccountDeviceListUpdater;
 import org.mozilla.gecko.util.GeckoBundle;
 
 public class FxAccountPushHandler {
     private static final String LOG_TAG = "FxAccountPush";
 
     private static final String COMMAND_DEVICE_DISCONNECTED = "fxaccounts:device_disconnected";
     private static final String COMMAND_PROFILE_UPDATED = "fxaccounts:profile_updated";
+    private static final String COMMAND_PASSWORD_CHANGED = "fxaccounts:password_changed";
     private static final String COMMAND_COLLECTION_CHANGED = "sync:collection_changed";
 
     private static final String CLIENTS_COLLECTION = "clients";
 
     // Forbid instantiation
     private FxAccountPushHandler() {}
 
     public static void handleFxAPushMessage(Context context, GeckoBundle bundle) {
@@ -52,16 +52,19 @@ public class FxAccountPushHandler {
                     handleDeviceDisconnection(context, message.getJSONObject("data"));
                     break;
                 case COMMAND_COLLECTION_CHANGED:
                     handleCollectionChanged(context, message.getJSONObject("data"));
                     break;
                 case COMMAND_PROFILE_UPDATED:
                     handleProfileUpdated(context);
                     break;
+                case COMMAND_PASSWORD_CHANGED:
+                    handlePasswordChanged(context);
+                    break;
                 default:
                     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);
         }
     }
@@ -116,9 +119,19 @@ public class FxAccountPushHandler {
             // an updated FxA devices list in order to have an up-to-date clients list in the UI.
             Log.i(LOG_TAG, "Another device in the account got disconnected, refreshing FxA device list.");
             final FxAccountDeviceListUpdater deviceListUpdater = new FxAccountDeviceListUpdater(fxAccount, context.getContentResolver());
             deviceListUpdater.update();
             return;
         }
         AccountManager.get(context).removeAccount(account, null, null);
     }
+
+    private static void handlePasswordChanged(Context context) {
+        final Account account = FirefoxAccounts.getFirefoxAccount(context);
+        if (account == null) {
+            Log.e(LOG_TAG, "The account does not exist anymore");
+            return;
+        }
+        final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
+        FirefoxAccountsUtils.separateAccountAndShowNotification(context, fxAccount);
+    }
 }