diff options
| author | 2020-10-14 21:10:06 +0000 | |
|---|---|---|
| committer | 2020-10-14 21:10:06 +0000 | |
| commit | 4587809e21fccd31ab3d096f5dd4bece6d1e2dbb (patch) | |
| tree | 087cd12bd6e51fb4288d5a10a4a3b64420352020 | |
| parent | 6312580f8c3dae588ef894dad285a977dbbb3156 (diff) | |
| parent | 0642113b7c2f8316205b8d899299f47c92d82bc5 (diff) | |
Merge "Expose get/set notification listeners as a @SystemAPI"
| -rw-r--r-- | api/system-current.txt | 3 | ||||
| -rw-r--r-- | api/test-current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/NotificationManager.java | 31 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 6 | ||||
| -rw-r--r-- | non-updatable-api/system-current.txt | 3 | ||||
| -rw-r--r-- | packages/Shell/AndroidManifest.xml | 3 | ||||
| -rwxr-xr-x | services/core/java/com/android/server/notification/NotificationManagerService.java | 12 |
7 files changed, 57 insertions, 4 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index c1ac0c276c4c..daf712c3b9ad 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -122,6 +122,7 @@ package android { field public static final String MANAGE_FACTORY_RESET_PROTECTION = "android.permission.MANAGE_FACTORY_RESET_PROTECTION"; field public static final String MANAGE_IPSEC_TUNNELS = "android.permission.MANAGE_IPSEC_TUNNELS"; field public static final String MANAGE_MUSIC_RECOGNITION = "android.permission.MANAGE_MUSIC_RECOGNITION"; + field public static final String MANAGE_NOTIFICATION_LISTENERS = "android.permission.MANAGE_NOTIFICATION_LISTENERS"; field public static final String MANAGE_ONE_TIME_PERMISSION_SESSIONS = "android.permission.MANAGE_ONE_TIME_PERMISSION_SESSIONS"; field public static final String MANAGE_ROLE_HOLDERS = "android.permission.MANAGE_ROLE_HOLDERS"; field public static final String MANAGE_ROLLBACKS = "android.permission.MANAGE_ROLLBACKS"; @@ -674,8 +675,10 @@ package android.app { public class NotificationManager { method @NonNull public java.util.List<java.lang.String> getAllowedAssistantAdjustments(); method @Nullable public android.content.ComponentName getAllowedNotificationAssistant(); + method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public java.util.List<android.content.ComponentName> getEnabledNotificationListeners(); method public boolean isNotificationAssistantAccessGranted(@NonNull android.content.ComponentName); method public void setNotificationAssistantAccessGranted(@Nullable android.content.ComponentName, boolean); + method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean); field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_CLOSE_NOTIFICATION_HANDLER_PANEL = "android.app.action.CLOSE_NOTIFICATION_HANDLER_PANEL"; field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_OPEN_NOTIFICATION_HANDLER_PANEL = "android.app.action.OPEN_NOTIFICATION_HANDLER_PANEL"; field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_TOGGLE_NOTIFICATION_HANDLER_PANEL = "android.app.action.TOGGLE_NOTIFICATION_HANDLER_PANEL"; diff --git a/api/test-current.txt b/api/test-current.txt index 3c44a3c45744..6c3df282e09a 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -14,6 +14,7 @@ package android { field public static final String FORCE_STOP_PACKAGES = "android.permission.FORCE_STOP_PACKAGES"; field public static final String MANAGE_ACTIVITY_STACKS = "android.permission.MANAGE_ACTIVITY_STACKS"; field public static final String MANAGE_CRATES = "android.permission.MANAGE_CRATES"; + field public static final String MANAGE_NOTIFICATION_LISTENERS = "android.permission.MANAGE_NOTIFICATION_LISTENERS"; field public static final String MANAGE_ROLLBACKS = "android.permission.MANAGE_ROLLBACKS"; field public static final String NETWORK_SETTINGS = "android.permission.NETWORK_SETTINGS"; field public static final String NETWORK_STACK = "android.permission.NETWORK_STACK"; @@ -494,9 +495,11 @@ package android.app { method @NonNull public java.util.List<java.lang.String> getAllowedAssistantAdjustments(); method @Nullable public android.content.ComponentName getAllowedNotificationAssistant(); method public android.content.ComponentName getEffectsSuppressor(); + method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public java.util.List<android.content.ComponentName> getEnabledNotificationListeners(); method public boolean isNotificationAssistantAccessGranted(@NonNull android.content.ComponentName); method public boolean matchesCallFilter(android.os.Bundle); method public void setNotificationAssistantAccessGranted(@Nullable android.content.ComponentName, boolean); + method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean); method public void updateNotificationChannel(@NonNull String, int, @NonNull android.app.NotificationChannel); } diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index fe8936654aa4..d442f5f321ec 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -1567,8 +1567,20 @@ public class NotificationManager { } } - /** @hide */ - public void setNotificationListenerAccessGranted(ComponentName listener, boolean granted) { + /** + * Grants/revokes Notification Listener access to the given component for current user. + * To grant access for a particular user, obtain this service by using the {@link Context} + * provided by {@link Context#createPackageContextAsUser} + * + * @param listener Name of component to grant/revoke access + * @param granted Grant/revoke access + * @hide + */ + @SystemApi + @TestApi + @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) + public void setNotificationListenerAccessGranted( + @NonNull ComponentName listener, boolean granted) { INotificationManager service = getService(); try { service.setNotificationListenerAccessGranted(listener, granted); @@ -1610,6 +1622,21 @@ public class NotificationManager { } } + /** + * Gets the list of enabled notification listener components for current user. + * To query for a particular user, obtain this service by using the {@link Context} + * provided by {@link Context#createPackageContextAsUser} + * + * @return the list of {@link ComponentName}s of the notification listeners + * @hide + */ + @SystemApi + @TestApi + @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) + public @NonNull List<ComponentName> getEnabledNotificationListeners() { + return getEnabledNotificationListeners(mContext.getUserId()); + } + /** @hide */ public List<ComponentName> getEnabledNotificationListeners(int userId) { INotificationManager service = getService(); diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index e2f4f2f9294b..f2af514c08ba 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -4518,6 +4518,12 @@ <permission android:name="android.permission.MANAGE_NOTIFICATIONS" android:protectionLevel="signature" /> + <!-- @SystemApi @TestApi Allows adding/removing enabled notification listener components. + @hide --> + <permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" + android:protectionLevel="signature" /> + <uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" /> + <!-- Allows notifications to be colorized <p>Not for use by third-party applications. @hide --> <permission android:name="android.permission.USE_COLORIZED_NOTIFICATIONS" diff --git a/non-updatable-api/system-current.txt b/non-updatable-api/system-current.txt index 4cf1b2202256..e0395d45a1b0 100644 --- a/non-updatable-api/system-current.txt +++ b/non-updatable-api/system-current.txt @@ -122,6 +122,7 @@ package android { field public static final String MANAGE_FACTORY_RESET_PROTECTION = "android.permission.MANAGE_FACTORY_RESET_PROTECTION"; field public static final String MANAGE_IPSEC_TUNNELS = "android.permission.MANAGE_IPSEC_TUNNELS"; field public static final String MANAGE_MUSIC_RECOGNITION = "android.permission.MANAGE_MUSIC_RECOGNITION"; + field public static final String MANAGE_NOTIFICATION_LISTENERS = "android.permission.MANAGE_NOTIFICATION_LISTENERS"; field public static final String MANAGE_ONE_TIME_PERMISSION_SESSIONS = "android.permission.MANAGE_ONE_TIME_PERMISSION_SESSIONS"; field public static final String MANAGE_ROLE_HOLDERS = "android.permission.MANAGE_ROLE_HOLDERS"; field public static final String MANAGE_ROLLBACKS = "android.permission.MANAGE_ROLLBACKS"; @@ -674,8 +675,10 @@ package android.app { public class NotificationManager { method @NonNull public java.util.List<java.lang.String> getAllowedAssistantAdjustments(); method @Nullable public android.content.ComponentName getAllowedNotificationAssistant(); + method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public java.util.List<android.content.ComponentName> getEnabledNotificationListeners(); method public boolean isNotificationAssistantAccessGranted(@NonNull android.content.ComponentName); method public void setNotificationAssistantAccessGranted(@Nullable android.content.ComponentName, boolean); + method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean); field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_CLOSE_NOTIFICATION_HANDLER_PANEL = "android.app.action.CLOSE_NOTIFICATION_HANDLER_PANEL"; field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_OPEN_NOTIFICATION_HANDLER_PANEL = "android.app.action.OPEN_NOTIFICATION_HANDLER_PANEL"; field @RequiresPermission(android.Manifest.permission.STATUS_BAR_SERVICE) public static final String ACTION_TOGGLE_NOTIFICATION_HANDLER_PANEL = "android.app.action.TOGGLE_NOTIFICATION_HANDLER_PANEL"; diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index bba29dba0827..5f018a0322a3 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -335,6 +335,9 @@ <!-- Permission required for CTS test - android.server.biometrics --> <uses-permission android:name="android.permission.TEST_BIOMETRIC" /> + <!-- Permissions required for CTS test - NotificationManagerTest --> + <uses-permission android:name="android.permission.MANAGE_NOTIFICATION_LISTENERS" /> + <application android:label="@string/app_label" android:theme="@android:style/Theme.DeviceDefault.DayNight" android:defaultToDeviceProtectedStorage="true" diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 23798c0622fc..03bf74f40205 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -4769,7 +4769,7 @@ public class NotificationManagerService extends SystemService { @Override public List<ComponentName> getEnabledNotificationListeners(int userId) { - checkCallerIsSystem(); + checkNotificationListenerAccess(); return mListeners.getAllowedComponents(userId); } @@ -4838,7 +4838,7 @@ public class NotificationManagerService extends SystemService { public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId, boolean granted) { Objects.requireNonNull(listener); - checkCallerIsSystemOrShell(); + checkNotificationListenerAccess(); final long identity = Binder.clearCallingIdentity(); try { if (mAllowedManagedServicePackages.test( @@ -5111,6 +5111,14 @@ public class NotificationManagerService extends SystemService { } }; + protected void checkNotificationListenerAccess() { + if (!isCallerSystemOrPhone()) { + getContext().enforceCallingPermission( + permission.MANAGE_NOTIFICATION_LISTENERS, + "Caller must hold " + permission.MANAGE_NOTIFICATION_LISTENERS); + } + } + @VisibleForTesting protected void setNotificationAssistantAccessGrantedForUserInternal( ComponentName assistant, int baseUserId, boolean granted) { |