Reputation: 5412
I'd like to test android's behavior on all possible combinations of the following "inputs":
setRequestedOrientation()
(15 possible values, not including SCREEN_ORIENTATION_BEHIND
)Settings.System.ACCELEROMETER_ROTATION
(2 possible values)Settings.System.USER_ROTATION
(4 possible values)OrientationEventListener
) (4 possible quadrants)Specifically, I want to see how the inputs affect the following "output":
getWindowManager().getDefaultDisplay()
.getRotation()
(4 possible values)So this will require testing at least all 15*2*4*4=480
possible input states.
Additionally, since rotation behavior is often dependent on the history of the inputs (not just the current input values), I want to test (at least) all possible transitions from one input state to an "adjacent" input state, i.e. to an input state that differs from the given input state by one input parameter. The number of such input state transitions is:
(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
Furthermore, sometimes output is dependent on the previous output as well as previous and current
input (e.g. SCREEN_ORIENTATION_LOCKED
, SCREEN_ORIENTATION_SENSOR_LANDSCAPE
).
The number of possible outputs for a given input state can be between 1 and 4,
so this multiplies the number of transitions that must be tested by up to 4:
10080 * 4 = 40320
That's a lot of transitions to test, so the testing would have to be programmatic/scripted. Three out of the four input params are straightforward to control programmatically; the one that's not straightforward to control is the device's physical orientation.
So, how would one go about scripting it? I can think of the following approaches.
Approach #1: Replace the (physical or emulated) device's accelerometer with a scriptable mock accelerometer for the duration of the test. But, if I understand correctly, mock accelerometers do not exist for android.
Approach #2: Use the android emulator, and script pressing of the "rotate counterclockwise" and "rotate clockwise" buttons using an interaction automation tool on the host machine (e.g. applescript / autohotkey / xdotool).
Any other ideas?
Upvotes: 2
Views: 366
Reputation: 5412
It turns out this is actually a duplicate of the following excellent question: How can i simulate accelerometer in android emulator? which has this excellent answer from @user1302884 : Unfortunately, that question got no respect and was closed as off-topic (?!) so I won't mark this as a duplicate.
But here's the answer: no need for applescript/autohotkey/xdotool to drive the emulator's ui; instead, telnet to the emulator and tell it which direction you want "up" to be.
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
It would be nice if the emulated display would appear rotated by the specified number of degrees in response, but you can't have everything.
Upvotes: 1