Bug 1140243 - Refactor default client name in FxAccountUtils. r=nalexander, a=readinglist
authorRichard Newman <rnewman@mozilla.com>
Fri, 06 Mar 2015 10:05:13 -0800
changeset 262331 01153eab1ffaff31ae905dad32951baa77270a2d
parent 262330 571b6e13c58c0f13b52b974bf6f17b3bf1624827
child 262332 c4e811a11277cab3eabcdd94f0044c43dfb752b5
push id1963
push userpaolo.mozmail@amadzone.org
push dateSun, 10 May 2015 10:26:20 +0000
reviewersnalexander, readinglist
bugs1140243
milestone38.0a2
Bug 1140243 - Refactor default client name in FxAccountUtils. r=nalexander, a=readinglist
mobile/android/base/background/fxa/FxAccountUtils.java
mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java
--- a/mobile/android/base/background/fxa/FxAccountUtils.java
+++ b/mobile/android/base/background/fxa/FxAccountUtils.java
@@ -7,23 +7,29 @@ package org.mozilla.gecko.background.fxa
 import java.io.UnsupportedEncodingException;
 import java.math.BigInteger;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.security.GeneralSecurityException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 
+import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.R.string;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.nativecode.NativeCrypto;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.crypto.HKDF;
 import org.mozilla.gecko.sync.crypto.KeyBundle;
 import org.mozilla.gecko.sync.crypto.PBKDF2;
 
+import android.content.Context;
+import android.os.Build;
+
 public class FxAccountUtils {
   private static final String LOG_TAG = FxAccountUtils.class.getSimpleName();
 
   public static final int SALT_LENGTH_BYTES = 32;
   public static final int SALT_LENGTH_HEX = 2 * SALT_LENGTH_BYTES;
 
   public static final int HASH_LENGTH_BYTES = 16;
   public static final int HASH_LENGTH_HEX = 2 * HASH_LENGTH_BYTES;
@@ -192,9 +198,22 @@ public class FxAccountUtils {
    * @param serverURI endpoint.
    * @return BrowserID audience.
    * @throws URISyntaxException
    */
   public static String getAudienceForURL(String serverURI) throws URISyntaxException {
     URI uri = new URI(serverURI);
     return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), null, null, null).toString();
   }
+
+  public static String defaultClientName(Context context) {
+    String name = AppConstants.MOZ_APP_DISPLAYNAME; // The display name is never translated.
+    // Change "Firefox Aurora" or similar into "Aurora".
+    if (name.contains("Aurora")) {
+        name = "Aurora";
+    } else if (name.contains("Beta")) {
+        name = "Beta";
+    } else if (name.contains("Nightly")) {
+        name = "Nightly";
+    }
+    return context.getResources().getString(R.string.sync_default_client_name, name, android.os.Build.MODEL);
+  }
 }
--- a/mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java
+++ b/mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java
@@ -1,16 +1,15 @@
 /* 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.sync;
 
-import org.mozilla.gecko.AppConstants;
-import org.mozilla.gecko.R;
+import org.mozilla.gecko.background.fxa.FxAccountUtils;
 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
 import org.mozilla.gecko.util.HardwareUtils;
 
 import android.content.Context;
 import android.content.SharedPreferences;
 
 /**
  * A <code>ClientsDataDelegate</code> implementation that persists to a
@@ -49,26 +48,17 @@ public class SharedPreferencesClientsDat
       .edit()
       .putString(SyncConfiguration.PREF_CLIENT_NAME, clientName)
       .putLong(SyncConfiguration.PREF_CLIENT_DATA_TIMESTAMP, now)
       .commit();
   }
 
   @Override
   public String getDefaultClientName() {
-    String name = AppConstants.MOZ_APP_DISPLAYNAME; // The display name is never translated.
-    // Change "Firefox Aurora" or similar into "Aurora".
-    if (name.contains("Aurora")) {
-        name = "Aurora";
-    } else if (name.contains("Beta")) {
-        name = "Beta";
-    } else if (name.contains("Nightly")) {
-        name = "Nightly";
-    }
-    return context.getResources().getString(R.string.sync_default_client_name, name, android.os.Build.MODEL);
+    return FxAccountUtils.defaultClientName(context);
   }
 
   @Override
   public synchronized String getClientName() {
     String clientName = sharedPreferences.getString(SyncConfiguration.PREF_CLIENT_NAME, null);
     if (clientName == null) {
       clientName = getDefaultClientName();
       long now = System.currentTimeMillis();