mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-26 16:41:43 +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 java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
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
|
* 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 {
|
public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport> implements GattCallback, BTLEOperation {
|
||||||
private final T mSupport;
|
private final T mSupport;
|
||||||
|
protected OperationStatus operationStatus = OperationStatus.INITIAL;
|
||||||
|
|
||||||
protected AbstractBTLEOperation(T support) {
|
protected AbstractBTLEOperation(T support) {
|
||||||
mSupport = support;
|
mSupport = support;
|
||||||
@ -38,7 +40,9 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void perform() throws IOException {
|
public final void perform() throws IOException {
|
||||||
|
operationStatus = OperationStatus.STARTED;
|
||||||
prePerform();
|
prePerform();
|
||||||
|
operationStatus = OperationStatus.RUNNING;
|
||||||
doPerform();
|
doPerform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +105,10 @@ public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport>
|
|||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOperationRunning() {
|
||||||
|
return operationStatus == OperationStatus.RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
public T getSupport() {
|
public T getSupport() {
|
||||||
return mSupport;
|
return mSupport;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public abstract class AbstractMiBandOperation extends AbstractBTLEOperation<MiBa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void operationFinished() {
|
protected void operationFinished() {
|
||||||
|
operationStatus = OperationStatus.FINISHED;
|
||||||
if (getDevice() != null && getDevice().isConnected()) {
|
if (getDevice() != null && getDevice().isConnected()) {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("reenabling disabled notifications");
|
TransactionBuilder builder = performInitialized("reenabling disabled notifications");
|
||||||
|
@ -174,6 +174,12 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
|||||||
* @see #bufferActivityData(byte[])
|
* @see #bufferActivityData(byte[])
|
||||||
*/
|
*/
|
||||||
private void handleActivityNotif(byte[] value) {
|
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) {
|
if (value.length == activityMetadataLength) {
|
||||||
handleActivityMetadata(value);
|
handleActivityMetadata(value);
|
||||||
} else {
|
} 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