mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.sync;
michael@0 6
michael@0 7 import org.mozilla.gecko.background.common.GlobalConstants;
michael@0 8 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
michael@0 9
michael@0 10 import android.content.SharedPreferences;
michael@0 11
michael@0 12 /**
michael@0 13 * A <code>ClientsDataDelegate</code> implementation that persists to a
michael@0 14 * <code>SharedPreferences</code> instance.
michael@0 15 */
michael@0 16 public class SharedPreferencesClientsDataDelegate implements ClientsDataDelegate {
michael@0 17 protected final SharedPreferences sharedPreferences;
michael@0 18
michael@0 19 public SharedPreferencesClientsDataDelegate(SharedPreferences sharedPreferences) {
michael@0 20 this.sharedPreferences = sharedPreferences;
michael@0 21 }
michael@0 22
michael@0 23 @Override
michael@0 24 public synchronized String getAccountGUID() {
michael@0 25 String accountGUID = sharedPreferences.getString(SyncConfiguration.PREF_ACCOUNT_GUID, null);
michael@0 26 if (accountGUID == null) {
michael@0 27 accountGUID = Utils.generateGuid();
michael@0 28 sharedPreferences.edit().putString(SyncConfiguration.PREF_ACCOUNT_GUID, accountGUID).commit();
michael@0 29 }
michael@0 30 return accountGUID;
michael@0 31 }
michael@0 32
michael@0 33 @Override
michael@0 34 public synchronized String getClientName() {
michael@0 35 String clientName = sharedPreferences.getString(SyncConfiguration.PREF_CLIENT_NAME, null);
michael@0 36 if (clientName == null) {
michael@0 37 clientName = GlobalConstants.MOZ_APP_DISPLAYNAME + " on " + android.os.Build.MODEL;
michael@0 38 sharedPreferences.edit().putString(SyncConfiguration.PREF_CLIENT_NAME, clientName).commit();
michael@0 39 }
michael@0 40 return clientName;
michael@0 41 }
michael@0 42
michael@0 43 @Override
michael@0 44 public synchronized void setClientsCount(int clientsCount) {
michael@0 45 sharedPreferences.edit().putLong(SyncConfiguration.PREF_NUM_CLIENTS, (long) clientsCount).commit();
michael@0 46 }
michael@0 47
michael@0 48 @Override
michael@0 49 public boolean isLocalGUID(String guid) {
michael@0 50 return getAccountGUID().equals(guid);
michael@0 51 }
michael@0 52
michael@0 53 @Override
michael@0 54 public synchronized int getClientsCount() {
michael@0 55 return (int) sharedPreferences.getLong(SyncConfiguration.PREF_NUM_CLIENTS, 0);
michael@0 56 }
michael@0 57 }

mercurial