Keep boot-time logs when the logcat service restarts after a reboot (#1074)

`AndroidDevice.handle_reboot()` stops all services before the reboot and
starts them again once `sys.boot_completed` is set. `Logcat.start()` did
not distinguish that restart from the first start of a run: it cleared the
device buffer (`Config.clear_log` defaults to True) and started
`adb logcat -T 1`, which only follows from the most recent line. Everything
logged between kernel boot and boot completion was therefore dropped from
`adb_logcat_file_path`, and `get_lines()` / `wait_for()` / `listen()` could
not see boot-time events such as the MediaProvider `MEDIA_MOUNTED` scan,
even though they were still available via a raw `adb logcat -d`.

`start()` now reads `/proc/sys/kernel/random/boot_id` and, when it differs
from the id seen by the previous start, treats the call as a restart after a
reboot: the buffer (which only holds this boot's logs) is not cleared and
the new `adb logcat` process dumps the whole buffer before following. A
stop/start on the same boot, or when the boot id cannot be read, keeps the
existing clear-and-follow behavior. `pause()`/`resume()` are unchanged.
2 files changed
tree: 39d246367483594b0da35fb4584b83c21ff6e85d
  1. .github/
  2. docs/
  3. mobly/
  4. tests/
  5. tools/
  6. .gitignore
  7. .readthedocs.yaml
  8. CHANGELOG.md
  9. CONTRIBUTING.md
  10. LICENSE
  11. pyproject.toml
  12. README.md
  13. tox.ini
README.md

Welcome to Mobly

Latest release Build Status

Mobly is a Python-based test framework that specializes in supporting test cases that require multiple devices, complex environments, or custom hardware setups.

Here are some example use cases:

  • P2P data transfer between two devices
  • Conference calls across three phones
  • Wearable device interacting with a phone
  • Internet-Of-Things devices interacting with each other
  • Testing RF characteristics of devices with special equipment
  • Testing LTE network by controlling phones, base stations, and eNBs

Mobly can support many different types of devices and equipment, and it's easy to plug your own device or custom equipment/service into Mobly.

Mobly comes with a set of libs to control common devices like Android devices.

While developed by Googlers, Mobly is not an official Google product.

Compatibility

Mobly requires python 3.14 or newer.

Mobly tests could run on the following platforms:

  • Ubuntu 14.04+
  • MacOS 10.6+
  • Windows 7+

System dependencies

  • adb (1.0.40+ recommended)
  • python3.14+

Installation

You can install the released package from pip

pip install mobly

or install from the source to use the bleeding edge:

git clone https://github.com/google/mobly.git
cd mobly
pip install -e .

You may need sudo for the above commands if your system has certain permission restrictions.

Tutorials

Mobly Snippet

The Mobly Snippet projects let users better control Android devices.

  • Mobly Snippet Lib: used for triggering custom device-side code from host-side Mobly tests. You could use existing Android libraries like UI Automator and Espresso.
  • Mobly Bundled Snippets: a set of Snippets to allow Mobly tests to control Android devices by exposing a simplified version of the public Android API suitable for testing.