diff options
author | Marco Nelissen <marcone@google.com> | 2012-01-27 09:43:20 -0800 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2012-01-27 15:10:14 -0800 |
commit | ca78f3d9aff78c35bc065b0c35a0b3c917f56435 (patch) | |
tree | b2a318b1d3519e0dcb9cfe00f7cdf51aec56a98f /media | |
parent | d4760fc2b731f1ffe1d5f2efb4a887772f1c5150 (diff) | |
download | frameworks_base-ca78f3d9aff78c35bc065b0c35a0b3c917f56435.zip frameworks_base-ca78f3d9aff78c35bc065b0c35a0b3c917f56435.tar.gz frameworks_base-ca78f3d9aff78c35bc065b0c35a0b3c917f56435.tar.bz2 |
Handle adding/removing/renaming nomedia paths
b/5849015
Change-Id: I3ec7419498d1ecc83db6d4605b3d7610349231f7
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaScanner.java | 22 | ||||
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 32 |
2 files changed, 54 insertions, 0 deletions
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index b06ef95..fbf65fd 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -35,6 +35,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.SystemProperties; import android.provider.MediaStore; +import android.provider.MediaStore.Files.FileColumns; import android.provider.Settings; import android.provider.MediaStore.Audio; import android.provider.MediaStore.Files; @@ -58,6 +59,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Locale; /** * Internal service helper that no-one should use directly. @@ -946,6 +948,22 @@ public class MediaScanner // path should never change, and we want to avoid replacing mixed cased paths // with squashed lower case paths values.remove(MediaStore.MediaColumns.DATA); + + int mediaType = 0; + if (!MediaScanner.isNoMediaPath(entry.mPath)) { + int fileType = MediaFile.getFileTypeForMimeType(mMimeType); + if (MediaFile.isAudioFileType(fileType)) { + mediaType = FileColumns.MEDIA_TYPE_AUDIO; + } else if (MediaFile.isVideoFileType(fileType)) { + mediaType = FileColumns.MEDIA_TYPE_VIDEO; + } else if (MediaFile.isImageFileType(fileType)) { + mediaType = FileColumns.MEDIA_TYPE_IMAGE; + } else if (MediaFile.isPlayListFileType(fileType)) { + mediaType = FileColumns.MEDIA_TYPE_PLAYLIST; + } + values.put(FileColumns.MEDIA_TYPE, mediaType); + } + mMediaProvider.update(result, values, null, null); } @@ -1180,6 +1198,10 @@ public class MediaScanner mMediaProvider.delete(ContentUris.withAppendedId(mFilesUri, entry.mRowId), null, null); iterator.remove(); + if (entry.mPath.toLowerCase(Locale.US).endsWith("/.nomedia")) { + File f = new File(path); + mMediaProvider.call(MediaStore.UNHIDE_CALL, f.getParent(), null); + } } } } diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index 19db1c0..6bb578b 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -752,6 +752,29 @@ public class MtpDatabase { return MtpConstants.RESPONSE_GENERAL_ERROR; } + // check if nomedia status changed + if (newFile.isDirectory()) { + // for directories, check if renamed from something hidden to something non-hidden + if (oldFile.getName().startsWith(".") && !newPath.startsWith(".")) { + // directory was unhidden + try { + mMediaProvider.call(MediaStore.UNHIDE_CALL, newPath, null); + } catch (RemoteException e) { + Log.e(TAG, "failed to unhide/rescan for " + newPath); + } + } + } else { + // for files, check if renamed from .nomedia to something else + if (oldFile.getName().toLowerCase(Locale.US).equals(".nomedia") + && !newPath.toLowerCase(Locale.US).equals(".nomedia")) { + try { + mMediaProvider.call(MediaStore.UNHIDE_CALL, oldFile.getParent(), null); + } catch (RemoteException e) { + Log.e(TAG, "failed to unhide/rescan for " + newPath); + } + } + } + return MtpConstants.RESPONSE_OK; } @@ -915,6 +938,15 @@ public class MtpDatabase { Uri uri = Files.getMtpObjectsUri(mVolumeName, handle); if (mMediaProvider.delete(uri, null, null) > 0) { + if (format != MtpConstants.FORMAT_ASSOCIATION + && path.toLowerCase(Locale.US).endsWith("/.nomedia")) { + try { + String parentPath = path.substring(0, path.lastIndexOf("/")); + mMediaProvider.call(MediaStore.UNHIDE_CALL, parentPath, null); + } catch (RemoteException e) { + Log.e(TAG, "failed to unhide/rescan for " + path); + } + } return MtpConstants.RESPONSE_OK; } else { return MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE; |