diff options
| author | Jin Seok Park <jinpark@google.com> | 2020-07-14 21:15:44 +0900 |
|---|---|---|
| committer | Jin Seok Park <jinpark@google.com> | 2020-07-20 16:01:23 +0900 |
| commit | e1f4d51d555eac69d9d56ecefafcd4cc65a4c1bd (patch) | |
| tree | 95a0a6aef303fe6a403f8ba65a866ce64671b22c /core/java | |
| parent | 4cc7111329edcc0d89a3f352669127decdbd8a0a (diff) | |
Add hasEnabledNotificationListener API
This CL adds a system API to NotificationManager for checking whether
the NotificationListener for the current package name and user id is
enabled or not.
This replaces existing implementation which was using binder calls
directly to NotificationManagerService.
Bug: 160762852
Test: atest CtsMediaHostTestCases:\
android.media.session.cts.MediaSessionManagerHostTest\
#testGetActiveSessions_withSession2
-> MediaSessionManager#getActiveSessions verifies call by checking if
the notification listener is currently enabled.
Change-Id: Ic730b0abfe08c40171062421b2015be9cc05310a
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/INotificationManager.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/app/NotificationManager.java | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 0deef53c478f..a970322601ec 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -185,6 +185,7 @@ interface INotificationManager List<ComponentName> getEnabledNotificationListeners(int userId); ComponentName getAllowedNotificationAssistantForUser(int userId); ComponentName getAllowedNotificationAssistant(); + boolean hasEnabledNotificationListener(String packageName, int userId); @UnsupportedAppUsage int getZenMode(); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index eef9c022fda8..3f1e5614b90c 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; @@ -1539,6 +1540,25 @@ public class NotificationManager { } } + /** + * Whether the given user has an enabled + * {@link android.service.notification.NotificationListenerService} with the given package name. + * + * @param packageName the package name of the NotificationListenerService class + * @param userHandle the handle of the user that set the listener + * @hide + */ + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + @SuppressLint("UserHandle") + public boolean hasEnabledNotificationListener(@NonNull String packageName, + @NonNull UserHandle userHandle) { + INotificationManager service = getService(); + try { + return service.hasEnabledNotificationListener(packageName, userHandle.getIdentifier()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } private Context mContext; |
