Merge pull request #254 from NordicSemiconductor/pull/247

Modifications to #247
This commit is contained in:
Aleksander Nowakowski 2020-06-25 10:54:55 +02:00 committed by GitHub
commit e720d006c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -627,6 +627,13 @@ public abstract class DfuBaseService extends IntentService implements DfuProgres
* Thrown when device had to be paired before the DFU process was started.
*/
public static final int ERROR_DEVICE_NOT_BONDED = ERROR_MASK | 0x0E;
/**
* Thrown when the DFU library lost track of what is going on. Reported number of bytes is
* not equal to the number of bytes sent and due to some other events the library cannot recover.
* <p>
* Check https://github.com/NordicSemiconductor/Android-DFU-Library/issues/229
*/
public static final int ERROR_PROGRESS_LOST = ERROR_MASK | 0x0F;
/**
* Flag set when the DFU target returned a DFU error. Look for DFU specification to get error
* codes. The error code is binary OR-ed with one of: {@link #ERROR_REMOTE_TYPE_LEGACY},

View File

@ -653,6 +653,12 @@ class SecureDfuImpl extends BaseCustomDfuImpl {
loge("Error while reading firmware stream", e);
mService.terminateConnection(gatt, DfuBaseService.ERROR_FILE_IO_EXCEPTION);
return;
} catch (final Throwable tr) {
// crash fix
// Check https://github.com/NordicSemiconductor/Android-DFU-Library/issues/229
loge("Progress lost. Bytes sent: " + mProgressInfo.getBytesSent(), tr);
mService.terminateConnection(gatt, DfuBaseService.ERROR_PROGRESS_LOST);
return;
}
// To decrease the chance of loosing data next time let's set PRN to 1.
// This will make the update very long, but perhaps it will succeed.