Fix do not disturb settings for calls.

This commit is contained in:
Michelle Tang 2025-01-16 11:14:19 -05:00 committed by Greyson Parrelli
parent 1459dbf64d
commit f9ec9ac2fd
2 changed files with 23 additions and 12 deletions

View file

@ -52,12 +52,15 @@ public final class DoNotDisturbUtil {
NotificationManager notificationManager = ServiceUtil.getNotificationManager(context); NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
switch (notificationManager.getCurrentInterruptionFilter()) { switch (notificationManager.getCurrentInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
return true;
case NotificationManager.INTERRUPTION_FILTER_PRIORITY: case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
return handlePriority(context, notificationManager, recipient); return handlePriority(context, notificationManager, recipient);
case NotificationManager.INTERRUPTION_FILTER_NONE: case NotificationManager.INTERRUPTION_FILTER_NONE:
case NotificationManager.INTERRUPTION_FILTER_ALARMS: case NotificationManager.INTERRUPTION_FILTER_ALARMS:
return false; return false;
default: default:
Log.w(TAG, "Unknown interruption filter, will interrupt user: " + notificationManager.getCurrentInterruptionFilter());
return true; return true;
} }
} }
@ -77,25 +80,37 @@ public final class DoNotDisturbUtil {
return false; return false;
} }
final boolean isContactPriority = isContactPriority(context, recipient, policy.priorityCallSenders);
final boolean isRepeatCaller = isRepeatCaller(context, recipient);
Log.i(TAG, "Handling priority - Contact priority: " + isContactPriority + ", Repeat caller: " + isRepeatCaller);
if (areCallsPrioritized && !isRepeatCallerEnabled) { if (areCallsPrioritized && !isRepeatCallerEnabled) {
return isContactPriority(context, recipient, policy.priorityCallSenders); return isContactPriority;
} }
if (!areCallsPrioritized) { if (!areCallsPrioritized) {
return isRepeatCaller(context, recipient); return isRepeatCaller;
} }
return isContactPriority(context, recipient, policy.priorityCallSenders) || isRepeatCaller(context, recipient); return isContactPriority || isRepeatCaller;
} }
private static boolean isContactPriority(@NonNull Context context, @NonNull Recipient recipient, int priority) { private static boolean isContactPriority(@NonNull Context context, @NonNull Recipient recipient, int priority) {
if (!Permissions.hasAny(context, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
return false;
}
boolean isSystemContact = recipient.resolve().isSystemContact();
boolean isContactStarred = isContactStarred(context, recipient);
Log.i(TAG, "Checking contact priority - Priority " + priority + ", System contact: " + isSystemContact + ", Starred contact: " + isContactStarred);
switch (priority) { switch (priority) {
case NotificationManager.Policy.PRIORITY_SENDERS_ANY: case NotificationManager.Policy.PRIORITY_SENDERS_ANY:
return true; return true;
case NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS: case NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS:
return recipient.resolve().isSystemContact(); return isSystemContact;
case NotificationManager.Policy.PRIORITY_SENDERS_STARRED: case NotificationManager.Policy.PRIORITY_SENDERS_STARRED:
return isContactStarred(context, recipient); return isContactStarred;
} }
Log.w(TAG, "Unknown priority " + priority); Log.w(TAG, "Unknown priority " + priority);
@ -105,10 +120,6 @@ public final class DoNotDisturbUtil {
private static boolean isContactStarred(@NonNull Context context, @NonNull Recipient recipient) { private static boolean isContactStarred(@NonNull Context context, @NonNull Recipient recipient) {
if (!recipient.resolve().isSystemContact()) return false; if (!recipient.resolve().isSystemContact()) return false;
if (!Permissions.hasAny(context, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
return false;
}
//noinspection ConstantConditions //noinspection ConstantConditions
try (Cursor cursor = context.getContentResolver().query(recipient.resolve().getContactUri(), new String[]{ContactsContract.Contacts.STARRED}, null, null, null)) { try (Cursor cursor = context.getContentResolver().query(recipient.resolve().getContactUri(), new String[]{ContactsContract.Contacts.STARRED}, null, null, null)) {
if (cursor == null || !cursor.moveToFirst()) return false; if (cursor == null || !cursor.moveToFirst()) return false;

View file

@ -174,8 +174,9 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
protected @NonNull WebRtcServiceState handleLocalRinging(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleLocalRinging(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
Log.i(TAG, "handleLocalRinging(): call_id: " + remotePeer.getCallId()); Log.i(TAG, "handleLocalRinging(): call_id: " + remotePeer.getCallId());
RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer(); RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
Recipient recipient = remotePeer.getRecipient(); Recipient recipient = remotePeer.getRecipient();
boolean shouldDisturbUserWithCall = DoNotDisturbUtil.shouldDisturbUserWithCall(context.getApplicationContext(), recipient);
activePeer.localRinging(); activePeer.localRinging();
@ -187,7 +188,6 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
CallTable.Event.ONGOING); CallTable.Event.ONGOING);
boolean shouldDisturbUserWithCall = DoNotDisturbUtil.shouldDisturbUserWithCall(context.getApplicationContext(), recipient);
if (shouldDisturbUserWithCall) { if (shouldDisturbUserWithCall) {
webRtcInteractor.updatePhoneState(LockManager.PhoneState.INTERACTIVE); webRtcInteractor.updatePhoneState(LockManager.PhoneState.INTERACTIVE);
boolean started = webRtcInteractor.startWebRtcCallActivityIfPossible(); boolean started = webRtcInteractor.startWebRtcCallActivityIfPossible();