forked from upstream-mirrors/OpenTracks
+8
-2
@@ -69,6 +69,8 @@ public abstract class BluetoothConnectionManager<DataType> {
|
|||||||
|
|
||||||
case BluetoothProfile.STATE_DISCONNECTED:
|
case BluetoothProfile.STATE_DISCONNECTED:
|
||||||
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
|
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
|
||||||
|
|
||||||
|
clearData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,14 +132,18 @@ public abstract class BluetoothConnectionManager<DataType> {
|
|||||||
observer.onChanged(sensorData);
|
observer.onChanged(sensorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void clearData() {
|
||||||
|
observer.onDisconnecting(createEmptySensorData(bluetoothGatt.getDevice().getAddress()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
synchronized void disconnect() {
|
synchronized void disconnect() {
|
||||||
if (bluetoothGatt == null) {
|
if (bluetoothGatt == null) {
|
||||||
Log.w(TAG, "Cannot disconnect if not connected.");
|
Log.w(TAG, "Cannot disconnect if not connected.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bluetoothGatt.close();
|
bluetoothGatt.close();
|
||||||
observer.onDisconnecting(createEmptySensorData(bluetoothGatt.getDevice().getAddress()));
|
clearData();
|
||||||
|
|
||||||
bluetoothGatt = null;
|
bluetoothGatt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user