NordicSemiconductor / IOS-nRF-Connect-Device-Manager

A mobile management library for devices supporting nRF Connect Device Manager.
https://www.nordicsemi.com/Software-and-tools/Software/nRF-Connect-SDK
Apache License 2.0
90 stars 41 forks source link

Fix for situation where the same image is in both slots #57

Closed philips77 closed 2 years ago

philips77 commented 2 years ago

This PR fixes the endless loop happening when the same image is in both primary and secondary slot of an image. In #55 (and before) the flags of each image in the images property in DFU manager were modified multiple times. https://github.com/NordicSemiconductor/IOS-nRF-Connect-Device-Manager/blob/bab7cba94ec1944f99461a8f1a19ca9dcf552d65/Source/Managers/DFU/FirmwareUpgradeManager.swift#L353-L370 However, as FirmwareUpgradeImage is a struct, each modification is effectively replacing the image object with a new struct. The following call to markAs...(_ image:) was not finding the image instance, and returning, without changing the flag.

The image, in the above case, was marked as uploaded, but not as confirmed or tested, thus the library tried to test it again. As it was already in the primary and secondary slot, the confirm call was acting on the primary slot, but the check was verifying the secondary slot, which was never confirmed (why would it be). Now, it will not be sent twice in the first place, will be marked as confirmed and no additional confirm commands will be sent.