mobly.controllers.android_device_lib.services package

Submodules

mobly.controllers.android_device_lib.services.base_service module

Module for the BaseService.

class mobly.controllers.android_device_lib.services.base_service.BaseService(device, configs=None)[source]

Bases: abc.ABC

Base class of a Mobly AndroidDevice service.

This class defines the interface for Mobly’s AndroidDevice service.

alias

String, alias used to register this service with service manager.

This can be None if the service is never registered.

create_output_excerpts(test_info)[source]

Creates excerpts of the service’s output files.

[Optional] This method only applies to services with output files.

For services that generates output files, calling this method would create excerpts of the output files. An excerpt should contain info between two calls of create_output_excerpts or from the start of the service to the call to create_output_excerpts.

Use AndroidDevice#generate_filename to get the proper filenames for excerpts.

This is usually called at the end of: setup_class, teardown_test, or teardown_class.

Parameters:test_info – RuntimeTestInfo, the test info associated with the scope of the excerpts.
Returns:
List of strings, the absolute paths to the excerpt files created.
Empty list if no excerpt files are created.
is_alive

True if the service is active; False otherwise.

pause()[source]

Pauses a service temporarily.

For when the Python service object needs to temporarily lose connection to the device without shutting down the service running on the actual device.

This is relevant when a service needs to maintain a constant connection to the device and the connection is lost if USB connection to the device is disrupted.

E.g. a services that utilizes a socket connection over adb port forwarding would need to implement this for the situation where the USB connection to the device will be temporarily cut, but the device is not rebooted.

For more context, see: mobly.controllers.android_device.AndroidDevice.handle_usb_disconnect

If not implemented, we assume the service is not sensitive to device disconnect, and stop will be called by default.

resume()[source]

Resumes a paused service.

Same context as the pause method. This should resume the service after the connection to the device has been re-established.

If not implemented, we assume the service is not sensitive to device disconnect, and start will be called by default.

start()[source]

Starts the service.

stop()[source]

Stops the service and cleans up all resources.

This method should handle any error and not throw.

mobly.controllers.android_device_lib.services.logcat module

class mobly.controllers.android_device_lib.services.logcat.Config(logcat_params=None, clear_log=True, output_file_path=None)[source]

Bases: object

Config object for logcat service.

clear_log

bool, clears the logcat before collection if True.

logcat_params

string, extra params to be added to logcat command.

output_file_path

string, the path on the host to write the log file to, including the actual filename. The service will automatically generate one if not specified.

exception mobly.controllers.android_device_lib.services.logcat.Error(device, msg)[source]

Bases: mobly.controllers.android_device_lib.errors.ServiceError

Root error type for logcat service.

SERVICE_TYPE = 'Logcat'
class mobly.controllers.android_device_lib.services.logcat.Logcat(android_device, configs=None)[source]

Bases: mobly.controllers.android_device_lib.services.base_service.BaseService

Android logcat service for Mobly’s AndroidDevice controller.

adb_logcat_file_path

string, path to the file that the service writes adb logcat to by default.

OUTPUT_FILE_TYPE = 'logcat'
clear_adb_log()[source]

Clears cached adb content.

create_output_excerpts(test_info)[source]

Convenient method for creating excerpts of adb logcat.

This copies logcat lines from self.adb_logcat_file_path to an excerpt file, starting from the location where the previous excerpt ended.

Call this method at the end of: setup_class, teardown_test, and teardown_class.

Parameters:test_infoself.current_test_info in a Mobly test.
Returns:List of strings, the absolute paths to excerpt files.
is_alive

True if the service is active; False otherwise.

pause()[source]

Pauses logcat.

Note: the service is unable to collect the logs when paused, if more logs are generated on the device than the device’s log buffer can hold, some logs would be lost.

resume()[source]

Resumes a paused logcat service.

start()[source]

Starts a standing adb logcat collection.

The collection runs in a separate subprocess and saves logs in a file.

stop()[source]

Stops the adb logcat service.

update_config(new_config)[source]

Updates the configuration for the service.

The service needs to be stopped before updating, and explicitly started after the update.

This will reset the service. Previous output files may be orphaned if output path is changed.

Parameters:new_config – Config, the new config to use.

mobly.controllers.android_device_lib.services.sl4a_service module

Module for the Sl4aService.

class mobly.controllers.android_device_lib.services.sl4a_service.Sl4aService(device, configs=None)[source]

Bases: mobly.controllers.android_device_lib.services.base_service.BaseService

Service for managing sl4a’s client.

Direct calls on the service object will forwarded to the client object as syntactic sugar. So Sl4aService.doFoo() is equivalent to Sl4aClient.doFoo().

is_alive

True if the service is active; False otherwise.

pause()[source]

Pauses a service temporarily.

For when the Python service object needs to temporarily lose connection to the device without shutting down the service running on the actual device.

This is relevant when a service needs to maintain a constant connection to the device and the connection is lost if USB connection to the device is disrupted.

E.g. a services that utilizes a socket connection over adb port forwarding would need to implement this for the situation where the USB connection to the device will be temporarily cut, but the device is not rebooted.

For more context, see: mobly.controllers.android_device.AndroidDevice.handle_usb_disconnect

If not implemented, we assume the service is not sensitive to device disconnect, and stop will be called by default.

resume()[source]

Resumes a paused service.

Same context as the pause method. This should resume the service after the connection to the device has been re-established.

If not implemented, we assume the service is not sensitive to device disconnect, and start will be called by default.

start()[source]

Starts the service.

stop()[source]

Stops the service and cleans up all resources.

This method should handle any error and not throw.

mobly.controllers.android_device_lib.services.snippet_management_service module

Module for the snippet management service.

exception mobly.controllers.android_device_lib.services.snippet_management_service.Error(device, msg)[source]

Bases: mobly.controllers.android_device_lib.errors.ServiceError

Root error type for snippet management service.

SERVICE_TYPE = 'SnippetManagementService'
class mobly.controllers.android_device_lib.services.snippet_management_service.SnippetManagementService(device, configs=None)[source]

Bases: mobly.controllers.android_device_lib.services.base_service.BaseService

Management service of snippet clients.

This service manages all the snippet clients associated with an Android device.

add_snippet_client(name, package, config=None)[source]

Adds a snippet client to the management.

Parameters:
  • name – string, the attribute name to which to attach the snippet client. E.g. name=’maps’ attaches the snippet client to ad.maps.
  • package – string, the package name of the snippet apk to connect to.
  • config – snippet_client_v2.Config, the configuration object for controlling the snippet behaviors. See the docstring of the Config class for supported configurations.
Raises:

Error, if a duplicated name or package is passed in.

get_snippet_client(name)[source]

Gets the snippet client managed under a given name.

Parameters:name – string, the name of the snippet client under management.
Returns:SnippetClient.
is_alive

True if any client is running, False otherwise.

pause()[source]

Pauses all the snippet clients under management.

This clears the host port of a client because a new port will be allocated in resume.

remove_snippet_client(name)[source]

Removes a snippet client from management.

Parameters:name – string, the name of the snippet client to remove.
Raises:Error – if no snippet client is managed under the specified name.
resume()[source]

Resumes all paused snippet clients.

start()[source]

Starts all the snippet clients under management.

stop()[source]

Stops all the snippet clients under management.

Module contents