Bug 1017242 - Part A: remove API 8 code from webapp Allocator. r=myk
authorRichard Newman <rnewman@mozilla.com>
Fri, 18 Jul 2014 16:47:10 -0700
changeset 195063 8bb625db40152d1f5d61aa54ade10862e98c9115
parent 195062 6bfbded8be02dbb3f9c8accf56cf31c798b00607
child 195064 6d78d2be19f674c51d46096c3dafbde3137ed9d7
push id27168
push userryanvm@gmail.com
push dateSun, 20 Jul 2014 22:30:25 +0000
treeherdermozilla-central@e9cdcf646d1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs1017242
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1017242 - Part A: remove API 8 code from webapp Allocator. r=myk
mobile/android/base/webapp/Allocator.java
--- a/mobile/android/base/webapp/Allocator.java
+++ b/mobile/android/base/webapp/Allocator.java
@@ -65,29 +65,16 @@ public class Allocator {
     private static String oldAppKey(int index) {
         return PREFIX_OLD_APP + index;
     }
 
     private static String oldIconKey(int index) {
         return PREFIX_OLD_ICON + index;
     }
 
-    private static void save(Editor editor) {
-        // Use SharedPreferences.Editor.apply() where available and commit()
-        // where it isn't.  We could also use a background thread with commit(),
-        // but our callers might expect the changes we make to be available
-        // immediately, so we instead take the commit() performance hit
-        // on the small percentage of extant devices that don't support apply().
-        if (android.os.Build.VERSION.SDK_INT > 8) {
-            editor.apply();
-        } else {
-            editor.commit();
-        }
-    }
-
     public ArrayList<String> getInstalledPackageNames() {
         ArrayList<String> installedPackages = new ArrayList<String>();
 
         for (int i = 0; i < MAX_WEB_APPS; ++i) {
             if (mPrefs.contains(appKey(i))) {
                 installedPackages.add(mPrefs.getString(appKey(i), ""));
             }
         }
@@ -107,21 +94,21 @@ public class Allocator {
             }
         }
 
         // no more apps!
         return -1;
     }
 
     public synchronized void putPackageName(final int index, final String packageName) {
-        save(mPrefs.edit().putString(appKey(index), packageName));
+        mPrefs.edit().putString(appKey(index), packageName).apply();
     }
 
     public void updateColor(int index, int color) {
-        save(mPrefs.edit().putInt(iconKey(index), color));
+        mPrefs.edit().putInt(iconKey(index), color).apply();
     }
 
     public synchronized int getIndexForApp(String packageName) {
         return findSlotForPrefix(PREFIX_PACKAGE_NAME, packageName);
     }
 
     public synchronized int getIndexForOrigin(String origin) {
         return findSlotForPrefix(PREFIX_ORIGIN, origin);
@@ -145,21 +132,21 @@ public class Allocator {
         if (index == -1)
             return -1;
 
         releaseIndex(index);
         return index;
     }
 
     public synchronized void releaseIndex(final int index) {
-        save(mPrefs.edit().remove(appKey(index)).remove(iconKey(index)).remove(originKey(index)));
+        mPrefs.edit().remove(appKey(index)).remove(iconKey(index)).remove(originKey(index)).apply();
     }
 
     public void putOrigin(int index, String origin) {
-        save(mPrefs.edit().putString(originKey(index), origin));
+        mPrefs.edit().putString(originKey(index), origin).apply();
     }
 
     public String getOrigin(int index) {
         return mPrefs.getString(originKey(index), null);
     }
 
     public int getColor(int index) {
         return mPrefs.getInt(iconKey(index), -1);
@@ -180,11 +167,11 @@ public class Allocator {
         // stores the packageName, so we migrate oldAppKey to the origin pref.
         putOrigin(index, mPrefs.getString(oldAppKey(index), null));
 
         // The old iconKey pref actually stored the splash screen background
         // color, so we migrate oldIconKey to the color pref.
         updateColor(index, mPrefs.getInt(oldIconKey(index), -1));
 
         // Remove the old prefs so we don't migrate them the next time around.
-        save(mPrefs.edit().remove(oldAppKey(index)).remove(oldIconKey(index)));
+        mPrefs.edit().remove(oldAppKey(index)).remove(oldIconKey(index)).apply();
     }
 }