DO NOT MERGE Fix media scanner uri handling.

If a file was originally considered a video file (because it had
a .mp4 extension, for example), but was then discovered to have
only an audio track, it would update the type, but not the URI
for insertion into the media provider.

Change-Id: Ie589c9b52b436d73e295609d21238b2b3e829502
Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Marco Nelissen
2011-03-29 13:29:42 -07:00
committed by Mike Lockwood
parent c535f7f291
commit 7dd592298a

View File

@@ -347,7 +347,6 @@ public class MediaScanner
private BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); private BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options();
private static class FileCacheEntry { private static class FileCacheEntry {
Uri mTableUri;
long mRowId; long mRowId;
String mPath; String mPath;
long mLastModified; long mLastModified;
@@ -355,8 +354,7 @@ public class MediaScanner
boolean mSeenInFileSystem; boolean mSeenInFileSystem;
boolean mLastModifiedChanged; boolean mLastModifiedChanged;
FileCacheEntry(Uri tableUri, long rowId, String path, long lastModified, int format) { FileCacheEntry(long rowId, String path, long lastModified, int format) {
mTableUri = tableUri;
mRowId = rowId; mRowId = rowId;
mPath = path; mPath = path;
mLastModified = lastModified; mLastModified = lastModified;
@@ -367,7 +365,7 @@ public class MediaScanner
@Override @Override
public String toString() { public String toString() {
return mPath + " mTableUri: " + mTableUri + " mRowId: " + mRowId; return mPath + " mRowId: " + mRowId;
} }
} }
@@ -491,23 +489,10 @@ public class MediaScanner
long delta = (entry != null) ? (lastModified - entry.mLastModified) : 0; long delta = (entry != null) ? (lastModified - entry.mLastModified) : 0;
boolean wasModified = delta > 1 || delta < -1; boolean wasModified = delta > 1 || delta < -1;
if (entry == null || wasModified) { if (entry == null || wasModified) {
Uri tableUri;
if (isDirectory) {
tableUri = mFilesUri;
} else if (MediaFile.isVideoFileType(mFileType)) {
tableUri = mVideoUri;
} else if (MediaFile.isImageFileType(mFileType)) {
tableUri = mImagesUri;
} else if (MediaFile.isAudioFileType(mFileType)) {
tableUri = mAudioUri;
} else {
tableUri = mFilesUri;
}
if (wasModified) { if (wasModified) {
entry.mLastModified = lastModified; entry.mLastModified = lastModified;
entry.mTableUri = tableUri;
} else { } else {
entry = new FileCacheEntry(tableUri, 0, path, lastModified, entry = new FileCacheEntry(0, path, lastModified,
(isDirectory ? MtpConstants.FORMAT_ASSOCIATION : 0)); (isDirectory ? MtpConstants.FORMAT_ASSOCIATION : 0));
mFileCache.put(key, entry); mFileCache.put(key, entry);
} }
@@ -829,7 +814,14 @@ public class MediaScanner
} }
} }
Uri tableUri = entry.mTableUri; Uri tableUri = mFilesUri;
if (MediaFile.isVideoFileType(mFileType)) {
tableUri = mVideoUri;
} else if (MediaFile.isImageFileType(mFileType)) {
tableUri = mImagesUri;
} else if (MediaFile.isAudioFileType(mFileType)) {
tableUri = mAudioUri;
}
Uri result = null; Uri result = null;
if (rowId == 0) { if (rowId == 0) {
if (mMtpObjectHandle != 0) { if (mMtpObjectHandle != 0) {
@@ -1021,13 +1013,13 @@ public class MediaScanner
// Only consider entries with absolute path names. // Only consider entries with absolute path names.
// This allows storing URIs in the database without the // This allows storing URIs in the database without the
// media scanner removing them. // media scanner removing them.
if (path.startsWith("/")) { if (path != null && path.startsWith("/")) {
String key = path; String key = path;
if (mCaseInsensitivePaths) { if (mCaseInsensitivePaths) {
key = path.toLowerCase(); key = path.toLowerCase();
} }
FileCacheEntry entry = new FileCacheEntry(mFilesUri, rowId, path, FileCacheEntry entry = new FileCacheEntry(rowId, path,
lastModified, format); lastModified, format);
mFileCache.put(key, entry); mFileCache.put(key, entry);
} }