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