use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl in project Gadgetbridge by Freeyourgadget.
the class PebbleProtocol method decodeAction.
private GBDeviceEvent[] decodeAction(ByteBuffer buf) {
buf.order(ByteOrder.LITTLE_ENDIAN);
byte command = buf.get();
if (command == NOTIFICATIONACTION_INVOKE) {
int id;
UUID uuid = new UUID(0, 0);
if (mFwMajor >= 3) {
uuid = getUUID(buf);
id = (int) (uuid.getLeastSignificantBits() & 0xffffffffL);
} else {
id = buf.getInt();
}
byte action = buf.get();
if (action >= 0x00 && action <= 0x05) {
GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl();
devEvtNotificationControl.handle = id;
String caption = "undefined";
int icon_id = 1;
boolean needsAck2x = true;
switch(action) {
case 0x01:
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.OPEN;
caption = "Opened";
icon_id = PebbleIconID.DURING_PHONE_CALL;
break;
case 0x02:
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS;
caption = "Dismissed";
icon_id = PebbleIconID.RESULT_DISMISSED;
needsAck2x = false;
break;
case 0x03:
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL;
caption = "All dismissed";
icon_id = PebbleIconID.RESULT_DISMISSED;
needsAck2x = false;
break;
case 0x04:
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE;
caption = "Muted";
icon_id = PebbleIconID.RESULT_MUTE;
break;
case 0x05:
case 0x00:
boolean failed = true;
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.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) {
caption = "FAILED";
icon_id = PebbleIconID.RESULT_FAILED;
// error
devEvtNotificationControl = null;
}
break;
}
GBDeviceEventSendBytes sendBytesAck = null;
if (mFwMajor >= 3 || needsAck2x) {
sendBytesAck = new GBDeviceEventSendBytes();
if (mFwMajor >= 3) {
sendBytesAck.encodedBytes = encodeActionResponse(uuid, icon_id, caption);
} else {
sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, caption);
}
}
return new GBDeviceEvent[] { sendBytesAck, devEvtNotificationControl };
}
LOG.info("unexpected action: " + action);
}
return null;
}
Aggregations