def adb_disconnect(self, serial):
        msg = self.adb_client.disconnect(serial)
        if msg:
            logger.info(msg)

        del_cached_property(self, 'hermit_session')
        del_cached_property(self, 'minitouch_builder')
Exemple #2
0
 def adb_restart(self):
     """
         Reboot adb client
     """
     logger.info('Restart adb')
     # Kill current client
     self.adb_client.server_kill()
     # Init adb client
     del_cached_property(self, 'adb_client')
     _ = self.adb_client
Exemple #3
0
 def reverse_server(self):
     """
     Setup a server on Alas, access it from emulator.
     This will bypass adb shell and be faster.
     """
     del_cached_property(self, '_nc_server_host_port')
     host_port = self._nc_server_host_port
     logger.info(
         f'Reverse server listening on {host_port[0]}:{host_port[1]}, '
         f'client can send data to {host_port[2]}:{host_port[3]}')
     server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     server.bind(host_port[:2])
     server.listen(5)
     return server
 def init():
     del_cached_property(self, 'minitouch_builder')
 def init():
     self.restart_atx()
     if self._minitouch_port:
         self.adb_forward_remove(f'tcp:{self._minitouch_port}')
     del_cached_property(self, 'minitouch_builder')
 def init():
     self.install_uiautomator2()
     if self._minitouch_port:
         self.adb_forward_remove(f'tcp:{self._minitouch_port}')
     del_cached_property(self, 'minitouch_builder')
Exemple #7
0
    def detect_device(self):
        """
        Find available devices
        If serial=='auto' and only 1 device detected, use it
        """
        logger.hr('Detect device')
        logger.info(
            'Here are the available devices, '
            'copy to Alas.Emulator.Serial to use it or set Alas.Emulator.Serial="auto"'
        )
        devices = self.list_device()

        # Show available devices
        available = devices.select(status='device')
        for device in available:
            logger.info(device.serial)
        if not len(available):
            logger.info('No available devices')

        # Show unavailable devices if having any
        unavailable = devices.delete(available)
        if len(unavailable):
            logger.info('Here are the devices detected but unavailable')
            for device in unavailable:
                logger.info(f'{device.serial} ({device.status})')

        # Auto device detection
        if self.config.Emulator_Serial == 'auto':
            if available.count == 0:
                logger.critical(
                    'No available device found, auto device detection cannot work, '
                    'please set an exact serial in Alas.Emulator.Serial instead of using "auto"'
                )
                raise RequestHumanTakeover
            elif available.count == 1:
                logger.info(
                    f'Auto device detection found only one device, using it')
                self.serial = devices[0].serial
                del_cached_property(self, 'adb')
            else:
                logger.critical(
                    'Multiple devices found, auto device detection cannot decide which to choose, '
                    'please copy one of the available devices listed above to Alas.Emulator.Serial'
                )
                raise RequestHumanTakeover

        # Handle LDPlayer
        # LDPlayer serial jumps between `127.0.0.1:5555+{X}` and `emulator-5554+{X}`
        port_serial, emu_serial = get_serial_pair(self.serial)
        if port_serial and emu_serial:
            # Might be LDPlayer, check connected devices
            port_device = devices.select(serial=port_serial).first_or_none()
            emu_device = devices.select(serial=emu_serial).first_or_none()
            if port_device and emu_device:
                # Paired devices found, check status to get the correct one
                if port_device.status == 'device' and emu_device.status == 'offline':
                    self.serial = port_serial
                    logger.info(
                        f'LDPlayer device pair found: {port_device}, {emu_device}. '
                        f'Using serial: {self.serial}')
                elif port_device.status == 'offline' and emu_device.status == 'device':
                    self.serial = emu_serial
                    logger.info(
                        f'LDPlayer device pair found: {port_device}, {emu_device}. '
                        f'Using serial: {self.serial}')
            elif not devices.select(serial=self.serial):
                # Current serial not found
                if port_device and not emu_device:
                    logger.info(
                        f'Current serial {self.serial} not found but paired device {port_serial} found. '
                        f'Using serial: {port_serial}')
                    self.serial = port_serial
                if not port_device and emu_device:
                    logger.info(
                        f'Current serial {self.serial} not found but paired device {emu_serial} found. '
                        f'Using serial: {emu_serial}')
                    self.serial = emu_serial