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. Verify by default BT should be ON always 21 2. BluetoothManagerService: Startup: Bluetooth persisted state is ON 22 23""" 24 25import logging 26 27from mobly import asserts 28from utilities.main_utils import common_main 29from bluetooth_test import bluetooth_base_test 30from utilities import constants 31 32class BluetoothDisableEnablePhoneTest(bluetooth_base_test.BluetoothBaseTest): 33 34 NO_PHONE_TAG = 'no phone' 35 36 def setup_test(self): 37 # Pair the devices 38 self.bt_utils.pair_primary_to_secondary() 39 super().enable_recording() 40 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() 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 53 54 # Confirm that the phone button is unchecked 55 asserts.assert_false( 56 self.discoverer.mbs.isPhonePreferenceChecked(), 57 "Expected phone button to be unchecked after pressing it.") 58 self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIVE_SECS) 59 60 61 # Click on device and confirm that the summary says "No phone" 62 self.discoverer.mbs.pressDeviceInBluetoothSettings(target_name) 63 self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD) 64 summary = self.discoverer.mbs.getDeviceSummary() 65 asserts.assert_true( 66 self.NO_PHONE_TAG in summary, 67 ("Expected device summary (on Level Two page) to include \'%s\'" 68 % self.NO_PHONE_TAG) 69 ) 70 self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIVE_SECS) 71 72 # Go back to the bluetooth settings page and enable phone via the preference button 73 self.call_utils.press_home() 74 self.call_utils.open_bluetooth_settings() 75 self.call_utils.press_phone_toggle_on_device(target_name) 76 77 # Confirm that the phone button is re-enabled 78 asserts.assert_true( 79 self.discoverer.mbs.isPhonePreferenceChecked(), 80 "Expected phone button to be checked after pressing it a second time.") 81 82 # Click on the device and confirm that the summary doesn't include "phone" 83 self.discoverer.mbs.pressDeviceInBluetoothSettings(target_name) 84 self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD) 85 summary = self.discoverer.mbs.getDeviceSummary() 86 asserts.assert_false( 87 self.NO_PHONE_TAG in summary, 88 "Found unexpected \'%s\' in device summary after re-enabling phone." 89 % self.NO_PHONE_TAG 90 ) 91 92 93 94if __name__ == '__main__': 95 # Take test args 96 common_main()