diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-08-21 11:33:50 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-08-23 12:19:19 -0700 |
commit | 6398343e83b3fd11dd6536cf6f390a52c1e19d2e (patch) | |
tree | fdb3b9d3c1ab6e4c0d59ae747e9b3e722ccf1ab0 /packages/ExternalStorageProvider | |
parent | bd3b902567b09379e1b62c60b3319ad82102efad (diff) | |
download | frameworks_base-6398343e83b3fd11dd6536cf6f390a52c1e19d2e.zip frameworks_base-6398343e83b3fd11dd6536cf6f390a52c1e19d2e.tar.gz frameworks_base-6398343e83b3fd11dd6536cf6f390a52c1e19d2e.tar.bz2 |
Return EXIF thumbnails when available.
Adds new ExifInterface method to extract the thumbnail range from
a larger image file, and use that to return an AssetFileDescriptor.
When decoding an AssetFileDescriptor thumbnail with offsets, read out
the raw data entirely, since Skia uses lseek() aggressively.
Bug: 10412208
Change-Id: I7906cdf82c0c3794cec7043c801a86f66efeb143
Diffstat (limited to 'packages/ExternalStorageProvider')
-rw-r--r-- | packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index b4bf563..8843e19 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -20,10 +20,13 @@ import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentValues; import android.content.UriMatcher; +import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MatrixCursor.RowBuilder; +import android.media.ExifInterface; import android.net.Uri; +import android.os.Bundle; import android.os.Environment; import android.os.ParcelFileDescriptor; import android.provider.DocumentsContract; @@ -296,7 +299,6 @@ public class ExternalStorageProvider extends ContentProvider { final Root root = mRoots.get(DocumentsContract.getRootId(uri)); final String docId = DocumentsContract.getDocId(uri); - // TODO: offer as thumbnail final File file = docIdToFile(root, docId); return ParcelFileDescriptor.open(file, ContentResolver.modeToMode(uri, mode)); } @@ -307,6 +309,39 @@ public class ExternalStorageProvider extends ContentProvider { } @Override + public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts) + throws FileNotFoundException { + if (opts == null || !opts.containsKey(DocumentsContract.EXTRA_THUMBNAIL_SIZE)) { + return super.openTypedAssetFile(uri, mimeTypeFilter, opts); + } + + switch (sMatcher.match(uri)) { + case URI_DOCS_ID: { + final Root root = mRoots.get(DocumentsContract.getRootId(uri)); + final String docId = DocumentsContract.getDocId(uri); + + final File file = docIdToFile(root, docId); + final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( + file, ParcelFileDescriptor.MODE_READ_ONLY); + + try { + final ExifInterface exif = new ExifInterface(file.getAbsolutePath()); + final long[] thumb = exif.getThumbnailRange(); + if (thumb != null) { + return new AssetFileDescriptor(pfd, thumb[0], thumb[1]); + } + } catch (IOException e) { + } + + return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH); + } + default: { + throw new UnsupportedOperationException("Unsupported Uri " + uri); + } + } + } + + @Override public Uri insert(Uri uri, ContentValues values) { switch (sMatcher.match(uri)) { case URI_DOCS_ID: { |