From f7b71c1f9641dfb2b91843d667ba3c5ad0f74ab2 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 20 Mar 2016 23:41:57 +0100 Subject: [PATCH] Add logging to firmware detection #234 --- .../devices/miband/AbstractMi1FirmwareInfo.java | 14 ++++++++++---- .../service/devices/miband/Mi1SFirmwareInfo.java | 5 +++-- .../devices/miband/Mi1SFirmwareInfoFW1.java | 16 ++++++++++++---- .../devices/miband/Mi1SFirmwareInfoFW2.java | 15 ++++++++++++--- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java index cf626593..3e423641 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/AbstractMi1FirmwareInfo.java @@ -52,16 +52,22 @@ public abstract class AbstractMi1FirmwareInfo extends AbstractMiFirmwareInfo { @Override protected boolean isGenerallySupportedFirmware() { if (!isSingleMiBandFirmware()) { + LOG.warn("not a single firmware"); return false; } try { int majorVersion = getFirmwareVersionMajor(); - return majorVersion == getSupportedMajorVersion(); - } catch (IllegalArgumentException e) { - return false; + if (majorVersion == getSupportedMajorVersion()) { + return true; + } else { + LOG.info("Only major version " + getSupportedMajorVersion() + " is supported: " + majorVersion); + } + } catch (IllegalArgumentException ex) { + LOG.warn("invalid firmware or bug: " + ex.getLocalizedMessage(), ex); } catch (IndexOutOfBoundsException ex) { - return false; + LOG.warn("not supported firmware: " + ex.getLocalizedMessage(), ex); } + return false; } protected abstract int getSupportedMajorVersion(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java index c9301b90..058bfb43 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfo.java @@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory; * FW2 is heartrate firmware */ public class Mi1SFirmwareInfo extends AbstractMi1SFirmwareInfo { - private static final Logger LOG = LoggerFactory.getLogger(AbstractMi1FirmwareInfo.class); + private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfo.class); private final Mi1SFirmwareInfoFW1 fw1Info; private final Mi1SFirmwareInfoFW2 fw2Info; @@ -53,9 +53,10 @@ public class Mi1SFirmwareInfo extends AbstractMi1SFirmwareInfo { && fw1Info.getFirmwareBytes().length > 0 && fw2Info.getFirmwareBytes().length > 0; } catch (IndexOutOfBoundsException ex) { + LOG.warn("invalid firmware or bug: " + ex.getLocalizedMessage(), ex); return false; } catch (IllegalArgumentException ex) { - LOG.warn("not supported 1S firmware: ", ex); + LOG.warn("not supported 1S firmware: " + ex.getLocalizedMessage(), ex); return false; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW1.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW1.java index b8ea7aab..9bb5e572 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW1.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW1.java @@ -2,12 +2,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband; import android.support.annotation.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * FW1 is Mi Band firmware * FW2 is heartrate firmware */ public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo { - + private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW1.class); private static final int MI1S_FW_BASE_OFFSET = 1092; Mi1SFirmwareInfoFW1(@NonNull byte[] wholeFirmwareBytes) { @@ -42,9 +45,14 @@ public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo { protected boolean isGenerallySupportedFirmware() { try { int majorVersion = getFirmwareVersionMajor(); - return majorVersion == 4; - } catch (IllegalArgumentException e) { - return false; + if (majorVersion == 4) { + return true; + } else { + LOG.warn("Only major version 4 is supported for 1S fw1: " + majorVersion); + } + } catch (IllegalArgumentException ex) { + LOG.warn("not supported 1S firmware 1: " + ex.getLocalizedMessage(), ex); } + return false; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW2.java index 9cd013f7..38484f7b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/Mi1SFirmwareInfoFW2.java @@ -2,11 +2,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband; import android.support.annotation.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * FW1 is Mi Band firmware * FW2 is heartrate firmware */ public class Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo { + private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW2.class); Mi1SFirmwareInfoFW2(@NonNull byte[] wholeFirmwareBytes) { super(wholeFirmwareBytes); @@ -32,10 +36,15 @@ public class Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo { protected boolean isGenerallySupportedFirmware() { try { int majorVersion = getFirmwareVersionMajor(); - return majorVersion == 1; - } catch (IllegalArgumentException e) { - return false; + if (majorVersion == 1) { + return true; + } else { + LOG.warn("Only major version 1 is supported for 1S fw2: " + majorVersion); + } + } catch (IllegalArgumentException ex) { + LOG.warn("not supported 1S firmware 2: " + ex.getLocalizedMessage(), ex); } + return false; } @Override