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

Xiaomi: Ignore activity files without timestamp and version

Some watches will send a sequence of zeroes, which would make activity
fetch become stuck, as the file does not exist.
This commit is contained in:
José Rebelo 2024-06-02 21:48:41 +01:00
parent 09bcb782da
commit 0e9c709a59
2 changed files with 11 additions and 0 deletions

View File

@ -845,6 +845,10 @@ public class XiaomiHealthService extends AbstractXiaomiService {
while (buf.position() < buf.limit()) {
final XiaomiActivityFileId fileId = XiaomiActivityFileId.from(buf);
LOG.debug("Got activity to fetch: {}", fileId);
if (fileId.getTimestamp().getTime() == 0 && fileId.getVersion() == 0) {
LOG.warn("Skipping invalid file with no timestamp and version");
continue;
}
fileIds.add(fileId);
}
activityFetcher.fetch(fileIds);

View File

@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@ -80,4 +81,10 @@ public class XiaomiActivityFileIdTest {
assertArrayEquals(bytes, bufEncode.array());
}
@Test
public void testZero() {
final XiaomiActivityFileId fileId = XiaomiActivityFileId.from(new byte[]{0, 0, 0, 0, 0, 0, 0});
assertTrue(fileId.getTimestamp().getTime() == 0 && fileId.getVersion() == 0);
}
}