5

While debugging my app using Monkey (which is almost as fun as the real thing), I managed to crash! Yay, that's what it's for, right?

Looking at the log (and while watching) I noticed that Monkey is occasionally doing:

:Sending Flip keyboardOpen=true

which seems to be part of my problem. When this happens, the screen in the emulator rotates 90 degrees, but this is NOT the same as a regular rotation you get by hitting KEYPAD_7. Here's a picture:

unusual screen orientation

It looks to me the emulator is emulating a keyboard opening (flip), which is subtly different from a rotation.

So the question is: How do I emulate that myself? Sure, running Monkey is neat, but waiting for it to randomly choose to send a keyboardOpen message is no way to debug a program.

SMBiggs
  • 11,034
  • 6
  • 68
  • 83

1 Answers1

2

Maybe use the --pct-majornav to restrict the monkey to just the 'major' nav events (I'm assuming keyboard changes are 'major', I'm not sure though).

You could also look into writing a specific test based on the different but similar monkeyrunner framework: http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html ... but I don't see any way to inject keyboard flip codes.

I found this relevant SO question: Simulating opening/closing the hardware keyboard in emulator but the "answer" there is confusing and seems insufficient.

Not really your question, but related to your root issue:

Did you forget to include 'keyboardHidden' in the 'android:configChanges' section of the manifest file? (Or did you include it, but you don't handle the config change callbacks?)

The keyboard hide/reveal will restart your activity. You can either declare that you handle that restart, or if you don't, the OS will stop and restart the app itself.

See http://developer.android.com/guide/topics/resources/runtime-changes.html

Update

I believe this is the source for the monkey application's keyboard flip event. It looks like injecting a keyboard flip event would be relatively straight-forward: Open /dev/input/input0 and write 16 magical bytes into it.

Also, the source seems to have an undocumented --pct-flip option for controlling keyboard flip rates: link

Community
  • 1
  • 1
P.T.
  • 24,557
  • 7
  • 64
  • 95
  • Thanks for the link--I didn't find it during my search. It's sad that it seems there just is NOT a way to emulate purely a keyboard flip/slide (but the Monkey can do it!--sigh). We have to do a rotate AND a flip. [BTW, my bug WAS related to an odd condition during restarts and EditTexts--fixed it without needing to step through. Thanks!] – SMBiggs Oct 14 '11 at 19:33
  • Thanks for the follow-up, P.T.! Unfortunately the links are no longer active, sigh. This is a real bugger of a situation, but I consider this question answered enough. If anyone else has more info, please add it to this conversation. – SMBiggs Feb 04 '12 at 03:15
  • 1
    The source is still available at various other places - try http://www.java2s.com/Open-Source/Android/android-core/platform-development/com/android/commands/monkey/MonkeyFlipEvent.java.htm – PacificSky Apr 18 '12 at 06:26