diff --git a/dfu/src/main/java/no/nordicsemi/android/dfu/BaseCustomDfuImpl.java b/dfu/src/main/java/no/nordicsemi/android/dfu/BaseCustomDfuImpl.java index a5808764..1b2d5ff6 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/BaseCustomDfuImpl.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/BaseCustomDfuImpl.java @@ -373,8 +373,11 @@ void uploadFirmwareImage(final BluetoothGattCharacteristic packetCharacteristic) mFirmwareUploadInProgress = true; mPacketsSentSinceNotification = 0; - final byte[] buffer = mBuffer; try { + final int available = mProgressInfo.getAvailableObjectSizeIsBytes(); + byte[] buffer = mBuffer; + if (available < buffer.length) + buffer = new byte[available]; final int size = mFirmwareStream.read(buffer); mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_VERBOSE, "Sending firmware to characteristic " + packetCharacteristic.getUuid() + "..."); 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 2f738274..5465699f 100644 --- a/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java +++ b/dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java @@ -565,6 +565,8 @@ private void sendFirmware(final BluetoothGatt gatt) throws RemoteDfuException, throw e; } mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_APPLICATION, "Data object already executed"); + // At this point, the error flag should be cleared, and the subsequent process can be executed normally. + mRemoteErrorOccurred = false; } } else { resumeSendingData = true;