mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Pebble: generalize handling of incoming actions (from watch)
Also add missing casts back to int in NotificationListener
This commit is contained in:
parent
7c0c50e960
commit
549dfce2e7
@ -103,7 +103,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
case ACTION_MUTE:
|
||||
case ACTION_OPEN: {
|
||||
StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications();
|
||||
int handle = intent.getIntExtra("handle", -1);
|
||||
int handle = (int) intent.getLongExtra("handle", -1);
|
||||
for (StatusBarNotification sbn : sbns) {
|
||||
if ((int) sbn.getPostTime() == handle) {
|
||||
if (action.equals(ACTION_OPEN)) {
|
||||
@ -126,7 +126,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
case ACTION_DISMISS: {
|
||||
StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications();
|
||||
int handle = intent.getIntExtra("handle", -1);
|
||||
int handle = (int) intent.getLongExtra("handle", -1);
|
||||
for (StatusBarNotification sbn : sbns) {
|
||||
if ((int) sbn.getPostTime() == handle) {
|
||||
if (GBApplication.isRunningLollipopOrLater()) {
|
||||
@ -146,7 +146,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
NotificationListener.this.cancelAllNotifications();
|
||||
break;
|
||||
case ACTION_REPLY:
|
||||
int id = intent.getIntExtra("handle", -1);
|
||||
int id = (int)intent.getLongExtra("handle", -1);
|
||||
NotificationCompat.Action wearableAction = (NotificationCompat.Action) mActionLookup.lookup(id);
|
||||
String reply = intent.getStringExtra("reply");
|
||||
if (wearableAction != null) {
|
||||
|
@ -2144,46 +2144,37 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
icon_id = PebbleIconID.RESULT_MUTE;
|
||||
break;
|
||||
//TODO: 0x05 is not a special case anymore, and reply action might have an index that is higher. see default below
|
||||
case 0x05:
|
||||
case 0x00:
|
||||
default:
|
||||
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);
|
||||
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.reply = new String(reply);
|
||||
caption = "SENT";
|
||||
icon_id = PebbleIconID.RESULT_SENT;
|
||||
failed = false;
|
||||
}
|
||||
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
|
||||
devEvtNotificationControl.reply = new String(reply);
|
||||
devEvtNotificationControl.handle = (devEvtNotificationControl.handle << 4) + 1;
|
||||
caption = "SENT";
|
||||
icon_id = PebbleIconID.RESULT_SENT;
|
||||
failed = false;
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
caption = "FAILED";
|
||||
icon_id = PebbleIconID.RESULT_FAILED;
|
||||
devEvtNotificationControl = null; // error
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (action > 0x05) {
|
||||
int simpleActionId = action - 0x05;
|
||||
caption = "EXECUTED";
|
||||
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
|
||||
devEvtNotificationControl.handle = (devEvtNotificationControl.handle << 4) + simpleActionId;
|
||||
LOG.info("detected simple action, subId:" + simpleActionId + " title:" + devEvtNotificationControl.title);
|
||||
} else {
|
||||
icon_id = PebbleIconID.GENERIC_CONFIRMATION;
|
||||
caption = "EXECUTED";
|
||||
failed = false;
|
||||
}
|
||||
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
|
||||
devEvtNotificationControl.handle = (devEvtNotificationControl.handle << 4) + action - 0x04;
|
||||
if (failed) {
|
||||
caption = "FAILED";
|
||||
icon_id = PebbleIconID.RESULT_FAILED;
|
||||
devEvtNotificationControl = null; // error
|
||||
|
Loading…
Reference in New Issue
Block a user