blob: 4d91839fd5133e377819224bf8feb0024211b282 [file] [log] [blame]
Markus Liue3143912021-03-31 10:49:00 +08001#!/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
17import re
Markus Liu481eccd2021-04-21 14:36:15 +080018import time
Markus Liuccd95342021-07-05 01:55:05 +080019from datetime import datetime, timedelta
Markus Liue3143912021-03-31 10:49:00 +080020
Markus Liue3143912021-03-31 10:49:00 +080021from acts import signals
Markus Liufdef3062021-06-27 15:08:29 +080022from acts.utils import rand_ascii_str
Markus Liuf1bbcb02021-10-20 11:30:12 +080023from acts.libs.utils.multithread import multithread_func
Markus Liue3143912021-03-31 10:49:00 +080024from acts_contrib.test_utils.tel.loggers.protos.telephony_metric_pb2 import TelephonyVoiceTestResult
Markus Liue3143912021-03-31 10:49:00 +080025from acts_contrib.test_utils.tel.tel_defines import INVALID_SUB_ID
Markus Liufdef3062021-06-27 15:08:29 +080026from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_SMS_RECEIVE
27from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
Markus Liu3bedf212021-06-16 17:39:07 +080028from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
Richard Chang8d40b882021-06-28 23:58:51 +080029from acts_contrib.test_utils.tel.tel_defines import YOUTUBE_PACKAGE_NAME
Markus Liu82791952021-11-01 18:43:42 +080030from acts_contrib.test_utils.tel.tel_message_utils import log_messaging_screen_shot
31from acts_contrib.test_utils.tel.tel_message_utils import mms_send_receive_verify
32from acts_contrib.test_utils.tel.tel_message_utils import sms_send_receive_verify_for_subscription
Markus Liuca44a202021-11-03 18:47:06 +080033from acts_contrib.test_utils.tel.tel_ss_utils import erase_call_forwarding_by_mmi
34from acts_contrib.test_utils.tel.tel_ss_utils import set_call_forwarding_by_mmi
35from acts_contrib.test_utils.tel.tel_ss_utils import set_call_waiting
Markus Liu7b42b3b2021-11-02 16:56:11 +080036from acts_contrib.test_utils.tel.tel_ims_utils import toggle_wfc_for_subscription
37from acts_contrib.test_utils.tel.tel_ims_utils import set_wfc_mode_for_subscription
Markus Liu44b04be2021-11-05 13:59:32 +080038from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_general
39from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_on_rat
40from acts_contrib.test_utils.tel.tel_phone_setup_utils import wait_for_network_idle
41from acts_contrib.test_utils.tel.tel_ss_utils import three_phone_call_forwarding_short_seq
42from acts_contrib.test_utils.tel.tel_ss_utils import three_phone_call_waiting_short_seq
Markus Liufdef3062021-06-27 15:08:29 +080043from acts_contrib.test_utils.tel.tel_subscription_utils import get_default_data_sub_id
Markus Liue3143912021-03-31 10:49:00 +080044from acts_contrib.test_utils.tel.tel_subscription_utils import get_incoming_voice_sub_id
Markus Liufdef3062021-06-27 15:08:29 +080045from acts_contrib.test_utils.tel.tel_subscription_utils import get_outgoing_message_sub_id
Markus Liue3143912021-03-31 10:49:00 +080046from acts_contrib.test_utils.tel.tel_subscription_utils import get_outgoing_voice_sub_id
Markus Liu6dc6e4e2021-11-29 20:22:28 +080047from acts_contrib.test_utils.tel.tel_subscription_utils import get_slot_index_from_subid
Markus Liue3143912021-03-31 10:49:00 +080048from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_from_slot_index
Markus Liufdef3062021-06-27 15:08:29 +080049from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_on_same_network_of_host_ad
50from acts_contrib.test_utils.tel.tel_subscription_utils import set_dds_on_slot
Markus Liufdef3062021-06-27 15:08:29 +080051from acts_contrib.test_utils.tel.tel_subscription_utils import set_message_subid
52from acts_contrib.test_utils.tel.tel_subscription_utils import set_subid_for_data
53from acts_contrib.test_utils.tel.tel_subscription_utils import set_voice_sub_id
Markus Liuccd95342021-07-05 01:55:05 +080054from acts_contrib.test_utils.tel.tel_test_utils import active_file_download_test
Markus Liu481eccd2021-04-21 14:36:15 +080055from acts_contrib.test_utils.tel.tel_test_utils import get_operator_name
Markus Liufdef3062021-06-27 15:08:29 +080056from acts_contrib.test_utils.tel.tel_test_utils import num_active_calls
Markus Liuccd95342021-07-05 01:55:05 +080057from acts_contrib.test_utils.tel.tel_test_utils import power_off_sim
58from acts_contrib.test_utils.tel.tel_test_utils import power_on_sim
Richard Chang8d40b882021-06-28 23:58:51 +080059from acts_contrib.test_utils.tel.tel_test_utils import start_youtube_video
Markus Liufdef3062021-06-27 15:08:29 +080060from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
Markus Liufdef3062021-06-27 15:08:29 +080061from acts_contrib.test_utils.tel.tel_test_utils import verify_incall_state
62from acts_contrib.test_utils.tel.tel_test_utils import verify_http_connection
Markus Liu481eccd2021-04-21 14:36:15 +080063from acts_contrib.test_utils.tel.tel_voice_conf_utils import _test_ims_conference_merge_drop_second_call_from_participant
64from acts_contrib.test_utils.tel.tel_voice_conf_utils import _test_wcdma_conference_merge_drop
Markus Liu3bedf212021-06-16 17:39:07 +080065from acts_contrib.test_utils.tel.tel_voice_conf_utils import _three_phone_call_mo_add_mt
Markus Liu44b04be2021-11-05 13:59:32 +080066from acts_contrib.test_utils.tel.tel_voice_utils import call_setup_teardown
67from acts_contrib.test_utils.tel.tel_voice_utils import hangup_call
68from acts_contrib.test_utils.tel.tel_voice_utils import initiate_call
69from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_on_rat
70from acts_contrib.test_utils.tel.tel_voice_utils import swap_calls
71from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_msim_for_slot
72from acts_contrib.test_utils.tel.tel_voice_utils import wait_and_reject_call_for_subscription
Markus Liu889876b2021-12-07 10:13:01 +080073from acts_contrib.test_utils.tel.tel_wifi_utils import ensure_wifi_connected
74from acts_contrib.test_utils.tel.tel_wifi_utils import wifi_toggle_state
Markus Liue3143912021-03-31 10:49:00 +080075
76CallResult = TelephonyVoiceTestResult.CallResult.Value
Richard Chang2243e0e2021-08-03 01:15:05 +080077
Markus Liu44b04be2021-11-05 13:59:32 +080078
Markus Liue3143912021-03-31 10:49:00 +080079def dsds_voice_call_test(
80 log,
Markus Liu86d06832021-10-13 17:31:02 +080081 tel_logger,
Markus Liue3143912021-03-31 10:49:00 +080082 ads,
83 mo_slot,
84 mt_slot,
85 dds,
86 mo_rat=["", ""],
87 mt_rat=["", ""],
Markus Liu528ac982021-07-19 01:30:37 +080088 call_direction="mo",
89 is_airplane_mode=False,
90 wfc_mode=[
91 WFC_MODE_CELLULAR_PREFERRED,
92 WFC_MODE_CELLULAR_PREFERRED],
93 wifi_network_ssid=None,
94 wifi_network_pass=None,
95 turn_off_wifi_in_the_end=False,
96 turn_off_airplane_mode_in_the_end=False):
Markus Liue3143912021-03-31 10:49:00 +080097 """Make MO/MT voice call at specific slot in specific RAT with DDS at
98 specific slot.
99
100 Test step:
101 1. Get sub IDs of specific slots of both MO and MT devices.
102 2. Switch DDS to specific slot.
103 3. Check HTTP connection after DDS switch.
104 4. Set up phones in desired RAT.
105 5. Make voice call.
Markus Liu528ac982021-07-19 01:30:37 +0800106 6. Turn off airplane mode if necessary.
107 7. Turn off Wi-Fi if necessary.
108 8. Verify RAT and HTTP connection.
Markus Liue3143912021-03-31 10:49:00 +0800109
110 Args:
111 log: logger object
Markus Liu86d06832021-10-13 17:31:02 +0800112 tel_logger: logger object for telephony proto
Markus Liue3143912021-03-31 10:49:00 +0800113 ads: list of android devices
114 mo_slot: Slot making MO call (0 or 1)
115 mt_slot: Slot receiving MT call (0 or 1)
116 dds: Preferred data slot
117 mo_rat: RAT for both slots of MO device
118 mt_rat: RAT for both slots of MT device
119 call_direction: "mo" or "mt"
Markus Liu528ac982021-07-19 01:30:37 +0800120 is_airplane_mode: True or False for WFC setup
121 wfc_mode: Cellular preferred or Wi-Fi preferred.
122 wifi_network_ssid: SSID of Wi-Fi AP
123 wifi_network_pass: Password of Wi-Fi AP SSID
124 turn_off_wifi_in_the_end: True to turn off Wi-Fi and False not to turn
125 off Wi-Fi in the end of the function.
126 turn_off_airplane_mode_in_the_end: True to turn off airplane mode and
127 False not to turn off airplane mode in the end of the function.
Markus Liue3143912021-03-31 10:49:00 +0800128
129 Returns:
130 TestFailure if failed.
131 """
Markus Liu528ac982021-07-19 01:30:37 +0800132 if not toggle_airplane_mode(log, ads[0], False):
133 ads[0].log.error("Failed to disable airplane mode.")
134 return False
135
Markus Liue3143912021-03-31 10:49:00 +0800136 if call_direction == "mo":
137 ad_mo = ads[0]
138 ad_mt = ads[1]
139 else:
140 ad_mo = ads[1]
141 ad_mt = ads[0]
142
143 if mo_slot is not None:
144 mo_sub_id = get_subid_from_slot_index(log, ad_mo, mo_slot)
145 if mo_sub_id == INVALID_SUB_ID:
146 ad_mo.log.warning("Failed to get sub ID ar slot %s.", mo_slot)
147 return False
148 mo_other_sub_id = get_subid_from_slot_index(
149 log, ad_mo, 1-mo_slot)
150 set_voice_sub_id(ad_mo, mo_sub_id)
151 else:
152 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
153 if mo_sub_id == INVALID_SUB_ID:
154 ad_mo.log.warning("Failed to get sub ID ar slot %s.", mo_slot)
155 return False
156 mo_slot = "auto"
157 set_voice_sub_id(ad_mo, mo_sub_id)
158 ad_mo.log.info("Sub ID for outgoing call at slot %s: %s",
159 mo_slot, get_outgoing_voice_sub_id(ad_mo))
160
161 if mt_slot is not None:
162 mt_sub_id = get_subid_from_slot_index(log, ad_mt, mt_slot)
163 if mt_sub_id == INVALID_SUB_ID:
164 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
165 return False
166 mt_other_sub_id = get_subid_from_slot_index(
167 log, ad_mt, 1-mt_slot)
168 set_voice_sub_id(ad_mt, mt_sub_id)
169 else:
170 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
171 if mt_sub_id == INVALID_SUB_ID:
172 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
173 return False
174 mt_slot = "auto"
175 set_voice_sub_id(ad_mt, mt_sub_id)
176 ad_mt.log.info("Sub ID for incoming call at slot %s: %s", mt_slot,
177 get_incoming_voice_sub_id(ad_mt))
178
179 log.info("Step 1: Switch DDS.")
Markus Liufdef3062021-06-27 15:08:29 +0800180 if not set_dds_on_slot(ads[0], dds):
181 log.error(
182 "Failed to set DDS at slot %s on %s",(dds, ads[0].serial))
183 return False
Markus Liue3143912021-03-31 10:49:00 +0800184
185 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liufdef3062021-06-27 15:08:29 +0800186 if not verify_http_connection(log, ads[0]):
Markus Liue3143912021-03-31 10:49:00 +0800187 log.error("Failed to verify http connection.")
188 return False
189 else:
190 log.info("Verify http connection successfully.")
191
Markus Liu528ac982021-07-19 01:30:37 +0800192 log.info("Step 3: Set up phones in desired RAT.")
Markus Liue3143912021-03-31 10:49:00 +0800193 if mo_slot == 0 or mo_slot == 1:
Markus Liu528ac982021-07-19 01:30:37 +0800194 phone_setup_on_rat(
195 log,
196 ad_mo,
197 mo_rat[1-mo_slot],
198 mo_other_sub_id,
199 is_airplane_mode,
200 wfc_mode[1-mo_slot],
201 wifi_network_ssid,
202 wifi_network_pass)
203
204 mo_phone_setup_func_argv = (
205 log,
206 ad_mo,
207 mo_rat[mo_slot],
208 mo_sub_id,
209 is_airplane_mode,
210 wfc_mode[mo_slot],
211 wifi_network_ssid,
212 wifi_network_pass)
213
Markus Liue3143912021-03-31 10:49:00 +0800214 is_mo_in_call = is_phone_in_call_on_rat(
215 log, ad_mo, mo_rat[mo_slot], only_return_fn=True)
216 else:
217 mo_phone_setup_func_argv = (log, ad_mo, 'general')
218 is_mo_in_call = is_phone_in_call_on_rat(
219 log, ad_mo, 'general', only_return_fn=True)
220
221 if mt_slot == 0 or mt_slot == 1:
Markus Liu528ac982021-07-19 01:30:37 +0800222 phone_setup_on_rat(
223 log,
224 ad_mt,
225 mt_rat[1-mt_slot],
226 mt_other_sub_id,
227 is_airplane_mode,
228 wfc_mode[1-mt_slot],
229 wifi_network_ssid,
230 wifi_network_pass)
231
232 mt_phone_setup_func_argv = (
233 log,
234 ad_mt,
235 mt_rat[mt_slot],
236 mt_sub_id,
237 is_airplane_mode,
238 wfc_mode[mt_slot],
239 wifi_network_ssid,
240 wifi_network_pass)
241
Markus Liue3143912021-03-31 10:49:00 +0800242 is_mt_in_call = is_phone_in_call_on_rat(
243 log, ad_mt, mt_rat[mt_slot], only_return_fn=True)
244 else:
245 mt_phone_setup_func_argv = (log, ad_mt, 'general')
246 is_mt_in_call = is_phone_in_call_on_rat(
247 log, ad_mt, 'general', only_return_fn=True)
248
Markus Liue3143912021-03-31 10:49:00 +0800249 tasks = [(phone_setup_on_rat, mo_phone_setup_func_argv),
250 (phone_setup_on_rat, mt_phone_setup_func_argv)]
251 if not multithread_func(log, tasks):
252 log.error("Phone Failed to Set Up Properly.")
253 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
254 raise signals.TestFailure("Failed",
255 extras={"fail_reason": "Phone Failed to Set Up Properly."})
256
257 log.info("Step 4: Make voice call.")
258 result = two_phone_call_msim_for_slot(
259 log,
260 ad_mo,
Markus Liu6dc6e4e2021-11-29 20:22:28 +0800261 get_slot_index_from_subid(ad_mo, mo_sub_id),
Markus Liue3143912021-03-31 10:49:00 +0800262 None,
263 is_mo_in_call,
264 ad_mt,
Markus Liu6dc6e4e2021-11-29 20:22:28 +0800265 get_slot_index_from_subid(ad_mt, mt_sub_id),
Markus Liue3143912021-03-31 10:49:00 +0800266 None,
267 is_mt_in_call)
268
269 tel_logger.set_result(result.result_value)
270
271 if not result:
272 log.error(
273 "Failed to make MO call from %s slot %s to %s slot %s",
274 ad_mo.serial, mo_slot, ad_mt.serial, mt_slot)
275 raise signals.TestFailure("Failed",
Markus Liu481eccd2021-04-21 14:36:15 +0800276 extras={"fail_reason": str(result.result_value)})
277
Markus Liu528ac982021-07-19 01:30:37 +0800278 log.info("Step 5: Verify RAT and HTTP connection.")
279 if call_direction == "mo":
280 rat_list = [mo_rat[mo_slot], mo_rat[1-mo_slot]]
281 sub_id_list = [mo_sub_id, mo_other_sub_id]
282 else:
283 rat_list = [mt_rat[mt_slot], mt_rat[1-mt_slot]]
284 sub_id_list = [mt_sub_id, mt_other_sub_id]
285
286 # For the tese cases related to WFC in which airplane mode will be turned
287 # off in the end.
288 if turn_off_airplane_mode_in_the_end:
289 log.info("Step 5-1: Turning off airplane mode......")
290 if not toggle_airplane_mode(log, ads[0], False):
291 ads[0].log.error('Failed to toggle off airplane mode.')
292
293 # For the tese cases related to WFC in which Wi-Fi will be turned off in the
294 # end.
295 if turn_off_wifi_in_the_end:
296 log.info("Step 5-2: Turning off Wi-Fi......")
297 if not wifi_toggle_state(log, ads[0], False):
298 ads[0].log.error('Failed to toggle off Wi-Fi.')
299 return False
300
301 for index, value in enumerate(rat_list):
302 if value == '5g_wfc':
303 rat_list[index] = '5g'
304 elif value == 'wfc':
305 rat_list[index] = '4g'
306
307 for rat, sub_id in zip(rat_list, sub_id_list):
308 if not wait_for_network_idle(log, ads[0], rat, sub_id):
309 raise signals.TestFailure(
310 "Failed",
311 extras={
312 "fail_reason": "Idle state of sub ID %s does not match the "
313 "given RAT %s." % (sub_id, rat)})
314
Richard Chang2243e0e2021-08-03 01:15:05 +0800315
Markus Liufdef3062021-06-27 15:08:29 +0800316def dsds_message_test(
317 log,
318 ads,
319 mo_slot,
320 mt_slot,
321 dds_slot,
322 msg="SMS",
323 mo_rat=["", ""],
324 mt_rat=["", ""],
325 direction="mo",
Richard Chang8d40b882021-06-28 23:58:51 +0800326 streaming=False,
Markus Liufdef3062021-06-27 15:08:29 +0800327 expected_result=True):
328 """Make MO/MT SMS/MMS at specific slot in specific RAT with DDS at
329 specific slot.
330
331 Test step:
332 1. Get sub IDs of specific slots of both MO and MT devices.
333 2. Switch DDS to specific slot.
334 3. Check HTTP connection after DDS switch.
335 4. Set up phones in desired RAT.
336 5. Send SMS/MMS.
337
338 Args:
339 mo_slot: Slot sending MO SMS (0 or 1)
340 mt_slot: Slot receiving MT SMS (0 or 1)
341 dds_slot: Preferred data slot
342 mo_rat: RAT for both slots of MO device
343 mt_rat: RAT for both slots of MT device
344 direction: "mo" or "mt"
Richard Chang8d40b882021-06-28 23:58:51 +0800345 streaming: True for playing Youtube before send/receive SMS/MMS and
346 False on the contrary.
347 expected_result: True or False
Markus Liufdef3062021-06-27 15:08:29 +0800348
349 Returns:
350 TestFailure if failed.
351 """
352 if direction == "mo":
353 ad_mo = ads[0]
354 ad_mt = ads[1]
355 else:
356 ad_mo = ads[1]
357 ad_mt = ads[0]
358
359 if mo_slot is not None:
360 mo_sub_id = get_subid_from_slot_index(log, ad_mo, mo_slot)
361 if mo_sub_id == INVALID_SUB_ID:
362 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
363 return False
364 mo_other_sub_id = get_subid_from_slot_index(
365 log, ad_mo, 1-mo_slot)
366 set_message_subid(ad_mo, mo_sub_id)
367 else:
368 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
369 ads, type="sms")
370 if mo_sub_id == INVALID_SUB_ID:
371 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
372 return False
373 mo_slot = "auto"
374 set_message_subid(ad_mo, mo_sub_id)
375 if msg == "MMS":
376 set_subid_for_data(ad_mo, mo_sub_id)
377 ad_mo.droid.telephonyToggleDataConnection(True)
378 ad_mo.log.info("Sub ID for outgoing %s at slot %s: %s", msg, mo_slot,
379 get_outgoing_message_sub_id(ad_mo))
380
381 if mt_slot is not None:
382 mt_sub_id = get_subid_from_slot_index(log, ad_mt, mt_slot)
383 if mt_sub_id == INVALID_SUB_ID:
384 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
385 return False
386 mt_other_sub_id = get_subid_from_slot_index(log, ad_mt, 1-mt_slot)
387 set_message_subid(ad_mt, mt_sub_id)
388 else:
389 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
390 ads, type="sms")
391 if mt_sub_id == INVALID_SUB_ID:
392 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
393 return False
394 mt_slot = "auto"
395 set_message_subid(ad_mt, mt_sub_id)
396 if msg == "MMS":
397 set_subid_for_data(ad_mt, mt_sub_id)
398 ad_mt.droid.telephonyToggleDataConnection(True)
399 ad_mt.log.info("Sub ID for incoming %s at slot %s: %s", msg, mt_slot,
400 get_outgoing_message_sub_id(ad_mt))
401
402 log.info("Step 1: Switch DDS.")
403 if not set_dds_on_slot(ads[0], dds_slot):
404 log.error(
405 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
406 return False
407
408 log.info("Step 2: Check HTTP connection after DDS switch.")
409 if not verify_http_connection(log, ads[0]):
410 log.error("Failed to verify http connection.")
411 return False
412 else:
413 log.info("Verify http connection successfully.")
414
415 if mo_slot == 0 or mo_slot == 1:
416 phone_setup_on_rat(log, ad_mo, mo_rat[1-mo_slot], mo_other_sub_id)
417 mo_phone_setup_func_argv = (log, ad_mo, mo_rat[mo_slot], mo_sub_id)
418 else:
419 mo_phone_setup_func_argv = (log, ad_mo, 'general', mo_sub_id)
420
421 if mt_slot == 0 or mt_slot == 1:
422 phone_setup_on_rat(log, ad_mt, mt_rat[1-mt_slot], mt_other_sub_id)
423 mt_phone_setup_func_argv = (log, ad_mt, mt_rat[mt_slot], mt_sub_id)
424 else:
425 mt_phone_setup_func_argv = (log, ad_mt, 'general', mt_sub_id)
426
427 log.info("Step 3: Set up phones in desired RAT.")
428 tasks = [(phone_setup_on_rat, mo_phone_setup_func_argv),
429 (phone_setup_on_rat, mt_phone_setup_func_argv)]
430 if not multithread_func(log, tasks):
431 log.error("Phone Failed to Set Up Properly.")
432 return False
Markus Liufdef3062021-06-27 15:08:29 +0800433 time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
Markus Liufdef3062021-06-27 15:08:29 +0800434
Richard Chang8d40b882021-06-28 23:58:51 +0800435 if streaming:
436 log.info("Step 4: Start Youtube streaming.")
437 if not start_youtube_video(ads[0]):
438 log.warning("Fail to bring up youtube video")
439 time.sleep(10)
440 else:
441 log.info("Step 4: Skip Youtube streaming.")
442
443 log.info("Step 5: Send %s.", msg)
Markus Liufdef3062021-06-27 15:08:29 +0800444 if msg == "MMS":
445 for ad, current_data_sub_id, current_msg_sub_id in [
446 [ ads[0],
447 get_default_data_sub_id(ads[0]),
448 get_outgoing_message_sub_id(ads[0]) ],
449 [ ads[1],
450 get_default_data_sub_id(ads[1]),
451 get_outgoing_message_sub_id(ads[1]) ]]:
452 if current_data_sub_id != current_msg_sub_id:
453 ad.log.warning(
454 "Current data sub ID (%s) does not match message"
455 " sub ID (%s). MMS should NOT be sent.",
456 current_data_sub_id,
457 current_msg_sub_id)
458 expected_result = False
459
460 result = msim_message_test(log, ad_mo, ad_mt, mo_sub_id, mt_sub_id,
461 msg=msg, expected_result=expected_result)
462
463 if not result:
464 log_messaging_screen_shot(ad_mo, test_name="%s_tx" % msg)
465 log_messaging_screen_shot(ad_mt, test_name="%s_rx" % msg)
466
Richard Chang8d40b882021-06-28 23:58:51 +0800467 if streaming:
468 ads[0].force_stop_apk(YOUTUBE_PACKAGE_NAME)
Markus Liufdef3062021-06-27 15:08:29 +0800469 return result
470
Richard Chang2243e0e2021-08-03 01:15:05 +0800471
472def dds_switch_during_data_transfer_test(
473 log,
Markus Liu86d06832021-10-13 17:31:02 +0800474 tel_logger,
Richard Chang2243e0e2021-08-03 01:15:05 +0800475 ads,
476 nw_rat=["volte", "volte"],
477 call_slot=0,
478 call_direction=None,
479 call_or_sms_or_mms="call",
480 streaming=True,
481 is_airplane_mode=False,
482 wfc_mode=[WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_CELLULAR_PREFERRED],
483 wifi_network_ssid=None,
484 wifi_network_pass=None):
485 """Switch DDS and make voice call(VoLTE/WFC/CS call)/SMS/MMS together with
486 Youtube playing after each DDS switch at specific slot in specific RAT.
487
488 Test step:
489 1. Get sub ID of each slot of the primary device.
490 2. Set up phones in desired RAT.
491 3. Switch DDS to slot 0.
492 4. Check HTTP connection after DDS switch.
493 5. Play Youtube.
494 6. Make voice call (VoLTE/WFC/CS call)/SMS/MMS
495 7. Switch DDS to slot 1 and repeat step 4-6.
496 8. Switch DDS to slot 0 again and repeat step 4-6.
497
498 Args:
499 log: logger object
Markus Liu86d06832021-10-13 17:31:02 +0800500 tel_logger: logger object for telephony proto
Richard Chang2243e0e2021-08-03 01:15:05 +0800501 ads: list of android devices
502 nw_rat: RAT for both slots of the primary device
503 call_slot: Slot for making voice call
504 call_direction: "mo" or "mt" or None to stoping making call.
505 call_or_sms_or_mms: Voice call or SMS or MMS
506 streaming: True for playing Youtube after DDS switch and False on the contrary.
507 is_airplane_mode: True or False for WFC setup
508 wfc_mode: Cellular preferred or Wi-Fi preferred.
509 wifi_network_ssid: SSID of Wi-Fi AP
510 wifi_network_pass: Password of Wi-Fi AP SSID
511
512 Returns:
513 TestFailure if failed.
514 """
515 ad = ads[0]
516 slot_0_subid = get_subid_from_slot_index(log, ad, 0)
517 slot_1_subid = get_subid_from_slot_index(log, ad, 1)
518
519 if slot_0_subid == INVALID_SUB_ID or slot_1_subid == INVALID_SUB_ID:
520 ad.log.error("Not all slots have valid sub ID.")
521 raise signals.TestFailure("Failed",
522 extras={"fail_reason": "Not all slots have valid sub ID"})
523
524 ad.log.info(
525 "Step 0: Set up phone in desired RAT (slot 0: %s, slot 1: %s)",
526 nw_rat[0], nw_rat[1])
527
528 if not phone_setup_on_rat(
529 log,
530 ad,
531 nw_rat[0],
532 slot_0_subid,
533 is_airplane_mode,
534 wfc_mode[0],
535 wifi_network_ssid,
536 wifi_network_pass):
537 log.error("Phone Failed to Set Up Properly.")
538 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
539 raise signals.TestFailure("Failed",
540 extras={"fail_reason": "Phone Failed to Set Up Properly."})
541
542 if not phone_setup_on_rat(
543 log,
544 ad,
545 nw_rat[1],
546 slot_1_subid,
547 is_airplane_mode,
548 wfc_mode[1],
549 wifi_network_ssid,
550 wifi_network_pass):
551 log.error("Phone Failed to Set Up Properly.")
552 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
553 raise signals.TestFailure("Failed",
554 extras={"fail_reason": "Phone Failed to Set Up Properly."})
555
556 is_slot0_in_call = is_phone_in_call_on_rat(
557 log, ad, nw_rat[0], True)
558 is_slot1_in_call = is_phone_in_call_on_rat(
559 log, ad, nw_rat[1], True)
560
561 for attempt in range(3):
562 if attempt != 0:
563 ad.log.info("Repeat step 1 to 4.")
564
565 ad.log.info("Step 1: Switch DDS.")
566 if attempt % 2 == 0:
567 set_dds_on_slot(ad, 0)
568 else:
569 set_dds_on_slot(ad, 1)
570
571 ad.log.info("Step 2: Check HTTP connection after DDS switch.")
572 if not verify_http_connection(log, ad):
573 ad.log.error("Failed to verify http connection.")
574 return False
575 else:
576 ad.log.info("Verify http connection successfully.")
577
578 if streaming:
579 ad.log.info("Step 3: Start Youtube streaming.")
580 if not start_youtube_video(ad):
581 ad.log.warning("Fail to bring up youtube video")
582 time.sleep(10)
583 else:
584 ad.log.info("Step 3: Skip Youtube streaming.")
585
586 if not call_direction:
587 return True
588 else:
589 expected_result = True
590 if call_direction == "mo":
591 ad_mo = ads[0]
592 ad_mt = ads[1]
593 phone_setup_on_rat(log, ad_mt, 'general')
594 mo_sub_id = get_subid_from_slot_index(log, ad, call_slot)
595 if call_or_sms_or_mms == "call":
596 set_voice_sub_id(ad_mo, mo_sub_id)
597 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
598 ads)
599
600 if call_slot == 0:
601 is_mo_in_call = is_slot0_in_call
602 elif call_slot == 1:
603 is_mo_in_call = is_slot1_in_call
604 is_mt_in_call = None
605
606 elif call_or_sms_or_mms == "sms":
607 set_message_subid(ad_mo, mo_sub_id)
608 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
609 ads, type="sms")
610 set_message_subid(ad_mt, mt_sub_id)
611
612 elif call_or_sms_or_mms == "mms":
613 current_data_sub_id = get_default_data_sub_id(ad_mo)
614 if mo_sub_id != current_data_sub_id:
615 ad_mo.log.warning(
616 "Current data sub ID (%s) does not match"
617 " message sub ID (%s). MMS should NOT be sent.",
618 current_data_sub_id, mo_sub_id)
619 expected_result = False
620 set_message_subid(ad_mo, mo_sub_id)
621 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
622 ads, type="sms")
623 set_message_subid(ad_mt, mt_sub_id)
624 set_subid_for_data(ad_mt, mt_sub_id)
625 ad_mt.droid.telephonyToggleDataConnection(True)
626
627 elif call_direction == "mt":
628 ad_mo = ads[1]
629 ad_mt = ads[0]
630 phone_setup_on_rat(log, ad_mo, 'general')
631 mt_sub_id = get_subid_from_slot_index(log, ad, call_slot)
632 if call_or_sms_or_mms == "call":
633 set_voice_sub_id(ad_mt, mt_sub_id)
634 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
635 ads)
636
637 if call_slot == 0:
638 is_mt_in_call = is_slot0_in_call
639 elif call_slot == 1:
640 is_mt_in_call = is_slot1_in_call
641 is_mo_in_call = None
642
643 elif call_or_sms_or_mms == "sms":
644 set_message_subid(ad_mt, mt_sub_id)
645 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
646 ads, type="sms")
647 set_message_subid(ad_mo, mo_sub_id)
648
649 elif call_or_sms_or_mms == "mms":
650 current_data_sub_id = get_default_data_sub_id(ad_mt)
651 if mt_sub_id != current_data_sub_id:
652 ad_mt.log.warning(
653 "Current data sub ID (%s) does not match"
654 " message sub ID (%s). MMS should NOT be"
655 " received.", current_data_sub_id, mt_sub_id)
656 expected_result = False
657 set_message_subid(ad_mt, mt_sub_id)
658 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
659 ads, type="sms")
660 set_message_subid(ad_mo, mo_sub_id)
661 set_subid_for_data(ad_mo, mo_sub_id)
662 ad_mo.droid.telephonyToggleDataConnection(True)
663
664 if call_or_sms_or_mms == "call":
665 log.info("Step 4: Make voice call.")
Markus Liu6dc6e4e2021-11-29 20:22:28 +0800666 mo_slot = get_slot_index_from_subid(ad_mo, mo_sub_id)
667 mt_slot = get_slot_index_from_subid(ad_mt, mt_sub_id)
Richard Chang2243e0e2021-08-03 01:15:05 +0800668 result = two_phone_call_msim_for_slot(
669 log,
670 ad_mo,
671 mo_slot,
672 None,
673 is_mo_in_call,
674 ad_mt,
675 mt_slot,
676 None,
677 is_mt_in_call)
678 tel_logger.set_result(result.result_value)
679
680 if not result:
681 log.error(
682 "Failed to make MO call from %s slot %s to %s"
683 " slot %s", ad_mo.serial, mo_slot, ad_mt.serial,
684 mt_slot)
685 raise signals.TestFailure("Failed",
686 extras={"fail_reason": str(result.result_value)})
687 else:
688 log.info("Step 4: Send %s.", call_or_sms_or_mms)
689 if call_or_sms_or_mms == "sms":
690 result = msim_message_test(
691 ad_mo,
692 ad_mt,
693 mo_sub_id,
694 mt_sub_id,
695 msg=call_or_sms_or_mms.upper())
696 elif call_or_sms_or_mms == "mms":
697 result = msim_message_test(
698 ad_mo,
699 ad_mt,
700 mo_sub_id,
701 mt_sub_id,
702 msg=call_or_sms_or_mms.upper(),
703 expected_result=expected_result)
704 if not result:
705 log_messaging_screen_shot(
706 ad_mo, test_name="%s_tx" % call_or_sms_or_mms)
707 log_messaging_screen_shot(
708 ad_mt, test_name="%s_rx" % call_or_sms_or_mms)
709 return False
710 if streaming:
711 ad.force_stop_apk(YOUTUBE_PACKAGE_NAME)
712 return True
713
714
Markus Liuccd95342021-07-05 01:55:05 +0800715def enable_slot_after_voice_call_test(
716 log,
Markus Liu86d06832021-10-13 17:31:02 +0800717 tel_logger,
Markus Liuccd95342021-07-05 01:55:05 +0800718 ads,
719 mo_slot,
720 mt_slot,
721 disabled_slot,
722 mo_rat=["", ""],
723 mt_rat=["", ""],
724 call_direction="mo"):
725 """Disable/enable pSIM or eSIM with voice call
726
727 Test step:
728 1. Get sub IDs of specific slots of both MO and MT devices.
729 2. Set up phones in desired RAT.
730 3. Disable assigned slot.
731 4. Switch DDS to the other slot.
732 5. Verify RAT and HTTP connection after DDS switch.
733 6. Make voice call.
734 7. Enable assigned slot.
735 8. Switch DDS to the assigned slot.
736 9. Verify RAT and HTTP connection after DDS switch.
737
738 Args:
739 log: logger object
Markus Liu86d06832021-10-13 17:31:02 +0800740 tel_logger: logger object for telephony proto
Markus Liuccd95342021-07-05 01:55:05 +0800741 ads: list of android devices
742 mo_slot: Slot making MO call (0 or 1)
743 mt_slot: Slot receiving MT call (0 or 1)
744 disabled_slot: slot to be disabled/enabled
745 mo_rat: RAT for both slots of MO device
746 mt_rat: RAT for both slots of MT device
747 call_direction: "mo" or "mt"
748
749 Returns:
750 TestFailure if failed.
751 """
752 if call_direction == "mo":
753 ad_mo = ads[0]
754 ad_mt = ads[1]
755 else:
756 ad_mo = ads[1]
757 ad_mt = ads[0]
758
759 if mo_slot is not None:
760 mo_sub_id = get_subid_from_slot_index(log, ad_mo, mo_slot)
761 if mo_sub_id == INVALID_SUB_ID:
762 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
763 raise signals.TestFailure(
764 "Failed",
765 extras={
766 "fail_reason": "Failed to get sub ID at slot %s." % mo_slot})
767 mo_other_sub_id = get_subid_from_slot_index(
768 log, ad_mo, 1-mo_slot)
769 set_voice_sub_id(ad_mo, mo_sub_id)
770 else:
771 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
772 if mo_sub_id == INVALID_SUB_ID:
773 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
774 raise signals.TestFailure(
775 "Failed",
776 extras={
777 "fail_reason": "Failed to get sub ID at slot %s." % mo_slot})
778 mo_slot = "auto"
779 set_voice_sub_id(ad_mo, mo_sub_id)
780 ad_mo.log.info("Sub ID for outgoing call at slot %s: %s",
781 mo_slot, get_outgoing_voice_sub_id(ad_mo))
782
783 if mt_slot is not None:
784 mt_sub_id = get_subid_from_slot_index(log, ad_mt, mt_slot)
785 if mt_sub_id == INVALID_SUB_ID:
786 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
787 raise signals.TestFailure(
788 "Failed",
789 extras={
790 "fail_reason": "Failed to get sub ID at slot %s." % mt_slot})
791 mt_other_sub_id = get_subid_from_slot_index(
792 log, ad_mt, 1-mt_slot)
793 set_voice_sub_id(ad_mt, mt_sub_id)
794 else:
795 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
796 if mt_sub_id == INVALID_SUB_ID:
797 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
798 raise signals.TestFailure(
799 "Failed",
800 extras={
801 "fail_reason": "Failed to get sub ID at slot %s." % mt_slot})
802 mt_slot = "auto"
803 set_voice_sub_id(ad_mt, mt_sub_id)
804 ad_mt.log.info("Sub ID for incoming call at slot %s: %s", mt_slot,
805 get_incoming_voice_sub_id(ad_mt))
806
807 if mo_slot == 0 or mo_slot == 1:
808 phone_setup_on_rat(log, ad_mo, mo_rat[1-mo_slot], mo_other_sub_id)
809 mo_phone_setup_func_argv = (log, ad_mo, mo_rat[mo_slot], mo_sub_id)
810 is_mo_in_call = is_phone_in_call_on_rat(
811 log, ad_mo, mo_rat[mo_slot], only_return_fn=True)
812 else:
813 mo_phone_setup_func_argv = (log, ad_mo, 'general')
814 is_mo_in_call = is_phone_in_call_on_rat(
815 log, ad_mo, 'general', only_return_fn=True)
816
817 if mt_slot == 0 or mt_slot == 1:
818 phone_setup_on_rat(log, ad_mt, mt_rat[1-mt_slot], mt_other_sub_id)
819 mt_phone_setup_func_argv = (log, ad_mt, mt_rat[mt_slot], mt_sub_id)
820 is_mt_in_call = is_phone_in_call_on_rat(
821 log, ad_mt, mt_rat[mt_slot], only_return_fn=True)
822 else:
823 mt_phone_setup_func_argv = (log, ad_mt, 'general')
824 is_mt_in_call = is_phone_in_call_on_rat(
825 log, ad_mt, 'general', only_return_fn=True)
826
827 log.info("Step 1: Set up phones in desired RAT.")
828 tasks = [(phone_setup_on_rat, mo_phone_setup_func_argv),
829 (phone_setup_on_rat, mt_phone_setup_func_argv)]
830 if not multithread_func(log, tasks):
831 log.error("Phone Failed to Set Up Properly.")
832 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
833 raise signals.TestFailure(
834 "Failed",
835 extras={"fail_reason": "Phone Failed to Set Up Properly."})
836
837 log.info("Step 2: Disable slot %s.", disabled_slot)
838 if not power_off_sim(ads[0], disabled_slot):
839 raise signals.TestFailure(
840 "Failed",
841 extras={
842 "fail_reason": "Failed to disable slot %s." % disabled_slot})
843
844 log.info("Step 3: Switch DDS.")
845 if not set_dds_on_slot(ads[0], 1-disabled_slot):
846 log.error(
847 "Failed to set DDS at slot %s on %s.",
848 (1-disabled_slot, ads[0].serial))
849 raise signals.TestFailure(
850 "Failed",
851 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
852 1-disabled_slot, ads[0].serial)})
853
854 log.info("Step 4: Verify RAT and HTTP connection after DDS switch.")
855 if mo_slot == 0 or mo_slot == 1:
856 if not wait_for_network_idle(
857 log, ad_mo, mo_rat[1-disabled_slot], mo_sub_id):
858 raise signals.TestFailure(
859 "Failed",
860 extras={
861 "fail_reason": "Idle state does not match the given "
862 "RAT %s." % mo_rat[1-disabled_slot]})
863
864 if mt_slot == 0 or mt_slot == 1:
865 if not wait_for_network_idle(
866 log, ad_mt, mt_rat[1-disabled_slot], mt_sub_id):
867 raise signals.TestFailure(
868 "Failed",
869 extras={
870 "fail_reason": "Idle state does not match the given "
871 "RAT %s." % mt_rat[1-disabled_slot]})
872
873 if not verify_http_connection(log, ads[0]):
874 log.error("Failed to verify http connection.")
875 raise signals.TestFailure(
876 "Failed",
877 extras={"fail_reason": "Failed to verify http connection."})
878 else:
879 log.info("Verify http connection successfully.")
880
881 log.info("Step 5: Make voice call.")
882 result = two_phone_call_msim_for_slot(
883 log,
884 ad_mo,
Markus Liu6dc6e4e2021-11-29 20:22:28 +0800885 get_slot_index_from_subid(ad_mo, mo_sub_id),
Markus Liuccd95342021-07-05 01:55:05 +0800886 None,
887 is_mo_in_call,
888 ad_mt,
Markus Liu6dc6e4e2021-11-29 20:22:28 +0800889 get_slot_index_from_subid(ad_mt, mt_sub_id),
Markus Liuccd95342021-07-05 01:55:05 +0800890 None,
891 is_mt_in_call)
892
893 tel_logger.set_result(result.result_value)
894
895 if not result:
896 log.error(
897 "Failed to make MO call from %s slot %s to %s slot %s",
898 ad_mo.serial, mo_slot, ad_mt.serial, mt_slot)
899 raise signals.TestFailure("Failed",
900 extras={"fail_reason": str(result.result_value)})
901
902 log.info("Step 6: Enable slot %s.", disabled_slot)
903 if not power_on_sim(ads[0], disabled_slot):
904 raise signals.TestFailure(
905 "Failed",
906 extras={"fail_reason": "Failed to enable slot %s." % disabled_slot})
907
908 log.info("Step 7: Switch DDS to slot %s.", disabled_slot)
909 if not set_dds_on_slot(ads[0], disabled_slot):
910 log.error(
911 "Failed to set DDS at slot %s on %s.",(disabled_slot, ads[0].serial))
912 raise signals.TestFailure(
913 "Failed",
914 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
915 disabled_slot, ads[0].serial)})
916
917 log.info("Step 8: Verify RAT and HTTP connection after DDS switch.")
918 if mo_slot == 0 or mo_slot == 1:
919 if not wait_for_network_idle(
920 log, ad_mo, mo_rat[disabled_slot], mo_other_sub_id):
921 raise signals.TestFailure(
922 "Failed",
923 extras={
924 "fail_reason": "Idle state does not match the given "
925 "RAT %s." % mo_rat[mo_slot]})
926
927 if mt_slot == 0 or mt_slot == 1:
928 if not wait_for_network_idle(
929 log, ad_mt, mt_rat[disabled_slot], mt_other_sub_id):
930 raise signals.TestFailure(
931 "Failed",
932 extras={"fail_reason": "Idle state does not match the given "
933 "RAT %s." % mt_rat[mt_slot]})
934
935 if not verify_http_connection(log, ads[0]):
936 log.error("Failed to verify http connection.")
937 raise signals.TestFailure(
938 "Failed",
939 extras={"fail_reason": "Failed to verify http connection."})
940 else:
941 log.info("Verify http connection successfully.")
942
Richard Chang2243e0e2021-08-03 01:15:05 +0800943
Markus Liuccd95342021-07-05 01:55:05 +0800944def enable_slot_after_data_call_test(
945 log,
946 ad,
947 disabled_slot,
948 rat=["", ""]):
949 """Disable/enable pSIM or eSIM with data call
950
951 Test step:
952 1. Get sub IDs of specific slots of both MO and MT devices.
953 2. Set up phones in desired RAT.
954 3. Disable assigned slot.
955 4. Switch DDS to the other slot.
956 5. Verify RAT and HTTP connection after DDS switch.
957 6. Make a data call by http download.
958 7. Enable assigned slot.
959 8. Switch DDS to the assigned slot.
960 9. Verify RAT and HTTP connection after DDS switch.
961
962 Args:
963 log: logger object
964 ads: list of android devices
965 disabled_slot: slot to be disabled/enabled
966 mo_rat: RAT for both slots of MO device
967 mt_rat: RAT for both slots of MT device
968
969 Returns:
970 TestFailure if failed.
971 """
972 data_sub_id = get_subid_from_slot_index(log, ad, 1-disabled_slot)
973 if data_sub_id == INVALID_SUB_ID:
974 ad.log.warning("Failed to get sub ID at slot %s.", 1-disabled_slot)
975 raise signals.TestFailure(
976 "Failed",
977 extras={
978 "fail_reason": "Failed to get sub ID at slot %s." % (
979 1-disabled_slot)})
980 other_sub_id = get_subid_from_slot_index(log, ad, disabled_slot)
981
982 log.info("Step 1: Set up phones in desired RAT.")
983 if not phone_setup_on_rat(log, ad, rat[1-disabled_slot], data_sub_id):
984 raise signals.TestFailure(
985 "Failed",
986 extras={"fail_reason": "Phone Failed to Set Up Properly."})
987
988 if not phone_setup_on_rat(log, ad, rat[disabled_slot], other_sub_id):
989 raise signals.TestFailure(
990 "Failed",
991 extras={"fail_reason": "Phone Failed to Set Up Properly."})
992
993 log.info("Step 2: Disable slot %s.", disabled_slot)
994 if not power_off_sim(ad, disabled_slot):
995 raise signals.TestFailure(
996 "Failed",
997 extras={"fail_reason": "Failed to disable slot %s." % disabled_slot})
998
999 log.info("Step 3: Switch DDS.")
1000 if not set_dds_on_slot(ad, 1-disabled_slot):
1001 log.error(
1002 "Failed to set DDS at slot %s on %s.",(1-disabled_slot, ad.serial))
1003 raise signals.TestFailure(
1004 "Failed",
1005 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
1006 1-disabled_slot, ad.serial)})
1007
1008 log.info("Step 4: Verify RAT and HTTP connection after DDS switch.")
1009 if not wait_for_network_idle(log, ad, rat[1-disabled_slot], data_sub_id):
1010 raise signals.TestFailure(
1011 "Failed",
1012 extras={
1013 "fail_reason": "Idle state does not match the given "
1014 "RAT %s." % rat[1-disabled_slot]})
1015
1016 if not verify_http_connection(log, ad):
1017 log.error("Failed to verify http connection.")
1018 raise signals.TestFailure("Failed",
1019 extras={"fail_reason": "Failed to verify http connection."})
1020 else:
1021 log.info("Verify http connection successfully.")
1022
1023 duration = 30
1024 start_time = datetime.now()
1025 while datetime.now() - start_time <= timedelta(seconds=duration):
1026 if not active_file_download_test(
1027 log, ad, file_name='20MB', method='sl4a'):
1028 raise signals.TestFailure(
1029 "Failed",
1030 extras={"fail_reason": "Failed to download by sl4a."})
1031
1032 log.info("Step 6: Enable slot %s.", disabled_slot)
1033 if not power_on_sim(ad, disabled_slot):
1034 raise signals.TestFailure(
1035 "Failed",
1036 extras={"fail_reason": "Failed to enable slot %s." % disabled_slot})
1037
1038 log.info("Step 7: Switch DDS to slot %s.", disabled_slot)
1039 if not set_dds_on_slot(ad, disabled_slot):
1040 log.error(
1041 "Failed to set DDS at slot %s on %s.",(disabled_slot, ad.serial))
1042 raise signals.TestFailure(
1043 "Failed",
1044 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
1045 disabled_slot, ad.serial)})
1046
1047 log.info("Step 8: Verify RAT and HTTP connection after DDS switch.")
1048 if not wait_for_network_idle(log, ad, rat[disabled_slot], other_sub_id):
1049 raise signals.TestFailure(
1050 "Failed",
1051 extras={
1052 "fail_reason": "Idle state does not match the given "
1053 "RAT %s." % rat[disabled_slot]})
1054
1055 if not verify_http_connection(log, ad):
1056 log.error("Failed to verify http connection.")
1057 raise signals.TestFailure(
1058 "Failed",
1059 extras={"fail_reason": "Failed to verify http connection."})
1060 else:
1061 log.info("Verify http connection successfully.")
1062
Richard Chang2243e0e2021-08-03 01:15:05 +08001063
Markus Liu481eccd2021-04-21 14:36:15 +08001064def erase_call_forwarding(log, ad):
1065 slot0_sub_id = get_subid_from_slot_index(log, ad, 0)
1066 slot1_sub_id = get_subid_from_slot_index(log, ad, 1)
1067 current_voice_sub_id = get_incoming_voice_sub_id(ad)
1068 for sub_id in (slot0_sub_id, slot1_sub_id):
1069 set_voice_sub_id(ad, sub_id)
1070 get_operator_name(log, ad, sub_id)
1071 erase_call_forwarding_by_mmi(log, ad)
1072 set_voice_sub_id(ad, current_voice_sub_id)
1073
Richard Chang2243e0e2021-08-03 01:15:05 +08001074
Markus Liu481eccd2021-04-21 14:36:15 +08001075def three_way_calling_mo_and_mt_with_hangup_once(
1076 log,
1077 ads,
1078 phone_setups,
1079 verify_funcs,
1080 reject_once=False):
1081 """Use 3 phones to make MO call and MT call.
1082
1083 Call from PhoneA to PhoneB, accept on PhoneB.
1084 Call from PhoneC to PhoneA, accept on PhoneA.
1085
1086 Args:
1087 ads: list of ad object.
1088 The list should have three objects.
1089 phone_setups: list of phone setup functions.
1090 The list should have three objects.
1091 verify_funcs: list of phone call verify functions.
1092 The list should have three objects.
1093
1094 Returns:
1095 If success, return 'call_AB' id in PhoneA.
1096 if fail, return None.
1097 """
1098
1099 class _CallException(Exception):
1100 pass
1101
1102 try:
1103 verify_func_a, verify_func_b, verify_func_c = verify_funcs
1104 tasks = []
1105 for ad, setup_func in zip(ads, phone_setups):
1106 if setup_func is not None:
1107 tasks.append((setup_func, (log, ad, get_incoming_voice_sub_id(ad))))
1108 if tasks != [] and not multithread_func(log, tasks):
1109 log.error("Phone Failed to Set Up Properly.")
1110 raise _CallException("Setup failed.")
1111 for ad in ads:
1112 ad.droid.telecomCallClearCallList()
1113 if num_active_calls(log, ad) != 0:
1114 ad.log.error("Phone Call List is not empty.")
1115 raise _CallException("Clear call list failed.")
1116
1117 log.info("Step1: Call From PhoneA to PhoneB.")
1118 if not call_setup_teardown(
1119 log,
1120 ads[0],
1121 ads[1],
1122 ad_hangup=None,
1123 verify_caller_func=verify_func_a,
1124 verify_callee_func=verify_func_b):
1125 raise _CallException("PhoneA call PhoneB failed.")
1126
1127 calls = ads[0].droid.telecomCallGetCallIds()
1128 ads[0].log.info("Calls in PhoneA %s", calls)
1129 if num_active_calls(log, ads[0]) != 1:
1130 raise _CallException("Call list verify failed.")
1131 call_ab_id = calls[0]
1132
1133 log.info("Step2: Call From PhoneC to PhoneA.")
1134 if reject_once:
1135 log.info("Step2-1: Reject incoming call once.")
1136 if not initiate_call(
1137 log,
1138 ads[2],
1139 ads[0].telephony['subscription'][get_incoming_voice_sub_id(
1140 ads[0])]['phone_num']):
1141 ads[2].log.error("Initiate call failed.")
1142 raise _CallException("Failed to initiate call.")
1143
1144 if not wait_and_reject_call_for_subscription(
1145 log,
1146 ads[0],
1147 get_incoming_voice_sub_id(ads[0]),
1148 incoming_number= \
1149 ads[2].telephony['subscription'][
1150 get_incoming_voice_sub_id(
1151 ads[2])]['phone_num']):
1152 ads[0].log.error("Reject call fail.")
1153 raise _CallException("Failed to reject call.")
1154
1155 hangup_call(log, ads[2])
1156 time.sleep(15)
1157
1158 if not call_setup_teardown(
1159 log,
1160 ads[2],
1161 ads[0],
1162 ad_hangup=None,
1163 verify_caller_func=verify_func_c,
1164 verify_callee_func=verify_func_a):
1165 raise _CallException("PhoneA call PhoneC failed.")
1166 if not verify_incall_state(log, [ads[0], ads[1], ads[2]],
1167 True):
1168 raise _CallException("Not All phones are in-call.")
1169
1170 except Exception as e:
1171 setattr(ads[0], "exception", e)
1172 return None
1173
1174 return call_ab_id
1175
Richard Chang2243e0e2021-08-03 01:15:05 +08001176
Markus Liufdef3062021-06-27 15:08:29 +08001177def msim_message_test(
1178 log,
1179 ad_mo,
1180 ad_mt,
1181 mo_sub_id,
1182 mt_sub_id, msg="SMS",
1183 max_wait_time=MAX_WAIT_TIME_SMS_RECEIVE,
1184 expected_result=True):
1185 """Make MO/MT SMS/MMS at specific slot.
1186
1187 Args:
1188 ad_mo: Android object of the device sending SMS/MMS
1189 ad_mt: Android object of the device receiving SMS/MMS
1190 mo_sub_id: Sub ID of MO device
1191 mt_sub_id: Sub ID of MT device
1192 max_wait_time: Max wait time before SMS/MMS is received.
1193 expected_result: True for successful sending/receiving and False on
1194 the contrary
1195
1196 Returns:
1197 True if the result matches expected_result and False on the
1198 contrary.
1199 """
1200 message_lengths = (50, 160, 180)
1201 if msg == "SMS":
1202 for length in message_lengths:
1203 message_array = [rand_ascii_str(length)]
1204 if not sms_send_receive_verify_for_subscription(
1205 log,
1206 ad_mo,
1207 ad_mt,
1208 mo_sub_id,
1209 mt_sub_id,
1210 message_array,
1211 max_wait_time):
1212 ad_mo.log.warning(
1213 "%s of length %s test failed", msg, length)
1214 return False
1215 else:
1216 ad_mo.log.info(
1217 "%s of length %s test succeeded", msg, length)
1218 log.info("%s test of length %s characters succeeded.",
1219 msg, message_lengths)
1220
1221 elif msg == "MMS":
1222 for length in message_lengths:
1223 message_array = [("Test Message", rand_ascii_str(length), None)]
1224
1225 if not mms_send_receive_verify(
1226 log,
1227 ad_mo,
1228 ad_mt,
1229 message_array,
1230 max_wait_time,
1231 expected_result):
1232 log.warning("%s of body length %s test failed",
1233 msg, length)
1234 return False
1235 else:
1236 log.info(
1237 "%s of body length %s test succeeded", msg, length)
1238 log.info("%s test of body lengths %s succeeded",
1239 msg, message_lengths)
1240 return True
1241
Richard Chang2243e0e2021-08-03 01:15:05 +08001242
Markus Liu481eccd2021-04-21 14:36:15 +08001243def msim_call_forwarding(
1244 log,
Markus Liu86d06832021-10-13 17:31:02 +08001245 tel_logger,
Markus Liu481eccd2021-04-21 14:36:15 +08001246 ads,
1247 caller_slot,
1248 callee_slot,
1249 forwarded_callee_slot,
1250 dds_slot,
1251 caller_rat=["", ""],
1252 callee_rat=["", ""],
1253 forwarded_callee_rat=["", ""],
1254 call_forwarding_type="unconditional"):
1255 """Make MO voice call to the primary device at specific slot in specific
1256 RAT with DDS at specific slot, and then forwarded to 3rd device with
1257 specific call forwarding type.
1258
1259 Test step:
1260 1. Get sub IDs of specific slots of both MO and MT devices.
1261 2. Switch DDS to specific slot.
1262 3. Check HTTP connection after DDS switch.
1263 4. Set up phones in desired RAT.
1264 5. Register and enable call forwarding with specifc type.
1265 5. Make voice call to the primary device and wait for being forwarded
1266 to 3rd device.
1267
1268 Args:
Markus Liu86d06832021-10-13 17:31:02 +08001269 log: logger object
1270 tel_logger: logger object for telephony proto
1271 ads: list of android devices
Markus Liu481eccd2021-04-21 14:36:15 +08001272 caller_slot: Slot of 2nd device making MO call (0 or 1)
1273 callee_slot: Slot of primary device receiving and forwarding MT call
1274 (0 or 1)
1275 forwarded_callee_slot: Slot of 3rd device receiving forwarded call.
1276 dds_slot: Preferred data slot
1277 caller_rat: RAT for both slots of the 2nd device
1278 callee_rat: RAT for both slots of the primary device
1279 forwarded_callee_rat: RAT for both slots of the 3rd device
1280 call_forwarding_type:
1281 "unconditional"
1282 "busy"
1283 "not_answered"
1284 "not_reachable"
1285
1286 Returns:
1287 True or False
1288 """
1289 ad_caller = ads[1]
1290 ad_callee = ads[0]
1291 ad_forwarded_callee = ads[2]
1292
1293 if callee_slot is not None:
1294 callee_sub_id = get_subid_from_slot_index(
1295 log, ad_callee, callee_slot)
1296 if callee_sub_id == INVALID_SUB_ID:
1297 ad_callee.log.warning(
1298 "Failed to get sub ID at slot %s.", callee_slot)
1299 return False
1300 callee_other_sub_id = get_subid_from_slot_index(
1301 log, ad_callee, 1-callee_slot)
1302 set_voice_sub_id(ad_callee, callee_sub_id)
1303 else:
1304 callee_sub_id, _, _ = get_subid_on_same_network_of_host_ad(ads)
1305 if callee_sub_id == INVALID_SUB_ID:
1306 ad_callee.log.warning(
1307 "Failed to get sub ID at slot %s.", callee_slot)
1308 return False
1309 callee_slot = "auto"
1310 set_voice_sub_id(ad_callee, callee_sub_id)
1311 ad_callee.log.info(
1312 "Sub ID for incoming call at slot %s: %s",
1313 callee_slot, get_incoming_voice_sub_id(ad_callee))
1314
1315 if caller_slot is not None:
1316 caller_sub_id = get_subid_from_slot_index(
1317 log, ad_caller, caller_slot)
1318 if caller_sub_id == INVALID_SUB_ID:
1319 ad_caller.log.warning(
1320 "Failed to get sub ID at slot %s.", caller_slot)
1321 return False
1322 caller_other_sub_id = get_subid_from_slot_index(
1323 log, ad_caller, 1-caller_slot)
1324 set_voice_sub_id(ad_caller, caller_sub_id)
1325 else:
1326 _, caller_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1327 if caller_sub_id == INVALID_SUB_ID:
1328 ad_caller.log.warning(
1329 "Failed to get sub ID at slot %s.", caller_slot)
1330 return False
1331 caller_slot = "auto"
1332 set_voice_sub_id(ad_caller, caller_sub_id)
1333 ad_caller.log.info(
1334 "Sub ID for outgoing call at slot %s: %s",
1335 caller_slot, get_outgoing_voice_sub_id(ad_caller))
1336
1337 if forwarded_callee_slot is not None:
1338 forwarded_callee_sub_id = get_subid_from_slot_index(
1339 log, ad_forwarded_callee, forwarded_callee_slot)
1340 if forwarded_callee_sub_id == INVALID_SUB_ID:
1341 ad_forwarded_callee.log.warning(
1342 "Failed to get sub ID at slot %s.", forwarded_callee_slot)
1343 return False
1344 forwarded_callee_other_sub_id = get_subid_from_slot_index(
1345 log, ad_forwarded_callee, 1-forwarded_callee_slot)
1346 set_voice_sub_id(
1347 ad_forwarded_callee, forwarded_callee_sub_id)
1348 else:
1349 _, _, forwarded_callee_sub_id = \
1350 get_subid_on_same_network_of_host_ad(ads)
1351 if forwarded_callee_sub_id == INVALID_SUB_ID:
1352 ad_forwarded_callee.log.warning(
1353 "Failed to get sub ID at slot %s.", forwarded_callee_slot)
1354 return False
1355 forwarded_callee_slot = "auto"
1356 set_voice_sub_id(
1357 ad_forwarded_callee, forwarded_callee_sub_id)
1358 ad_forwarded_callee.log.info(
1359 "Sub ID for incoming call at slot %s: %s",
1360 forwarded_callee_slot,
1361 get_incoming_voice_sub_id(ad_forwarded_callee))
1362
1363 log.info("Step 1: Switch DDS.")
Markus Liufdef3062021-06-27 15:08:29 +08001364 if not set_dds_on_slot(ads[0], dds_slot):
1365 log.error(
1366 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1367 return False
Markus Liu481eccd2021-04-21 14:36:15 +08001368
1369 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liufdef3062021-06-27 15:08:29 +08001370 if not verify_http_connection(log, ads[0]):
Markus Liu481eccd2021-04-21 14:36:15 +08001371 log.error("Failed to verify http connection.")
1372 return False
1373 else:
1374 log.info("Verify http connection successfully.")
1375
1376 if caller_slot == 1:
1377 phone_setup_on_rat(
1378 log,
1379 ad_caller,
1380 caller_rat[0],
1381 caller_other_sub_id)
1382
1383 elif caller_slot == 0:
1384 phone_setup_on_rat(
1385 log,
1386 ad_caller,
1387 caller_rat[1],
1388 caller_other_sub_id)
1389 else:
1390 phone_setup_on_rat(
1391 log,
1392 ad_caller,
1393 'general')
1394
1395 if callee_slot == 1:
1396 phone_setup_on_rat(
1397 log,
1398 ad_callee,
1399 callee_rat[0],
1400 callee_other_sub_id)
1401
1402 elif callee_slot == 0:
1403 phone_setup_on_rat(
1404 log,
1405 ad_callee,
1406 callee_rat[1],
1407 callee_other_sub_id)
1408 else:
1409 phone_setup_on_rat(
1410 log,
1411 ad_callee,
1412 'general')
1413
1414 if forwarded_callee_slot == 1:
1415 phone_setup_on_rat(
1416 log,
1417 ad_forwarded_callee,
1418 forwarded_callee_rat[0],
1419 forwarded_callee_other_sub_id)
1420
1421 elif forwarded_callee_slot == 0:
1422 phone_setup_on_rat(
1423 log,
1424 ad_forwarded_callee,
1425 forwarded_callee_rat[1],
1426 forwarded_callee_other_sub_id)
1427 else:
1428 phone_setup_on_rat(
1429 log,
1430 ad_forwarded_callee,
1431 'general')
1432
1433 if caller_slot == 0 or caller_slot == 1:
1434 caller_phone_setup_func_argv = (log, ad_caller, caller_rat[caller_slot], caller_sub_id)
1435 else:
1436 caller_phone_setup_func_argv = (log, ad_caller, 'general')
1437
1438 callee_phone_setup_func_argv = (log, ad_callee, callee_rat[callee_slot], callee_sub_id)
1439
1440 if forwarded_callee_slot == 0 or forwarded_callee_slot == 1:
1441 forwarded_callee_phone_setup_func_argv = (
1442 log,
1443 ad_forwarded_callee,
1444 forwarded_callee_rat[forwarded_callee_slot],
1445 forwarded_callee_sub_id)
1446 else:
1447 forwarded_callee_phone_setup_func_argv = (
1448 log,
1449 ad_forwarded_callee,
1450 'general')
1451
1452 log.info("Step 3: Set up phones in desired RAT.")
1453 tasks = [(phone_setup_on_rat, caller_phone_setup_func_argv),
1454 (phone_setup_on_rat, callee_phone_setup_func_argv),
1455 (phone_setup_on_rat,
1456 forwarded_callee_phone_setup_func_argv)]
1457 if not multithread_func(log, tasks):
1458 log.error("Phone Failed to Set Up Properly.")
1459 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1460 raise signals.TestFailure("Failed",
1461 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1462
1463 is_callee_in_call = is_phone_in_call_on_rat(
1464 log, ad_callee, callee_rat[callee_slot], only_return_fn=True)
1465
1466 is_call_waiting = re.search(
1467 "call_waiting (True (\d)|False)", call_forwarding_type, re.I)
1468 if is_call_waiting:
1469 if is_call_waiting.group(1) == "False":
1470 call_waiting = False
1471 scenario = None
1472 else:
1473 call_waiting = True
1474 scenario = int(is_call_waiting.group(2))
1475
1476 log.info(
1477 "Step 4: Make voice call with call waiting enabled = %s.",
1478 call_waiting)
1479 result = three_phone_call_waiting_short_seq(
1480 log,
1481 ads[0],
1482 None,
1483 is_callee_in_call,
1484 ads[1],
1485 ads[2],
1486 call_waiting=call_waiting, scenario=scenario)
1487 else:
1488 log.info(
1489 "Step 4: Make voice call with call forwarding %s.",
1490 call_forwarding_type)
1491 result = three_phone_call_forwarding_short_seq(
1492 log,
1493 ads[0],
1494 None,
1495 is_callee_in_call,
1496 ads[1],
1497 ads[2],
1498 call_forwarding_type=call_forwarding_type)
1499
1500 if not result:
1501 if is_call_waiting:
1502 pass
1503 else:
1504 log.error(
1505 "Failed to make MO call from %s slot %s to %s slot %s"
1506 " and forward to %s slot %s",
1507 ad_caller.serial,
1508 caller_slot,
1509 ad_callee.serial,
1510 callee_slot,
1511 ad_forwarded_callee.serial,
1512 forwarded_callee_slot)
1513
1514 return result
1515
Richard Chang2243e0e2021-08-03 01:15:05 +08001516
Markus Liu481eccd2021-04-21 14:36:15 +08001517def msim_call_voice_conf(
1518 log,
Markus Liu86d06832021-10-13 17:31:02 +08001519 tel_logger,
Markus Liu481eccd2021-04-21 14:36:15 +08001520 ads,
1521 host_slot,
1522 p1_slot,
1523 p2_slot,
1524 dds_slot,
1525 host_rat=["volte", "volte"],
1526 p1_rat="",
1527 p2_rat="",
1528 merge=True,
1529 disable_cw=False):
1530 """Make a voice conference call at specific slot in specific RAT with
1531 DDS at specific slot.
1532
1533 Test step:
1534 1. Get sub IDs of specific slots of both MO and MT devices.
1535 2. Switch DDS to specific slot.
1536 3. Check HTTP connection after DDS switch.
1537 4. Set up phones in desired RAT and make 3-way voice call.
1538 5. Swap calls.
1539 6. Merge calls.
1540
1541 Args:
Markus Liu86d06832021-10-13 17:31:02 +08001542 log: logger object
1543 tel_logger: logger object for telephony proto
1544 ads: list of android devices
Markus Liu481eccd2021-04-21 14:36:15 +08001545 host_slot: Slot on the primary device to host the comference call.
1546 0 or 1 (0 for pSIM or 1 for eSIM)
1547 p1_slot: Slot on the participant device for the call
1548 p2_slot: Slot on another participant device for the call
1549 dds_slot: Preferred data slot
1550 host_rat: RAT for both slots of the primary device
1551 p1_rat: RAT for both slots of the participant device
1552 p2_rat: RAT for both slots of another participant device
1553 merge: True for merging 2 calls into the conference call. False for
1554 not merging 2 separated call.
1555 disable_cw: True for disabling call waiting and False on the
1556 contrary.
1557
1558 Returns:
Markus Liu3bedf212021-06-16 17:39:07 +08001559 True or False
Markus Liu481eccd2021-04-21 14:36:15 +08001560 """
1561 ad_host = ads[0]
1562 ad_p1 = ads[1]
1563 ad_p2 = ads[2]
1564
1565 if host_slot is not None:
1566 host_sub_id = get_subid_from_slot_index(
1567 log, ad_host, host_slot)
1568 if host_sub_id == INVALID_SUB_ID:
1569 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
1570 return False
1571 host_other_sub_id = get_subid_from_slot_index(
1572 log, ad_host, 1-host_slot)
1573 set_voice_sub_id(ad_host, host_sub_id)
1574 else:
1575 host_sub_id, _, _ = get_subid_on_same_network_of_host_ad(ads)
1576 if host_sub_id == INVALID_SUB_ID:
1577 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
1578 return False
1579 host_slot = "auto"
1580 set_voice_sub_id(ad_host, host_sub_id)
1581
1582 ad_host.log.info("Sub ID for outgoing call at slot %s: %s",
1583 host_slot, get_outgoing_voice_sub_id(ad_host))
1584
1585 if p1_slot is not None:
1586 p1_sub_id = get_subid_from_slot_index(log, ad_p1, p1_slot)
1587 if p1_sub_id == INVALID_SUB_ID:
1588 ad_p1.log.warning("Failed to get sub ID at slot %s.", p1_slot)
1589 return False
1590 set_voice_sub_id(ad_p1, p1_sub_id)
1591 else:
1592 _, p1_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1593 if p1_sub_id == INVALID_SUB_ID:
1594 ad_p1.log.warning("Failed to get sub ID at slot %s.", p1_slot)
1595 return False
1596 p1_slot = "auto"
1597 set_voice_sub_id(ad_p1, p1_sub_id)
1598 ad_p1.log.info("Sub ID for incoming call at slot %s: %s",
1599 p1_slot, get_incoming_voice_sub_id(ad_p1))
1600
1601 if p2_slot is not None:
1602 p2_sub_id = get_subid_from_slot_index(log, ad_p2, p2_slot)
1603 if p2_sub_id == INVALID_SUB_ID:
1604 ad_p2.log.warning("Failed to get sub ID at slot %s.", p2_slot)
1605 return False
1606 set_voice_sub_id(ad_p2, p2_sub_id)
1607 else:
1608 _, _, p2_sub_id = get_subid_on_same_network_of_host_ad(ads)
1609 if p2_sub_id == INVALID_SUB_ID:
1610 ad_p2.log.warning("Failed to get sub ID at slot %s.", p2_slot)
1611 return False
1612 p2_slot = "auto"
1613 set_voice_sub_id(ad_p2, p2_sub_id)
1614 ad_p2.log.info("Sub ID for incoming call at slot %s: %s",
1615 p2_slot, get_incoming_voice_sub_id(ad_p2))
1616
1617 log.info("Step 1: Switch DDS.")
Markus Liufdef3062021-06-27 15:08:29 +08001618 if not set_dds_on_slot(ads[0], dds_slot):
1619 log.error(
1620 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1621 return False
Markus Liu481eccd2021-04-21 14:36:15 +08001622
1623 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liufdef3062021-06-27 15:08:29 +08001624 if not verify_http_connection(log, ads[0]):
Markus Liu481eccd2021-04-21 14:36:15 +08001625 log.error("Failed to verify http connection.")
1626 return False
1627 else:
1628 log.info("Verify http connection successfully.")
1629
1630 if disable_cw:
1631 if not set_call_waiting(log, ad_host, enable=0):
1632 return False
1633 else:
1634 if not set_call_waiting(log, ad_host, enable=1):
1635 return False
1636
1637 if host_slot == 1:
1638 phone_setup_on_rat(
1639 log,
1640 ad_host,
1641 host_rat[0],
1642 host_other_sub_id)
1643
1644 elif host_slot == 0:
1645 phone_setup_on_rat(
1646 log,
1647 ad_host,
1648 host_rat[1],
1649 host_other_sub_id)
1650
1651 if host_slot == 0 or host_slot == 1:
1652 host_phone_setup_func_argv = (log, ad_host, host_rat[host_slot], host_sub_id)
1653 is_host_in_call = is_phone_in_call_on_rat(
1654 log, ad_host, host_rat[host_slot], only_return_fn=True)
1655 else:
1656 host_phone_setup_func_argv = (log, ad_host, 'general')
1657 is_host_in_call = is_phone_in_call_on_rat(
1658 log, ad_host, 'general', only_return_fn=True)
1659
1660 if p1_rat:
1661 p1_phone_setup_func_argv = (log, ad_p1, p1_rat, p1_sub_id)
1662 is_p1_in_call = is_phone_in_call_on_rat(
1663 log, ad_p1, p1_rat, only_return_fn=True)
1664 else:
1665 p1_phone_setup_func_argv = (log, ad_p1, 'general')
1666 is_p1_in_call = is_phone_in_call_on_rat(
1667 log, ad_p1, 'general', only_return_fn=True)
1668
1669 if p2_rat:
1670 p2_phone_setup_func_argv = (log, ad_p2, p2_rat, p2_sub_id)
1671 is_p2_in_call = is_phone_in_call_on_rat(
1672 log, ad_p2, p2_rat, only_return_fn=True)
1673 else:
1674 p2_phone_setup_func_argv = (log, ad_p2, 'general')
1675 is_p2_in_call = is_phone_in_call_on_rat(
1676 log, ad_p2, 'general', only_return_fn=True)
1677
1678 log.info("Step 3: Set up phone in desired RAT and make 3-way"
1679 " voice call.")
1680
1681 tasks = [(phone_setup_on_rat, host_phone_setup_func_argv),
1682 (phone_setup_on_rat, p1_phone_setup_func_argv),
1683 (phone_setup_on_rat, p2_phone_setup_func_argv)]
1684 if not multithread_func(log, tasks):
1685 log.error("Phone Failed to Set Up Properly.")
1686 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1687 raise signals.TestFailure("Failed",
1688 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1689
1690 call_ab_id = three_way_calling_mo_and_mt_with_hangup_once(
1691 log,
1692 [ad_host, ad_p1, ad_p2],
1693 [None, None, None], [
1694 is_host_in_call, is_p1_in_call,
1695 is_p2_in_call
1696 ])
1697
1698 if call_ab_id is None:
1699 if disable_cw:
1700 set_call_waiting(log, ad_host, enable=1)
1701 if str(getattr(ad_host, "exception", None)) == \
1702 "PhoneA call PhoneC failed.":
1703 ads[0].log.info("PhoneA failed to call PhoneC due to call"
1704 " waiting being disabled.")
1705 delattr(ad_host, "exception")
1706 return True
1707 log.error("Failed to get call_ab_id")
1708 return False
1709 else:
1710 if disable_cw:
1711 return False
1712
1713 calls = ads[0].droid.telecomCallGetCallIds()
1714 ads[0].log.info("Calls in PhoneA %s", calls)
1715 if num_active_calls(log, ads[0]) != 2:
1716 return False
1717 if calls[0] == call_ab_id:
1718 call_ac_id = calls[1]
1719 else:
1720 call_ac_id = calls[0]
1721
1722 if call_ac_id is None:
1723 log.error("Failed to get call_ac_id")
1724 return False
1725
1726 num_swaps = 2
1727 log.info("Step 4: Begin Swap x%s test.", num_swaps)
1728 if not swap_calls(log, ads, call_ab_id, call_ac_id,
1729 num_swaps):
1730 log.error("Swap test failed.")
1731 return False
1732
1733 if not merge:
1734 result = True
1735 if not hangup_call(log, ads[1]):
1736 result = False
1737 if not hangup_call(log, ads[2]):
1738 result = False
1739 return result
1740 else:
1741 log.info("Step 5: Merge calls.")
1742 if host_rat[host_slot] == "volte":
1743 return _test_ims_conference_merge_drop_second_call_from_participant(
1744 log, ads, call_ab_id, call_ac_id)
1745 else:
1746 return _test_wcdma_conference_merge_drop(
Markus Liu3bedf212021-06-16 17:39:07 +08001747 log, ads, call_ab_id, call_ac_id)
1748
Richard Chang2243e0e2021-08-03 01:15:05 +08001749
Markus Liu3bedf212021-06-16 17:39:07 +08001750def msim_volte_wfc_call_forwarding(
1751 log,
Markus Liu86d06832021-10-13 17:31:02 +08001752 tel_logger,
Markus Liu3bedf212021-06-16 17:39:07 +08001753 ads,
1754 callee_slot,
1755 dds_slot,
1756 callee_rat=["5g_wfc", "5g_wfc"],
1757 call_forwarding_type="unconditional",
1758 is_airplane_mode=False,
1759 is_wifi_connected=False,
1760 wfc_mode=[
1761 WFC_MODE_CELLULAR_PREFERRED,
1762 WFC_MODE_CELLULAR_PREFERRED],
1763 wifi_network_ssid=None,
1764 wifi_network_pass=None):
1765 """Make VoLTE/WFC call to the primary device at specific slot with DDS
1766 at specific slot, and then forwarded to 3rd device with specific call
1767 forwarding type.
1768
1769 Test step:
1770 1. Get sub IDs of specific slots of both MO and MT devices.
1771 2. Switch DDS to specific slot.
1772 3. Check HTTP connection after DDS switch.
1773 4. Set up phones in desired RAT.
1774 5. Register and enable call forwarding with specifc type.
1775 6. Make VoLTE/WFC call to the primary device and wait for being
1776 forwarded to 3rd device.
1777
1778 Args:
Markus Liu86d06832021-10-13 17:31:02 +08001779 log: logger object
1780 tel_logger: logger object for telephony proto
1781 ads: list of android devices
Markus Liu3bedf212021-06-16 17:39:07 +08001782 callee_slot: Slot of primary device receiving and forwarding MT call
1783 (0 or 1)
1784 dds_slot: Preferred data slot
1785 callee_rat: RAT for both slots of the primary device
1786 call_forwarding_type:
1787 "unconditional"
1788 "busy"
1789 "not_answered"
1790 "not_reachable"
1791 is_airplane_mode: True or False for WFC setup
1792 wfc_mode: Cellular preferred or Wi-Fi preferred.
1793 wifi_network_ssid: SSID of Wi-Fi AP
1794 wifi_network_pass: Password of Wi-Fi AP SSID
1795
1796 Returns:
1797 True or False
1798 """
1799 ad_caller = ads[1]
1800 ad_callee = ads[0]
1801 ad_forwarded_callee = ads[2]
1802
1803 if not toggle_airplane_mode(log, ad_callee, False):
1804 ad_callee.log.error("Failed to disable airplane mode.")
1805 return False
1806
1807 # Set up callee (primary device)
1808 callee_sub_id = get_subid_from_slot_index(
1809 log, ad_callee, callee_slot)
1810 if callee_sub_id == INVALID_SUB_ID:
1811 log.warning(
1812 "Failed to get sub ID at slot %s.", callee_slot)
1813 return
1814 callee_other_sub_id = get_subid_from_slot_index(
1815 log, ad_callee, 1-callee_slot)
1816 set_voice_sub_id(ad_callee, callee_sub_id)
1817 ad_callee.log.info(
1818 "Sub ID for incoming call at slot %s: %s",
1819 callee_slot, get_incoming_voice_sub_id(ad_callee))
1820
1821 # Set up caller
1822 _, caller_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1823 if caller_sub_id == INVALID_SUB_ID:
1824 ad_caller.log.warning("Failed to get proper sub ID of the caller")
1825 return
1826 set_voice_sub_id(ad_caller, caller_sub_id)
1827 ad_caller.log.info(
1828 "Sub ID for outgoing call of the caller: %s",
1829 get_outgoing_voice_sub_id(ad_caller))
1830
1831 # Set up forwarded callee
1832 _, _, forwarded_callee_sub_id = get_subid_on_same_network_of_host_ad(
1833 ads)
1834 if forwarded_callee_sub_id == INVALID_SUB_ID:
1835 ad_forwarded_callee.log.warning(
1836 "Failed to get proper sub ID of the forwarded callee.")
1837 return
1838 set_voice_sub_id(ad_forwarded_callee, forwarded_callee_sub_id)
1839 ad_forwarded_callee.log.info(
1840 "Sub ID for incoming call of the forwarded callee: %s",
1841 get_incoming_voice_sub_id(ad_forwarded_callee))
1842
Markus Liufdef3062021-06-27 15:08:29 +08001843 log.info("Step 1: Switch DDS.")
1844 if not set_dds_on_slot(ads[0], dds_slot):
1845 log.error(
1846 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1847 return False
Markus Liu3bedf212021-06-16 17:39:07 +08001848
Markus Liufdef3062021-06-27 15:08:29 +08001849 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liu3bedf212021-06-16 17:39:07 +08001850 if not verify_http_connection(log, ad_callee):
1851 ad_callee.log.error("Failed to verify http connection.")
1852 return False
1853 else:
1854 ad_callee.log.info("Verify http connection successfully.")
1855
1856 is_callee_in_call = is_phone_in_call_on_rat(
1857 log, ad_callee, callee_rat[callee_slot], only_return_fn=True)
1858
1859 if is_airplane_mode:
1860 set_call_forwarding_by_mmi(log, ad_callee, ad_forwarded_callee)
1861
Markus Liufdef3062021-06-27 15:08:29 +08001862 log.info("Step 3: Set up phones in desired RAT.")
Markus Liu3bedf212021-06-16 17:39:07 +08001863 if callee_slot == 1:
1864 phone_setup_on_rat(
1865 log,
1866 ad_callee,
1867 callee_rat[0],
1868 callee_other_sub_id,
1869 is_airplane_mode,
1870 wfc_mode[0],
1871 wifi_network_ssid,
1872 wifi_network_pass)
1873
1874 elif callee_slot == 0:
1875 phone_setup_on_rat(
1876 log,
1877 ad_callee,
1878 callee_rat[1],
1879 callee_other_sub_id,
1880 is_airplane_mode,
1881 wfc_mode[1],
1882 wifi_network_ssid,
1883 wifi_network_pass)
1884
1885 argv = (
1886 log,
1887 ad_callee,
1888 callee_rat[callee_slot],
1889 callee_sub_id,
1890 is_airplane_mode,
1891 wfc_mode[callee_slot],
1892 wifi_network_ssid,
1893 wifi_network_pass)
1894
1895 tasks = [(phone_setup_voice_general, (log, ad_caller)),
1896 (phone_setup_on_rat, argv),
1897 (phone_setup_voice_general, (log, ad_forwarded_callee))]
1898
1899 if not multithread_func(log, tasks):
1900 log.error("Phone Failed to Set Up Properly.")
1901 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1902 raise signals.TestFailure("Failed",
1903 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1904
1905 if is_wifi_connected:
1906 if not ensure_wifi_connected(
1907 log,
1908 ad_callee,
1909 wifi_network_ssid,
1910 wifi_network_pass,
1911 apm=is_airplane_mode):
1912 return False
1913 time.sleep(5)
1914
1915 if "wfc" not in callee_rat[callee_slot]:
1916 if not toggle_wfc_for_subscription(
1917 log,
1918 ad_callee,
1919 new_state=True,
1920 sub_id=callee_sub_id):
1921 return False
1922 if not set_wfc_mode_for_subscription(
1923 ad_callee, wfc_mode[callee_slot], sub_id=callee_sub_id):
1924 return False
1925
1926 log.info(
1927 "Step 4: Make voice call with call forwarding %s.",
1928 call_forwarding_type)
1929 result = three_phone_call_forwarding_short_seq(
1930 log,
1931 ad_callee,
1932 None,
1933 is_callee_in_call,
1934 ad_caller,
1935 ad_forwarded_callee,
1936 call_forwarding_type=call_forwarding_type)
1937
1938 if not result:
1939 log.error(
1940 "Failed to make MO call from %s to %s slot %s and forward"
1941 " to %s.",
1942 ad_caller.serial,
1943 ad_callee.serial,
1944 callee_slot,
1945 ad_forwarded_callee.serial)
1946 return result
1947
Richard Chang2243e0e2021-08-03 01:15:05 +08001948
Markus Liu3bedf212021-06-16 17:39:07 +08001949def msim_volte_wfc_call_voice_conf(
1950 log,
Markus Liu86d06832021-10-13 17:31:02 +08001951 tel_logger,
Markus Liu3bedf212021-06-16 17:39:07 +08001952 ads,
1953 host_slot,
1954 dds_slot,
1955 host_rat=["5g_wfc", "5g_wfc"],
1956 merge=True,
1957 disable_cw=False,
1958 is_airplane_mode=False,
1959 is_wifi_connected=False,
1960 wfc_mode=[WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_CELLULAR_PREFERRED],
1961 reject_once=False,
1962 wifi_network_ssid=None,
1963 wifi_network_pass=None):
1964 """Make a VoLTE/WFC conference call at specific slot with DDS at
1965 specific slot.
1966
1967 Test step:
1968 1. Get sub IDs of specific slots of both MO and MT devices.
1969 2. Set up phones in desired RAT
1970 3. Enable VoLTE/WFC.
1971 4. Switch DDS to specific slot.
1972 5. Check HTTP connection after DDS switch.
1973 6. Make 3-way VoLTE/WFC call.
1974 7. Swap calls.
1975 8. Merge calls.
1976
1977 Args:
Markus Liu86d06832021-10-13 17:31:02 +08001978 log: logger object
1979 tel_logger: logger object for telephony proto
1980 ads: list of android devices
Markus Liu3bedf212021-06-16 17:39:07 +08001981 host_slot: Slot on the primary device to host the comference call.
1982 0 or 1 (0 for pSIM or 1 for eSIM)call
1983 dds_slot: Preferred data slot
1984 host_rat: RAT for both slots of the primary devicevice
1985 merge: True for merging 2 calls into the conference call. False for
1986 not merging 2 separated call.
1987 disable_cw: True for disabling call waiting and False on the
1988 contrary.
1989 enable_volte: True for enabling and False for disabling VoLTE for
1990 each slot on the primary device
1991 enable_wfc: True for enabling and False for disabling WFC for
1992 each slot on the primary device
1993 is_airplane_mode: True or False for WFC setup
1994 wfc_mode: Cellular preferred or Wi-Fi preferred.
1995 reject_once: True for rejecting the 2nd call once from the 3rd
1996 device (Phone C) to the primary device (Phone A).
1997 wifi_network_ssid: SSID of Wi-Fi AP
1998 wifi_network_pass: Password of Wi-Fi AP SSID
1999
2000 Returns:
2001 True or False
2002 """
2003 ad_host = ads[0]
2004 ad_p1 = ads[1]
2005 ad_p2 = ads[2]
2006
2007 host_sub_id = get_subid_from_slot_index(log, ad_host, host_slot)
2008 if host_sub_id == INVALID_SUB_ID:
2009 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
2010 return
2011 host_other_sub_id = get_subid_from_slot_index(
2012 log, ad_host, 1-host_slot)
2013 set_voice_sub_id(ad_host, host_sub_id)
2014 ad_host.log.info(
2015 "Sub ID for outgoing call at slot %s: %s",
2016 host_slot, get_outgoing_voice_sub_id(ad_host))
2017
2018 _, p1_sub_id, p2_sub_id = get_subid_on_same_network_of_host_ad(ads)
2019
2020 if p1_sub_id == INVALID_SUB_ID:
2021 ad_p1.log.warning("Failed to get proper sub ID.")
2022 return
2023 set_voice_sub_id(ad_p1, p1_sub_id)
2024 ad_p1.log.info(
2025 "Sub ID for incoming call: %s",
2026 get_incoming_voice_sub_id(ad_p1))
2027
2028 if p2_sub_id == INVALID_SUB_ID:
2029 ad_p2.log.warning("Failed to get proper sub ID.")
2030 return
2031 set_voice_sub_id(ad_p2, p2_sub_id)
2032 ad_p2.log.info(
2033 "Sub ID for incoming call: %s", get_incoming_voice_sub_id(ad_p2))
2034
Markus Liufdef3062021-06-27 15:08:29 +08002035 log.info("Step 1: Switch DDS.")
2036 if not set_dds_on_slot(ads[0], dds_slot):
2037 log.error(
2038 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
2039 return False
Markus Liu3bedf212021-06-16 17:39:07 +08002040
Markus Liufdef3062021-06-27 15:08:29 +08002041 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liu3bedf212021-06-16 17:39:07 +08002042 if not verify_http_connection(log, ads[0]):
2043 ad_host.log.error("Failed to verify http connection.")
2044 return False
2045 else:
2046 ad_host.log.info("Verify http connection successfully.")
2047
2048 if disable_cw:
2049 if not set_call_waiting(log, ad_host, enable=0):
2050 return False
2051
Markus Liufdef3062021-06-27 15:08:29 +08002052 log.info("Step 3: Set up phones in desired RAT.")
Markus Liu3bedf212021-06-16 17:39:07 +08002053 if host_slot == 1:
2054 phone_setup_on_rat(
2055 log,
2056 ad_host,
2057 host_rat[0],
2058 host_other_sub_id,
2059 is_airplane_mode,
2060 wfc_mode[0],
2061 wifi_network_ssid,
2062 wifi_network_pass)
2063
2064 elif host_slot == 0:
2065 phone_setup_on_rat(
2066 log,
2067 ad_host,
2068 host_rat[1],
2069 host_other_sub_id,
2070 is_airplane_mode,
2071 wfc_mode[1],
2072 wifi_network_ssid,
2073 wifi_network_pass)
2074
2075 argv = (
2076 log,
2077 ad_host,
2078 host_rat[host_slot],
2079 host_sub_id,
2080 is_airplane_mode,
2081 wfc_mode[host_slot],
2082 wifi_network_ssid,
2083 wifi_network_pass)
2084
2085 tasks = [(phone_setup_voice_general, (log, ad_p1)),
2086 (phone_setup_on_rat, argv),
2087 (phone_setup_voice_general, (log, ad_p2))]
2088
2089 if not multithread_func(log, tasks):
2090 log.error("Phone Failed to Set Up Properly.")
2091 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
2092 raise signals.TestFailure("Failed",
2093 extras={"fail_reason": "Phone Failed to Set Up Properly."})
2094
2095 if is_wifi_connected:
2096 if not ensure_wifi_connected(
2097 log,
2098 ad_host,
2099 wifi_network_ssid,
2100 wifi_network_pass,
2101 apm=is_airplane_mode):
2102 return False
2103 time.sleep(5)
2104
2105 if "wfc" not in host_rat[host_slot]:
2106 if not toggle_wfc_for_subscription(
2107 log,
2108 ad_host,
2109 new_state=True,
2110 sub_id=host_sub_id):
2111 return False
2112 if not set_wfc_mode_for_subscription(
2113 ad_host, wfc_mode[host_slot], sub_id=host_sub_id):
2114 return False
2115
2116 log.info("Step 4: Make 3-way voice call.")
2117 is_host_in_call = is_phone_in_call_on_rat(
2118 log, ad_host, host_rat[host_slot], only_return_fn=True)
2119 call_ab_id = _three_phone_call_mo_add_mt(
2120 log,
2121 [ad_host, ad_p1, ad_p2],
2122 [None, None, None],
2123 [is_host_in_call, None, None],
2124 reject_once=reject_once)
2125
2126 if call_ab_id is None:
2127 if disable_cw:
2128 set_call_waiting(log, ad_host, enable=1)
2129 if str(getattr(ad_host, "exception", None)) == \
2130 "PhoneA call PhoneC failed.":
2131 ads[0].log.info("PhoneA failed to call PhoneC due to call"
2132 " waiting being disabled.")
2133 delattr(ad_host, "exception")
2134 return True
2135 log.error("Failed to get call_ab_id")
2136 return False
2137 else:
2138 if disable_cw:
2139 set_call_waiting(log, ad_host, enable=0)
2140 return False
2141
2142 calls = ads[0].droid.telecomCallGetCallIds()
2143 ads[0].log.info("Calls in PhoneA %s", calls)
2144 if num_active_calls(log, ads[0]) != 2:
2145 return False
2146 if calls[0] == call_ab_id:
2147 call_ac_id = calls[1]
2148 else:
2149 call_ac_id = calls[0]
2150
2151 if call_ac_id is None:
2152 log.error("Failed to get call_ac_id")
2153 return False
2154
2155 num_swaps = 2
Markus Liufdef3062021-06-27 15:08:29 +08002156 log.info("Step 5: Begin Swap x%s test.", num_swaps)
Markus Liu3bedf212021-06-16 17:39:07 +08002157 if not swap_calls(log, ads, call_ab_id, call_ac_id,
2158 num_swaps):
2159 ad_host.log.error("Swap test failed.")
2160 return False
2161
2162 if not merge:
2163 result = True
2164 if not hangup_call(log, ads[1]):
2165 result = False
2166 if not hangup_call(log, ads[2]):
2167 result = False
2168 return result
2169 else:
Markus Liufdef3062021-06-27 15:08:29 +08002170 log.info("Step 6: Merge calls.")
Markus Liu3bedf212021-06-16 17:39:07 +08002171
2172 if re.search('csfb|2g|3g', host_rat[host_slot].lower(), re.I):
2173 return _test_wcdma_conference_merge_drop(
2174 log, ads, call_ab_id, call_ac_id)
2175 else:
2176 return _test_ims_conference_merge_drop_second_call_from_participant(
Markus Liu481eccd2021-04-21 14:36:15 +08002177 log, ads, call_ab_id, call_ac_id)