Skip to content

Commit

Permalink
Merge pull request #206 from NordicSemiconductor/bugfix/crash-on-cancel
Browse files Browse the repository at this point in the history
Bugfix: Fixed crash when upload gets cancelled in the wrong moment
  • Loading branch information
philips77 authored Nov 14, 2024
2 parents 94d24c1 + 896bfe6 commit d09f3a7
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UploadCache extends SUITUpgradeTask {

private final byte @NotNull [] data;
private final int targetId;
private boolean canceled = false;

/**
* Upload controller used to pause, resume, and cancel upload. Set when the upload is started.
Expand Down Expand Up @@ -76,6 +77,12 @@ public void onUploadCompleted() {
}
};

// Check if the task was canceled before starting the upload.
if (canceled) {
callback.onUploadCanceled();
return;
}

LOG.info("Uploading cache image with target partition ID: {} ({} bytes)", targetId, data.length);
final SUITUpgradePerformer.Settings settings = performer.getSettings();
final SUITManager manager = new SUITManager(performer.getTransport());
Expand All @@ -90,11 +97,17 @@ public void onUploadCompleted() {

@Override
public void pause() {
mUploadController.pause();
if (mUploadController != null) {
mUploadController.pause();
}
}

@Override
public void cancel() {
mUploadController.cancel();
if (mUploadController != null) {
mUploadController.cancel();
} else {
canceled = true;
}
}
}

0 comments on commit d09f3a7

Please sign in to comment.