Bug 720471 - Missing Arrays and SharedPreferences.Editor methods in Android SDK <= 8. r=rnewman
authorRichard Newman <rnewman@mozilla.com>
Wed, 25 Jan 2012 15:53:13 -0800
changeset 86634 6eecafcc7914f6dce2258eb0d3cd5459fda649b9
parent 86633 bcd88f12416d2683f6a0947ed26c23576b8e6968
child 86635 691af0af89da90c91ae9c007c4567ca3815b93ba
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs720471
milestone12.0a1
Bug 720471 - Missing Arrays and SharedPreferences.Editor methods in Android SDK <= 8. r=rnewman
mobile/android/base/sync/SyncConfiguration.java
mobile/android/base/sync/Utils.java
mobile/android/base/sync/crypto/HKDF.java
--- a/mobile/android/base/sync/SyncConfiguration.java
+++ b/mobile/android/base/sync/SyncConfiguration.java
@@ -58,19 +58,19 @@ public class SyncConfiguration implement
     public EditorBranch(SyncConfiguration config, String prefix) {
       if (!prefix.endsWith(".")) {
         throw new IllegalArgumentException("No trailing period in prefix.");
       }
       this.prefix = prefix;
       this.editor = config.getEditor();
     }
 
-    @Override
     public void apply() {
-      this.editor.apply();
+      // Android <=r8 SharedPreferences.Editor does not contain apply() for overriding.
+      this.editor.commit();
     }
 
     @Override
     public Editor clear() {
       this.editor = this.editor.clear();
       return this;
     }
 
--- a/mobile/android/base/sync/Utils.java
+++ b/mobile/android/base/sync/Utils.java
@@ -36,17 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko.sync;
 
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Random;
 
 import org.mozilla.apache.commons.codec.binary.Base32;
 import org.mozilla.apache.commons.codec.binary.Base64;
 import org.mozilla.gecko.sync.crypto.Cryptographer;
 
 import android.content.Context;
@@ -123,18 +122,20 @@ public class Utils {
    * Output: A concatenated version of them
    */
   public static byte[] concatAll(byte[] first, byte[]... rest) {
       int totalLength = first.length;
       for (byte[] array : rest) {
           totalLength += array.length;
       }
   
-      byte[] result = Arrays.copyOf(first, totalLength);
+      byte[] result = new byte[totalLength];
       int offset = first.length;
+
+      System.arraycopy(first, 0, result, 0, offset);
   
       for (byte[] array : rest) {
           System.arraycopy(array, 0, result, offset, array.length);
           offset += array.length;
       }
       return result;
   }
 
--- a/mobile/android/base/sync/crypto/HKDF.java
+++ b/mobile/android/base/sync/crypto/HKDF.java
@@ -35,17 +35,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko.sync.crypto;
 
 import java.security.InvalidKeyException;
 import java.security.Key;
 import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.mozilla.gecko.sync.Utils;
 
 
 /*
@@ -93,17 +92,19 @@ public class HKDF {
 
         int iterations = (int) Math.ceil(((double)len) / ((double)BLOCKSIZE));
         for (int i = 0; i < iterations; i++) {
             Tn = digestBytes(Utils.concatAll
                     (Tn, info, Utils.hex2Byte(Integer.toHexString(i + 1))), hmacHasher);
             T = Utils.concatAll(T, Tn);
         }
 
-        return Arrays.copyOfRange(T, 0, len);
+        byte[] result = new byte[len];
+        System.arraycopy(T, 0, result, 0, len);
+        return result;
     }
 
     /*
      * Make HMAC key
      * Input: key (salt)
      * Output: Key HMAC-Key
      */
     public static Key makeHMACKey(byte[] key) {