[X 2014 Q&A, Help & Troubleshooting] CUBENSIS:
Sigh, I realized after writing all this that I'm talking about kit kat, not lollipop. I'd assume that much is the same safe mode thing should still work, but not sure about the various directories I refer to when undoing encryption or app compatibilities.

--

I encountered this problem. There are multiple potential roadblocks. Mostly related to uncooperative background programs. The easiest thing to do is to boot into safe mode and then encrypt. That's what worked for me. If you still have a problem, have supersu remove the su binary and then try again in safe mode.

Just Google how to boot into safe mode.

---------- Post added at 02:50 AM ---------- Previous post was at 02:03 AM ----------

Note that TWRP does not decrypt encrypted data partitions for our device. Also, you can't simply unencrypt.

I ended up undoing encryption because the phone was noticeably laggier. Thus process was not well documented anywhere and was painful.

How to undo encryption (need root, obviously. From my recollection, so there may be errors):

1) Make an onandroid. Since you're doing this after you've booted, the nandroid will have images of the unencrypted partitions. https://play.google.com/store/apps/details?id=com.h3r3t1c.onnandbup

2) copy this to the appropriate place in the twrp folder, to prepare for your eventual nandroid restore. Example: /data/media/0/TWRP/BACKUPS/TA44904H9S/2014-10-31--01-05-42/

3) copy the entire contents of your sdcard, including the nandroid you just made, to a computer or USB OTG (usb otg drive is easier). Twrp directory ownership and permission are screwed up, so make sure the nandroid copied over. You may have to explicitly navigate to /data/media/0 to make it copy (as opposed to /storage/emulated/0)

4) Use the following program to copy and eventually restore the timestamps: https://play.google.com/store/apps/details?id=br.com.pogsoftwares.filetimestamp . If you don't do this, the grouping of your photos and videos in gallery will be messed up. There may be other files for which this is important, I'm not sure.

5) go to twrp, and at least do a factory reset and format/wipe sdcard (not 100% sure, I may have just wiped everything)

6) copy the saved contents of your SD card to /data/media/0. I don't recall if I used twrp file manager or qtadb for this.

7) the directory and file permission on sdcard will be ****ed. Run this script to fix that: https://www.dropbox.com/s/ur596dpgzw478qm/perm.sh?dl=0 . Google to figure out how to run scripts from twrp terminal. Don't try to do this later. When I tried to do it from within android it didn't work because the version of chown I had didn't support one of the switches in the script

8) reboot into android

9) use the timestamp program to fix the file timestamps on your sdcard. I never saved the timestamps ahead of time. The program can fix the photo timestamps based on exif and the video timestamps based on filenames. But it's just easier if you saved the timestamps ahead of time.

10) immediately reboot to twrp and restore just the data partition. If you don't do this, Gallery will never fix itself based on the fixed timestamps.

11) some app data on sdcard may still be screwed up. If a program is not working right, go the the relevant directory in /sdcard/android/data and delete it.

I'm sure there are errors somewhere in the guide, just pm me if there is a problem and I'll figure it out and fix this guide