blob: 8e030c2ac178223fca3e4f12991c71c44c90547c [file] [log] [blame]
Eric Caruso1034fb42014-12-17 17:26:37 -08001# Copyright 2014 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 logging
6
7POWER_DIR = '/var/lib/power_manager'
8TMP_POWER_DIR = '/tmp/power_manager'
9POWER_DEFAULTS = '/usr/share/power_manager/board_specific'
10
11
12def dark_resume_setup(host):
13 """Set up powerd preferences so we will properly go into dark resume,
14 and still be able to communicate with the DUT.
15
16 @param host: the DUT to set up dark resume for
17
18 """
19 logging.info('Setting up dark resume preferences')
20
21 # Make temporary directory, which will be used to hold
22 # temporary preferences. We want to avoid writing into
23 # /var/lib so we don't have to save any state.
24 logging.debug('Creating temporary powerd prefs at %s', TMP_POWER_DIR)
25 host.run('mkdir -p %s' % TMP_POWER_DIR)
26
27 logging.debug('Enabling dark resume')
28 host.run('echo 0 > %s/disable_dark_resume' % TMP_POWER_DIR)
29
30 logging.debug('Enabling USB ports in dark resume')
31
32 dev_contents = host.run('cat %s/dark_resume_devices' % POWER_DEFAULTS,
33 ignore_status=True).stdout
34 dev_list = dev_contents.split('\n')
35 new_dev_list = filter(lambda dev: dev.find('usb') == -1, dev_list)
36 new_dev_contents = '\n'.join(new_dev_list)
37 host.run('echo -e \'%s\' > %s/dark_resume_devices' %
38 (new_dev_contents, TMP_POWER_DIR))
39
40 # bind the tmp directory to the power preference directory
41 host.run('mount --bind %s %s' % (TMP_POWER_DIR, POWER_DIR))
42
43 logging.debug('Restarting powerd with new settings')
44 host.run('restart powerd')
45
46
47def dark_resume_teardown(host):
48 """Clean up changes made by dark_resume_setup.
49
50 @param host: the DUT to remove dark resume prefs for
51
52 """
53 logging.info('Tearing down dark resume preferences')
54
55 logging.debug('Cleaning up temporary powerd bind mounts')
56 host.run('umount %s' % POWER_DIR, ignore_status=True)
57
58 logging.debug('Restarting powerd to revert to old settings')
59 host.run('restart powerd')