通过ADB检查设备方向是否可能?
不需要安装任何软件,调用任何现有软件,只需通过ADB即可。猜测在/proc
某处存在状态文件,但尚未找到。
通过ADB检查设备方向是否可能?
不需要安装任何软件,调用任何现有软件,只需通过ADB即可。猜测在/proc
某处存在状态文件,但尚未找到。
这可以通过以下命令完成:
adb shell dumpsys | grep 'SurfaceOrientation' | awk '{ print $2 }'
每个方向的输出将是一个整数,范围从0到3。0和2为横向,1和3为竖向。由于dumpsys
输出非常大,该命令可能需要几秒钟才能完成。
更新:dgmltn的修改可能会更快:
adb shell dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'
在Pixel和Pixel Tablet上验证过,可以使用
adb shell dumpsys window displays | grep 'DisplayFrmaes'
结果类似于DisplayFrames w=1080 h=2340 r=0
r=0,1,2,3是显示方向。
SurfaceOrientation
还是mLandscapeRotation
都没有在dumpsys中显示出来。
在旋转之间比较dumpsys
的输出后,我发现了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
更简单的解决方案:
adb shell dumpsys window | grep -i surfaceorientation | awk '{ print $2 }'
在打开adb shell
后,我发现了这个方法:content query --uri content://settings/system --projection name:value --where "name='user_rotation'"
。虽然如果不先打开shell输入似乎无法正常工作。
adb shell dumpsys | grep 'SurfaceOrientation'
的返回值在不同设备上并不总是遵循特定规则("0 和 2 是横屏,1 和 3 是竖屏" 是错误的)。dumpsys window | grep 'mLandscapeRotation'
数值0表示:0和2为横向,1和3为纵向
数值1表示相反的情况
%time adb shell
=> 在Nexus 7上大约需要9秒钟,输出为adb shell dumpsys 0.01s user 0.03s system 0% cpu 9.001 total
。无论如何,你做得很好。谢谢! - Sebastian Rothadb shell dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'
- dgmltn