Skip to content

Commit

Permalink
fix (AndroidFileUploader.java, IOSFileUploader.swift): if the file-up…
Browse files Browse the repository at this point in the history
…loading operation fails to commence we now return error code .FAILED__ERROR_UPON_COMMENCING / .failedErrorUponCommencing (old was: .errorInvalidSettings which wasn't accurate)
  • Loading branch information
ksidirop-laerdal committed Oct 3, 2024
1 parent 31c3866 commit bec12cc
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,22 @@ public EAndroidFileUploaderVerdict beginUpload(

try
{
_uploadController = new FileUploader( //00
FileUploader fileUploader = new FileUploader( //00
_fileSystemManager,
_remoteFilePathSanitized,
data,
Math.max(1, windowCapacity),
Math.max(1, memoryAlignment)
).uploadAsync(_fileUploaderCallbackProxy);
);

_uploadController = fileUploader.uploadAsync(_fileUploaderCallbackProxy);
}
catch (final Exception ex)
{
setState(EAndroidFileUploaderState.ERROR);
onError(_remoteFilePathSanitized, "Failed to initialize the upload", ex);

return EAndroidFileUploaderVerdict.FAILED__INVALID_SETTINGS;
return EAndroidFileUploaderVerdict.FAILED__ERROR_UPON_COMMENCING;
}

return EAndroidFileUploaderVerdict.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
public enum EAndroidFileUploaderVerdict //this must mirror the enum values of E[Android|iOS]FileUploaderVerdict
{
SUCCESS(0),
FAILED__INVALID_SETTINGS(1),
FAILED__INVALID_DATA(2),
FAILED__OTHER_UPLOAD_ALREADY_IN_PROGRESS(3);
FAILED__INVALID_DATA(1),
FAILED__INVALID_SETTINGS(2),
FAILED__ERROR_UPON_COMMENCING(3), //connection problems
FAILED__OTHER_UPLOAD_ALREADY_IN_PROGRESS(4);

@SuppressWarnings({"FieldCanBeLocal", "unused"})
private final int _value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@objc
public enum EIOSFileUploadingInitializationVerdict: Int {
case success = 0
case failedInvalidSettings = 1
case failedInvalidData = 2
case failedOtherUploadAlreadyInProgress = 3
case failedInvalidData = 1
case failedInvalidSettings = 2
case failedErrorUponCommencing = 3
case failedOtherUploadAlreadyInProgress = 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class IOSFileUploader: NSObject {
@objc
public func beginUpload(
_ remoteFilePath: String,
_ data: Data,
_ data: Data?,
_ pipelineDepth: Int,
_ byteAlignment: Int
) -> EIOSFileUploadingInitializationVerdict {
Expand Down Expand Up @@ -115,15 +115,13 @@ public class IOSFileUploader: NSObject {
return EIOSFileUploadingInitializationVerdict.failedInvalidSettings
}

// if data == nil { // data being nil is not ok but in swift Data can never be nil anyway btw data.length==0 is perfectly ok because we might want to create empty files
// return EIOSFileUploaderVerdict.FAILED__INVALID_DATA
// }

disposeFilesystemManager() //vital hack normally we shouldnt need this but there seems to be a bug in the lib https://github.com/NordicSemiconductor/IOS-nRF-Connect-Device-Manager/issues/209
if data == nil { // data being nil is not ok btw data.length==0 is perfectly ok because we might want to create empty files
return EIOSFileUploadingInitializationVerdict.failedInvalidData
}

disposeFilesystemManager() //00 vital hack
ensureTransportIsInitializedExactlyOnce() //order
ensureFilesystemManagerIsInitializedExactlyOnce() //order

resetUploadState() //order

var configuration = FirmwareUpgradeConfiguration(byteAlignment: byteAlignmentEnum!)
Expand All @@ -132,19 +130,21 @@ public class IOSFileUploader: NSObject {
}

let success = _fileSystemManager.upload( //order
name: _remoteFilePathSanitized,
data: data,
using: configuration,
delegate: self
name: _remoteFilePathSanitized,
data: data!,
using: configuration,
delegate: self
)
if !success {
setState(EIOSFileUploaderState.error)
onError("Failed to commence file-uploading (check logs for details)")

return EIOSFileUploadingInitializationVerdict.failedInvalidSettings
return EIOSFileUploadingInitializationVerdict.failedErrorUponCommencing
}

return EIOSFileUploadingInitializationVerdict.success

//00 normally we shouldnt need this but there seems to be a bug in the lib https://github.com/NordicSemiconductor/IOS-nRF-Connect-Device-Manager/issues/209
}

private func translateByteAlignmentMode(_ alignment: Int) -> ImageUploadAlignment? {
Expand Down
11 changes: 8 additions & 3 deletions Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,22 @@ static private EFileUploaderVerdict TranslateFileUploaderVerdict(EAndroidFileUpl
{
return EFileUploaderVerdict.Success;
}

if (verdict == EAndroidFileUploaderVerdict.FailedInvalidData)
{
return EFileUploaderVerdict.FailedInvalidData;
}

if (verdict == EAndroidFileUploaderVerdict.FailedInvalidSettings)
{
return EFileUploaderVerdict.FailedInvalidSettings;
}

if (verdict == EAndroidFileUploaderVerdict.FailedInvalidData)
if (verdict == EAndroidFileUploaderVerdict.FailedErrorUponCommencing)
{
return EFileUploaderVerdict.FailedInvalidData;
return EFileUploaderVerdict.FailedErrorUponCommencing;
}

if (verdict == EAndroidFileUploaderVerdict.FailedOtherUploadAlreadyInProgress)
{
return EFileUploaderVerdict.FailedOtherUploadAlreadyInProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace Laerdal.McuMgr.FileUploader.Contracts.Enums
public enum EFileUploaderVerdict //this must mirror the java enum values of E[Android|iOS]FileUploaderVerdict
{
Success = 0,
FailedInvalidSettings = 1,
FailedInvalidData = 2,
FailedOtherUploadAlreadyInProgress = 3,
FailedInvalidData = 1,
FailedInvalidSettings = 2,
FailedErrorUponCommencing = 3,
FailedOtherUploadAlreadyInProgress = 4,
}
}
11 changes: 8 additions & 3 deletions Laerdal.McuMgr/iOS/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,22 @@ static private EFileUploaderVerdict TranslateFileUploaderVerdict(EIOSFileUploadi
{
return EFileUploaderVerdict.Success;
}

if (verdict == EIOSFileUploadingInitializationVerdict.FailedInvalidData)
{
return EFileUploaderVerdict.FailedInvalidData;
}

if (verdict == EIOSFileUploadingInitializationVerdict.FailedInvalidSettings)
{
return EFileUploaderVerdict.FailedInvalidSettings;
}

if (verdict == EIOSFileUploadingInitializationVerdict.FailedInvalidData)
if (verdict == EIOSFileUploadingInitializationVerdict.FailedErrorUponCommencing)
{
return EFileUploaderVerdict.FailedInvalidData;
return EFileUploaderVerdict.FailedErrorUponCommencing;
}

if (verdict == EIOSFileUploadingInitializationVerdict.FailedOtherUploadAlreadyInProgress)
{
return EFileUploaderVerdict.FailedOtherUploadAlreadyInProgress;
Expand Down

0 comments on commit bec12cc

Please sign in to comment.