mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-11 12:39:26 +01:00
Xiaomi: Reject call with SMS reply
This commit is contained in:
parent
e6aa9d276a
commit
8f2924c873
@ -33,7 +33,6 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePref
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Support;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public class ZeppOsPhoneService extends AbstractZeppOsService {
|
public class ZeppOsPhoneService extends AbstractZeppOsService {
|
||||||
|
@ -67,6 +67,8 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
|
|||||||
public static final int CMD_OPEN_ON_PHONE = 8;
|
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_GET = 9;
|
||||||
public static final int CMD_CANNED_MESSAGES_SET = 12; // also canned message reply
|
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_REQUEST = 15;
|
||||||
public static final int CMD_NOTIFICATION_ICON_QUERY = 16;
|
public static final int CMD_NOTIFICATION_ICON_QUERY = 16;
|
||||||
|
|
||||||
@ -135,6 +137,9 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
|
|||||||
case CMD_CANNED_MESSAGES_GET:
|
case CMD_CANNED_MESSAGES_GET:
|
||||||
handleCannedMessages(cmd.getNotification().getCannedMessages());
|
handleCannedMessages(cmd.getNotification().getCannedMessages());
|
||||||
return;
|
return;
|
||||||
|
case CMD_CALL_REPLY_SEND:
|
||||||
|
handleCannedSmsReply(cmd.getNotification().getNotificationReply());
|
||||||
|
return;
|
||||||
case CMD_NOTIFICATION_ICON_REQUEST:
|
case CMD_NOTIFICATION_ICON_REQUEST:
|
||||||
handleNotificationIconRequest(cmd.getNotification().getNotificationIconRequest());
|
handleNotificationIconRequest(cmd.getNotification().getNotificationIconRequest());
|
||||||
return;
|
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) {
|
private void handleNotificationIconRequest(final XiaomiProto.NotificationIconRequest notificationIconRequest) {
|
||||||
if (iconPackageName == null) {
|
if (iconPackageName == null) {
|
||||||
LOG.warn("No icon package name");
|
LOG.warn("No icon package name");
|
||||||
|
@ -626,6 +626,11 @@ message Notification {
|
|||||||
// 7, 9 get | 7, 12 set
|
// 7, 9 get | 7, 12 set
|
||||||
optional CannedMessages cannedMessages = 9;
|
optional CannedMessages cannedMessages = 9;
|
||||||
|
|
||||||
|
// 7, 13
|
||||||
|
optional NotificationReply notificationReply = 12;
|
||||||
|
// 7, 14
|
||||||
|
optional uint32 notificationReplyStatus = 13; // 0 on success, 1 on failure
|
||||||
|
|
||||||
// 7, 15
|
// 7, 15
|
||||||
optional NotificationIconPackage notificationIconReply = 14;
|
optional NotificationIconPackage notificationIconReply = 14;
|
||||||
// 7, 15
|
// 7, 15
|
||||||
@ -674,6 +679,13 @@ message NotificationIconRequest {
|
|||||||
optional uint32 size = 3;
|
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 {
|
message NotificationIconPackage {
|
||||||
optional string package = 1;
|
optional string package = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user