Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 1 | #/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 16 | """ |
| 17 | Test the HFP profile for basic calling functionality. |
| 18 | """ |
| 19 | |
| 20 | import time |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 21 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 22 | from acts.test_utils.bt.BluetoothCarHfpBaseTest import BluetoothCarHfpBaseTest |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 23 | from acts.test_utils.bt import BtEnum |
| 24 | from acts.test_utils.bt import bt_test_utils |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 25 | from acts.test_utils.car import car_telecom_utils |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 26 | from acts.test_utils.car import tel_telecom_utils |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 27 | from acts.test_utils.tel import tel_defines |
| 28 | |
| 29 | BLUETOOTH_PKG_NAME = "com.android.bluetooth" |
| 30 | CALL_TYPE_OUTGOING = "CALL_TYPE_OUTGOING" |
| 31 | CALL_TYPE_INCOMING = "CALL_TYPE_INCOMING" |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 32 | SHORT_TIMEOUT = 5 |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 33 | |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 34 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 35 | class BtCarHfpTest(BluetoothCarHfpBaseTest): |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 36 | def setup_class(self): |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 37 | if not super(BtCarHfpTest, self).setup_class(): |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 38 | return False |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 39 | # Disable the A2DP profile. |
| 40 | bt_test_utils.set_profile_priority( |
| 41 | self.hf, self.ag, [BtEnum.BluetoothProfile.PBAP_CLIENT.value, |
Sanket Agarwal | 99f300a | 2016-09-07 17:06:33 -0700 | [diff] [blame] | 42 | BtEnum.BluetoothProfile.A2DP_SINK.value], |
| 43 | BtEnum.BluetoothPriorityLevel.PRIORITY_OFF) |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 44 | bt_test_utils.set_profile_priority( |
| 45 | self.hf, self.ag, [BtEnum.BluetoothProfile.HEADSET_CLIENT.value], |
| 46 | BtEnum.BluetoothPriorityLevel.PRIORITY_ON) |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 47 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 48 | if not bt_test_utils.connect_pri_to_sec(self.hf, self.ag, set( |
| 49 | [BtEnum.BluetoothProfile.HEADSET_CLIENT.value])): |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 50 | self.log.error("Failed to connect") |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 51 | # Additional profile connection check |
| 52 | if bt_test_utils.is_hfp_client_device_connected( |
| 53 | self.hf, self.ag.droid.bluetoothGetLocalAddress()): |
| 54 | self.log.info( |
| 55 | "HFP Client connected even though connection state changed " |
| 56 | + " event not found") |
| 57 | else: |
| 58 | return False |
| 59 | return True |
Sanket Agarwal | bd9689b | 2016-08-24 11:14:53 -0700 | [diff] [blame] | 60 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 61 | #@BluetoothTest(UUID=4ce2195a-b70a-4584-912e-cbd20d20e19d) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 62 | @BluetoothBaseTest.bt_test_wrap |
| 63 | def test_default_calling_account(self): |
| 64 | """ |
| 65 | Tests if the default calling account is coming from the |
| 66 | bluetooth pacakge. |
| 67 | |
| 68 | Precondition: |
| 69 | 1. Devices are connected. |
| 70 | |
| 71 | Steps: |
| 72 | 1. Check if the default calling account is via Bluetooth package. |
| 73 | |
| 74 | Returns: |
| 75 | Pass if True |
| 76 | Fail if False |
| 77 | |
| 78 | Priority: 0 |
| 79 | """ |
| 80 | selected_acc = \ |
| 81 | self.hf.droid.telecomGetUserSelectedOutgoingPhoneAccount() |
| 82 | if not selected_acc: |
| 83 | self.log.info("No default account found.") |
| 84 | return False |
| 85 | |
| 86 | # Check if the default account is from the Bluetooth package. This is a |
| 87 | # light weight check. |
| 88 | try: |
| 89 | acc_component_id = selected_acc['ComponentName'] |
| 90 | except KeyError: |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 91 | self.log.info("No component name for account {}".format( |
| 92 | selected_acc)) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 93 | return False |
| 94 | if not acc_component_id.startswith(BLUETOOTH_PKG_NAME): |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 95 | self.log.info("Component name does not start with pkg name {}". |
| 96 | format(selected_acc)) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 97 | return False |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 98 | return True |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 99 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 100 | #@BluetoothTest(UUID=e579009d-05f3-4236-a698-5de8c11d73a9) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 101 | @BluetoothBaseTest.bt_test_wrap |
| 102 | def test_outgoing_call_hf(self): |
| 103 | """ |
| 104 | Tests if we can make a phone call from HF role and disconnect from HF |
| 105 | role. |
| 106 | |
| 107 | Precondition: |
| 108 | 1. Devices are connected. |
| 109 | |
| 110 | Steps: |
| 111 | 1. Make a call from HF role. |
| 112 | 2. Wait for the HF, AG to be dialing and RE to see the call ringing. |
| 113 | 3. Hangup the call on HF role. |
| 114 | 4. Wait for all devices to hangup the call. |
| 115 | |
| 116 | Returns: |
| 117 | Pass if True |
| 118 | Fail if False |
| 119 | |
| 120 | Priority: 0 |
| 121 | """ |
| 122 | return self.dial_a_hangup_b(self.hf, self.hf) |
| 123 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 124 | #@BluetoothTest(UUID=c9d5f9cd-f275-4adf-b212-c2e9a70d4cac) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 125 | @BluetoothBaseTest.bt_test_wrap |
| 126 | def test_outgoing_call_ag(self): |
| 127 | """ |
| 128 | Tests if we can make a phone call from AG role and disconnect from AG |
| 129 | role. |
| 130 | |
| 131 | Precondition: |
| 132 | 1. Devices are connected. |
| 133 | |
| 134 | Steps: |
| 135 | 1. Make a call from AG role. |
| 136 | 2. Wait for the HF, AG to be in dialing and RE to see the call ringing. |
| 137 | 3. Hangup the call on AG role. |
| 138 | 4. Wait for all devices to hangup the call. |
| 139 | |
| 140 | Returns: |
| 141 | Pass if True |
| 142 | Fail if False |
| 143 | |
| 144 | Priority: 0 |
| 145 | """ |
| 146 | return self.dial_a_hangup_b(self.ag, self.ag) |
| 147 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 148 | #@BluetoothTest(UUID=908c199b-ca65-4694-821d-1b864ee3fe69) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 149 | @BluetoothBaseTest.bt_test_wrap |
| 150 | def test_outgoing_dial_ag_hangup_hf(self): |
| 151 | """ |
| 152 | Tests if we can make a phone call from AG role and disconnect from HF |
| 153 | role. |
| 154 | |
| 155 | Precondition: |
| 156 | 1. Devices are connected. |
| 157 | |
| 158 | Steps: |
| 159 | 1. Make a call from AG role. |
| 160 | 2. Wait for the HF, AG to show dialing and RE to see the call ringing. |
| 161 | 3. Hangup the call on HF role. |
| 162 | 4. Wait for all devices to hangup the call. |
| 163 | |
| 164 | Returns: |
| 165 | Pass if True |
| 166 | Fail if False |
| 167 | |
| 168 | Priority: 0 |
| 169 | """ |
| 170 | return self.dial_a_hangup_b(self.ag, self.hf) |
| 171 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 172 | #@BluetoothTest(UUID=5d1d52c7-51d8-4c82-b437-2e91a6220db3) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 173 | @BluetoothBaseTest.bt_test_wrap |
| 174 | def test_outgoing_dial_hf_hangup_ag(self): |
| 175 | """ |
| 176 | Tests if we can make a phone call from HF role and disconnect from AG |
| 177 | role. |
| 178 | |
| 179 | Precondition: |
| 180 | 1. Devices are connected. |
| 181 | |
| 182 | Steps: |
| 183 | 1. Make a call from HF role. |
| 184 | 2. Wait for the HF, AG to show dialing and RE to see the call ringing. |
| 185 | 3. Hangup the call on AG role. |
| 186 | 4. Wait for all devices to hangup the call. |
| 187 | |
| 188 | Returns: |
| 189 | Pass if True |
| 190 | Fail if False |
| 191 | |
| 192 | Priority: 0 |
| 193 | """ |
| 194 | return self.dial_a_hangup_b(self.hf, self.ag) |
| 195 | |
Phillip Walker | 827112a | 2016-09-08 16:27:19 -0700 | [diff] [blame] | 196 | #@BluetoothTest(UUID=a718e238-7e31-40c9-a45b-72081210cc73) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 197 | @BluetoothBaseTest.bt_test_wrap |
| 198 | def test_incoming_dial_re_hangup_re(self): |
| 199 | """ |
| 200 | Tests if we can make a phone call from remote and disconnect from |
| 201 | remote. |
| 202 | |
| 203 | Precondition: |
| 204 | 1. Devices are connected. |
| 205 | |
| 206 | Steps: |
| 207 | 1. Make a call from RE role. |
| 208 | 2. Wait for the HF, AG to show ringing and RE to see the call dialing. |
| 209 | 3. Hangup the call on RE role. |
| 210 | 4. Wait for all devices to hangup the call. |
| 211 | |
| 212 | Returns: |
| 213 | Pass if True |
| 214 | Fail if False |
| 215 | |
| 216 | Priority: 0 |
| 217 | """ |
| 218 | return self.dial_a_hangup_b(self.re, self.re, self.ag_phone_number) |
| 219 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 220 | def dial_a_hangup_b(self, caller, callee, ph=""): |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 221 | """ |
| 222 | a, b and c can be either of AG, HF or Remote. |
| 223 | 1. Make a call from 'a' on a fixed number. |
| 224 | 2. Wait for the call to get connected (check on both 'a' and 'b') |
| 225 | Check that 'c' is in ringing state. |
| 226 | 3. Hangup the call on 'b'. |
| 227 | 4. Wait for call to get completely disconnected |
| 228 | (check on both 'a' and 'b') |
| 229 | It is assumed that scenarios will not go into voice mail. |
| 230 | """ |
| 231 | if ph == "": ph = self.re_phone_number |
| 232 | |
| 233 | # Determine if this is outgoing or incoming call. |
| 234 | call_type = None |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 235 | if caller == self.ag or caller == self.hf: |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 236 | call_type = CALL_TYPE_OUTGOING |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 237 | if callee != self.ag and callee != self.hf: |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 238 | self.log.info("outgoing call should terminate at AG or HF") |
| 239 | return False |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 240 | elif caller == self.re: |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 241 | call_type = CALL_TYPE_INCOMING |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 242 | if callee != self.re: |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 243 | self.log.info("Incoming call should terminate at Re") |
| 244 | return False |
| 245 | |
| 246 | self.log.info("Call type is {}".format(call_type)) |
| 247 | |
| 248 | # make a call on 'a' |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 249 | if not tel_telecom_utils.dial_number(self.log, caller, ph): |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 250 | return False |
| 251 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 252 | # Give time for state to update due to carrier limitations |
| 253 | time.sleep(SHORT_TIMEOUT) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 254 | # Check that everyone is in dialing/ringing state. |
| 255 | ret = True |
| 256 | if call_type == CALL_TYPE_OUTGOING: |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 257 | ret &= tel_telecom_utils.wait_for_dialing(self.log, self.hf) |
| 258 | ret &= tel_telecom_utils.wait_for_dialing(self.log, self.ag) |
| 259 | ret &= tel_telecom_utils.wait_for_ringing(self.log, self.re) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 260 | else: |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 261 | ret &= tel_telecom_utils.wait_for_ringing(self.log, self.hf) |
| 262 | ret &= tel_telecom_utils.wait_for_ringing(self.log, self.ag) |
| 263 | ret &= tel_telecom_utils.wait_for_dialing(self.log, self.re) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 264 | if not ret: |
| 265 | return False |
| 266 | |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 267 | # Give time for state to update due to carrier limitations |
| 268 | time.sleep(SHORT_TIMEOUT) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 269 | # Check if we have any calls with dialing or active state on 'b'. |
| 270 | # We assume we never disconnect from 'ringing' state since it will lead |
| 271 | # to voicemail. |
| 272 | call_state_dialing_or_active = \ |
| 273 | [tel_defines.CALL_STATE_CONNECTING, |
| 274 | tel_defines.CALL_STATE_DIALING, |
| 275 | tel_defines.CALL_STATE_ACTIVE] |
| 276 | |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 277 | calls_in_dialing_or_active = tel_telecom_utils.get_calls_in_states( |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 278 | self.log, callee, call_state_dialing_or_active) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 279 | |
| 280 | # Make sure there is only one! |
| 281 | if len(calls_in_dialing_or_active) != 1: |
| 282 | self.log.info("Call State in dialing or active failed {}".format( |
| 283 | calls_in_dialing_or_active)) |
| 284 | return False |
| 285 | |
| 286 | # Hangup the *only* call on 'b' |
tturney | e3934a2 | 2016-10-20 15:47:34 -0700 | [diff] [blame^] | 287 | if not car_telecom_utils.hangup_call(self.log, caller, |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 288 | calls_in_dialing_or_active[0]): |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 289 | return False |
| 290 | |
| 291 | # Make sure everyone got out of in call state. |
| 292 | for d in self.android_devices: |
Sanket Agarwal | 54ad623 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 293 | ret &= tel_telecom_utils.wait_for_not_in_call(self.log, d) |
Sanket Agarwal | d09c7d8 | 2016-05-17 20:24:51 -0700 | [diff] [blame] | 294 | return ret |