Merge "Make media scanner use new delete-parameter"
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index d11219b..d3ad63d 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -70,6 +70,18 @@
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 1c13fff..9dc9cef 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -1176,15 +1176,14 @@
}
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 @@
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);