From 8da2b68eed8ab052353ed6b2954d882e53bc78d7 Mon Sep 17 00:00:00 2001 From: Me7c7 Date: Sat, 4 Jan 2025 10:14:39 +0200 Subject: [PATCH] Huawei: reply only if quick actions allow it --- .../devices/huawei/HuaweiCoordinator.java | 4 +-- .../devices/huawei/packets/Notifications.java | 29 +++++++------------ .../huawei/HuaweiNotificationsManager.java | 3 +- .../requests/SendNotificationRequest.java | 19 ++++++++++-- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java index c605e15d6..8d4c9e1ec 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java @@ -664,7 +664,7 @@ public class HuaweiCoordinator { return false; } - public boolean supportsNotificationsReply() { + public boolean supportsNotificationsReplyActions() { if (supportsExpandCapability()) return supportsExpandCapability(73); return false; @@ -676,7 +676,7 @@ public class HuaweiCoordinator { return false; } - public boolean supportsNotificationsSyncKey() { + public boolean supportsNotificationsReply() { if (supportsExpandCapability()) return supportsExpandCapability(89); return false; 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 84ab1497b..6b2b4fd83 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 @@ -37,12 +37,13 @@ public class Notifications { public static class AdditionalParams { - public boolean supportsSyncKey = false; + public boolean supportsReply = false; public boolean supportsRepeatedNotify = false; public boolean supportsRemoveSingle = false; - public boolean supportsReply = false; + public boolean supportsReplyActions = false; public boolean supportsTimestamp = false; + public String replyKey = ""; public String notificationKey = ""; public int notificationId = -1; public String channelId = ""; @@ -126,32 +127,24 @@ public class Notifications { if(addParams != null) { - - if(!TextUtils.isEmpty(addParams.category)) { //TODO: device type >=34 + if(!TextUtils.isEmpty(addParams.category)) { // type >= 34 this.tlv.put(0x12, addParams.category); // "imcall" also possible value, not standard for android } - - if (addParams.supportsSyncKey) - this.tlv.put(0x18, (addParams.notificationKey != null) ? addParams.notificationKey : ""); - - //if(addParams.repeatedNotifySupports) { - // this.tlv.put(0x13, 0); // 0x13 - reminder 15 = vibrate, 0 - default - //} - - if (addParams.supportsReply && notificationType == NotificationType.sms) { + if (addParams.supportsReply) { + this.tlv.put(0x18, (addParams.replyKey != null) ? addParams.replyKey : ""); + } + if (addParams.supportsReplyActions && notificationType == NotificationType.sms) { this.tlv.put(0x14, addParams.subscriptionId); this.tlv.put(0x17, addParams.address); } - + if (addParams.supportsTimestamp) { + this.tlv.put(0x15, (int) (System.currentTimeMillis() / 1000)); + } if (addParams.supportsRepeatedNotify || addParams.supportsRemoveSingle) { this.tlv.put(0x19, (addParams.notificationKey != null) ? addParams.notificationKey : ""); this.tlv.put(0x1a, addParams.notificationId); this.tlv.put(0x1b, (addParams.channelId != null) ? addParams.channelId : ""); } - - if (addParams.supportsTimestamp) { - this.tlv.put(0x15, (int) (System.currentTimeMillis() / 1000)); - } } this.complete = true; 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 3e79ceb5d..77066f73e 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 @@ -91,7 +91,7 @@ public class HuaweiNotificationsManager { void onReplyResponse(Notifications.NotificationReply.ReplyResponse response) { LOG.info(" KEY: {}, Text: {}", response.key, response.text); - if(!this.support.getHuaweiCoordinator().supportsNotificationsReply()) { + if(!this.support.getHuaweiCoordinator().supportsNotificationsReplyActions()) { LOG.info("Reply is not supported"); return; } @@ -131,7 +131,6 @@ 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 diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendNotificationRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendNotificationRequest.java index a54359e02..4a1ec1e12 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendNotificationRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendNotificationRequest.java @@ -66,16 +66,31 @@ public class SendNotificationRequest extends Request { body = notificationSpec.body.substring(0x0, supportProvider.getHuaweiCoordinator().getContentLength() - 0xD); body += "..."; } + + String replyKey = ""; + final boolean hasActions = (null != notificationSpec.attachedActions && !notificationSpec.attachedActions.isEmpty()); + if (hasActions) { + for (int i = 0; i < notificationSpec.attachedActions.size(); i++) { + final NotificationSpec.Action action = notificationSpec.attachedActions.get(i); + if (action.type == NotificationSpec.Action.TYPE_WEARABLE_REPLY || action.type == NotificationSpec.Action.TYPE_SYNTECTIC_REPLY_PHONENR) { + //NOTE: store notification key instead action key. The watch returns this key so it is more easier to find action by notification key + replyKey = notificationSpec.key; + break; + } + } + } + Notifications.NotificationActionRequest.AdditionalParams params = new Notifications.NotificationActionRequest.AdditionalParams(); - params.supportsSyncKey = supportProvider.getHuaweiCoordinator().supportsNotificationsSyncKey(); + params.supportsReply = supportProvider.getHuaweiCoordinator().supportsNotificationsReply(); params.supportsRepeatedNotify = supportProvider.getHuaweiCoordinator().supportsNotificationsRepeatedNotify(); params.supportsRemoveSingle = supportProvider.getHuaweiCoordinator().supportsNotificationsRemoveSingle(); - params.supportsReply = supportProvider.getHuaweiCoordinator().supportsNotificationsReply(); + params.supportsReplyActions = supportProvider.getHuaweiCoordinator().supportsNotificationsReplyActions(); params.supportsTimestamp = supportProvider.getHuaweiCoordinator().supportsNotificationsTimestamp(); params.notificationId = notificationSpec.getId(); params.notificationKey = notificationSpec.key; + params.replyKey = replyKey; params.channelId = notificationSpec.channelId; params.category = notificationSpec.category;