Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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/. */
5 package org.mozilla.gecko.sync;
7 import org.mozilla.gecko.background.common.GlobalConstants;
8 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
10 import android.content.SharedPreferences;
12 /**
13 * A <code>ClientsDataDelegate</code> implementation that persists to a
14 * <code>SharedPreferences</code> instance.
15 */
16 public class SharedPreferencesClientsDataDelegate implements ClientsDataDelegate {
17 protected final SharedPreferences sharedPreferences;
19 public SharedPreferencesClientsDataDelegate(SharedPreferences sharedPreferences) {
20 this.sharedPreferences = sharedPreferences;
21 }
23 @Override
24 public synchronized String getAccountGUID() {
25 String accountGUID = sharedPreferences.getString(SyncConfiguration.PREF_ACCOUNT_GUID, null);
26 if (accountGUID == null) {
27 accountGUID = Utils.generateGuid();
28 sharedPreferences.edit().putString(SyncConfiguration.PREF_ACCOUNT_GUID, accountGUID).commit();
29 }
30 return accountGUID;
31 }
33 @Override
34 public synchronized String getClientName() {
35 String clientName = sharedPreferences.getString(SyncConfiguration.PREF_CLIENT_NAME, null);
36 if (clientName == null) {
37 clientName = GlobalConstants.MOZ_APP_DISPLAYNAME + " on " + android.os.Build.MODEL;
38 sharedPreferences.edit().putString(SyncConfiguration.PREF_CLIENT_NAME, clientName).commit();
39 }
40 return clientName;
41 }
43 @Override
44 public synchronized void setClientsCount(int clientsCount) {
45 sharedPreferences.edit().putLong(SyncConfiguration.PREF_NUM_CLIENTS, (long) clientsCount).commit();
46 }
48 @Override
49 public boolean isLocalGUID(String guid) {
50 return getAccountGUID().equals(guid);
51 }
53 @Override
54 public synchronized int getClientsCount() {
55 return (int) sharedPreferences.getLong(SyncConfiguration.PREF_NUM_CLIENTS, 0);
56 }
57 }