1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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"""
17    Test Script for IMS Settings
18"""
19
20import time
21
22from acts import signals
23from acts.test_decorators import test_tracker_info
24from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
25from acts.test_utils.tel.tel_defines import CarrierConfigs
26from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
27from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
28from acts.test_utils.tel.tel_defines import CAPABILITY_WFC_MODE_CHANGE
29from acts.test_utils.tel.tel_defines import GEN_4G
30from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WIFI_CONNECTION
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 MAX_WAIT_TIME_IMS_REGISTRATION
34from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_WFC_ENABLED
35from acts.test_utils.tel.tel_defines import RAT_FAMILY_WLAN
36from acts.test_utils.tel.tel_defines import RAT_LTE
37from acts.test_utils.tel.tel_defines import RAT_UNKNOWN
38from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
39from acts.test_utils.tel.tel_defines import WFC_MODE_DISABLED
40from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_ONLY
41from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
42from acts.test_utils.tel.tel_subscription_utils import get_outgoing_voice_sub_id
43from acts.test_utils.tel.tel_test_utils import call_setup_teardown
44from acts.test_utils.tel.tel_test_utils import dumpsys_carrier_config
45from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
46from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
47from acts.test_utils.tel.tel_test_utils import fastboot_wipe
48from acts.test_utils.tel.tel_test_utils import get_user_config_profile
49from acts.test_utils.tel.tel_test_utils import is_droid_in_rat_family
50from acts.test_utils.tel.tel_test_utils import revert_default_telephony_setting
51from acts.test_utils.tel.tel_test_utils import set_wfc_mode
52from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
53from acts.test_utils.tel.tel_test_utils import toggle_volte
54from acts.test_utils.tel.tel_test_utils import toggle_wfc
55from acts.test_utils.tel.tel_test_utils import verify_default_telephony_setting
56from acts.test_utils.tel.tel_test_utils import verify_internet_connection
57from acts.test_utils.tel.tel_test_utils import wait_for_ims_registered
58from acts.test_utils.tel.tel_test_utils import wait_for_network_rat
59from acts.test_utils.tel.tel_test_utils import wait_for_not_network_rat
60from acts.test_utils.tel.tel_test_utils import wait_for_state
61from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach
62from acts.test_utils.tel.tel_test_utils import wait_for_volte_enabled
63from acts.test_utils.tel.tel_test_utils import wait_for_wfc_disabled
64from acts.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
65from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
66from acts.test_utils.tel.tel_test_utils import wifi_reset
67from acts.test_utils.tel.tel_test_utils import wifi_toggle_state
68from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
69from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
70from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
71from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
72from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
73from acts.test_utils.tel.tel_test_utils import WIFI_SSID_KEY
74from acts.test_utils.tel.tel_test_utils import WIFI_PWD_KEY
75
76
77class TelLiveImsSettingsTest(TelephonyBaseTest):
78    def setup_class(self):
79        TelephonyBaseTest.setup_class(self)
80        self.dut = self.android_devices[0]
81        self.number_of_devices = 1
82        self.skip_reset_between_cases = False
83        subid = get_outgoing_voice_sub_id(self.dut)
84        self.carrier_configs = dumpsys_carrier_config(self.dut)[subid]
85        self.dut_capabilities = self.dut.telephony["subscription"][
86            subid].get("capabilities", [])
87        self.dut.log.info("DUT capabilities: %s", self.dut_capabilities)
88        if CAPABILITY_VOLTE not in self.dut_capabilities:
89            raise signals.TestAbortClass("VoLTE is not supported")
90        if CAPABILITY_WFC not in self.dut_capabilities:
91            raise signals.TestAbortClass("WFC is not supported")
92
93        self.default_volte = (CAPABILITY_VOLTE in self.dut_capabilities) and (
94            self.carrier_configs[CarrierConfigs.
95                                 ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL])
96        self.default_wfc_enabled = (
97            CAPABILITY_WFC in self.dut_capabilities
98        ) and (
99            self.carrier_configs[CarrierConfigs.DEFAULT_WFC_IMS_ENABLED_BOOL])
100        self.default_wfc_mode = self.carrier_configs.get(
101            CarrierConfigs.DEFAULT_WFC_IMS_MODE_INT, None)
102        self.dut_wfc_modes = self.dut.telephony[
103            "subscription"][subid].get("wfc_modes", [])
104
105    def check_call_in_wfc(self):
106        result = True
107        if not call_setup_teardown(self.log, self.android_devices[1], self.dut,
108                                   self.dut, None, is_phone_in_call_iwlan):
109            if not call_setup_teardown(self.log, self.android_devices[1],
110                                       self.dut, self.dut, None,
111                                       is_phone_in_call_iwlan):
112                self.dut.log.error("MT WFC call failed")
113                result = False
114        if not call_setup_teardown(self.log, self.dut, self.android_devices[1],
115                                   self.dut, is_phone_in_call_iwlan):
116            self.dut.log.error("MO WFC call failed")
117            result = False
118        return result
119
120    def check_call_in_volte(self):
121        result = True
122        if not call_setup_teardown(self.log, self.android_devices[1], self.dut,
123                                   self.dut, None, is_phone_in_call_volte):
124            if not call_setup_teardown(self.log, self.android_devices[1],
125                                       self.dut, self.dut, None,
126                                       is_phone_in_call_volte):
127                self.dut.log.error("MT VoLTE call failed")
128                result = False
129        if not call_setup_teardown(self.log, self.dut, self.android_devices[1],
130                                   self.dut, is_phone_in_call_volte):
131            self.dut.log.error("MO VoLTE call failed")
132            result = False
133        return result
134
135    def check_call(self):
136        result = True
137        if not call_setup_teardown(self.log, self.android_devices[1], self.dut,
138                                   self.dut):
139            if not call_setup_teardown(self.log, self.android_devices[1],
140                                       self.dut, self.dut):
141                self.dut.log.error("MT call failed")
142                result = False
143        if not call_setup_teardown(self.log, self.dut, self.android_devices[1],
144                                   self.dut):
145            self.dut.log.error("MO call failed")
146            result = False
147        return result
148
149    def change_ims_setting(self,
150                           airplane_mode,
151                           wifi_enabled,
152                           volte_enabled,
153                           wfc_enabled,
154                           wfc_mode=None):
155        result = True
156        self.dut.log.info(
157            "Setting APM %s, WIFI %s, VoLTE %s, WFC %s, WFC mode %s",
158            airplane_mode, wifi_enabled, volte_enabled, wfc_enabled, wfc_mode)
159        toggle_airplane_mode_by_adb(self.log, self.dut, airplane_mode)
160        if wifi_enabled:
161            if not ensure_wifi_connected(self.log, self.dut,
162                                         self.wifi_network_ssid,
163                                         self.wifi_network_pass):
164                self.dut.log.error("Fail to connected to WiFi")
165                result = False
166        else:
167            if not wifi_toggle_state(self.log, self.dut, False):
168                self.dut.log.error("Failed to turn off WiFi.")
169                result = False
170        toggle_volte(self.log, self.dut, volte_enabled)
171        toggle_wfc(self.log, self.dut, wfc_enabled)
172        if wfc_mode:
173            set_wfc_mode(self.log, self.dut, wfc_mode)
174        wfc_mode = self.dut.droid.imsGetWfcMode()
175        if wifi_enabled or not airplane_mode:
176            if not ensure_phone_subscription(self.log, self.dut):
177                self.dut.log.error("Failed to find valid subscription")
178                result = False
179        if airplane_mode:
180            if (CAPABILITY_WFC in self.dut_capabilities) and (wifi_enabled
181                                                              and wfc_enabled):
182                if not wait_for_wfc_enabled(self.log, self.dut):
183                    result = False
184                elif not self.check_call_in_wfc():
185                    result = False
186            else:
187                if not wait_for_state(
188                        self.dut.droid.telephonyGetCurrentVoiceNetworkType,
189                        RAT_UNKNOWN):
190                    self.dut.log.error(
191                        "Voice RAT is %s not UNKNOWN",
192                        self.dut.droid.telephonyGetCurrentVoiceNetworkType())
193                    result = False
194                else:
195                    self.dut.log.info("Voice RAT is in UNKKNOWN")
196        else:
197            if (wifi_enabled and wfc_enabled) and (
198                    wfc_mode == WFC_MODE_WIFI_PREFERRED) and (
199                        CAPABILITY_WFC in self.dut_capabilities):
200                if not wait_for_wfc_enabled(self.log, self.dut):
201                    result = False
202                if not wait_for_state(
203                        self.dut.droid.telephonyGetCurrentVoiceNetworkType,
204                        RAT_UNKNOWN):
205                    self.dut.log.error(
206                        "Voice RAT is %s, not UNKNOWN",
207                        self.dut.droid.telephonyGetCurrentVoiceNetworkType())
208                if not self.check_call_in_wfc():
209                    result = False
210            else:
211                if not wait_for_wfc_disabled(self.log, self.dut):
212                    self.dut.log.error("WFC is not disabled")
213                    result = False
214                if volte_enabled and CAPABILITY_VOLTE in self.dut_capabilities:
215                    if not wait_for_volte_enabled(self.log, self.dut):
216                        result = False
217                    if not self.check_call_in_volte():
218                        result = False
219                else:
220                    if not wait_for_not_network_rat(
221                            self.log,
222                            self.dut,
223                            RAT_LTE,
224                            voice_or_data=NETWORK_SERVICE_VOICE):
225                        self.dut.log.error(
226                            "Voice RAT is %s",
227                            self.dut.droid.telephonyGetCurrentVoiceNetworkType(
228                            ))
229                        result = False
230                    if not wait_for_voice_attach(self.log, self.dut):
231                        result = False
232                    if not self.check_call():
233                        result = False
234        user_config_profile = get_user_config_profile(self.dut)
235        self.dut.log.info("user_config_profile: %s ",
236                          sorted(user_config_profile.items()))
237        return result
238
239    def verify_default_ims_setting(self):
240        result = True
241        airplane_mode = self.dut.droid.connectivityCheckAirplaneMode()
242        default_wfc_mode = self.carrier_configs.get(
243            CarrierConfigs.DEFAULT_WFC_IMS_MODE_INT, WFC_MODE_DISABLED)
244        if self.default_wfc_enabled:
245            wait_for_wfc_enabled(self.log, self.dut)
246        else:
247            wait_for_wfc_disabled(self.log, self.dut)
248            if airplane_mode:
249                wait_for_network_rat(
250                    self.log,
251                    self.dut,
252                    RAT_UNKNOWN,
253                    voice_or_data=NETWORK_SERVICE_VOICE)
254            else:
255                if self.default_volte:
256                    wait_for_volte_enabled(self.log, self.dut)
257                else:
258                    wait_for_not_network_rat(
259                        self.log,
260                        self.dut,
261                        RAT_UNKNOWN,
262                        voice_or_data=NETWORK_SERVICE_VOICE)
263        if not ensure_phone_subscription(self.log, self.dut):
264            ad.log.error("Failed to find valid subscription")
265            result = False
266        user_config_profile = get_user_config_profile(self.dut)
267        self.dut.log.info("user_config_profile = %s ",
268                          sorted(user_config_profile.items()))
269        if user_config_profile["VoLTE Enabled"] != self.default_volte:
270            self.dut.log.error("VoLTE mode is not %s", self.default_volte)
271            result = False
272        else:
273            self.dut.log.info("VoLTE mode is %s as expected",
274                              self.default_volte)
275        if user_config_profile["WFC Enabled"] != self.default_wfc_enabled:
276            self.dut.log.error("WFC enabled is not %s", default_wfc_enabled)
277        if user_config_profile["WFC Enabled"]:
278            if user_config_profile["WFC Mode"] != default_wfc_mode:
279                self.dut.log.error(
280                    "WFC mode is not %s after IMS factory reset",
281                    default_wfc_mode)
282                result = False
283            else:
284                self.dut.log.info("WFC mode is %s as expected",
285                                  default_wfc_mode)
286        if self.default_wfc_enabled and \
287            default_wfc_mode == WFC_MODE_WIFI_PREFERRED:
288            if not self.check_call_in_wfc():
289                result = False
290        elif not airplane_mode:
291            if self.default_volte:
292                if not self.check_call_in_volte():
293                    result = False
294            else:
295                if not self.check_call():
296                    result = False
297        if result == False:
298            user_config_profile = get_user_config_profile(self.dut)
299            self.dut.log.info("user_config_profile = %s ",
300                              sorted(user_config_profile.items()))
301        return result
302
303    @test_tracker_info(uuid="a3a680ba-d1e0-4770-a38c-4de8f15f9171")
304    @TelephonyBaseTest.tel_test_wrap
305    def test_lte_volte_wifi_connected_toggle_wfc(self):
306        """Test for WiFi Calling settings:
307        LTE + VoLTE Enabled + WiFi Connected, Toggling WFC
308
309        Steps:
310        1. Setup DUT Idle, LTE network type, VoLTE enabled.
311        2. Make sure DUT WiFi connected, WFC disabled.
312        3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
313            report iwlan rat.
314        4. Set DUT WFC disabled, verify DUT WFC unavailable,
315            not report iwlan rat.
316
317        Expected Results:
318        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
319        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
320        """
321        if not phone_setup_volte(self.log, self.dut):
322            self.log.error("Failed to setup VoLTE")
323            return False
324        if not self.change_ims_setting(False, True, True, True,
325                                       self.default_wfc_mode):
326            return False
327        if not self.change_ims_setting(False, True, True, False, None):
328            return False
329        return self.change_ims_setting(False, True, True, True, None)
330
331    @test_tracker_info(uuid="d3ffae75-ae4a-4ed8-9337-9155c413311d")
332    @TelephonyBaseTest.tel_test_wrap
333    def test_lte_wifi_connected_toggle_wfc(self):
334        """Test for WiFi Calling settings:
335        LTE + VoLTE Disabled + WiFi Connected, Toggling WFC
336
337        Steps:
338        1. Setup DUT Idle, LTE network type, VoLTE disabled.
339        2. Make sure DUT WiFi connected, WFC disabled.
340        3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
341            report iwlan rat.
342        4. Set DUT WFC disabled, verify DUT WFC unavailable,
343            not report iwlan rat.
344
345        Expected Results:
346        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
347        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
348        """
349        if not phone_setup_csfb(self.log, self.dut):
350            self.log.error("Failed to setup LTE")
351            return False
352        if not self.change_ims_setting(False, True, False, True,
353                                       self.default_wfc_mode):
354            return False
355        if not self.change_ims_setting(False, True, False, False, None):
356            return False
357        return self.change_ims_setting(False, True, False, True, None)
358
359    @test_tracker_info(uuid="29d2d7b7-1c31-4a2c-896a-3f6756c620ac")
360    @TelephonyBaseTest.tel_test_wrap
361    def test_3g_wifi_connected_toggle_wfc(self):
362        """Test for WiFi Calling settings:
363        3G + WiFi Connected, Toggling WFC
364
365        Steps:
366        1. Setup DUT Idle, 3G network type.
367        2. Make sure DUT WiFi connected, WFC disabled.
368        3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
369            report iwlan rat.
370        4. Set DUT WFC disabled, verify DUT WFC unavailable,
371            not report iwlan rat.
372
373        Expected Results:
374        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
375        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
376        """
377        if not phone_setup_voice_3g(self.log, self.dut):
378            self.log.error("Failed to setup 3G")
379            return False
380        if not self.change_ims_setting(False, True, False, True,
381                                       self.default_wfc_mode):
382            return False
383        if not self.change_ims_setting(False, True, False, False, None):
384            return False
385        return self.change_ims_setting(False, True, False, True, None)
386
387    @test_tracker_info(uuid="ce2c0208-9ea0-4b31-91f4-d06a62cb927a")
388    @TelephonyBaseTest.tel_test_wrap
389    def test_apm_wifi_connected_toggle_wfc(self):
390        """Test for WiFi Calling settings:
391        APM + WiFi Connected, Toggling WFC
392
393        Steps:
394        1. Setup DUT Idle, Airplane mode.
395        2. Make sure DUT WiFi connected, WFC disabled.
396        3. Set DUT WFC enabled (WiFi Preferred), verify DUT WFC available,
397            report iwlan rat.
398        4. Set DUT WFC disabled, verify DUT WFC unavailable,
399            not report iwlan rat.
400
401        Expected Results:
402        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
403        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
404        """
405        if not self.change_ims_setting(True, True, True, True,
406                                       self.default_wfc_mode):
407            return False
408        if not self.change_ims_setting(True, True, True, False, None):
409            return False
410        return self.change_ims_setting(True, True, True, True, None)
411
412    @test_tracker_info(uuid="681e2448-32a2-434d-abd6-0bc2ab5afd9c")
413    @TelephonyBaseTest.tel_test_wrap
414    def test_lte_volte_wfc_enabled_toggle_wifi(self):
415        """Test for WiFi Calling settings:
416        LTE + VoLTE Enabled + WFC enabled, Toggling WiFi
417
418        Steps:
419        1. Setup DUT Idle, LTE network type, VoLTE enabled.
420        2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
421        3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
422        4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
423
424        Expected Results:
425        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
426        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
427        """
428        if not phone_setup_volte(self.log, self.dut):
429            self.log.error("Failed to setup VoLTE")
430            return False
431        if not self.change_ims_setting(False, True, True, True,
432                                       self.default_wfc_mode):
433            return False
434        if not self.change_ims_setting(False, True, True, False, None):
435            return False
436        return self.change_ims_setting(False, True, True, True, None)
437
438    @test_tracker_info(uuid="63922066-9caa-42e6-bc9f-49f5ac01cbe2")
439    @TelephonyBaseTest.tel_test_wrap
440    def test_lte_wfc_enabled_toggle_wifi(self):
441        """Test for WiFi Calling settings:
442        LTE + VoLTE Disabled + WFC enabled, Toggling WiFi
443
444        Steps:
445        1. Setup DUT Idle, LTE network type, VoLTE disabled.
446        2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
447        3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
448        4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
449
450        Expected Results:
451        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
452        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
453        """
454        if not phone_setup_csfb(self.log, self.dut):
455            self.log.error("Failed to setup CSFB")
456            return False
457        if not self.change_ims_setting(False, True, False, True,
458                                       self.default_wfc_mode):
459            return False
460        if not self.change_ims_setting(False, False, False, True, None):
461            return False
462        return self.change_ims_setting(False, True, False, True, None)
463
464    @test_tracker_info(uuid="8a80a446-2116-4b19-b0ef-f771f30a6d15")
465    @TelephonyBaseTest.tel_test_wrap
466    def test_3g_wfc_enabled_toggle_wifi(self):
467        """Test for WiFi Calling settings:
468        3G + WFC enabled, Toggling WiFi
469
470        Steps:
471        1. Setup DUT Idle, 3G network type.
472        2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
473        3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
474        4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
475
476        Expected Results:
477        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
478        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
479        """
480        if not phone_setup_voice_3g(self.log, self.dut):
481            self.log.error("Failed to setup 3G")
482            return False
483        if not self.change_ims_setting(False, True, False, True,
484                                       self.default_wfc_mode):
485            return False
486        if not self.change_ims_setting(False, False, False, True, None):
487            return False
488        return self.change_ims_setting(False, True, False, True, None)
489
490    @test_tracker_info(uuid="9889eebf-cde6-4f47-aec0-9cb204fdf2e5")
491    @TelephonyBaseTest.tel_test_wrap
492    def test_apm_wfc_enabled_toggle_wifi(self):
493        """Test for WiFi Calling settings:
494        APM + WFC enabled, Toggling WiFi
495
496        Steps:
497        1. Setup DUT Idle, Airplane mode.
498        2. Make sure DUT WiFi disconnected, WFC enabled (WiFi Preferred).
499        3. DUT connect WiFi, verify DUT WFC available, report iwlan rat.
500        4. DUT disconnect WiFi,verify DUT WFC unavailable, not report iwlan rat.
501
502        Expected Results:
503        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
504        4. DUT WiFi Calling feature bit return False, network rat is not iwlan.
505        """
506        if not self.change_ims_setting(True, True, True, True,
507                                       self.default_wfc_mode):
508            return False
509        if not self.change_ims_setting(True, False, True, True, None):
510            return False
511        return self.change_ims_setting(True, True, True, True, None)
512
513    @test_tracker_info(uuid="9b23e04b-4f70-4e73-88e7-6376262c739d")
514    @TelephonyBaseTest.tel_test_wrap
515    def test_lte_wfc_enabled_wifi_connected_toggle_volte(self):
516        """Test for WiFi Calling settings:
517        LTE + VoLTE Enabled + WiFi Connected + WFC enabled, toggle VoLTE setting
518
519        Steps:
520        1. Setup DUT Idle, LTE network type, VoLTE enabled.
521        2. Make sure DUT WiFi connected, WFC enabled (WiFi Preferred).
522            Verify DUT WFC available, report iwlan rat.
523        3. Disable VoLTE on DUT, verify in 2 minutes period,
524            DUT does not lost WiFi Calling, DUT still report WFC available,
525            rat iwlan.
526        4. Enable VoLTE on DUT, verify in 2 minutes period,
527            DUT does not lost WiFi Calling, DUT still report WFC available,
528            rat iwlan.
529
530        Expected Results:
531        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
532        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
533        4. DUT WiFi Calling feature bit return True, network rat is iwlan.
534        """
535        if not phone_setup_volte(self.log, self.dut):
536            self.dut.log.error("Failed to setup VoLTE.")
537            return False
538        if not self.change_ims_setting(False, True, True, True,
539                                       self.default_wfc_mode):
540            return False
541        if not self.change_ims_setting(False, True, False, True, None):
542            return False
543        return self.change_ims_setting(False, True, True, True, None)
544
545    @test_tracker_info(uuid="04bdfda4-06f7-41df-9352-a8534bc2a67a")
546    @TelephonyBaseTest.tel_test_wrap
547    def test_lte_volte_wfc_wifi_preferred_to_cellular_preferred(self):
548        """Test for WiFi Calling settings:
549        LTE + VoLTE Enabled + WiFi Connected + WiFi Preferred,
550        change WFC to Cellular Preferred
551
552        Steps:
553        1. Setup DUT Idle, LTE network type, VoLTE enabled.
554        2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
555            Verify DUT WFC available, report iwlan rat.
556        3. Change WFC setting to Cellular Preferred.
557        4. Verify DUT report WFC not available.
558
559        Expected Results:
560        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
561        4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
562        """
563        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
564            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
565        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
566            raise signals.TestSkip(
567                "WFC_MODE_CELLULAR_PREFERRED is not supported")
568        if not phone_setup_volte(self.log, self.dut):
569            self.dut.log.error("Failed to setup VoLTE.")
570            return False
571        if not self.change_ims_setting(False, True, True, True,
572                                       WFC_MODE_WIFI_PREFERRED):
573            return False
574        return self.change_ims_setting(False, True, True, True,
575                                       WFC_MODE_CELLULAR_PREFERRED)
576
577    @test_tracker_info(uuid="80d26bdb-992a-4b30-ad51-68308d5af168")
578    @TelephonyBaseTest.tel_test_wrap
579    def test_lte_wfc_wifi_preferred_to_cellular_preferred(self):
580        """Test for WiFi Calling settings:
581        LTE + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
582
583        Steps:
584        1. Setup DUT Idle, LTE network type, VoLTE disabled.
585        2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
586            Verify DUT WFC available, report iwlan rat.
587        3. Change WFC setting to Cellular Preferred.
588        4. Verify DUT report WFC not available.
589
590        Expected Results:
591        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
592        4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
593        """
594        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
595            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
596        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
597            raise signals.TestSkip(
598                "WFC_MODE_CELLULAR_PREFERRED is not supported")
599        if not phone_setup_csfb(self.log, self.dut):
600            self.dut.log.error("Failed to setup LTE.")
601            return False
602        if not self.change_ims_setting(False, True, False, True,
603                                       WFC_MODE_WIFI_PREFERRED):
604            return False
605        return self.change_ims_setting(False, True, False, True,
606                                       WFC_MODE_CELLULAR_PREFERRED)
607
608    @test_tracker_info(uuid="d486c7e3-3d2b-4552-8af8-7b19f6347427")
609    @TelephonyBaseTest.tel_test_wrap
610    def test_3g_wfc_wifi_preferred_to_cellular_preferred(self):
611        """Test for WiFi Calling settings:
612        3G + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
613
614        Steps:
615        1. Setup DUT Idle, 3G network type.
616        2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
617            Verify DUT WFC available, report iwlan rat.
618        3. Change WFC setting to Cellular Preferred.
619        4. Verify DUT report WFC not available.
620
621        Expected Results:
622        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
623        4. DUT WiFI Calling feature bit return False, network rat is not iwlan.
624        """
625        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
626            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
627        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
628            raise signals.TestSkip(
629                "WFC_MODE_CELLULAR_PREFERRED is not supported")
630        if not phone_setup_voice_3g(self.dut.log, self.dut):
631            self.dut.log.error("Failed to setup 3G.")
632            return False
633        if not self.change_ims_setting(False, True, False, True,
634                                       WFC_MODE_WIFI_PREFERRED):
635            return False
636        return self.change_ims_setting(False, True, False, True,
637                                       WFC_MODE_CELLULAR_PREFERRED)
638
639    @test_tracker_info(uuid="0feb0add-8e22-4c86-b13e-be68659cdd87")
640    @TelephonyBaseTest.tel_test_wrap
641    def test_apm_wfc_wifi_preferred_to_cellular_preferred(self):
642        """Test for WiFi Calling settings:
643        APM + WiFi Connected + WiFi Preferred, change WFC to Cellular Preferred
644
645        Steps:
646        1. Setup DUT Idle, airplane mode.
647        2. Make sure DUT WiFi connected, WFC is set to WiFi Preferred.
648            Verify DUT WFC available, report iwlan rat.
649        3. Change WFC setting to Cellular Preferred.
650        4. Verify DUT report WFC not available.
651
652        Expected Results:
653        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
654        4. DUT WiFI Calling feature bit return True, network rat is iwlan.
655        """
656        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
657            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
658        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
659            raise signals.TestSkip(
660                "WFC_MODE_CELLULAR_PREFERRED is not supported")
661        if not self.change_ims_setting(True, True, True, True,
662                                       WFC_MODE_WIFI_PREFERRED):
663            return False
664        return self.change_ims_setting(True, True, True, True,
665                                       WFC_MODE_CELLULAR_PREFERRED)
666
667    @test_tracker_info(uuid="9c8f359f-a084-4413-b8a9-34771af166c5")
668    @TelephonyBaseTest.tel_test_wrap
669    def test_lte_volte_wfc_cellular_preferred_to_wifi_preferred(self):
670        """Test for WiFi Calling settings:
671        LTE + VoLTE Enabled + WiFi Connected + Cellular Preferred,
672        change WFC to WiFi Preferred
673
674        Steps:
675        1. Setup DUT Idle, LTE network type, VoLTE enabled.
676        2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
677            Verify DUT WFC not available.
678        3. Change WFC setting to WiFi Preferred.
679        4. Verify DUT report WFC available.
680
681        Expected Results:
682        2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
683        4. DUT WiFI Calling feature bit return True, network rat is iwlan.
684        """
685        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
686            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
687        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
688            raise signals.TestSkip(
689                "WFC_MODE_CELLULAR_PREFERRED is not supported")
690        if not phone_setup_volte(self.log, self.dut):
691            self.dut.log.error("Failed to setup VoLTE.")
692            return False
693        if not self.change_ims_setting(False, True, True, True,
694                                       WFC_MODE_CELLULAR_PREFERRED):
695            return False
696        return self.change_ims_setting(False, True, True, True,
697                                       WFC_MODE_WIFI_PREFERRED)
698
699    @test_tracker_info(uuid="1894e685-63cf-43aa-91ed-938782ca35a9")
700    @TelephonyBaseTest.tel_test_wrap
701    def test_lte_wfc_cellular_preferred_to_wifi_preferred(self):
702        """Test for WiFi Calling settings:
703        LTE + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
704
705        Steps:
706        1. Setup DUT Idle, LTE network type, VoLTE disabled.
707        2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
708            Verify DUT WFC not available.
709        3. Change WFC setting to WiFi Preferred.
710        4. Verify DUT report WFC available.
711
712        Expected Results:
713        2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
714        4. DUT WiFI Calling feature bit return True, network rat is iwlan.
715        """
716        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
717            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
718        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
719            raise signals.TestSkip(
720                "WFC_MODE_CELLULAR_PREFERRED is not supported")
721        if not phone_setup_csfb(self.log, self.dut):
722            self.dut.log.error("Failed to setup LTE.")
723            return False
724        if not self.change_ims_setting(False, True, False, True,
725                                       WFC_MODE_CELLULAR_PREFERRED):
726            return False
727        return self.change_ims_setting(False, True, False, True,
728                                       WFC_MODE_WIFI_PREFERRED)
729
730    @test_tracker_info(uuid="e7fb6a6c-4672-44da-bca2-78b4d96dea9e")
731    @TelephonyBaseTest.tel_test_wrap
732    def test_3g_wfc_cellular_preferred_to_wifi_preferred(self):
733        """Test for WiFi Calling settings:
734        3G + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
735
736        Steps:
737        1. Setup DUT Idle, 3G network type.
738        2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
739            Verify DUT WFC not available.
740        3. Change WFC setting to WiFi Preferred.
741        4. Verify DUT report WFC available.
742
743        Expected Results:
744        2. DUT WiFi Calling feature bit return False, network rat is not iwlan.
745        4. DUT WiFI Calling feature bit return True, network rat is iwlan.
746        """
747        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
748            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
749        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
750            raise signals.TestSkip(
751                "WFC_MODE_CELLULAR_PREFERRED is not supported")
752        if not phone_setup_voice_3g(self.log, self.dut):
753            self.dut.log.error("Failed to setup 3G.")
754            return False
755        if not self.change_ims_setting(False, True, False, True,
756                                       WFC_MODE_CELLULAR_PREFERRED):
757            return False
758        return self.change_ims_setting(False, True, False, True,
759                                       WFC_MODE_WIFI_PREFERRED)
760
761    @test_tracker_info(uuid="46262b2d-5de9-4984-87e8-42f44469289e")
762    @TelephonyBaseTest.tel_test_wrap
763    def test_apm_wfc_cellular_preferred_to_wifi_preferred(self):
764        """Test for WiFi Calling settings:
765        APM + WiFi Connected + Cellular Preferred, change WFC to WiFi Preferred
766
767        Steps:
768        1. Setup DUT Idle, airplane mode.
769        2. Make sure DUT WiFi connected, WFC is set to Cellular Preferred.
770            Verify DUT WFC not available.
771        3. Change WFC setting to WiFi Preferred.
772        4. Verify DUT report WFC available.
773
774        Expected Results:
775        2. DUT WiFi Calling feature bit return True, network rat is iwlan.
776        4. DUT WiFI Calling feature bit return True, network rat is iwlan.
777        """
778        if WFC_MODE_WIFI_PREFERRED not in self.dut_wfc_modes:
779            raise signals.TestSkip("WFC_MODE_WIFI_PREFERRED is not supported")
780        if WFC_MODE_CELLULAR_PREFERRED not in self.dut_wfc_modes:
781            raise signals.TestSkip(
782                "WFC_MODE_CELLULAR_PREFERRED is not supported")
783        if not self.change_ims_setting(True, True, True, True,
784                                       WFC_MODE_CELLULAR_PREFERRED):
785            return False
786        return self.change_ims_setting(True, True, True, True,
787                                       WFC_MODE_WIFI_PREFERRED)
788
789    @test_tracker_info(uuid="5b514f51-fed9-475e-99d3-17d2165e11a1")
790    @TelephonyBaseTest.tel_test_wrap
791    def test_apm_wfc_wifi_preferred_turn_off_apm(self):
792        """Test for WiFi Calling settings:
793        APM + WiFi Connected + WiFi Preferred + turn off APM
794
795        Steps:
796        1. Setup DUT Idle in Airplane mode.
797        2. Make sure DUT WiFi connected, set WFC mode to WiFi preferred.
798        3. verify DUT WFC available, report iwlan rat.
799        4. Turn off airplane mode.
800        5. Verify DUT WFC still available, report iwlan rat
801
802        Expected Results:
803        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
804        5. DUT WiFI Calling feature bit return True, network rat is iwlan.
805        """
806        if not self.change_ims_setting(True, True, True, True,
807                                       WFC_MODE_WIFI_PREFERRED):
808            return False
809        return self.change_ims_setting(False, True, True, True, None)
810
811    @test_tracker_info(uuid="f328cff2-9dec-44b3-ba74-a662b76fcf2a")
812    @TelephonyBaseTest.tel_test_wrap
813    def test_apm_wfc_cellular_preferred_turn_off_apm(self):
814        """Test for WiFi Calling settings:
815        APM + WiFi Connected + Cellular Preferred + turn off APM
816
817        Steps:
818        1. Setup DUT Idle in Airplane mode.
819        2. Make sure DUT WiFi connected, set WFC mode to Cellular preferred.
820        3. verify DUT WFC available, report iwlan rat.
821        4. Turn off airplane mode.
822        5. Verify DUT WFC not available, not report iwlan rat
823
824        Expected Results:
825        3. DUT WiFi Calling feature bit return True, network rat is iwlan.
826        5. DUT WiFI Calling feature bit return False, network rat is not iwlan.
827        """
828        if not self.change_ims_setting(True, True, True, True,
829                                       WFC_MODE_CELLULAR_PREFERRED):
830            return False
831        return self.change_ims_setting(False, True, True, True, None)
832
833    @test_tracker_info(uuid="7e30d219-42ee-4309-a95c-2b45b8831d26")
834    @TelephonyBaseTest.tel_test_wrap
835    def test_wfc_setup_timing(self):
836        """ Measures the time delay in enabling WiFi calling
837
838        Steps:
839        1. Make sure DUT idle.
840        2. Turn on Airplane Mode, Set WiFi Calling to WiFi_Preferred.
841        3. Turn on WiFi, connect to WiFi AP and measure time delay.
842        4. Wait for WiFi connected, verify Internet and measure time delay.
843        5. Wait for rat to be reported as iwlan and measure time delay.
844        6. Wait for ims registered and measure time delay.
845        7. Wait for WiFi Calling feature bit to be True and measure time delay.
846
847        Expected results:
848        Time Delay in each step should be within pre-defined limit.
849
850        Returns:
851            Currently always return True.
852        """
853        # TODO: b/26338119 Set pass/fail criteria
854        time_values = {
855            'start': 0,
856            'wifi_enabled': 0,
857            'wifi_connected': 0,
858            'wifi_data': 0,
859            'iwlan_rat': 0,
860            'ims_registered': 0,
861            'wfc_enabled': 0,
862            'mo_call_success': 0
863        }
864
865        wifi_reset(self.log, self.dut)
866        toggle_airplane_mode_by_adb(self.log, self.dut, True)
867
868        set_wfc_mode(self.log, self.dut, WFC_MODE_WIFI_PREFERRED)
869
870        time_values['start'] = time.time()
871
872        self.dut.log.info("Start Time %ss", time_values['start'])
873
874        wifi_toggle_state(self.log, self.dut, True)
875        time_values['wifi_enabled'] = time.time()
876        self.dut.log.info("WiFi Enabled After %ss",
877                          time_values['wifi_enabled'] - time_values['start'])
878
879        network = {WIFI_SSID_KEY: self.wifi_network_ssid}
880        if self.wifi_network_pass:
881            network[WIFI_PWD_KEY] = self.wifi_network_pass
882        try:
883            self.dut.droid.wifiConnectByConfig(network)
884        except Exception:
885            self.dut.log.info("Connecting to wifi by RPC wifiConnect instead")
886            self.dut.droid.wifiConnect(network)
887        self.dut.droid.wakeUpNow()
888
889        if not wait_for_wifi_data_connection(self.log, self.dut, True,
890                                             MAX_WAIT_TIME_WIFI_CONNECTION):
891            self.dut.log.error("Failed WiFi connection, aborting!")
892            return False
893        time_values['wifi_connected'] = time.time()
894
895        self.dut.log.info(
896            "WiFi Connected After %ss",
897            time_values['wifi_connected'] - time_values['wifi_enabled'])
898
899        if not verify_internet_connection(self.log, self.dut, retries=3):
900            self.dut.log.error("Failed to get user-plane traffic, aborting!")
901            return False
902
903        time_values['wifi_data'] = time.time()
904        self.dut.log.info(
905            "WifiData After %ss",
906            time_values['wifi_data'] - time_values['wifi_connected'])
907
908        if not wait_for_network_rat(
909                self.log,
910                self.dut,
911                RAT_FAMILY_WLAN,
912                voice_or_data=NETWORK_SERVICE_DATA):
913            self.dut.log.error("Failed to set-up iwlan, aborting!")
914            if is_droid_in_rat_family(self.log, self.dut, RAT_FAMILY_WLAN,
915                                      NETWORK_SERVICE_DATA):
916                self.dut.log.error(
917                    "Never received the event, but droid in iwlan")
918            else:
919                return False
920        time_values['iwlan_rat'] = time.time()
921        self.dut.log.info("iWLAN Reported After %ss",
922                          time_values['iwlan_rat'] - time_values['wifi_data'])
923
924        if not wait_for_ims_registered(self.log, self.dut,
925                                       MAX_WAIT_TIME_IMS_REGISTRATION):
926            self.dut.log.error("Never received IMS registered, aborting")
927            return False
928        time_values['ims_registered'] = time.time()
929        self.dut.log.info(
930            "Ims Registered After %ss",
931            time_values['ims_registered'] - time_values['iwlan_rat'])
932
933        if not wait_for_wfc_enabled(self.log, self.dut,
934                                    MAX_WAIT_TIME_WFC_ENABLED):
935            self.dut.log.error("Never received WFC feature, aborting")
936            return False
937
938        time_values['wfc_enabled'] = time.time()
939        self.dut.log.info(
940            "Wifi Calling Feature Enabled After %ss",
941            time_values['wfc_enabled'] - time_values['ims_registered'])
942
943        set_wfc_mode(self.log, self.dut, WFC_MODE_DISABLED)
944
945        wait_for_not_network_rat(
946            self.log,
947            self.dut,
948            RAT_FAMILY_WLAN,
949            voice_or_data=NETWORK_SERVICE_DATA)
950
951        self.dut.log.info("\n\n------------------summary-----------------")
952        self.dut.log.info("WiFi Enabled After %.2f seconds",
953                          time_values['wifi_enabled'] - time_values['start'])
954        self.dut.log.info(
955            "WiFi Connected After %.2f seconds",
956            time_values['wifi_connected'] - time_values['wifi_enabled'])
957        self.dut.log.info(
958            "WifiData After %.2f s",
959            time_values['wifi_data'] - time_values['wifi_connected'])
960        self.dut.log.info("iWLAN Reported After %.2f seconds",
961                          time_values['iwlan_rat'] - time_values['wifi_data'])
962        self.dut.log.info(
963            "Ims Registered After %.2f seconds",
964            time_values['ims_registered'] - time_values['iwlan_rat'])
965        self.dut.log.info(
966            "Wifi Calling Feature Enabled After %.2f seconds",
967            time_values['wfc_enabled'] - time_values['ims_registered'])
968        self.dut.log.info("\n\n")
969        return True
970
971    @test_tracker_info(uuid="135301ea-6d00-4233-98fd-cda706d61eb2")
972    @TelephonyBaseTest.tel_test_wrap
973    def test_ims_factory_reset(self):
974        """Test VOLTE and WFC reset to factory default.
975
976        Steps:
977        1. Setup VoLTE, WFC, APM is various mode.
978        2. Call IMS factory reset.
979        3. Verify VoLTE and WFC are back to factory default.
980        4. Verify VoLTE, WFC Voice call can be made successful if enabled.
981
982        """
983        result = True
984        wifi_enabled = True
985        for airplane_mode in (True, False):
986            for volte_enabled in (True, False):
987                for wfc_enabled in (True, False):
988                    if wfc_enabled:
989                        wfc_modes = self.dut_wfc_modes
990                    else:
991                        wfc_modes = [None]
992                    for wfc_mode in wfc_modes:
993                        if not self.change_ims_setting(
994                                airplane_mode, wifi_enabled, volte_enabled,
995                                wfc_enabled, wfc_mode):
996                            result = False
997                        self.dut.log.info("Call IMS factory reset")
998                        self.dut.droid.telephonyFactoryReset()
999                        if not self.verify_default_ims_setting():
1000                            result = False
1001        return result
1002
1003    @test_tracker_info(uuid="ce60740f-4d8e-4013-a7cf-65589e8a0893")
1004    @TelephonyBaseTest.tel_test_wrap
1005    def test_factory_reset_by_fastboot_wipe(self):
1006        """Verify the network setting after factory reset by wipe.
1007
1008        Steps:
1009        1. Config VoLTE, WFC, APM, data_roamingn, mobile_data,
1010           preferred_network_mode to non-factory default.
1011        2. Factory reset by fastboot wipe.
1012        3. Verify network configs back to factory default.
1013
1014        """
1015        self.dut.log.info("Set VoLTE off, WFC wifi preferred, APM on")
1016        toggle_volte(self.log, self.dut, False)
1017        revert_default_telephony_setting(self.dut)
1018        self.change_ims_setting(True, True, False, True,
1019                                WFC_MODE_WIFI_PREFERRED)
1020        self.dut.log.info("Wipe in fastboot")
1021        fastboot_wipe(self.dut)
1022        return verify_default_telephony_setting(
1023            self.dut) and (self.verify_default_ims_setting())
1024