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_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) {
|
||||||
|
@ -2144,46 +2144,37 @@ 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) {
|
||||||
byte attribute = buf.get();
|
byte attribute = buf.get();
|
||||||
if (attribute == 0x01) { // reply string is in attribute 0x01
|
if (attribute == 0x01) { // reply string is in attribute 0x01
|
||||||
short length = buf.getShort();
|
short length = buf.getShort();
|
||||||
if (length > 64) length = 64;
|
if (length > 64) length = 64;
|
||||||
byte[] reply = new byte[length];
|
byte[] reply = new byte[length];
|
||||||
buf.get(reply);
|
buf.get(reply);
|
||||||
devEvtNotificationControl.phoneNumber = null;
|
devEvtNotificationControl.phoneNumber = null;
|
||||||
if (buf.remaining() > 1 && buf.get() == 0x0c) {
|
if (buf.remaining() > 1 && buf.get() == 0x0c) {
|
||||||
short phoneNumberLength = buf.getShort();
|
short phoneNumberLength = buf.getShort();
|
||||||
byte[] phoneNumberBytes = new byte[phoneNumberLength];
|
byte[] phoneNumberBytes = new byte[phoneNumberLength];
|
||||||
buf.get(phoneNumberBytes);
|
buf.get(phoneNumberBytes);
|
||||||
devEvtNotificationControl.phoneNumber = new String(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 {
|
} 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
|
||||||
|
Loading…
Reference in New Issue
Block a user