1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 11:26:47 +01:00

Xiaomi: Prevent NPE when not yet connected

This commit is contained in:
José Rebelo 2023-10-22 10:06:32 +01:00
parent ce1d095074
commit 81ca617601

View File

@ -428,6 +428,12 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
}
public void sendCommand(final TransactionBuilder builder, final XiaomiProto.Command command) {
if (this.characteristicCommandWrite == null) {
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
LOG.warn("characteristicCommandWrite is null!");
return;
}
// FIXME builder is ignored
final byte[] commandBytes = command.toByteArray();
LOG.debug("Sending command {}", GB.hexdump(commandBytes));
@ -435,6 +441,12 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
}
public void sendCommand(final TransactionBuilder builder, final byte[] commandBytes) {
if (this.characteristicCommandWrite == null) {
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
LOG.warn("characteristicCommandWrite is null!");
return;
}
// FIXME builder is ignored
this.characteristicCommandWrite.write(commandBytes);
}