Performing a factory reset is the best way to get rid of viruses, spyware, and other malware. A factory reset will delete everything that wasn't originally installed on the device. This includes any viruses that infected your operating system and files.