summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2016-04-12 18:07:57 -0700
committerDianne Hackborn <hackbod@google.com>2016-04-12 18:07:57 -0700
commit929a6d57a581d6a2865ac80fb81caeb090a000e5 (patch)
tree7047cc0a16fd4c4e524a0214272cd56d467dc35c /src/com
parent9aecbd92265fe74a29d47866abbb233c1454effc (diff)
downloadMediaProvider-929a6d57a581d6a2865ac80fb81caeb090a000e5.tar.gz
Be smarter about reporting changes to containing URIs.
This is for work on issue #26390151 (Add new JobScheduler API... for monitoring content providers) The media provider uses the new content observer flag when reporting a change to the containing URI of a specific file changing, so content observers can avoid seeing that if they are already listening for the specific file. This allows observers to avoid getting dirty data that prevents them from telling that only a specific URI has changed. Change-Id: I38b4c1941f1b06c121a1caf2b5d8593da2007410
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/providers/media/MediaProvider.java21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 9a32526be..cd45b10fa 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -2924,20 +2924,17 @@ public class MediaProvider extends ContentProvider {
// we will signal instead after file transfer is successful.
if (newUri != null && match != MTP_OBJECTS) {
// Report a general change to the media provider.
- // XXX do we really need to do this? It is what we used to report,
- // and if apps are looking at these explicit URIs and not monitoring
- // descendants, they will no longer see the change if we remove it.
- // On the other hand, if we report the general directory changed, then it
- // is hard for clients to know if they can count on looking at the more
- // specific URI to understand the change or if they will need to do a
- // full query under the path to resolve it with an arbitrary change.
- // (For example a bulk insert will currently report a change for just the
- // containing path, which tells clients there was a complicated change that
- // they will need to resolve with a new query.)
- getContext().getContentResolver().notifyChange(uri, null);
+ // We only report this to observers that are not looking at
+ // this specific URI and its descendants, because they will
+ // still see the following more-specific URI and thus get
+ // redundant info (and not be able to know if there was just
+ // the specific URI change or also some general change in the
+ // parent URI).
+ getContext().getContentResolver().notifyChange(uri, null, match != MEDIA_SCANNER
+ ? ContentResolver.NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS : 0);
// Also report the specific URIs that changed.
if (match != MEDIA_SCANNER) {
- getContext().getContentResolver().notifyChange(newUri, null);
+ getContext().getContentResolver().notifyChange(newUri, null, 0);
}
}
return newUri;