Huawei: fix SMS reply from the watch

This commit is contained in:
Me7c7 2025-01-06 13:21:21 +02:00
parent 790e81a6f6
commit b1cccae3ac
3 changed files with 62 additions and 10 deletions

View File

@ -404,7 +404,6 @@ public class Notifications {
} }
} }
//TODO: send ack if required, 7f on error.
public static class ReplyAck extends HuaweiPacket { public static class ReplyAck extends HuaweiPacket {
public ReplyAck( public ReplyAck(

View File

@ -16,6 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotificationRequest; 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.SendNotificationRemoveRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendSMSReplyAck;
public class HuaweiNotificationsManager { public class HuaweiNotificationsManager {
private static final Logger LOG = LoggerFactory.getLogger(HuaweiNotificationsManager.class); private static final Logger LOG = LoggerFactory.getLogger(HuaweiNotificationsManager.class);
@ -105,16 +106,25 @@ public class HuaweiNotificationsManager {
LOG.info("Reply is empty"); LOG.info("Reply is empty");
return; return;
} }
if(response.type != 1 && response.type != 2) {
LOG.info("Reply: only type 1 and 2 supported");
return;
}
NotificationSpec notificationSpec = null; NotificationSpec notificationSpec = null;
for (NotificationSpec spec : notificationSpecCache) { if(response.type == 1) { // generic SMS notification reply. Find by phone number
if (getNotificationKey(spec).equals(response.key)) { for (NotificationSpec spec : notificationSpecCache) {
notificationSpec = spec; if (spec.phoneNumber.equals(response.key)) {
break; 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) { if (notificationSpec == null) {
LOG.info("Notification for reply is not found"); LOG.info("Notification for reply is not found");
@ -139,7 +149,21 @@ public class HuaweiNotificationsManager {
} }
} }
this.support.evaluateGBDeviceEvent(deviceEvtNotificationControl); 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);
}
}
} }
} }

View File

@ -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<byte[]> createRequest() throws RequestCreationException {
try {
return new Notifications.NotificationReply.ReplyAck(this.paramsProvider, this.resultCode).serialize();
} catch(HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e.getMessage());
}
}
}