Android-DFU-Library: DFU - DFU Service not found

Hi all, Before I tried to run my code, I tested DFU device services in nRF Connect app:

Device: Huawei P20, Samsuns S9 (Android 10s)

https://i.imgur.com/eoStwLQ.png

My code:

return DfuServiceInitiator(device.address)
                .setDeviceName(device.name)
                .setKeepBond(true)
                .setNumberOfRetries(5)
                .setZip(fileStreamUri, null)

Logcat:

Attempt: 1
Refreshing result: true
Cleaning up...
Restarting the service
Starting DFU service in foreground
Connecting to the device...
Connected to GATT server
Attempting to start service discovery... succeed
Action received: android.bluetooth.device.action.ACL_CONNECTED
I/DfuBaseService: Services discovered
**W/DfuBaseService: DFU Service not found.**
I/DfuBaseService: Disconnecting from the device...
I/DfuBaseService: Disconnected from GATT server
I/DfuBaseService: Refreshing result: true
I/DfuBaseService: Cleaning up...
I/DfuBaseService: Starting DFU service in foreground
I/DfuBaseService: Action received: android.bluetooth.device.action.ACL_DISCONNECTED

Do I have wrong configuration of DFUService initiator object?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (9 by maintainers)

Most upvoted comments

Hi @archie94,

Observations

It’s a bit hard to say what is the root cause of this. Based on the logs I see that:

  1. You’re using Secure DFU (8ec90003-f315-4f60-9fb8-838830daea50 is the Secure DFU Buttonless Charactersitic UUID)
  2. The library sends Jump to bootloader command:
    1672653688, BleManager, d, address = EF:31:55:E9:31:9C; msg = [DFU] Enter bootloader sent (Op Code = 1)
    1672653688, BleManager, d, address = EF:31:55:E9:31:9C; msg = [DFU] Response received (Op Code = 1; Status = 1)
    
    but is unable to reconnect to the device in bootloader mode:
    1672653688, BleManager, v, address = EF:31:55:E9:31:9C; msg = [DFU] Scanning for the DFU Bootloader...
    1672653693, BleManager, i, address = EF:31:55:E9:31:9C; msg = [DFU] DFU Bootloader not found. Trying the same address...
    
  3. After that it tries to reconnect to the device with the same MAC address, but does it twice, which indicates an issue:
    1672653696, BleManager, v, address = EF:31:55:E9:31:9C; msg = [DFU] Connecting to DFU target...
    1672653696, BleManager, d, address = EF:31:55:E9:31:9C; msg = [DFU] gatt = device.connectGatt(autoConnect = false; TRANSPORT_LE; preferredPhy = LE_1M | LE_2M)
     // Connection event is received twice:
    1672653696, BleManager, i, address = EF:31:55:E9:31:9C; msg = [DFU] Connected to EF:31:55:E9:31:9C
    1672653696, BleManager, v, address = EF:31:55:E9:31:9C; msg = [DFU] Discovering services...
    1672653696, BleManager, d, address = EF:31:55:E9:31:9C; msg = [DFU] gatt.discoverServices()
     // Here as well:
    1672653696, BleManager, i, address = EF:31:55:E9:31:9C; msg = [DFU] Connected to EF:31:55:E9:31:9C
    1672653696, BleManager, v, address = EF:31:55:E9:31:9C; msg = [DFU] Discovering services...
    1672653696, BleManager, d, address = EF:31:55:E9:31:9C; msg = [DFU] gatt.discoverServices()
    // And service is not found
    1672653724, BleManager, i, address = EF:31:55:E9:31:9C; msg = [DFU] Services discovered
    1672653724, BleManager, w, address = EF:31:55:E9:31:9C; msg = [DFU] DFU Service not found
    

Conclusions

We did address similar issue with in #356 or #345. The issue is that on some Android devices switching to bootlaoder mode doesn’t trigger disconnection. The phone still thinks it’s connected. Some phones actually keep the connection active for some time. When the lib is searching for an incremented MAC it is still not ready. Then, after 2 seconds it tries to reconnect to the old MAC (which is still connected), so this succeeds, or at least the phone thinks so. Service discovery may fail, as the device has perhaps reset.

Those 2 PRs try to fix this issue by calling disconnect() to make “sure” Android gets that, allowing setting “reset time” (delay before the lib starts scanning) or settings scan period (to increase from the default 2 seconds).

Recommendation

I would recommend trying updating using the DFU app and trying different settings on the Settings screen. Check if you’re able to make it work on those phones before applying changes to your app. If that works, I recommend to migrate to the latest version or doing cherry-picking important commits (you need to search for them on your own).

Questions

  1. Does it work on some phones and fails on some other?
  2. Does it work sometimes on those phones, or never?