diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsPhoneService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsPhoneService.java index f106f11bc..d625e199d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsPhoneService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/services/ZeppOsPhoneService.java @@ -33,7 +33,6 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePref import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Support; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService; -import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public class ZeppOsPhoneService extends AbstractZeppOsService { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java index 53e07a36d..3a2bdeea1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiNotificationService.java @@ -67,6 +67,8 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements public static final int CMD_OPEN_ON_PHONE = 8; public static final int CMD_CANNED_MESSAGES_GET = 9; public static final int CMD_CANNED_MESSAGES_SET = 12; // also canned message reply + public static final int CMD_CALL_REPLY_SEND = 13; + public static final int CMD_CALL_REPLY_ACK = 14; public static final int CMD_NOTIFICATION_ICON_REQUEST = 15; public static final int CMD_NOTIFICATION_ICON_QUERY = 16; @@ -135,6 +137,9 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements case CMD_CANNED_MESSAGES_GET: handleCannedMessages(cmd.getNotification().getCannedMessages()); return; + case CMD_CALL_REPLY_SEND: + handleCannedSmsReply(cmd.getNotification().getNotificationReply()); + return; case CMD_NOTIFICATION_ICON_REQUEST: handleNotificationIconRequest(cmd.getNotification().getNotificationIconRequest()); return; @@ -456,6 +461,49 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements ); } + private void handleCannedSmsReply(final XiaomiProto.NotificationReply notificationReply) { + final String phoneNumber = notificationReply.getNumber(); + if (phoneNumber == null) { + LOG.warn("Missing phone number for sms reply"); + ackSmsReply(false); + return; + } + + final String message = notificationReply.getMessage(); + if (message == null) { + LOG.warn("Missing message for sms reply"); + ackSmsReply(false); + return; + } + + LOG.debug("Sending SMS message '{}' to number '{}' and rejecting call", message, phoneNumber); + + final GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl(); + devEvtNotificationControl.handle = -1; + devEvtNotificationControl.phoneNumber = phoneNumber; + devEvtNotificationControl.reply = message; + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; + getSupport().evaluateGBDeviceEvent(devEvtNotificationControl); + + final GBDeviceEventCallControl rejectCallCmd = new GBDeviceEventCallControl(GBDeviceEventCallControl.Event.REJECT); + getSupport().evaluateGBDeviceEvent(rejectCallCmd); + + // FIXME probably premature + ackSmsReply(true); + } + + private void ackSmsReply(final boolean success) { + getSupport().sendCommand( + "ack sms reply success=" + success, + XiaomiProto.Command.newBuilder() + .setType(COMMAND_TYPE) + .setSubtype(CMD_CALL_REPLY_ACK) + .setNotification(XiaomiProto.Notification.newBuilder() + .setNotificationReplyStatus(success ? 0 : 1) + ).build() + ); + } + private void handleNotificationIconRequest(final XiaomiProto.NotificationIconRequest notificationIconRequest) { if (iconPackageName == null) { LOG.warn("No icon package name"); diff --git a/app/src/main/proto/xiaomi.proto b/app/src/main/proto/xiaomi.proto index edb9df498..888b430f8 100644 --- a/app/src/main/proto/xiaomi.proto +++ b/app/src/main/proto/xiaomi.proto @@ -626,6 +626,11 @@ message Notification { // 7, 9 get | 7, 12 set optional CannedMessages cannedMessages = 9; + // 7, 13 + optional NotificationReply notificationReply = 12; + // 7, 14 + optional uint32 notificationReplyStatus = 13; // 0 on success, 1 on failure + // 7, 15 optional NotificationIconPackage notificationIconReply = 14; // 7, 15 @@ -674,6 +679,13 @@ message NotificationIconRequest { optional uint32 size = 3; } +message NotificationReply { + optional uint32 unknown1 = 1; // 1 + optional string message = 2; + optional uint32 unknown3 = 3; // 1 + optional string number = 4; +} + message NotificationIconPackage { optional string package = 1; }