diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java index b99a33929..abcf59c5a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java @@ -54,11 +54,11 @@ public class HuaweiInstallHandler implements InstallHandler { private HuaweiMusicUtils.FormatRestrictions getRestriction(HuaweiMusicUtils.MusicCapabilities capabilities, String ext) { List restrictions = capabilities.formatsRestrictions; - if(restrictions == null) + if (restrictions == null) return null; - for(HuaweiMusicUtils.FormatRestrictions r: restrictions) { - if(ext.equals(r.getName())) { + for (HuaweiMusicUtils.FormatRestrictions r : restrictions) { + if (ext.equals(r.getName())) { return r; } } @@ -67,24 +67,24 @@ public class HuaweiInstallHandler implements InstallHandler { //TODO: add proper checks private boolean checkMediaCompatibility(HuaweiMusicUtils.MusicCapabilities capabilities, HuaweiMusicManager.AudioInfo currentMusicInfo) { - if(capabilities == null) { + if (capabilities == null) { LOG.error("No media info from device"); return false; } String ext = currentMusicInfo.getExtension(); List supportedFormats = capabilities.supportedFormats; - if(supportedFormats == null) { + if (supportedFormats == null) { LOG.error("Format not supported {}", ext); return false; } - if(!supportedFormats.contains(ext)) { + if (!supportedFormats.contains(ext)) { LOG.error("Format not supported {}", ext); return false; } HuaweiMusicUtils.FormatRestrictions restrictions = getRestriction(capabilities, ext); - if(restrictions == null) { + if (restrictions == null) { LOG.info("no restriction for: {}", ext); return true; } @@ -95,7 +95,7 @@ public class HuaweiInstallHandler implements InstallHandler { LOG.info("sampleRate {}", Arrays.toString(restrictions.sampleRates)); LOG.info("unknownBitrate {}", restrictions.unknownBitrate); - if(currentMusicInfo.getChannels() > restrictions.channels) { + if (currentMusicInfo.getChannels() > restrictions.channels) { LOG.error("Not supported channels count {} > {}", currentMusicInfo.getChannels(), restrictions.channels); return false; } @@ -116,24 +116,17 @@ public class HuaweiInstallHandler implements InstallHandler { return; } - if(helper.isFirmware) { + if (helper.isFirmware) { this.valid = true; //NOTE: nothing to verify for now - installActivity.setInstallEnabled(true); - - GenericItem installItem = new GenericItem(); - - installItem.setName(helper.fwInfo.versionName); - installActivity.setInstallItem(installItem); if (device.isBusy()) { LOG.error("Firmware cannot be uploaded (device busy)"); installActivity.setInfoText("Firmware cannot be uploaded (device busy)"); - installActivity.setInfoText(device.getBusyTask()); installActivity.setInstallEnabled(false); return; } - if (!device.isConnected()) { + if (!device.isConnected() || !device.isInitialized()) { LOG.error("Firmware cannot be uploaded(not connected or wrong device)"); installActivity.setInfoText("Firmware cannot be uploaded (not connected or wrong device)"); installActivity.setInstallEnabled(false); @@ -146,11 +139,20 @@ public class HuaweiInstallHandler implements InstallHandler { return; } - //installItem.setDetails(config.version); + GenericItem installItem = new GenericItem(); + + installItem.setName(helper.fwInfo.versionName); + + installItem.setDetails(helper.fwInfo.osVersion); installItem.setIcon(R.drawable.ic_firmware); - //installActivity.setInfoText(context.getString(R.string.app_install_info, installItem.getName(), config.version, config.vendor)); + installActivity.setInstallItem(installItem); + + installActivity.setInfoText(context.getString(R.string.fw_upgrade_notice_huawei, helper.fwInfo.versionName, device.getAliasOrName(), device.getFirmwareVersion())); + + installActivity.setInstallEnabled(true); + LOG.debug("Initialized HuaweiInstallHandler: Firmware"); return; @@ -252,7 +254,7 @@ public class HuaweiInstallHandler implements InstallHandler { final HuaweiCoordinatorSupplier huaweiCoordinatorSupplier = (HuaweiCoordinatorSupplier) coordinator; HuaweiMusicUtils.MusicCapabilities capabilities = huaweiCoordinatorSupplier.getHuaweiCoordinator().getExtendedMusicInfoParams(); - if(capabilities == null) { + if (capabilities == null) { capabilities = huaweiCoordinatorSupplier.getHuaweiCoordinator().getMusicInfoParams(); } HuaweiMusicManager.AudioInfo currentMusicInfo = helper.getMusicInfo(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/ota/HuaweiOTAFileList.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/ota/HuaweiOTAFileList.java index 1faf3e0c0..8ba901802 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/ota/HuaweiOTAFileList.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/ota/HuaweiOTAFileList.java @@ -29,6 +29,7 @@ public class HuaweiOTAFileList { public long size; public String packageName; public String versionName; + public String osVersion; public int versionCode; } @@ -70,6 +71,10 @@ public class HuaweiOTAFileList { info.size = Long.parseLong(elem.getElementsByTagName("size").item(0).getTextContent()); info.packageName = elem.getElementsByTagName("packageName").item(0).getTextContent(); info.versionName = elem.getElementsByTagName("versionName").item(0).getTextContent(); + NodeList osVerNodes = elem.getElementsByTagName("osVersion"); + if(osVerNodes.getLength() > 0) { + info.osVersion = osVerNodes.item(0).getTextContent(); + } info.versionCode = Integer.parseInt(elem.getElementsByTagName("versionCode").item(0).getTextContent()); ret.files.add(info); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5afe70737..8b63f7d93 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -176,6 +176,7 @@ \n \nPROCEED AT YOUR OWN RISK! You are about to install the %1$s and %2$s firmware, instead of the ones currently on your Mi Band. + You are about to upload the %s firmware on your %s.\n\nYour current firmware is %s\n\nYour device will reboot after uploading.\n\nPROCEED AT YOUR OWN RISK! This firmware has been tested and is known to be compatible with Gadgetbridge. "This firmware is untested and may not be compatible with Gadgetbridge.\n\nYou are DISCOURAGED from flashing it!" If you still want to proceed and things continue to work properly afterwards, please tell the Gadgetbridge developers to whitelist the %s firmware version.