Java Code Examples for android.bluetooth.bluetoothgatt#GATT_INSUFFICIENT_AUTHENTICATION
The following examples show how to use
android.bluetooth.bluetoothgatt#GATT_INSUFFICIENT_AUTHENTICATION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BleManager.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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); } }
Example 2
Source File: BleManager.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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); } }
Example 3
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 6 votes |
@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"); } }
Example 4
Source File: BleManager.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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); } }
Example 5
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 6 votes |
@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"); } }
Example 6
Source File: DexShareCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
@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"); } }
Example 7
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@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"); } }
Example 8
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@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"); } }
Example 9
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 10
Source File: PA_Task_ReadOrWrite.java From SweetBlue with GNU General Public License v3.0 | 5 votes |
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; }
Example 11
Source File: BleManager.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); } }
Example 12
Source File: DexShareCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 13
Source File: BleUtils.java From bleYan with GNU General Public License v2.0 | 5 votes |
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; } }
Example 14
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 15
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 16
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 17
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@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"); } }
Example 18
Source File: BleManagerHandler.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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); }
Example 19
Source File: BleManagerHandler.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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); }
Example 20
Source File: BleManagerHandler.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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); }