mobile/android/base/fxa/receivers/FxAccountDeletedService.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:009a336098d6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.gecko.fxa.receivers;
6
7 import org.mozilla.gecko.background.common.log.Logger;
8 import org.mozilla.gecko.fxa.FxAccountConstants;
9 import org.mozilla.gecko.sync.config.AccountPickler;
10
11 import android.app.IntentService;
12 import android.content.Context;
13 import android.content.Intent;
14
15 /**
16 * A background service to clean up after a Firefox Account is deleted.
17 * <p>
18 * Note that we specifically handle deleting the pickle file using a Service and a
19 * BroadcastReceiver, rather than a background thread, to allow channels sharing a Firefox account
20 * to delete their respective pickle files (since, if one remains, the account will be restored
21 * when that channel is used).
22 */
23 public class FxAccountDeletedService extends IntentService {
24 public static final String LOG_TAG = FxAccountDeletedService.class.getSimpleName();
25
26 public FxAccountDeletedService() {
27 super(LOG_TAG);
28 }
29
30 @Override
31 protected void onHandleIntent(final Intent intent) {
32 // Intent can, in theory, be null. Bug 1025937.
33 if (intent == null) {
34 Logger.debug(LOG_TAG, "Short-circuiting on null intent.");
35 return;
36 }
37
38 final Context context = this;
39
40 long intentVersion = intent.getLongExtra(
41 FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION_KEY, 0);
42 long expectedVersion = FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION;
43 if (intentVersion != expectedVersion) {
44 Logger.warn(LOG_TAG, "Intent malformed: version " + intentVersion + " given but " +
45 "version " + expectedVersion + "expected. Not cleaning up after deleted Account.");
46 return;
47 }
48
49 // Android Account name, not Sync encoded account name.
50 final String accountName = intent.getStringExtra(
51 FxAccountConstants.ACCOUNT_DELETED_INTENT_ACCOUNT_KEY);
52 if (accountName == null) {
53 Logger.warn(LOG_TAG, "Intent malformed: no account name given. Not cleaning up after " +
54 "deleted Account.");
55 return;
56 }
57
58 Logger.info(LOG_TAG, "Firefox account named " + accountName + " being removed; " +
59 "deleting saved pickle file '" + FxAccountConstants.ACCOUNT_PICKLE_FILENAME + "'.");
60 deletePickle(context);
61 }
62
63 public static void deletePickle(final Context context) {
64 try {
65 AccountPickler.deletePickle(context, FxAccountConstants.ACCOUNT_PICKLE_FILENAME);
66 } catch (Exception e) {
67 // This should never happen, but we really don't want to die in a background thread.
68 Logger.warn(LOG_TAG, "Got exception deleting saved pickle file; ignoring.", e);
69 }
70 }
71 }

mercurial