1"""
2  Copyright (C) 2024 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. Verify by default BT should be ON always
21  2. Disable Phone Button from Bluetooth Settings Page
22  3. Disable Bluetooth Button and enable Bluetooth
23  4. Verify After reconnecting Bluetooth - Phone-HFP remains disabled and not displayed
24
25"""
26
27import logging
28
29from mobly import asserts
30from utilities.main_utils import common_main
31from bluetooth_test import bluetooth_base_test
32from utilities import constants
33
34class BluetoothDisablePhoneAfterReconnectTest(bluetooth_base_test.BluetoothBaseTest):
35
36    def setup_test(self):
37        # Pair the devices
38        self.bt_utils.pair_primary_to_secondary()
39        super().enable_recording()
40        self.call_utils.press_home()
41
42    def test_disable_enable_phone(self):
43        # Log BT Connection State after pairing
44        bt_connection_state=self.call_utils.get_bt_connection_status_using_adb_command(self.discoverer)
45        logging.info("BT State after pairing : <%s>", bt_connection_state)
46
47        # Navigate to the bluetooth settings page
48        self.call_utils.open_bluetooth_settings_form_status_bar()
49        target_name = self.target.mbs.btGetName()
50        # Disable phone for the listed paired device via the preference button
51        self.call_utils.press_phone_toggle_on_device(target_name)
52        self.call_utils.wait_with_log(5)
53        # Confirm that the phone button is unchecked
54        asserts.assert_false(
55            self.discoverer.mbs.isPhonePreferenceChecked(),
56            "Expected phone button to be unchecked after pressing it.")
57
58        # Tap Bluetooth button to Disable Bluetooth
59        self.call_utils.press_bluetooth_toggle_on_device(self.target.mbs.btGetName())
60        self.call_utils.wait_with_log(5)
61        # Tap Grey Bluetooth Button to Enable Bluetooth
62        self.call_utils.press_bluetooth_toggle_on_device(self.target.mbs.btGetName())
63        self.call_utils.wait_with_log(10)
64        # After reconnecting Bluetooth - Confirm that the phone button is unchecked
65        asserts.assert_false(
66            self.discoverer.mbs.isPhonePreferenceChecked(),
67            "Expected phone button to be unchecked after pressing it.")
68
69        self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIVE_SECS)
70
71        # Go back to the bluetooth settings page and enable phone via the preference button
72        self.call_utils.press_home()
73        self.call_utils.open_bluetooth_settings()
74        self.call_utils.press_phone_toggle_on_device(target_name)
75
76        # Confirm that the phone button is re-enabled
77        asserts.assert_true(
78            self.discoverer.mbs.isPhonePreferenceChecked(),
79            "Expected phone button to be checked after pressing it a second time.")
80
81if __name__ == '__main__':
82    # Take test args
83    common_main()