Try restarting in safe mode and testing the sensor for a software cause, if that doesn't work, do the following.
There is a method that has worked for a few users, you can try it, but if it works, it can start again at slightest shock, not a definitive solution, although I wonder if the service center can provide a real solution.
You remove the back protection if you have one
You put a clean cloth or rag on a flat surface
You put the smartphone on it upside down, screen on the laundry, back on top
You hold the smartphone well and you massage it at the bottom, from left to right by pressing firmly (at the level of the area that I have surrounded where the connectors are)
If that doesn't work, don't insist, and visit a service center.