1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-15 22:49:26 +01:00

Garmin: fix notification crashes and handle SMS correctly

It looks like (some) watches really don't like having an empty list of actions, hence enable the legacy "refuse" action in every case, leaving it empty and inactive.
Further display the SMS sender in the notification and enable the correct code path for the reply action to work.
This commit is contained in:
Daniele Gobbetti 2024-04-25 11:18:51 +02:00
parent cbd2c040bb
commit 416b7b075c
3 changed files with 66 additions and 8 deletions

View File

@ -55,7 +55,7 @@ public class NotificationsHandler implements MessageHandler {
final byte[] bytes = entry.getKey().getNotificationSpecAttribute(notificationSpec, entry.getValue()); final byte[] bytes = entry.getKey().getNotificationSpecAttribute(notificationSpec, entry.getValue());
messageWriter.writeShort(bytes.length); messageWriter.writeShort(bytes.length);
messageWriter.writeBytes(bytes); messageWriter.writeBytes(bytes);
// LOG.info("ATTRIBUTE:{} value:{} length:{}", entry.getKey(), new String(bytes), bytes.length); // LOG.info("ATTRIBUTE:{} value:{}/{} length:{}", entry.getKey(), new String(bytes), GB.hexdump(bytes), bytes.length);
} }
@ -183,7 +183,7 @@ public class NotificationsHandler implements MessageHandler {
case REPLY_MESSAGES: case REPLY_MESSAGES:
deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
deviceEvtNotificationControl.reply = message.getActionString(); deviceEvtNotificationControl.reply = message.getActionString();
if (notificationSpec.type.equals(NotificationType.GENERIC_PHONE)) { if (notificationSpec.type.equals(NotificationType.GENERIC_PHONE) || notificationSpec.type.equals(NotificationType.GENERIC_SMS)) {
deviceEvtNotificationControl.phoneNumber = notificationSpec.phoneNumber; deviceEvtNotificationControl.phoneNumber = notificationSpec.phoneNumber;
} else { } else {
deviceEvtNotificationControl.handle = mNotificationReplyAction.lookup(notificationSpec.getId()); //handle of wearable action is needed deviceEvtNotificationControl.handle = mNotificationReplyAction.lookup(notificationSpec.getId()); //handle of wearable action is needed
@ -267,7 +267,7 @@ public class NotificationsHandler implements MessageHandler {
MESSAGE_SIZE(4), MESSAGE_SIZE(4),
DATE(5), DATE(5),
// POSITIVE_ACTION_LABEL(6), //needed only for legacy notification actions // POSITIVE_ACTION_LABEL(6), //needed only for legacy notification actions
// NEGATIVE_ACTION_LABEL(7), //needed only for legacy notification actions NEGATIVE_ACTION_LABEL(7), //needed only for legacy notification actions
// Garmin extensions // Garmin extensions
// PHONE_NUMBER(126, true), // PHONE_NUMBER(126, true),
ACTIONS(127, false, true), ACTIONS(127, false, true),
@ -312,6 +312,9 @@ public class NotificationsHandler implements MessageHandler {
toReturn = NOTIFICATION_DATE_FORMAT.format(new Date(notificationTimestamp)); toReturn = NOTIFICATION_DATE_FORMAT.format(new Date(notificationTimestamp));
break; break;
case TITLE: case TITLE:
if (NotificationType.GENERIC_SMS.equals(notificationSpec.type))
toReturn = notificationSpec.sender == null ? "" : notificationSpec.sender;
else
toReturn = notificationSpec.title == null ? "" : notificationSpec.title; toReturn = notificationSpec.title == null ? "" : notificationSpec.title;
break; break;
case SUBTITLE: case SUBTITLE:

View File

@ -1,7 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages; package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -77,7 +77,7 @@ public class NotificationControlMessage extends GFDIMessage {
} }
private static Map<NotificationsHandler.NotificationAttribute, Integer> createGetNotificationAttributesCommand(MessageReader reader) { private static Map<NotificationsHandler.NotificationAttribute, Integer> createGetNotificationAttributesCommand(MessageReader reader) {
final Map<NotificationsHandler.NotificationAttribute, Integer> notificationAttributesMap = new HashMap<>(); final Map<NotificationsHandler.NotificationAttribute, Integer> notificationAttributesMap = new LinkedHashMap<>();
while (reader.remaining() > 0) { while (reader.remaining() > 0) {
final int attributeID = reader.readByte(); final int attributeID = reader.readByte();

View File

@ -34,17 +34,64 @@ public class NotificationUpdateMessage extends GFDIMessage {
writer.writeByte(getCategoryValue(this.notificationType)); writer.writeByte(getCategoryValue(this.notificationType));
writer.writeByte(this.count); writer.writeByte(this.count);
writer.writeInt(this.notificationId); writer.writeInt(this.notificationId);
writer.writeByte(this.useLegacyActions ? 0x00 : 0x03); writer.writeByte(getNotificationPhoneFlags());
return true; return true;
} }
private int getNotificationPhoneFlags() {
EnumSet<NotificationPhoneFlags> flags = EnumSet.noneOf(NotificationPhoneFlags.class);
if (this.hasActions)
flags.add(NotificationPhoneFlags.NEW_ACTIONS);
if (this.useLegacyActions)
flags.add(NotificationPhoneFlags.LEGACY_ACTIONS);
return (int) EnumUtils.generateBitVector(NotificationPhoneFlags.class, flags);
}
//no image
//00 updatetype
// 12 flags
// 00 notif type
// 00 count
// 03000000
// 02
//image
//00
// 12
// 00
// 00
// 04000000
// 06
//0F00
// A913
// 00
// 12
// 0C
// 00
// 471D2A66
// 02
// BC14
//0F00
// A913
// 00
// 11
// 00
// 00
// 461D2A66
// 00
// 8C00
private int getCategoryFlags(NotificationType notificationType) { private int getCategoryFlags(NotificationType notificationType) {
EnumSet<NotificationFlag> flags = EnumSet.noneOf(NotificationFlag.class); EnumSet<NotificationFlag> flags = EnumSet.noneOf(NotificationFlag.class);
if (this.hasActions && this.useLegacyActions) { //only needed for legacy actions if (this.hasActions && this.useLegacyActions) { //only needed for legacy actions
flags.add(NotificationFlag.ACTION_ACCEPT); flags.add(NotificationFlag.ACTION_ACCEPT);
flags.add(NotificationFlag.ACTION_DECLINE);
} }
flags.add(NotificationFlag.ACTION_DECLINE);
switch (notificationType.getGenericType()) { switch (notificationType.getGenericType()) {
case "generic_phone": case "generic_phone":
@ -111,5 +158,13 @@ public class NotificationUpdateMessage extends GFDIMessage {
LOCATION, LOCATION,
ENTERTAINMENT, ENTERTAINMENT,
SMS SMS
}
enum NotificationPhoneFlags {
LEGACY_ACTIONS,
NEW_ACTIONS,
HAS_ATTACHMENTS,
;
} }
} }