From 5ff55617721b3f4a1fe9184f9c5c0ee8468a16fb Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 24 Jul 2019 09:33:53 +0200 Subject: [PATCH] Mi Band 4: Fix notification icons and cut-off text --- .../huami/miband4/MiBand4Coordinator.java | 4 +++- .../devices/huami/HuamiFirmwareInfo.java | 2 ++ .../huami/amazfitbip/AmazfitBipSupport.java | 17 +++++++++++++---- .../amazfitcor2/AmazfitCor2FirmwareInfo.java | 3 --- .../devices/huami/miband4/MiBand4Support.java | 3 ++- app/src/main/res/values/strings.xml | 7 ++++++- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java index 2a171e15c..f6bbc8461 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband4/MiBand4Coordinator.java @@ -57,9 +57,11 @@ public class MiBand4Coordinator extends HuamiCoordinator { } + @Override public InstallHandler findInstallHandler(Uri uri, Context context) { - return null; + MiBand4FWInstallHandler handler = new MiBand4FWInstallHandler(uri, context); + return handler.isValid() ? handler : null; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java index 981388a00..c511daa27 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java @@ -49,6 +49,8 @@ public abstract class HuamiFirmwareInfo { }; protected static final int FONT_TYPE_OFFSET = 0x9; + protected static final int COMPRESSED_RES_HEADER_OFFSET = 0x9; + protected static final int COMPRESSED_RES_HEADER_OFFSET_NEW = 0xd; private HuamiFirmwareType firmwareType; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java index 787702c6c..967f48076 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java @@ -137,16 +137,25 @@ public class AmazfitBipSupport extends HuamiSupport { appSuffix = appName.getBytes(); suffixlength = appSuffix.length; } + if (gbDevice.getType() == DeviceType.MIBAND4) { + prefixlength += 4; + } byte[] rawmessage = message.getBytes(); int length = Math.min(rawmessage.length, maxLength - prefixlength); byte[] command = new byte[length + prefixlength + suffixlength]; - - command[0] = (byte) alertCategory.getId(); - command[1] = (byte) (gbDevice.getType() == DeviceType.MIBAND4 ? 0 : 1); // FIXME: remove hack + int pos = 0; + command[pos++] = (byte) alertCategory.getId(); + if (gbDevice.getType() == DeviceType.MIBAND4) { + command[pos++] = 0; // TODO + command[pos++] = 0; + command[pos++] = 0; + command[pos++] = 0; + } + command[pos++] = 1; if (alertCategory == AlertCategory.CustomHuami) { - command[2] = customIconId; + command[pos] = customIconId; } System.arraycopy(rawmessage, 0, command, prefixlength, length); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitcor2/AmazfitCor2FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitcor2/AmazfitCor2FirmwareInfo.java index 119fbb35d..3fcccc536 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitcor2/AmazfitCor2FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitcor2/AmazfitCor2FirmwareInfo.java @@ -31,9 +31,6 @@ public class AmazfitCor2FirmwareInfo extends HuamiFirmwareInfo { 0x00, (byte) 0x98, 0x00, 0x20, (byte) 0xA5, 0x04, 0x00, 0x20, (byte) 0xAD, 0x04, 0x00, 0x20, (byte) 0xC5, 0x04, 0x00, 0x20 }; - private static final int COMPRESSED_RES_HEADER_OFFSET = 0x9; - private static final int COMPRESSED_RES_HEADER_OFFSET_NEW = 0xd; - private static Map crcToVersion = new HashMap<>(); static { 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 d7feb5b97..2250925a0 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 @@ -22,6 +22,7 @@ import android.net.Uri; import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband4.MiBand4FWHelper; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3.MiBand3Support; public class MiBand4Support extends MiBand3Support { @@ -33,6 +34,6 @@ public class MiBand4Support extends MiBand3Support { @Override public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { - return null; + return new MiBand4FWHelper(uri, context); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b9adc3bc0..c67acfef2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,7 +57,8 @@ You are about to install the %s firmware on your Amazfit Bip.\n\nPlease make sure to install the .fw file, then the .res file, and finally the .gps file. Your watch will reboot after installing the .fw file.\n\nNote: You do not have to install .res and .gps if these files are exactly the same as the ones previously installed.\n\nPROCEED AT YOUR OWN RISK! You are about to install the %s firmware on your Amazfit Cor.\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 Cor 2.\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!\n\nCOMPLETELY UNTESTED, PROBABLY YOU NEED TO FLASH A BEATS_W FIRMWARE IF YOUR DEVICE NAME is \"Amazfit Band 2\!" - You are about to install the %s firmware on your Mi Band 3.\n\nPlease make sure to install the .fw file, and after that the .res file. Your watch 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 3.\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 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 %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!" @@ -225,6 +226,10 @@ Auth Key Change the auth key to a common key on all your Android devices from which you would like to connect from. The previous default key for all devices is 0123456789@ABCDE + Heart rate alarm during sports activity + Low limit + High limit + Auto export Auto export enabled