Add logging to firmware detection #234

This commit is contained in:
cpfeiffer 2016-03-20 23:41:57 +01:00
parent 76fc7a2aec
commit f7b71c1f96
4 changed files with 37 additions and 13 deletions

View File

@ -52,16 +52,22 @@ public abstract class AbstractMi1FirmwareInfo extends AbstractMiFirmwareInfo {
@Override @Override
protected boolean isGenerallySupportedFirmware() { protected boolean isGenerallySupportedFirmware() {
if (!isSingleMiBandFirmware()) { if (!isSingleMiBandFirmware()) {
LOG.warn("not a single firmware");
return false; return false;
} }
try { try {
int majorVersion = getFirmwareVersionMajor(); int majorVersion = getFirmwareVersionMajor();
return majorVersion == getSupportedMajorVersion(); if (majorVersion == getSupportedMajorVersion()) {
} catch (IllegalArgumentException e) { return true;
return false; } 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) { } catch (IndexOutOfBoundsException ex) {
return false; LOG.warn("not supported firmware: " + ex.getLocalizedMessage(), ex);
} }
return false;
} }
protected abstract int getSupportedMajorVersion(); protected abstract int getSupportedMajorVersion();

View File

@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
* FW2 is heartrate firmware * FW2 is heartrate firmware
*/ */
public class Mi1SFirmwareInfo extends AbstractMi1SFirmwareInfo { 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 Mi1SFirmwareInfoFW1 fw1Info;
private final Mi1SFirmwareInfoFW2 fw2Info; private final Mi1SFirmwareInfoFW2 fw2Info;
@ -53,9 +53,10 @@ public class Mi1SFirmwareInfo extends AbstractMi1SFirmwareInfo {
&& fw1Info.getFirmwareBytes().length > 0 && fw1Info.getFirmwareBytes().length > 0
&& fw2Info.getFirmwareBytes().length > 0; && fw2Info.getFirmwareBytes().length > 0;
} catch (IndexOutOfBoundsException ex) { } catch (IndexOutOfBoundsException ex) {
LOG.warn("invalid firmware or bug: " + ex.getLocalizedMessage(), ex);
return false; return false;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
LOG.warn("not supported 1S firmware: ", ex); LOG.warn("not supported 1S firmware: " + ex.getLocalizedMessage(), ex);
return false; return false;
} }
} }

View File

@ -2,12 +2,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* FW1 is Mi Band firmware * FW1 is Mi Band firmware
* FW2 is heartrate firmware * FW2 is heartrate firmware
*/ */
public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo { public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo {
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW1.class);
private static final int MI1S_FW_BASE_OFFSET = 1092; private static final int MI1S_FW_BASE_OFFSET = 1092;
Mi1SFirmwareInfoFW1(@NonNull byte[] wholeFirmwareBytes) { Mi1SFirmwareInfoFW1(@NonNull byte[] wholeFirmwareBytes) {
@ -42,9 +45,14 @@ public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo {
protected boolean isGenerallySupportedFirmware() { protected boolean isGenerallySupportedFirmware() {
try { try {
int majorVersion = getFirmwareVersionMajor(); int majorVersion = getFirmwareVersionMajor();
return majorVersion == 4; if (majorVersion == 4) {
} catch (IllegalArgumentException e) { return true;
return false; } 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;
} }
} }

View File

@ -2,11 +2,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* FW1 is Mi Band firmware * FW1 is Mi Band firmware
* FW2 is heartrate firmware * FW2 is heartrate firmware
*/ */
public class Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo { public class Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo {
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW2.class);
Mi1SFirmwareInfoFW2(@NonNull byte[] wholeFirmwareBytes) { Mi1SFirmwareInfoFW2(@NonNull byte[] wholeFirmwareBytes) {
super(wholeFirmwareBytes); super(wholeFirmwareBytes);
@ -32,10 +36,15 @@ public class Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo {
protected boolean isGenerallySupportedFirmware() { protected boolean isGenerallySupportedFirmware() {
try { try {
int majorVersion = getFirmwareVersionMajor(); int majorVersion = getFirmwareVersionMajor();
return majorVersion == 1; if (majorVersion == 1) {
} catch (IllegalArgumentException e) { return true;
return false; } 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 @Override