Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Commit aed4af5

Browse files
committed
Bluetooth logs: make them slightly more readable.
1 parent 333f795 commit aed4af5

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/main/java/de/dennisguse/opentracks/sensors/BluetoothConnectionManager.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,23 @@ public class BluetoothConnectionManager {
4747

4848
private final SensorHandlerInterface sensorHandler;
4949
private BluetoothGatt bluetoothGatt;
50-
5150
private final BluetoothGattCallback connectCallback = new BluetoothGattCallback() {
5251
@Override
5352
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
5453
switch (newState) {
5554
case BluetoothProfile.STATE_CONNECTING ->
56-
Log.i(TAG, "Connecting to sensor: " + gatt.getDevice());
55+
Log.i(TAG, gatt.getDevice() + ": connecting to sensor");
5756
case BluetoothProfile.STATE_CONNECTED -> {
58-
Log.i(TAG, "Connected to sensor: " + gatt.getDevice() + "; discovering services.");
57+
Log.i(TAG, gatt.getDevice() + ": connected to sensor; discovering services");
5958
gatt.discoverServices();
6059
}
6160
case BluetoothProfile.STATE_DISCONNECTING ->
62-
Log.i(TAG, "Disconnecting from sensor: " + gatt.getDevice());
61+
Log.i(TAG, gatt.getDevice() + ": disconnecting from sensor: ");
6362
case BluetoothProfile.STATE_DISCONNECTED -> {
6463
//This is also triggered, if no connection was established (ca. 30s)
65-
Log.i(TAG, "Disconnected from sensor: " + gatt.getDevice() + "; trying to reconnect");
64+
Log.i(TAG, gatt.getDevice() + ": disconnected from sensor: trying to reconnect");
6665
if (gatt.connect()) {
67-
Log.e(TAG, "Could not trigger reconnect for sensor: " + gatt.getDevice());
66+
Log.e(TAG, gatt.getDevice() + ": could not trigger reconnect for sensor");
6867
}
6968
clearData();
7069
}
@@ -84,13 +83,13 @@ public void onServicesDiscovered(@NonNull BluetoothGatt gatt, int status) {
8483
}
8584

8685
if (gattService == null) {
87-
Log.e(TAG, "Could not get gattService for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement);
86+
Log.e(TAG, gatt.getDevice() + ": could not get gattService for serviceUUID=" + serviceMeasurement);
8887
return;
8988
}
9089

9190
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(serviceMeasurement.measurementUUID());
9291
if (characteristic == null) {
93-
Log.e(TAG, "Could not get BluetoothCharacteristic for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement.serviceUUID() + " characteristicUUID=" + serviceMeasurement.measurementUUID());
92+
Log.e(TAG, gatt.getDevice() + ": could not get BluetoothCharacteristic for serviceUUID=" + serviceMeasurement.serviceUUID() + " characteristicUUID=" + serviceMeasurement.measurementUUID());
9493
return;
9594
}
9695
gatt.setCharacteristicNotification(characteristic, true);
@@ -110,13 +109,14 @@ public void onServicesDiscovered(@NonNull BluetoothGatt gatt, int status) {
110109
@Override
111110
public void onCharacteristicChanged(BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic) {
112111
UUID serviceUUID = characteristic.getService().getUuid();
113-
Log.d(TAG, "Received data from " + gatt.getDevice().getAddress() + " with service " + serviceUUID + " and characteristics " + characteristic.getUuid());
112+
BluetoothDevice device = gatt.getDevice();
113+
Log.d(TAG, device + ": Received data with service " + serviceUUID + " and characteristics " + characteristic.getUuid());
114114
Optional<ServiceMeasurementUUID> serviceMeasurementUUID = sensorHandler.getServices()
115115
.stream()
116116
.filter(s -> s.serviceUUID().equals(characteristic.getService().getUuid()))
117117
.findFirst();
118118
if (serviceMeasurementUUID.isEmpty()) {
119-
Log.e(TAG, "Unknown service UUID; not supported?");
119+
Log.e(TAG, device + ": Unknown service UUID; not supported?");
120120
return;
121121
}
122122

@@ -135,7 +135,7 @@ synchronized void connect(Context context, Handler handler, @NonNull BluetoothDe
135135
return;
136136
}
137137

138-
Log.d(TAG, "Connecting to: " + device);
138+
Log.d(TAG, device + ": trying to connect");
139139

140140
bluetoothGatt = device.connectGatt(context, false, connectCallback, BluetoothDevice.TRANSPORT_AUTO, 0, handler);
141141

@@ -148,11 +148,13 @@ private synchronized void clearData() {
148148

149149
synchronized void disconnect() {
150150
if (bluetoothGatt == null) {
151-
Log.w(TAG, "Cannot disconnect if not connected.");
152151
return;
153152
}
153+
Log.i(TAG, bluetoothGatt.getDevice() + ": start disconnect");
154+
bluetoothGatt.disconnect();
154155
bluetoothGatt.close();
155156
clearData();
157+
Log.i(TAG, bluetoothGatt.getDevice() + ": disconnect finished");
156158
bluetoothGatt = null;
157159
}
158160

src/main/java/de/dennisguse/opentracks/sensors/sensorData/SensorDataSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void reset() {
188188
}
189189

190190
private void set(@NonNull Aggregator<?, ?> type, @Nullable Aggregator<?, ?> sensorData) {
191-
Log.i(TAG, "Setting aggregator " + type.getClass().getCanonicalName());
191+
Log.i(TAG, "Setting aggregator " + type.getClass().getCanonicalName() + " to " + sensorData);
192192

193193
if (type instanceof AggregatorHeartRate) {
194194
heartRate = (AggregatorHeartRate) sensorData;

src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public boolean newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontal
255255

256256
@Override
257257
public void newGpsStatus(GpsStatusValue gpsStatusValue) {
258-
Log.e(TAG, "newGpsStatus: " + gpsStatusValue.message);
258+
Log.i(TAG, "newGpsStatus: " + gpsStatusValue.message);
259259

260260
if (notificationManager == null) {
261261

0 commit comments

Comments
 (0)