From b1cccae3accde01dc9ddf1158a63ddc0829b6c9a Mon Sep 17 00:00:00 2001 From: Me7c7 Date: Mon, 6 Jan 2025 13:21:21 +0200 Subject: [PATCH] Huawei: fix SMS reply from the watch --- .../devices/huawei/packets/Notifications.java | 1 - .../huawei/HuaweiNotificationsManager.java | 42 +++++++++++++++---- .../huawei/requests/SendSMSReplyAck.java | 29 +++++++++++++ 3 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendSMSReplyAck.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Notifications.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Notifications.java index 6b2b4fd83..0a0e6b206 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Notifications.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Notifications.java @@ -404,7 +404,6 @@ public class Notifications { } } - //TODO: send ack if required, 7f on error. public static class ReplyAck extends HuaweiPacket { public ReplyAck( diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiNotificationsManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiNotificationsManager.java index 282b31af9..b7b1202eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiNotificationsManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiNotificationsManager.java @@ -16,6 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotificationRemoveRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendSMSReplyAck; public class HuaweiNotificationsManager { private static final Logger LOG = LoggerFactory.getLogger(HuaweiNotificationsManager.class); @@ -105,16 +106,25 @@ public class HuaweiNotificationsManager { LOG.info("Reply is empty"); return; } - if(response.type != 1 && response.type != 2) { - LOG.info("Reply: only type 1 and 2 supported"); - return; - } + NotificationSpec notificationSpec = null; - for (NotificationSpec spec : notificationSpecCache) { - if (getNotificationKey(spec).equals(response.key)) { - notificationSpec = spec; - break; + if(response.type == 1) { // generic SMS notification reply. Find by phone number + for (NotificationSpec spec : notificationSpecCache) { + if (spec.phoneNumber.equals(response.key)) { + notificationSpec = spec; + break; + } } + } else if(response.type == 2) { + for (NotificationSpec spec : notificationSpecCache) { + if (getNotificationKey(spec).equals(response.key)) { + notificationSpec = spec; + break; + } + } + } else { + LOG.info("Reply type {} is not supported", response.type); + return; } if (notificationSpec == null) { LOG.info("Notification for reply is not found"); @@ -139,7 +149,21 @@ public class HuaweiNotificationsManager { } } this.support.evaluateGBDeviceEvent(deviceEvtNotificationControl); - //TODO: maybe should be send reply. Service: 0x2, command: 0x10, tlv 7 and/or 1, type byte, 7f on error + if(response.type == 1) { + // NOTE: send response only for SMS reply + try { + // 0xff - OK + // 0x7f - error + // TODO: get response from SMSManager. Send pending intent result. + // result can be one of the RESULT_ERROR_* from SmsManager. Not sure, need to check. + // currently always send OK. + byte resultCode = (byte)0xff; + SendSMSReplyAck sendNotificationReq = new SendSMSReplyAck(this.support, resultCode); + sendNotificationReq.doPerform(); + } catch (IOException e) { + LOG.error("Sending sns reply ACK", e); + } + } } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendSMSReplyAck.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendSMSReplyAck.java new file mode 100644 index 000000000..a67bf4ccd --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendSMSReplyAck.java @@ -0,0 +1,29 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests; + +import java.util.List; + +import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket; +import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.Notifications; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider; + +public class SendSMSReplyAck extends Request { + private final byte resultCode; + + public SendSMSReplyAck(HuaweiSupportProvider support, + byte resultCode) { + super(support); + this.serviceId = Notifications.id; + this.commandId = Notifications.NotificationReply.id; + this.resultCode = resultCode; + this.addToResponse = false; + } + + @Override + protected List createRequest() throws RequestCreationException { + try { + return new Notifications.NotificationReply.ReplyAck(this.paramsProvider, this.resultCode).serialize(); + } catch(HuaweiPacket.CryptoException e) { + throw new RequestCreationException(e.getMessage()); + } + } +}