Reporting disconnection before an error

This commit is contained in:
Aleksander Nowakowski 2019-02-20 14:40:49 +01:00
parent e749cecf53
commit a24f1e8cd9
4 changed files with 18 additions and 18 deletions

View File

@ -347,10 +347,10 @@ import no.nordicsemi.android.dfu.internal.exception.UploadAbortedException;
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mError != 0)
throw new DfuException("Unable to write Init DFU Parameters", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to write Init DFU Parameters: device disconnected");
if (mError != 0)
throw new DfuException("Unable to write Init DFU Parameters", mError);
}
/**
@ -394,10 +394,10 @@ import no.nordicsemi.android.dfu.internal.exception.UploadAbortedException;
loge("Sleeping interrupted", e);
}
if (mError != 0)
throw new DfuException("Uploading Firmware Image failed", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Uploading Firmware Image failed: device disconnected");
if (mError != 0)
throw new DfuException("Uploading Firmware Image failed", mError);
}
/**

View File

@ -453,10 +453,10 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mError != 0)
throw new DfuException("Unable to set " + debugString + " state", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to set " + debugString + " state: device disconnected");
if (mError != 0)
throw new DfuException("Unable to set " + debugString + " state", mError);
}
/**
@ -506,10 +506,10 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mError != 0)
throw new DfuException("Unable to read Service Changed CCCD", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to read Service Changed CCCD: device disconnected");
if (mError != 0)
throw new DfuException("Unable to read Service Changed CCCD", mError);
// Return true if the CCCD value is
return descriptor.getValue() != null && descriptor.getValue().length == 2
@ -562,10 +562,10 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (!mResetRequestSent && mError != 0)
throw new DfuException("Unable to write Op Code " + value[0], mError);
if (!mResetRequestSent && !mConnected)
throw new DeviceDisconnectedException("Unable to write Op Code " + value[0] + ": device disconnected");
if (!mResetRequestSent && mError != 0)
throw new DfuException("Unable to write Op Code " + value[0], mError);
}
/**
@ -725,10 +725,10 @@ import no.nordicsemi.android.dfu.internal.scanner.BootloaderScannerFactory;
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to write Op Code", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to write Op Code: device disconnected");
if (mError != 0)
throw new DfuException("Unable to write Op Code", mError);
return mReceivedData;
}

View File

@ -238,10 +238,10 @@ import no.nordicsemi.android.dfu.internal.exception.UploadAbortedException;
} catch (final InterruptedException e) {
loge("Sleeping interrupted", e);
}
if (mError != 0)
throw new DfuException("Unable to read version number", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to read version number: device disconnected");
if (mError != 0)
throw new DfuException("Unable to read version number", mError);
// The version is a 16-bit unsigned int
return characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);

View File

@ -647,10 +647,10 @@ import no.nordicsemi.android.error.LegacyDfuError;
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to write Image Size", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to write Image Size: device disconnected");
if (mError != 0)
throw new DfuException("Unable to write Image Size", mError);
}
/**
@ -701,10 +701,10 @@ import no.nordicsemi.android.error.LegacyDfuError;
}
if (mAborted)
throw new UploadAbortedException();
if (mError != 0)
throw new DfuException("Unable to write Image Sizes", mError);
if (!mConnected)
throw new DeviceDisconnectedException("Unable to write Image Sizes: device disconnected");
if (mError != 0)
throw new DfuException("Unable to write Image Sizes", mError);
}
/**