Merge "Don't use SynchronousQueue to pass results." into gb-ub-photos-bryce
diff --git a/src/com/android/camera/ComboPreferences.java b/src/com/android/camera/ComboPreferences.java
index c561e6b..e17e47a 100644
--- a/src/com/android/camera/ComboPreferences.java
+++ b/src/com/android/camera/ComboPreferences.java
@@ -22,6 +22,8 @@
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.preference.PreferenceManager;
 
+import com.android.gallery3d.util.UsageStatistics;
+
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
@@ -205,9 +207,7 @@
 
     @Override
     public boolean contains(String key) {
-        if (mPrefLocal.contains(key)) return true;
-        if (mPrefGlobal.contains(key)) return true;
-        return false;
+        return mPrefLocal.contains(key) || mPrefGlobal.contains(key);
     }
 
     private class MyEditor implements Editor {
@@ -330,5 +330,6 @@
             listener.onSharedPreferenceChanged(this, key);
         }
         BackupManager.dataChanged(mPackageName);
+        UsageStatistics.onEvent("CameraSettingsChange", null, key);
     }
 }
diff --git a/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java b/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java
index 5e1fb34..30868c2 100644
--- a/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java
+++ b/src/com/android/gallery3d/ingest/data/MtpBitmapFetch.java
@@ -38,16 +38,28 @@
 
     public static Bitmap getThumbnail(MtpDevice device, MtpObjectInfo info) {
         byte[] imageBytes = device.getThumbnail(info.getObjectHandle());
-        if (imageBytes == null) return null;
+        if (imageBytes == null) {
+            return null;
+        }
         BitmapFactory.Options o = new BitmapFactory.Options();
         o.inJustDecodeBounds = true;
         BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o);
-        if (o.outWidth == 0 || o.outHeight == 0) return null;
+        if (o.outWidth == 0 || o.outHeight == 0) {
+            return null;
+        }
         o.inBitmap = GalleryBitmapPool.getInstance().get(o.outWidth, o.outHeight);
         o.inMutable = true;
         o.inJustDecodeBounds = false;
         o.inSampleSize = 1;
-        return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o);
+        try {
+            return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, o);
+        } catch (IllegalArgumentException e) {
+            // BitmapFactory throws an exception rather than returning null
+            // when image decoding fails and an existing bitmap was supplied
+            // for recycling, even if the failure was not caused by the use
+            // of that bitmap.
+            return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
+        }
     }
 
     public static BitmapWithMetadata getFullsize(MtpDevice device, MtpObjectInfo info) {
@@ -56,7 +68,9 @@
 
     public static BitmapWithMetadata getFullsize(MtpDevice device, MtpObjectInfo info, int maxSide) {
         byte[] imageBytes = device.getObject(info.getObjectHandle(), info.getCompressedSize());
-        if (imageBytes == null) return null;
+        if (imageBytes == null) {
+            return null;
+        }
         Bitmap created;
         if (maxSide > 0) {
             BitmapFactory.Options o = new BitmapFactory.Options();
@@ -76,7 +90,9 @@
         } else {
             created = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
         }
-        if (created == null) return null;
+        if (created == null) {
+            return null;
+        }
 
         return new BitmapWithMetadata(created, Exif.getOrientation(imageBytes));
     }
diff --git a/src/com/android/photos/data/GalleryBitmapPool.java b/src/com/android/photos/data/GalleryBitmapPool.java
index 4c3279f..a5a17ed 100644
--- a/src/com/android/photos/data/GalleryBitmapPool.java
+++ b/src/com/android/photos/data/GalleryBitmapPool.java
@@ -106,7 +106,7 @@
     }
 
     public boolean put(Bitmap b) {
-        if (b == null) {
+        if (b == null || b.getConfig() != Bitmap.Config.ARGB_8888) {
             return false;
         }
         SparseArrayBitmapPool pool = getPoolForDimensions(b.getWidth(), b.getHeight());