1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-12 13:09:24 +01:00

Add creation timestamps to BtLEActions and transactions in debug output

(I think I still sometimes get "old" notifications)
This commit is contained in:
cpfeiffer 2015-07-03 21:58:13 +02:00
parent 78c0f2797d
commit 580b86f41b
4 changed files with 22 additions and 3 deletions

View File

@ -3,6 +3,9 @@ package nodomain.freeyourgadget.gadgetbridge.btle;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import java.text.DateFormat;
import java.util.Date;
/**
* The Bluedroid implementation only allows performing one GATT request at a time.
* As they are asynchronous anyway, we encapsulate every GATT request (read and write)
@ -13,9 +16,11 @@ import android.bluetooth.BluetoothGattCharacteristic;
*/
public abstract class BtLEAction {
private final BluetoothGattCharacteristic characteristic;
private final long creationTimestamp;
public BtLEAction(BluetoothGattCharacteristic characteristic) {
this.characteristic = characteristic;
creationTimestamp = System.currentTimeMillis();
}
/**
@ -44,9 +49,13 @@ public abstract class BtLEAction {
return characteristic;
}
protected String getCreationTime() {
return DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(creationTimestamp));
}
public String toString() {
BluetoothGattCharacteristic characteristic = getCharacteristic();
String uuid = characteristic == null ? "(null)" : characteristic.getUuid().toString();
return getClass().getSimpleName() + " on characteristic: " + uuid;
return getCreationTime() + ": " + getClass().getSimpleName() + " on characteristic: " + uuid;
}
}

View File

@ -71,6 +71,9 @@ public final class BtLEQueue {
for (BtLEAction action : transaction.getActions()) {
mWaitCharacteristic = action.getCharacteristic();
mWaitForActionResultLatch = new CountDownLatch(1);
if (LOG.isDebugEnabled()) {
LOG.debug("About to run action: " + action);
}
if (action.run(mBluetoothGatt)) {
// check again, maybe due to some condition, action did not need to write, so we can't wait
boolean waitForResult = action.expectsResult();

View File

@ -32,6 +32,6 @@ public class SetDeviceBusyAction extends PlainAction {
@Override
public String toString() {
return getClass().getName() + ": " + busyTask;
return getCreationTime() + ": " + getClass().getName() + ": " + busyTask;
}
}

View File

@ -1,7 +1,9 @@
package nodomain.freeyourgadget.gadgetbridge.btle;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -14,6 +16,7 @@ import java.util.Locale;
public class Transaction {
private String mName;
private List<BtLEAction> mActions = new ArrayList<>(4);
private long creationTimestamp = System.currentTimeMillis();
public Transaction(String taskName) {
this.mName = taskName;
@ -35,8 +38,12 @@ public class Transaction {
return mActions.isEmpty();
}
protected String getCreationTime() {
return DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(creationTimestamp));
}
@Override
public String toString() {
return String.format(Locale.US, "Transaction task: %s with %d actions", getTaskName(), mActions.size());
return String.format(Locale.US, "%s: Transaction task: %s with %d actions", getCreationTime(), getTaskName(), mActions.size());
}
}