# Path: android_env/components/errors.py
# class ReadObservationError(Exception):
# class ObservationDecodingError(ReadObservationError):
# class PipeTimedOutError(ReadObservationError):
# class CoordinatorError(Exception):
# class TooManyRestartsError(CoordinatorError):
# class NotAllowedError(Exception):
# class PlayerExitedActivityError(NotAllowedError):
# class PlayerExitedViewHierarchyError(NotAllowedError):
# class AdbControllerError(Exception):
# class AdbControllerShellInitError(AdbControllerError):
# class AdbControllerPexpectError(AdbControllerError):
# class AdbControllerDeviceTimeoutError(AdbControllerError):
# class AdbControllerConnectionError(AdbControllerError):
# class AdbControllerInputDeviceNotFoundError(AdbControllerError):
# class AdbControllerScreenPinningError(AdbControllerError):
# class SimulatorCrashError(Exception):
# class ConsoleConnectionError(Exception):
# class SendActionError(Exception):
# class StepCommandError(Exception):
# class WaitForAppScreenError(StepCommandError):
# class CheckInstallError(StepCommandError):
# class WaitForMessageError(StepCommandError):


import os
import pathlib
import re
import subprocess
import sys
import threading
import time
import pexpect
from typing import List, Optional, Sequence, Tuple
from absl import logging
from android_env.components import errors
from android_env.proto import adb_pb2

    raise errors.AdbControllerShellInitError(
        'Failed to start ADB shell. Max number of retries reached.')

  def _wait_for_device(self,
                       max_tries: int = 20,
                       sleep_time: float = 1.0,
                       timeout: Optional[float] = None) -> None:
    """Waits for the device to be ready.

    Args:
      max_tries: Number of times to check if device is ready.
      sleep_time: Sleep time between checks, in seconds.
      timeout: A timeout to use for this operation. If not set the default
        timeout set on the constructor will be used.

    Returns:
      True if the device is ready, False if the device timed out.
    Raises:
      errors.AdbControllerDeviceTimeoutError when the device is not ready after
        exhausting `max_tries`.
    """
    num_tries = 0
    while num_tries < max_tries:
      ready = self._check_device_is_ready(timeout=timeout)
      if ready:
        logging.info('Device is ready.')
        return
      time.sleep(sleep_time)
      logging.error('Device is not ready.')

# Path: android_env/components/errors.py
# class ReadObservationError(Exception):
# class ObservationDecodingError(ReadObservationError):
# class PipeTimedOutError(ReadObservationError):
# class CoordinatorError(Exception):
# class TooManyRestartsError(CoordinatorError):
# class NotAllowedError(Exception):
# class PlayerExitedActivityError(NotAllowedError):
# class PlayerExitedViewHierarchyError(NotAllowedError):
# class AdbControllerError(Exception):
# class AdbControllerShellInitError(AdbControllerError):
# class AdbControllerPexpectError(AdbControllerError):
# class AdbControllerDeviceTimeoutError(AdbControllerError):
# class AdbControllerConnectionError(AdbControllerError):
# class AdbControllerInputDeviceNotFoundError(AdbControllerError):
# class AdbControllerScreenPinningError(AdbControllerError):
# class SimulatorCrashError(Exception):
# class ConsoleConnectionError(Exception):
# class SendActionError(Exception):
# class StepCommandError(Exception):
# class WaitForAppScreenError(StepCommandError):
# class CheckInstallError(StepCommandError):
# class WaitForMessageError(StepCommandError):


# Path: android_env/components/adb_controller.py
import os
import pathlib
import re
import subprocess
import sys
import threading
import time
import pexpect
from typing import List, Optional, Sequence, Tuple
from absl import logging
from android_env.components import errors
from android_env.proto import adb_pb2


    raise errors.AdbControllerShellInitError(
        'Failed to start ADB shell. Max number of retries reached.')

  def _wait_for_device(self,
                       max_tries: int = 20,
                       sleep_time: float = 1.0,
                       timeout: Optional[float] = None) -> None:
    """Waits for the device to be ready.

    Args:
      max_tries: Number of times to check if device is ready.
      sleep_time: Sleep time between checks, in seconds.
      timeout: A timeout to use for this operation. If not set the default
        timeout set on the constructor will be used.

    Returns:
      True if the device is ready, False if the device timed out.
    Raises:
      errors.AdbControllerDeviceTimeoutError when the device is not ready after
        exhausting `max_tries`.
    """
    num_tries = 0
    while num_tries < max_tries:
      ready = self._check_device_is_ready(timeout=timeout)
      if ready:
        logging.info('Device is ready.')
        return
      time.sleep(sleep_time)
      logging.error('Device is not ready.')

    raise errors.AdbControllerDeviceTimeoutError('Device timed out.')