Mobly Android Screen Recorder service for using Python code to screencast the Android devices in Mobly tests.
Project description
Mobly Android Screen Recorder
Mobly Android Screen Recorder service for using Python code to screencast the Android devices in Mobly tests (https://github.com/google/mobly).
This tool is upgraded to scrcpy v3.3 and adds audio recording feature.
Responsible Use
This tool is designed for legitimate testing and debugging purposes within the context of Mobly. It should only be used in situations where you have:
- Explicit consent: Obtain clear and informed consent from any individuals
- whose screens might be recorded.
- Legitimate purpose: Use the tool for legitimate testing, debugging,
- or development activities related to Mobly.
- Data security: Handle recorded screen data responsibly. Store it
- securely and delete it when it's no longer needed.
- Transparency: Be transparent about how the tool is being used and what
- data is being collected.
Misuse of this tool for unauthorized surveillance or any other malicious activity is strictly prohibited.
Remember: Recording someone's screen without their knowledge or consent is a serious breach of privacy and may have legal consequences.
Requirements
- Python 3.11+
- Mobly 1.12.2+
- FFMPEG 6.1.1+
Please make sure your FFMPEG support H.264 (run ffmpeg -codecs and
look for libx264 encoder in the output) and the OpenCV in Python built
with the H.264 encoder(print(cv2.getBuildInformation()) then look at the
Video I/O section).
Note: To use the audio recording feature, you must have ffmpeg installed
and available in your system's PATH.
Installation
pip install mobly-android-screen-recorder
Start to Use
After initializing the Android device, you can register the screen recorder service with the following code:
from mobly.controllers.android_device_lib.services import screen_recorder
...
self.dut = self.register_controller(android_device)[0]
# To enable audio recording, set `enable_audio=True` in the configs.
configs = screen_recorder.Configs(enable_audio=True)
self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)
Then the screen recorder will start recording the screen when the test starts and stop recording when the test finishes. The screen recording will be saved to the test output folder as a video file during teardown process for each test case with create_output_excerpts_all for all registered Mobly services.
Example 1: Hello World!
Let's start with the simple example of posting "Hello World" on the Android device's screen. Create the following files: sample_config.yml
TestBeds:
# A test bed where adb will find Android devices.
- Name: SampleTestBed
Controllers:
AndroidDevice: '*'
hello_world_test.py
from mobly import base_test
from mobly import test_runner
from mobly.controllers import android_device
from mobly.controllers.android_device_lib.services import screen_recorder
class HelloWorldTest(base_test.BaseTestClass):
def setup_class(self):
# Registering android_device controller module declares the test's
# dependency on Android device hardware. By default, we expect at least one
# object is created from this.
self.ads = self.register_controller(android_device)
self.dut = self.ads[0]
# Start Mobly Bundled Snippets (MBS).
self.dut.load_snippet('mbs', android_device.MBS_PACKAGE)
# Register screen recorder service, it will start recording when the test
# starts and stop recording when the test finishes.
# To enable audio recording, set `enable_audio=True` in the configs.
configs = screen_recorder.Configs(enable_audio=True)
self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)
def test_hello(self):
self.dut.mbs.makeToast('Hello World!')
def teardown_test(self):
self.dut.services.create_output_excerpts_all(self.current_test_info)
if __name__ == '__main__':
test_runner.main()
To execute:
$ python hello_world_test.py -c sample_config.yml
Expect:
A "Hello World!" toast notification appears on your device's screen. And a video
file named video,{device_serial},{device_model},{timestamp}.mp4 is created in
the test output folder.
Disclaimer
This tool, owned by Google and its developers, provides screen recording functionality for Android devices within the context of Mobly testing. It is essential to use this tool responsibly and ethically.
Privacy Warning: Screen recording can capture sensitive information. Always obtain explicit consent before recording anyone's screen. Unauthorized screen recording may violate privacy laws and ethical guidelines. Neither Google nor the developers of this tool are responsible for any misuse or illegal activity conducted with this software.
Users of this tool are solely responsible for ensuring compliance with all applicable laws and regulations regarding privacy and data protection.
Licensing
This project is licensed under the Apache License 2.0.
This project uses scrcpy, which is licensed under the Apache License 2.0. See the NOTICE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mobly_android_screen_recorder-1.0.3.tar.gz.
File metadata
- Download URL: mobly_android_screen_recorder-1.0.3.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa65797196757d9322c7771db1ad9b6823f2878d67cf123d654ea783b59581d9
|
|
| MD5 |
484733ccee32035b8faf83d2efe4662f
|
|
| BLAKE2b-256 |
d4a520a69a095602c1d73df27f96b8dd4fd932d5cf2a03e278e8313fae6cc46c
|
Provenance
The following attestation bundles were made for mobly_android_screen_recorder-1.0.3.tar.gz:
Publisher:
publish-to-pypi.yml on google/mobly-android-screen-recorder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mobly_android_screen_recorder-1.0.3.tar.gz -
Subject digest:
aa65797196757d9322c7771db1ad9b6823f2878d67cf123d654ea783b59581d9 - Sigstore transparency entry: 699792124
- Sigstore integration time:
-
Permalink:
google/mobly-android-screen-recorder@407562bce7aee2aeba966ca542ac706f26b00951 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/google
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@407562bce7aee2aeba966ca542ac706f26b00951 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mobly_android_screen_recorder-1.0.3-py3-none-any.whl.
File metadata
- Download URL: mobly_android_screen_recorder-1.0.3-py3-none-any.whl
- Upload date:
- Size: 3.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc050cc99f85e3840a7a06de2690bba81c13e7e65c51e75f90a50bfca7d61097
|
|
| MD5 |
8dedd188a58b599eaabafa5d3e738298
|
|
| BLAKE2b-256 |
303066cfe55f9eb13696694f916421105abc8289783c0cf756d566650fa730e7
|
Provenance
The following attestation bundles were made for mobly_android_screen_recorder-1.0.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on google/mobly-android-screen-recorder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mobly_android_screen_recorder-1.0.3-py3-none-any.whl -
Subject digest:
bc050cc99f85e3840a7a06de2690bba81c13e7e65c51e75f90a50bfca7d61097 - Sigstore transparency entry: 699792127
- Sigstore integration time:
-
Permalink:
google/mobly-android-screen-recorder@407562bce7aee2aeba966ca542ac706f26b00951 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/google
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@407562bce7aee2aeba966ca542ac706f26b00951 -
Trigger Event:
release
-
Statement type: