Skip to content

Commit ed4cfe7

Browse files
Chih-Chung ChangAndroid (Google) Code Review
authored andcommitted
Merge "Fix 5224359: Add width and height to media store."
2 parents 291c6d7 + e1bf8ef commit ed4cfe7

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

core/java/android/provider/MediaStore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,17 @@ public interface MediaColumns extends BaseColumns {
283283
*/
284284
public static final String IS_DRM = "is_drm";
285285

286+
/**
287+
* The width of the image/video in pixels.
288+
* @hide
289+
*/
290+
public static final String WIDTH = "width";
291+
292+
/**
293+
* The height of the image/video in pixels.
294+
* @hide
295+
*/
296+
public static final String HEIGHT = "height";
286297
}
287298

288299
/**

media/java/android/media/MediaScanner.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ private class MyMediaScannerClient implements MediaScannerClient {
470470
private int mCompilation;
471471
private boolean mIsDrm;
472472
private boolean mNoMedia; // flag to suppress file from appearing in media tables
473+
private int mWidth;
474+
private int mHeight;
473475

474476
public FileCacheEntry beginFile(String path, String mimeType, long lastModified,
475477
long fileSize, boolean isDirectory, boolean noMedia) {
@@ -545,6 +547,8 @@ public FileCacheEntry beginFile(String path, String mimeType, long lastModified,
545547
mWriter = null;
546548
mCompilation = 0;
547549
mIsDrm = false;
550+
mWidth = 0;
551+
mHeight = 0;
548552

549553
return entry;
550554
}
@@ -583,6 +587,10 @@ public Uri doScanFile(String path, String mimeType, long lastModified,
583587
processFile(path, mimeType, this);
584588
}
585589

590+
if (MediaFile.isImageFileType(mFileType)) {
591+
processImageFile(path);
592+
}
593+
586594
result = endFile(entry, ringtones, notifications, alarms, music, podcasts);
587595
}
588596
}
@@ -697,6 +705,18 @@ public String getGenreName(String genreTagValue) {
697705
return genreTagValue;
698706
}
699707

708+
private void processImageFile(String path) {
709+
try {
710+
mBitmapOptions.outWidth = 0;
711+
mBitmapOptions.outHeight = 0;
712+
BitmapFactory.decodeFile(path, mBitmapOptions);
713+
mWidth = mBitmapOptions.outWidth;
714+
mHeight = mBitmapOptions.outHeight;
715+
} catch (Throwable th) {
716+
// ignore;
717+
}
718+
}
719+
700720
public void setMimeType(String mimeType) {
701721
if ("audio/mp4".equals(mMimeType) &&
702722
mimeType.startsWith("video")) {
@@ -725,6 +745,11 @@ private ContentValues toValues() {
725745
map.put(MediaStore.MediaColumns.MIME_TYPE, mMimeType);
726746
map.put(MediaStore.MediaColumns.IS_DRM, mIsDrm);
727747

748+
if (mWidth > 0 && mHeight > 0) {
749+
map.put(MediaStore.MediaColumns.WIDTH, mWidth);
750+
map.put(MediaStore.MediaColumns.HEIGHT, mHeight);
751+
}
752+
728753
if (!mNoMedia) {
729754
if (MediaFile.isVideoFileType(mFileType)) {
730755
map.put(Video.Media.ARTIST, (mArtist != null && mArtist.length() > 0

0 commit comments

Comments
 (0)