summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-04-24 11:15:09 -0700
committerMike Lockwood <lockwood@android.com>2011-04-25 09:21:54 -0700
commit997354e4b4a9666cedd62282471e97822affced9 (patch)
tree4f9af265b59489bdc0b2e1562cde035d984c5767 /media/libmedia
parent653935da6bfe45301bc362c92d4aa9b4f50277ca (diff)
downloadframeworks_base-997354e4b4a9666cedd62282471e97822affced9.zip
frameworks_base-997354e4b4a9666cedd62282471e97822affced9.tar.gz
frameworks_base-997354e4b4a9666cedd62282471e97822affced9.tar.bz2
MediaScanner: reimplement the ".nomedia" feature for hiding files from the media provider
Previously we ignored any files and directories that had name started with '.' and ignored any directories that contained a ".nomedia" file. Now to support transferring any file via MTP, we now add these previously ignored files to the media database, but will not mark them as audio, video, image or playlist files. That way they will be included in the files table but will be hidden from the audio, video, images and playlist views that are used by apps like Music and Gallery. Bug: 3405327 Change-Id: I2d7285bd32e06c1a5c4ef6a8a15f8f8b2c33b39b Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/MediaScanner.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/media/libmedia/MediaScanner.cpp b/media/libmedia/MediaScanner.cpp
index 5ec573e..4e22175 100644
--- a/media/libmedia/MediaScanner.cpp
+++ b/media/libmedia/MediaScanner.cpp
@@ -70,8 +70,7 @@ status_t MediaScanner::processDirectory(
client.setLocale(locale());
status_t result =
- doProcessDirectory(
- pathBuffer, pathRemaining, client, exceptionCheck, exceptionEnv);
+ doProcessDirectory(pathBuffer, pathRemaining, client, false, exceptionCheck, exceptionEnv);
free(pathBuffer);
@@ -80,20 +79,18 @@ status_t MediaScanner::processDirectory(
status_t MediaScanner::doProcessDirectory(
char *path, int pathRemaining, MediaScannerClient &client,
- ExceptionCheck exceptionCheck, void *exceptionEnv) {
+ bool noMedia, ExceptionCheck exceptionCheck, void *exceptionEnv) {
// place to copy file or directory name
char* fileSpot = path + strlen(path);
struct dirent* entry;
struct stat statbuf;
- // ignore directories that contain a ".nomedia" file
+ // Treat all files as non-media in directories that contain a ".nomedia" file
if (pathRemaining >= 8 /* strlen(".nomedia") */ ) {
strcpy(fileSpot, ".nomedia");
if (access(path, F_OK) == 0) {
- LOGD("found .nomedia, skipping directory\n");
- fileSpot[0] = 0;
- client.addNoMediaFolder(path);
- return OK;
+ LOGD("found .nomedia, setting noMedia flag\n");
+ noMedia = true;
}
// restore path
@@ -138,19 +135,20 @@ status_t MediaScanner::doProcessDirectory(
}
if (type == DT_REG || type == DT_DIR) {
if (type == DT_DIR) {
- // ignore directories with a name that starts with '.'
+ // set noMedia flag on directories with a name that starts with '.'
// for example, the Mac ".Trashes" directory
- if (name[0] == '.') continue;
+ if (name[0] == '.')
+ noMedia = true;
// report the directory to the client
if (stat(path, &statbuf) == 0) {
- client.scanFile(path, statbuf.st_mtime, 0, true);
+ client.scanFile(path, statbuf.st_mtime, 0, true, noMedia);
}
// and now process its contents
strcat(fileSpot, "/");
int err = doProcessDirectory(path, pathRemaining - nameLength - 1, client,
- exceptionCheck, exceptionEnv);
+ noMedia, exceptionCheck, exceptionEnv);
if (err) {
// pass exceptions up - ignore other errors
if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
@@ -159,7 +157,7 @@ status_t MediaScanner::doProcessDirectory(
}
} else {
stat(path, &statbuf);
- client.scanFile(path, statbuf.st_mtime, statbuf.st_size, false);
+ client.scanFile(path, statbuf.st_mtime, statbuf.st_size, false, noMedia);
if (exceptionCheck && exceptionCheck(exceptionEnv)) goto failure;
}
}