summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorYuri Lin <yurilin@google.com>2021-10-12 15:11:58 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-10-12 15:11:58 +0000
commitbf88de825aa0619a2abdd5192ff2ef8bd31741b1 (patch)
treeab59f4a06861d1da21536bc47d84bac0a7b746b4 /core/java
parent3866f66fcb039a9c63b7c472f4b718994f464d0f (diff)
parent026456eccee8390343a1cf46b8ef6bc3ded92ebd (diff)
Merge "Add matchesCallFilter function to NotificationManager."
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/INotificationManager.aidl1
-rw-r--r--core/java/android/app/NotificationManager.java55
2 files changed, 55 insertions, 1 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 098492c8234b..01885b27e84b 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -175,6 +175,7 @@ interface INotificationManager
ComponentName getEffectsSuppressor();
boolean matchesCallFilter(in Bundle extras);
+ void cleanUpCallersAfter(long timeThreshold);
boolean isSystemConditionProviderEnabled(String path);
boolean isNotificationListenerAccessGranted(in ComponentName listener);
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index ccf1edb3fecc..9be4adcbec75 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -25,6 +25,7 @@ import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
+import android.annotation.WorkerThread;
import android.app.Notification.Builder;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
@@ -1079,7 +1080,6 @@ public class NotificationManager {
/**
* @hide
*/
- @TestApi
public boolean matchesCallFilter(Bundle extras) {
INotificationManager service = getService();
try {
@@ -1092,6 +1092,19 @@ public class NotificationManager {
/**
* @hide
*/
+ @TestApi
+ public void cleanUpCallersAfter(long timeThreshold) {
+ INotificationManager service = getService();
+ try {
+ service.cleanUpCallersAfter(timeThreshold);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * @hide
+ */
public boolean isSystemConditionProviderEnabled(String path) {
INotificationManager service = getService();
try {
@@ -2544,6 +2557,46 @@ public class NotificationManager {
}
}
+ /**
+ * Returns whether a call from the provided URI is permitted to notify the user.
+ * <p>
+ * A true return value indicates one of the following: Do Not Disturb is not currently active;
+ * or the caller is a repeat caller and the current policy allows interruptions from repeat
+ * callers; or the caller is in the user's set of contacts whose calls are allowed to interrupt
+ * Do Not Disturb.
+ * </p>
+ * <p>
+ * If Do Not Disturb is enabled and either no interruptions or only alarms are allowed, this
+ * method will return false regardless of input.
+ * </p>
+ * <p>
+ * The provided URI must meet the requirements for a URI associated with a
+ * {@link Person}: it may be the {@code String} representation of a
+ * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}, or a
+ * <code>mailto:</code> or <code>tel:</code> schema URI matching an entry in the
+ * Contacts database. See also {@link Person.Builder#setUri} and
+ * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
+ * for more information.
+ * </p>
+ * <p>
+ * NOTE: This method calls into Contacts, which may take some time, and should not be called
+ * on the main thread.
+ * </p>
+ *
+ * @param uri A URI representing a caller. Must not be null.
+ * @return A boolean indicating whether a call from the URI provided would be allowed to
+ * interrupt the user given the current filter.
+ */
+ @WorkerThread
+ public boolean matchesCallFilter(@NonNull Uri uri) {
+ Bundle extras = new Bundle();
+ ArrayList<Person> pList = new ArrayList<>();
+ pList.add(new Person.Builder().setUri(uri.toString()).build());
+ extras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST, pList);
+
+ return matchesCallFilter(extras);
+ }
+
/** @hide */
public static int zenModeToInterruptionFilter(int zen) {
switch (zen) {