Fix a bug in DFU service when there is no Service Changed indication and
the device is bonded.
This commit is contained in:
parent
7d96ad3b9d
commit
73bc9eb51a
|
@ -1085,11 +1085,13 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
* we are in the bootloader or application by simply checking the number of characteristics.
|
* we are in the bootloader or application by simply checking the number of characteristics.
|
||||||
*/
|
*/
|
||||||
if (version == 1 || (version == 0 && gatt.getServices().size() > 3 /* No DFU Version char but more services than Generic Access, Generic Attribute, DFU Service */)) {
|
if (version == 1 || (version == 0 && gatt.getServices().size() > 3 /* No DFU Version char but more services than Generic Access, Generic Attribute, DFU Service */)) {
|
||||||
// the service is connected to the application, not to the bootloader
|
// The service is connected to the application, not to the bootloader
|
||||||
logw("Application with buttonless update found");
|
logw("Application with buttonless update found");
|
||||||
sendLogBroadcast(Level.WARNING, "Application with buttonless update found");
|
sendLogBroadcast(Level.WARNING, "Application with buttonless update found");
|
||||||
|
|
||||||
// if we are bonded we may want to enable Service Changed characteristic indications
|
// If we are bonded we may want to enable Service Changed characteristic indications.
|
||||||
|
// Note: This feature will be introduced in the SDK 8.0 as this is the proper way to refresh attribute list on the phone.
|
||||||
|
boolean hasServiceChanged = false;
|
||||||
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_BONDED) {
|
if (gatt.getDevice().getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||||
final BluetoothGattService genericAttributeService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE_UUID);
|
final BluetoothGattService genericAttributeService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE_UUID);
|
||||||
if (genericAttributeService != null) {
|
if (genericAttributeService != null) {
|
||||||
|
@ -1097,6 +1099,7 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
if (serviceChangedCharacteristic != null) {
|
if (serviceChangedCharacteristic != null) {
|
||||||
enableCCCD(gatt, serviceChangedCharacteristic, INDICATIONS);
|
enableCCCD(gatt, serviceChangedCharacteristic, INDICATIONS);
|
||||||
sendLogBroadcast(Level.APPLICATION, "Service Changed indications enabled");
|
sendLogBroadcast(Level.APPLICATION, "Service Changed indications enabled");
|
||||||
|
hasServiceChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1131,7 +1134,7 @@ public abstract class DfuBaseService extends IntentService {
|
||||||
* However, as up to Android 5 the system does NOT respect this requirement and servers are cached for every device, even if Service Changed is enabled -> Android BUG?
|
* However, as up to Android 5 the system does NOT respect this requirement and servers are cached for every device, even if Service Changed is enabled -> Android BUG?
|
||||||
* For bonded devices Android performs service re-discovery when SC indication is received.
|
* For bonded devices Android performs service re-discovery when SC indication is received.
|
||||||
*/
|
*/
|
||||||
refreshDeviceCache(gatt, false);
|
refreshDeviceCache(gatt, !hasServiceChanged);
|
||||||
|
|
||||||
// Close the device
|
// Close the device
|
||||||
close(gatt);
|
close(gatt);
|
||||||
|
|
Loading…
Reference in New Issue