might be this problem - in my case, it was

https://forum.xda-developers.com/nexus-7-2013/nexus-7-2013-qa/accelerometer-compass-t3383223