Search code examples
android

Check if device is landscape via ADB


Is it possible to check a devices orientation via ADB?

Not by installing any software, calling any existing software, just through ADB. Would guess there is a status file somewhere in /proc, but could not find it yet.


Solution

  • This can be done through the following command:

    adb shell dumpsys | grep 'SurfaceOrientation' | awk '{ print $2 }'
    

    The output will be an integer ranging from 0 to 3 for each of the four possible orientations. 0 and 2 are landscapes while 1 and 3 are portraits. As the dumpsys output is very large, the command might take a few seconds to complete.

    Update: dgmltn's modification is likely much faster:

    adb shell dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'