1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-22 06:41:06 +02:00

Add support for native Do Not Disturb call/SMS functionality on Fossil watches

This commit is contained in:
mvn23 2022-05-15 16:51:41 +02:00 committed by Gitea
parent 65ebdb6ff8
commit 9ca3fff101
9 changed files with 35 additions and 18 deletions

View File

@ -438,10 +438,8 @@ public class GBApplication extends Application {
@TargetApi(Build.VERSION_CODES.M)
public static int getGrantedInterruptionFilter() {
if (prefs.getBoolean("notification_filter", false) && GBApplication.isRunningMarshmallowOrLater()) {
if (notificationManager.isNotificationPolicyAccessGranted()) {
return notificationManager.getCurrentInterruptionFilter();
}
if (GBApplication.isRunningMarshmallowOrLater() && notificationManager.isNotificationPolicyAccessGranted()) {
return notificationManager.getCurrentInterruptionFilter();
}
return NotificationManager.INTERRUPTION_FILTER_ALL;
}

View File

@ -107,22 +107,28 @@ public class PhoneCallReceiver extends BroadcastReceiver {
if ("never".equals(prefs.getString("notification_mode_calls", "always"))) {
return;
}
int dndSuppressed = 0;
switch (GBApplication.getGrantedInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
break;
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
case NotificationManager.INTERRUPTION_FILTER_NONE:
return;
dndSuppressed = 1;
break;
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_CALLS, mSavedNumber)) {
break;
}
// FIXME: Handle Repeat callers if it is enabled in Do Not Disturb
return;
dndSuppressed = 1;
}
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
return;
}
CallSpec callSpec = new CallSpec();
callSpec.number = mSavedNumber;
callSpec.command = callCommand;
callSpec.dndSuppressed = dndSuppressed;
GBApplication.deviceService().onSetCallState(callSpec);
}
mLastState = state;

View File

@ -87,18 +87,24 @@ public class SMSReceiver extends BroadcastReceiver {
dismissAllAction.type = NotificationSpec.Action.TYPE_SYNTECTIC_DISMISS_ALL;
notificationSpec.attachedActions.add(dismissAllAction);
int dndSuppressed = 0;
switch (GBApplication.getGrantedInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
break;
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
case NotificationManager.INTERRUPTION_FILTER_NONE:
return;
dndSuppressed = 1;
break;
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_MESSAGES, notificationSpec.phoneNumber)) {
break;
}
return;
dndSuppressed = 1;
}
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
return;
}
notificationSpec.dndSuppressed = dndSuppressed;
GBApplication.deviceService().onNotification(notificationSpec);
}
}

View File

@ -201,7 +201,8 @@ public class GBDeviceService implements DeviceService {
Intent intent = createIntent().setAction(ACTION_CALLSTATE)
.putExtra(EXTRA_CALL_PHONENUMBER, callSpec.number)
.putExtra(EXTRA_CALL_DISPLAYNAME, callSpec.name)
.putExtra(EXTRA_CALL_COMMAND, callSpec.command);
.putExtra(EXTRA_CALL_COMMAND, callSpec.command)
.putExtra(EXTRA_CALL_DNDSUPPRESSED, callSpec.dndSuppressed);
invokeService(intent);
}

View File

@ -28,4 +28,5 @@ public class CallSpec {
public String number;
public String name;
public int command;
public int dndSuppressed;
}

View File

@ -91,6 +91,7 @@ public interface DeviceService extends EventHandler {
String EXTRA_CALL_COMMAND = "call_command";
String EXTRA_CALL_PHONENUMBER = "call_phonenumber";
String EXTRA_CALL_DISPLAYNAME = "call_displayname";
String EXTRA_CALL_DNDSUPPRESSED = "call_dndsuppressed";
String EXTRA_CANNEDMESSAGES = "cannedmessages";
String EXTRA_CANNEDMESSAGES_TYPE = "cannedmessages_type";
String EXTRA_MUSIC_ARTIST = "music_artist";

View File

@ -141,6 +141,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CAL
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALENDAREVENT_TYPE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_DISPLAYNAME;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_DNDSUPPRESSED;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_PHONENUMBER;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CANNEDMESSAGES;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CANNEDMESSAGES_TYPE;
@ -511,6 +512,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
callSpec.command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
callSpec.number = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
callSpec.name = sanitizeNotifText(intent.getStringExtra(EXTRA_CALL_DISPLAYNAME));
callSpec.dndSuppressed = intent.getIntExtra(EXTRA_CALL_DNDSUPPRESSED, 0);
mDeviceSupport.onSetCallState(callSpec);
break;
case ACTION_SETCANNEDMESSAGES:

View File

@ -1157,10 +1157,10 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
boolean quickRepliesEnabled = quickReplies.length > 0 && callSpec.number != null && callSpec.number.matches("^\\+(?:[0-9] ?){6,14}[0-9]$");
if (callSpec.command == CallSpec.CALL_INCOMING) {
currentCallSpec = callSpec;
queueWrite(new PlayCallNotificationRequest(StringUtils.getFirstOf(callSpec.name, callSpec.number), true, quickRepliesEnabled, this));
queueWrite(new PlayCallNotificationRequest(StringUtils.getFirstOf(callSpec.name, callSpec.number), true, quickRepliesEnabled, callSpec.dndSuppressed, this));
} else {
currentCallSpec = null;
queueWrite(new PlayCallNotificationRequest(StringUtils.getFirstOf(callSpec.name, callSpec.number), false, quickRepliesEnabled, this));
queueWrite(new PlayCallNotificationRequest(StringUtils.getFirstOf(callSpec.name, callSpec.number), false, quickRepliesEnabled, callSpec.dndSuppressed, this));
}
}
@ -1616,7 +1616,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
private void handleCallRequest(byte[] value) {
boolean acceptCall = value[7] == (byte) 0x00;
queueWrite(new PlayCallNotificationRequest("", false, false, this));
queueWrite(new PlayCallNotificationRequest("", false, false, 0,this));
GBDeviceEventCallControl callControlEvent = new GBDeviceEventCallControl();
callControlEvent.event = acceptCall ? GBDeviceEventCallControl.Event.START : GBDeviceEventCallControl.Event.REJECT;

View File

@ -24,18 +24,20 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.foss
public class PlayCallNotificationRequest extends PlayNotificationRequest {
private final static int MESSAGE_ID_CALL = 1;
private static int notificationFlags(boolean callStart, boolean quickReplies) {
private static int notificationFlags(boolean callStart, boolean quickReplies, int dndSuppressed) {
int flags = 0;
if (callStart && quickReplies) {
return 0b00111000;
flags = 0b00111000;
} else if (callStart) {
return 0b00011000;
flags = 0b00011000;
} else {
return 0b00000010;
flags = 0b00000010;
}
return (flags | dndSuppressed);
}
public PlayCallNotificationRequest(String number, boolean callStart, boolean quickReplies, FossilWatchAdapter adapter) {
super(callStart ? NotificationType.INCOMING_CALL : NotificationType.DISMISS_NOTIFICATION, notificationFlags(callStart, quickReplies),
public PlayCallNotificationRequest(String number, boolean callStart, boolean quickReplies, int dndSuppressed, FossilWatchAdapter adapter) {
super(callStart ? NotificationType.INCOMING_CALL : NotificationType.DISMISS_NOTIFICATION, notificationFlags(callStart, quickReplies, dndSuppressed),
ByteBuffer.wrap(new byte[]{(byte) 0x80, (byte) 0x00, (byte) 0x59, (byte) 0xB7}).order(ByteOrder.LITTLE_ENDIAN).getInt(),
number, "Incoming Call", MESSAGE_ID_CALL, adapter);
}