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.
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.
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 }'
% time adb shell
=> adb shell dumpsys 0.01s user 0.03s system 0% cpu 9.001 total
about 9 seconds on a Nexus 7. Good catch anyway. Thanks!
Jan 9, 2013 at 3:34
adb shell dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'
adb shell dumpsys input | awk '/SurfaceOrientation/ {print $2}'
That will then only process lines in awk which match the regex specified.
Jan 8, 2020 at 7:00
Simpler solution:
adb shell dumpsys window | grep -i surfaceorientation | awk '{ print $2 }'
I found this method content query --uri content://settings/system --projection name:value --where "name='user_rotation'"
after opening adb shell
. Although doesn't seem to work if entered without opening a shell first.
In addition to the previous answers, I would like to point out that the return value of adb shell dumpsys | grep 'SurfaceOrientation'
does not always follow a specific rule across devices ("0 and 2 are landscapes while 1 and 3 are portraits" is wrong).
I improved the method by an additional query, which advises how to interpret the return value, namely
dumpsys window | grep 'mLandscapeRotation'
value 0 means: 0 and 2 are landscapes, 1 and 3 are portraits
value 1 means the opposite situation
I am not sure if something has changed since the last answers were written, or if it is because I am emulating a different device.
but neither SurfaceOrientation
nor mLandscapeRotation
showed up in dumpsys for me.
After diffing the outputs of dumpsys
between rotations I found
mPredictedRotation
#Normal
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=0
#Right
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=3
#Inverted
$./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=2
$Left
#./adb shell dumpsys window displays | grep 'mPredictedRotation'
mPredictedRotation=1