I guess it is function using calling plus light sensor, which has bunch of examples around.
Updated
Sorry, it would be Proximity Sensor. just try putting on your hand when messaging, whether it calls or not. Here is the link for it. http://developer.android.com/guide/topics/sensors/sensors_position.html#sensors-pos-prox