1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-18 06:37:47 +01:00

WIP: Work towards SMS replies / canned replies, round 2

- parse the reply string in PebbleProtocol
- put replies into GBDeviceEvents
- display a toast in AbstractDeviceSupport, containing the reply

THIS STILL DOES NOT DO ANYTHING USEFUL
This commit is contained in:
Andreas Shimokawa 2015-12-13 22:43:53 +01:00
parent 53fb63781e
commit e5cf22bda6
3 changed files with 46 additions and 13 deletions

View File

@ -2,7 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.deviceevents;
public class GBDeviceEventNotificationControl extends GBDeviceEvent { public class GBDeviceEventNotificationControl extends GBDeviceEvent {
public int handle; public int handle;
public String reply;
public Event event = Event.UNKNOWN; public Event event = Event.UNKNOWN;
public enum Event { public enum Event {
@ -10,6 +10,7 @@ public class GBDeviceEventNotificationControl extends GBDeviceEvent {
DISMISS, DISMISS,
DISMISS_ALL, DISMISS_ALL,
OPEN, OPEN,
MUTE MUTE,
REPLY,
} }
} }

View File

@ -226,6 +226,9 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
case MUTE: case MUTE:
action = NotificationListener.ACTION_MUTE; action = NotificationListener.ACTION_MUTE;
break; break;
case REPLY:
GB.toast(context, "got notfication reply: " + deviceEvent.reply, 2, GB.INFO);
break;
} }
if (action != null) { if (action != null) {
Intent notificationListenerIntent = new Intent(action); Intent notificationListenerIntent = new Intent(action);

View File

@ -1486,7 +1486,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
private GBDeviceEvent[] decodeNotificationAction2x(ByteBuffer buf) { private GBDeviceEvent[] decodeNotificationAction2x(ByteBuffer buf) {
buf.order(ByteOrder.LITTLE_ENDIAN); buf.order(ByteOrder.LITTLE_ENDIAN);
byte command = buf.get(); byte command = buf.get();
if (command == 0x02) { if (command == 0x02) {
int id = buf.getInt(); int id = buf.getInt();
@ -1514,7 +1513,22 @@ public class PebbleProtocol extends GBDeviceProtocol {
sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "Muted"); sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "Muted");
break; break;
case 0x05: 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 = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "NOT IMPLEMENTED"); sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, "NOT IMPLEMENTED");
break; break;
@ -1531,49 +1545,64 @@ public class PebbleProtocol extends GBDeviceProtocol {
private GBDeviceEvent[] decodeNotificationAction3x(ByteBuffer buf) { private GBDeviceEvent[] decodeNotificationAction3x(ByteBuffer buf) {
buf.order(ByteOrder.LITTLE_ENDIAN); buf.order(ByteOrder.LITTLE_ENDIAN);
byte command = buf.get(); byte command = buf.get();
if (command == NOTIFICATIONACTION_INVOKE) { if (command == NOTIFICATIONACTION_INVOKE) {
buf.order(ByteOrder.BIG_ENDIAN); buf.order(ByteOrder.BIG_ENDIAN);
long uuid_high = buf.getLong(); long uuid_high = buf.getLong();
long uuid_low = buf.getLong(); long uuid_low = buf.getLong();
buf.order(ByteOrder.LITTLE_ENDIAN);
int id = (int) (uuid_low & 0xffffffffL); int id = (int) (uuid_low & 0xffffffffL);
byte action = buf.get(); byte action = buf.get();
if (action >= 0x01 && action <= 0x05) { if (action >= 0x01 && action <= 0x05) {
GBDeviceEventNotificationControl dismissNotification = new GBDeviceEventNotificationControl(); GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl();
dismissNotification.handle = id; devEvtNotificationControl.handle = id;
String caption = "undefined"; String caption = "undefined";
int icon_id = 1; int icon_id = 1;
switch (action) { switch (action) {
case 0x01: case 0x01:
dismissNotification.event = GBDeviceEventNotificationControl.Event.OPEN; devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.OPEN;
caption = "Opened"; caption = "Opened";
icon_id = PebbleIconID.DURING_PHONE_CALL; icon_id = PebbleIconID.DURING_PHONE_CALL;
break; break;
case 0x02: case 0x02:
dismissNotification.event = GBDeviceEventNotificationControl.Event.DISMISS; devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS;
caption = "Dismissed"; caption = "Dismissed";
icon_id = PebbleIconID.RESULT_DISMISSED; icon_id = PebbleIconID.RESULT_DISMISSED;
break; break;
case 0x03: case 0x03:
dismissNotification.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL; devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL;
caption = "All dismissed"; caption = "All dismissed";
icon_id = PebbleIconID.RESULT_DISMISSED; icon_id = PebbleIconID.RESULT_DISMISSED;
break; break;
case 0x04: case 0x04:
dismissNotification.event = GBDeviceEventNotificationControl.Event.MUTE; devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE;
caption = "Muted"; caption = "Muted";
icon_id = PebbleIconID.RESULT_MUTE; icon_id = PebbleIconID.RESULT_MUTE;
break; break;
case 0x05: 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"; caption = "NOT IMPLEMENTED";
icon_id = PebbleIconID.GENERIC_WARNING; icon_id = PebbleIconID.GENERIC_WARNING;
break; break;
} }
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = encodeActionResponse(new UUID(uuid_high, uuid_low), icon_id, caption); 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); LOG.info("unexpected action: " + action);
} }