Skip to content

Commit

Permalink
Don't log written data, as they may not be up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Nov 28, 2022
1 parent aadc47d commit 11ad316
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2334,17 +2334,18 @@ public void onCharacteristicRead(@NonNull final BluetoothGatt gatt,
public void onCharacteristicWrite(final BluetoothGatt gatt,
final BluetoothGattCharacteristic characteristic,
final int status) {
final byte[] data = characteristic.getValue();

if (status == BluetoothGatt.GATT_SUCCESS) {
log(Log.INFO, () ->
"Data written to " + characteristic.getUuid() +
", value: " + ParserUtils.parse(data));
// When writing without response, the characteristic value is not updated on Android 13+.
// The data written was logged out when the request was executed.
log(Log.INFO, () -> "Data written to " + characteristic.getUuid());

BleManagerHandler.this.onCharacteristicWrite(gatt, characteristic);
if (request instanceof WriteRequest) {
final WriteRequest wr = (WriteRequest) request;
final boolean valid = wr.notifyPacketSent(gatt.getDevice(), data);
// Notify the listeners about the packet being sent.
// This method also compares the data written with the data received in the callback
// if the write type is WRITE_TYPE_DEFAULT.
final boolean valid = wr.notifyPacketSent(gatt.getDevice(), characteristic.getValue());
if (!valid && requestQueue instanceof ReliableWriteRequest) {
wr.notifyFail(gatt.getDevice(), FailCallback.REASON_VALIDATION);
requestQueue.cancelQueue();
Expand Down Expand Up @@ -2451,8 +2452,7 @@ public void onDescriptorWrite(final BluetoothGatt gatt,
final byte[] data = descriptor.getValue();

if (status == BluetoothGatt.GATT_SUCCESS) {
log(Log.INFO, () -> "Data written to descr. " + descriptor.getUuid() +
", value: " + ParserUtils.parse(data));
log(Log.INFO, () -> "Data written to descr. " + descriptor.getUuid());

if (isServiceChangedCCCD(descriptor)) {
log(Log.INFO, () -> "Service Changed notifications enabled");
Expand Down

0 comments on commit 11ad316

Please sign in to comment.