From 89ada9791087c8004f300ddd9e8ba58fbc84eaae Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Wed, 3 Oct 2012 11:42:52 -0400 Subject: fix NPE un stream unpacking failure. Bug: 7242346 Change-Id: I5f27baba860081111224b7312cfef027c1312264 --- src/com/android/dreams/phototable/PhotoSource.java | 64 ++++++++++++---------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java index 06dd816..21c6646 100644 --- a/src/com/android/dreams/phototable/PhotoSource.java +++ b/src/com/android/dreams/phototable/PhotoSource.java @@ -163,38 +163,46 @@ public abstract class PhotoSource { image = BitmapFactory.decodeStream(bis, null, options); rawLongSide = Math.max(options.outWidth, options.outHeight); rawShortSide = Math.max(options.outWidth, options.outHeight); - ratio = Math.max((float) longSide / (float) rawLongSide, - (float) shortSide / (float) rawShortSide); - - if (Math.abs(ratio - 1.0f) > 0.001) { - log(TAG, "still too big, scaling down by " + ratio); - options.outWidth = (int) (ratio * options.outWidth); - options.outHeight = (int) (ratio * options.outHeight); - - image = Bitmap.createScaledBitmap(image, - options.outWidth, options.outHeight, - true); - } + if (image != null && rawLongSide != -1 && rawShortSide != -1) { + ratio = Math.max((float) longSide / (float) rawLongSide, + (float) shortSide / (float) rawShortSide); + + if (Math.abs(ratio - 1.0f) > 0.001) { + log(TAG, "still too big, scaling down by " + ratio); + options.outWidth = (int) (ratio * options.outWidth); + options.outHeight = (int) (ratio * options.outHeight); + + image = Bitmap.createScaledBitmap(image, + options.outWidth, options.outHeight, + true); + } - if (data.orientation != 0) { - log(TAG, "rotated by " + data.orientation + ": fixing"); - if (data.orientation == 90 || data.orientation == 270) { - int tmp = options.outWidth; - options.outWidth = options.outHeight; - options.outHeight = tmp; + if (data.orientation != 0) { + log(TAG, "rotated by " + data.orientation + ": fixing"); + if (data.orientation == 90 || data.orientation == 270) { + int tmp = options.outWidth; + options.outWidth = options.outHeight; + options.outHeight = tmp; + } + Matrix matrix = new Matrix(); + matrix.setRotate(data.orientation, + (float) image.getWidth() / 2, + (float) image.getHeight() / 2); + image = Bitmap.createBitmap(image, 0, 0, + options.outHeight, options.outWidth, + matrix, true); } - Matrix matrix = new Matrix(); - matrix.setRotate(data.orientation, - (float) image.getWidth() / 2, - (float) image.getHeight() / 2); - image = Bitmap.createBitmap(image, 0, 0, - options.outHeight, options.outWidth, - matrix, true); - } - log(TAG, "returning bitmap " + image.getWidth() + ", " + image.getHeight()); + log(TAG, "returning bitmap " + image.getWidth() + ", " + image.getHeight()); + } else { + image = null; + } } else { - log(TAG, "decoding failed with no error: " + options.mCancel); + image = null; + } + if (image == null) { + log(TAG, "Stream decoding failed with no error" + + (options.mCancel ? " due to cancelation." : ".")); } } catch (FileNotFoundException fnf) { log(TAG, "file not found: " + fnf); -- cgit v1.2.3