From dbb92b55bc4d8ae49d7768c00049da54e87a6893 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Tue, 18 Aug 2015 00:28:17 +0200 Subject: [PATCH] Make the Operations classes BLE-generic --- .../btle/AbstractBTLEDeviceSupport.java | 2 +- .../AbstractBTLEOperation.java} | 24 ++++++++----------- .../BTLEOperation.java} | 4 ++-- .../service/devices/miband/MiBandSupport.java | 6 ----- .../operations/FetchActivityOperation.java | 3 ++- 5 files changed, 15 insertions(+), 24 deletions(-) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/{devices/miband/operations/AbstractMiBandOperation.java => btle/AbstractBTLEOperation.java} (74%) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/{devices/miband/operations/MiBandOperation.java => btle/BTLEOperation.java} (58%) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java index af4d987a..486215e3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java @@ -80,7 +80,7 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im * @see #performConnected(Transaction) * @see #initializeDevice(TransactionBuilder) */ - protected TransactionBuilder performInitialized(String taskName) throws IOException { + public TransactionBuilder performInitialized(String taskName) throws IOException { if (!isConnected()) { if (!connect()) { throw new IOException("1: Unable to connect to device: " + getDevice()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java similarity index 74% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java index ccca9d0c..3fe5aa69 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java @@ -1,4 +1,4 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations; +package nodomain.freeyourgadget.gadgetbridge.service.btle; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; @@ -9,33 +9,29 @@ import java.io.IOException; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue; -import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCallback; -import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; -import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport; /** - * Abstract base class for a MiBandOperation, i.e. an operation that does more than - * just sending a few bytes to the band. It typically involves exchanging many messages - * between the mobile and the band. + * Abstract base class for a BTLEOperation, i.e. an operation that does more than + * just sending a few bytes to the device. It typically involves exchanging many messages + * between the mobile and the device. * * One operation may execute multiple @{link Transaction transactions} with each * multiple @{link BTLEAction actions}. * * This class implements GattCallback so that subclasses may override those methods * to handle those events. - * Note: by default all Gatt events are forwarded to MiBandSupport, subclasses may override + * Note: by default all Gatt events are forwarded to AbstractBTLEDeviceSupport, subclasses may override * this behavior. */ -public abstract class AbstractMiBandOperation implements GattCallback, MiBandOperation { - private final MiBandSupport mSupport; +public abstract class AbstractBTLEOperation implements GattCallback, BTLEOperation { + private final T mSupport; - protected AbstractMiBandOperation(MiBandSupport support) { + protected AbstractBTLEOperation(T support) { mSupport = support; } /** - * Delegates to MiBandSupport and additionally sets this instance as the Gatt + * Delegates to the DeviceSupport instance and additionally sets this instance as the Gatt * callback for the transaction. * @param taskName * @return @@ -68,7 +64,7 @@ public abstract class AbstractMiBandOperation implements GattCallback, MiBandOpe getDevice().sendDeviceUpdateIntent(getContext()); } - public MiBandSupport getSupport() { + public T getSupport() { return mSupport; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/MiBandOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BTLEOperation.java similarity index 58% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/MiBandOperation.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BTLEOperation.java index 2cd8f1c4..3b64e3d8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/MiBandOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BTLEOperation.java @@ -1,9 +1,9 @@ -package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations; +package nodomain.freeyourgadget.gadgetbridge.service.btle; import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport; -public interface MiBandOperation { +public interface BTLEOperation { public void perform() throws IOException; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 4089d862..63838575 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -917,10 +917,4 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } return true; } - - // overridden to make visible to operations - @Override - public TransactionBuilder performInitialized(String taskName) throws IOException { - return super.performInitialized(taskName); - } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java index e81dab0b..cf05b1b3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/FetchActivityOperation.java @@ -20,13 +20,14 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService; +import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; -public class FetchActivityOperation extends AbstractMiBandOperation { +public class FetchActivityOperation extends AbstractBTLEOperation { private static final Logger LOG = LoggerFactory.getLogger(FetchActivityOperation.class); private static final byte[] fetch = new byte[]{MiBandService.COMMAND_FETCH_DATA};