From c896e476f4b0a2d7b5474374fd2f8c72b54441de Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 6 Jan 2021 16:28:20 +0100 Subject: [PATCH] Amazfit GTR2: Try to fix incoming calls blindly --- .../service/devices/huami/HuamiSupport.java | 27 ++++++++++++++++++ .../huami/amazfitbips/AmazfitBipSSupport.java | 28 +------------------ .../huami/amazfitgtr2/AmazfitGTR2Support.java | 10 +++++-- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index bdfc9f83a..1e4ce1aba 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -804,6 +804,33 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { } } + public void onSetCallStateNew(CallSpec callSpec) { + if (callSpec.command == CallSpec.CALL_INCOMING) { + byte[] message = NotificationUtils.getPreferredTextFor(callSpec).getBytes(); + int length = 10 + message.length; + ByteBuffer buf = ByteBuffer.allocate(length); + buf.order(ByteOrder.LITTLE_ENDIAN); + buf.put(new byte[]{3, 0, 0, 0, 0, 0}); + buf.put(message); + buf.put(new byte[]{0, 0, 0, 2}); + try { + TransactionBuilder builder = performInitialized("incoming call"); + writeToChunked(builder, 0, buf.array()); + builder.queue(getQueue()); + } catch (IOException e) { + LOG.error("Unable to send incoming call"); + } + } else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) { + try { + TransactionBuilder builder = performInitialized("end call"); + writeToChunked(builder, 0, new byte[]{3, 3, 0, 0, 0, 0}); + builder.queue(getQueue()); + } catch (IOException e) { + LOG.error("Unable to send end call"); + } + } + } + private void stopCurrentCallNotification() { try { TransactionBuilder builder = performInitialized("stop notification"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java index 98526d557..ef9f68cbf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java @@ -23,8 +23,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; @@ -36,7 +34,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.Ama 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.util.NotificationUtils; import nodomain.freeyourgadget.gadgetbridge.util.Version; public class AmazfitBipSSupport extends AmazfitBipSupport { @@ -66,30 +63,7 @@ public class AmazfitBipSSupport extends AmazfitBipSupport { @Override public void onSetCallState(CallSpec callSpec) { - if (callSpec.command == CallSpec.CALL_INCOMING) { - byte[] message = NotificationUtils.getPreferredTextFor(callSpec).getBytes(); - int length = 10 + message.length; - ByteBuffer buf = ByteBuffer.allocate(length); - buf.order(ByteOrder.LITTLE_ENDIAN); - buf.put(new byte[]{3, 0, 0, 0, 0, 0}); - buf.put(message); - buf.put(new byte[]{0, 0, 0, 2}); - try { - TransactionBuilder builder = performInitialized("incoming call"); - writeToChunked(builder, 0, buf.array()); - builder.queue(getQueue()); - } catch (IOException e) { - LOG.error("Unable to send incoming call"); - } - } else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) { - try { - TransactionBuilder builder = performInitialized("end call"); - writeToChunked(builder, 0, new byte[]{3, 3, 0, 0, 0, 0}); - builder.queue(getQueue()); - } catch (IOException e) { - LOG.error("Unable to send end call"); - } - } + onSetCallStateNew(callSpec); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2Support.java index d8a33c002..6ebe709dc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2Support.java @@ -23,17 +23,23 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgtr2.AmazfitGTR2FWHelper; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts.AmazfitGTSSupport; +import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgtr.AmazfitGTRSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation2020; -public class AmazfitGTR2Support extends AmazfitGTSSupport { +public class AmazfitGTR2Support extends AmazfitGTRSupport { @Override public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { return new AmazfitGTR2FWHelper(uri, context); } + @Override + public void onSetCallState(CallSpec callSpec) { + onSetCallStateNew(callSpec); + } + @Override public UpdateFirmwareOperation createUpdateFirmwareOperation(Uri uri) { return new UpdateFirmwareOperation2020(uri, this);