Ejemplo n.º 1
0
  /**
   * Persist Firefox account to disk as a JSON object.
   *
   * @param AndroidFxAccount the account to persist to disk
   * @param filename name of file to persist to; must not contain path separators.
   */
  public static void pickle(final AndroidFxAccount account, final String filename) {
    final ExtendedJSONObject o = new ExtendedJSONObject();
    o.put(KEY_PICKLE_VERSION, Long.valueOf(PICKLE_VERSION));
    o.put(KEY_PICKLE_TIMESTAMP, Long.valueOf(System.currentTimeMillis()));

    o.put(KEY_ACCOUNT_VERSION, AndroidFxAccount.CURRENT_ACCOUNT_VERSION);
    o.put(KEY_ACCOUNT_TYPE, FxAccountConstants.ACCOUNT_TYPE);
    o.put(KEY_EMAIL, account.getEmail());
    o.put(KEY_PROFILE, account.getProfile());
    o.put(KEY_IDP_SERVER_URI, account.getAccountServerURI());
    o.put(KEY_TOKEN_SERVER_URI, account.getTokenServerURI());
    o.put(KEY_IS_SYNCING_ENABLED, account.isSyncing());

    // TODO: If prefs version changes under us, SyncPrefsPath will change, "clearing" prefs.

    final ExtendedJSONObject bundle = account.unbundle();
    if (bundle == null) {
      Logger.warn(LOG_TAG, "Unable to obtain account bundle; aborting.");
      return;
    }
    o.put(KEY_BUNDLE, bundle);

    writeToDisk(account.context, filename, o);
  }