Amazfit Neo: Implement firmware update but keep it disabled for now

Flashing to the latest firmware breaks Gadgetbridge compatibility
This commit is contained in:
Andreas Shimokawa 2021-03-24 23:49:52 +01:00
parent 9dc4dde5e7
commit c410f0e4a7
7 changed files with 38 additions and 29 deletions

View File

@ -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[]{

View File

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

View File

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

View File

@ -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<Integer, String> 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<Integer, String> getCrcMap() {
return crcToVersion;
}
@Override
protected String searchFirmwareVersion(byte[] fwbytes) {
// Not implemented
return null;
}
}

View File

@ -16,14 +16,25 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
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);
}
}

View File

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

View File

@ -86,6 +86,7 @@
<string name="fw_upgrade_notice_miband4">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!</string>
<string name="fw_upgrade_notice_miband5">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!</string>
<string name="fw_upgrade_notice_amazfitx">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!</string>
<string name="fw_upgrade_notice_amazfitneo">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!</string>
<string name="fw_multi_upgrade_notice">You are about to install the %1$s and %2$s firmware, instead of the ones currently on your Mi Band.</string>
<string name="miband_firmware_known">This firmware has been tested and is known to be compatible with Gadgetbridge.</string>
<string name="miband_firmware_unknown_warning">"This firmware is untested and may not be compatible with Gadgetbridge.\n\nYou are DISCOURAGED from flashing it!"</string>