MediaScanner: Fix handling of .nomedia files in directories
In particular, fix the code that prevents the database triggers from deleting
files when a .nomedia file is added to a directory
Change-Id: Ie913223f3b1bbf9122842a675b96d4baac3b1c6f
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index 365fd65..ae6dd61 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -388,7 +388,14 @@
String prop = SystemProperties.get("drm.service.enabled");
return prop != null && prop.equals("true");
}
-
+
+ private final String mediaToExternalPath(String path) {
+ if (mMediaStoragePath != null && path.startsWith(mMediaStoragePath)) {
+ path = mExternalStoragePath + path.substring(mMediaStoragePath.length());
+ }
+ return path;
+ }
+
private class MyMediaScannerClient implements MediaScannerClient {
private String mArtist;
@@ -463,12 +470,9 @@
}
}
- String key = path;
- if (mMediaStoragePath != null && key.startsWith(mMediaStoragePath)) {
- // MediaProvider uses external variant of path for _data, so we need to match
- // against that path instead.
- key = mExternalStoragePath + key.substring(mMediaStoragePath.length());
- }
+ // MediaProvider uses external variant of path for _data, so we need to match
+ // against that path instead.
+ String key = mediaToExternalPath(path);
if (mCaseInsensitivePaths) {
key = path.toLowerCase();
}
@@ -881,6 +885,8 @@
}
public void addNoMediaFolder(String path) {
+ path = mediaToExternalPath(path);
+
ContentValues values = new ContentValues();
values.put(MediaStore.Images.ImageColumns.DATA, "");
String [] pathSpec = new String[] {path + '%'};
@@ -939,11 +945,9 @@
}
if (filePath != null) {
- if (mMediaStoragePath != null && filePath.startsWith(mMediaStoragePath)) {
- // MediaProvider uses external variant of path for _data, so we need to query
- // using that path instead.
- filePath = mExternalStoragePath + filePath.substring(mMediaStoragePath.length());
- }
+ // MediaProvider uses external variant of path for _data, so we need to query
+ // using that path instead.
+ filePath = mediaToExternalPath(filePath);
// query for only one file
where = Files.FileColumns.DATA + "=?";
@@ -1212,12 +1216,9 @@
// build file cache so we can look up tracks in the playlist
prescan(null, true);
- String key = path;
- if (mMediaStoragePath != null && key.startsWith(mMediaStoragePath)) {
- // MediaProvider uses external variant of path for _data, so we need to match
- // against that path instead.
- key = mExternalStoragePath + key.substring(mMediaStoragePath.length());
- }
+ // MediaProvider uses external variant of path for _data, so we need to match
+ // against that path instead.
+ String key = mediaToExternalPath(path);
if (mCaseInsensitivePaths) {
key = path.toLowerCase();
}