How to "clean" the phone completely and secure the privacy?

A

AC Question

Everyone knows your phone sends out your personal info to third party without your consent. Is it possible to remove all apps, android firmware, and everything else in the phone, then reinstall the thing I need?

I did some search and I think rooting the device and install a ROM (CyanogenMod?) is the solution. The problem is, I can identify crapwares and remove them, but how can I identify and remove hidden services that may cause the info leak? Someone commented a rooted and ROM installed Xiaomi will still send info to China, how can I "clean" a phone properly?