def __init__(self, device_serial=None, is_emulator=True, output_dir=None, grant_perm=False, telnet_auth_token=None): """ initialize a device connection :param device_serial: serial number of target device :param is_emulator: boolean, type of device, True for emulator, False for real device :return: """ self.logger = logging.getLogger(self.__class__.__name__) if device_serial is None: import utils all_devices = utils.get_available_devices() if len(all_devices) == 0: self.logger.warning("ERROR: No device connected.") sys.exit(-1) device_serial = all_devices[0] self.serial = device_serial self.is_emulator = is_emulator self.output_dir = output_dir if output_dir is not None: if not os.path.isdir(output_dir): os.mkdir(output_dir) self.grant_perm = grant_perm # basic device information self.settings = {} self.display_info = None self.model_number = None self.sdk_version = None self.release_version = None self.ro_debuggable = None self.ro_secure = None self.connected = True self.last_know_state = None self.__used_ports = [] self.pause_sending_event = False # adapters self.adb = ADB(device=self) self.telnet = TelnetConsole(device=self, auth_token=telnet_auth_token) self.droidbot_app = DroidBotAppConn(device=self) self.minicap = Minicap(device=self) self.logcat = Logcat(device=self) self.user_input_monitor = UserInputMonitor(device=self) self.process_monitor = ProcessMonitor(device=self) self.droidbot_ime = DroidBotIme(device=self) self.adapters = { self.adb: True, self.telnet: False, self.droidbot_app: True, self.minicap: True, self.logcat: True, self.user_input_monitor: True, self.process_monitor: True, self.droidbot_ime: True }
def get_telnet(self): """ get telnet connection of the device note that only emulator have telnet connection """ if self.telnet_enabled and self.telnet is None: from adapter.telnet import TelnetConsole, TelnetException try: self.telnet = TelnetConsole(self) except TelnetException: self.logger.warning("Cannot connect to telnet.") return self.telnet
def __init__(self, device_serial=None, is_emulator=False, output_dir=None, cv_mode=False, grant_perm=False, telnet_auth_token=None, enable_accessibility_hard=False, humanoid=None, ignore_ad=False): """ initialize a device connection :param device_serial: serial number of target device :param is_emulator: boolean, type of device, True for emulator, False for real device :return: """ self.logger = logging.getLogger(self.__class__.__name__) if device_serial is None: from utils import get_available_devices all_devices = get_available_devices() if len(all_devices) == 0: self.logger.warning("ERROR: No device connected.") sys.exit(-1) device_serial = all_devices[0] if "emulator" in device_serial and not is_emulator: self.logger.warning("Seems like you are using an emulator. If so, please add is_emulator option.") self.serial = device_serial self.is_emulator = is_emulator self.cv_mode = cv_mode self.output_dir = output_dir if output_dir is not None: if not os.path.isdir(output_dir): os.makedirs(output_dir) self.grant_perm = grant_perm self.enable_accessibility_hard = enable_accessibility_hard self.humanoid = humanoid self.ignore_ad = ignore_ad # basic device information self.settings = {} self.display_info = None self.model_number = None self.sdk_version = None self.release_version = None self.ro_debuggable = None self.ro_secure = None self.connected = True self.last_know_state = None self.__used_ports = [] self.pause_sending_event = False # adapters self.adb = ADB(device=self) self.telnet = TelnetConsole(device=self, auth_token=telnet_auth_token) self.droidbot_app = DroidBotAppConn(device=self) self.minicap = Minicap(device=self) self.logcat = Logcat(device=self) self.user_input_monitor = UserInputMonitor(device=self) self.process_monitor = ProcessMonitor(device=self) self.droidbot_ime = DroidBotIme(device=self) self.adapters = { self.adb: True, self.telnet: False, self.droidbot_app: True, self.minicap: True, self.logcat: True, self.user_input_monitor: True, self.process_monitor: True, self.droidbot_ime: True } # minicap currently not working on emulators if self.is_emulator: self.logger.info("disable minicap on emulator") self.adapters[self.minicap] = False