diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-09-23 17:36:29 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-09-23 17:36:40 -0700 |
commit | ca709d4f9f6ef66337b96010a150e30a5888855e (patch) | |
tree | de3c56e8a58719f2f28208c321829305f762ac86 | |
parent | a2bd8dfeac57dc09727c6d16ebf9bac1061df23d (diff) | |
download | MediaProvider-ca709d4f9f6ef66337b96010a150e30a5888855e.tar.gz |
Notify when media roots go non-empty.
If we reported that Images, Videos, or Audio were empty, notify
when they become non-empty so RootsCache is updated and they appear
in UI.
Bug: 10745490
Change-Id: I0b10ca1b8a08ef7f5bd8bbee1eca62ca871aa4e6
-rw-r--r-- | src/com/android/providers/media/MediaDocumentsProvider.java | 35 | ||||
-rwxr-xr-x | src/com/android/providers/media/MediaProvider.java | 15 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/com/android/providers/media/MediaDocumentsProvider.java b/src/com/android/providers/media/MediaDocumentsProvider.java index fc80066a2..b0be20ff0 100644 --- a/src/com/android/providers/media/MediaDocumentsProvider.java +++ b/src/com/android/providers/media/MediaDocumentsProvider.java @@ -18,6 +18,7 @@ package com.android.providers.media; import android.content.ContentResolver; import android.content.ContentUris; +import android.content.Context; import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.database.MatrixCursor; @@ -87,6 +88,10 @@ public class MediaDocumentsProvider extends DocumentsProvider { private static final String TYPE_ARTIST = "artist"; private static final String TYPE_ALBUM = "album"; + private static boolean sReturnedImagesEmpty = false; + private static boolean sReturnedVideosEmpty = false; + private static boolean sReturnedAudioEmpty = false; + private static String joinNewline(String... args) { return TextUtils.join("\n", args); } @@ -100,6 +105,33 @@ public class MediaDocumentsProvider extends DocumentsProvider { return true; } + private static void notifyRootsChanged(Context context) { + context.getContentResolver().notifyChange( + DocumentsContract.buildRootsUri("com.android.providers.media.documents"), null, + false); + } + + static void onImagesInserted(Context context) { + if (sReturnedImagesEmpty) { + notifyRootsChanged(context); + sReturnedImagesEmpty = false; + } + } + + static void onVideoInserted(Context context) { + if (sReturnedVideosEmpty) { + notifyRootsChanged(context); + sReturnedVideosEmpty = false; + } + } + + static void onAudioInserted(Context context) { + if (sReturnedAudioEmpty) { + notifyRootsChanged(context); + sReturnedAudioEmpty = false; + } + } + private static class Ident { public String type; public long id; @@ -430,6 +462,7 @@ public class MediaDocumentsProvider extends DocumentsProvider { int flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS; if (isEmpty(Images.Media.EXTERNAL_CONTENT_URI)) { flags |= Root.FLAG_EMPTY; + sReturnedImagesEmpty = true; } final RowBuilder row = result.newRow(); @@ -445,6 +478,7 @@ public class MediaDocumentsProvider extends DocumentsProvider { int flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS; if (isEmpty(Video.Media.EXTERNAL_CONTENT_URI)) { flags |= Root.FLAG_EMPTY; + sReturnedVideosEmpty = true; } final RowBuilder row = result.newRow(); @@ -460,6 +494,7 @@ public class MediaDocumentsProvider extends DocumentsProvider { int flags = Root.FLAG_LOCAL_ONLY; if (isEmpty(Audio.Media.EXTERNAL_CONTENT_URI)) { flags |= Root.FLAG_EMPTY; + sReturnedAudioEmpty = true; } final RowBuilder row = result.newRow(); diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java index 8ce26eda8..a2bff9647 100755 --- a/src/com/android/providers/media/MediaProvider.java +++ b/src/com/android/providers/media/MediaProvider.java @@ -85,6 +85,12 @@ import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; +import libcore.io.ErrnoException; +import libcore.io.IoUtils; +import libcore.io.Libcore; +import libcore.io.OsConstants; +import libcore.io.StructStat; + import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -102,12 +108,6 @@ import java.util.Locale; import java.util.PriorityQueue; import java.util.Stack; -import libcore.io.ErrnoException; -import libcore.io.IoUtils; -import libcore.io.Libcore; -import libcore.io.OsConstants; -import libcore.io.StructStat; - /** * Media content provider. See {@link android.provider.MediaStore} for details. * Separate databases are kept for each external storage card we see (using the @@ -3393,6 +3393,7 @@ public class MediaProvider extends ContentProvider { rowId = insertFile(helper, uri, initialValues, FileColumns.MEDIA_TYPE_IMAGE, true, notifyRowIds); if (rowId > 0) { + MediaDocumentsProvider.onImagesInserted(getContext()); newUri = ContentUris.withAppendedId( Images.Media.getContentUri(uri.getPathSegments().get(0)), rowId); } @@ -3429,6 +3430,7 @@ public class MediaProvider extends ContentProvider { rowId = insertFile(helper, uri, initialValues, FileColumns.MEDIA_TYPE_AUDIO, true, notifyRowIds); if (rowId > 0) { + MediaDocumentsProvider.onAudioInserted(getContext()); newUri = ContentUris.withAppendedId(Audio.Media.getContentUri(uri.getPathSegments().get(0)), rowId); if (genre != null) { updateGenre(rowId, genre); @@ -3511,6 +3513,7 @@ public class MediaProvider extends ContentProvider { rowId = insertFile(helper, uri, initialValues, FileColumns.MEDIA_TYPE_VIDEO, true, notifyRowIds); if (rowId > 0) { + MediaDocumentsProvider.onVideoInserted(getContext()); newUri = ContentUris.withAppendedId(Video.Media.getContentUri( uri.getPathSegments().get(0)), rowId); } |