1#!/usr/bin/env python3 2# 3# Copyright 2016 - Google 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of 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, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import time 18from acts import signals 19from acts.test_utils.tel.loggers.protos.telephony_metric_pb2 import TelephonyVoiceTestResult 20from acts.test_utils.tel.tel_defines import CALL_PROPERTY_HIGH_DEF_AUDIO 21from acts.test_utils.tel.tel_defines import CALL_STATE_ACTIVE 22from acts.test_utils.tel.tel_defines import CALL_STATE_HOLDING 23from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE 24from acts.test_utils.tel.tel_defines import CAPABILITY_WFC 25from acts.test_utils.tel.tel_defines import GEN_2G 26from acts.test_utils.tel.tel_defines import GEN_3G 27from acts.test_utils.tel.tel_defines import GEN_4G 28from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION 29from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VOLTE_ENABLED 30from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WFC_ENABLED 31from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA 32from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_VOICE 33from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000 34from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE 35from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM 36from acts.test_utils.tel.tel_defines import RAT_FAMILY_WCDMA 37from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN 38from acts.test_utils.tel.tel_defines import RAT_1XRTT 39from acts.test_utils.tel.tel_defines import RAT_IWLAN 40from acts.test_utils.tel.tel_defines import RAT_LTE 41from acts.test_utils.tel.tel_defines import RAT_UMTS 42from acts.test_utils.tel.tel_defines import WAIT_TIME_BETWEEN_REG_AND_CALL 43from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL 44from acts.test_utils.tel.tel_defines import WAIT_TIME_LEAVE_VOICE_MAIL 45from acts.test_utils.tel.tel_defines import WFC_MODE_DISABLED 46from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED 47from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA 48from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY 49from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS 50from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_CDMA_EVDO 51from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA 52from acts.test_utils.tel.tel_subscription_utils import get_outgoing_voice_sub_id 53from acts.test_utils.tel.tel_subscription_utils import set_subid_for_outgoing_call 54from acts.test_utils.tel.tel_subscription_utils import get_subid_from_slot_index 55from acts.test_utils.tel.tel_subscription_utils import get_default_data_sub_id 56from acts.test_utils.tel.tel_test_utils import call_reject_leave_message 57from acts.test_utils.tel.tel_test_utils import call_setup_teardown 58from acts.test_utils.tel.tel_test_utils import ensure_network_generation 59from acts.test_utils.tel.tel_test_utils import \ 60 ensure_network_generation_for_subscription 61from acts.test_utils.tel.tel_test_utils import \ 62 ensure_network_rat_for_subscription 63from acts.test_utils.tel.tel_test_utils import ensure_phones_idle 64from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected 65from acts.test_utils.tel.tel_test_utils import get_network_gen_for_subscription 66from acts.test_utils.tel.tel_test_utils import get_network_rat 67from acts.test_utils.tel.tel_test_utils import get_network_rat_for_subscription 68from acts.test_utils.tel.tel_test_utils import get_telephony_signal_strength 69from acts.test_utils.tel.tel_test_utils import is_wfc_enabled 70from acts.test_utils.tel.tel_test_utils import \ 71 reset_preferred_network_type_to_allowable_range 72from acts.test_utils.tel.tel_test_utils import set_wfc_mode 73from acts.test_utils.tel.tel_test_utils import set_wifi_to_default 74from acts.test_utils.tel.tel_test_utils import TelResultWrapper 75from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode 76from acts.test_utils.tel.tel_test_utils import toggle_volte 77from acts.test_utils.tel.tel_test_utils import toggle_volte_for_subscription 78from acts.test_utils.tel.tel_test_utils import verify_incall_state 79from acts.test_utils.tel.tel_test_utils import verify_internet_connection 80from acts.test_utils.tel.tel_test_utils import \ 81 wait_for_data_attach_for_subscription 82from acts.test_utils.tel.tel_test_utils import wait_for_enhanced_4g_lte_setting 83from acts.test_utils.tel.tel_test_utils import wait_for_network_generation 84from acts.test_utils.tel.tel_test_utils import \ 85 wait_for_network_generation_for_subscription 86from acts.test_utils.tel.tel_test_utils import wait_for_not_network_rat 87from acts.test_utils.tel.tel_test_utils import wait_for_network_rat 88from acts.test_utils.tel.tel_test_utils import \ 89 wait_for_network_rat_for_subscription 90from acts.test_utils.tel.tel_test_utils import \ 91 wait_for_not_network_rat_for_subscription 92from acts.test_utils.tel.tel_test_utils import wait_for_volte_enabled 93from acts.test_utils.tel.tel_test_utils import \ 94 wait_for_voice_attach_for_subscription 95from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled 96from acts.test_utils.tel.tel_test_utils import wait_for_wfc_disabled 97 98CallResult = TelephonyVoiceTestResult.CallResult.Value 99 100 101def two_phone_call_leave_voice_mail( 102 log, 103 caller, 104 caller_idle_func, 105 caller_in_call_check_func, 106 callee, 107 callee_idle_func, 108 wait_time_in_call=WAIT_TIME_LEAVE_VOICE_MAIL): 109 """Call from caller to callee, reject on callee, caller leave a voice mail. 110 111 1. Caller call Callee. 112 2. Callee reject incoming call. 113 3. Caller leave a voice mail. 114 4. Verify callee received the voice mail notification. 115 116 Args: 117 caller: caller android device object. 118 caller_idle_func: function to check caller's idle state. 119 caller_in_call_check_func: function to check caller's in-call state. 120 callee: callee android device object. 121 callee_idle_func: function to check callee's idle state. 122 wait_time_in_call: time to wait when leaving a voice mail. 123 This is optional, default is WAIT_TIME_LEAVE_VOICE_MAIL 124 125 Returns: 126 True: if voice message is received on callee successfully. 127 False: for errors 128 """ 129 130 ads = [caller, callee] 131 132 # Make sure phones are idle. 133 ensure_phones_idle(log, ads) 134 if caller_idle_func and not caller_idle_func(log, caller): 135 caller.log.error("Caller Failed to Reselect") 136 return False 137 if callee_idle_func and not callee_idle_func(log, callee): 138 callee.log.error("Callee Failed to Reselect") 139 return False 140 141 # TODO: b/26337871 Need to use proper API to check phone registered. 142 time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL) 143 144 # Make call and leave a message. 145 if not call_reject_leave_message( 146 log, caller, callee, caller_in_call_check_func, wait_time_in_call): 147 log.error("make a call and leave a message failed.") 148 return False 149 return True 150 151 152def two_phone_call_short_seq(log, 153 phone_a, 154 phone_a_idle_func, 155 phone_a_in_call_check_func, 156 phone_b, 157 phone_b_idle_func, 158 phone_b_in_call_check_func, 159 call_sequence_func=None, 160 wait_time_in_call=WAIT_TIME_IN_CALL): 161 """Call process short sequence. 162 1. Ensure phone idle and in idle_func check return True. 163 2. Call from PhoneA to PhoneB, accept on PhoneB. 164 3. Check phone state, hangup on PhoneA. 165 4. Ensure phone idle and in idle_func check return True. 166 5. Call from PhoneA to PhoneB, accept on PhoneB. 167 6. Check phone state, hangup on PhoneB. 168 169 Args: 170 phone_a: PhoneA's android device object. 171 phone_a_idle_func: function to check PhoneA's idle state. 172 phone_a_in_call_check_func: function to check PhoneA's in-call state. 173 phone_b: PhoneB's android device object. 174 phone_b_idle_func: function to check PhoneB's idle state. 175 phone_b_in_call_check_func: function to check PhoneB's in-call state. 176 call_sequence_func: default parameter, not implemented. 177 wait_time_in_call: time to wait in call. 178 This is optional, default is WAIT_TIME_IN_CALL 179 180 Returns: 181 TelResultWrapper which will evaluate as False if error. 182 """ 183 ads = [phone_a, phone_b] 184 185 call_params = [ 186 (ads[0], ads[1], ads[0], phone_a_in_call_check_func, 187 phone_b_in_call_check_func), 188 (ads[0], ads[1], ads[1], phone_a_in_call_check_func, 189 phone_b_in_call_check_func), 190 ] 191 192 tel_result = TelResultWrapper(CallResult('SUCCESS')) 193 for param in call_params: 194 # Make sure phones are idle. 195 ensure_phones_idle(log, ads) 196 if phone_a_idle_func and not phone_a_idle_func(log, phone_a): 197 phone_a.log.error("Phone A Failed to Reselect") 198 return TelResultWrapper(CallResult('CALL_SETUP_FAILURE')) 199 if phone_b_idle_func and not phone_b_idle_func(log, phone_b): 200 phone_b.log.error("Phone B Failed to Reselect") 201 return TelResultWrapper(CallResult('CALL_SETUP_FAILURE')) 202 203 # TODO: b/26337871 Need to use proper API to check phone registered. 204 time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL) 205 206 # Make call. 207 log.info("---> Call test: %s to %s <---", param[0].serial, 208 param[1].serial) 209 tel_result = call_setup_teardown( 210 log, *param, wait_time_in_call=wait_time_in_call) 211 if not tel_result: 212 log.error("Call Iteration Failed") 213 break 214 215 return tel_result 216 217 218def two_phone_call_msim_short_seq(log, 219 phone_a, 220 phone_a_idle_func, 221 phone_a_in_call_check_func, 222 phone_b, 223 phone_b_idle_func, 224 phone_b_in_call_check_func, 225 call_sequence_func=None, 226 wait_time_in_call=WAIT_TIME_IN_CALL): 227 """Call process short sequence. 228 1. Ensure phone idle and in idle_func check return True. 229 2. Call from PhoneA to PhoneB, accept on PhoneB. 230 3. Check phone state, hangup on PhoneA. 231 4. Ensure phone idle and in idle_func check return True. 232 5. Call from PhoneA to PhoneB, accept on PhoneB. 233 6. Check phone state, hangup on PhoneB. 234 235 Args: 236 phone_a: PhoneA's android device object. 237 phone_a_idle_func: function to check PhoneA's idle state. 238 phone_a_in_call_check_func: function to check PhoneA's in-call state. 239 phone_b: PhoneB's android device object. 240 phone_b_idle_func: function to check PhoneB's idle state. 241 phone_b_in_call_check_func: function to check PhoneB's in-call state. 242 call_sequence_func: default parameter, not implemented. 243 wait_time_in_call: time to wait in call. 244 This is optional, default is WAIT_TIME_IN_CALL 245 246 Returns: 247 True: if call sequence succeed. 248 False: for errors 249 """ 250 ads = [phone_a, phone_b] 251 252 call_params = [ 253 (ads[0], ads[1], ads[0], phone_a_in_call_check_func, 254 phone_b_in_call_check_func), 255 (ads[0], ads[1], ads[1], phone_a_in_call_check_func, 256 phone_b_in_call_check_func), 257 ] 258 259 for param in call_params: 260 # Make sure phones are idle. 261 ensure_phones_idle(log, ads) 262 if phone_a_idle_func and not phone_a_idle_func(log, phone_a): 263 phone_a.log.error("Phone A Failed to Reselect") 264 return False 265 if phone_b_idle_func and not phone_b_idle_func(log, phone_b): 266 phone_b.log.error("Phone B Failed to Reselect") 267 return False 268 269 # TODO: b/26337871 Need to use proper API to check phone registered. 270 time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL) 271 272 # Make call. 273 log.info("--> Call test: %s to %s <--", phone_a.serial, phone_b.serial) 274 slots = 2 275 for slot in range(slots): 276 set_subid_for_outgoing_call( 277 ads[0], get_subid_from_slot_index(log,ads[0],slot)) 278 set_subid_for_outgoing_call( 279 ads[1], get_subid_from_slot_index(log,ads[1],slot)) 280 time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL) 281 if not call_setup_teardown(log, *param,slot_id_callee = slot, 282 wait_time_in_call=wait_time_in_call): 283 log.error("Call Iteration Failed") 284 return False 285 if not call_setup_teardown(log, *param,slot_id_callee = 1-slot, 286 wait_time_in_call=wait_time_in_call): 287 log.error("Call Iteration Failed") 288 return False 289 return True 290 291 292def two_phone_call_long_seq(log, 293 phone_a, 294 phone_a_idle_func, 295 phone_a_in_call_check_func, 296 phone_b, 297 phone_b_idle_func, 298 phone_b_in_call_check_func, 299 call_sequence_func=None, 300 wait_time_in_call=WAIT_TIME_IN_CALL): 301 """Call process long sequence. 302 1. Ensure phone idle and in idle_func check return True. 303 2. Call from PhoneA to PhoneB, accept on PhoneB. 304 3. Check phone state, hangup on PhoneA. 305 4. Ensure phone idle and in idle_func check return True. 306 5. Call from PhoneA to PhoneB, accept on PhoneB. 307 6. Check phone state, hangup on PhoneB. 308 7. Ensure phone idle and in idle_func check return True. 309 8. Call from PhoneB to PhoneA, accept on PhoneA. 310 9. Check phone state, hangup on PhoneA. 311 10. Ensure phone idle and in idle_func check return True. 312 11. Call from PhoneB to PhoneA, accept on PhoneA. 313 12. Check phone state, hangup on PhoneB. 314 315 Args: 316 phone_a: PhoneA's android device object. 317 phone_a_idle_func: function to check PhoneA's idle state. 318 phone_a_in_call_check_func: function to check PhoneA's in-call state. 319 phone_b: PhoneB's android device object. 320 phone_b_idle_func: function to check PhoneB's idle state. 321 phone_b_in_call_check_func: function to check PhoneB's in-call state. 322 call_sequence_func: default parameter, not implemented. 323 wait_time_in_call: time to wait in call. 324 This is optional, default is WAIT_TIME_IN_CALL 325 326 Returns: 327 TelResultWrapper which will evaluate as False if error. 328 329 """ 330 ads = [phone_a, phone_b] 331 332 call_params = [ 333 (ads[0], ads[1], ads[0], phone_a_in_call_check_func, 334 phone_b_in_call_check_func), 335 (ads[0], ads[1], ads[1], phone_a_in_call_check_func, 336 phone_b_in_call_check_func), 337 (ads[1], ads[0], ads[0], phone_b_in_call_check_func, 338 phone_a_in_call_check_func), 339 (ads[1], ads[0], ads[1], phone_b_in_call_check_func, 340 phone_a_in_call_check_func), 341 ] 342 343 tel_result = TelResultWrapper(CallResult('SUCCESS')) 344 for param in call_params: 345 # Make sure phones are idle. 346 ensure_phones_idle(log, ads) 347 if phone_a_idle_func and not phone_a_idle_func(log, phone_a): 348 phone_a.log.error("Phone A Failed to Reselect") 349 return TelResultWrapper(CallResult('CALL_SETUP_FAILURE')) 350 if phone_b_idle_func and not phone_b_idle_func(log, phone_b): 351 phone_b.log.error("Phone B Failed to Reselect") 352 return TelResultWrapper(CallResult('CALL_SETUP_FAILURE')) 353 354 # TODO: b/26337871 Need to use proper API to check phone registered. 355 time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL) 356 357 # Make call. 358 log.info("---> Call test: %s to %s <---", param[0].serial, 359 param[1].serial) 360 tel_result = call_setup_teardown( 361 log, *param, wait_time_in_call=wait_time_in_call) 362 if not tel_result: 363 log.error("Call Iteration Failed") 364 break 365 366 return tel_result 367 368 369def phone_setup_iwlan(log, 370 ad, 371 is_airplane_mode, 372 wfc_mode, 373 wifi_ssid=None, 374 wifi_pwd=None): 375 """Phone setup function for epdg call test. 376 Set WFC mode according to wfc_mode. 377 Set airplane mode according to is_airplane_mode. 378 Make sure phone connect to WiFi. (If wifi_ssid is not None.) 379 Wait for phone to be in iwlan data network type. 380 Wait for phone to report wfc enabled flag to be true. 381 382 Args: 383 log: Log object. 384 ad: Android device object. 385 is_airplane_mode: True to turn on airplane mode. False to turn off airplane mode. 386 wfc_mode: WFC mode to set to. 387 wifi_ssid: WiFi network SSID. This is optional. 388 If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi. 389 wifi_pwd: WiFi network password. This is optional. 390 391 Returns: 392 True if success. False if fail. 393 """ 394 #TODO: get per sub_id carrier_config for multi-sim purpose 395 if CAPABILITY_WFC not in ad.telephony.get("capabilities", []): 396 ad.log.error("WFC is not supported, abort test.") 397 raise signals.TestSkip("WFC is not supported, abort test.") 398 return phone_setup_iwlan_for_subscription(log, ad, 399 get_outgoing_voice_sub_id(ad), 400 is_airplane_mode, wfc_mode, 401 wifi_ssid, wifi_pwd) 402 403 404def phone_setup_iwlan_for_subscription(log, 405 ad, 406 sub_id, 407 is_airplane_mode, 408 wfc_mode, 409 wifi_ssid=None, 410 wifi_pwd=None): 411 """Phone setup function for epdg call test for subscription id. 412 Set WFC mode according to wfc_mode. 413 Set airplane mode according to is_airplane_mode. 414 Make sure phone connect to WiFi. (If wifi_ssid is not None.) 415 Wait for phone to be in iwlan data network type. 416 Wait for phone to report wfc enabled flag to be true. 417 418 Args: 419 log: Log object. 420 ad: Android device object. 421 sub_id: subscription id. 422 is_airplane_mode: True to turn on airplane mode. False to turn off airplane mode. 423 wfc_mode: WFC mode to set to. 424 wifi_ssid: WiFi network SSID. This is optional. 425 If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi. 426 wifi_pwd: WiFi network password. This is optional. 427 428 Returns: 429 True if success. False if fail. 430 """ 431 toggle_airplane_mode(log, ad, is_airplane_mode, strict_checking=False) 432 433 # check if WFC supported phones 434 if wfc_mode != WFC_MODE_DISABLED and not ad.droid.imsIsWfcEnabledByPlatform( 435 ): 436 ad.log.error("WFC is not enabled on this device by checking " 437 "ImsManager.isWfcEnabledByPlatform") 438 return False 439 440 if wifi_ssid is not None: 441 if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd): 442 ad.log.error("Fail to bring up WiFi connection on %s.", wifi_ssid) 443 return False 444 445 if not set_wfc_mode(log, ad, wfc_mode): 446 ad.log.error("Unable to set WFC mode to %s.", wfc_mode) 447 return False 448 449 if not wait_for_wfc_enabled(log, ad, max_time=MAX_WAIT_TIME_WFC_ENABLED): 450 ad.log.error("WFC is not enabled") 451 return False 452 return True 453 454 455def phone_setup_iwlan_cellular_preferred(log, 456 ad, 457 wifi_ssid=None, 458 wifi_pwd=None): 459 """Phone setup function for iwlan Non-APM CELLULAR_PREFERRED test. 460 Set WFC mode according to CELLULAR_PREFERRED. 461 Set airplane mode according to False. 462 Make sure phone connect to WiFi. (If wifi_ssid is not None.) 463 Make sure phone don't report iwlan data network type. 464 Make sure phone don't report wfc enabled flag to be true. 465 466 Args: 467 log: Log object. 468 ad: Android device object. 469 wifi_ssid: WiFi network SSID. This is optional. 470 If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi. 471 wifi_pwd: WiFi network password. This is optional. 472 473 Returns: 474 True if success. False if fail. 475 """ 476 toggle_airplane_mode(log, ad, False, strict_checking=False) 477 try: 478 toggle_volte(log, ad, True) 479 if not wait_for_network_generation( 480 log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 481 if not ensure_network_generation( 482 log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 483 ad.log.error("Fail to ensure data in 4G") 484 return False 485 except Exception as e: 486 ad.log.error(e) 487 ad.droid.telephonyToggleDataConnection(True) 488 if wifi_ssid is not None: 489 if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd): 490 ad.log.error("Connect to WiFi failed.") 491 return False 492 if not set_wfc_mode(log, ad, WFC_MODE_CELLULAR_PREFERRED): 493 ad.log.error("Set WFC mode failed.") 494 return False 495 if not wait_for_not_network_rat( 496 log, ad, RAT_FAMILY_WLAN, voice_or_data=NETWORK_SERVICE_DATA): 497 ad.log.error("Data rat in iwlan mode.") 498 return False 499 elif not wait_for_wfc_disabled(log, ad, MAX_WAIT_TIME_WFC_ENABLED): 500 ad.log.error("Should report wifi calling disabled within %s.", 501 MAX_WAIT_TIME_WFC_ENABLED) 502 return False 503 return True 504 505 506def phone_setup_data_for_subscription(log, ad, sub_id, network_generation): 507 """Setup Phone <sub_id> Data to <network_generation> 508 509 Args: 510 log: log object 511 ad: android device object 512 sub_id: subscription id 513 network_generation: network generation, e.g. GEN_2G, GEN_3G, GEN_4G 514 515 Returns: 516 True if success, False if fail. 517 """ 518 toggle_airplane_mode(log, ad, False, strict_checking=False) 519 set_wifi_to_default(log, ad) 520 if not set_wfc_mode(log, ad, WFC_MODE_DISABLED): 521 ad.log.error("Disable WFC failed.") 522 return False 523 if not ensure_network_generation_for_subscription( 524 log, 525 ad, 526 sub_id, 527 network_generation, 528 voice_or_data=NETWORK_SERVICE_DATA): 529 get_telephony_signal_strength(ad) 530 return False 531 return True 532 533 534def phone_setup_4g(log, ad): 535 """Setup Phone default data sub_id data to 4G. 536 537 Args: 538 log: log object 539 ad: android device object 540 541 Returns: 542 True if success, False if fail. 543 """ 544 return phone_setup_4g_for_subscription(log, ad, 545 get_default_data_sub_id(ad)) 546 547 548def phone_setup_4g_for_subscription(log, ad, sub_id): 549 """Setup Phone <sub_id> Data to 4G. 550 551 Args: 552 log: log object 553 ad: android device object 554 sub_id: subscription id 555 556 Returns: 557 True if success, False if fail. 558 """ 559 return phone_setup_data_for_subscription(log, ad, sub_id, GEN_4G) 560 561 562def phone_setup_3g(log, ad): 563 """Setup Phone default data sub_id data to 3G. 564 565 Args: 566 log: log object 567 ad: android device object 568 569 Returns: 570 True if success, False if fail. 571 """ 572 return phone_setup_3g_for_subscription(log, ad, 573 get_default_data_sub_id(ad)) 574 575 576def phone_setup_3g_for_subscription(log, ad, sub_id): 577 """Setup Phone <sub_id> Data to 3G. 578 579 Args: 580 log: log object 581 ad: android device object 582 sub_id: subscription id 583 584 Returns: 585 True if success, False if fail. 586 """ 587 return phone_setup_data_for_subscription(log, ad, sub_id, GEN_3G) 588 589 590def phone_setup_2g(log, ad): 591 """Setup Phone default data sub_id data to 2G. 592 593 Args: 594 log: log object 595 ad: android device object 596 597 Returns: 598 True if success, False if fail. 599 """ 600 return phone_setup_2g_for_subscription(log, ad, 601 get_default_data_sub_id(ad)) 602 603 604def phone_setup_2g_for_subscription(log, ad, sub_id): 605 """Setup Phone <sub_id> Data to 3G. 606 607 Args: 608 log: log object 609 ad: android device object 610 sub_id: subscription id 611 612 Returns: 613 True if success, False if fail. 614 """ 615 return phone_setup_data_for_subscription(log, ad, sub_id, GEN_2G) 616 617 618def phone_setup_csfb(log, ad): 619 """Setup phone for CSFB call test. 620 621 Setup Phone to be in 4G mode. 622 Disabled VoLTE. 623 624 Args: 625 log: log object 626 ad: Android device object. 627 628 Returns: 629 True if setup successfully. 630 False for errors. 631 """ 632 return phone_setup_csfb_for_subscription(log, ad, 633 get_outgoing_voice_sub_id(ad)) 634 635 636def phone_setup_csfb_for_subscription(log, ad, sub_id): 637 """Setup phone for CSFB call test for subscription id. 638 639 Setup Phone to be in 4G mode. 640 Disabled VoLTE. 641 642 Args: 643 log: log object 644 ad: Android device object. 645 sub_id: subscription id. 646 647 Returns: 648 True if setup successfully. 649 False for errors. 650 """ 651 if not phone_setup_4g_for_subscription(log, ad, sub_id): 652 ad.log.error("Failed to set to 4G data.") 653 return False 654 if ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform(): 655 toggle_volte(log, ad, False) 656 if not ensure_network_generation_for_subscription( 657 log, ad, sub_id, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 658 return False 659 660 if not wait_for_voice_attach_for_subscription(log, ad, sub_id, 661 MAX_WAIT_TIME_NW_SELECTION): 662 return False 663 664 return phone_idle_csfb_for_subscription(log, ad, sub_id) 665 666 667def phone_setup_volte(log, ad): 668 """Setup VoLTE enable. 669 670 Args: 671 log: log object 672 ad: android device object. 673 674 Returns: 675 True: if VoLTE is enabled successfully. 676 False: for errors 677 """ 678 #TODO: get per sub_id carrier_config for multi-sim purpose 679 if CAPABILITY_VOLTE not in ad.telephony.get("capabilities", []): 680 ad.log.error("VoLTE is not supported, abort test.") 681 raise signals.TestSkip("VoLTE is not supported, abort test.") 682 return phone_setup_volte_for_subscription(log, ad, 683 get_outgoing_voice_sub_id(ad)) 684 685 686def phone_setup_volte_for_subscription(log, ad, sub_id): 687 """Setup VoLTE enable for subscription id. 688 689 Args: 690 log: log object 691 ad: android device object. 692 sub_id: subscription id. 693 694 Returns: 695 True: if VoLTE is enabled successfully. 696 False: for errors 697 """ 698 if not phone_setup_4g_for_subscription(log, ad, sub_id): 699 ad.log.error("Failed to set to 4G data.") 700 return False 701 if not wait_for_enhanced_4g_lte_setting(log, ad): 702 ad.log.error("Enhanced 4G LTE setting is not available") 703 return False 704 toggle_volte_for_subscription(log, ad, sub_id, True) 705 return phone_idle_volte_for_subscription(log, ad, sub_id) 706 707 708def phone_setup_voice_3g(log, ad): 709 """Setup phone voice to 3G. 710 711 Args: 712 log: log object 713 ad: Android device object. 714 715 Returns: 716 True if setup successfully. 717 False for errors. 718 """ 719 return phone_setup_voice_3g_for_subscription(log, ad, 720 get_outgoing_voice_sub_id(ad)) 721 722 723def phone_setup_voice_3g_for_subscription(log, ad, sub_id): 724 """Setup phone voice to 3G for subscription id. 725 726 Args: 727 log: log object 728 ad: Android device object. 729 sub_id: subscription id. 730 731 Returns: 732 True if setup successfully. 733 False for errors. 734 """ 735 if not phone_setup_3g_for_subscription(log, ad, sub_id): 736 ad.log.error("Failed to set to 3G data.") 737 return False 738 if not wait_for_voice_attach_for_subscription(log, ad, sub_id, 739 MAX_WAIT_TIME_NW_SELECTION): 740 return False 741 return phone_idle_3g_for_subscription(log, ad, sub_id) 742 743 744def phone_setup_voice_2g(log, ad): 745 """Setup phone voice to 2G. 746 747 Args: 748 log: log object 749 ad: Android device object. 750 751 Returns: 752 True if setup successfully. 753 False for errors. 754 """ 755 return phone_setup_voice_2g_for_subscription(log, ad, 756 get_outgoing_voice_sub_id(ad)) 757 758 759def phone_setup_voice_2g_for_subscription(log, ad, sub_id): 760 """Setup phone voice to 2G for subscription id. 761 762 Args: 763 log: log object 764 ad: Android device object. 765 sub_id: subscription id. 766 767 Returns: 768 True if setup successfully. 769 False for errors. 770 """ 771 if not phone_setup_2g_for_subscription(log, ad, sub_id): 772 ad.log.error("Failed to set to 2G data.") 773 return False 774 if not wait_for_voice_attach_for_subscription(log, ad, sub_id, 775 MAX_WAIT_TIME_NW_SELECTION): 776 return False 777 return phone_idle_2g_for_subscription(log, ad, sub_id) 778 779 780def phone_setup_voice_general(log, ad): 781 """Setup phone for voice general call test. 782 783 Make sure phone attached to voice. 784 Make necessary delay. 785 786 Args: 787 ad: Android device object. 788 789 Returns: 790 True if setup successfully. 791 False for errors. 792 """ 793 return phone_setup_voice_general_for_subscription( 794 log, ad, get_outgoing_voice_sub_id(ad)) 795 796 797def phone_setup_voice_general_for_slot(log,ad,slot_id): 798 return phone_setup_voice_general_for_subscription( 799 log, ad, get_subid_from_slot_index(log,ad,slot_id)) 800 801 802def phone_setup_voice_general_for_subscription(log, ad, sub_id): 803 """Setup phone for voice general call test for subscription id. 804 805 Make sure phone attached to voice. 806 Make necessary delay. 807 808 Args: 809 ad: Android device object. 810 sub_id: subscription id. 811 812 Returns: 813 True if setup successfully. 814 False for errors. 815 """ 816 toggle_airplane_mode(log, ad, False, strict_checking=False) 817 if not wait_for_voice_attach_for_subscription(log, ad, sub_id, 818 MAX_WAIT_TIME_NW_SELECTION): 819 # if phone can not attach voice, try phone_setup_voice_3g 820 return phone_setup_voice_3g_for_subscription(log, ad, sub_id) 821 return True 822 823 824def phone_setup_data_general(log, ad): 825 """Setup phone for data general test. 826 827 Make sure phone attached to data. 828 Make necessary delay. 829 830 Args: 831 ad: Android device object. 832 833 Returns: 834 True if setup successfully. 835 False for errors. 836 """ 837 return phone_setup_data_general_for_subscription( 838 log, ad, ad.droid.subscriptionGetDefaultDataSubId()) 839 840 841def phone_setup_data_general_for_subscription(log, ad, sub_id): 842 """Setup phone for data general test for subscription id. 843 844 Make sure phone attached to data. 845 Make necessary delay. 846 847 Args: 848 ad: Android device object. 849 sub_id: subscription id. 850 851 Returns: 852 True if setup successfully. 853 False for errors. 854 """ 855 toggle_airplane_mode(log, ad, False, strict_checking=False) 856 if not wait_for_data_attach_for_subscription(log, ad, sub_id, 857 MAX_WAIT_TIME_NW_SELECTION): 858 # if phone can not attach data, try reset network preference settings 859 reset_preferred_network_type_to_allowable_range(log, ad) 860 861 return wait_for_data_attach_for_subscription(log, ad, sub_id, 862 MAX_WAIT_TIME_NW_SELECTION) 863 864 865def phone_setup_rat_for_subscription(log, ad, sub_id, network_preference, 866 rat_family): 867 toggle_airplane_mode(log, ad, False, strict_checking=False) 868 set_wifi_to_default(log, ad) 869 if not set_wfc_mode(log, ad, WFC_MODE_DISABLED): 870 ad.log.error("Disable WFC failed.") 871 return False 872 return ensure_network_rat_for_subscription(log, ad, sub_id, 873 network_preference, rat_family) 874 875 876def phone_setup_lte_gsm_wcdma(log, ad): 877 return phone_setup_lte_gsm_wcdma_for_subscription( 878 log, ad, ad.droid.subscriptionGetDefaultSubId()) 879 880 881def phone_setup_lte_gsm_wcdma_for_subscription(log, ad, sub_id): 882 return phone_setup_rat_for_subscription( 883 log, ad, sub_id, NETWORK_MODE_LTE_GSM_WCDMA, RAT_FAMILY_LTE) 884 885 886def phone_setup_gsm_umts(log, ad): 887 return phone_setup_gsm_umts_for_subscription( 888 log, ad, ad.droid.subscriptionGetDefaultSubId()) 889 890 891def phone_setup_gsm_umts_for_subscription(log, ad, sub_id): 892 return phone_setup_rat_for_subscription( 893 log, ad, sub_id, NETWORK_MODE_GSM_UMTS, RAT_FAMILY_WCDMA) 894 895 896def phone_setup_gsm_only(log, ad): 897 return phone_setup_gsm_only_for_subscription( 898 log, ad, ad.droid.subscriptionGetDefaultSubId()) 899 900 901def phone_setup_gsm_only_for_subscription(log, ad, sub_id): 902 return phone_setup_rat_for_subscription( 903 log, ad, sub_id, NETWORK_MODE_GSM_ONLY, RAT_FAMILY_GSM) 904 905 906def phone_setup_lte_cdma_evdo(log, ad): 907 return phone_setup_lte_cdma_evdo_for_subscription( 908 log, ad, ad.droid.subscriptionGetDefaultSubId()) 909 910 911def phone_setup_lte_cdma_evdo_for_subscription(log, ad, sub_id): 912 return phone_setup_rat_for_subscription( 913 log, ad, sub_id, NETWORK_MODE_LTE_CDMA_EVDO, RAT_FAMILY_LTE) 914 915 916def phone_setup_cdma(log, ad): 917 return phone_setup_cdma_for_subscription( 918 log, ad, ad.droid.subscriptionGetDefaultSubId()) 919 920 921def phone_setup_cdma_for_subscription(log, ad, sub_id): 922 return phone_setup_rat_for_subscription(log, ad, sub_id, NETWORK_MODE_CDMA, 923 RAT_FAMILY_CDMA2000) 924 925 926def phone_idle_volte(log, ad): 927 """Return if phone is idle for VoLTE call test. 928 929 Args: 930 ad: Android device object. 931 """ 932 return phone_idle_volte_for_subscription(log, ad, 933 get_outgoing_voice_sub_id(ad)) 934 935 936def phone_idle_volte_for_subscription(log, ad, sub_id): 937 """Return if phone is idle for VoLTE call test for subscription id. 938 939 Args: 940 ad: Android device object. 941 sub_id: subscription id. 942 """ 943 if not wait_for_network_rat_for_subscription( 944 log, ad, sub_id, RAT_FAMILY_LTE, 945 voice_or_data=NETWORK_SERVICE_VOICE): 946 ad.log.error("Voice rat not in LTE mode.") 947 return False 948 if not wait_for_volte_enabled(log, ad, MAX_WAIT_TIME_VOLTE_ENABLED): 949 ad.log.error( 950 "Failed to <report volte enabled true> within %s seconds.", 951 MAX_WAIT_TIME_VOLTE_ENABLED) 952 return False 953 return True 954 955 956def phone_idle_iwlan(log, ad): 957 """Return if phone is idle for WiFi calling call test. 958 959 Args: 960 ad: Android device object. 961 """ 962 return phone_idle_iwlan_for_subscription(log, ad, 963 get_outgoing_voice_sub_id(ad)) 964 965 966def phone_idle_iwlan_for_subscription(log, ad, sub_id): 967 """Return if phone is idle for WiFi calling call test for subscription id. 968 969 Args: 970 ad: Android device object. 971 sub_id: subscription id. 972 """ 973 if not wait_for_wfc_enabled(log, ad, MAX_WAIT_TIME_WFC_ENABLED): 974 ad.log.error("Failed to <report wfc enabled true> within %s seconds.", 975 MAX_WAIT_TIME_WFC_ENABLED) 976 return False 977 return True 978 979 980def phone_idle_not_iwlan(log, ad): 981 """Return if phone is idle for non WiFi calling call test. 982 983 Args: 984 ad: Android device object. 985 """ 986 return phone_idle_not_iwlan_for_subscription(log, ad, 987 get_outgoing_voice_sub_id(ad)) 988 989 990def phone_idle_not_iwlan_for_subscription(log, ad, sub_id): 991 """Return if phone is idle for non WiFi calling call test for sub id. 992 993 Args: 994 ad: Android device object. 995 sub_id: subscription id. 996 """ 997 if not wait_for_not_network_rat_for_subscription( 998 log, ad, sub_id, RAT_FAMILY_WLAN, 999 voice_or_data=NETWORK_SERVICE_DATA): 1000 log.error("{} data rat in iwlan mode.".format(ad.serial)) 1001 return False 1002 return True 1003 1004 1005def phone_idle_csfb(log, ad): 1006 """Return if phone is idle for CSFB call test. 1007 1008 Args: 1009 ad: Android device object. 1010 """ 1011 return phone_idle_csfb_for_subscription(log, ad, 1012 get_outgoing_voice_sub_id(ad)) 1013 1014 1015def phone_idle_csfb_for_subscription(log, ad, sub_id): 1016 """Return if phone is idle for CSFB call test for subscription id. 1017 1018 Args: 1019 ad: Android device object. 1020 sub_id: subscription id. 1021 """ 1022 if not wait_for_network_rat_for_subscription( 1023 log, ad, sub_id, RAT_FAMILY_LTE, 1024 voice_or_data=NETWORK_SERVICE_DATA): 1025 ad.log.error("Data rat not in lte mode.") 1026 return False 1027 return True 1028 1029 1030def phone_idle_3g(log, ad): 1031 """Return if phone is idle for 3G call test. 1032 1033 Args: 1034 ad: Android device object. 1035 """ 1036 return phone_idle_3g_for_subscription(log, ad, 1037 get_outgoing_voice_sub_id(ad)) 1038 1039 1040def phone_idle_3g_for_subscription(log, ad, sub_id): 1041 """Return if phone is idle for 3G call test for subscription id. 1042 1043 Args: 1044 ad: Android device object. 1045 sub_id: subscription id. 1046 """ 1047 return wait_for_network_generation_for_subscription( 1048 log, ad, sub_id, GEN_3G, voice_or_data=NETWORK_SERVICE_VOICE) 1049 1050 1051def phone_idle_2g(log, ad): 1052 """Return if phone is idle for 2G call test. 1053 1054 Args: 1055 ad: Android device object. 1056 """ 1057 return phone_idle_2g_for_subscription(log, ad, 1058 get_outgoing_voice_sub_id(ad)) 1059 1060 1061def phone_idle_2g_for_subscription(log, ad, sub_id): 1062 """Return if phone is idle for 2G call test for subscription id. 1063 1064 Args: 1065 ad: Android device object. 1066 sub_id: subscription id. 1067 """ 1068 return wait_for_network_generation_for_subscription( 1069 log, ad, sub_id, GEN_2G, voice_or_data=NETWORK_SERVICE_VOICE) 1070 1071 1072def get_current_voice_rat(log, ad): 1073 """Return current Voice RAT 1074 1075 Args: 1076 ad: Android device object. 1077 """ 1078 return get_current_voice_rat_for_subscription( 1079 log, ad, get_outgoing_voice_sub_id(ad)) 1080 1081 1082def get_current_voice_rat_for_subscription(log, ad, sub_id): 1083 """Return current Voice RAT for subscription id. 1084 1085 Args: 1086 ad: Android device object. 1087 sub_id: subscription id. 1088 """ 1089 return get_network_rat_for_subscription(log, ad, sub_id, 1090 NETWORK_SERVICE_VOICE) 1091 1092 1093def is_phone_in_call_volte(log, ad): 1094 """Return if phone is in VoLTE call. 1095 1096 Args: 1097 ad: Android device object. 1098 """ 1099 return is_phone_in_call_volte_for_subscription( 1100 log, ad, get_outgoing_voice_sub_id(ad)) 1101 1102 1103def is_phone_in_call_volte_for_subscription(log, ad, sub_id): 1104 """Return if phone is in VoLTE call for subscription id. 1105 1106 Args: 1107 ad: Android device object. 1108 sub_id: subscription id. 1109 """ 1110 if not ad.droid.telecomIsInCall(): 1111 ad.log.error("Not in call.") 1112 return False 1113 nw_type = get_network_rat_for_subscription(log, ad, sub_id, 1114 NETWORK_SERVICE_VOICE) 1115 if nw_type != RAT_LTE: 1116 ad.log.error("Voice rat on: %s. Expected: LTE", nw_type) 1117 return False 1118 return True 1119 1120 1121def is_phone_in_call_csfb(log, ad): 1122 """Return if phone is in CSFB call. 1123 1124 Args: 1125 ad: Android device object. 1126 """ 1127 return is_phone_in_call_csfb_for_subscription( 1128 log, ad, get_outgoing_voice_sub_id(ad)) 1129 1130 1131def is_phone_in_call_csfb_for_subscription(log, ad, sub_id): 1132 """Return if phone is in CSFB call for subscription id. 1133 1134 Args: 1135 ad: Android device object. 1136 sub_id: subscription id. 1137 """ 1138 if not ad.droid.telecomIsInCall(): 1139 ad.log.error("Not in call.") 1140 return False 1141 nw_type = get_network_rat_for_subscription(log, ad, sub_id, 1142 NETWORK_SERVICE_VOICE) 1143 if nw_type == RAT_LTE: 1144 ad.log.error("Voice rat on: %s. Expected: not LTE", nw_type) 1145 return False 1146 return True 1147 1148 1149def is_phone_in_call_3g(log, ad): 1150 """Return if phone is in 3G call. 1151 1152 Args: 1153 ad: Android device object. 1154 """ 1155 return is_phone_in_call_3g_for_subscription(log, ad, 1156 get_outgoing_voice_sub_id(ad)) 1157 1158 1159def is_phone_in_call_3g_for_subscription(log, ad, sub_id): 1160 """Return if phone is in 3G call for subscription id. 1161 1162 Args: 1163 ad: Android device object. 1164 sub_id: subscription id. 1165 """ 1166 if not ad.droid.telecomIsInCall(): 1167 ad.log.error("Not in call.") 1168 return False 1169 nw_gen = get_network_gen_for_subscription(log, ad, sub_id, 1170 NETWORK_SERVICE_VOICE) 1171 if nw_gen != GEN_3G: 1172 ad.log.error("Voice rat on: %s. Expected: 3g", nw_gen) 1173 return False 1174 return True 1175 1176 1177def is_phone_in_call_2g(log, ad): 1178 """Return if phone is in 2G call. 1179 1180 Args: 1181 ad: Android device object. 1182 """ 1183 return is_phone_in_call_2g_for_subscription(log, ad, 1184 get_outgoing_voice_sub_id(ad)) 1185 1186 1187def is_phone_in_call_2g_for_subscription(log, ad, sub_id): 1188 """Return if phone is in 2G call for subscription id. 1189 1190 Args: 1191 ad: Android device object. 1192 sub_id: subscription id. 1193 """ 1194 if not ad.droid.telecomIsInCall(): 1195 ad.log.error("Not in call.") 1196 return False 1197 nw_gen = get_network_gen_for_subscription(log, ad, sub_id, 1198 NETWORK_SERVICE_VOICE) 1199 if nw_gen != GEN_2G: 1200 ad.log.error("Voice rat on: %s. Expected: 2g", nw_gen) 1201 return False 1202 return True 1203 1204 1205def is_phone_in_call_1x(log, ad): 1206 """Return if phone is in 1x call. 1207 1208 Args: 1209 ad: Android device object. 1210 """ 1211 return is_phone_in_call_1x_for_subscription(log, ad, 1212 get_outgoing_voice_sub_id(ad)) 1213 1214 1215def is_phone_in_call_1x_for_subscription(log, ad, sub_id): 1216 """Return if phone is in 1x call for subscription id. 1217 1218 Args: 1219 ad: Android device object. 1220 sub_id: subscription id. 1221 """ 1222 if not ad.droid.telecomIsInCall(): 1223 ad.log.error("Not in call.") 1224 return False 1225 nw_type = get_network_rat_for_subscription(log, ad, sub_id, 1226 NETWORK_SERVICE_VOICE) 1227 if nw_type != RAT_1XRTT: 1228 ad.log.error("Voice rat on: %s. Expected: 1xrtt", nw_type) 1229 return False 1230 return True 1231 1232 1233def is_phone_in_call_wcdma(log, ad): 1234 """Return if phone is in WCDMA call. 1235 1236 Args: 1237 ad: Android device object. 1238 """ 1239 return is_phone_in_call_wcdma_for_subscription( 1240 log, ad, get_outgoing_voice_sub_id(ad)) 1241 1242 1243def is_phone_in_call_wcdma_for_subscription(log, ad, sub_id): 1244 """Return if phone is in WCDMA call for subscription id. 1245 1246 Args: 1247 ad: Android device object. 1248 sub_id: subscription id. 1249 """ 1250 # Currently checking 'umts'. 1251 # Changes may needed in the future. 1252 if not ad.droid.telecomIsInCall(): 1253 ad.log.error("Not in call.") 1254 return False 1255 nw_type = get_network_rat_for_subscription(log, ad, sub_id, 1256 NETWORK_SERVICE_VOICE) 1257 if nw_type != RAT_UMTS: 1258 ad.log.error("%s voice rat on: %s. Expected: umts", nw_type) 1259 return False 1260 return True 1261 1262 1263def is_phone_in_call_iwlan(log, ad, call_id=None): 1264 """Return if phone is in WiFi call. 1265 1266 Args: 1267 ad: Android device object. 1268 """ 1269 if not ad.droid.telecomIsInCall(): 1270 ad.log.error("Not in call.") 1271 return False 1272 if not ad.droid.telephonyIsImsRegistered(): 1273 ad.log.info("IMS is not registered.") 1274 return False 1275 if not ad.droid.telephonyIsWifiCallingAvailable(): 1276 ad.log.info("IsWifiCallingAvailble is False") 1277 return False 1278 if not call_id: 1279 call_ids = ad.droid.telecomCallGetCallIds() 1280 if call_ids: 1281 call_id = call_ids[-1] 1282 if not call_id: 1283 ad.log.error("Failed to get call id") 1284 return False 1285 else: 1286 call_prop = ad.droid.telecomCallGetProperties(call_id) 1287 if "WIFI" not in call_prop: 1288 ad.log.info("callProperties = %s, expecting WIFI", call_prop) 1289 return False 1290 nw_type = get_network_rat(log, ad, NETWORK_SERVICE_DATA) 1291 if nw_type != RAT_IWLAN: 1292 ad.log.error("Data rat on: %s. Expected: iwlan", nw_type) 1293 return False 1294 return True 1295 1296 1297def is_phone_in_call_not_iwlan(log, ad): 1298 """Return if phone is in WiFi call for subscription id. 1299 1300 Args: 1301 ad: Android device object. 1302 sub_id: subscription id. 1303 """ 1304 if not ad.droid.telecomIsInCall(): 1305 ad.log.error("Not in call.") 1306 return False 1307 nw_type = get_network_rat(log, ad, NETWORK_SERVICE_DATA) 1308 if nw_type == RAT_IWLAN: 1309 ad.log.error("Data rat on: %s. Expected: not iwlan", nw_type) 1310 return False 1311 if is_wfc_enabled(log, ad): 1312 ad.log.error("WiFi Calling feature bit is True.") 1313 return False 1314 return True 1315 1316 1317def swap_calls(log, 1318 ads, 1319 call_hold_id, 1320 call_active_id, 1321 num_swaps=1, 1322 check_call_status=True): 1323 """PhoneA in call with B and C. Swap active/holding call on PhoneA. 1324 1325 Swap call and check status on PhoneA. 1326 (This step may have multiple times according to 'num_swaps'.) 1327 Check if all 3 phones are 'in-call'. 1328 1329 Args: 1330 ads: list of ad object, at least three need to pass in. 1331 Swap operation will happen on ads[0]. 1332 ads[1] and ads[2] are call participants. 1333 call_hold_id: id for the holding call in ads[0]. 1334 call_hold_id should be 'STATE_HOLDING' when calling this function. 1335 call_active_id: id for the active call in ads[0]. 1336 call_active_id should be 'STATE_ACTIVE' when calling this function. 1337 num_swaps: how many swap/check operations will be done before return. 1338 check_call_status: This is optional. Default value is True. 1339 If this value is True, then call status (active/hold) will be 1340 be checked after each swap operation. 1341 1342 Returns: 1343 If no error happened, return True, otherwise, return False. 1344 """ 1345 if check_call_status: 1346 # Check status before swap. 1347 if ads[0].droid.telecomCallGetCallState( 1348 call_active_id) != CALL_STATE_ACTIVE: 1349 ads[0].log.error( 1350 "Call_id:%s, state:%s, expected: STATE_ACTIVE", call_active_id, 1351 ads[0].droid.telecomCallGetCallState(call_active_id)) 1352 return False 1353 if ads[0].droid.telecomCallGetCallState( 1354 call_hold_id) != CALL_STATE_HOLDING: 1355 ads[0].log.error( 1356 "Call_id:%s, state:%s, expected: STATE_HOLDING", call_hold_id, 1357 ads[0].droid.telecomCallGetCallState(call_hold_id)) 1358 return False 1359 1360 i = 1 1361 while (i <= num_swaps): 1362 ads[0].log.info("swap_test %s: swap and check call status.", i) 1363 ads[0].droid.telecomCallHold(call_active_id) 1364 time.sleep(WAIT_TIME_IN_CALL) 1365 # Swap object reference 1366 call_active_id, call_hold_id = call_hold_id, call_active_id 1367 if check_call_status: 1368 # Check status 1369 if ads[0].droid.telecomCallGetCallState( 1370 call_active_id) != CALL_STATE_ACTIVE: 1371 ads[0].log.error( 1372 "Call_id:%s, state:%s, expected: STATE_ACTIVE", 1373 call_active_id, 1374 ads[0].droid.telecomCallGetCallState(call_active_id)) 1375 return False 1376 if ads[0].droid.telecomCallGetCallState( 1377 call_hold_id) != CALL_STATE_HOLDING: 1378 ads[0].log.error( 1379 "Call_id:%s, state:%s, expected: STATE_HOLDING", 1380 call_hold_id, 1381 ads[0].droid.telecomCallGetCallState(call_hold_id)) 1382 return False 1383 # TODO: b/26296375 add voice check. 1384 1385 i += 1 1386 1387 #In the end, check all three phones are 'in-call'. 1388 if not verify_incall_state(log, [ads[0], ads[1], ads[2]], True): 1389 return False 1390 1391 return True 1392 1393 1394def get_audio_route(log, ad): 1395 """Gets the audio route for the active call 1396 1397 Args: 1398 log: logger object 1399 ad: android_device object 1400 1401 Returns: 1402 Audio route string ["BLUETOOTH", "EARPIECE", "SPEAKER", "WIRED_HEADSET" 1403 "WIRED_OR_EARPIECE"] 1404 """ 1405 1406 audio_state = ad.droid.telecomCallGetAudioState() 1407 return audio_state["AudioRoute"] 1408 1409 1410def set_audio_route(log, ad, route): 1411 """Sets the audio route for the active call 1412 1413 Args: 1414 log: logger object 1415 ad: android_device object 1416 route: string ["BLUETOOTH", "EARPIECE", "SPEAKER", "WIRED_HEADSET" 1417 "WIRED_OR_EARPIECE"] 1418 1419 Returns: 1420 If no error happened, return True, otherwise, return False. 1421 """ 1422 ad.droid.telecomCallSetAudioRoute(route) 1423 return True 1424 1425 1426def is_property_in_call_properties(log, ad, call_id, expected_property): 1427 """Return if the call_id has the expected property 1428 1429 Args: 1430 log: logger object 1431 ad: android_device object 1432 call_id: call id. 1433 expected_property: expected property. 1434 1435 Returns: 1436 True if call_id has expected_property. False if not. 1437 """ 1438 properties = ad.droid.telecomCallGetProperties(call_id) 1439 return (expected_property in properties) 1440 1441 1442def is_call_hd(log, ad, call_id): 1443 """Return if the call_id is HD call. 1444 1445 Args: 1446 log: logger object 1447 ad: android_device object 1448 call_id: call id. 1449 1450 Returns: 1451 True if call_id is HD call. False if not. 1452 """ 1453 return is_property_in_call_properties(log, ad, call_id, 1454 CALL_PROPERTY_HIGH_DEF_AUDIO) 1455 1456 1457def get_cep_conference_call_id(ad): 1458 """Get CEP conference call id if there is an ongoing CEP conference call. 1459 1460 Args: 1461 ad: android device object. 1462 1463 Returns: 1464 call id for CEP conference call if there is an ongoing CEP conference call. 1465 None otherwise. 1466 """ 1467 for call in ad.droid.telecomCallGetCallIds(): 1468 if len(ad.droid.telecomCallGetCallChildren(call)) != 0: 1469 return call 1470 return None 1471