Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8356898b authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Gerrit Code Review
Browse files

WallpaperCropper: handle decoding errors for preview generation

Repro:
 - Open wallpaper picker
 - Select "Pick image"
 - In DocumentsUI, open drawer and select "Photos" app
 - Select incompatible file (e.g. video, gif)
 - Observe: Force Close

Change-Id: Ibd873ddfd631a4bd8ba53fc22c7d543e6702cd00
parent c07c92fa
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -41,4 +41,7 @@
    <string name="activity_not_found">App isn\'t installed.</string>
    <!-- Button label on LockWallpaper picker screen to set a lockscreen wallpaper -->
    <string name="lockscreen_wallpaper_instructions">Set lock screen wallpaper</string>

    <!-- Image load error: e.g. decoding mp4 file -->
    <string name="image_decode_error">Unable to decode image</string>
</resources>
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -31,10 +31,12 @@ import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.util.Log;

import android.widget.Toast;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.glrenderer.BasicTexture;
import com.android.gallery3d.glrenderer.BitmapTexture;
import com.android.photos.views.TiledImageRenderer;
import com.android.wallpapercropper.R;
import com.android.wallpapercropper.Utilities;

import java.io.BufferedInputStream;
@@ -130,6 +132,12 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource {
            // loaded, the lifecycle is different and interactions are on a different
            // thread. Thus to simplify, this source will decode its own bitmap.
            Bitmap preview = decodePreview(res, context, path, uri, resId, previewSize, assetPath);
            if (preview == null) {
                Toast.makeText(context,
                        context.getResources().getString(R.string.image_decode_error),
                        Toast.LENGTH_SHORT).show();
                return;
            }
            if (preview.getWidth() <= GL_SIZE_LIMIT && preview.getHeight() <= GL_SIZE_LIMIT) {
                mPreview = new BitmapTexture(preview);
            } else {