From bcfc8bc110f6a27f3a9ccf68116a78850287bdc8 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 11 Dec 2016 21:57:20 +0100 Subject: [PATCH] Mi1/Mi2: fix firmware file probing for the different devices --- .../gadgetbridge/devices/miband2/MiBand2FWHelper.java | 3 +++ .../gadgetbridge/service/devices/miband2/Mi2FirmwareInfo.java | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband2/MiBand2FWHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband2/MiBand2FWHelper.java index a4beb56d..207aceef 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband2/MiBand2FWHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband2/MiBand2FWHelper.java @@ -56,6 +56,9 @@ public class MiBand2FWHelper extends AbstractMiBandFWHelper { @Override protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) { firmwareInfo = new Mi2FirmwareInfo(wholeFirmwareBytes); + if (!firmwareInfo.isHeaderValid()) { + throw new IllegalArgumentException("Not a Mi Band 2 firmware"); + } } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2FirmwareInfo.java index c0bb6717..6e9cb0a0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2FirmwareInfo.java @@ -57,8 +57,8 @@ public class Mi2FirmwareInfo { return isHeaderValid() && device.getType() == DeviceType.MIBAND2; } - protected boolean isHeaderValid() { - // TODO: not sure if this is a correct check! + public boolean isHeaderValid() { + // TODO: this is certainly not a correct validation, but it works for now return ArrayUtils.equals(FW_HEADER, bytes, FW_HEADER_OFFSET, FW_HEADER_OFFSET + FW_HEADER.length); }