The complementary filter idea is to combine slow-moving signals from an accelerometer with fast-moving signals from a gyroscope. The accelerometer provides a good indicator of orientation in static conditions, while the gyroscope provides a good indicator of tilt in dynamic conditions. Thus, the idea is to pass the accelerometer signals through a low-pass filter and the gyroscope signals through a high-pass filter, and then combine them to give the final rate.
See Github here.
getRotationMatrix
function: https://developer.android.com/reference/android/hardware/SensorManager#getRotationMatrixhttps://developer.android.com/reference/android/hardware/SensorManager#getRotationMatrix(float[], float[], float[], float[])getOrientation
function: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/SensorManager.java#1478