summaryrefslogtreecommitdiff
path: root/core/java/android/database/ContentObserver.java
diff options
context:
space:
mode:
authorXiaoyu Jin <xyj@google.com>2021-10-28 04:52:44 +0000
committerXiaoyu Jin <xyj@google.com>2021-11-16 02:02:16 +0000
commitc06b02ddba46bd1b467fa7f9c42c35db3209795c (patch)
treef5932cbcdf58c0f7d67a0309eada00bac07e199c /core/java/android/database/ContentObserver.java
parent420679dea6c620ce2aa011f4de0fa8c085e815ee (diff)
Add @SystemApi registerContentObserverForAllUsers in ContentResolver
Also add ContentObserver#onChange(boolean, Collection, int, UserHandle) so clients can know the corresponding UserHandle for the notification. Bug: 203606981 Test: atest CtsContentTestCases and manual testing to verify the observer can get notifications for all the users. Change-Id: Icec7e70b71d7de1c15faf1736539f169856304a8
Diffstat (limited to 'core/java/android/database/ContentObserver.java')
-rw-r--r--core/java/android/database/ContentObserver.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/java/android/database/ContentObserver.java b/core/java/android/database/ContentObserver.java
index 578d53b17bf9..c27ee51b9315 100644
--- a/core/java/android/database/ContentObserver.java
+++ b/core/java/android/database/ContentObserver.java
@@ -18,6 +18,7 @@ package android.database;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import android.annotation.UserIdInt;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
@@ -188,6 +189,27 @@ public abstract class ContentObserver {
}
}
+ /**
+ * This method is called when a content change occurs. Includes the changed
+ * content Uris when available.
+ * <p>
+ * Subclasses should override this method to handle content changes. To
+ * ensure correct operation on older versions of the framework that did not
+ * provide richer arguments, applications should implement all overloads.
+ *
+ * @param selfChange True if this is a self-change notification.
+ * @param uris The Uris of the changed content.
+ * @param flags Flags indicating details about this change.
+ * @param user The corresponding {@link UserHandle} for the current notification.
+ *
+ * @hide
+ */
+ @SystemApi
+ public void onChange(boolean selfChange, @NonNull Collection<Uri> uris,
+ @NotifyFlags int flags, @NonNull UserHandle user) {
+ onChange(selfChange, uris, user.getIdentifier());
+ }
+
/** @hide */
public void onChange(boolean selfChange, @NonNull Collection<Uri> uris,
@NotifyFlags int flags, @UserIdInt int userId) {
@@ -197,7 +219,7 @@ public abstract class ContentObserver {
if (!CompatChanges.isChangeEnabled(ADD_CONTENT_OBSERVER_FLAGS)
|| android.os.Process.myUid() == android.os.Process.SYSTEM_UID) {
// Deliver userId through argument to preserve hidden API behavior
- onChange(selfChange, uris, userId);
+ onChange(selfChange, uris, flags, UserHandle.of(userId));
} else {
onChange(selfChange, uris, flags);
}