Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 026456ec authored by Yuri Lin's avatar Yuri Lin
Browse files

Add matchesCallFilter function to NotificationManager.

This method takes a URI for a phone number that's calling and returns a boolean indicating whether the call would be allowed to interrupt the user. It's a light wrapper around the pre-existing (hidden) matchesCallFilter call that takes a Bundle with the same information.

Bug: 192592755
Test: atest NotificationManagerTest

Change-Id: I6e819b28b0f5047f005258bfd6044c6670628789
parent a3391604
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6255,6 +6255,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);
+1 −1
Original line number Diff line number Diff line
@@ -303,10 +303,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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
+54 −1
Original line number Diff line number Diff line
@@ -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.
     * <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) {
+6 −1
Original line number Diff line number Diff line
@@ -5022,7 +5022,6 @@ public class NotificationManagerService extends SystemService {

        @Override
        public boolean matchesCallFilter(Bundle extras) {
            enforceSystemOrSystemUI("INotificationManager.matchesCallFilter");
            return mZenModeHelper.matchesCallFilter(
                    Binder.getCallingUserHandle(),
                    extras,
@@ -5031,6 +5030,12 @@ public class NotificationManagerService extends SystemService {
                    MATCHES_CALL_FILTER_TIMEOUT_AFFINITY);
        }

        @Override
        public void cleanUpCallersAfter(long timeThreshold) {
            enforceSystemOrSystemUI("INotificationManager.cleanUpCallersAfter");
            mZenModeHelper.cleanUpCallersAfter(timeThreshold);
        }

        @Override
        public boolean isSystemConditionProviderEnabled(String path) {
            enforceSystemOrSystemUI("INotificationManager.isSystemConditionProviderEnabled");
Loading