• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2021 - 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
17from acts_contrib.test_utils.tel.tel_subscription_utils import get_outgoing_voice_sub_id
18from acts_contrib.test_utils.tel.tel_defines import CAPABILITY_VOLTE
19from acts_contrib.test_utils.tel.tel_defines import CAPABILITY_WFC
20from acts_contrib.test_utils.tel.tel_defines import CarrierConfigs
21from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_VOICE
22from acts_contrib.test_utils.tel.tel_defines import RAT_LTE
23from acts_contrib.test_utils.tel.tel_defines import RAT_NR
24from acts_contrib.test_utils.tel.tel_defines import RAT_UNKNOWN
25from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
26from acts_contrib.test_utils.tel.tel_test_utils import call_setup_teardown
27from acts_contrib.test_utils.tel.tel_test_utils import ensure_phone_subscription
28from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected
29from acts_contrib.test_utils.tel.tel_test_utils import get_user_config_profile
30from acts_contrib.test_utils.tel.tel_test_utils import set_wfc_mode
31from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
32from acts_contrib.test_utils.tel.tel_test_utils import toggle_volte
33from acts_contrib.test_utils.tel.tel_test_utils import toggle_wfc
34from acts_contrib.test_utils.tel.tel_test_utils import wait_for_network_rat
35from acts_contrib.test_utils.tel.tel_test_utils import wait_for_not_network_rat
36from acts_contrib.test_utils.tel.tel_test_utils import wait_for_state
37from acts_contrib.test_utils.tel.tel_test_utils import wait_for_voice_attach
38from acts_contrib.test_utils.tel.tel_test_utils import wait_for_volte_enabled
39from acts_contrib.test_utils.tel.tel_test_utils import wait_for_wfc_disabled
40from acts_contrib.test_utils.tel.tel_test_utils import wait_for_wfc_enabled
41from acts_contrib.test_utils.tel.tel_test_utils import wifi_toggle_state
42from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
43from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
44
45
46def check_call(log, dut, dut_client):
47    result = True
48    if not call_setup_teardown(log, dut_client, dut,
49                               dut):
50        if not call_setup_teardown(log, dut_client,
51                                   dut, dut):
52            dut.log.error("MT call failed")
53            result = False
54    if not call_setup_teardown(log, dut, dut_client,
55                               dut):
56        dut.log.error("MO call failed")
57        result = False
58    return result
59
60
61def check_call_in_wfc(log, dut, dut_client):
62    result = True
63    if not call_setup_teardown(log, dut_client, dut,
64                               dut, None, is_phone_in_call_iwlan):
65        if not call_setup_teardown(log, dut_client,
66                                   dut, dut, None,
67                                   is_phone_in_call_iwlan):
68            dut.log.error("MT WFC call failed")
69            result = False
70    if not call_setup_teardown(log, dut, dut_client,
71                               dut, is_phone_in_call_iwlan):
72        dut.log.error("MO WFC call failed")
73        result = False
74    return result
75
76
77def check_call_in_volte(log, dut, dut_client):
78    result = True
79    if not call_setup_teardown(log, dut_client, dut,
80                               dut, None, is_phone_in_call_volte):
81        if not call_setup_teardown(log, dut_client,
82                                   dut, dut, None,
83                                   is_phone_in_call_volte):
84            dut.log.error("MT VoLTE call failed")
85            result = False
86    if not call_setup_teardown(log, dut, dut_client,
87                               dut, is_phone_in_call_volte):
88        dut.log.error("MO VoLTE call failed")
89        result = False
90    return result
91
92
93def change_ims_setting(log,
94                       ad,
95                       dut_client,
96                       wifi_network_ssid,
97                       wifi_network_pass,
98                       subid,
99                       dut_capabilities,
100                       airplane_mode,
101                       wifi_enabled,
102                       volte_enabled,
103                       wfc_enabled,
104                       nw_gen=RAT_LTE,
105                       wfc_mode=None):
106    result = True
107    ad.log.info(
108        "Setting APM %s, WIFI %s, VoLTE %s, WFC %s, WFC mode %s",
109        airplane_mode, wifi_enabled, volte_enabled, wfc_enabled, wfc_mode)
110
111    toggle_airplane_mode_by_adb(log, ad, airplane_mode)
112    if wifi_enabled:
113        if not ensure_wifi_connected(log, ad,
114                                     wifi_network_ssid,
115                                     wifi_network_pass,
116                                     apm=airplane_mode):
117            ad.log.error("Fail to connected to WiFi")
118            result = False
119    else:
120        if not wifi_toggle_state(log, ad, False):
121            ad.log.error("Failed to turn off WiFi.")
122            result = False
123    toggle_volte(log, ad, volte_enabled)
124    toggle_wfc(log, ad, wfc_enabled)
125    if wfc_mode:
126        set_wfc_mode(log, ad, wfc_mode)
127    wfc_mode = ad.droid.imsGetWfcMode()
128    if wifi_enabled or not airplane_mode:
129        if not ensure_phone_subscription(log, ad):
130            ad.log.error("Failed to find valid subscription")
131            result = False
132    if airplane_mode:
133        if (CAPABILITY_WFC in dut_capabilities) and (wifi_enabled
134                                                          and wfc_enabled):
135            if not wait_for_wfc_enabled(log, ad):
136                result = False
137            elif not check_call_in_wfc(log, ad, dut_client):
138                result = False
139        else:
140            if not wait_for_state(
141                    ad.droid.telephonyGetCurrentVoiceNetworkType,
142                    RAT_UNKNOWN):
143                ad.log.error(
144                    "Voice RAT is %s not UNKNOWN",
145                    ad.droid.telephonyGetCurrentVoiceNetworkType())
146                result = False
147            else:
148                ad.log.info("Voice RAT is in UNKKNOWN")
149    else:
150        if (wifi_enabled and wfc_enabled) and (
151                wfc_mode == WFC_MODE_WIFI_PREFERRED) and (
152                    CAPABILITY_WFC in dut_capabilities):
153            if not wait_for_wfc_enabled(log, ad):
154                result = False
155            if not wait_for_state(
156                    ad.droid.telephonyGetCurrentVoiceNetworkType,
157                    RAT_UNKNOWN):
158                ad.log.error(
159                    "Voice RAT is %s, not UNKNOWN",
160                    ad.droid.telephonyGetCurrentVoiceNetworkType())
161            if not check_call_in_wfc(log, ad, dut_client):
162                result = False
163        else:
164            if not wait_for_wfc_disabled(log, ad):
165               ad.log.error("WFC is not disabled")
166               result = False
167            if volte_enabled and CAPABILITY_VOLTE in dut_capabilities:
168               if not wait_for_volte_enabled(log, ad):
169                    result = False
170               if not check_call_in_volte(log, ad, dut_client):
171                    result = False
172            else:
173                if not wait_for_not_network_rat(
174                        log,
175                        ad,
176                        nw_gen,
177                        voice_or_data=NETWORK_SERVICE_VOICE):
178                    ad.log.error(
179                        "Voice RAT is %s",
180                        ad.droid.telephonyGetCurrentVoiceNetworkType(
181                        ))
182                    result = False
183                if not wait_for_voice_attach(log, ad):
184                    result = False
185                if not check_call(log, ad, dut_client):
186                    result = False
187    user_config_profile = get_user_config_profile(ad)
188    ad.log.info("user_config_profile: %s ",
189                      sorted(user_config_profile.items()))
190    return result
191
192
193def verify_default_ims_setting(log,
194                       ad,
195                       dut_client,
196                       carrier_configs,
197                       default_wfc_enabled,
198                       default_volte,
199                       wfc_mode=None):
200    result = True
201    airplane_mode = ad.droid.connectivityCheckAirplaneMode()
202    default_wfc_mode = carrier_configs.get(
203        CarrierConfigs.DEFAULT_WFC_IMS_MODE_INT, wfc_mode)
204    if default_wfc_enabled:
205        wait_for_wfc_enabled(log, ad)
206    else:
207        wait_for_wfc_disabled(log, ad)
208        if airplane_mode:
209            wait_for_network_rat(
210                log,
211                ad,
212                RAT_UNKNOWN,
213                voice_or_data=NETWORK_SERVICE_VOICE)
214        else:
215            if default_volte:
216                wait_for_volte_enabled(log, ad)
217            else:
218                wait_for_not_network_rat(
219                    log,
220                    ad,
221                    RAT_UNKNOWN,
222                    voice_or_data=NETWORK_SERVICE_VOICE)
223
224    if not ensure_phone_subscription(log, ad):
225        ad.log.error("Failed to find valid subscription")
226        result = False
227    user_config_profile = get_user_config_profile(ad)
228    ad.log.info("user_config_profile = %s ",
229                      sorted(user_config_profile.items()))
230    if user_config_profile["VoLTE Enabled"] != default_volte:
231        ad.log.error("VoLTE mode is not %s", default_volte)
232        result = False
233    else:
234        ad.log.info("VoLTE mode is %s as expected",
235                          default_volte)
236    if user_config_profile["WFC Enabled"] != default_wfc_enabled:
237        ad.log.error("WFC enabled is not %s", default_wfc_enabled)
238    if user_config_profile["WFC Enabled"]:
239        if user_config_profile["WFC Mode"] != default_wfc_mode:
240            ad.log.error(
241                "WFC mode is not %s after IMS factory reset",
242                default_wfc_mode)
243            result = False
244        else:
245            ad.log.info("WFC mode is %s as expected",
246                              default_wfc_mode)
247    if default_wfc_enabled and \
248        default_wfc_mode == WFC_MODE_WIFI_PREFERRED:
249        if not check_call_in_wfc(log, ad, dut_client):
250            result = False
251    elif not airplane_mode:
252        if default_volte:
253            if not check_call_in_volte(log, ad, dut_client):
254                result = False
255        else:
256            if not check_call(log, ad, dut_client):
257                result = False
258    if result == False:
259        user_config_profile = get_user_config_profile(ad)
260        ad.log.info("user_config_profile = %s ",
261                          sorted(user_config_profile.items()))
262    return result
263
264
265
266