[Galaxy Grand 2 Q&A, Help & Troubleshooting] EoflaOE:
I finally managed to get out of the "Factory data reset" loop! Here's how.

When I had a chance to discover why this factory reset loop is occurring, I proceeded to reinstall the entire system with Android 12 LineageOS 19.1 using the older TWRP 3.2.3 recovery. I also restored the data partition from the backup that I made before installing LineageOS 18.1 Go. However, it didn't fix the problem, which is strange, considering that the data partition in the backup was supposed to be pristine.

I went ahead to spin up the terminal from within the TWRP recovery to find any possible variables in default.prop that caused this to happen, but I found nothing. Then, I looked at the hexdump of a fota partition (/dev/block/bootdevices/by-name/fota) and wrapped its output using the "more" command, and saw something I've never seen before. It said something along the lines of "prepareUserData failed for system user" and "recovery".

Confused, I went as far as to open the source code of Android as found in this link (https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/pm/UserDataPreparer.java;l=128?q="userdata failed"&ss=android/platform/superproject) and saw something about user data preparation, so I went to turning on the USB debugging using TWRP because Android won't let me in because of the "Factory data reset" loop by appending the following properties to the build.prop file:

persist.service.adb.enable=1
persist.service.debuggable=1

My file already had the "persist.sys.usb.config=adb" line.

Upon rebooting to Android, I turned my old PC on and plugged my phone in to my PC. Then, I installed ADB using "sudo apt install adb" and executed the "adb devices" command to find that it found a device with "no permissions", so I added my device to my udev configuration. When I plugged my phone back in, I tested the command again, and saw "device".

I went ahead to test running Android again, and upon encountering the "Factory data reset" problem, I immediately took a snapshot of the Logcat of my device from my computer. When my phone rebooted to the recovery, I opened the text editor on my computer to look for potential problems. As I scrolled down, I saw the following:

11-09 09:56:17.500 245 257 E cutils : Failed to chmod(/data/media/0, 1528): Permission denied
11-09 09:56:17.500 245 257 E vold : Failed to prepare /data/media/0: Permission denied

Weird!

My phone was still in the recovery mode at the time. I rolled up my terminal emulator from my phone and checked the permission of the affected folder using "ls /data/media -l" and saw something that is beyond imagination. The user and group permissions for the "0" folder was set to "root"! I wrote the "chown -R media_rw:media_rw /data/media/" command thinking that it'll fix the factory reset loop. Upon rebooting, same issue occurred!

Thinking that I may have missed something, I proceeded to look for possible solutions to this debacle, until I found a viable solution. I captured the Logcat, looked for the error, and found this:

11-09 09:56:18.189 245 257 E cutils : Failed to chmod(/data/media/0, 1528): Permission denied
11-09 09:56:18.186 257 257 W Binder:245_3: type=1400 audit(0.0:112): avc: denied { setattr } for name="0" dev="mmcblk0p25" ino=129282 scontext=u:r:vold:s0 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=0
11-09 09:56:18.189 245 257 E vold : Failed to prepare /data/media/0: Permission denied
11-09 09:56:18.186 257 257 W Binder:245_3: type=1300 audit(0.0:112): arch=40000028 syscall=333 per=800008 success=no exit=-13 a0=ffffff9c a1=b24c88e0 a2=5f8 a3=0 items=1 ppid=1 ppcomm=init auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 exe="/system/bin/vold" subj=u:r:vold:s0 key=(null)

In my phone, I opened the terminal, and wrote the following commands:

chown -R media_rw:media_rw /data/media/
find /data/media/ -type d -exec chmod 775 {} ';'
find /data/media/ -type f -exec chmod 664 {} ';'
restorecon -FR /data/media/

When I rebooted my phone, the "Factory reset" issue went away! My SIM is now seen by my phone! The only thing now is that I'll have to set all my applications up, as even Windscribe, Instagram, and all apps are now prompting me to provide login details or configure them. The phone still works smoothly, but still suffers from the date and the time problem.

I prefer to have the date and time problem fixed. Any advice?