From 197243bf7a04acea8e6edaee84c9747773816960 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Mon, 6 Jan 2020 15:06:29 +0100 Subject: [PATCH] fixed crash --- .../devices/qhybrid/QHybridSupport.java | 35 ++++++-- .../fossil_hr/FossilHRWatchAdapter.java | 82 +++++++++++++------ .../fossil_hr/music/MusicInfoSetRequest.java | 3 +- 3 files changed, 89 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java index 0bb4e9eea..038befc5d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java @@ -267,10 +267,31 @@ public class QHybridSupport extends QHybridBaseSupport { break; } case QHYBRID_COMMAND_SET_WIDGET_CONTENT: { - String id = String.valueOf(intent.getExtras().get("EXTRA_WIDGET_ID")); - String content = String.valueOf(intent.getExtras().get("EXTRA_CONTENT")); - boolean render = intent.getBooleanExtra("EXTRA_RENDER", true); - watchAdapter.setWidgetContent(id, content, render); + HashMap widgetValues = new HashMap<>(); + + for(String key : intent.getExtras().keySet()){ + if(key.matches("^EXTRA_WIDGET_ID_.*$")){ + widgetValues.put(key.substring(16), String.valueOf(intent.getExtras().get(key))); + } + } + if(widgetValues.size() > 0){ + Iterator valuesIterator = widgetValues.keySet().iterator(); + valuesIterator.next(); + + while(valuesIterator.hasNext()){ + String id = valuesIterator.next(); + watchAdapter.setWidgetContent(id, widgetValues.get(id), false); + } + + valuesIterator = widgetValues.keySet().iterator(); + String id = valuesIterator.next(); + watchAdapter.setWidgetContent(id, widgetValues.get(id), true); + }else { + String id = String.valueOf(intent.getExtras().get("EXTRA_WIDGET_ID")); + String content = String.valueOf(intent.getExtras().get("EXTRA_CONTENT")); + boolean render = intent.getBooleanExtra("EXTRA_RENDER", true); + watchAdapter.setWidgetContent(id, content, render); + } break; } } @@ -338,7 +359,11 @@ public class QHybridSupport extends QHybridBaseSupport { public void onSetMusicInfo(MusicSpec musicSpec) { super.onSetMusicInfo(musicSpec); - watchAdapter.setMusicInfo(musicSpec); + try { + watchAdapter.setMusicInfo(musicSpec); + }catch (Exception e){ + GB.log("setMusicInfo error", GB.ERROR, e); + } } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index fbd46556f..de88ce833 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -14,6 +14,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.util.Date; import java.util.GregorianCalendar; @@ -23,6 +24,7 @@ import java.util.TimeZone; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.Widget; import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HRConfigActivity; +import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationHRConfiguration; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; @@ -46,6 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.menu.SetCommuteMenuMessage; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicInfoSetRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.notification.NotificationFilterPutHRRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.StringUtils; @@ -59,7 +62,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { private byte[] phoneRandomNumber; private byte[] watchRandomNumber; - CustomWidget[] widgets; + CustomWidget[] widgets = new CustomWidget[0]; private MusicSpec currentSpec = null; @@ -90,7 +93,14 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { // }, this)); // queueWrite(new PlayNotificationRequest("com.whatsapp", "WhatsAp", "wHATSaPP", this)); - // queueWrite(new PlayNotificationRequest("twitterrrr", "Twitterr", "tWITTER", this)); + // queueWrite(new PlayNotificationRequest("twitterrrr", "Twitterr", "tWITTER", this));queueWrite(new NotificationFilterPutRequest( + // new NotificationConfiguration[]{ + // new NotificationConfiguration((short) -1, (short) -1, "generic", "", false, PlayNotificationRequest.VibrationType.SINGLE_LONG, 0) + // }, + + queueWrite(new NotificationFilterPutHRRequest(new NotificationHRConfiguration[]{ + new NotificationHRConfiguration("generic", 0) + },this)); syncSettings(); @@ -99,9 +109,30 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { overwriteButtons(null); loadWidgets(); - // renderWidgets(); + renderWidgets(); // dunno if there is any point in doing this at start since when no watch is connected the QHybridSupport will not receive any intents anyway + /*try { + queueWrite(new AssetFilePutRequest(new AssetImage[]{ + AssetImageFactory.createAssetImage("0D58BD24", new byte[]{(byte) 0x18, (byte) 0x18, (byte) 0x1D, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x0E, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x0D, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x0E, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x0F, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x11, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x0B, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x0D, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x13, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x1D, (byte) 0x00, (byte) 0xFF, (byte) 0xFF}, 0, 0, 0), + AssetImageFactory.createAssetImage("AD365776", new byte[]{(byte) 0x18, (byte) 0x18, (byte) 0x1D, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x0B, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x07, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x08, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x0A, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x0C, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0x04, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x05, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x13, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x1D, (byte) 0x00, (byte) 0xFF, (byte) 0xFF}, 0, 0, 0), + AssetImageFactory.createAssetImage("C3F69363", new byte[]{(byte) 0x18, (byte) 0x18, (byte) 0x1E, (byte) 0x00, (byte) 0x0C, (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x0E, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x0E, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x0B, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x00, (byte) 0x0D, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x09, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x0F, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x11, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x12, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x13, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x16, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0xFF, (byte) 0xFF}, 0, 0, 0), + AssetImageFactory.createAssetImage("7251C82B", new byte[]{(byte) 0x18, (byte) 0x18, (byte) 0x3B, (byte) 0x0C, (byte) 0x02, (byte) 0x0D, (byte) 0x16, (byte) 0x0C, (byte) 0x02, (byte) 0x07, (byte) 0x16, (byte) 0x0C, (byte) 0x02, (byte) 0x03, (byte) 0x15, (byte) 0x0C, (byte) 0x01, (byte) 0x0A, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0A, (byte) 0x14, (byte) 0x0C, (byte) 0x04, (byte) 0x03, (byte) 0x13, (byte) 0x0C, (byte) 0x01, (byte) 0x09, (byte) 0x01, (byte) 0x03, (byte) 0x02, (byte) 0x0A, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09, (byte) 0x0F, (byte) 0x0C, (byte) 0x02, (byte) 0x0D, (byte) 0x01, (byte) 0x09, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x0C, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x09, (byte) 0x02, (byte) 0x0D, (byte) 0x08, (byte) 0x0C, (byte) 0x01, (byte) 0x0A, (byte) 0x07, (byte) 0x03, (byte) 0x01, (byte) 0x06, (byte) 0x02, (byte) 0x0C, (byte) 0x01, (byte) 0x06, (byte) 0x07, (byte) 0x03, (byte) 0x01, (byte) 0x0A, (byte) 0x05, (byte) 0x0C, (byte) 0x01, (byte) 0x06, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x06, (byte) 0x02, (byte) 0x09, (byte) 0x01, (byte) 0x0D, (byte) 0x04, (byte) 0x0C, (byte) 0x01, (byte) 0x0D, (byte) 0x01, (byte) 0x09, (byte) 0x01, (byte) 0x0A, (byte) 0x01, (byte) 0x06, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x06, (byte) 0x07, (byte) 0x0C, (byte) 0x01, (byte) 0x0A, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0D, (byte) 0x08, (byte) 0x0C, (byte) 0x01, (byte) 0x0D, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0A, (byte) 0x09, (byte) 0x0C, (byte) 0x01, (byte) 0x09, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x09, (byte) 0x06, (byte) 0x0C, (byte) 0x01, (byte) 0x09, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x09, (byte) 0x0B, (byte) 0x0C, (byte) 0x01, (byte) 0x0D, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0D, (byte) 0x05, (byte) 0x0C, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0D, (byte) 0x0D, (byte) 0x0C, (byte) 0x01, (byte) 0x07, (byte) 0x01, (byte) 0x03, (byte) 0x06, (byte) 0x0C, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x0E, (byte) 0x0C, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x0C, (byte) 0x02, (byte) 0x09, (byte) 0x02, (byte) 0x0C, (byte) 0x01, (byte) 0x07, (byte) 0x01, (byte) 0x03, (byte) 0x0D, (byte) 0x0C, (byte) 0x01, (byte) 0x0D, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x06, (byte) 0x01, (byte) 0x0D, (byte) 0x01, (byte) 0x07, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x01, (byte) 0x0D, (byte) 0x01, (byte) 0x06, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x0D, (byte) 0x0C, (byte) 0x0C, (byte) 0x01, (byte) 0x09, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x02, (byte) 0x03, (byte) 0x02, (byte) 0x06, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x07, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09, (byte) 0x0C, (byte) 0x0C, (byte) 0x01, (byte) 0x06, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x0D, (byte) 0x02, (byte) 0x0C, (byte) 0x01, (byte) 0x0D, (byte) 0x03, (byte) 0x03, (byte) 0x01, (byte) 0x06, (byte) 0x0C, (byte) 0x0C, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x0A, (byte) 0x06, (byte) 0x0C, (byte) 0x01, (byte) 0x0A, (byte) 0x02, (byte) 0x03, (byte) 0x0C, (byte) 0x0C, (byte) 0x01, (byte) 0x06, (byte) 0x0A, (byte) 0x0C, (byte) 0x01, (byte) 0x06, (byte) 0x4E, (byte) 0x0C, (byte) 0xFF, (byte) 0xFF}, 0, 0, 0), + }, this)); + } catch (IOException e) { + e.printStackTrace(); + }*/ + + /*queueWrite(new ImagesSetRequest( + new AssetImage[]{ + AssetImageFactory.createAssetImage("0D58BD24", null, 0, 60, 1), + AssetImageFactory.createAssetImage("AD365776", null, 90, 60, 1), + AssetImageFactory.createAssetImage("C3F69363", null, 180, 60, 1), + AssetImageFactory.createAssetImage("7251C82B", null, 270, 60, 1), + }, + this + )); +*/ queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED)); } @@ -116,7 +147,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { btcWidget.addElement(new CustomWidgetElement(CustomWidgetElement.WidgetElementType.TYPE_TEXT, "btc", "wtf", CustomWidgetElement.X_CENTER, CustomWidgetElement.Y_LOWER_HALF)); this.widgets = new CustomWidget[]{ ethWidget, - // btcWidget, + btcWidget, }; } @@ -127,7 +158,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { for (int i = 0; i < this.widgets.length; i++) { CustomWidget widget = widgets[i]; - Bitmap widgetBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888); + Bitmap widgetBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_4444); Canvas widgetCanvas = new Canvas(widgetBitmap); @@ -168,17 +199,10 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { // queueWrite(new FileDeleteRequest((short) 0x0700)); queueWrite(new AssetFilePutRequest( - new AssetFile[]{widgetImages[0]}, + widgetImages, this )); - // for(int i = 0; i < widgetImages.length; i++){ - // queueWrite(new AssetFilePutRequest(widgetImages[i], i + 1, this)); - // } - - // widgetImages[1].setFileName(widgetImages[0].getFileName()); - - queueWrite(new FileDeleteRequest((short) 0x0503)); queueWrite(new ImagesSetRequest( widgetImages, this @@ -189,17 +213,17 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { } @Override - public void setWidgetContent(String widgetID, String content, boolean render) { + public void setWidgetContent(String widgetID, String content, boolean renderOnWatch) { boolean update = false; - for(CustomWidget widget : this.widgets){ + for (CustomWidget widget : this.widgets) { CustomWidgetElement element = widget.getElement(widgetID); - if(element == null) continue; + if (element == null) continue; element.setValue(content); update = true; } - if(render && update) renderWidgets(); + if (renderOnWatch && update) renderWidgets(); } private void negotiateSymmetricKey() { @@ -236,12 +260,16 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { && currentSpec.track.equals(musicSpec.track) ) return; currentSpec = musicSpec; - queueWrite(new MusicInfoSetRequest( - musicSpec.artist, - musicSpec.album, - musicSpec.track, - this - )); + try { + queueWrite(new MusicInfoSetRequest( + musicSpec.artist, + musicSpec.album, + musicSpec.track, + this + )); + }catch (BufferOverflowException e){ + GB.log("musicInfo: " + musicSpec, GB.ERROR, e); + } } @Override @@ -276,7 +304,11 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { public boolean playRawNotification(NotificationSpec notificationSpec) { String sender = notificationSpec.sender; if (sender == null) sender = notificationSpec.sourceName; - queueWrite(new PlayNotificationRequest("generic", notificationSpec.sourceName, notificationSpec.body, this)); + try { + queueWrite(new PlayNotificationRequest("generic", notificationSpec.sourceName, notificationSpec.body, this)); + }catch (Exception e){ + e.printStackTrace(); + } return true; } @@ -349,7 +381,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { if (requestType == (byte) 0x05) { handleMusicRequest(value); - }else if(requestType == (byte) 0x01) { + } else if (requestType == (byte) 0x01) { int eventId = value[2]; try { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/music/MusicInfoSetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/music/MusicInfoSetRequest.java index f9011fc88..7331b90e0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/music/MusicInfoSetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/music/MusicInfoSetRequest.java @@ -1,5 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music; +import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -11,7 +12,7 @@ public class MusicInfoSetRequest extends FilePutRequest { super((short) 0x0400, createFile(artist, album, title), adapter); } - private static byte[] createFile(String artist, String album, String title){ + private static byte[] createFile(String artist, String album, String title) { int length = artist.length() + album.length() + title.length() + 3 // null terminators + 8; // length and header