gpt4 book ai didi

android - 如何测试/执行 android 的屏幕旋转行为?

转载 作者:行者123 更新时间:2023-11-30 00:36:36 26 4
gpt4 key购买 nike

我想测试 android 在以下“输入”的所有可能组合上的行为:

具体来说,我想看看输入如何影响以下“输出”:

  • getWindowManager().getDefaultDisplay() .getRotation() (4 个可能的值)

因此这将需要至少测试所有 15*2*4*4=480 可能的输入状态。

此外,由于旋转行为通常取决于历史输入的(不仅仅是当前输入值),我想(至少)测试从一个输入状态到“相邻”输入状态的所有可能转换,即输入状态与给定输入状态的一个输入参数不同。这种输入状态转换的次数是:

      (number of input states) * (number of states adjacent to a given input state)    = (15*2*4*4) * ((15-1) + (2-1) + (4-1) + (4-1))    = 480 * 21    = 10080

此外,有时输出取决于之前的输出以及之前和当前的输出输入(例如 SCREEN_ORIENTATION_LOCKEDSCREEN_ORIENTATION_SENSOR_LANDSCAPE)。给定输入状态的可能输出数可以在 1 到 4 之间,所以这会将必须测试的转换数量乘以最多 4:

    10080 * 4 = 40320

有很多转换要测试,因此测试必须是程序化/脚本化的。四个输入参数中的三个可以通过编程直接控制;不容易控制的是设备的物理方向。

那么,如何编写脚本呢?我可以想到以下方法。

方法 #1:将(物理或仿真)设备的加速度计替换为可编写脚本的模拟加速度计在测试期间。但是,如果我理解正确的话,Android 不存在模拟加速度计。

方法 #2:使用 android 模拟器,并按脚本按下“逆时针旋转”和使用主机上的交互自动化工具(例如 applescript/autohotkey/xdotool)“顺时针旋转”按钮。

还有其他想法吗?

最佳答案

事实证明,这实际上是以下优秀问题的重复: How can i simulate accelerometer in android emulator?里面有这个excellent answer来自@user1302884:不幸的是,这个问题没有得到尊重,并作为题外话(?!)关闭,所以我不会将其标记为重复。

但答案是:不需要 applescript/autohotkey/xdotool 来驱动模拟器的 ui;相反,远程登录到模拟器并告诉它你想要“向上”的方向。

telnet localhost 5554  # or whatever the port is
telnet> sensor # to get help on the sensor command
telnet> sensor get acceleration
acceleration = 0:9.81:0 # if in natural orientation
telnet> sensor get acceleration
acceleration = -9.81:0:0 # if rotated 90 degrees CW from natural orientation
telnet> sensor set orientation -1:1:0 # to set to 45 degrees CW from natural orientation

如果模拟显示能够旋转指定的度数作为响应就好了,但你不能拥有一切。

关于android - 如何测试/执行 android 的屏幕旋转行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43319781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com