From 7e0de29dd75a981446183d59ccf757ceb399d8d8 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 26 Nov 2019 11:51:13 -0400 Subject: [PATCH] Add notification policy permission and runtime check. Fixes #9217 --- AndroidManifest.xml | 1 + .../securesms/notifications/DoNotDisturbUtil.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2e6261673d..921daf8c9a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -27,6 +27,7 @@ tools:ignore="ProtectedPermissions"/> + diff --git a/src/org/thoughtcrime/securesms/notifications/DoNotDisturbUtil.java b/src/org/thoughtcrime/securesms/notifications/DoNotDisturbUtil.java index 50e96ca4bc..0559cc4565 100644 --- a/src/org/thoughtcrime/securesms/notifications/DoNotDisturbUtil.java +++ b/src/org/thoughtcrime/securesms/notifications/DoNotDisturbUtil.java @@ -43,6 +43,11 @@ public final class DoNotDisturbUtil { @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;