mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 03:46:49 +01:00
Handle notifications with long body
This commit is contained in:
parent
cf61ab9d38
commit
290a90ec0e
@ -28,8 +28,8 @@ public final class WatchXPlusConstants {
|
||||
public static final UUID UUID_CHARACTERISTIC_UNKNOWN_3 = UUID.fromString("0000a803-0000-1000-8000-00805f9b34fb");
|
||||
public static final UUID UUID_CHARACTERISTIC_UNKNOWN_4 = UUID.fromString("0000a804-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
public static final int NOTIFICATION_CHANNEL_DEFAULT = 7;
|
||||
public static final int NOTIFICATION_CHANNEL_PHONE_CALL = 1024;
|
||||
public static final int NOTIFICATION_CHANNEL_DEFAULT = 0;
|
||||
public static final int NOTIFICATION_CHANNEL_PHONE_CALL = 10;
|
||||
|
||||
public static final byte RESPONSE = 0x13;
|
||||
public static final byte REQUEST = 0x31;
|
||||
|
@ -142,14 +142,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||
|
||||
String message = StringUtils.truncate(senderOrTitle, 32) + "\0";
|
||||
// TODO: Commented out to simplify testing
|
||||
// if (notificationSpec.subject != null) {
|
||||
// message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n";
|
||||
// }
|
||||
// if (notificationSpec.body != null) {
|
||||
// message += StringUtils.truncate(notificationSpec.body, 128);
|
||||
// }
|
||||
String message = StringUtils.truncate(senderOrTitle, 14) + "\0";
|
||||
if (notificationSpec.subject != null) {
|
||||
message += StringUtils.truncate(notificationSpec.subject, 20) + ": ";
|
||||
}
|
||||
if (notificationSpec.body != null) {
|
||||
message += StringUtils.truncate(notificationSpec.body, 64);
|
||||
}
|
||||
|
||||
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_DEFAULT, message);
|
||||
}
|
||||
@ -159,17 +158,36 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
TransactionBuilder builder = performInitialized("showNotification");
|
||||
byte[] command = WatchXPlusConstants.CMD_NOTIFICATION_TEXT_TASK;
|
||||
byte[] text = notificationText.getBytes("UTF-8");
|
||||
byte[] value = new byte[text.length + 2];
|
||||
value[0] = (byte)(notificationChannel);
|
||||
// TODO: Split message into 9-byte arrays and send them one by one.
|
||||
// Set the message index to FF to indicate end of message
|
||||
value[1] = (byte) 0xFF;
|
||||
System.arraycopy(text, 0, value, 2, text.length);
|
||||
byte[] messagePart;
|
||||
|
||||
int messageLength = text.length;
|
||||
int parts = messageLength / 9;
|
||||
int remainder = messageLength % 9;
|
||||
|
||||
// Increment parts quantity if message length is not multiple of 9
|
||||
if (remainder != 0) {
|
||||
parts++;
|
||||
}
|
||||
for (int messageIndex = 0; messageIndex < parts; messageIndex++) {
|
||||
if(messageIndex+1 != parts || remainder == 0) {
|
||||
messagePart = new byte[11];
|
||||
} else {
|
||||
messagePart = new byte[remainder+2];
|
||||
}
|
||||
|
||||
System.arraycopy(text, messageIndex*9, messagePart, 2, messagePart.length-2);
|
||||
|
||||
if(messageIndex+1 == parts) {
|
||||
messageIndex = 0xFF;
|
||||
}
|
||||
messagePart[0] = (byte)notificationChannel;
|
||||
messagePart[1] = (byte)messageIndex;
|
||||
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
|
||||
buildCommand(command,
|
||||
WatchXPlusConstants.KEEP_ALIVE,
|
||||
value));
|
||||
messagePart));
|
||||
}
|
||||
|
||||
performImmediately(builder);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Unable to send notification", e);
|
||||
|
Loading…
Reference in New Issue
Block a user