DO NOT MERGE Harden thumbnail creation
* Catch some errors earlier; Log all errors. Bug: 2905324 Backport from master: Icdf4ec881f404787a0621e606d7e611d5e50aab1 Change-Id: I817a770da2d158984476cfa2b10a5de6bc0b43f8
This commit is contained in:
parent
16657c9c20
commit
ed824a07ae
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user