зеркало из https://github.com/mozilla/gecko-dev.git
66 строки
2.5 KiB
Java
66 строки
2.5 KiB
Java
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.gecko.fxa.receivers;
|
|
|
|
import org.mozilla.gecko.background.common.log.Logger;
|
|
import org.mozilla.gecko.fxa.FxAccountConstants;
|
|
import org.mozilla.gecko.sync.config.AccountPickler;
|
|
|
|
import android.app.IntentService;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
|
|
/**
|
|
* A background service to clean up after a Firefox Account is deleted.
|
|
* <p>
|
|
* Note that we specifically handle deleting the pickle file using a Service and a
|
|
* BroadcastReceiver, rather than a background thread, to allow channels sharing a Firefox account
|
|
* to delete their respective pickle files (since, if one remains, the account will be restored
|
|
* when that channel is used).
|
|
*/
|
|
public class FxAccountDeletedService extends IntentService {
|
|
public static final String LOG_TAG = FxAccountDeletedService.class.getSimpleName();
|
|
|
|
public FxAccountDeletedService() {
|
|
super(LOG_TAG);
|
|
}
|
|
|
|
@Override
|
|
protected void onHandleIntent(final Intent intent) {
|
|
final Context context = this;
|
|
|
|
long intentVersion = intent.getLongExtra(
|
|
FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION_KEY, 0);
|
|
long expectedVersion = FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION;
|
|
if (intentVersion != expectedVersion) {
|
|
Logger.warn(LOG_TAG, "Intent malformed: version " + intentVersion + " given but " +
|
|
"version " + expectedVersion + "expected. Not cleaning up after deleted Account.");
|
|
return;
|
|
}
|
|
|
|
// Android Account name, not Sync encoded account name.
|
|
final String accountName = intent.getStringExtra(
|
|
FxAccountConstants.ACCOUNT_DELETED_INTENT_ACCOUNT_KEY);
|
|
if (accountName == null) {
|
|
Logger.warn(LOG_TAG, "Intent malformed: no account name given. Not cleaning up after " +
|
|
"deleted Account.");
|
|
return;
|
|
}
|
|
|
|
Logger.info(LOG_TAG, "Firefox account named " + accountName + " being removed; " +
|
|
"deleting saved pickle file '" + FxAccountConstants.ACCOUNT_PICKLE_FILENAME + "'.");
|
|
deletePickle(context);
|
|
}
|
|
|
|
public static void deletePickle(final Context context) {
|
|
try {
|
|
AccountPickler.deletePickle(context, FxAccountConstants.ACCOUNT_PICKLE_FILENAME);
|
|
} catch (Exception e) {
|
|
// This should never happen, but we really don't want to die in a background thread.
|
|
Logger.warn(LOG_TAG, "Got exception deleting saved pickle file; ignoring.", e);
|
|
}
|
|
}
|
|
}
|