Give better feedback when a firmware cannot be installed #234
This commit is contained in:
parent
767f359319
commit
b0ec74696d
|
@ -26,12 +26,13 @@ public class MiBandFWHelper {
|
|||
|
||||
private final Uri uri;
|
||||
private final ContentResolver cr;
|
||||
private final
|
||||
@NonNull
|
||||
AbstractMiFirmwareInfo firmwareInfo;
|
||||
private final
|
||||
@NonNull
|
||||
byte[] fw;
|
||||
/**
|
||||
* The backing firmware info instance, which in general supports the provided
|
||||
* given firmware. You must call AbstractMiFirmwareInfo#checkValid() before
|
||||
* attempting to flash it.
|
||||
*/
|
||||
private final @NonNull AbstractMiFirmwareInfo firmwareInfo;
|
||||
private final @NonNull byte[] fw;
|
||||
|
||||
/**
|
||||
* Provides a different notification API which is also used on Mi1A devices.
|
||||
|
@ -139,6 +140,11 @@ public class MiBandFWHelper {
|
|||
return AbstractMiFirmwareInfo.determineFirmwareInfoFor(wholeFirmwareBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The backing firmware info instance, which in general supports the provided
|
||||
* given firmware. You MUST call AbstractMiFirmwareInfo#checkValid() AND
|
||||
* isGenerallyCompatibleWithDevice() before attempting to flash it.
|
||||
*/
|
||||
public AbstractMiFirmwareInfo getFirmwareInfo() {
|
||||
return firmwareInfo;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,14 @@ public class MiBandFWInstallHandler implements InstallHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
helper.getFirmwareInfo().checkValid();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
installActivity.setInfoText(ex.getLocalizedMessage());
|
||||
installActivity.setInstallEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
GenericItem fwItem = new GenericItem(mContext.getString(R.string.miband_installhandler_miband_firmware, helper.getHumanFirmwareVersion()));
|
||||
fwItem.setIcon(R.drawable.ic_device_miband);
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ public abstract class AbstractMiFirmwareInfo {
|
|||
throw new IllegalArgumentException("Unsupported data (maybe not even a firmware?).");
|
||||
}
|
||||
if (candidates.length == 1) {
|
||||
candidates[0].checkValid();
|
||||
return candidates[0];
|
||||
}
|
||||
throw new IllegalArgumentException("don't know for which device the firmware is, matches multiple devices");
|
||||
|
@ -60,10 +59,24 @@ public abstract class AbstractMiFirmwareInfo {
|
|||
|
||||
public abstract int getFirmwareVersion();
|
||||
|
||||
/**
|
||||
* Returns true if the firmware data is recognized as such and can be
|
||||
* handled by this instance. No further sanity checks are done at this point.
|
||||
*/
|
||||
protected abstract boolean isGenerallySupportedFirmware();
|
||||
|
||||
/**
|
||||
* This method checks whether the firmware data is recognized as such and can be handled
|
||||
* by this instance. It will be called by #isGenerallySupportedFirmware() in order to check
|
||||
* whether this instance can be used at all or shall be thrown away.
|
||||
*/
|
||||
protected abstract boolean isHeaderValid();
|
||||
|
||||
/**
|
||||
* Checks whether this instance, with the provided firmware data is compatible with the
|
||||
* given device. Must be called to avoid installing Mi1 firmware on Mi1A, for example.
|
||||
* @param device
|
||||
*/
|
||||
public abstract boolean isGenerallyCompatibleWith(GBDevice device);
|
||||
|
||||
public @NonNull byte[] getFirmwareBytes() {
|
||||
|
@ -80,6 +93,11 @@ public abstract class AbstractMiFirmwareInfo {
|
|||
|
||||
public abstract boolean isSingleMiBandFirmware();
|
||||
|
||||
/**
|
||||
* Performs a thorough sanity check of the firmware data and throws IllegalArgumentException
|
||||
* if there's any problem with it.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public void checkValid() throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue