From 4d4410d119d2f5a4449cf68b5d1353e08cfd0350 Mon Sep 17 00:00:00 2001 From: philips77 Date: Thu, 25 Jun 2020 09:26:38 +0200 Subject: [PATCH] #252 fixed --- .../no/nordicsemi/android/dfu/SecureDfuImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java b/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java index cea3840..d849c28 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java @@ -554,8 +554,18 @@ class SecureDfuImpl extends BaseCustomDfuImpl { // If the whole page was sent and CRC match, we have to make sure it was executed if (bytesSentNotExecuted == info.maxSize && info.offset < mImageSizeInBytes) { logi("Executing data object (Op Code = 4)"); - writeExecute(); - mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Data object executed"); + try { + writeExecute(); + mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Data object executed"); + } catch (final RemoteDfuException e) { + // In DFU bootloader from SDK 15.x, 16 and 17 there's a bug, which + // prevents executing an object that has already been executed. + // See: https://github.com/NordicSemiconductor/Android-DFU-Library/issues/252 + if (e.getErrorNumber() != SecureDfuError.OPERATION_NOT_PERMITTED) { + throw e; + } + mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Data object already executed"); + } } else { resumeSendingData = true; }