コード例 #1
0
ファイル: device_manager.py プロジェクト: Machiry/ddator
def get_available_devices():
    """
    Get total number of available devices.
    :return: int: Number of available devices.
    """
    global _available_devices
    global _free_devices
    global _busy_devices
    ret_val = 0
    if _available_devices is None:
        with _devices_lock:
            _available_devices = []
            _free_devices = []
            _busy_devices = []
            for device_name in get_adb_devices():
                # if the device is emulator
                # TODO: better check?
                if device_name.startswith("emulator"):
                    dev_handler = EmulatorHandler(device_name)
                else:
                    # else, its a real device.
                    dev_handler = RealDeviceHandler(device_name)
                _available_devices.append(dev_handler)
                # initially all devices are free.
                _free_devices.append(dev_handler)
    ret_val = len(_available_devices)
    return ret_val
コード例 #2
0
ファイル: device_handler.py プロジェクト: Machiry/ddator
 def restart_device(self):
     """
     Restart the device.
     :return: True/False => Success/Failure
     """
     # restart device
     restart_device_args = ['adb', '-s', self.target_device_id, 'reboot']
     run_command(restart_device_args)
     # wait for some time.
     time.sleep(DeviceHandler.REBOOT_WAIT_TIME)
     if self.target_device_id not in get_adb_devices():
         # if the device is no, up. wait for more time.
         time.sleep(DeviceHandler.REBOOT_WAIT_TIME / 2)
     if self.target_device_id not in get_adb_devices():
         DDLogger.write_failure_message("Device:" + str(self.target_device_id) + " failed to Reboot.")
         return False
     return True