Bug 786826 - Use SharedPrefs.commit in WebAppAllocator for Eclair compatibility r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Mon, 24 Sep 2012 08:55:52 -0700
changeset 108026 e42062ef74330cc76131e01444a61b97c0456e1e
parent 108025 71b59b120de8751c99fa38ecd036df0e3b1cc8f4
child 108027 2c38bb9142ba82c07ba11b8c2d077139a3d6e35f
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersmfinkle
bugs786826
milestone18.0a1
Bug 786826 - Use SharedPrefs.commit in WebAppAllocator for Eclair compatibility r=mfinkle
mobile/android/base/WebAppAllocator.java
--- a/mobile/android/base/WebAppAllocator.java
+++ b/mobile/android/base/WebAppAllocator.java
@@ -10,16 +10,17 @@ import android.content.SharedPreferences
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.util.Base64;
 import android.util.Log;
 
 import java.io.FileOutputStream;
 
 import org.mozilla.gecko.gfx.BitmapUtils;
+import org.mozilla.gecko.util.GeckoBackgroundThread;
 
 public class WebAppAllocator {
     private final String LOGTAG = "GeckoWebAppAllocator";
     // The number of WebApp# and WEBAPP# activites/apps/intents
     private final static int MAX_WEB_APPS = 100;
 
     protected static GeckoApp sContext = null;
     protected static WebAppAllocator sInstance = null;
@@ -62,35 +63,40 @@ public class WebAppAllocator {
     }
 
     public synchronized int findAndAllocateIndex(String app, String name, String aIconData) {
         byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
         Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
         return findAndAllocateIndex(app, name, bitmap);
     }
 
-    public synchronized int findAndAllocateIndex(String app, String name, Bitmap aIcon) {
+    public synchronized int findAndAllocateIndex(final String app, final String name, final Bitmap aIcon) {
         int index = getIndexForApp(app);
         if (index != -1)
             return index;
 
-        int color = 0;
-        try {
-            color = BitmapUtils.getDominantColor(aIcon);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
         for (int i = 0; i < MAX_WEB_APPS; ++i) {
             if (!mPrefs.contains(appKey(i))) {
                 // found unused index i
-                mPrefs.edit()
-                    .putString(appKey(i), app)
-                    .putInt(iconKey(i), color)
-                    .apply();
+                final int foundIndex = i;
+                GeckoBackgroundThread.getHandler().post(new Runnable() {
+                    public void run() {
+                        int color = 0;
+                        try {
+                            color = BitmapUtils.getDominantColor(aIcon);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+
+                        mPrefs.edit()
+                            .putString(appKey(foundIndex), app)
+                            .putInt(iconKey(foundIndex), color)
+                            .commit();
+                    }
+                });
                 return i;
             }
         }
 
         // no more apps!
         return -1;
     }