Skip to content

Commit

Permalink
DO NOT MERGE Fix media scanner uri handling.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
marcone authored and mikeandroid committed May 4, 2011
1 parent c535f7f commit 7dd5922
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions media/java/android/media/MediaScanner.java
Expand Up @@ -347,16 +347,14 @@ public class MediaScanner
private BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options();

private static class FileCacheEntry {
Uri mTableUri;
long mRowId;
String mPath;
long mLastModified;
int mFormat;
boolean mSeenInFileSystem;
boolean mLastModifiedChanged;

FileCacheEntry(Uri tableUri, long rowId, String path, long lastModified, int format) {
mTableUri = tableUri;
FileCacheEntry(long rowId, String path, long lastModified, int format) {
mRowId = rowId;
mPath = path;
mLastModified = lastModified;
Expand All @@ -367,7 +365,7 @@ private static class FileCacheEntry {

@Override
public String toString() {
return mPath + " mTableUri: " + mTableUri + " mRowId: " + mRowId;
return mPath + " mRowId: " + mRowId;
}
}

Expand Down Expand Up @@ -491,23 +489,10 @@ public FileCacheEntry beginFile(String path, String mimeType, long lastModified,
long delta = (entry != null) ? (lastModified - entry.mLastModified) : 0;
boolean wasModified = delta > 1 || delta < -1;
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) {
entry.mLastModified = lastModified;
entry.mTableUri = tableUri;
} else {
entry = new FileCacheEntry(tableUri, 0, path, lastModified,
entry = new FileCacheEntry(0, path, lastModified,
(isDirectory ? MtpConstants.FORMAT_ASSOCIATION : 0));
mFileCache.put(key, entry);
}
Expand Down Expand Up @@ -829,7 +814,14 @@ private Uri endFile(FileCacheEntry entry, boolean ringtones, boolean notificatio
}
}

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;
if (rowId == 0) {
if (mMtpObjectHandle != 0) {
Expand Down Expand Up @@ -1021,13 +1013,13 @@ private void prescan(String filePath, boolean prescanFiles) throws RemoteExcepti
// Only consider entries with absolute path names.
// This allows storing URIs in the database without the
// media scanner removing them.
if (path.startsWith("/")) {
if (path != null && path.startsWith("/")) {
String key = path;
if (mCaseInsensitivePaths) {
key = path.toLowerCase();
}

FileCacheEntry entry = new FileCacheEntry(mFilesUri, rowId, path,
FileCacheEntry entry = new FileCacheEntry(rowId, path,
lastModified, format);
mFileCache.put(key, entry);
}
Expand Down

0 comments on commit 7dd5922

Please sign in to comment.