diff options
| -rw-r--r-- | media/java/android/media/MediaScanner.java | 39 | ||||
| -rw-r--r-- | media/jni/android_media_MediaScanner.cpp | 13 |
2 files changed, 31 insertions, 21 deletions
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index f476a6ccb257..8a757b86a5fa 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -488,6 +488,7 @@ public class MediaScanner implements AutoCloseable { private int mCompilation; private boolean mIsDrm; private boolean mNoMedia; // flag to suppress file from appearing in media tables + private boolean mScanSuccess; private int mWidth; private int mHeight; @@ -502,6 +503,7 @@ public class MediaScanner implements AutoCloseable { mFileType = 0; mFileSize = fileSize; mIsDrm = false; + mScanSuccess = true; if (!isDirectory) { if (!noMedia && isNoMediaFile(path)) { @@ -623,14 +625,6 @@ public class MediaScanner implements AutoCloseable { if (noMedia) { result = endFile(entry, false, false, false, false, false); } else { - String lowpath = path.toLowerCase(Locale.ROOT); - boolean ringtones = (lowpath.indexOf(RINGTONES_DIR) > 0); - boolean notifications = (lowpath.indexOf(NOTIFICATIONS_DIR) > 0); - boolean alarms = (lowpath.indexOf(ALARMS_DIR) > 0); - boolean podcasts = (lowpath.indexOf(PODCAST_DIR) > 0); - boolean music = (lowpath.indexOf(MUSIC_DIR) > 0) || - (!ringtones && !notifications && !alarms && !podcasts); - boolean isaudio = MediaFile.isAudioFileType(mFileType); boolean isvideo = MediaFile.isVideoFileType(mFileType); boolean isimage = MediaFile.isImageFileType(mFileType); @@ -642,13 +636,22 @@ public class MediaScanner implements AutoCloseable { // we only extract metadata for audio and video files if (isaudio || isvideo) { - processFile(path, mimeType, this); + mScanSuccess = processFile(path, mimeType, this); } if (isimage) { - processImageFile(path); + mScanSuccess = processImageFile(path); } + String lowpath = path.toLowerCase(Locale.ROOT); + boolean ringtones = mScanSuccess && (lowpath.indexOf(RINGTONES_DIR) > 0); + boolean notifications = mScanSuccess && + (lowpath.indexOf(NOTIFICATIONS_DIR) > 0); + boolean alarms = mScanSuccess && (lowpath.indexOf(ALARMS_DIR) > 0); + boolean podcasts = mScanSuccess && (lowpath.indexOf(PODCAST_DIR) > 0); + boolean music = mScanSuccess && ((lowpath.indexOf(MUSIC_DIR) > 0) || + (!ringtones && !notifications && !alarms && !podcasts)); + result = endFile(entry, ringtones, notifications, alarms, music, podcasts); } } @@ -816,16 +819,18 @@ public class MediaScanner implements AutoCloseable { return genreTagValue; } - private void processImageFile(String path) { + private boolean processImageFile(String path) { try { mBitmapOptions.outWidth = 0; mBitmapOptions.outHeight = 0; BitmapFactory.decodeFile(path, mBitmapOptions); mWidth = mBitmapOptions.outWidth; mHeight = mBitmapOptions.outHeight; + return mWidth > 0 && mHeight > 0; } catch (Throwable th) { // ignore; } + return false; } public void setMimeType(String mimeType) { @@ -878,7 +883,7 @@ public class MediaScanner implements AutoCloseable { } } else if (MediaFile.isImageFileType(mFileType)) { // FIXME - add DESCRIPTION - } else if (MediaFile.isAudioFileType(mFileType)) { + } else if (mScanSuccess && MediaFile.isAudioFileType(mFileType)) { map.put(Audio.Media.ARTIST, (mArtist != null && mArtist.length() > 0) ? mArtist : MediaStore.UNKNOWN_STRING); map.put(Audio.Media.ALBUM_ARTIST, (mAlbumArtist != null && @@ -894,6 +899,10 @@ public class MediaScanner implements AutoCloseable { map.put(Audio.Media.DURATION, mDuration); map.put(Audio.Media.COMPILATION, mCompilation); } + if (!mScanSuccess) { + // force mediaprovider to not determine the media type from the mime type + map.put(Files.FileColumns.MEDIA_TYPE, 0); + } } return map; } @@ -1001,7 +1010,7 @@ public class MediaScanner implements AutoCloseable { Uri tableUri = mFilesUri; MediaInserter inserter = mMediaInserter; - if (!mNoMedia) { + if (mScanSuccess && !mNoMedia) { if (MediaFile.isVideoFileType(mFileType)) { tableUri = mVideoUri; } else if (MediaFile.isImageFileType(mFileType)) { @@ -1071,7 +1080,7 @@ public class MediaScanner implements AutoCloseable { values.remove(MediaStore.MediaColumns.DATA); int mediaType = 0; - if (!MediaScanner.isNoMediaPath(entry.mPath)) { + if (mScanSuccess && !MediaScanner.isNoMediaPath(entry.mPath)) { int fileType = MediaFile.getFileTypeForMimeType(mMimeType); if (MediaFile.isAudioFileType(fileType)) { mediaType = FileColumns.MEDIA_TYPE_AUDIO; @@ -1890,7 +1899,7 @@ public class MediaScanner implements AutoCloseable { } private native void processDirectory(String path, MediaScannerClient client); - private native void processFile(String path, String mimeType, MediaScannerClient client); + private native boolean processFile(String path, String mimeType, MediaScannerClient client); private native void setLocale(String locale); public native byte[] extractAlbumArt(FileDescriptor fd); diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp index 3b475b2d70c8..c0ceb0152271 100644 --- a/media/jni/android_media_MediaScanner.cpp +++ b/media/jni/android_media_MediaScanner.cpp @@ -264,7 +264,7 @@ android_media_MediaScanner_processDirectory( env->ReleaseStringUTFChars(path, pathStr); } -static void +static jboolean android_media_MediaScanner_processFile( JNIEnv *env, jobject thiz, jstring path, jstring mimeType, jobject client) @@ -275,17 +275,17 @@ android_media_MediaScanner_processFile( MediaScanner *mp = getNativeScanner_l(env, thiz); if (mp == NULL) { jniThrowException(env, kRunTimeException, "No scanner available"); - return; + return false; } if (path == NULL) { jniThrowException(env, kIllegalArgumentException, NULL); - return; + return false; } const char *pathStr = env->GetStringUTFChars(path, NULL); if (pathStr == NULL) { // Out of memory - return; + return false; } const char *mimeTypeStr = @@ -293,7 +293,7 @@ android_media_MediaScanner_processFile( if (mimeType && mimeTypeStr == NULL) { // Out of memory // ReleaseStringUTFChars can be called with an exception pending. env->ReleaseStringUTFChars(path, pathStr); - return; + return false; } MyMediaScannerClient myClient(env, client); @@ -305,6 +305,7 @@ android_media_MediaScanner_processFile( if (mimeType) { env->ReleaseStringUTFChars(mimeType, mimeTypeStr); } + return result != MEDIA_SCAN_RESULT_ERROR; } static void @@ -421,7 +422,7 @@ static const JNINativeMethod gMethods[] = { { "processFile", - "(Ljava/lang/String;Ljava/lang/String;Landroid/media/MediaScannerClient;)V", + "(Ljava/lang/String;Ljava/lang/String;Landroid/media/MediaScannerClient;)Z", (void *)android_media_MediaScanner_processFile }, |