How to use the mobly.controllers.android_device_lib.errors.DeviceError function in mobly

To help you get started, we’ve selected a few mobly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / mobly / mobly / controllers / android_device_lib / snippet_client.py View on Github external
# want to call stop_standing_subprocess() to perform a health check,
        # print the failure stack trace if there was any, and reap it from the
        # process table.
        self.log.debug('Stopping snippet apk %s', self.package)
        try:
            # Close the socket connection.
            self.disconnect()
            if self._proc:
                utils.stop_standing_subprocess(self._proc)
            self._proc = None
            out = self._adb.shell(
                _STOP_CMD.format(
                    snippet_package=self.package,
                    user=self._get_user_command_string())).decode('utf-8')
            if 'OK (0 tests)' not in out:
                raise errors.DeviceError(
                    self._ad,
                    'Failed to stop existing apk. Unexpected output: %s' % out)
        finally:
            # Always clean up the adb port
            self.clear_host_port()
github google / mobly / mobly / controllers / android_device.py View on Github external
DEFAULT_VALUE_DEVICE_REQUIRED = True
# If True, logcat collection will not be started during `create`.
# Default is False.
KEY_SKIP_LOGCAT = 'skip_logcat'
DEFAULT_VALUE_SKIP_LOGCAT = False
SERVICE_NAME_LOGCAT = 'logcat'

# Default name for bug reports taken without a specified test name.
DEFAULT_BUG_REPORT_NAME = 'bugreport'

# Default Timeout to wait for boot completion
DEFAULT_TIMEOUT_BOOT_COMPLETION_SECOND = 15 * 60

# Aliases of error types for backward compatibility.
Error = errors.Error
DeviceError = errors.DeviceError
SnippetError = snippet_management_service.Error

# Regex to heuristically determine if the device is an emulator.
EMULATOR_SERIAL_REGEX = re.compile(r'emulator-\d+')


def create(configs):
    """Creates AndroidDevice controller objects.

    Args:
        configs: A list of dicts, each representing a configuration for an
            Android device.

    Returns:
        A list of AndroidDevice objects.
    """
github google / mobly / mobly / controllers / android_device_lib / callback_handler.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.

import time

from mobly.controllers.android_device_lib import errors
from mobly.controllers.android_device_lib import snippet_event

# The max timeout cannot be larger than the max time the socket waits for a
# response message. Otherwise, the socket would timeout before the Rpc call
# does, leaving both server and client in unknown states.
MAX_TIMEOUT = 60 * 10
DEFAULT_TIMEOUT = 120  # two minutes


class Error(errors.DeviceError):
    pass


class TimeoutError(Error):
    pass


class CallbackHandler(object):
    """The class used to handle a specific group of callback events.

    All the events handled by a CallbackHandler are originally triggered by one
    async Rpc call. All the events are tagged with a callback_id specific to a
    call to an AsyncRpc method defined on the server side.

    The raw message representing an event looks like:
github google / mobly / mobly / controllers / android_device_lib / errors.py View on Github external
class DeviceError(Error):
    """Raised for errors specific to an AndroidDevice object."""

    def __init__(self, ad, msg):
        template = '%s %s'
        # If the message starts with the hierarchy token, don't add the extra
        # space.
        if isinstance(msg, str) and msg.startswith(HIERARCHY_TOKEN):
            template = '%s%s'
        new_msg = template % (repr(ad), msg)
        super(DeviceError, self).__init__(new_msg)


class ServiceError(DeviceError):
    """Raised for errors specific to an AndroidDevice service.

    A service is inherently associated with a device instance, so the service
    error type is a subtype of `DeviceError`.
    """
    SERVICE_TYPE = None

    def __init__(self, device, msg):
        new_msg = '%sService<%s> %s' % (HIERARCHY_TOKEN, self.SERVICE_TYPE,
                                        msg)
        super(ServiceError, self).__init__(device, new_msg)
github google / mobly / mobly / controllers / android_device_lib / jsonrpc_client_base.py View on Github external
import threading

from mobly.controllers.android_device_lib import callback_handler
from mobly.controllers.android_device_lib import errors

# UID of the 'unknown' jsonrpc session. Will cause creation of a new session.
UNKNOWN_UID = -1

# Maximum time to wait for the socket to open on the device.
_SOCKET_CONNECTION_TIMEOUT = 60

# Maximum time to wait for a response message on the socket.
_SOCKET_READ_TIMEOUT = callback_handler.MAX_TIMEOUT


class Error(errors.DeviceError):
    pass


class AppStartError(Error):
    """Raised when the app is not able to be started."""


class AppRestoreConnectionError(Error):
    """Raised when failed to restore app from disconnection."""


class ApiError(Error):
    """Raised when remote API reports an error."""


class ProtocolError(Error):
github google / mobly / mobly / controllers / android_device_lib / errors.py View on Github external
def __init__(self, ad, msg):
        template = '%s %s'
        # If the message starts with the hierarchy token, don't add the extra
        # space.
        if isinstance(msg, str) and msg.startswith(HIERARCHY_TOKEN):
            template = '%s%s'
        new_msg = template % (repr(ad), msg)
        super(DeviceError, self).__init__(new_msg)
github google / mobly / mobly / controllers / android_device_lib / service_manager.py View on Github external
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for the manager of services."""
# TODO(xpconanfan: move the device errors to a more generic location so
# other device controllers like iOS can share it.
import collections
import inspect

from mobly import expects
from mobly.controllers.android_device_lib import errors
from mobly.controllers.android_device_lib.services import base_service


class Error(errors.DeviceError):
    """Root error type for this module."""


class ServiceManager(object):
    """Manager for services of AndroidDevice.

    A service is a long running process that involves an Android device, like
    adb logcat or Snippet.
    """

    def __init__(self, device):
        self._service_objects = collections.OrderedDict()
        self._device = device

    def has_service_by_name(self, name):
        """Checks if the manager has a service registered with a specific name.