From c410f0e4a732ddfabb4943c050f387a2bde54d7b Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 24 Mar 2021 23:49:52 +0100 Subject: [PATCH] Amazfit Neo: Implement firmware update but keep it disabled for now Flashing to the latest firmware breaks Gadgetbridge compatibility --- .../amazfitneo/AmazfitNeoCoordinator.java | 5 ---- .../huami/amazfitneo/AmazfitNeoFWHelper.java | 2 +- .../AmazfitNeoFWInstallHandler.java | 2 +- .../amazfitneo/AmazfitNeoFirmwareInfo.java | 27 +++++++++---------- .../huami/amazfitneo/AmazfitNeoSupport.java | 26 ++++++++++++++---- .../devices/huami/miband4/MiBand4Support.java | 4 +-- app/src/main/res/values/strings.xml | 1 + 7 files changed, 38 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java index eba57ae95..3da06f0cb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoCoordinator.java @@ -79,11 +79,6 @@ public class AmazfitNeoCoordinator extends HuamiCoordinator { return true; } - //@Override - //public boolean supportsMusicInfo() { - // return true; - //} - @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return new int[]{ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWHelper.java index 2e4499c7c..b68253557 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWHelper.java @@ -35,7 +35,7 @@ public class AmazfitNeoFWHelper extends HuamiFWHelper { protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) { firmwareInfo = new AmazfitNeoFirmwareInfo(wholeFirmwareBytes); if (!firmwareInfo.isHeaderValid()) { - throw new IllegalArgumentException("Not even a Amazfit Band 5 firmware and you really want Amazfit Neo firmware"); + throw new IllegalArgumentException("Not an Amazfit Neo firmware"); } } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWInstallHandler.java index 61cd8e502..26843f027 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitneo/AmazfitNeoFWInstallHandler.java @@ -35,7 +35,7 @@ class AmazfitNeoFWInstallHandler extends AbstractMiBandFWInstallHandler { @Override protected String getFwUpgradeNotice() { - return mContext.getString(R.string.fw_upgrade_notice_miband5, helper.getHumanFirmwareVersion()); + return mContext.getString(R.string.fw_upgrade_notice_amazfitneo, helper.getHumanFirmwareVersion()); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoFirmwareInfo.java index 21aa7d41a..f0bee1a5e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoFirmwareInfo.java @@ -29,10 +29,11 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; public class AmazfitNeoFirmwareInfo extends HuamiFirmwareInfo { public static final byte[] FW_HEADER = new byte[]{ - 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x9c, (byte) 0xe3, 0x7d, 0x5c, 0x00, 0x04 + // this might be incorrect but found in 1.1.1.18 and 1.1.2.52 + 0x06, 0x68, 0x45, 0x68, (byte) 0x84, 0x68, (byte) 0xC1, 0x68, 0x02, (byte) 0x91, 0x01, 0x69, 0x01, (byte) 0x91, 0x41, 0x69 }; - public static final int FW_HEADER_OFFSET = 16; + public static final int FW_HEADER_OFFSET = 0x90; private static Map crcToVersion = new HashMap<>(); @@ -46,32 +47,22 @@ public class AmazfitNeoFirmwareInfo extends HuamiFirmwareInfo { @Override protected HuamiFirmwareType determineFirmwareType(byte[] bytes) { - return HuamiFirmwareType.INVALID; /* - if (ArrayUtils.equals(bytes, RES_HEADER, COMPRESSED_RES_HEADER_OFFSET) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET)) { - return HuamiFirmwareType.RES_COMPRESSED; - } if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET)) { if (searchString32BitAligned(bytes, "Amazfit Neo")) { return HuamiFirmwareType.FIRMWARE; } return HuamiFirmwareType.INVALID; } - if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) { - return HuamiFirmwareType.WATCHFACE; - } if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) { if (bytes[10] == 0x03 || bytes[10] == 0x06) { return HuamiFirmwareType.FONT; } } - // somebody might have unpacked the compressed res - if (ArrayUtils.startsWith(bytes, RES_HEADER)) { - return HuamiFirmwareType.RES; - } - return HuamiFirmwareType.INVALID;*/ - } + */ + return HuamiFirmwareType.INVALID; + } @Override public boolean isGenerallyCompatibleWith(GBDevice device) { @@ -82,4 +73,10 @@ public class AmazfitNeoFirmwareInfo extends HuamiFirmwareInfo { protected Map getCrcMap() { return crcToVersion; } + + @Override + protected String searchFirmwareVersion(byte[] fwbytes) { + // Not implemented + return null; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java index f207cd041..51ccc3e2b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java @@ -16,14 +16,25 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitneo; +import android.content.Context; +import android.net.Uri; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; + import nodomain.freeyourgadget.gadgetbridge.R; -//import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitneo.AmazfitBand5FWHelper; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitneo.AmazfitNeoFWHelper; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation2020; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperationNew; + +//import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitneo.AmazfitBand5FWHelper; public class AmazfitNeoSupport extends MiBand5Support { private static final Logger LOG = LoggerFactory.getLogger(AmazfitNeoSupport.class); @@ -39,8 +50,13 @@ public class AmazfitNeoSupport extends MiBand5Support { return this; } - //@Override - //public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { - // return new AmazfitBand5FWHelper(uri, context); - //} + @Override + public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { + return new AmazfitNeoFWHelper(uri, context); + } + + @Override + public UpdateFirmwareOperation createUpdateFirmwareOperation(Uri uri) { + return new UpdateFirmwareOperation2020(uri, this); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband4/MiBand4Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband4/MiBand4Support.java index 89048e8cb..28e4bf798 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband4/MiBand4Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband4/MiBand4Support.java @@ -24,8 +24,8 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband4.MiBand4FWHelper; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3.MiBand3Support; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperationNew; public class MiBand4Support extends MiBand3Support { @@ -46,7 +46,7 @@ public class MiBand4Support extends MiBand3Support { } @Override - public UpdateFirmwareOperationNew createUpdateFirmwareOperation(Uri uri) { + public UpdateFirmwareOperation createUpdateFirmwareOperation(Uri uri) { return new UpdateFirmwareOperationNew(uri, this); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2cd89fc68..c28bcf5c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,6 +86,7 @@ You are about to install the %s firmware on your Mi Band 4.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK! You are about to install the %s firmware on your Mi Band 5.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK! You are about to install the %s firmware on your Amazfit X.\n\nPlease make sure to install the .fw file, and after that the .res file. Your band will reboot after installing the .fw file.\n\nNote: You do not have to install .res if it is exactly the same as the one previously installed.\n\nPROCEED AT YOUR OWN RISK! + You are about to install the %s firmware on your Amazfit Neo.\n\n. Your band will reboot after installing the .fw file.\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. 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!"