From 6610524e4c465cff66c24bb5ffe70f47124cc5af Mon Sep 17 00:00:00 2001 From: Xiaoyu Jin Date: Wed, 1 Dec 2021 15:57:49 +0000 Subject: [PATCH] Change registerContentObserverForAllUsers to registerContentObserverAsUser Make the change based on API council's suggestion. Bug: 206743591 Test: Manual testing to verify the observer can get notifications for all the users. Change-Id: I725307f65c288c4fc8bc3acf923cd7092ccc2f97 --- core/api/module-lib-current.txt | 4 ++++ core/api/system-current.txt | 1 - core/java/android/content/ContentResolver.java | 14 +++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index 70bb13a36b6ec..0bbc80c55af62 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -78,6 +78,10 @@ package android.content { method @NonNull public static android.net.Uri createContentUriForUser(@NonNull android.net.Uri, @NonNull android.os.UserHandle); } + public abstract class ContentResolver { + method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public final void registerContentObserverAsUser(@NonNull android.net.Uri, boolean, @NonNull android.database.ContentObserver, @NonNull android.os.UserHandle); + } + public abstract class Context { method @NonNull public android.os.UserHandle getUser(); field public static final String PAC_PROXY_SERVICE = "pac_proxy"; diff --git a/core/api/system-current.txt b/core/api/system-current.txt index dd1760c510978..c024d532e858b 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2440,7 +2440,6 @@ package android.content { method @NonNull public static java.io.File encodeToFile(@NonNull android.net.Uri); method @Nullable @RequiresPermission("android.permission.CACHE_CONTENT") public android.os.Bundle getCache(@NonNull android.net.Uri); method @RequiresPermission("android.permission.CACHE_CONTENT") public void putCache(@NonNull android.net.Uri, @Nullable android.os.Bundle); - method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public final void registerContentObserverForAllUsers(@NonNull android.net.Uri, boolean, @NonNull android.database.ContentObserver); } public abstract class Context { diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java index a9a232518e5f6..adae5996372a5 100644 --- a/core/java/android/content/ContentResolver.java +++ b/core/java/android/content/ContentResolver.java @@ -2666,7 +2666,7 @@ public abstract class ContentResolver implements ContentInterface { /** * Same as {@link #registerContentObserver(Uri, boolean, ContentObserver)}, but the observer - * registered will get content change notifications from all users. + * registered will get content change notifications for the specified user. * {@link ContentObserver#onChange(boolean, Collection, int, UserHandle)} should be * overwritten to get the corresponding {@link UserHandle} for that notification. * @@ -2679,21 +2679,25 @@ public abstract class ContentResolver implements ContentInterface { * whenever a change occurs to the URI's descendants in the path * hierarchy. * @param observer The object that receives callbacks when changes occur. + * @param userHandle The UserHandle of the user the content change notifications are + * for. * @hide * @see #unregisterContentObserver */ @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) - @SystemApi - public final void registerContentObserverForAllUsers(@NonNull Uri uri, + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + public final void registerContentObserverAsUser(@NonNull Uri uri, boolean notifyForDescendants, - @NonNull ContentObserver observer) { + @NonNull ContentObserver observer, + @NonNull UserHandle userHandle) { Objects.requireNonNull(uri, "uri"); Objects.requireNonNull(observer, "observer"); + Objects.requireNonNull(userHandle, "userHandle"); registerContentObserver( ContentProvider.getUriWithoutUserId(uri), notifyForDescendants, observer, - UserHandle.USER_ALL); + userHandle.getIdentifier()); } /** @hide - designated user version */