1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 01:09:47 +01:00

Mi Band 8: Fix watchface upload

This commit is contained in:
José Rebelo 2023-10-23 23:30:59 +01:00
parent 27fba50283
commit cab63b2c98
2 changed files with 7 additions and 8 deletions

View File

@ -276,21 +276,18 @@ public class XiaomiCharacteristic {
final boolean encrypt = isEncrypted && authService.isEncryptionInitialized(); final boolean encrypt = isEncrypted && authService.isEncryptionInitialized();
if (encrypt) { if (encrypt) {
currentPayload.setBytesToSend(authService.encrypt(currentPayload.getBytesToSend(), encryptedIndex)); currentPayload.setBytesToSend(authService.encrypt(currentPayload.getBytesToSend(), incrementNonce ? encryptedIndex : 0));
} }
if (shouldWriteChunked(currentPayload.getBytesToSend())) { if (shouldWriteChunked(currentPayload.getBytesToSend())) {
if (encrypt) { if (encrypt && incrementNonce) {
// Prepend encrypted index for the nonce // Prepend encrypted index for the nonce
currentPayload.setBytesToSend( currentPayload.setBytesToSend(
ByteBuffer.allocate(2 + currentPayload.getBytesToSend().length).order(ByteOrder.LITTLE_ENDIAN) ByteBuffer.allocate(2 + currentPayload.getBytesToSend().length).order(ByteOrder.LITTLE_ENDIAN)
.putShort(encryptedIndex) .putShort(encryptedIndex++)
.put(currentPayload.getBytesToSend()) .put(currentPayload.getBytesToSend())
.array() .array()
); );
if (incrementNonce) {
encryptedIndex++;
}
} }
LOG.debug("Sending {} - chunked", currentPayload.getTaskName()); LOG.debug("Sending {} - chunked", currentPayload.getTaskName());
@ -319,9 +316,10 @@ public class XiaomiCharacteristic {
buf.put((byte) 2); // 2 for command buf.put((byte) 2); // 2 for command
buf.put((byte) (encrypt ? 1 : 2)); buf.put((byte) (encrypt ? 1 : 2));
if (encrypt) { if (encrypt) {
buf.putShort(encryptedIndex);
if (incrementNonce) { if (incrementNonce) {
encryptedIndex++; buf.putShort(encryptedIndex++);
} else {
buf.putShort((short) 0);
} }
} }
buf.put(currentPayload.getBytesToSend()); // it's already encrypted buf.put(currentPayload.getBytesToSend()); // it's already encrypted

View File

@ -244,6 +244,7 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService implements Xia
if (success) { if (success) {
setWatchface(fwHelper.getId()); setWatchface(fwHelper.getId());
requestWatchfaceList();
} }
fwHelper = null; fwHelper = null;