Add logging to firmware detection #234

here
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
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();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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