aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/io/trygvis/android/bt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/io/trygvis/android/bt')
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtCallback.java12
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtDevice.java26
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtPromise.java179
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtService.java2
-rw-r--r--app/src/main/java/io/trygvis/android/bt/DefaultBtService.java2
-rw-r--r--app/src/main/java/io/trygvis/android/bt/WrappingBluetoothGattCallback.java60
6 files changed, 215 insertions, 66 deletions
diff --git a/app/src/main/java/io/trygvis/android/bt/BtCallback.java b/app/src/main/java/io/trygvis/android/bt/BtCallback.java
index 8dab149..71f7d56 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtCallback.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtCallback.java
@@ -4,16 +4,18 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
-import static io.trygvis.android.bt.BtPromise.*;
+import static io.trygvis.android.bt.BtPromise.PromiseResult;
public class BtCallback {
+ public final boolean stopOnFailure;
public final String name;
- public BtCallback(String name) {
+ public BtCallback(boolean stopOnFailure, String name) {
+ this.stopOnFailure = stopOnFailure;
this.name = name;
}
- public PromiseResult onConnectionStateChange(BluetoothGatt gatt, int newState) {
+ public PromiseResult onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
throw new NotOverriddenException();
}
@@ -49,6 +51,10 @@ public class BtCallback {
throw new NotOverriddenException();
}
+ public PromiseResult onDirect(Object value) {
+ throw new NotOverriddenException();
+ }
+
public void onFailure() {
throw new NotOverriddenException();
}
diff --git a/app/src/main/java/io/trygvis/android/bt/BtDevice.java b/app/src/main/java/io/trygvis/android/bt/BtDevice.java
index 1c7666e..d8dfefc 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtDevice.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtDevice.java
@@ -3,6 +3,7 @@ package io.trygvis.android.bt;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
+import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import java.util.Date;
@@ -21,23 +22,25 @@ public class BtDevice<A extends BtDevice.BtDeviceWrapper<A>> {
private final boolean seenBefore;
private final Date firstSeen;
private Date lastSeen;
+ private boolean connected;
public static interface BtDeviceWrapper<A extends BtDevice.BtDeviceWrapper<A>> {
BtDevice<A> getBtDevice();
}
- BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice,
+ BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice, SQLiteDatabase db,
BtService.BtDbIntegration<A> btDbIntegration, long id, Integer rssi,
BtScanResult scanResult, boolean seenBefore, Date firstSeen, Date lastSeen) {
this.btService = btService;
this.bluetoothDevice = bluetoothDevice;
- this.tag = btDbIntegration.createTag(this);
this.id = id;
this.rssi = rssi;
this.scanResult = scanResult;
this.seenBefore = seenBefore;
this.firstSeen = firstSeen;
this.lastSeen = lastSeen;
+
+ this.tag = btDbIntegration.createTag(db, this);
}
public long getId() {
@@ -60,6 +63,10 @@ public class BtDevice<A extends BtDevice.BtDeviceWrapper<A>> {
return rssi;
}
+ public BtScanResult getScanResult() {
+ return scanResult;
+ }
+
public boolean isSeenBefore() {
return seenBefore;
}
@@ -78,8 +85,15 @@ public class BtDevice<A extends BtDevice.BtDeviceWrapper<A>> {
public synchronized boolean connect(BtPromise executor) {
Log.i(TAG, "connect(), address=" + bluetoothDevice.getAddress());
- BluetoothGattCallback callback = executor.asCallback();
- gatt = bluetoothDevice.connectGatt(btService, false, callback);
+ BluetoothGattCallback callback = executor.asCallback(bluetoothDevice.getAddress());
+ gatt = bluetoothDevice.connectGatt(btService, false, new WrappingBluetoothGattCallback(callback) {
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ BtDevice.this.connected = newState == BluetoothGatt.STATE_CONNECTED;
+
+ super.onConnectionStateChange(gatt, status, newState);
+ }
+ });
return true;
}
@@ -90,8 +104,8 @@ public class BtDevice<A extends BtDevice.BtDeviceWrapper<A>> {
}
}
- public BtScanResult getScanResult() {
- return scanResult;
+ public boolean connected() {
+ return connected;
}
@Override
diff --git a/app/src/main/java/io/trygvis/android/bt/BtPromise.java b/app/src/main/java/io/trygvis/android/bt/BtPromise.java
index 55b6315..6af62c0 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtPromise.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtPromise.java
@@ -10,9 +10,11 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import java.util.Queue;
import io.trygvis.android.F2;
+import io.trygvis.android.F3;
import io.trygvis.android.Function;
import static io.trygvis.android.bt.BtPromise.EventType.onCharacteristicChanged;
@@ -21,6 +23,7 @@ import static io.trygvis.android.bt.BtPromise.EventType.onCharacteristicWrite;
import static io.trygvis.android.bt.BtPromise.EventType.onConnectionStateChange;
import static io.trygvis.android.bt.BtPromise.EventType.onDescriptorRead;
import static io.trygvis.android.bt.BtPromise.EventType.onDescriptorWrite;
+import static io.trygvis.android.bt.BtPromise.EventType.onDirect;
import static io.trygvis.android.bt.BtPromise.EventType.onFailure;
import static io.trygvis.android.bt.BtPromise.EventType.onFinally;
import static io.trygvis.android.bt.BtPromise.EventType.onReliableWriteCompleted;
@@ -28,20 +31,48 @@ import static io.trygvis.android.bt.BtPromise.EventType.onServicesDiscovered;
public class BtPromise {
private final static String TAG = BtPromise.class.getSimpleName();
- private final Queue<BtCallback> actionQ = new ArrayDeque<>();
+ private final List<BtCallback> actionQ = new ArrayList<>();
private final Queue<BtCallback> failureQ = new ArrayDeque<>();
private final Queue<BtCallback> finallyQ = new ArrayDeque<>();
- public static final PromiseResult continueDownChain = new Continue();
- public static final PromiseResult doneWithChain = new Done();
+ private static final PromiseResult waitForNextEvent = new WaitForNextEvent();
+ private static final PromiseResult stop = new Stop();
- public abstract static class PromiseResult {
+ private Boolean stopOnFailure;
+
+ public static class PromiseResult {
+ private PromiseResult() {
+ }
+
+ public static PromiseResult waitForNextEvent() {
+ return waitForNextEvent;
+ }
+
+ public static PromiseResult continueDirectly(Object value) {
+ return new ContinueDirectly(value);
+ }
+
+ public static PromiseResult stop() {
+ return stop;
+ }
+
+ public static PromiseResult detour(BtPromise promise) {
+ return new Detour(promise);
+ }
}
- private static class Continue extends PromiseResult {
+ private static class WaitForNextEvent extends PromiseResult {
}
- private static class Done extends PromiseResult {
+ private static class ContinueDirectly extends PromiseResult {
+ private final Object value;
+
+ private ContinueDirectly(Object value) {
+ this.value = value;
+ }
+ }
+
+ private static class Stop extends PromiseResult {
}
private static class Detour extends PromiseResult {
@@ -52,18 +83,32 @@ public class BtPromise {
}
}
- public synchronized BtPromise onConnectionStateChange(F2<BluetoothGatt, Integer, PromiseResult> callback) {
- actionQ.add(new BtCallback("onConnectionStateChange") {
+ private boolean stopOnFailure() {
+ if(stopOnFailure != null) {
+ boolean b = stopOnFailure;
+ stopOnFailure = null;
+ return b;
+ }
+ return false;
+ }
+
+ public BtPromise ignoreFailureForNext() {
+ stopOnFailure = true;
+ return this;
+ }
+
+ public synchronized BtPromise onConnectionStateChange(F3<BluetoothGatt, Integer, Integer, PromiseResult> callback) {
+ actionQ.add(new BtCallback(stopOnFailure(), "onConnectionStateChange") {
@Override
- public PromiseResult onConnectionStateChange(BluetoothGatt gatt, int newState) {
- return callback.apply(gatt, newState);
+ public PromiseResult onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ return callback.apply(gatt, status,newState);
}
});
return this;
}
public synchronized BtPromise onServicesDiscovered(Function<BluetoothGatt, PromiseResult> callback) {
- actionQ.add(new BtCallback("onServicesDiscovered") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onServicesDiscovered") {
@Override
public PromiseResult onServicesDiscovered(BluetoothGatt gatt) {
return callback.apply(gatt);
@@ -73,7 +118,7 @@ public class BtPromise {
}
public synchronized BtPromise onCharacteristicRead(F2<BluetoothGatt, BluetoothGattCharacteristic, PromiseResult> callback) {
- actionQ.add(new BtCallback("onCharacteristicRead") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onCharacteristicRead") {
@Override
public PromiseResult onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
return callback.apply(gatt, characteristic);
@@ -83,7 +128,7 @@ public class BtPromise {
}
public synchronized BtPromise onCharacteristicWrite(F2<BluetoothGatt, BluetoothGattCharacteristic, PromiseResult> callback) {
- actionQ.add(new BtCallback("onCharacteristicWrite") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onCharacteristicWrite") {
@Override
public PromiseResult onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
return callback.apply(gatt, characteristic);
@@ -93,7 +138,7 @@ public class BtPromise {
}
public synchronized BtPromise onCharacteristicChanged(F2<BluetoothGatt, BluetoothGattCharacteristic, PromiseResult> callback) {
- actionQ.add(new BtCallback("onCharacteristicChanged") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onCharacteristicChanged") {
@Override
public PromiseResult onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
return callback.apply(gatt, characteristic);
@@ -103,7 +148,7 @@ public class BtPromise {
}
public synchronized BtPromise onDescriptorRead(F2<BluetoothGatt, BluetoothGattDescriptor, PromiseResult> callback) {
- actionQ.add(new BtCallback("onDescriptorRead") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onDescriptorRead") {
@Override
public PromiseResult onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor) {
return callback.apply(gatt, descriptor);
@@ -113,7 +158,7 @@ public class BtPromise {
}
public synchronized BtPromise onDescriptorWrite(F2<BluetoothGatt, BluetoothGattDescriptor, PromiseResult> callback) {
- actionQ.add(new BtCallback("onDescriptorWrite") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onDescriptorWrite") {
@Override
public PromiseResult onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor) {
return callback.apply(gatt, descriptor);
@@ -123,7 +168,7 @@ public class BtPromise {
}
public synchronized BtPromise onReliableWriteCompleted(Function<BluetoothGatt, PromiseResult> callback) {
- actionQ.add(new BtCallback("onReliableWriteCompleted") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onReliableWriteCompleted") {
@Override
public PromiseResult onReliableWriteCompleted(BluetoothGatt gatt) {
return callback.apply(gatt);
@@ -133,7 +178,7 @@ public class BtPromise {
}
public synchronized BtPromise onReadRemoteRssi(F2<BluetoothGatt, Integer, PromiseResult> callback) {
- actionQ.add(new BtCallback("onReadRemoteRssi") {
+ actionQ.add(new BtCallback(stopOnFailure(), "onReadRemoteRssi") {
@Override
public PromiseResult onReadRemoteRssi(BluetoothGatt gatt, int rssi) {
return callback.apply(gatt, rssi);
@@ -142,8 +187,18 @@ public class BtPromise {
return this;
}
+ public synchronized BtPromise onDirect(Function<Object, PromiseResult> callback) {
+ actionQ.add(new BtCallback(stopOnFailure(), "onDirect") {
+ @Override
+ public PromiseResult onDirect(Object value) {
+ return callback.apply(value);
+ }
+ });
+ return this;
+ }
+
public synchronized BtPromise onFailure(Runnable callback) {
- failureQ.add(new BtCallback("onFailure") {
+ failureQ.add(new BtCallback(stopOnFailure(), "onFailure") {
@Override
public void onFailure() {
callback.run();
@@ -153,7 +208,7 @@ public class BtPromise {
}
public synchronized BtPromise onFinally(Runnable callback) {
- finallyQ.add(new BtCallback("finally") {
+ finallyQ.add(new BtCallback(stopOnFailure(), "finally") {
@Override
public void onFinally() {
callback.run();
@@ -180,12 +235,8 @@ public class BtPromise {
return s.toString();
}
- BtBluetoothGattCallback asCallback() {
- return new BtBluetoothGattCallback(actionQ, failureQ, finallyQ);
- }
-
- public PromiseResult toDetour() {
- return new Detour(this);
+ BtBluetoothGattCallback asCallback(String address) {
+ return new BtBluetoothGattCallback(address, actionQ, failureQ, finallyQ);
}
enum EventType {
@@ -200,16 +251,18 @@ public class BtPromise {
onReadRemoteRssi,
+ onDirect,
onFailure,
onFinally,
}
private static PromiseResult callCallback(EventType key, BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
- BluetoothGattDescriptor descriptor, int newState, BtCallback btCallback) {
+ BluetoothGattDescriptor descriptor, int status, int newState,
+ BtCallback btCallback, Object value) {
switch (key) {
case onConnectionStateChange:
- return btCallback.onConnectionStateChange(gatt, newState);
+ return btCallback.onConnectionStateChange(gatt, status, newState);
case onServicesDiscovered:
return btCallback.onServicesDiscovered(gatt);
case onCharacteristicRead:
@@ -225,6 +278,8 @@ public class BtPromise {
case onReliableWriteCompleted:
return btCallback.onReliableWriteCompleted(gatt);
+ case onDirect:
+ return btCallback.onDirect(value);
case onFailure:
btCallback.onFailure();
return null;
@@ -239,23 +294,27 @@ public class BtPromise {
static class BtBluetoothGattCallback extends BluetoothGattCallback {
- private ArrayDeque<BtCallback> actionQ;
+ private final String address;
+ private List<BtCallback> actionQ;
+ private ListIterator<BtCallback> it;
private ArrayDeque<BtCallback> failureQ;
ArrayDeque<BtCallback> finallyQ;
-// private ArrayDeque<BtCallback> initialActionQ;
private List<String> events = new ArrayList<>();
- private BtBluetoothGattCallback(Queue<BtCallback> actionQ, Queue<BtCallback> failureQ, Queue<BtCallback> finallyQ) {
- this.actionQ = new ArrayDeque<>(actionQ);
+ private BtBluetoothGattCallback(String address, List<BtCallback> actionQ, Queue<BtCallback> failureQ, Queue<BtCallback> finallyQ) {
+ this.address = address;
+ this.actionQ = new ArrayList<>(actionQ);
this.failureQ = new ArrayDeque<>(failureQ);
this.finallyQ = new ArrayDeque<>(finallyQ);
+ this.it = actionQ.listIterator();
}
- void onEvent(EventType key, String values, BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, BluetoothGattDescriptor descriptor, int status, int newState) {
+ void onEvent(EventType key, String values, BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
+ BluetoothGattDescriptor descriptor, int status, int newState, Object value) {
boolean success = status == BluetoothGatt.GATT_SUCCESS;
events.add(key + "(" + values + "), success=" + success);
- Log.i(TAG, key + "(" + values + "), success=" + success);
+ Log.i(TAG, "event: " + key + "(" + values + "), success=" + success);
if (!success) {
doFailure();
@@ -264,31 +323,33 @@ public class BtPromise {
BtCallback btCallback;
synchronized (this) {
- if (actionQ.isEmpty()) {
+ if (!it.hasNext()) {
Log.d(TAG, "All Bluetooth actions are done");
doFinally();
return;
}
+ btCallback = it.next();
+ Log.i(TAG, "Executing bt action: " + btCallback.name);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
- btCallback = actionQ.remove();
- Log.i(TAG, "Executing bt action: " + btCallback.name);
}
try {
- PromiseResult result = callCallback(key, gatt, characteristic, descriptor, newState, btCallback);
+ PromiseResult result = callCallback(key, gatt, characteristic, descriptor, status, newState, btCallback,
+ value);
- if (result instanceof Done) {
- Log.i(TAG, "The chain is done.");
+ if (result instanceof Stop) {
+ Log.i(TAG, "The chain want to stop.");
doFinally();
} else if (result instanceof Detour) {
Log.i(TAG, "Adding detour");
BtPromise promise = ((Detour) result).promise;
+ events.add("detour " + promise.actionQ.size());
if (!promise.failureQ.isEmpty()) {
Log.i(TAG, "Ignoring " + promise.failureQ.size() + " items from the failure Q");
}
@@ -296,12 +357,19 @@ public class BtPromise {
Log.i(TAG, "Ignoring " + promise.finallyQ.size() + " items from the finally Q");
}
- for (BtCallback callback : promise.actionQ) {
- actionQ.addFirst(callback);
+ synchronized (this) {
+ for (BtCallback cb : promise.actionQ) {
+ it.add(cb);
+ }
}
+ } else if (result instanceof ContinueDirectly) {
+ value = ((ContinueDirectly) result).value;
+ onEvent(onDirect, "value=" + value, null, null, null, BluetoothGatt.GATT_SUCCESS, 0,
+ value);
+ return;
}
- if (actionQ.isEmpty()) {
+ if (!it.hasNext()) {
Log.i(TAG, "The queue is empty");
}
} catch (NotOverriddenException e) {
@@ -313,14 +381,15 @@ public class BtPromise {
private void doFailure() {
StringBuilder msg = new StringBuilder();
+ msg.append("Address: ").append(address).append("\n");
msg.append("Expected events: \n");
for (BtCallback cb : actionQ) {
- msg.append(" ").append(cb.name).append("\n");
+ msg.append("- ").append(cb.name).append("\n");
}
msg.append("Actual events: \n");
for (String event : events) {
- msg.append(" ").append(event).append("\n");
+ msg.append("- ").append(event).append("\n");
}
Log.w(TAG, msg.toString());
@@ -329,7 +398,7 @@ public class BtPromise {
for (BtCallback callback = failureQ.poll(); callback != null; callback = failureQ.poll()) {
try {
- callCallback(onFailure, null, null, null, 0, callback);
+ callCallback(onFailure, null, null, null, 0, 0, callback, null);
} catch (NotOverriddenException e) {
return;
}
@@ -345,7 +414,7 @@ public class BtPromise {
for (BtCallback callback = finallyQ.poll(); callback != null; callback = finallyQ.poll()) {
try {
- callCallback(onFinally, null, null, null, 0, callback);
+ callCallback(onFinally, null, null, null, 0, 0, callback, null);
} catch (NotOverriddenException e) {
return;
}
@@ -358,42 +427,42 @@ public class BtPromise {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
- onEvent(onConnectionStateChange, "status=" + status + ", newState=" + newState, gatt, null, null, status, newState);
+ onEvent(onConnectionStateChange, "status=" + status + ", newState=" + newState, gatt, null, null, status, newState, null);
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
- onEvent(onServicesDiscovered, "status=" + status, gatt, null, null, status, 9);
+ onEvent(onServicesDiscovered, "status=" + status, gatt, null, null, status, 9, null);
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
- onEvent(onCharacteristicRead, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0);
+ onEvent(onCharacteristicRead, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0, null);
}
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
- onEvent(onCharacteristicWrite, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0);
+ onEvent(onCharacteristicWrite, "status=" + status + ", characteristic=" + characteristic.getUuid(), gatt, characteristic, null, status, 0, null);
}
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
- onEvent(onCharacteristicChanged, "characteristic=" + characteristic.getUuid(), gatt, characteristic, null, BluetoothGatt.GATT_SUCCESS, 0);
+ onEvent(onCharacteristicChanged, "characteristic=" + characteristic.getUuid(), gatt, characteristic, null, BluetoothGatt.GATT_SUCCESS, 0, null);
}
@Override
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
- onEvent(onDescriptorRead, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0);
+ onEvent(onDescriptorRead, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0, null);
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
- onEvent(onDescriptorWrite, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0);
+ onEvent(onDescriptorWrite, "status=" + status + ", descriptor=" + descriptor.getUuid(), gatt, null, descriptor, status, 0, null);
}
@Override
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
- onEvent(onReliableWriteCompleted, "status=" + status, gatt, null, null, status, 0);
+ onEvent(onReliableWriteCompleted, "status=" + status, gatt, null, null, status, 0, null);
}
@Override
diff --git a/app/src/main/java/io/trygvis/android/bt/BtService.java b/app/src/main/java/io/trygvis/android/bt/BtService.java
index fb11027..ff2c68c 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtService.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtService.java
@@ -33,7 +33,7 @@ public interface BtService<A extends BtDevice.BtDeviceWrapper<A>> {
<T> T runTx(Function<SQLiteDatabase, T> action);
public static interface BtDbIntegration<A extends BtDevice.BtDeviceWrapper<A>> {
- A createTag(BtDevice<A> a);
+ A createTag(SQLiteDatabase db, BtDevice<A> a);
}
public static class BtServiceListenerBroadcastReceiver extends BroadcastReceiver {
diff --git a/app/src/main/java/io/trygvis/android/bt/DefaultBtService.java b/app/src/main/java/io/trygvis/android/bt/DefaultBtService.java
index 80a195a..cc7d484 100644
--- a/app/src/main/java/io/trygvis/android/bt/DefaultBtService.java
+++ b/app/src/main/java/io/trygvis/android/bt/DefaultBtService.java
@@ -289,7 +289,7 @@ public class DefaultBtService<A extends BtDevice.BtDeviceWrapper<A>> extends Ser
Log.i(TAG, "New device: " + address + ", seenBefore=" + seenBefore);
cursor.close();
- return new BtDevice<>(this, bluetoothDevice, btDbIntegration, id, rssi, scanResult,
+ return new BtDevice<>(this, bluetoothDevice, db, btDbIntegration, id, rssi, scanResult,
seenBefore, firstSeen, lastSeen);
});
diff --git a/app/src/main/java/io/trygvis/android/bt/WrappingBluetoothGattCallback.java b/app/src/main/java/io/trygvis/android/bt/WrappingBluetoothGattCallback.java
new file mode 100644
index 0000000..8d790d1
--- /dev/null
+++ b/app/src/main/java/io/trygvis/android/bt/WrappingBluetoothGattCallback.java
@@ -0,0 +1,60 @@
+package io.trygvis.android.bt;
+
+import android.bluetooth.BluetoothGatt;
+import android.bluetooth.BluetoothGattCallback;
+import android.bluetooth.BluetoothGattCharacteristic;
+import android.bluetooth.BluetoothGattDescriptor;
+
+class WrappingBluetoothGattCallback extends BluetoothGattCallback {
+
+ private final BluetoothGattCallback wrapped;
+
+ public WrappingBluetoothGattCallback(BluetoothGattCallback wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ wrapped.onConnectionStateChange(gatt, status, newState);
+ }
+
+ @Override
+ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+ wrapped.onServicesDiscovered(gatt, status);
+ }
+
+ @Override
+ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
+ wrapped.onCharacteristicRead(gatt, characteristic, status);
+ }
+
+ @Override
+ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
+ wrapped.onCharacteristicWrite(gatt, characteristic, status);
+ }
+
+ @Override
+ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
+ wrapped.onCharacteristicChanged(gatt, characteristic);
+ }
+
+ @Override
+ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
+ wrapped.onDescriptorRead(gatt, descriptor, status);
+ }
+
+ @Override
+ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
+ wrapped.onDescriptorWrite(gatt, descriptor, status);
+ }
+
+ @Override
+ public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
+ wrapped.onReliableWriteCompleted(gatt, status);
+ }
+
+ @Override
+ public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
+ wrapped.onReadRemoteRssi(gatt, rssi, status);
+ }
+}