I wonder what kind of phone ?
There are various ways to measure distance, including ultrasonic sound waves and infrared light. In the first case, sound waves are emitted from the camera, and by measuring the delay in their reflection, distance to the subject is calculated.
In the latter case, infrared light is usually used to triangulate the distance to the subject. Compact cameras as well as early video cameras, used this system.
A newer approach included in some consumer electronic devices, like mobile phones, is based on the time-of-flight principle, which involves shining a laser or LED light to the subject and calculating the distance based on the time it takes for the light to travel to the subject and back.
This technique is sometimes called laser autofocus, and is present in many mobile phone models from several vendors.
New iPhones have LIDAR, I don’t know about others.