NordicSemiconductor / Android-DFU-Library

Device Firmware Update library and Android app
http://www.nordicsemi.com/dfu
BSD 3-Clause "New" or "Revised" License
763 stars 269 forks source link

DFU disconnecting on Nougat, LG Nexus 5X #21

Closed Iljo closed 7 years ago

Iljo commented 8 years ago

Version of DFU library is 1.0.3. OS build number on Nexus 5x is NRD90R, which is last official update.

Short after beggining of DFU process, when sending firmware to device, device disconnects from phone with status 8. According to Androids BLE api, it's a status for error A remote device connection is congested.

Comit before adef02a6ec49a65d826dda0b8ccdf0e7917eadbf, it's working fine. So far this is happening only with Nougat on LG Nexus 5X. On the other hand, Nexus 6P, running Nougat, is working quite fine.

Here is part of stack trace, when error occures:

E/DfuActivity: Extras: DFU_PROGRESS_CHANGED; 14;
D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=5 device=DD:46:F1:C7:CE:F2
E/DfuBaseService: Connection state change error: 8 newState: 0
E/DfuImpl: Disconnected while sending data
E/DfuBaseService: Uploading Firmware Image failed: device disconnected
I/DfuBaseService: Cleaning up...
D/BluetoothGatt: close()
D/BluetoothGatt: unregisterApp() - mClientIf=5

Currently we are fixing it by setting PRN in Androids SharedPreference, before every DFU, like so:

PreferenceManager.getDefaultSharedPreferences(this)
        .edit()
        .putBoolean(DfuSettingsConstants.SETTINGS_PACKET_RECEIPT_NOTIFICATION_ENABLED, true)
        .putString(DfuSettingsConstants.SETTINGS_NUMBER_OF_PACKETS, String.valueOf(12))
        .commit();

If not reverting commit adef02a6ec49a65d826dda0b8ccdf0e7917eadbf, could PRN setting be an extra for an intent that's starting DfuBaseService, instead of value in preferences?

philips77 commented 8 years ago

Hi, Thanks for the report. I will test it on Nexus 5X in a second and come back to you. I did some testing on different phones and Android version, but not on Nexus 5X, of course... However, from what I saw in AOSP the buffer overflow has been fixed in Android 6.0, so PRNs should not be required. But let me check. Regarding the PRN value - yes, it should be an extra. However, no to break backwards compatibility, I will have to check the SharedPreferences value as well when the extra is not set.

Iljo commented 8 years ago

OK, thanks.

philips77 commented 8 years ago

Hi, I've tried DFU on Nexus 5X (mine build version is NRD90S) and had no problems. I managed to perform 2 tests: sending only an app and sending SD+BL+App. Both finished with success.

Sending SD+BL

Seding App afterwards

As you see from the graph PRNs were disabled. During SD+BL upload first it fills the whole buffer, then the buffer is partially-emptied before continuing. I'm pretty much sure it is NOT the update to NRD90S which causes it to work on my side. Could you send my some hex files and zip so that I could try with your configuration?

philips77 commented 8 years ago

Hi, I've just published version 1.0.4 of the DFU Library. Changes:

Also, I did a lot of testing on Nexus 5X and I couldn't get error 8... it was working 100% times using different firmwares, in Legacy and Secure DFU. If it doen't work for you you should be able to set PRNs now with the initiator, as you requested.

Iljo commented 8 years ago

@philips77 Unfortunately I can't send you firmware, because it's proprietary software.

I can send you screencast of DFU process using nRF Connect application, that fails when not using PRN. If it helps, I can also send you screenshot of successfull update when PRN is set to 12. If it would help, I can send it around end of week, when I get hands on that phone again.

P. S. I'm uploading only application.

KentaHarada commented 8 years ago

@philips77 I've tried with following conditions on my Nexus 5X(ver 7.0 NRD90M) and other android devices.

DFU finished successfully with case 3 condition. I think that BLE buffer over flow problem has not been fixed on marshmallow. How do you think ? If the bug fixed already, I will use case 3 condition on my Android Application. Is that valid workaround?

Case 1 PRN : Disabled PRN Value : - Result : Failed with error 8 short after beginning of DFU process.

Case 2 PRN : Enabled PRN Value : 1 Result : DFU finished successfully, but my device didn't boot up.

Case 3 PRN : Enabled PRN Value : 2 Result : DFU finished successfully, but my device(nRF51) boot up normally.

philips77 commented 8 years ago

How about leaving PRN value at default 12? It's significantly faster. Also, it's really weird that the device hasn't reboot. Which SD and SDK are you using?

KentaHarada commented 8 years ago

@philips77 Thank you for your reply. I tried with PRN default value 12. But failed with error 8.

And this is my device information. nRF51822 SDK6.1.0 SoftDevice s110 7.3.0

KentaHarada commented 8 years ago

@philips77 I've tested DFU on several Android devices such as KitKat, Lollipop, Marshmallow and Nougat with following conditions. And DFU finished successfully on all devices.

DFU Library : ver 1.0.4 PRN : Enabled PRN Value : 2 Device : nRF51822, SDK6.1.0, SoftDevice s110 7.3.0

So, I plan to release my application with DFU library ver 1.0.4. If you have any update or concern about this issue, could you leave a comment ?

TomorrowDreamer commented 7 years ago

when i develop the DFU,a toast show me" DFU FILE NOT FOUND" DfuServiceInitiator.setZip(A,B),A is the fileStream path or the file absolute path? please help.

philips77 commented 7 years ago

@GHDreamer please open another issue for this.

philips77 commented 7 years ago

I'm closing this issue.