From a5dbb7fea7289e9cc97fdc192cbf198f51039de2 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Fri, 3 May 2024 09:30:38 +0200 Subject: [PATCH] Garmin: fix regression in call handling Add a fictitious action to the notification to enable reply/hangup/reject from the watch. Also fixes the behavior on sms reply, which should also reject the incoming call. Change the log level in case some of the canned messages types are left as default to info, as this is a supported scenario. --- .../devices/garmin/NotificationsHandler.java | 17 ++++++++++++----- .../devices/garmin/ProtocolBufferHandler.java | 2 +- .../messages/NotificationControlMessage.java | 13 +++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/NotificationsHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/NotificationsHandler.java index e4e1a48a3..655e73976 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/NotificationsHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/NotificationsHandler.java @@ -84,6 +84,11 @@ public class NotificationsHandler implements MessageHandler { callNotificationSpec.type = NotificationType.GENERIC_PHONE; callNotificationSpec.body = StringUtils.isEmpty(callSpec.name) ? callSpec.number : callSpec.name; + // add an empty bogus action to toggle the hasActions boolean. The actions are hardcoded on the watch in case of incoming calls. + callNotificationSpec.attachedActions = new ArrayList<>(); + callNotificationSpec.attachedActions.add(0, new NotificationSpec.Action()); + + return onNotification(callNotificationSpec); } else { if (callSpec.number != null) // this happens in debug screen @@ -180,6 +185,8 @@ public class NotificationsHandler implements MessageHandler { final GBDeviceEventCallControl deviceEvtCallControl = new GBDeviceEventCallControl(); switch (message.getNotificationAction()) { case REPLY_INCOMING_CALL: + deviceEvtCallControl.event = GBDeviceEventCallControl.Event.REJECT; + message.addGbDeviceEvent(deviceEvtCallControl); case REPLY_MESSAGES: deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; deviceEvtNotificationControl.reply = message.getActionString(); @@ -188,23 +195,23 @@ public class NotificationsHandler implements MessageHandler { } else { deviceEvtNotificationControl.handle = mNotificationReplyAction.lookup(notificationSpec.getId()); //handle of wearable action is needed } - message.setDeviceEvent(deviceEvtNotificationControl); + message.addGbDeviceEvent(deviceEvtNotificationControl); break; case ACCEPT_INCOMING_CALL: deviceEvtCallControl.event = GBDeviceEventCallControl.Event.ACCEPT; - message.setDeviceEvent(deviceEvtCallControl); + message.addGbDeviceEvent(deviceEvtCallControl); break; case REJECT_INCOMING_CALL: deviceEvtCallControl.event = GBDeviceEventCallControl.Event.REJECT; - message.setDeviceEvent(deviceEvtCallControl); + message.addGbDeviceEvent(deviceEvtCallControl); break; case DISMISS_NOTIFICATION: deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS; - message.setDeviceEvent(deviceEvtNotificationControl); + message.addGbDeviceEvent(deviceEvtNotificationControl); break; case BLOCK_APPLICATION: deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE; - message.setDeviceEvent(deviceEvtNotificationControl); + message.addGbDeviceEvent(deviceEvtNotificationControl); break; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java index 20d7927ad..fb0be3d6a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/ProtocolBufferHandler.java @@ -349,7 +349,7 @@ public class ProtocolBufferHandler implements MessageHandler { ); } else { builder.setStatus(GdiSmsNotification.SmsNotificationService.ResponseStatus.GENERIC_ERROR); - LOG.error("Missing canned messages data for type {}", requestedType); + LOG.info("Missing canned messages data for type {}", requestedType); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/NotificationControlMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/NotificationControlMessage.java index bb9b9a31b..8b7ef5301 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/NotificationControlMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/NotificationControlMessage.java @@ -1,5 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages; +import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -21,7 +22,7 @@ public class NotificationControlMessage extends GFDIMessage { private NotificationsHandler.LegacyNotificationAction legacyNotificationAction; private NotificationsHandler.NotificationAction notificationAction; private String actionString; - private GBDeviceEvent deviceEvent; + private List gbDeviceEventList; public NotificationControlMessage(GarminMessage garminMessage, NotificationsHandler.NotificationCommand command, int notificationId, NotificationsHandler.NotificationAction notificationAction, String actionString) { this.garminMessage = garminMessage; @@ -108,13 +109,17 @@ public class NotificationControlMessage extends GFDIMessage { return actionString; } - public void setDeviceEvent(GBDeviceEvent deviceEvent) { - this.deviceEvent = deviceEvent; + public void addGbDeviceEvent(GBDeviceEvent gbDeviceEvent) { + if (null == this.gbDeviceEventList) + this.gbDeviceEventList = new ArrayList<>(); + this.gbDeviceEventList.add(gbDeviceEvent); } @Override public List getGBDeviceEvent() { - return Collections.singletonList(deviceEvent); + if (null == this.gbDeviceEventList) + return Collections.emptyList(); + return gbDeviceEventList; } public NotificationsHandler.LegacyNotificationAction getLegacyNotificationAction() {