summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/INotificationManager.aidl4
-rw-r--r--core/java/android/service/notification/NotificationListenerFilter.aidl20
-rw-r--r--core/java/android/service/notification/NotificationListenerFilter.java102
-rw-r--r--core/java/android/service/notification/NotificationListenerService.java17
4 files changed, 143 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index a8ce73d9bd27..697a377dd99f 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -35,6 +35,7 @@ import android.service.notification.Condition;
import android.service.notification.IConditionListener;
import android.service.notification.IConditionProvider;
import android.service.notification.INotificationListener;
+import android.service.notification.NotificationListenerFilter;
import android.service.notification.StatusBarNotification;
import android.app.AutomaticZenRule;
import android.service.notification.ZenModeConfig;
@@ -224,4 +225,7 @@ interface INotificationManager
boolean getPrivateNotificationsAllowed();
long pullStats(long startNs, int report, boolean doAgg, out List<ParcelFileDescriptor> stats);
+
+ NotificationListenerFilter getListenerFilter(in ComponentName cn, int userId);
+ void setListenerFilter(in ComponentName cn, int userId, in NotificationListenerFilter nlf);
}
diff --git a/core/java/android/service/notification/NotificationListenerFilter.aidl b/core/java/android/service/notification/NotificationListenerFilter.aidl
new file mode 100644
index 000000000000..c186b74d04f7
--- /dev/null
+++ b/core/java/android/service/notification/NotificationListenerFilter.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.notification;
+
+parcelable NotificationListenerFilter;
+
diff --git a/core/java/android/service/notification/NotificationListenerFilter.java b/core/java/android/service/notification/NotificationListenerFilter.java
new file mode 100644
index 000000000000..c945c2d64519
--- /dev/null
+++ b/core/java/android/service/notification/NotificationListenerFilter.java
@@ -0,0 +1,102 @@
+/**
+ * Copyright (c) 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.service.notification;
+
+import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING;
+import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_CONVERSATIONS;
+import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_SILENT;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.ArraySet;
+
+/**
+ * Specifies a filter for what types of notifications should be bridged to notification listeners.
+ * Each requested listener will have their own filter instance.
+ * @hide
+ */
+public class NotificationListenerFilter implements Parcelable {
+ private int mAllowedNotificationTypes;
+ private ArraySet<String> mDisallowedPackages;
+
+ public NotificationListenerFilter() {
+ mAllowedNotificationTypes = FLAG_FILTER_TYPE_CONVERSATIONS
+ | FLAG_FILTER_TYPE_ALERTING
+ | FLAG_FILTER_TYPE_SILENT;
+ mDisallowedPackages = new ArraySet<>();
+ }
+
+ public NotificationListenerFilter(int types, ArraySet<String> pkgs) {
+ mAllowedNotificationTypes = types;
+ mDisallowedPackages = pkgs;
+ }
+
+ /**
+ * @hide
+ */
+ protected NotificationListenerFilter(Parcel in) {
+ mAllowedNotificationTypes = in.readInt();
+ mDisallowedPackages = (ArraySet<String>) in.readArraySet(String.class.getClassLoader());
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mAllowedNotificationTypes);
+ dest.writeArraySet(mDisallowedPackages);
+ }
+
+ public static final Creator<NotificationListenerFilter> CREATOR =
+ new Creator<NotificationListenerFilter>() {
+ @Override
+ public NotificationListenerFilter createFromParcel(Parcel in) {
+ return new NotificationListenerFilter(in);
+ }
+
+ @Override
+ public NotificationListenerFilter[] newArray(int size) {
+ return new NotificationListenerFilter[size];
+ }
+ };
+
+ public boolean isTypeAllowed(int type) {
+ return (mAllowedNotificationTypes & type) != 0;
+ }
+
+ public boolean isPackageAllowed(String pkg) {
+ return !mDisallowedPackages.contains(pkg);
+ }
+
+ public int getTypes() {
+ return mAllowedNotificationTypes;
+ }
+
+ public ArraySet<String> getDisallowedPackages() {
+ return mDisallowedPackages;
+ }
+
+ public void setTypes(int types) {
+ mAllowedNotificationTypes = types;
+ }
+
+ public void setDisallowedPackages(ArraySet<String> pkgs) {
+ mDisallowedPackages = pkgs;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 440eeb1619f0..ccde0bcf71c3 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -242,6 +242,23 @@ public abstract class NotificationListenerService extends Service {
public @interface NotificationCancelReason{};
/**
+ * A flag value indicating that this notification listener can see conversation type
+ * notifications.
+ * @hide
+ */
+ public static final int FLAG_FILTER_TYPE_CONVERSATIONS = 1;
+ /**
+ * A flag value indicating that this notification listener can see altering type notifications.
+ * @hide
+ */
+ public static final int FLAG_FILTER_TYPE_ALERTING = 2;
+ /**
+ * A flag value indicating that this notification listener can see silent type notifications.
+ * @hide
+ */
+ public static final int FLAG_FILTER_TYPE_SILENT = 4;
+
+ /**
* The full trim of the StatusBarNotification including all its features.
*
* @hide