mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: initial plumbing for notifications' images (blind implementation)
This commit adds the signaling of notifications with images to the watch. According to https://codeberg.org/Freeyourgadget/Gadgetbridge/issues/3469 the watch should followup with a protobuf request "MediaRequest". The protobuf is documented in https://gadgetbridge.org/internals/specifics/garmin-protocol/#mediarequest As examples and only intended to help further developments, two new methods getNotificationAttachmentPath and getNotificationAttachmentBitmap are added to GarminSupport
This commit is contained in:
committed by
José Rebelo
parent
4cf076b3fa
commit
b70c2af117
+11
@@ -4,6 +4,8 @@ import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
@@ -233,6 +235,15 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
|
||||
}
|
||||
|
||||
protected String getNotificationAttachmentPath(int notificationId) {
|
||||
return notificationsHandler.getNotificationAttachmentPath(notificationId);
|
||||
}
|
||||
|
||||
protected Bitmap getNotificationAttachmentBitmap(int notificationId) {
|
||||
Bitmap pippo = BitmapFactory.decodeFile(getNotificationAttachmentPath(notificationId));
|
||||
return pippo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
LOG.info("INCOMING CALLSPEC: {}", callSpec.command);
|
||||
|
||||
+16
-2
@@ -116,7 +116,9 @@ public class NotificationsHandler implements MessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
return new NotificationUpdateMessage(notificationUpdateType, notificationSpec.type, getNotificationsCount(notificationSpec.type), notificationSpec.getId(), hasActions);
|
||||
|
||||
final boolean hasPicture = !nodomain.freeyourgadget.gadgetbridge.util.StringUtils.isEmpty(notificationSpec.picturePath);
|
||||
return new NotificationUpdateMessage(notificationUpdateType, notificationSpec.type, getNotificationsCount(notificationSpec.type), notificationSpec.getId(), hasActions, hasPicture);
|
||||
}
|
||||
|
||||
private int getNotificationsCount(NotificationType notificationType) {
|
||||
@@ -136,6 +138,13 @@ public class NotificationsHandler implements MessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getNotificationAttachmentPath(int notificationId) {
|
||||
NotificationSpec notificationSpec = getNotificationSpecFromQueue(notificationId);
|
||||
if (null != notificationSpec)
|
||||
return notificationSpec.picturePath;
|
||||
return null;
|
||||
}
|
||||
|
||||
public NotificationUpdateMessage onDeleteNotification(int id) {
|
||||
if (!enabled)
|
||||
return null;
|
||||
@@ -145,7 +154,7 @@ public class NotificationsHandler implements MessageHandler {
|
||||
NotificationSpec e = iterator.next();
|
||||
if (e.getId() == id) {
|
||||
iterator.remove();
|
||||
return new NotificationUpdateMessage(NotificationUpdateMessage.NotificationUpdateType.REMOVE, e.type, getNotificationsCount(e.type), id, false);
|
||||
return new NotificationUpdateMessage(NotificationUpdateMessage.NotificationUpdateType.REMOVE, e.type, getNotificationsCount(e.type), id, false, false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -277,6 +286,7 @@ public class NotificationsHandler implements MessageHandler {
|
||||
// Garmin extensions
|
||||
// PHONE_NUMBER(126, true),
|
||||
ACTIONS(127, false, true),
|
||||
ATTACHMENTS(128),
|
||||
;
|
||||
private static final SparseArray<NotificationAttribute> valueByCode;
|
||||
|
||||
@@ -338,6 +348,10 @@ public class NotificationsHandler implements MessageHandler {
|
||||
case ACTIONS:
|
||||
toReturn = encodeNotificationActionsString(notificationSpec);
|
||||
break;
|
||||
case ATTACHMENTS:
|
||||
LOG.debug("NOTIFICATION ATTACHMENTS REQUESTED. Notification Id: {}", notificationSpec.getId());
|
||||
toReturn = "1"; //TODO: possibly the number of attachments, or is it a progressive ID of the attachment to be requested?
|
||||
break;
|
||||
}
|
||||
if (maxLength == 0)
|
||||
return toReturn.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
+5
-37
@@ -13,15 +13,17 @@ public class NotificationUpdateMessage extends GFDIMessage {
|
||||
final private int count; //how many notifications of the same type are present
|
||||
final private int notificationId;
|
||||
final private boolean hasActions;
|
||||
final private boolean hasPicture;
|
||||
final private boolean useLegacyActions = false;
|
||||
|
||||
public NotificationUpdateMessage(NotificationUpdateType notificationUpdateType, NotificationType notificationType, int count, int notificationId, boolean hasActions) {
|
||||
public NotificationUpdateMessage(NotificationUpdateType notificationUpdateType, NotificationType notificationType, int count, int notificationId, boolean hasActions, boolean hasPicture) {
|
||||
this.garminMessage = GarminMessage.NOTIFICATION_UPDATE;
|
||||
this.notificationUpdateType = notificationUpdateType;
|
||||
this.notificationType = notificationType;
|
||||
this.count = count;
|
||||
this.notificationId = notificationId;
|
||||
this.hasActions = hasActions;
|
||||
this.hasPicture = hasPicture;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,47 +47,13 @@ public class NotificationUpdateMessage extends GFDIMessage {
|
||||
flags.add(NotificationPhoneFlags.NEW_ACTIONS);
|
||||
if (this.useLegacyActions)
|
||||
flags.add(NotificationPhoneFlags.LEGACY_ACTIONS);
|
||||
if (this.hasPicture)
|
||||
flags.add(NotificationPhoneFlags.HAS_ATTACHMENTS);
|
||||
|
||||
return (int) EnumUtils.generateBitVector(NotificationPhoneFlags.class, flags);
|
||||
|
||||
}
|
||||
|
||||
//no image
|
||||
//00 updatetype
|
||||
// 12 flags
|
||||
// 00 notif type
|
||||
// 00 count
|
||||
// 03000000
|
||||
// 02
|
||||
|
||||
|
||||
//image
|
||||
//00
|
||||
// 12
|
||||
// 00
|
||||
// 00
|
||||
// 04000000
|
||||
// 06
|
||||
|
||||
//0F00
|
||||
// A913
|
||||
// 00
|
||||
// 12
|
||||
// 0C
|
||||
// 00
|
||||
// 471D2A66
|
||||
// 02
|
||||
// BC14
|
||||
|
||||
//0F00
|
||||
// A913
|
||||
// 00
|
||||
// 11
|
||||
// 00
|
||||
// 00
|
||||
// 461D2A66
|
||||
// 00
|
||||
// 8C00
|
||||
private int getCategoryFlags(NotificationType notificationType) {
|
||||
EnumSet<NotificationFlag> flags = EnumSet.noneOf(NotificationFlag.class);
|
||||
if (this.hasActions && this.useLegacyActions) { //only needed for legacy actions
|
||||
|
||||
Reference in New Issue
Block a user