Recover from bitmap decode failure.

 Skia errors out when decoding a bitmap into another bitmap
 sometimes. When this situation is detected, the decode is
 is retried without reusing a bitmap.

Change-Id: I935dec988ed7e115ceda9233a65d3b6083a17468
diff --git a/src/com/android/photos/data/BitmapDecoder.java b/src/com/android/photos/data/BitmapDecoder.java
index 3e5a0f7..c5101cd 100644
--- a/src/com/android/photos/data/BitmapDecoder.java
+++ b/src/com/android/photos/data/BitmapDecoder.java
@@ -97,13 +97,13 @@
 
     private static <T> Bitmap delegateDecode(Decoder<T> decoder, T input) {
         BitmapFactory.Options options = getOptions();
+        GalleryBitmapPool pool = GalleryBitmapPool.getInstance();
         try {
             options.inJustDecodeBounds = true;
             if (!decoder.decodeBounds(input, options)) {
                 return null;
             }
             options.inJustDecodeBounds = false;
-            GalleryBitmapPool pool = GalleryBitmapPool.getInstance();
             Bitmap reuseBitmap = pool.get(options.outWidth, options.outHeight);
             options.inBitmap = reuseBitmap;
             Bitmap decodedBitmap = decoder.decode(input, options);
@@ -111,6 +111,13 @@
                 pool.put(reuseBitmap);
             }
             return decodedBitmap;
+        } catch (IllegalArgumentException e) {
+            if (options.inBitmap == null) {
+                throw e;
+            }
+            pool.put(options.inBitmap);
+            options.inBitmap = null;
+            return decoder.decode(input, options);
         } finally {
             options.inBitmap = null;
             options.inJustDecodeBounds = false;