diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java index 4a506817b..fb4cc144e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100DeviceCoordinator.java @@ -82,31 +82,11 @@ public class CasioGBX100DeviceCoordinator extends Casio2C2DDeviceCoordinator { return BONDING_STYLE_LAZY; } - @Override - public boolean supportsCalendarEvents() { - return false; - } - - @Override - public boolean supportsRealtimeData() { - return false; - } - - @Override - public boolean supportsWeather() { - return false; - } - @Override public boolean supportsAlarmSnoozing() { return true; } - @Override - public boolean supportsFindDevice() { - return false; - } - @Override public Class getPairingActivity() { return null; @@ -132,26 +112,11 @@ public class CasioGBX100DeviceCoordinator extends Casio2C2DDeviceCoordinator { return new CasioGBX100SampleProvider(device, session); } - @Override - public boolean supportsScreenshots(final GBDevice device) { - return false; - } - @Override public int getAlarmSlotCount(GBDevice device) { return 4; } - @Override - public boolean supportsHeartRateMeasurement(GBDevice device) { - return false; - } - - @Override - public boolean supportsAppsManagement(final GBDevice device) { - return false; - } - @Override public Class getAppsManagementActivity() { return null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java index 0626da017..120efa99b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java @@ -53,6 +53,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.Casio2C2DSupport; import nodomain.freeyourgadget.gadgetbridge.util.GB; +import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_AUTOLIGHT; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_AUTOREMOVE_MESSAGE; @@ -299,32 +300,27 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared // If not a call or email, check the sender and if null, promote the title and message preview // as subtitle if (showMessagePreview && icon != CasioConstants.CATEGORY_INCOMING_CALL && icon != CasioConstants.CATEGORY_EMAIL) { - if (sender == null) { + if (!StringUtils.isNullOrEmpty(sender)) { // Shift title to sender slot sender = title; } //Shift content to title - if (message != null) { + if (!StringUtils.isNullOrEmpty(message)) { title = message.substring(0, Math.min(message.length(), 18)) + ".."; } } // Make sure title and sender are less than 32 characters byte[] titleBytes = new byte[0]; - if(title != null) { + if (!StringUtils.isNullOrEmpty(title)) { if (title.length() > 32) { title = title.substring(0, 30) + ".."; } titleBytes = title.getBytes(StandardCharsets.UTF_8); } - byte[] messageBytes = new byte[0]; - if(message != null) { - messageBytes = message.getBytes(StandardCharsets.UTF_8); - } - byte[] senderBytes = new byte[0]; - if(sender != null) { + if (!StringUtils.isNullOrEmpty(sender)) { if (sender.length() > 32) { sender = sender.substring(0, 30) + ".."; } @@ -332,10 +328,17 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared } byte[] subtitleBytes = new byte[0]; - if (subtitle != null) { + if (!StringUtils.isNullOrEmpty(subtitle)) { subtitleBytes = subtitle.getBytes(StandardCharsets.UTF_8); } + // Ensure the sum of all messages is not over 287 bytes, as per #4063 + // FIXME: We probably need to take the MTU into account too... + byte[] messageBytes = new byte[0]; + if (!StringUtils.isNullOrEmpty(message)) { + messageBytes = StringUtils.truncateToBytes(message, 287 - titleBytes.length - senderBytes.length - subtitleBytes.length); + } + byte[] arr = new byte[22]; arr[0] = (byte)(id & 0xff); arr[1] = (byte) ((id >> 8) & 0xff); @@ -400,10 +403,10 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared try { TransactionBuilder builder = performInitialized("showNotification"); builder.write(getCharacteristic(CasioConstants.CASIO_NOTIFICATION_CHARACTERISTIC_UUID), copy); - LOG.info("Showing notification, title: " + title + " message (not sent): " + message); + LOG.info("Showing notification, title: {} message: {}", title, message); builder.queue(getQueue()); } catch (IOException e) { - LOG.warn("showNotification failed: " + e.getMessage()); + LOG.error("showNotification failed", e); } } @@ -432,7 +435,7 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared icon = CasioConstants.CATEGORY_OTHER; break; } - LOG.info("onNotification id=" + notificationSpec.getId()); + LOG.info("onNotification id={}", notificationSpec.getId()); showNotification(icon, notificationSpec.sender, notificationSpec.title, notificationSpec.body, notificationSpec.getId(), false); mSyncedNotificationIDs.add(notificationSpec.getId()); if(autoremove) {