1"""
2  Copyright (C) 2023 The Android Open Source Project
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16
17
18  Test Steps:
19  (0. Flash device)
20    1. Navigate to the Bluetooth settings page
21    2. Disconnect - Connect Mobile Device via Layer1 - via Bluetooth Button
22    3. Tap Device to see DisconnectedStatus in Layer2
23    4. Reconnect - Via layer 1
24    5. Tap device to see Connected status in Layer2
25
26    "Layer Two" represents the device-specific screen (the screen you see when clicking the device in the bluetooth settings page.
27
28"""
29
30import logging
31
32from bluetooth_test import bluetooth_base_test
33from mobly import asserts
34
35from utilities import constants
36from utilities.main_utils import common_main
37
38MOBILE_DEVICE_NAME = 'target'
39AUTOMOTIVE_DEVICE_NAME = 'discoverer'
40
41
42class BluetoothConnectionStatusOnLevelTwo(bluetooth_base_test.BluetoothBaseTest):
43
44    def setup_test(self):
45        # Enables BT on both devices.
46        super().setup_test()
47        # Set Bluetooth name on target device.
48        self.target.mbs.btSetName(MOBILE_DEVICE_NAME)
49
50        self.bt_utils.pair_primary_to_secondary()
51        self.call_utils.wait_with_log(constants.DEVICE_CONNECT_WAIT_TIME)
52        super().enable_recording()
53
54    def test_connection_status_displayed_on_device_screen(self):
55        # Log BT Connection State after pairing
56        bt_connection_state=self.call_utils.get_bt_connection_status_using_adb_command(self.discoverer)
57        logging.info("BT State after pairing : <%s>", bt_connection_state)
58
59        # Open bluetooth settings.
60        self.call_utils.open_bluetooth_settings_form_status_bar()
61        self.call_utils.wait_with_log(2)
62
63        # Find the target device and disconnect it on the Level One page
64        self.call_utils.press_bluetooth_toggle_on_device(MOBILE_DEVICE_NAME)
65        self.call_utils.wait_with_log(2)
66
67        # Click on the target device.
68        self.call_utils.press_device_entry_on_list_of_paired_devices(MOBILE_DEVICE_NAME)
69        self.call_utils.wait_with_log(2)
70
71        # Confirm that target device displays "disconnected"
72        summary = self.call_utils.get_device_summary()
73        logging.info("Summary received reads: %s" % summary)
74        asserts.assert_true((constants.DISCONNECTED_SUMMARY_STATUS in summary),
75                            "Expected summary  to contain %s, but instead summary reads: %s"
76                            % (constants.DISCONNECTED_SUMMARY_STATUS, summary))
77
78
79if __name__ == '__main__':
80    common_main()
81