From 97a8aebdb3f5f56c335e633909136f04acc5556b Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 29 Apr 2021 22:38:44 +0200 Subject: [PATCH] Fossil Hybrid HR: Fix crash and connection problem when using non-ascii in quick replies --- .../quickreply/QuickReplyConfigurationPutRequest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/quickreply/QuickReplyConfigurationPutRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/quickreply/QuickReplyConfigurationPutRequest.java index 066bfd2f1..c705178f2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/quickreply/QuickReplyConfigurationPutRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/quickreply/QuickReplyConfigurationPutRequest.java @@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fo import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr.FossilHRWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle; @@ -36,7 +37,7 @@ public class QuickReplyConfigurationPutRequest extends FilePutRequest { byte[] mysteryHeader = new byte[]{(byte) 0x02, (byte) 0x0b, (byte) 0x46, (byte) 0x00, (byte) 0x03, (byte) 0x19, (byte) 0x00, (byte) 0x00, (byte) 0x00}; - Charset charsetUTF8 = Charset.forName("UTF-8"); + Charset charsetUTF8 = StandardCharsets.UTF_8; String iconName = StringUtils.terminateNull("icMessage.icon"); byte[] iconNameBytes = iconName.getBytes(charsetUTF8); @@ -46,7 +47,7 @@ public class QuickReplyConfigurationPutRequest extends FilePutRequest { reply = reply.substring(0, 50); } processedReplies[index] = StringUtils.terminateNull(reply); - fileLength += 8 + processedReplies[index].length() + iconNameBytes.length; + fileLength += 8 + processedReplies[index].getBytes(charsetUTF8).length + iconNameBytes.length; } ByteBuffer mainBuffer = ByteBuffer.allocate(mysteryHeader.length + 4 + fileLength);