Phone keeps restarting by itself
Hello, I hope this is the right subreddit for my issue.
Just to get the basic info out first; phone is Samsung S21 FE, Android, around 2-3 years old.
Anyway, around 4-5 days ago my phone started randomly resetting. Every time I put it in my pocket and didn't use it, my phone restarted. It was hot outside and I was doing physical work, so I assumed it just overheated and had to restart. I thought that was all and it would go back to normal after it had cooled down, but things just got worse. A day later, I was on my phone, it got really hot really fast which I again assumed was because it was hot in my room and I'd been using it for a while, it froze and turned off. For the next 10 minutes, it kept repeatedly turning on, but instead of fully turning back on, the screen just went black again and it tried starting on its own again, over and over. Since then, every single time im not using my phone it resets. If I use it for longer periods of time, it will just freeze in the middle of what I'm doing, the screen would go black, and it's restarting again.
I've tried optimizing, I deleted an app which was supposedly constantly crashing in the background, i went into settings and turned off "auto reset when not functioning properly" or something like that. I tried leaving the battery to go completely empty, left my phone turned off for a good while and then charged it while fully turned off but that didn't help either.
My question is did I fuck up my battery? Did I somehow get a virus? Is there another solution than factory resetting my phone?
I'd appreciate any insight anyone can give me about this problem because it's making everything harder. People cant call me because phone is constantly either off, or I have to unlock it for it to get all the programs running again.