diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventNotificationControl.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventNotificationControl.java index 567782cda..473210391 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventNotificationControl.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventNotificationControl.java @@ -2,7 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.deviceevents; public class GBDeviceEventNotificationControl extends GBDeviceEvent { public int handle; - + public String reply; public Event event = Event.UNKNOWN; public enum Event { @@ -10,6 +10,7 @@ public class GBDeviceEventNotificationControl extends GBDeviceEvent { DISMISS, DISMISS_ALL, OPEN, - MUTE + MUTE, + REPLY, } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index f1d7f7b9a..40988d6e8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -226,6 +226,9 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { case MUTE: action = NotificationListener.ACTION_MUTE; break; + case REPLY: + GB.toast(context, "got notfication reply: " + deviceEvent.reply, 2, GB.INFO); + break; } if (action != null) { Intent notificationListenerIntent = new Intent(action); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index f938b85c8..471d25bbe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -1486,7 +1486,6 @@ public class PebbleProtocol extends GBDeviceProtocol { private GBDeviceEvent[] decodeNotificationAction2x(ByteBuffer buf) { buf.order(ByteOrder.LITTLE_ENDIAN); - byte command = buf.get(); if (command == 0x02) { int id = buf.getInt(); @@ -1514,7 +1513,22 @@ public class PebbleProtocol extends GBDeviceProtocol { sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "Muted"); break; case 0x05: - devEvtNotificationControl = null; // not implemented + byte attribute_count = buf.get(); + if (attribute_count > 0) { + byte attribute = buf.get(); + if (attribute == 0x01) { // reply string is in attribute 0x01 + short length = buf.getShort(); + if (length > 64) length = 64; + byte[] reply = new byte[length]; + buf.get(reply); + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; + devEvtNotificationControl.reply = new String(reply); + } else { + devEvtNotificationControl = null; // error + } + } else { + devEvtNotificationControl = null; // error + } sendBytesAck = new GBDeviceEventSendBytes(); sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "NOT IMPLEMENTED"); break; @@ -1531,49 +1545,64 @@ public class PebbleProtocol extends GBDeviceProtocol { private GBDeviceEvent[] decodeNotificationAction3x(ByteBuffer buf) { buf.order(ByteOrder.LITTLE_ENDIAN); - byte command = buf.get(); if (command == NOTIFICATIONACTION_INVOKE) { buf.order(ByteOrder.BIG_ENDIAN); long uuid_high = buf.getLong(); long uuid_low = buf.getLong(); + buf.order(ByteOrder.LITTLE_ENDIAN); int id = (int) (uuid_low & 0xffffffffL); byte action = buf.get(); if (action >= 0x01 && action <= 0x05) { - GBDeviceEventNotificationControl dismissNotification = new GBDeviceEventNotificationControl(); - dismissNotification.handle = id; + GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl(); + devEvtNotificationControl.handle = id; String caption = "undefined"; int icon_id = 1; switch (action) { case 0x01: - dismissNotification.event = GBDeviceEventNotificationControl.Event.OPEN; + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.OPEN; caption = "Opened"; icon_id = PebbleIconID.DURING_PHONE_CALL; break; case 0x02: - dismissNotification.event = GBDeviceEventNotificationControl.Event.DISMISS; + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS; caption = "Dismissed"; icon_id = PebbleIconID.RESULT_DISMISSED; break; case 0x03: - dismissNotification.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL; + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL; caption = "All dismissed"; icon_id = PebbleIconID.RESULT_DISMISSED; break; case 0x04: - dismissNotification.event = GBDeviceEventNotificationControl.Event.MUTE; + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE; caption = "Muted"; icon_id = PebbleIconID.RESULT_MUTE; break; case 0x05: - dismissNotification = null; // not implemented + byte attribute_count = buf.get(); + if (attribute_count > 0) { + byte attribute = buf.get(); + if (attribute == 0x01) { // reply string is in attribute 0x01 + short length = buf.getShort(); + if (length > 64) length = 64; + byte[] reply = new byte[length]; + buf.get(reply); + devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; + devEvtNotificationControl.reply = new String(reply); + } else { + devEvtNotificationControl = null; // error + } + } else { + devEvtNotificationControl = null; // error + } caption = "NOT IMPLEMENTED"; icon_id = PebbleIconID.GENERIC_WARNING; break; } GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); sendBytesAck.encodedBytes = encodeActionResponse(new UUID(uuid_high, uuid_low), icon_id, caption); - return new GBDeviceEvent[]{sendBytesAck, dismissNotification}; + return new GBDeviceEvent[]{sendBytesAck, devEvtNotificationControl}; } LOG.info("unexpected action: " + action); }