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