1"""Base class for automated android tests."""
2
3
4
5from mobly import base_test
6from mobly import logger
7from mobly.controllers import android_device
8from mobly.controllers.android_device_lib import adb
9
10ANDROID_SNIPPET_PACKAGE = 'com.google.android.test'
11
12
13class AndroidBaseTest(base_test.BaseTestClass):
14
15  def log_bt_stack_conf(self, device):
16    try:
17      bt_stack_conf = device.adb.shell(['cat', '/etc/bluetooth/bt_stack.conf'])
18    except adb.AdbError:
19      device.log.debug('No /etc/bluetooth/bt_stack.conf file found on device.')
20    else:
21      device.log.debug('Content of /etc/bluetooth/bt_stack.conf: %s',
22                       bt_stack_conf)
23
24  def setup_class(self):
25    # Registering android_device controller module, and declaring that the test
26    # requires at least two Android devices.
27    self.ads = self.register_controller(android_device, min_number=2)
28    self.dut_a = self.ads[0]
29    self.dut_b = self.ads[1]
30    self.dut_a.load_snippet('android', ANDROID_SNIPPET_PACKAGE)
31    self.dut_b.load_snippet('android', ANDROID_SNIPPET_PACKAGE)
32    self.log_bt_stack_conf(self.dut_a)
33    self.log_bt_stack_conf(self.dut_b)
34
35  def on_fail(self, record):
36    """Only executed after a test fails.
37
38    Collect debug info here.
39
40    Args:
41      record: a copy of the test result record of the test.
42    """
43    begin_time = logger.epoch_to_log_line_timestamp(record.begin_time)
44    android_device.take_bug_reports([self.dut_a, self.dut_b], record.test_name,
45                                    begin_time)
46