[Motorola Razr 40 Ultra / Razr+ / Razr 2023] nicksons28:
In short: to fix this problem you must restore the hardware backed TEE/keystore!

Be careful folks, refrain from clearing dalvik cache too often. Unless absolutely necessary, and backup all your high level partitions, they might just save you from having to replace your phone later down the road!!!!!!

Keep reading for a more in detail look into these types of issues....

so i later learned this was a problem with TEE being corrupt causing it to act as if a pin was already set even though it was not, the pin was still stored in the TEE when you remove your pin in settings it contacts the TEE to remove from there as well, when erasing locksettings.db this never happens, resulting in this error. see more info about this below.

you screen lock is stored in the TEE this is why erasing locksettings.db will cause this problem and screen lock will no longer function.

let this be a reminder to never remove or edit locksettings.db you will effectively break your screen lock functionality. and from that point it is incredibly difficult to manually fix this issue as the TEE is hard to access.

((update)))) solved, i now found out this is caused by the pin is stored in the keymaster partition a very low level partition and is only repairable if you have an original copy of keymaster the only way is to backup keymaster when you buy the phone, so basically i had to replace the phone as i didnt backup the part, psa to anyone if you ever erase locksettings.db before backing up keymaster without having a screen lock do not do this as it will result in this error, so when my replacement arrives i will backup keymaster as well as all partitions before doing anything, something i shouldve already done however lesson learned. just leaving this here in the event anyone else runs into something similar. or to hopefuly save someone else from this headache.

so i recommend everyone to backup all high level partitions if i had, then restoring them would fix this error as it was not the data partition causing this error. just clearifying that DECRYPTION doesnt cause this problem.!! this is 100% not caused by decrypting data so you have nothing to worry about just backup those high partitions if you havent already if theyre corrupt your in for a nightmere with functionality on your device. im leaving this here as i see no one else has figured this out and to BACKUP YOUR HW PARTITIONS!!!

for anyone like me who runs a daily rooted device and tampers a bit.

keymaster, tz, frp, keystore, etc, these partitions (theres a bit more) are vital and i recommend you all back these up while you can. rescue flash in rsa cant save you from a problem caused by any of them!!!!!!!!!!!!!

these partitions are unique to each device and someone elses will rare ever work. therefore one must back them up manually.

keymaster is only flashable through fastbootd if you try to flash in bootloader mode it will result in an error, certain partitions are also on flashable in fastbootd, if instaling custom recovery, refrain from running fastboot erase all in fastbootd only run in bootloader mode. some partitions can only be flashed over with a backup of the same partition from only your device, if you erase them or flash it incorrectly you will brick the device.

im aware of how hardware backed keystore works, however this method works nonetheless on very certain specific problems such as the one i had with the screen lock. qualcomm edl mode can also be used to handle hw caused corruption. see qualcomm method here: https://xdaforums.com/t/tee-hacking.4662185/ hw tee is in fact restorable to fix this issue.

if you want to be able to fix this if it ever happens or similar keystore errors (which can happen at anytime randomly with unlocked bootloader btw)

these partitions can be backed up by navigating to /dev/block/by-name

and copy over every part (not userdata) and rename them all to add .img

to make them flashable.

fastbootd= fastboot reboot fastboot

in short these types of issues result in an error with the TEE and are repairable however very very few know of this method so i have left this here for further research purposes.

note (keep this is mind) : save yourself the trouble and never erase locksettings.db even if your password changed itself just restore your device, it will be much less time consuming that way.