• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Bluetooth Base Test
3
4This test class serves as a base class for others to inherit from.
5It also serves as a device-cleaner to help reset devices between tests.
6
7"""
8
9import logging
10
11from mobly import base_test
12from mobly.controllers import android_device
13from mobly.controllers.android_device_lib.snippet_client_v2 import Config
14
15from utilities import spectatio_utils
16from utilities import bt_utils
17from utilities.main_utils import common_main, get_test_args
18from utilities.video_utils_service import VideoRecording
19
20
21class BluetoothBaseTest(base_test.BaseTestClass):
22
23    def setup_class(self):
24        # Registering android_device controller module, and declaring that the test
25        # requires at least two Android devices.
26        # This setup will need to be overwritten or extended if a test uses three devices.
27        logging.info("Running basic class setup.")
28        self.ads = self.register_controller(android_device, min_number=2)
29        # The device used to discover Bluetooth devices.
30        self.discoverer = android_device.get_device(
31            self.ads, label='auto')
32        # Sets the tag that represents this device in logs.
33        self.discoverer.debug_tag = 'discoverer'
34        # The device that is expected to be discovered
35        self.target = android_device.get_device(self.ads, label='phone')
36        self.target.debug_tag = 'target'
37
38        test_args = get_test_args(shell_escape=True)
39        logging.info("\tLoading Snippets.  Test args = {}".format(test_args))
40        snippet_config = Config(am_instrument_options=test_args)
41        logging.info("\tSnippet config: {}".format(snippet_config))
42        self.target.load_snippet('mbs', android_device.MBS_PACKAGE, config=snippet_config)
43        self.discoverer.load_snippet('mbs', android_device.MBS_PACKAGE, config=snippet_config)
44
45        logging.info("\tInitializing Utilities")
46        self.call_utils = (spectatio_utils.CallUtils(self.discoverer))
47        self.bt_utils = (bt_utils.BTUtils(self.discoverer, self.target))
48
49        logging.info("\tInitializing video services on HU")
50        self.video_utils_service = VideoRecording(self.discoverer, self.__class__.__name__)
51        logging.info("\tInitializing video services on target")
52        self.video_utils_service_target = VideoRecording(self.target, self.__class__.__name__)
53
54    def setup_test(self):
55        # Make sure bluetooth is on.
56        self.call_utils.press_home()
57        logging.info("Running basic test setup.")
58        logging.info("\tEnabling bluetooth on Target and Discoverer.")
59        self.target.mbs.btEnable()
60        self.discoverer.mbs.btEnable()
61
62    def teardown_test(self):
63        # Turn Bluetooth off on both devices.
64        logging.info("Running basic test teardown.")
65        self.call_utils.press_home()
66        self.call_utils.press_phone_home_icon_using_adb_command(self.target)
67        self.hu_recording_handler()
68        self.bt_utils.unpair()
69        logging.info("Disable Bluetooth on Discoverer device")
70        self.discoverer.mbs.btDisable()
71        logging.info("Disable Bluetooth on Target device")
72        self.target.mbs.btDisable()
73
74    def teardown_no_video_recording(self):
75        # Turn Bluetooth off on both devices.
76        logging.info("Running basic test teardown.")
77        self.call_utils.press_home()
78        self.call_utils.press_phone_home_icon_using_adb_command(self.target)
79        self.bt_utils.unpair()
80        logging.info("Disable Bluetooth on Discoverer device")
81        self.discoverer.mbs.btDisable()
82        logging.info("Disable Bluetooth on Target device")
83        self.target.mbs.btDisable()
84
85
86    def hu_recording_handler(self):
87        logging.info("Stopping the screen recording on Discoverer Device")
88        self.video_utils_service.stop_screen_recording()
89        logging.info("Pull the screen recording from Discoverer device")
90        self.video_utils_service.pull_recording_file(self.log_path)
91        logging.info("delete the screen recording from the Discoverer device")
92        self.video_utils_service.delete_screen_recording_from_device()
93
94        logging.info("Stopping the screen recording on Target Device")
95        self.video_utils_service_target.stop_screen_recording()
96        logging.info("Pull the screen recording from Target device")
97        self.video_utils_service_target.pull_recording_file(self.log_path)
98        logging.info("delete the screen recording from the Target device")
99        self.video_utils_service_target.delete_screen_recording_from_device()
100
101    def enable_recording(self):
102        logging.info("Enabling video recording for Discoverer device")
103        self.video_utils_service.enable_screen_recording()
104        logging.info("Enabling video recording for Target device")
105        self.video_utils_service_target.enable_screen_recording()
106        logging.info("Video recording started on Discoverer and Target")
107
108if __name__ == '__main__':
109    common_main()
110