Does gravity sensor return right values if device is in motion? I thought that gravity sensor use accelerometer to recognize gravitation direction. Are these two sensors different piece of hardware?
The Gravity sensor is what Android calls a 'software sensor' and calculates its values using more than one hardware sensor.
The software Gravity sensor is only available if the device has a gyroscope. By combining accelerometer data with gyroscope data, the acceleration due to moving the device can be filtered out to leave the pure gravity signal. So yes, it will return the right value under motion.
Thus, the Gravity sensor gives a much better signal for device orientation than just the accelerometer on its own.
Combining sensor values is called sensor fusion and important for high quality measurement values.
The Android Documentation describes the Gravity Sensor.
Unfortunately, many Android devices lack a Gyroscope, and thus, will have no Gravity sensor either. This leaves you with a sub optimal signal from just the accelerometer alone, giving a lower quality user experience compared to Android devices with both sensors, and lower quality experience compared to iOS devices.
You can block installations on incompatible devices by using a Google Play requirement specification as follows:
<uses-feature android:name="android.hardware.sensor.gyroscope" />