1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-15 06:29:24 +01:00

Pebble: generalize handling of incoming actions (from watch)

Also add missing casts back to int in NotificationListener
This commit is contained in:
Daniele Gobbetti 2018-11-01 19:40:26 +01:00
parent 7c0c50e960
commit 549dfce2e7
2 changed files with 28 additions and 37 deletions

View File

@ -103,7 +103,7 @@ public class NotificationListener extends NotificationListenerService {
case ACTION_MUTE: case ACTION_MUTE:
case ACTION_OPEN: { case ACTION_OPEN: {
StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications(); StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications();
int handle = intent.getIntExtra("handle", -1); int handle = (int) intent.getLongExtra("handle", -1);
for (StatusBarNotification sbn : sbns) { for (StatusBarNotification sbn : sbns) {
if ((int) sbn.getPostTime() == handle) { if ((int) sbn.getPostTime() == handle) {
if (action.equals(ACTION_OPEN)) { if (action.equals(ACTION_OPEN)) {
@ -126,7 +126,7 @@ public class NotificationListener extends NotificationListenerService {
} }
case ACTION_DISMISS: { case ACTION_DISMISS: {
StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications(); StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications();
int handle = intent.getIntExtra("handle", -1); int handle = (int) intent.getLongExtra("handle", -1);
for (StatusBarNotification sbn : sbns) { for (StatusBarNotification sbn : sbns) {
if ((int) sbn.getPostTime() == handle) { if ((int) sbn.getPostTime() == handle) {
if (GBApplication.isRunningLollipopOrLater()) { if (GBApplication.isRunningLollipopOrLater()) {
@ -146,7 +146,7 @@ public class NotificationListener extends NotificationListenerService {
NotificationListener.this.cancelAllNotifications(); NotificationListener.this.cancelAllNotifications();
break; break;
case ACTION_REPLY: case ACTION_REPLY:
int id = intent.getIntExtra("handle", -1); int id = (int)intent.getLongExtra("handle", -1);
NotificationCompat.Action wearableAction = (NotificationCompat.Action) mActionLookup.lookup(id); NotificationCompat.Action wearableAction = (NotificationCompat.Action) mActionLookup.lookup(id);
String reply = intent.getStringExtra("reply"); String reply = intent.getStringExtra("reply");
if (wearableAction != null) { if (wearableAction != null) {

View File

@ -2144,8 +2144,8 @@ public class PebbleProtocol extends GBDeviceProtocol {
icon_id = PebbleIconID.RESULT_MUTE; icon_id = PebbleIconID.RESULT_MUTE;
break; break;
//TODO: 0x05 is not a special case anymore, and reply action might have an index that is higher. see default below //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: case 0x00:
default:
boolean failed = true; boolean failed = true;
byte attribute_count = buf.get(); byte attribute_count = buf.get();
if (attribute_count > 0) { if (attribute_count > 0) {
@ -2162,28 +2162,19 @@ public class PebbleProtocol extends GBDeviceProtocol {
buf.get(phoneNumberBytes); buf.get(phoneNumberBytes);
devEvtNotificationControl.phoneNumber = new String(phoneNumberBytes); devEvtNotificationControl.phoneNumber = new String(phoneNumberBytes);
} }
devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
devEvtNotificationControl.reply = new String(reply); devEvtNotificationControl.reply = new String(reply);
devEvtNotificationControl.handle = (devEvtNotificationControl.handle << 4) + 1;
caption = "SENT"; caption = "SENT";
icon_id = PebbleIconID.RESULT_SENT; icon_id = PebbleIconID.RESULT_SENT;
failed = false; 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 { } 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"; caption = "FAILED";
icon_id = PebbleIconID.RESULT_FAILED; icon_id = PebbleIconID.RESULT_FAILED;
devEvtNotificationControl = null; // error devEvtNotificationControl = null; // error