下面列出了android.bluetooth.BluetoothGatt#GATT_INSUFFICIENT_AUTHENTICATION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic wrote " + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Wrote a characteristic successfully " + characteristic.getUuid());
if (mAuthenticationCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_authSucess = true;
gatt.readCharacteristic(mHeartBeatCharacteristic);
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: oncharacteristicwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing Characteristic");
}
}
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic wrote " + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Wrote a characteristic successfully " + characteristic.getUuid());
if (mAuthenticationCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_authSucess = true;
mBluetoothGatt.readCharacteristic(mHeartBeatCharacteristic);
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug?");
}
} else {
Log.e(TAG, "Unknown error writing Characteristic");
}
}
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic wrote " + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Wrote a characteristic successfully " + characteristic.getUuid());
if (mAuthenticationCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_authSucess = true;
gatt.readCharacteristic(mHeartBeatCharacteristic);
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: oncharacteristicwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing Characteristic");
}
}
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic wrote " + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Wrote a characteristic successfully " + characteristic.getUuid());
if (mAuthenticationCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_authSucess = true;
gatt.readCharacteristic(mHeartBeatCharacteristic);
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: oncharacteristicwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing Characteristic");
}
}
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic wrote " + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "Wrote a characteristic successfully " + characteristic.getUuid());
if (mAuthenticationCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_authSucess = true;
gatt.readCharacteristic(mHeartBeatCharacteristic);
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to");
}
} else {
Log.e(TAG, "Unknown error writing Characteristic");
}
}
@Override
public final void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
if (isBatteryLevelCharacteristic(characteristic)) {
final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
BleManager.this.batteryValue = batteryValue;
profile.onBatteryValueReceived(gatt, batteryValue);
} else {
// The value has been read. Notify the profile and proceed with the initialization queue.
profile.onCharacteristicRead(gatt, characteristic);
}
operationInProgress = false;
nextRequest();
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onCharacteristicRead error " + status);
onError(gatt.getDevice(), ERROR_READ_CHARACTERISTIC, status);
}
}
@Override
public final void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// The value has been written. Notify the profile and proceed with the initialization queue.
profile.onCharacteristicWrite(gatt, characteristic);
operationInProgress = false;
nextRequest();
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onCharacteristicWrite error " + status);
onError(gatt.getDevice(), ERROR_WRITE_CHARACTERISTIC, status);
}
}
@Override
public void onDescriptorRead(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// The value has been read. Notify the profile and proceed with the initialization queue.
profile.onDescriptorRead(gatt, descriptor);
operationInProgress = false;
nextRequest();
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onDescriptorRead error " + status);
onError(gatt.getDevice(), ERROR_READ_DESCRIPTOR, status);
}
}
@Override
public final void onDescriptorWrite(final BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// The value has been written. Notify the profile and proceed with the initialization queue.
profile.onDescriptorWrite(gatt, descriptor);
operationInProgress = false;
nextRequest();
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status);
}
} else {
DebugLogger.e(TAG, "onDescriptorWrite error " + status);
onError(gatt.getDevice(), ERROR_WRITE_DESCRIPTOR, status);
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug?");
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: ondescriptorwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: ondescriptorwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: ondescriptorwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to: ondescriptorwrite code: "+status+ "bond: "+gatt.getDevice().getBondState());
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
public static String getGattStatus(int status) {
switch (status) {
case BluetoothGatt.GATT_SUCCESS:
return "GATT_SUCCESS";
case BluetoothGatt.GATT_READ_NOT_PERMITTED:
return "GATT_READ_NOT_PERMITTED";
case BluetoothGatt.GATT_WRITE_NOT_PERMITTED:
return "GATT_WRITE_NOT_PERMITTED";
case BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION:
return "GATT_INSUFFICIENT_AUTHENTICATION";
case BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED:
return "GATT_REQUEST_NOT_SUPPORTED";
case BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION:
return "GATT_INSUFFICIENT_ENCRYPTION";
case BluetoothGatt.GATT_INVALID_OFFSET:
return "GATT_INVALID_OFFSET";
case BluetoothGatt.GATT_INVALID_ATTRIBUTE_LENGTH:
return "GATT_INVALID_ATTRIBUTE_LENGTH";
case BluetoothGatt.GATT_FAILURE:
return "GATT_FAILURE";
default:
return "STATE_UNKNOWN: " + status;
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
Log.d(TAG, "Characteristic onDescriptorWrite ch " + characteristic.getUuid());
if(mHeartBeatCharacteristic.getUuid().equals(characteristic.getUuid())) {
state_notifSetupSucess = true;
setCharacteristicIndication(mReceiveDataCharacteristic);
}
if(mReceiveDataCharacteristic.getUuid().equals(characteristic.getUuid())) {
setCharacteristicIndication(mResponseCharacteristic);
}
if(mResponseCharacteristic.getUuid().equals(characteristic.getUuid())) {
attemptRead();
}
} else if ((status & BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) != 0 || (status & BluetoothGatt.GATT_INSUFFICIENT_ENCRYPTION) != 0) {
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_NONE) {
device = gatt.getDevice();
state_authInProgress = true;
bondDevice();
} else {
Log.e(TAG, "The phone is trying to read from paired device without encryption. Android Bug? Have the dexcom forget whatever device it was previously paired to");
}
} else {
Log.e(TAG, "Unknown error writing descriptor");
}
}
protected boolean acknowledgeCallback(int status)
{
//--- DRK > As of now, on the nexus 7, if a write requires authentication, it kicks off a bonding process
//--- and we don't get a callback for the write (android bug), so we let this write task be interruptible
//--- by an implicit bond task. If on other devices we *do* get a callback, we ignore it so that this
//--- library's logic always follows the lowest common denominator that is the nexus 7.
//--- NOTE: Also happens with tab 4, same thing as nexus 7.
if( status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION || status == BleStatuses.GATT_AUTH_FAIL )
{
return false;
}
return true;
}
@Override
public void onCharacteristicRead(final BluetoothGatt gatt,
final BluetoothGattCharacteristic characteristic,
final int status) {
final byte[] data = characteristic.getValue();
if (status == BluetoothGatt.GATT_SUCCESS) {
log(Log.INFO, "Read Response received from " + characteristic.getUuid() +
", value: " + ParserUtils.parse(data));
BleManagerHandler.this.onCharacteristicRead(gatt, characteristic);
if (request instanceof ReadRequest) {
final ReadRequest rr = (ReadRequest) request;
final boolean matches = rr.matches(data);
if (matches) {
rr.notifyValueChanged(gatt.getDevice(), data);
}
if (!matches || rr.hasMore()) {
enqueueFirst(rr);
} else {
rr.notifySuccess(gatt.getDevice());
}
}
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION
|| status == 8 /* GATT INSUF AUTHORIZATION */
|| status == 137 /* GATT AUTH FAIL */) {
log(Log.WARN, "Authentication required (" + status + ")");
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
Log.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
postCallback(c -> c.onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status));
}
// The request will be repeated when the bond state changes to BONDED.
return;
} else {
Log.e(TAG, "onCharacteristicRead error " + status);
if (request instanceof ReadRequest) {
request.notifyFail(gatt.getDevice(), status);
}
awaitingRequest = null;
onError(gatt.getDevice(), ERROR_READ_CHARACTERISTIC, status);
}
checkCondition();
nextRequest(true);
}
@Override
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));
BleManagerHandler.this.onCharacteristicWrite(gatt, characteristic);
if (request instanceof WriteRequest) {
final WriteRequest wr = (WriteRequest) request;
final boolean valid = wr.notifyPacketSent(gatt.getDevice(), data);
if (!valid && requestQueue instanceof ReliableWriteRequest) {
wr.notifyFail(gatt.getDevice(), FailCallback.REASON_VALIDATION);
requestQueue.cancelQueue();
} else if (wr.hasMore()) {
enqueueFirst(wr);
} else {
wr.notifySuccess(gatt.getDevice());
}
}
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION
|| status == 8 /* GATT INSUF AUTHORIZATION */
|| status == 137 /* GATT AUTH FAIL */) {
log(Log.WARN, "Authentication required (" + status + ")");
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
Log.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
postCallback(c -> c.onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status));
}
// The request will be repeated when the bond state changes to BONDED.
return;
} else {
Log.e(TAG, "onCharacteristicWrite error " + status);
if (request instanceof WriteRequest) {
request.notifyFail(gatt.getDevice(), status);
// Automatically abort Reliable Write when write error happen
if (requestQueue instanceof ReliableWriteRequest)
requestQueue.cancelQueue();
}
awaitingRequest = null;
onError(gatt.getDevice(), ERROR_WRITE_CHARACTERISTIC, status);
}
checkCondition();
nextRequest(true);
}
@Override
public void onDescriptorWrite(final BluetoothGatt gatt,
final BluetoothGattDescriptor descriptor,
final int status) {
final byte[] data = descriptor.getValue();
if (status == BluetoothGatt.GATT_SUCCESS) {
log(Log.INFO, "Data written to descr. " + descriptor.getUuid() +
", value: " + ParserUtils.parse(data));
if (isServiceChangedCCCD(descriptor)) {
log(Log.INFO, "Service Changed notifications enabled");
} else if (isCCCD(descriptor)) {
if (data != null && data.length == 2 && data[1] == 0x00) {
switch (data[0]) {
case 0x00:
log(Log.INFO, "Notifications and indications disabled");
break;
case 0x01:
log(Log.INFO, "Notifications enabled");
break;
case 0x02:
log(Log.INFO, "Indications enabled");
break;
}
BleManagerHandler.this.onDescriptorWrite(gatt, descriptor);
}
} else {
BleManagerHandler.this.onDescriptorWrite(gatt, descriptor);
}
if (request instanceof WriteRequest) {
final WriteRequest wr = (WriteRequest) request;
final boolean valid = wr.notifyPacketSent(gatt.getDevice(), data);
if (!valid && requestQueue instanceof ReliableWriteRequest) {
wr.notifyFail(gatt.getDevice(), FailCallback.REASON_VALIDATION);
requestQueue.cancelQueue();
} else if (wr.hasMore()) {
enqueueFirst(wr);
} else {
wr.notifySuccess(gatt.getDevice());
}
}
} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION
|| status == 8 /* GATT INSUF AUTHORIZATION */
|| status == 137 /* GATT AUTH FAIL */) {
log(Log.WARN, "Authentication required (" + status + ")");
if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
// This should never happen but it used to: http://stackoverflow.com/a/20093695/2115352
Log.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
postCallback(c -> c.onError(gatt.getDevice(), ERROR_AUTH_ERROR_WHILE_BONDED, status));
}
// The request will be repeated when the bond state changes to BONDED.
return;
} else {
Log.e(TAG, "onDescriptorWrite error " + status);
if (request instanceof WriteRequest) {
request.notifyFail(gatt.getDevice(), status);
// Automatically abort Reliable Write when write error happen
if (requestQueue instanceof ReliableWriteRequest)
requestQueue.cancelQueue();
}
awaitingRequest = null;
onError(gatt.getDevice(), ERROR_WRITE_DESCRIPTOR, status);
}
checkCondition();
nextRequest(true);
}