1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-27 02:55:50 +01:00

Avoid NPE when fetching activity data:

java.lang.NullPointerException: Attempt to write to field 'int nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport$ActivityStruct.activityDataHolderProgress' on a null object reference
        at nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport.flushActivityDataHolder(MiBandSupport.java:748)
        at nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport.handleActivityNotif(MiBandSupport.java:689)
        at nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport.onCharacteristicChanged(MiBandSupport.java:583)
        at nodomain.freeyourgadget.gadgetbridge.btle.BtLEQueue$2.onCharacteristicChanged(BtLEQueue.java:369)
This commit is contained in:
cpfeiffer 2015-07-25 00:08:15 +02:00
parent a1f60aab91
commit 716bbc7b78

View File

@ -672,7 +672,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
if (activityStruct.activityDataRemainingBytes == 0) { if (activityStruct.activityDataRemainingBytes == 0) {
sendAckDataTransfer(activityStruct.activityDataTimestampToAck, activityStruct.activityDataUntilNextHeader); sendAckDataTransfer(activityStruct.activityDataTimestampToAck, activityStruct.activityDataUntilNextHeader);
flushActivityDataHolder();
} }
} }
@ -712,6 +711,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} }
private void flushActivityDataHolder() { private void flushActivityDataHolder() {
if (activityStruct == null) {
LOG.debug("nothing to flush, struct is already null");
return;
}
LOG.debug("flushing activity data holder");
byte category, intensity, steps; byte category, intensity, steps;
ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler(); ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler();
@ -770,6 +774,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("send acknowledge"); TransactionBuilder builder = performInitialized("send acknowledge");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), ack); builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), ack);
builder.queue(getQueue()); builder.queue(getQueue());
// flush to the DB after sending the ACK
flushActivityDataHolder();
//The last data chunk sent by the miband has always length 0. //The last data chunk sent by the miband has always length 0.
//When we ack this chunk, the transfer is done. //When we ack this chunk, the transfer is done.
if(getDevice().isBusy() && bytesTransferred==0) { if(getDevice().isBusy() && bytesTransferred==0) {
@ -781,6 +789,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} }
private void handleActivityFetchFinish() { private void handleActivityFetchFinish() {
LOG.info("Fetching activity data has finished.");
activityStruct = null; activityStruct = null;
unsetBusy(); unsetBusy();
} }