Java Code Examples for android.app.NotificationManager#getNotificationPolicy()

The following examples show how to use android.app.NotificationManager#getNotificationPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoNotDisturbUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(23)
private static boolean handlePriority(@NonNull Context context, @NonNull NotificationManager notificationManager, @NonNull Recipient recipient) {
  if (Build.VERSION.SDK_INT < 28 && !notificationManager.isNotificationPolicyAccessGranted()) {
    Log.w(TAG, "Notification Policy is not granted");
    return true;
  }

  final NotificationManager.Policy policy                = notificationManager.getNotificationPolicy();
  final boolean                    areCallsPrioritized   = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_CALLS) != 0;
  final boolean                    isRepeatCallerEnabled = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) != 0;

  if (!areCallsPrioritized && !isRepeatCallerEnabled) {
    return false;
  }

  if (areCallsPrioritized && !isRepeatCallerEnabled) {
    return isContactPriority(context, recipient, policy.priorityCallSenders);
  }

  if (!areCallsPrioritized) {
    return isRepeatCaller(context, recipient);
  }

  return isContactPriority(context, recipient, policy.priorityCallSenders) || isRepeatCaller(context, recipient);
}
 
Example 2
Source File: AlarmNotifications.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(23)
@Nullable
private static NotificationManager.Policy getNotificationPolicy(NotificationManager notificationManager)
{
    if (notificationManager != null)
    {
        try {
            NotificationManager.Policy policy = notificationManager.getNotificationPolicy();    // does getting the policy require a permission? conflicting documentation..
            Log.d(TAG, "getNotificationPolicy: " + policy);
            return policy;

        } catch (SecurityException e) {
            Log.e(TAG, "getNotificationPolicy: Access Denied.. " + e);
            return null;
        }
    } else return null;
}
 
Example 3
Source File: ApiTwentyThreePlus.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isDoNotDisturbPolicyAllowingRinging(
        Context context, Address remoteAddress) {
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    int filter = notificationManager.getCurrentInterruptionFilter();
    if (filter == NotificationManager.INTERRUPTION_FILTER_PRIORITY) {
        Log.w("[Audio Manager] Priority interruption filter detected");
        boolean accessGranted = notificationManager.isNotificationPolicyAccessGranted();
        if (!accessGranted) {
            Log.e(
                    "[Audio Manager] Access to policy is denied, let's assume it is not safe for ringing");
            return false;
        }

        NotificationManager.Policy policy = notificationManager.getNotificationPolicy();
        int callPolicy = policy.priorityCallSenders;
        if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_ANY) {
            Log.i("[Audio Manager] Priority for calls is Any, we can ring");
        } else {
            if (remoteAddress == null) {
                Log.e(
                        "[Audio Manager] Remote address is null, let's assume it is not safe for ringing");
                return false;
            }

            LinphoneContact contact =
                    ContactsManager.getInstance().findContactFromAddress(remoteAddress);
            if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS) {
                Log.i("[Audio Manager] Priority for calls is Contacts, let's check");
                if (contact == null) {
                    Log.w(
                            "[Audio Manager] Couldn't find a contact for address "
                                    + remoteAddress.asStringUriOnly());
                    return false;
                } else {
                    Log.i(
                            "[Audio Manager] Contact found for address "
                                    + remoteAddress.asStringUriOnly()
                                    + ", we can ring");
                }
            } else if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_STARRED) {
                Log.i("[Audio Manager] Priority for calls is Starred Contacts, let's check");
                if (contact == null) {
                    Log.w(
                            "[Audio Manager] Couldn't find a contact for address "
                                    + remoteAddress.asStringUriOnly());
                    return false;
                } else if (!contact.isFavourite()) {
                    Log.w(
                            "[Audio Manager] Contact found for address "
                                    + remoteAddress.asStringUriOnly()
                                    + ", but it isn't starred");
                    return false;
                } else {
                    Log.i(
                            "[Audio Manager] Starred contact found for address "
                                    + remoteAddress.asStringUriOnly()
                                    + ", we can ring");
                }
            }
        }
    } else if (filter == NotificationManager.INTERRUPTION_FILTER_ALARMS) {
        Log.w("[Audio Manager] Alarms interruption filter detected");
        return false;
    } else {
        Log.i("[Audio Manager] Interruption filter is " + filter + ", we can ring");
    }

    return true;
}