2016-03-20 01:05:23 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
|
|
|
|
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FW1 is Mi Band firmware
|
|
|
|
* FW2 is heartrate firmware
|
|
|
|
*/
|
|
|
|
public class Mi1SFirmwareInfo extends AbstractMi1SFirmwareInfo {
|
2016-03-20 23:41:57 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfo.class);
|
2016-03-20 01:05:23 +01:00
|
|
|
|
|
|
|
private final Mi1SFirmwareInfoFW1 fw1Info;
|
|
|
|
private final Mi1SFirmwareInfoFW2 fw2Info;
|
|
|
|
|
|
|
|
private Mi1SFirmwareInfo(byte[] wholeFirmwareBytes) {
|
|
|
|
super(wholeFirmwareBytes);
|
|
|
|
fw1Info = new Mi1SFirmwareInfoFW1(wholeFirmwareBytes);
|
|
|
|
fw2Info = new Mi1SFirmwareInfoFW2(wholeFirmwareBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AbstractMiFirmwareInfo getFirst() {
|
|
|
|
return fw1Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AbstractMiFirmwareInfo getSecond() {
|
|
|
|
return fw2Info;
|
|
|
|
}
|
|
|
|
|
2016-03-20 15:00:05 +01:00
|
|
|
public static
|
|
|
|
@Nullable
|
|
|
|
Mi1SFirmwareInfo getInstance(byte[] wholeFirmwareBytes) {
|
2016-03-20 01:05:23 +01:00
|
|
|
Mi1SFirmwareInfo info = new Mi1SFirmwareInfo(wholeFirmwareBytes);
|
|
|
|
if (info.isGenerallySupportedFirmware()) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
LOG.info("firmware not supported");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isGenerallySupportedFirmware() {
|
|
|
|
if (isSingleMiBandFirmware()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
2016-03-20 12:18:43 +01:00
|
|
|
return fw1Info.isGenerallySupportedFirmware()
|
|
|
|
&& fw2Info.isGenerallySupportedFirmware()
|
|
|
|
&& fw1Info.getFirmwareBytes().length > 0
|
|
|
|
&& fw2Info.getFirmwareBytes().length > 0;
|
2016-03-20 01:05:23 +01:00
|
|
|
} catch (IndexOutOfBoundsException ex) {
|
2016-03-20 23:41:57 +01:00
|
|
|
LOG.warn("invalid firmware or bug: " + ex.getLocalizedMessage(), ex);
|
2016-03-20 01:05:23 +01:00
|
|
|
return false;
|
2016-03-20 12:18:43 +01:00
|
|
|
} catch (IllegalArgumentException ex) {
|
2016-03-20 23:41:57 +01:00
|
|
|
LOG.warn("not supported 1S firmware: " + ex.getLocalizedMessage(), ex);
|
2016-03-20 12:18:43 +01:00
|
|
|
return false;
|
2016-03-20 01:05:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFirmwareOffset() {
|
|
|
|
throw new UnsupportedOperationException("call this method on getFirmwareXInfo()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFirmwareLength() {
|
|
|
|
throw new UnsupportedOperationException("call this method on getFirmwareXInfo()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFirmwareVersion() {
|
|
|
|
throw new UnsupportedOperationException("call this method on getFirmwareXInfo()");
|
|
|
|
}
|
|
|
|
}
|