mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 01:21:56 +01:00
Avoid NPEs when aborting an erroneous sync #205
This commit is contained in:
parent
a6d3c50f94
commit
ae5417b9cc
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
|
||||
|
||||
/**
|
||||
* Abstract base class for a BTLEOperation, i.e. an operation that does more than
|
||||
@ -25,6 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
*/
|
||||
public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport> implements GattCallback, BTLEOperation {
|
||||
private final T mSupport;
|
||||
protected OperationStatus operationStatus = OperationStatus.INITIAL;
|
||||
|
||||
protected AbstractBTLEOperation(T support) {
|
||||
mSupport = support;
|
||||
@ -38,7 +40,9 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
|
||||
*/
|
||||
@Override
|
||||
public final void perform() throws IOException {
|
||||
operationStatus = OperationStatus.STARTED;
|
||||
prePerform();
|
||||
operationStatus = OperationStatus.RUNNING;
|
||||
doPerform();
|
||||
}
|
||||
|
||||
@ -101,6 +105,10 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
}
|
||||
|
||||
public boolean isOperationRunning() {
|
||||
return operationStatus == OperationStatus.RUNNING;
|
||||
}
|
||||
|
||||
public T getSupport() {
|
||||
return mSupport;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public abstract class AbstractMiBandOperation extends AbstractBTLEOperation<MiBa
|
||||
|
||||
@Override
|
||||
protected void operationFinished() {
|
||||
operationStatus = OperationStatus.FINISHED;
|
||||
if (getDevice() != null && getDevice().isConnected()) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("reenabling disabled notifications");
|
||||
|
@ -174,6 +174,12 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||
* @see #bufferActivityData(byte[])
|
||||
*/
|
||||
private void handleActivityNotif(byte[] value) {
|
||||
if (!isOperationRunning()) {
|
||||
LOG.error("ignoring activity data notification because operation is not running. Data length: " + value.length);
|
||||
getSupport().logMessageContent(value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.length == activityMetadataLength) {
|
||||
handleActivityMetadata(value);
|
||||
} else {
|
||||
|
@ -0,0 +1,8 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations;
|
||||
|
||||
public enum OperationStatus {
|
||||
INITIAL,
|
||||
STARTED,
|
||||
RUNNING,
|
||||
FINISHED
|
||||
}
|
Loading…
Reference in New Issue
Block a user