diff options
| author | Julia Reynolds <juliacr@google.com> | 2021-04-05 13:30:57 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-04-05 13:30:57 +0000 |
| commit | 47fe65234faaf32fe2450e810ead596f30e8d1df (patch) | |
| tree | 860b9d7c89b7cbb725cc18ad930b82a011074bb6 /core/java | |
| parent | 6c63ebbb9e64dbccc563eebdd079cef549d57ac8 (diff) | |
| parent | 0e36d959d0fc2dbf7bbec2d33f297b400ac01197 (diff) | |
Merge "Allow apps to migrate NLS filter settings" into sc-dev
Diffstat (limited to 'core/java')
3 files changed, 34 insertions, 4 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index d0e17f00e990..dab5aff5c9a8 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -228,6 +228,7 @@ interface INotificationManager NotificationListenerFilter getListenerFilter(in ComponentName cn, int userId); void setListenerFilter(in ComponentName cn, int userId, in NotificationListenerFilter nlf); + void migrateNotificationFilter(in INotificationListener token, int defaultTypes, in List<String> disallowedPkgs); void setToastRateLimitingEnabled(boolean enable); } diff --git a/core/java/android/service/notification/NotificationListenerFilter.java b/core/java/android/service/notification/NotificationListenerFilter.java index 9de75cac159a..a69d33c17e9d 100644 --- a/core/java/android/service/notification/NotificationListenerFilter.java +++ b/core/java/android/service/notification/NotificationListenerFilter.java @@ -31,15 +31,17 @@ import android.util.ArraySet; * @hide */ public class NotificationListenerFilter implements Parcelable { + + private static final int DEFAULT_TYPES = FLAG_FILTER_TYPE_CONVERSATIONS + | FLAG_FILTER_TYPE_ALERTING + | FLAG_FILTER_TYPE_SILENT + | FLAG_FILTER_TYPE_ONGOING; private int mAllowedNotificationTypes; // VersionedPackage is holding the pkg name and pkg uid private ArraySet<VersionedPackage> mDisallowedPackages; public NotificationListenerFilter() { - mAllowedNotificationTypes = FLAG_FILTER_TYPE_CONVERSATIONS - | FLAG_FILTER_TYPE_ALERTING - | FLAG_FILTER_TYPE_SILENT - | FLAG_FILTER_TYPE_ONGOING; + mAllowedNotificationTypes = DEFAULT_TYPES; mDisallowedPackages = new ArraySet<>(); } @@ -80,6 +82,10 @@ public class NotificationListenerFilter implements Parcelable { return (mAllowedNotificationTypes & type) != 0; } + public boolean areAllTypesAllowed() { + return DEFAULT_TYPES == mAllowedNotificationTypes; + } + public boolean isPackageAllowed(VersionedPackage pkg) { return !mDisallowedPackages.contains(pkg); } diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index 09c3b2effcb0..6c775852fcee 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -792,6 +792,29 @@ public abstract class NotificationListenerService extends Service { } } + /** + * Lets an app migrate notification filters from its app into the OS. + * + * <p>This call will be ignored if the app has already migrated these settings or the user + * has set filters in the UI. This method is intended for user specific settings; if an app has + * already specified defaults types in its manifest with + * {@link #META_DATA_DEFAULT_FILTER_TYPES}, the defaultTypes option will be ignored.</p> + * @param defaultTypes A value representing the types of notifications that this listener should + * receive by default + * @param disallowedPkgs A list of package names whose notifications should not be seen by this + * listener, by default, because the listener does not process or display them, or because a + * user had previously disallowed these packages in the listener app's UI + */ + public final void migrateNotificationFilter(@NotificationFilterTypes int defaultTypes, + @Nullable List<String> disallowedPkgs) { + if (!isBound()) return; + try { + getNotificationInterface().migrateNotificationFilter( + mWrapper, defaultTypes, disallowedPkgs); + } catch (android.os.RemoteException ex) { + Log.v(TAG, "Unable to contact notification manager", ex); + } + } /** * Inform the notification manager that these notifications have been viewed by the |
