This procedure might fix problem but will clear whole memory
1 Backup from twrp only "persist" image and save it elsewhere (if you wish to try to restore your system later, then backup EVERY PARTITION and also save everything that's on internal memory elsewhere, IT WILL BE DELETED WITH PROCEDURE)
2 Install from twrp as zip this file:
https://www.mediafire.com/file/pjqui3toyxgr5c8/sensorfix.zip/file
3 flash from fastboot WITHOUT LOCKING BACK BOOTLOADER every single version, FROM OLDER TO NEWER, of these roms in THIS ORDER:
FROM OLDER TO NEWER china developer
FROM OLDER TO NEWER china stable
FROM OLDER TO NEWER global stable
4 when flashed the latest rom, check if everything works
5 if it does, you're good to go! If you wish to install a custom rom just do like you normally do, but remember:
DON'T EVER WIPE "PERSIST" IN TWRP
NEVER EVER EVER AGAIN!!!
6 (optional) if you want to try to recover your old system, normally install the same exact version of the rom you had before with a clean flashing, and then from twrp wipe cache, dalvik, data, system and internal storage and recover data and system, copy the old internal storage files inside internal storage and reboot