Exemplo n.º 1
0
 def __init__(self,
              serial="",
              product_type=ANDROID_PRODUCT_TYPE_UNKNOWN,
              device_callback_port=5010,
              shell_default_nohup=False):
     self.serial = serial
     self._product_type = product_type
     self.device_command_port = None
     self.device_callback_port = device_callback_port
     self.log = AndroidDeviceLoggerAdapter(logging.getLogger(),
                                           {"serial": self.serial})
     base_log_path = getattr(logging, "log_path", "/tmp/logs/")
     self.log_path = os.path.join(base_log_path, "AndroidDevice%s" % serial)
     self.adb_logcat_process = None
     self.adb_logcat_file_path = None
     self.vts_agent_process = None
     self.adb = adb.AdbProxy(serial)
     self.fastboot = fastboot.FastbootProxy(serial)
     if not self.isBootloaderMode:
         self.rootAdb()
     self.host_command_port = None
     self.host_callback_port = adb.get_available_host_port()
     if self.device_callback_port >= 0:
         self.adb.reverse_tcp_forward(self.device_callback_port,
                                      self.host_callback_port)
     self.hal = None
     self.lib = None
     self.shell = None
     self.shell_default_nohup = shell_default_nohup
     self.fatal_error = False
    def startServices(self):
        """Starts long running services on the android device.

        1. Start adb logcat capture.
        2. Start VtsAgent and create HalMirror unless disabled in config.
        3. If enabled in config, start sl4a service and create sl4a clients.
        """
        enable_vts_agent = getattr(self, "enable_vts_agent", True)
        enable_sl4a = getattr(self, "enable_sl4a", False)
        try:
            self.startAdbLogcat()
        except:
            self.log.exception("Failed to start adb logcat!")
            raise
        if enable_vts_agent:
            self.startVtsAgent()
            self.device_command_port = int(
                self.adb.shell("cat /data/local/tmp/vts_tcp_server_port"))
            logging.info("device_command_port: %s", self.device_command_port)
            if not self.host_command_port:
                self.host_command_port = adb.get_available_host_port()
            self.adb.tcp_forward(self.host_command_port, self.device_command_port)
            self.hal = hal_mirror.HalMirror(self.host_command_port,
                                            self.host_callback_port)
            self.lib = lib_mirror.LibMirror(self.host_command_port)
            self.shell = shell_mirror.ShellMirror(self.host_command_port)
        if enable_sl4a:
            self.startSl4aClient()
    def startSl4aClient(self, handle_event=True):
        """Create an sl4a connection to the device.

        Return the connection handler 'droid'. By default, another connection
        on the same session is made for EventDispatcher, and the dispatcher is
        returned to the caller as well.
        If sl4a server is not started on the device, try to start it.

        Args:
            handle_event: True if this droid session will need to handle
                          events.
        """
        self._sl4a_sessions = {}
        self._sl4a_event_dispatchers = {}
        if not self.sl4a_host_port or not adb.is_port_available(self.sl4a_host_port):
            self.sl4a_host_port = adb.get_available_host_port()
        self.adb.tcp_forward(self.sl4a_host_port, self.sl4a_target_port)
        try:
            droid = self._createNewSl4aSession()
        except sl4a_client.Error:
            sl4a_client.start_sl4a(self.adb)
            droid = self._createNewSl4aSession()
        self.sl4a = droid
        if handle_event:
            ed = self._getSl4aEventDispatcher(droid)
        self.sl4a_event = ed
 def __init__(self, serial="", product_type=ANDROID_PRODUCT_TYPE_UNKNOWN,
              device_callback_port=5010):
     self.serial = serial
     self._product_type = product_type
     self.device_command_port = None
     self.device_callback_port = device_callback_port
     self.log = AndroidDeviceLoggerAdapter(logging.getLogger(),
                                           {"serial": self.serial})
     base_log_path = getattr(logging, "log_path", "/tmp/logs/")
     self.log_path = os.path.join(base_log_path, "AndroidDevice%s" % serial)
     self.adb_logcat_process = None
     self.adb_logcat_file_path = None
     self.vts_agent_process = None
     self.adb = adb.AdbProxy(serial)
     self.fastboot = fastboot.FastbootProxy(serial)
     if not self.isBootloaderMode:
         self.rootAdb()
     self.host_command_port = None
     self.host_callback_port = adb.get_available_host_port()
     self.adb.reverse_tcp_forward(self.device_callback_port,
                                  self.host_callback_port)
     self.hal = None
     self.lib = None
     self.shell = None
     self.sl4a_host_port = None
     # TODO: figure out a good way to detect which port is available
     # on the target side, instead of hard coding a port number.
     self.sl4a_target_port = 8082
Exemplo n.º 5
0
    def startServices(self):
        """Starts long running services on the android device.

        1. Start adb logcat capture.
        2. Start VtsAgent and create HalMirror unless disabled in config.
        """
        event = tfi.Begin("start vts services", tfi.categories.FRAMEWORK_SETUP)

        self.enable_vts_agent = getattr(self, "enable_vts_agent", True)
        try:
            self.startAdbLogcat()
        except Exception as e:
            msg = "Failed to start adb logcat!"
            event.Remove(msg)
            self.log.error(msg)
            self.log.exception(e)
            raise
        if self.enable_vts_agent:
            self.startVtsAgent()
            self.device_command_port = int(
                self.adb.shell("cat /data/local/tmp/vts_tcp_server_port"))
            logging.debug("device_command_port: %s", self.device_command_port)
            if not self.host_command_port:
                self.host_command_port = adb.get_available_host_port()
            self.adb.tcp_forward(self.host_command_port,
                                 self.device_command_port)
            self.hal = mirror_tracker.MirrorTracker(self.host_command_port,
                                                    self.host_callback_port,
                                                    True)
            self.lib = mirror_tracker.MirrorTracker(self.host_command_port)
            self.shell = mirror_tracker.MirrorTracker(
                host_command_port=self.host_command_port, adb=self.adb)
            self.shell.shell_default_nohup = self.shell_default_nohup
            self.resource = mirror_tracker.MirrorTracker(
                self.host_command_port)
        event.End()