mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-23 15:51:47 +02:00
Mi Band 8: Add broken notifications
This commit is contained in:
parent
290383627e
commit
f23347c47d
@ -19,17 +19,28 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.services;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class XiaomiNotificationService extends AbstractXiaomiService {
|
public class XiaomiNotificationService extends AbstractXiaomiService {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(XiaomiNotificationService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(XiaomiNotificationService.class);
|
||||||
|
|
||||||
|
private static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ROOT);
|
||||||
|
|
||||||
public static final int COMMAND_TYPE = 7;
|
public static final int COMMAND_TYPE = 7;
|
||||||
|
|
||||||
|
public static final int CMD_NOTIFICATION_SEND = 0;
|
||||||
|
|
||||||
public XiaomiNotificationService(final XiaomiSupport support) {
|
public XiaomiNotificationService(final XiaomiSupport support) {
|
||||||
super(support);
|
super(support);
|
||||||
}
|
}
|
||||||
@ -40,7 +51,60 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onNotification(final NotificationSpec notificationSpec) {
|
public void onNotification(final NotificationSpec notificationSpec) {
|
||||||
// TODO
|
// TODO this is not working
|
||||||
|
if (true) {
|
||||||
|
LOG.warn("Notifications disabled, they're not working");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final XiaomiProto.Notification3.Builder notification3 = XiaomiProto.Notification3.newBuilder()
|
||||||
|
.setId(notificationSpec.getId())
|
||||||
|
.setTimestamp(TIMESTAMP_SDF.format(new Date(notificationSpec.when)));
|
||||||
|
|
||||||
|
if (notificationSpec.sourceAppId != null) {
|
||||||
|
notification3.setPackage(notificationSpec.sourceAppId);
|
||||||
|
} else {
|
||||||
|
notification3.setPackage(BuildConfig.APPLICATION_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||||
|
if (!senderOrTitle.isEmpty()) {
|
||||||
|
notification3.setTitle(senderOrTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notificationSpec.body != null) {
|
||||||
|
notification3.setBody(notificationSpec.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notificationSpec.sourceName != null) {
|
||||||
|
notification3.setAppName(notificationSpec.sourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO what is this?
|
||||||
|
final String unknown12 = String.format(
|
||||||
|
Locale.ROOT,
|
||||||
|
"0|%s|%d|null|12345",
|
||||||
|
notification3.getPackage(),
|
||||||
|
notification3.getId() // i think this needs to be converted to unsigned
|
||||||
|
);
|
||||||
|
notification3.setUnknown12(unknown12);
|
||||||
|
|
||||||
|
final XiaomiProto.Notification2 notification2 = XiaomiProto.Notification2.newBuilder()
|
||||||
|
.setNotification3(notification3)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final XiaomiProto.Notification notification = XiaomiProto.Notification.newBuilder()
|
||||||
|
.setNotification2(notification2)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
getSupport().sendCommand(
|
||||||
|
"send notification",
|
||||||
|
XiaomiProto.Command.newBuilder()
|
||||||
|
.setType(COMMAND_TYPE)
|
||||||
|
.setSubtype(CMD_NOTIFICATION_SEND)
|
||||||
|
.setNotification(notification)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDeleteNotification(final int id) {
|
public void onDeleteNotification(final int id) {
|
||||||
|
@ -458,6 +458,8 @@ message Notification3 {
|
|||||||
optional string unknown4 = 4;
|
optional string unknown4 = 4;
|
||||||
optional string body = 5;
|
optional string body = 5;
|
||||||
optional uint32 id = 7;
|
optional uint32 id = 7;
|
||||||
|
optional string unknown8 = 8;
|
||||||
|
optional string unknown11 = 11;
|
||||||
optional string unknown12 = 12;
|
optional string unknown12 = 12;
|
||||||
optional uint32 hasReply = 13;
|
optional uint32 hasReply = 13;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user