Bug 1497977 p2 - Handle fxaccounts:password_changed push messages. r=nalexander

Depends on D8606

Differential Revision: https://phabricator.services.mozilla.com/D8607

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edouard Oger 2018-10-17 18:22:59 +00:00
Родитель 98a90c55ba
Коммит d2f39914ab
2 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -96,11 +96,11 @@ public class FirefoxAccountsUtils {
return true; 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(); final State currentState = fxAccount.getState();
// Avoid work if we're already in the correct state. // Avoid work if we're already in the correct state.
if (!(currentState instanceof Separated)) { if (!(currentState instanceof Separated)) {
fxAccount.setState(new Separated(fxAccount.getEmail(), currentState.uid, currentState.verified)); fxAccount.setState(currentState.makeSeparatedState());
} }
final FxAccountNotificationManager notificationManager = new FxAccountNotificationManager( final FxAccountNotificationManager notificationManager = new FxAccountNotificationManager(
FxAccountSyncAdapter.NOTIFICATION_ID); FxAccountSyncAdapter.NOTIFICATION_ID);

Просмотреть файл

@ -3,7 +3,6 @@ package org.mozilla.gecko.fxa;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -19,6 +18,7 @@ public class FxAccountPushHandler {
private static final String COMMAND_DEVICE_DISCONNECTED = "fxaccounts:device_disconnected"; 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_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 COMMAND_COLLECTION_CHANGED = "sync:collection_changed";
private static final String CLIENTS_COLLECTION = "clients"; private static final String CLIENTS_COLLECTION = "clients";
@ -57,6 +57,9 @@ public class FxAccountPushHandler {
case COMMAND_PROFILE_UPDATED: case COMMAND_PROFILE_UPDATED:
handleProfileUpdated(context); handleProfileUpdated(context);
break; break;
case COMMAND_PASSWORD_CHANGED:
handlePasswordChanged(context);
break;
default: default:
Log.d(LOG_TAG, "No handler defined for FxA Push command " + command); Log.d(LOG_TAG, "No handler defined for FxA Push command " + command);
break; break;
@ -121,4 +124,14 @@ public class FxAccountPushHandler {
} }
AccountManager.get(context).removeAccount(account, null, null); 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);
}
} }