2

I'm using the adb shell command monkey to launch one application followed by another. It all works fine, except for one odd side effect where the orientation lock on the device is set back to auto-rotate. We usually have the tablets locked to portrait only.

Is anyone aware of any reason the monkey command would change the orientation lock? Or if there is a way to prevent this/set it back through the adb?

adb shell monkey -p com.application1 1
adb shell monkey -p com.application2 1

Tablet Info:

  • Nexus 7
  • Android v6.0.1
Dan Gardner
  • 1,069
  • 2
  • 13
  • 29
  • Possible duplicate of [Change screen orientations during monkey run](https://stackoverflow.com/questions/12872917/change-screen-orientations-during-monkey-run) – Martin Zeitler Jun 20 '19 at 11:18
  • for a stress-test one probably should not prevent orientation-change events, simply because they may lead to crashes, which otherwise might not surface, while it is locked (one can assume this behavior is by design). – Martin Zeitler Jun 20 '19 at 11:19
  • @MartinZeitler Thanks for that link, I'd managed to miss that. Whilst that does of explain the behavior. Even overriding the orientation with the switch still removes the orientation lock. That puts the screen at the correct orientation, but the issue is with the orientation setting being changed – Dan Gardner Jun 20 '19 at 11:27
  • the assumption that there would be a "correct" orientation is wrongful... unless not the `Activity` is being locked to a specific orientation in the `Manifest.xml`... as if `monkey` would press the "correct" buttons :) – Martin Zeitler Jun 20 '19 at 11:29
  • @MartinZeitler Sorry correct orientation was the wrong way to put it.. the `mainfest.xml` does specify a portrait orientation, we don't actually have an issue with the app we're testing that all works fine! It's just the fact it removes the lock setting that we're struggling with, we don't reply on the lock for the app, it's just we don't want to remove the lock if it's set when launching this way – Dan Gardner Jun 20 '19 at 11:41
  • 1
    for any other type of test the lock should be kept enabled - but not for a stress-test (crashes on orientation-change or not too uncommon, when not handling the event properly)... because the idea of it is, to expose the UI to as much random input as possible, and the sensor input is input, too. – Martin Zeitler Jun 20 '19 at 11:54
  • @MartinZeitler I think I understand what you mean now! Based on your input here I think most appropriate for the situation would to be to use another command to start the application, `am start` probably. As you point out `monkey` is a stress test command and that's not really what we're doing here! Thanks for your input :) – Dan Gardner Jun 20 '19 at 14:57

2 Answers2

1

To return to locked mode:

adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
Cesar Devesa
  • 990
  • 6
  • 14
0

As discussed in the comments above with @MartinZeitler, the problem was that the monkey command was not really suitable for the purpose I was putting it to. Although removing the orientation lock is not something I've been able to find explicitly documented anywhere, it looks as if this is one of the random elements monkey triggers.

My solution was to launch the application using the following command, which was more appropriate for just launching an application as part of another test rather than using the stress test command.

am start -n com.application1/.MainActivity`

The following Question contains some really good detail on launching apps through the ADB

How to start an application using android ADB tools?

Dan Gardner
  • 1,069
  • 2
  • 13
  • 29