def testGetLsusbSerial(self): with self.assertCalls( (mock.call.devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout( ['lsusb'], timeout=10), (None, DEVICE_LIST)), (mock.call.devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout( ['lsusb', '-v', '-s', '003:007'], timeout=10), (None, RAW_OUTPUT))): out = lsusb.lsusb().pop() self.assertEqual(lsusb.get_lsusb_serial(out), '01d2450ea194a93b')
def reset_android_usb(serial): """Reset the USB device for the given Android device.""" lsusb_info = lsusb.lsusb() bus = None device = None for device_info in lsusb_info: device_serial = lsusb.get_lsusb_serial(device_info) if device_serial == serial: bus = int(device_info.get('bus')) device = int(device_info.get('device')) if bus and device: reset_usb(bus, device) else: raise device_errors.DeviceUnreachableError( 'Unable to determine bus or device for device %s' % serial)
def _reset_all_matching(condition): lsusb_info = lsusb.lsusb() for device_info in lsusb_info: if int(device_info.get('device')) != 1 and condition(device_info): bus = int(device_info.get('bus')) device = int(device_info.get('device')) try: reset_usb(bus, device) serial = lsusb.get_lsusb_serial(device_info) if serial: logger.info('Reset USB device (bus: %03d, device: %03d, serial: %s)', bus, device, serial) else: logger.info('Reset USB device (bus: %03d, device: %03d)', bus, device) except IOError: logger.error('Failed to reset USB device (bus: %03d, device: %03d)', bus, device)
def reset_android_usb(serial): """Reset the USB presentation.device for the given Android presentation.device.""" lsusb_info = lsusb.lsusb() bus = None presentation.device = None for device_info in lsusb_info: device_serial = lsusb.get_lsusb_serial(device_info) if device_serial == serial: bus = int(device_info.get('bus')) presentation.device = int(device_info.get('presentation.device')) if bus and presentation.device: reset_usb(bus, presentation.device) else: raise device_errors.DeviceUnreachableError( 'Unable to determine bus(%s) or presentation.device(%s) for presentation.device %s' % (bus, presentation.device, serial))
def _reset_all_matching(condition): lsusb_info = lsusb.lsusb() for device_info in lsusb_info: if int(device_info.get('device')) != 1 and condition(device_info): bus = int(device_info.get('bus')) device = int(device_info.get('device')) try: reset_usb(bus, device) serial = lsusb.get_lsusb_serial(device_info) if serial: logging.info('Reset USB device (bus: %03d, device: %03d, serial: %s)', bus, device, serial) else: logging.info('Reset USB device (bus: %03d, device: %03d)', bus, device) except IOError: logging.error( 'Failed to reset USB device (bus: %03d, device: %03d)', bus, device)
def reset_all_android_devices(): """Reset all USB devices that look like an Android device.""" _reset_all_matching(lambda i: bool(lsusb.get_lsusb_serial(i)))