From ed824a07ae8389f1d9fb2214ad91356109b35a05 Mon Sep 17 00:00:00 2001 From: Andy Stadler Date: Wed, 22 Sep 2010 13:16:31 -0700 Subject: [PATCH] DO NOT MERGE Harden thumbnail creation * Catch some errors earlier; Log all errors. Bug: 2905324 Backport from master: Icdf4ec881f404787a0621e606d7e611d5e50aab1 Change-Id: I817a770da2d158984476cfa2b10a5de6bc0b43f8 --- .../android/email/activity/MessageView.java | 4 +-- .../email/provider/AttachmentProvider.java | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/com/android/email/activity/MessageView.java b/src/com/android/email/activity/MessageView.java index 959ba164e..482c742ca 100644 --- a/src/com/android/email/activity/MessageView.java +++ b/src/com/android/email/activity/MessageView.java @@ -954,9 +954,7 @@ public class MessageView extends Activity implements OnClickListener { 62))); } catch (Exception e) { - /* - * We don't care what happened, we just return null for the preview icon. - */ + Log.d(Email.LOG_TAG, "Attachment preview failed with exception " + e.getMessage()); return null; } } diff --git a/src/com/android/email/provider/AttachmentProvider.java b/src/com/android/email/provider/AttachmentProvider.java index 3b7818d74..2b3722a6e 100644 --- a/src/com/android/email/provider/AttachmentProvider.java +++ b/src/com/android/email/provider/AttachmentProvider.java @@ -35,6 +35,7 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.text.TextUtils; +import android.util.Log; import android.webkit.MimeTypeMap; import java.io.File; @@ -259,15 +260,21 @@ public class AttachmentProvider extends ContentProvider { InputStream in = getContext().getContentResolver().openInputStream(attachmentUri); Bitmap thumbnail = createThumbnail(type, in); + if (thumbnail == null) { + return null; + } thumbnail = Bitmap.createScaledBitmap(thumbnail, width, height, true); FileOutputStream out = new FileOutputStream(file); thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out); out.close(); in.close(); - } - catch (IOException ioe) { + } catch (IOException ioe) { + Log.d(Email.LOG_TAG, "openFile/thumbnail failed with " + ioe.getMessage()); return null; - } + } catch (OutOfMemoryError oome) { + Log.d(Email.LOG_TAG, "openFile/thumbnail failed with " + oome.getMessage()); + return null; + } } return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); } @@ -366,20 +373,15 @@ public class AttachmentProvider extends ContentProvider { try { Bitmap bitmap = BitmapFactory.decodeStream(data); return bitmap; - } - catch (OutOfMemoryError oome) { - /* - * Improperly downloaded images, corrupt bitmaps and the like can commonly - * cause OOME due to invalid allocation sizes. We're happy with a null bitmap in - * that case. If the system is really out of memory we'll know about it soon - * enough. - */ + } catch (OutOfMemoryError oome) { + Log.d(Email.LOG_TAG, "createImageThumbnail failed with " + oome.getMessage()); return null; - } - catch (Exception e) { + } catch (Exception e) { + Log.d(Email.LOG_TAG, "createImageThumbnail failed with " + e.getMessage()); return null; } } + /** * Resolve attachment id to content URI. Returns the resolved content URI (from the attachment * DB) or, if not found, simply returns the incoming value.