mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-24 08:37:32 +01:00
Pebble: remove notifications when dismissed on the phone (#326)
Most of the code is generic, so it could be implemented by other devices. I dont know what happens if multiple messages arrive in the same notification. So, this is experimental.
This commit is contained in:
parent
c6999713d2
commit
3644d5e7a6
@ -22,6 +22,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
public interface EventHandler {
|
||||
void onNotification(NotificationSpec notificationSpec);
|
||||
|
||||
void onDeleteNotification(int id);
|
||||
|
||||
void onSetTime();
|
||||
|
||||
void onSetAlarms(ArrayList<? extends Alarm> alarms);
|
||||
|
@ -392,7 +392,8 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
@Override
|
||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||
|
||||
LOG.info("notification removed, will ask device to delete it");
|
||||
GBApplication.deviceService().onDeleteNotification((int) sbn.getPostTime()); //FIMXE: a truly unique id would be better
|
||||
}
|
||||
|
||||
private void dumpExtras(Bundle bundle) {
|
||||
|
@ -105,6 +105,14 @@ public class GBDeviceService implements DeviceService {
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
Intent intent = createIntent().setAction(ACTION_DELETE_NOTIFICATION)
|
||||
.putExtra(EXTRA_NOTIFICATION_ID, id);
|
||||
invokeService(intent);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
Intent intent = createIntent().setAction(ACTION_SETTIME);
|
||||
|
@ -16,6 +16,7 @@ public interface DeviceService extends EventHandler {
|
||||
String ACTION_START = PREFIX + ".action.start";
|
||||
String ACTION_CONNECT = PREFIX + ".action.connect";
|
||||
String ACTION_NOTIFICATION = PREFIX + ".action.notification";
|
||||
String ACTION_DELETE_NOTIFICATION = PREFIX + ".action.delete_notification";
|
||||
String ACTION_CALLSTATE = PREFIX + ".action.callstate";
|
||||
String ACTION_SETCANNEDMESSAGES = PREFIX + ".action.setcannedmessages";
|
||||
String ACTION_SETTIME = PREFIX + ".action.settime";
|
||||
|
@ -60,6 +60,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CA
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETE_CALENDAREVENT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETE_NOTIFICATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DISCONNECT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT;
|
||||
@ -355,6 +356,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
mDeviceSupport.onNotification(notificationSpec);
|
||||
break;
|
||||
}
|
||||
case ACTION_DELETE_NOTIFICATION: {
|
||||
mDeviceSupport.onDeleteNotification(intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1));
|
||||
break;
|
||||
}
|
||||
case ACTION_ADD_CALENDAREVENT: {
|
||||
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
||||
calendarEventSpec.id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1);
|
||||
|
@ -135,6 +135,11 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
||||
delegate.onNotification(notificationSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
delegate.onDeleteNotification(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
if (checkBusy("set time") || checkThrottle("set time")) {
|
||||
|
@ -447,6 +447,11 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
showText(notificationSpec.body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
|
@ -545,6 +545,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
performPreferredNotification(origin + " received", origin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
try {
|
||||
|
@ -594,6 +594,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
performPreferredNotification(origin + " received", origin, alertLevel, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
try {
|
||||
|
@ -483,6 +483,11 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeDeleteNotification(int id) {
|
||||
return encodeBlobdb(new UUID(GB_UUID_MASK, id), BLOBDB_DELETE, BLOBDB_NOTIFICATION, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
|
||||
long id = calendarEventSpec.id != -1 ? calendarEventSpec.id : mRandom.nextLong();
|
||||
@ -917,16 +922,14 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(pin_length);
|
||||
|
||||
// pin - 46 bytes
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
buf.putLong(uuid.getMostSignificantBits());
|
||||
buf.putInt((int) (uuid.getLeastSignificantBits() >>> 32));
|
||||
buf.putInt(id);
|
||||
buf.putLong(GB_UUID_MASK);
|
||||
buf.putLong(id);
|
||||
buf.putLong(UUID_NOTIFICATIONS.getMostSignificantBits());
|
||||
buf.putLong(UUID_NOTIFICATIONS.getLeastSignificantBits());
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
@ -124,6 +124,11 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport {
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
|
||||
|
@ -108,6 +108,12 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
byte[] bytes = gbDeviceProtocol.encodeDeleteNotification(id);
|
||||
sendToDevice(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
byte[] bytes = gbDeviceProtocol.encodeSetTime();
|
||||
|
@ -21,6 +21,10 @@ public abstract class GBDeviceProtocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeDeleteNotification(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] encodeSetTime() {
|
||||
return null;
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteNotification(int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user