diff --git a/core/api/current.txt b/core/api/current.txt index 4dd311c0bdc3b..ec897e4a44379 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6257,6 +6257,7 @@ package android.app { method public android.app.NotificationManager.Policy getNotificationPolicy(); method public boolean isNotificationListenerAccessGranted(android.content.ComponentName); method public boolean isNotificationPolicyAccessGranted(); + method @WorkerThread public boolean matchesCallFilter(@NonNull android.net.Uri); method public void notify(int, android.app.Notification); method public void notify(String, int, android.app.Notification); method public void notifyAsPackage(@NonNull String, @Nullable String, int, @NonNull android.app.Notification); diff --git a/core/api/test-current.txt b/core/api/test-current.txt index b225f5b97d2dd..372ad9da67e49 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -305,10 +305,10 @@ package android.app { public class NotificationManager { method public void allowAssistantAdjustment(String); + method public void cleanUpCallersAfter(long); method public void disallowAssistantAdjustment(String); method public android.content.ComponentName getEffectsSuppressor(); method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String); - method public boolean matchesCallFilter(android.os.Bundle); method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean, boolean); method @RequiresPermission(android.Manifest.permission.MANAGE_TOAST_RATE_LIMITING) public void setToastRateLimitingEnabled(boolean); method public void updateNotificationChannel(@NonNull String, int, @NonNull android.app.NotificationChannel); diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 098492c8234b5..01885b27e84ba 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 ccf1edb3fecc0..9be4adcbec753 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 { @@ -1089,6 +1089,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 */ @@ -2544,6 +2557,46 @@ public class NotificationManager { } } + /** + * Returns whether a call from the provided URI is permitted to notify the user. + *
+ * 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. + *
+ *+ * If Do Not Disturb is enabled and either no interruptions or only alarms are allowed, this + * method will return false regardless of input. + *
+ *
+ * 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
+ * mailto: or tel: 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.
+ *
+ * NOTE: This method calls into Contacts, which may take some time, and should not be called + * on the main thread. + *
+ * + * @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