1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-20 20:10:15 +02:00

Mi Watch Lite: more small fixes for non-encrypted path

This commit is contained in:
Andreas Shimokawa 2023-10-17 15:40:15 +02:00 committed by José Rebelo
parent b103b4f3e4
commit a19318c5bd

View File

@ -140,7 +140,7 @@ public class XiaomiCharacteristic {
if (chunk == numChunks) {
sendChunkEndAck();
if (authService != null) {
if (isEncrypted) {
// chunks are always encrypted if an auth service is available
handler.handle(authService.decrypt(chunkBuffer.toByteArray()));
} else {
@ -157,9 +157,10 @@ public class XiaomiCharacteristic {
switch (type) {
case 0:
// Chunked start request
final byte one = buf.get(); // ?
if (one != 1) {
LOG.warn("Chunked start request: expected 1, got {}", one);
final byte messageEncrypted = buf.get();
byte expectedResult = (byte) (isEncrypted ? 1 : 0);
if (messageEncrypted != expectedResult) {
LOG.warn("Chunked start request: expected {}, got {}", expectedResult, messageEncrypted);
return;
}
numChunks = buf.getShort();
@ -258,7 +259,7 @@ public class XiaomiCharacteristic {
buf.putShort((short) 0);
buf.put((byte) 0);
buf.put((byte) (isEncrypted ? 1 : 0));
buf.putShort((short) Math.max(1,Math.round(currentSending.length / 247.0)));
buf.putShort((short) Math.max(1, Math.round(currentSending.length / 247.0)));
final TransactionBuilder builder = mSupport.createTransactionBuilder("send chunked start");
builder.write(bluetoothGattCharacteristic, buf.array());