*For the purposes of this post, Software OS Update == Firmware Upgrade. For instance when the device notifies you that there is a OS Software Update, this could also modify the firmware of the device.
QUESTION: I have been given an untrusted Android device recently which may or may not have malware of any type on it. Let's be clear, there is no suspicious activity, but I cannot personally confirm its history. Let's assume the worst case scenario, and that the device is infected with some sort of unknown sophisticated malware. Under these circumstances, is it:
Preferable to first wipe the device in order to remove any malware that may interfere with the firmware upgrade?
Or it is preferable to first upgrade the firmware and then wipe the device to prevent any malicious firmware with interfering with either the wiping of the device or the upgrading of its firmware?
*POSTNOTE: I know many will suggest it won't make a difference. Please pick the best option, and explain why. Also, I would like this question to pertain to more than just Android, to avoid posting duplicate Windows/Linux based questions. If possible please address any differences if the OS and firmware will affect the answer. Thank you.