Pebble: implement decline call with SMS

Based on a proposal by @danielegobbetti, thanks!

This still does not enable the feature since the necessary blobdb is not filled yet
master
Andreas Shimokawa 2016-06-21 00:31:53 +02:00
parent 72dff2abd2
commit 67e5bc0434
3 changed files with 16 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventNotificationControl extends GBDeviceEvent {
public int handle;
public String phoneNumber;
public String reply;
public Event event = Event.UNKNOWN;

View File

@ -243,10 +243,12 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
action = NotificationListener.ACTION_MUTE;
break;
case REPLY:
String phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
if (phoneNumber != null) {
LOG.info("got notfication reply for SMS from " + phoneNumber + " : " + deviceEvent.reply);
SmsManager.getDefault().sendTextMessage(phoneNumber, null, deviceEvent.reply, null, null);
if (deviceEvent.phoneNumber == null) {
deviceEvent.phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
}
if (deviceEvent.phoneNumber != null) {
LOG.info("got notfication reply for SMS from " + deviceEvent.phoneNumber + " : " + deviceEvent.reply);
SmsManager.getDefault().sendTextMessage(deviceEvent.phoneNumber, null, deviceEvent.reply, null, null);
} else {
LOG.info("got notfication reply for notification id " + deviceEvent.handle + " : " + deviceEvent.reply);
action = NotificationListener.ACTION_REPLY;

View File

@ -18,7 +18,6 @@ import java.util.Random;
import java.util.SimpleTimeZone;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement;
@ -1739,7 +1738,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
id = buf.getInt();
}
byte action = buf.get();
if (action >= 0x01 && action <= 0x05) {
if (action >= 0x00 && action <= 0x05) {
GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl();
devEvtNotificationControl.handle = id;
String caption = "undefined";
@ -1769,6 +1768,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
icon_id = PebbleIconID.RESULT_MUTE;
break;
case 0x05:
case 0x00:
boolean failed = true;
byte attribute_count = buf.get();
if (attribute_count > 0) {
@ -1778,15 +1778,18 @@ public class PebbleProtocol extends GBDeviceProtocol {
if (length > 64) length = 64;
byte[] reply = new byte[length];
buf.get(reply);
// FIXME: this does not belong here, but we want at least check if there is no chance at all to send out the SMS later before we report success
String phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(id);
//if (phoneNumber != null) {
devEvtNotificationControl.phoneNumber = null;
if (buf.remaining() > 1 && buf.get() == 0x0c) {
short phoneNumberLength = buf.getShort();
byte[] phoneNumberBytes = new byte[phoneNumberLength];
buf.get(phoneNumberBytes);
devEvtNotificationControl.phoneNumber = new String(phoneNumberBytes);
}
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
devEvtNotificationControl.reply = new String(reply);
caption = "SENT";
icon_id = PebbleIconID.RESULT_SENT;
failed = false;
//}
}
}
if (failed) {