mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-23 08:34:20 +01:00
Bug fixed: #33
This commit is contained in:
@@ -516,7 +516,7 @@ public abstract class BleManager<E extends BleManagerCallbacks> implements ILogg
|
||||
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
Logger.v(mLogSession, "Enabling notifications for " + characteristic.getUuid());
|
||||
Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x01-00)");
|
||||
return gatt.writeDescriptor(descriptor);
|
||||
return internalWriteDescriptorWorkaround(descriptor);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ public abstract class BleManager<E extends BleManagerCallbacks> implements ILogg
|
||||
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
|
||||
Logger.v(mLogSession, "Enabling indications for " + characteristic.getUuid());
|
||||
Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x02-00)");
|
||||
return gatt.writeDescriptor(descriptor);
|
||||
return internalWriteDescriptorWorkaround(descriptor);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -639,14 +639,7 @@ public abstract class BleManager<E extends BleManagerCallbacks> implements ILogg
|
||||
|
||||
Logger.v(mLogSession, "Writing descriptor " + descriptor.getUuid());
|
||||
Logger.d(mLogSession, "gatt.writeDescriptor(" + descriptor.getUuid() + ")");
|
||||
// There was a bug in Android up to 6.0 where the descriptor was written using parent characteristic write type, instead of always Write With Response,
|
||||
// as the spec says.
|
||||
final BluetoothGattCharacteristic parentCharacteristic = descriptor.getCharacteristic();
|
||||
final int originalWriteType = parentCharacteristic.getWriteType();
|
||||
parentCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
|
||||
final boolean result = gatt.writeDescriptor(descriptor);
|
||||
parentCharacteristic.setWriteType(originalWriteType);
|
||||
return result;
|
||||
return internalWriteDescriptorWorkaround(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -726,11 +719,30 @@ public abstract class BleManager<E extends BleManagerCallbacks> implements ILogg
|
||||
Logger.v(mLogSession, "Disabling notifications for " + BATTERY_LEVEL_CHARACTERISTIC);
|
||||
Logger.d(mLogSession, "gatt.writeDescriptor(" + CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID + ", value=0x0000)");
|
||||
}
|
||||
return gatt.writeDescriptor(descriptor);
|
||||
return internalWriteDescriptorWorkaround(descriptor);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* There was a bug in Android up to 6.0 where the descriptor was written using parent
|
||||
* characteristic's write type, instead of always Write With Response, as the spec says.
|
||||
* @param descriptor the descriptor to be written
|
||||
* @return the result of {@link BluetoothGatt#writeDescriptor(BluetoothGattDescriptor)}
|
||||
*/
|
||||
private boolean internalWriteDescriptorWorkaround(final BluetoothGattDescriptor descriptor) {
|
||||
final BluetoothGatt gatt = mBluetoothGatt;
|
||||
if (gatt == null || descriptor == null)
|
||||
return false;
|
||||
|
||||
final BluetoothGattCharacteristic parentCharacteristic = descriptor.getCharacteristic();
|
||||
final int originalWriteType = parentCharacteristic.getWriteType();
|
||||
parentCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
|
||||
final boolean result = gatt.writeDescriptor(descriptor);
|
||||
parentCharacteristic.setWriteType(originalWriteType);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues a new request. The request will be handled immediately if there is no operation in progress,
|
||||
* or automatically after the last enqueued one will finish.
|
||||
|
||||
Reference in New Issue
Block a user