Skip to content

Commit fc59a92

Browse files
kcttanxiaofengphilips77
authored andcommitted
fix NegativeArraySizeException crash in SecureDfuImpl.java
more detail: NordicSemiconductor#229
1 parent e29fb40 commit fc59a92

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
627627
* Thrown when device had to be paired before the DFU process was started.
628628
*/
629629
public static final int ERROR_DEVICE_NOT_BONDED = ERROR_MASK | 0x0E;
630+
/**
631+
* Thrown when breakpoint resume fw
632+
* <p>
633+
* Check https://github.com/NordicSemiconductor/Android-DFU-Library/issues/229
634+
* </p>
635+
*/
636+
public static final int ERROR_BREAKPOINT_RESUME = ERROR_MASK | 0x0F;
630637
/**
631638
* Flag set when the DFU target returned a DFU error. Look for DFU specification to get error
632639
* codes. The error code is binary OR-ed with one of: {@link #ERROR_REMOTE_TYPE_LEGACY},

dfu/src/main/java/no/nordicsemi/android/dfu/SecureDfuImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ private void sendFirmware(final BluetoothGatt gatt) throws RemoteDfuException,
653653
loge("Error while reading firmware stream", e);
654654
mService.terminateConnection(gatt, DfuBaseService.ERROR_FILE_IO_EXCEPTION);
655655
return;
656+
} catch (final Throwable tr) {
657+
// crash fix
658+
// Check https://github.com/NordicSemiconductor/Android-DFU-Library/issues/229
659+
loge("Error while reading firmware stream", tr);
660+
mService.terminateConnection(gatt, DfuBaseService.ERROR_BREAKPOINT_RESUME);
661+
return;
656662
}
657663
// To decrease the chance of loosing data next time let's set PRN to 1.
658664
// This will make the update very long, but perhaps it will succeed.

0 commit comments

Comments
 (0)