1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import dbus 6 7from autotest_lib.client.common_lib import utils 8from autotest_lib.client.common_lib.cros import dbus_send 9from autotest_lib.client.common_lib.cros.cfm.usb import usb_device_collector 10from autotest_lib.client.common_lib.cros.cfm.usb import cfm_usb_devices 11 12ATRUS = cfm_usb_devices.ATRUS 13 14def check_dbus_available(): 15 """ 16 Checks if Atrusd with dbus support is available. 17 18 @returns True if dbus is supported in atrusd. False otherwise. 19 """ 20 result = dbus_send.dbus_send( 21 'org.freedesktop.DBus', 22 'org.freedesktop.DBus', 23 '/org/freedesktop/DBus', 24 'ListNames', 25 args=None, 26 timeout_seconds=2, 27 tolerate_failures=False) 28 29 return 'org.chromium.Atrusctl' in result.response 30 31def force_upgrade_atrus(): 32 """ 33 Executes a forced upgrade of the Atrus device. 34 35 @returns True if the upgrade succeeded. False otherwise. 36 """ 37 args = [dbus.String('/lib/firmware/google/atrus-fw-bundle-latest.bin')] 38 result = dbus_send.dbus_send( 39 'org.chromium.Atrusctl', 40 'org.chromium.Atrusctl', 41 '/org/chromium/Atrusctl', 42 'ForceFirmwareUpgrade', 43 args=args, 44 timeout_seconds=90, 45 tolerate_failures=True) 46 47 return result.response 48 49def wait_for_atrus_enumeration(timeout_seconds=30): 50 """ 51 Wait for an Atrus device to enumerate. 52 53 @param timeout_seconds: Maximum number of seconds to wait. 54 """ 55 device_manager = usb_device_collector.UsbDeviceCollector() 56 utils.poll_for_condition( 57 lambda: len(device_manager.get_devices_by_spec(ATRUS)) >= 1, 58 timeout=timeout_seconds, 59 sleep_interval=1.0, 60 desc='No atrus device enumerated')