From ac259f17a0a6ba9e363bbf0c268c5942aab392c1 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Tue, 7 Feb 2012 07:54:39 -0800 Subject: [PATCH] Make media scanner use new delete-parameter This speeds up the media scan case where many files were deleted or moved. Change-Id: I86e6fc6d0968eebf24923c0b5587b90d309721bb --- core/java/android/provider/MediaStore.java | 12 ++++++++++++ media/java/android/media/MediaScanner.java | 18 ++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index d11219b0431cf..d3ad63d02fe36 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -69,6 +69,18 @@ public final class MediaStore { */ public static final String UNHIDE_CALL = "unhide"; + /** + * This is for internal use by the media scanner only. + * Name of the (optional) Uri parameter that determines whether to skip deleting + * the file pointed to by the _data column, when deleting the database entry. + * The only appropriate value for this parameter is "false", in which case the + * delete will be skipped. Note especially that setting this to true, or omitting + * the parameter altogether, will perform the default action, which is different + * for different types of media. + * @hide + */ + public static final String PARAM_DELETE_DATA = "deletedata"; + /** * Activity Action: Launch a music player. * The activity should be able to play, browse, or manipulate music files stored on the device. diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index 1c13ffffefbe7..9dc9cef133b23 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -1176,15 +1176,14 @@ public class MediaScanner } if (fileMissing) { - // Clear the file path to prevent the _DELETE_FILE database hook - // in the media provider from deleting the file. + // Tell the provider to not delete the file. // If the file is truly gone the delete is unnecessary, and we want to avoid - // accidentally deleting files that are really there. - ContentValues values = new ContentValues(); - values.put(Files.FileColumns.DATA, ""); - values.put(Files.FileColumns.DATE_MODIFIED, 0); - mMediaProvider.update(ContentUris.withAppendedId(mFilesUri, entry.mRowId), - values, null, null); + // accidentally deleting files that are really there (this may happen if the + // filesystem is mounted and unmounted while the scanner is running). + Uri.Builder builder = mFilesUri.buildUpon(); + builder.appendEncodedPath(String.valueOf(entry.mRowId)); + builder.appendQueryParameter(MediaStore.PARAM_DELETE_DATA, "false"); + Uri missingUri = builder.build(); // do not delete missing playlists, since they may have been modified by the user. // the user can delete them in the media player instead. @@ -1193,8 +1192,7 @@ public class MediaScanner int fileType = (mediaFileType == null ? 0 : mediaFileType.fileType); if (!MediaFile.isPlayListFileType(fileType)) { - mMediaProvider.delete(ContentUris.withAppendedId(mFilesUri, entry.mRowId), - null, null); + mMediaProvider.delete(missingUri, null, null); iterator.remove(); if (entry.mPath.toLowerCase(Locale.US).endsWith("/.nomedia")) { File f = new File(path);