Hi all...i am seeing many people confused over the methods to keep their devices decrypted over flashing. I always use this method and never have to format data either it being an miui or aosp rom.
1- First make a twrp backup of your rom in case anything goes wrong. But never backup a rom with security. So first remove all pins, passwords, patterns and fingerprints, then only backup in twrp...this avoids any restore problems.
2-Make sure to keep your internal memory backed up always to a PC or USB flash drive...these two steps keep you insured.
3- Wipe data and cache...this is different from formatting data, as it doesn't touch your internal memory...but use this only for fresh installs...if you want to dirty flash, just flash the rom zip.
4-Flash the rom zip.
5- Flash gapps if you want to...or if the rom doesn't have them.
6- Flash the Disable Force Encryption (DFE) zip.
7- Flash Magisk...if you want to root.
8- Flash any other zip you want to.
9-Reboot
This method is only applicable if you are already decrypted. If you are encrypted and want to decrypt, then follow these steps. Backup your rom and internal memory as in previous steps.
1-Steps 1 to 8 are same.
2-Reboot to recovery and format data...now Reboot
3-You are now decrypted.
4-Restore all internal memory from PC or USB flash drive.
Keep in mind to flash DFE always just after flashing any rom or Boot(Kernel)zip ....before flashing even Magisk...and never let to boot the device with new rom without flashing DFE. Because the DFE patches the Kernel to disable Encryption.
I keep a Type C OTG SanDisk 128 GB flashdrive always handy and always keep backing up my data. However never got a chance to restore as by above method, i never have to format the data.
Use the DFE zip from this thread
https://xdaforums.com/android/software/universal-dm-verity-forceencrypt-t3817389