blob: 58a3c1093f67d5e16869df15211c050f08102386 [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 Liue3143912021-03-31 10:49:00 +080023from acts_contrib.test_utils.tel.loggers.protos.telephony_metric_pb2 import TelephonyVoiceTestResult
24from acts_contrib.test_utils.tel.loggers.telephony_metric_logger import TelephonyMetricLogger
25from 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 Liufdef3062021-06-27 15:08:29 +080030from acts_contrib.test_utils.tel.tel_subscription_utils import get_default_data_sub_id
Markus Liue3143912021-03-31 10:49:00 +080031from acts_contrib.test_utils.tel.tel_subscription_utils import get_incoming_voice_sub_id
Markus Liufdef3062021-06-27 15:08:29 +080032from acts_contrib.test_utils.tel.tel_subscription_utils import get_outgoing_message_sub_id
Markus Liue3143912021-03-31 10:49:00 +080033from acts_contrib.test_utils.tel.tel_subscription_utils import get_outgoing_voice_sub_id
34from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_from_slot_index
Markus Liufdef3062021-06-27 15:08:29 +080035from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_on_same_network_of_host_ad
36from acts_contrib.test_utils.tel.tel_subscription_utils import set_dds_on_slot
Markus Liufdef3062021-06-27 15:08:29 +080037from acts_contrib.test_utils.tel.tel_subscription_utils import set_message_subid
38from acts_contrib.test_utils.tel.tel_subscription_utils import set_subid_for_data
39from acts_contrib.test_utils.tel.tel_subscription_utils import set_voice_sub_id
Markus Liuccd95342021-07-05 01:55:05 +080040from acts_contrib.test_utils.tel.tel_test_utils import active_file_download_test
Markus Liu481eccd2021-04-21 14:36:15 +080041from acts_contrib.test_utils.tel.tel_test_utils import call_setup_teardown
Markus Liu3bedf212021-06-16 17:39:07 +080042from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected
Markus Liu481eccd2021-04-21 14:36:15 +080043from acts_contrib.test_utils.tel.tel_test_utils import erase_call_forwarding_by_mmi
44from acts_contrib.test_utils.tel.tel_test_utils import get_operator_name
Markus Liufdef3062021-06-27 15:08:29 +080045from acts_contrib.test_utils.tel.tel_test_utils import get_slot_index_from_subid
46from acts_contrib.test_utils.tel.tel_test_utils import hangup_call
47from acts_contrib.test_utils.tel.tel_test_utils import initiate_call
48from acts_contrib.test_utils.tel.tel_test_utils import log_messaging_screen_shot
49from acts_contrib.test_utils.tel.tel_test_utils import multithread_func
50from acts_contrib.test_utils.tel.tel_test_utils import mms_send_receive_verify
51from acts_contrib.test_utils.tel.tel_test_utils import num_active_calls
Markus Liuccd95342021-07-05 01:55:05 +080052from acts_contrib.test_utils.tel.tel_test_utils import power_off_sim
53from acts_contrib.test_utils.tel.tel_test_utils import power_on_sim
Markus Liu3bedf212021-06-16 17:39:07 +080054from acts_contrib.test_utils.tel.tel_test_utils import set_call_forwarding_by_mmi
Markus Liufdef3062021-06-27 15:08:29 +080055from acts_contrib.test_utils.tel.tel_test_utils import set_call_waiting
56from acts_contrib.test_utils.tel.tel_test_utils import set_wfc_mode_for_subscription
57from acts_contrib.test_utils.tel.tel_test_utils import sms_send_receive_verify_for_subscription
Richard Chang8d40b882021-06-28 23:58:51 +080058from acts_contrib.test_utils.tel.tel_test_utils import start_youtube_video
Markus Liufdef3062021-06-27 15:08:29 +080059from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
60from acts_contrib.test_utils.tel.tel_test_utils import toggle_wfc_for_subscription
61from 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
63from acts_contrib.test_utils.tel.tel_test_utils import wait_and_reject_call_for_subscription
Markus Liu528ac982021-07-19 01:30:37 +080064from acts_contrib.test_utils.tel.tel_test_utils import wifi_toggle_state
Markus Liufdef3062021-06-27 15:08:29 +080065from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call_on_rat
Markus Liu3bedf212021-06-16 17:39:07 +080066from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_voice_general
Markus Liue3143912021-03-31 10:49:00 +080067from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_on_rat
Markus Liufdef3062021-06-27 15:08:29 +080068from acts_contrib.test_utils.tel.tel_voice_utils import swap_calls
69from acts_contrib.test_utils.tel.tel_voice_utils import three_phone_call_forwarding_short_seq
70from acts_contrib.test_utils.tel.tel_voice_utils import three_phone_call_waiting_short_seq
Markus Liue3143912021-03-31 10:49:00 +080071from acts_contrib.test_utils.tel.tel_voice_utils import two_phone_call_msim_for_slot
Markus Liuccd95342021-07-05 01:55:05 +080072from acts_contrib.test_utils.tel.tel_voice_utils import wait_for_network_idle
Markus Liu481eccd2021-04-21 14:36:15 +080073from acts_contrib.test_utils.tel.tel_voice_conf_utils import _test_ims_conference_merge_drop_second_call_from_participant
74from acts_contrib.test_utils.tel.tel_voice_conf_utils import _test_wcdma_conference_merge_drop
Markus Liu3bedf212021-06-16 17:39:07 +080075from acts_contrib.test_utils.tel.tel_voice_conf_utils import _three_phone_call_mo_add_mt
Markus Liue3143912021-03-31 10:49:00 +080076
77CallResult = TelephonyVoiceTestResult.CallResult.Value
78tel_logger = TelephonyMetricLogger.for_test_case()
79
Richard Chang2243e0e2021-08-03 01:15:05 +080080
Markus Liue3143912021-03-31 10:49:00 +080081def dsds_voice_call_test(
82 log,
83 ads,
84 mo_slot,
85 mt_slot,
86 dds,
87 mo_rat=["", ""],
88 mt_rat=["", ""],
Markus Liu528ac982021-07-19 01:30:37 +080089 call_direction="mo",
90 is_airplane_mode=False,
91 wfc_mode=[
92 WFC_MODE_CELLULAR_PREFERRED,
93 WFC_MODE_CELLULAR_PREFERRED],
94 wifi_network_ssid=None,
95 wifi_network_pass=None,
96 turn_off_wifi_in_the_end=False,
97 turn_off_airplane_mode_in_the_end=False):
Markus Liue3143912021-03-31 10:49:00 +080098 """Make MO/MT voice call at specific slot in specific RAT with DDS at
99 specific slot.
100
101 Test step:
102 1. Get sub IDs of specific slots of both MO and MT devices.
103 2. Switch DDS to specific slot.
104 3. Check HTTP connection after DDS switch.
105 4. Set up phones in desired RAT.
106 5. Make voice call.
Markus Liu528ac982021-07-19 01:30:37 +0800107 6. Turn off airplane mode if necessary.
108 7. Turn off Wi-Fi if necessary.
109 8. Verify RAT and HTTP connection.
Markus Liue3143912021-03-31 10:49:00 +0800110
111 Args:
112 log: logger object
113 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,
261 get_slot_index_from_subid(log, ad_mo, mo_sub_id),
262 None,
263 is_mo_in_call,
264 ad_mt,
265 get_slot_index_from_subid(log, ad_mt, mt_sub_id),
266 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,
474 ads,
475 nw_rat=["volte", "volte"],
476 call_slot=0,
477 call_direction=None,
478 call_or_sms_or_mms="call",
479 streaming=True,
480 is_airplane_mode=False,
481 wfc_mode=[WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_CELLULAR_PREFERRED],
482 wifi_network_ssid=None,
483 wifi_network_pass=None):
484 """Switch DDS and make voice call(VoLTE/WFC/CS call)/SMS/MMS together with
485 Youtube playing after each DDS switch at specific slot in specific RAT.
486
487 Test step:
488 1. Get sub ID of each slot of the primary device.
489 2. Set up phones in desired RAT.
490 3. Switch DDS to slot 0.
491 4. Check HTTP connection after DDS switch.
492 5. Play Youtube.
493 6. Make voice call (VoLTE/WFC/CS call)/SMS/MMS
494 7. Switch DDS to slot 1 and repeat step 4-6.
495 8. Switch DDS to slot 0 again and repeat step 4-6.
496
497 Args:
498 log: logger object
499 ads: list of android devices
500 nw_rat: RAT for both slots of the primary device
501 call_slot: Slot for making voice call
502 call_direction: "mo" or "mt" or None to stoping making call.
503 call_or_sms_or_mms: Voice call or SMS or MMS
504 streaming: True for playing Youtube after DDS switch and False on the contrary.
505 is_airplane_mode: True or False for WFC setup
506 wfc_mode: Cellular preferred or Wi-Fi preferred.
507 wifi_network_ssid: SSID of Wi-Fi AP
508 wifi_network_pass: Password of Wi-Fi AP SSID
509
510 Returns:
511 TestFailure if failed.
512 """
513 ad = ads[0]
514 slot_0_subid = get_subid_from_slot_index(log, ad, 0)
515 slot_1_subid = get_subid_from_slot_index(log, ad, 1)
516
517 if slot_0_subid == INVALID_SUB_ID or slot_1_subid == INVALID_SUB_ID:
518 ad.log.error("Not all slots have valid sub ID.")
519 raise signals.TestFailure("Failed",
520 extras={"fail_reason": "Not all slots have valid sub ID"})
521
522 ad.log.info(
523 "Step 0: Set up phone in desired RAT (slot 0: %s, slot 1: %s)",
524 nw_rat[0], nw_rat[1])
525
526 if not phone_setup_on_rat(
527 log,
528 ad,
529 nw_rat[0],
530 slot_0_subid,
531 is_airplane_mode,
532 wfc_mode[0],
533 wifi_network_ssid,
534 wifi_network_pass):
535 log.error("Phone Failed to Set Up Properly.")
536 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
537 raise signals.TestFailure("Failed",
538 extras={"fail_reason": "Phone Failed to Set Up Properly."})
539
540 if not phone_setup_on_rat(
541 log,
542 ad,
543 nw_rat[1],
544 slot_1_subid,
545 is_airplane_mode,
546 wfc_mode[1],
547 wifi_network_ssid,
548 wifi_network_pass):
549 log.error("Phone Failed to Set Up Properly.")
550 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
551 raise signals.TestFailure("Failed",
552 extras={"fail_reason": "Phone Failed to Set Up Properly."})
553
554 is_slot0_in_call = is_phone_in_call_on_rat(
555 log, ad, nw_rat[0], True)
556 is_slot1_in_call = is_phone_in_call_on_rat(
557 log, ad, nw_rat[1], True)
558
559 for attempt in range(3):
560 if attempt != 0:
561 ad.log.info("Repeat step 1 to 4.")
562
563 ad.log.info("Step 1: Switch DDS.")
564 if attempt % 2 == 0:
565 set_dds_on_slot(ad, 0)
566 else:
567 set_dds_on_slot(ad, 1)
568
569 ad.log.info("Step 2: Check HTTP connection after DDS switch.")
570 if not verify_http_connection(log, ad):
571 ad.log.error("Failed to verify http connection.")
572 return False
573 else:
574 ad.log.info("Verify http connection successfully.")
575
576 if streaming:
577 ad.log.info("Step 3: Start Youtube streaming.")
578 if not start_youtube_video(ad):
579 ad.log.warning("Fail to bring up youtube video")
580 time.sleep(10)
581 else:
582 ad.log.info("Step 3: Skip Youtube streaming.")
583
584 if not call_direction:
585 return True
586 else:
587 expected_result = True
588 if call_direction == "mo":
589 ad_mo = ads[0]
590 ad_mt = ads[1]
591 phone_setup_on_rat(log, ad_mt, 'general')
592 mo_sub_id = get_subid_from_slot_index(log, ad, call_slot)
593 if call_or_sms_or_mms == "call":
594 set_voice_sub_id(ad_mo, mo_sub_id)
595 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
596 ads)
597
598 if call_slot == 0:
599 is_mo_in_call = is_slot0_in_call
600 elif call_slot == 1:
601 is_mo_in_call = is_slot1_in_call
602 is_mt_in_call = None
603
604 elif call_or_sms_or_mms == "sms":
605 set_message_subid(ad_mo, mo_sub_id)
606 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
607 ads, type="sms")
608 set_message_subid(ad_mt, mt_sub_id)
609
610 elif call_or_sms_or_mms == "mms":
611 current_data_sub_id = get_default_data_sub_id(ad_mo)
612 if mo_sub_id != current_data_sub_id:
613 ad_mo.log.warning(
614 "Current data sub ID (%s) does not match"
615 " message sub ID (%s). MMS should NOT be sent.",
616 current_data_sub_id, mo_sub_id)
617 expected_result = False
618 set_message_subid(ad_mo, mo_sub_id)
619 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(
620 ads, type="sms")
621 set_message_subid(ad_mt, mt_sub_id)
622 set_subid_for_data(ad_mt, mt_sub_id)
623 ad_mt.droid.telephonyToggleDataConnection(True)
624
625 elif call_direction == "mt":
626 ad_mo = ads[1]
627 ad_mt = ads[0]
628 phone_setup_on_rat(log, ad_mo, 'general')
629 mt_sub_id = get_subid_from_slot_index(log, ad, call_slot)
630 if call_or_sms_or_mms == "call":
631 set_voice_sub_id(ad_mt, mt_sub_id)
632 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
633 ads)
634
635 if call_slot == 0:
636 is_mt_in_call = is_slot0_in_call
637 elif call_slot == 1:
638 is_mt_in_call = is_slot1_in_call
639 is_mo_in_call = None
640
641 elif call_or_sms_or_mms == "sms":
642 set_message_subid(ad_mt, mt_sub_id)
643 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
644 ads, type="sms")
645 set_message_subid(ad_mo, mo_sub_id)
646
647 elif call_or_sms_or_mms == "mms":
648 current_data_sub_id = get_default_data_sub_id(ad_mt)
649 if mt_sub_id != current_data_sub_id:
650 ad_mt.log.warning(
651 "Current data sub ID (%s) does not match"
652 " message sub ID (%s). MMS should NOT be"
653 " received.", current_data_sub_id, mt_sub_id)
654 expected_result = False
655 set_message_subid(ad_mt, mt_sub_id)
656 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(
657 ads, type="sms")
658 set_message_subid(ad_mo, mo_sub_id)
659 set_subid_for_data(ad_mo, mo_sub_id)
660 ad_mo.droid.telephonyToggleDataConnection(True)
661
662 if call_or_sms_or_mms == "call":
663 log.info("Step 4: Make voice call.")
664 mo_slot = get_slot_index_from_subid(
665 log, ad_mo, mo_sub_id)
666 mt_slot = get_slot_index_from_subid(
667 log, ad_mt, mt_sub_id)
668 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,
717 ads,
718 mo_slot,
719 mt_slot,
720 disabled_slot,
721 mo_rat=["", ""],
722 mt_rat=["", ""],
723 call_direction="mo"):
724 """Disable/enable pSIM or eSIM with voice call
725
726 Test step:
727 1. Get sub IDs of specific slots of both MO and MT devices.
728 2. Set up phones in desired RAT.
729 3. Disable assigned slot.
730 4. Switch DDS to the other slot.
731 5. Verify RAT and HTTP connection after DDS switch.
732 6. Make voice call.
733 7. Enable assigned slot.
734 8. Switch DDS to the assigned slot.
735 9. Verify RAT and HTTP connection after DDS switch.
736
737 Args:
738 log: logger object
739 ads: list of android devices
740 mo_slot: Slot making MO call (0 or 1)
741 mt_slot: Slot receiving MT call (0 or 1)
742 disabled_slot: slot to be disabled/enabled
743 mo_rat: RAT for both slots of MO device
744 mt_rat: RAT for both slots of MT device
745 call_direction: "mo" or "mt"
746
747 Returns:
748 TestFailure if failed.
749 """
750 if call_direction == "mo":
751 ad_mo = ads[0]
752 ad_mt = ads[1]
753 else:
754 ad_mo = ads[1]
755 ad_mt = ads[0]
756
757 if mo_slot is not None:
758 mo_sub_id = get_subid_from_slot_index(log, ad_mo, mo_slot)
759 if mo_sub_id == INVALID_SUB_ID:
760 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
761 raise signals.TestFailure(
762 "Failed",
763 extras={
764 "fail_reason": "Failed to get sub ID at slot %s." % mo_slot})
765 mo_other_sub_id = get_subid_from_slot_index(
766 log, ad_mo, 1-mo_slot)
767 set_voice_sub_id(ad_mo, mo_sub_id)
768 else:
769 _, mo_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
770 if mo_sub_id == INVALID_SUB_ID:
771 ad_mo.log.warning("Failed to get sub ID at slot %s.", mo_slot)
772 raise signals.TestFailure(
773 "Failed",
774 extras={
775 "fail_reason": "Failed to get sub ID at slot %s." % mo_slot})
776 mo_slot = "auto"
777 set_voice_sub_id(ad_mo, mo_sub_id)
778 ad_mo.log.info("Sub ID for outgoing call at slot %s: %s",
779 mo_slot, get_outgoing_voice_sub_id(ad_mo))
780
781 if mt_slot is not None:
782 mt_sub_id = get_subid_from_slot_index(log, ad_mt, mt_slot)
783 if mt_sub_id == INVALID_SUB_ID:
784 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
785 raise signals.TestFailure(
786 "Failed",
787 extras={
788 "fail_reason": "Failed to get sub ID at slot %s." % mt_slot})
789 mt_other_sub_id = get_subid_from_slot_index(
790 log, ad_mt, 1-mt_slot)
791 set_voice_sub_id(ad_mt, mt_sub_id)
792 else:
793 _, mt_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
794 if mt_sub_id == INVALID_SUB_ID:
795 ad_mt.log.warning("Failed to get sub ID at slot %s.", mt_slot)
796 raise signals.TestFailure(
797 "Failed",
798 extras={
799 "fail_reason": "Failed to get sub ID at slot %s." % mt_slot})
800 mt_slot = "auto"
801 set_voice_sub_id(ad_mt, mt_sub_id)
802 ad_mt.log.info("Sub ID for incoming call at slot %s: %s", mt_slot,
803 get_incoming_voice_sub_id(ad_mt))
804
805 if mo_slot == 0 or mo_slot == 1:
806 phone_setup_on_rat(log, ad_mo, mo_rat[1-mo_slot], mo_other_sub_id)
807 mo_phone_setup_func_argv = (log, ad_mo, mo_rat[mo_slot], mo_sub_id)
808 is_mo_in_call = is_phone_in_call_on_rat(
809 log, ad_mo, mo_rat[mo_slot], only_return_fn=True)
810 else:
811 mo_phone_setup_func_argv = (log, ad_mo, 'general')
812 is_mo_in_call = is_phone_in_call_on_rat(
813 log, ad_mo, 'general', only_return_fn=True)
814
815 if mt_slot == 0 or mt_slot == 1:
816 phone_setup_on_rat(log, ad_mt, mt_rat[1-mt_slot], mt_other_sub_id)
817 mt_phone_setup_func_argv = (log, ad_mt, mt_rat[mt_slot], mt_sub_id)
818 is_mt_in_call = is_phone_in_call_on_rat(
819 log, ad_mt, mt_rat[mt_slot], only_return_fn=True)
820 else:
821 mt_phone_setup_func_argv = (log, ad_mt, 'general')
822 is_mt_in_call = is_phone_in_call_on_rat(
823 log, ad_mt, 'general', only_return_fn=True)
824
825 log.info("Step 1: Set up phones in desired RAT.")
826 tasks = [(phone_setup_on_rat, mo_phone_setup_func_argv),
827 (phone_setup_on_rat, mt_phone_setup_func_argv)]
828 if not multithread_func(log, tasks):
829 log.error("Phone Failed to Set Up Properly.")
830 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
831 raise signals.TestFailure(
832 "Failed",
833 extras={"fail_reason": "Phone Failed to Set Up Properly."})
834
835 log.info("Step 2: Disable slot %s.", disabled_slot)
836 if not power_off_sim(ads[0], disabled_slot):
837 raise signals.TestFailure(
838 "Failed",
839 extras={
840 "fail_reason": "Failed to disable slot %s." % disabled_slot})
841
842 log.info("Step 3: Switch DDS.")
843 if not set_dds_on_slot(ads[0], 1-disabled_slot):
844 log.error(
845 "Failed to set DDS at slot %s on %s.",
846 (1-disabled_slot, ads[0].serial))
847 raise signals.TestFailure(
848 "Failed",
849 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
850 1-disabled_slot, ads[0].serial)})
851
852 log.info("Step 4: Verify RAT and HTTP connection after DDS switch.")
853 if mo_slot == 0 or mo_slot == 1:
854 if not wait_for_network_idle(
855 log, ad_mo, mo_rat[1-disabled_slot], mo_sub_id):
856 raise signals.TestFailure(
857 "Failed",
858 extras={
859 "fail_reason": "Idle state does not match the given "
860 "RAT %s." % mo_rat[1-disabled_slot]})
861
862 if mt_slot == 0 or mt_slot == 1:
863 if not wait_for_network_idle(
864 log, ad_mt, mt_rat[1-disabled_slot], mt_sub_id):
865 raise signals.TestFailure(
866 "Failed",
867 extras={
868 "fail_reason": "Idle state does not match the given "
869 "RAT %s." % mt_rat[1-disabled_slot]})
870
871 if not verify_http_connection(log, ads[0]):
872 log.error("Failed to verify http connection.")
873 raise signals.TestFailure(
874 "Failed",
875 extras={"fail_reason": "Failed to verify http connection."})
876 else:
877 log.info("Verify http connection successfully.")
878
879 log.info("Step 5: Make voice call.")
880 result = two_phone_call_msim_for_slot(
881 log,
882 ad_mo,
883 get_slot_index_from_subid(log, ad_mo, mo_sub_id),
884 None,
885 is_mo_in_call,
886 ad_mt,
887 get_slot_index_from_subid(log, ad_mt, mt_sub_id),
888 None,
889 is_mt_in_call)
890
891 tel_logger.set_result(result.result_value)
892
893 if not result:
894 log.error(
895 "Failed to make MO call from %s slot %s to %s slot %s",
896 ad_mo.serial, mo_slot, ad_mt.serial, mt_slot)
897 raise signals.TestFailure("Failed",
898 extras={"fail_reason": str(result.result_value)})
899
900 log.info("Step 6: Enable slot %s.", disabled_slot)
901 if not power_on_sim(ads[0], disabled_slot):
902 raise signals.TestFailure(
903 "Failed",
904 extras={"fail_reason": "Failed to enable slot %s." % disabled_slot})
905
906 log.info("Step 7: Switch DDS to slot %s.", disabled_slot)
907 if not set_dds_on_slot(ads[0], disabled_slot):
908 log.error(
909 "Failed to set DDS at slot %s on %s.",(disabled_slot, ads[0].serial))
910 raise signals.TestFailure(
911 "Failed",
912 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
913 disabled_slot, ads[0].serial)})
914
915 log.info("Step 8: Verify RAT and HTTP connection after DDS switch.")
916 if mo_slot == 0 or mo_slot == 1:
917 if not wait_for_network_idle(
918 log, ad_mo, mo_rat[disabled_slot], mo_other_sub_id):
919 raise signals.TestFailure(
920 "Failed",
921 extras={
922 "fail_reason": "Idle state does not match the given "
923 "RAT %s." % mo_rat[mo_slot]})
924
925 if mt_slot == 0 or mt_slot == 1:
926 if not wait_for_network_idle(
927 log, ad_mt, mt_rat[disabled_slot], mt_other_sub_id):
928 raise signals.TestFailure(
929 "Failed",
930 extras={"fail_reason": "Idle state does not match the given "
931 "RAT %s." % mt_rat[mt_slot]})
932
933 if not verify_http_connection(log, ads[0]):
934 log.error("Failed to verify http connection.")
935 raise signals.TestFailure(
936 "Failed",
937 extras={"fail_reason": "Failed to verify http connection."})
938 else:
939 log.info("Verify http connection successfully.")
940
Richard Chang2243e0e2021-08-03 01:15:05 +0800941
Markus Liuccd95342021-07-05 01:55:05 +0800942def enable_slot_after_data_call_test(
943 log,
944 ad,
945 disabled_slot,
946 rat=["", ""]):
947 """Disable/enable pSIM or eSIM with data call
948
949 Test step:
950 1. Get sub IDs of specific slots of both MO and MT devices.
951 2. Set up phones in desired RAT.
952 3. Disable assigned slot.
953 4. Switch DDS to the other slot.
954 5. Verify RAT and HTTP connection after DDS switch.
955 6. Make a data call by http download.
956 7. Enable assigned slot.
957 8. Switch DDS to the assigned slot.
958 9. Verify RAT and HTTP connection after DDS switch.
959
960 Args:
961 log: logger object
962 ads: list of android devices
963 disabled_slot: slot to be disabled/enabled
964 mo_rat: RAT for both slots of MO device
965 mt_rat: RAT for both slots of MT device
966
967 Returns:
968 TestFailure if failed.
969 """
970 data_sub_id = get_subid_from_slot_index(log, ad, 1-disabled_slot)
971 if data_sub_id == INVALID_SUB_ID:
972 ad.log.warning("Failed to get sub ID at slot %s.", 1-disabled_slot)
973 raise signals.TestFailure(
974 "Failed",
975 extras={
976 "fail_reason": "Failed to get sub ID at slot %s." % (
977 1-disabled_slot)})
978 other_sub_id = get_subid_from_slot_index(log, ad, disabled_slot)
979
980 log.info("Step 1: Set up phones in desired RAT.")
981 if not phone_setup_on_rat(log, ad, rat[1-disabled_slot], data_sub_id):
982 raise signals.TestFailure(
983 "Failed",
984 extras={"fail_reason": "Phone Failed to Set Up Properly."})
985
986 if not phone_setup_on_rat(log, ad, rat[disabled_slot], other_sub_id):
987 raise signals.TestFailure(
988 "Failed",
989 extras={"fail_reason": "Phone Failed to Set Up Properly."})
990
991 log.info("Step 2: Disable slot %s.", disabled_slot)
992 if not power_off_sim(ad, disabled_slot):
993 raise signals.TestFailure(
994 "Failed",
995 extras={"fail_reason": "Failed to disable slot %s." % disabled_slot})
996
997 log.info("Step 3: Switch DDS.")
998 if not set_dds_on_slot(ad, 1-disabled_slot):
999 log.error(
1000 "Failed to set DDS at slot %s on %s.",(1-disabled_slot, ad.serial))
1001 raise signals.TestFailure(
1002 "Failed",
1003 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
1004 1-disabled_slot, ad.serial)})
1005
1006 log.info("Step 4: Verify RAT and HTTP connection after DDS switch.")
1007 if not wait_for_network_idle(log, ad, rat[1-disabled_slot], data_sub_id):
1008 raise signals.TestFailure(
1009 "Failed",
1010 extras={
1011 "fail_reason": "Idle state does not match the given "
1012 "RAT %s." % rat[1-disabled_slot]})
1013
1014 if not verify_http_connection(log, ad):
1015 log.error("Failed to verify http connection.")
1016 raise signals.TestFailure("Failed",
1017 extras={"fail_reason": "Failed to verify http connection."})
1018 else:
1019 log.info("Verify http connection successfully.")
1020
1021 duration = 30
1022 start_time = datetime.now()
1023 while datetime.now() - start_time <= timedelta(seconds=duration):
1024 if not active_file_download_test(
1025 log, ad, file_name='20MB', method='sl4a'):
1026 raise signals.TestFailure(
1027 "Failed",
1028 extras={"fail_reason": "Failed to download by sl4a."})
1029
1030 log.info("Step 6: Enable slot %s.", disabled_slot)
1031 if not power_on_sim(ad, disabled_slot):
1032 raise signals.TestFailure(
1033 "Failed",
1034 extras={"fail_reason": "Failed to enable slot %s." % disabled_slot})
1035
1036 log.info("Step 7: Switch DDS to slot %s.", disabled_slot)
1037 if not set_dds_on_slot(ad, disabled_slot):
1038 log.error(
1039 "Failed to set DDS at slot %s on %s.",(disabled_slot, ad.serial))
1040 raise signals.TestFailure(
1041 "Failed",
1042 extras={"fail_reason": "Failed to set DDS at slot %s on %s." % (
1043 disabled_slot, ad.serial)})
1044
1045 log.info("Step 8: Verify RAT and HTTP connection after DDS switch.")
1046 if not wait_for_network_idle(log, ad, rat[disabled_slot], other_sub_id):
1047 raise signals.TestFailure(
1048 "Failed",
1049 extras={
1050 "fail_reason": "Idle state does not match the given "
1051 "RAT %s." % rat[disabled_slot]})
1052
1053 if not verify_http_connection(log, ad):
1054 log.error("Failed to verify http connection.")
1055 raise signals.TestFailure(
1056 "Failed",
1057 extras={"fail_reason": "Failed to verify http connection."})
1058 else:
1059 log.info("Verify http connection successfully.")
1060
Richard Chang2243e0e2021-08-03 01:15:05 +08001061
Markus Liu481eccd2021-04-21 14:36:15 +08001062def erase_call_forwarding(log, ad):
1063 slot0_sub_id = get_subid_from_slot_index(log, ad, 0)
1064 slot1_sub_id = get_subid_from_slot_index(log, ad, 1)
1065 current_voice_sub_id = get_incoming_voice_sub_id(ad)
1066 for sub_id in (slot0_sub_id, slot1_sub_id):
1067 set_voice_sub_id(ad, sub_id)
1068 get_operator_name(log, ad, sub_id)
1069 erase_call_forwarding_by_mmi(log, ad)
1070 set_voice_sub_id(ad, current_voice_sub_id)
1071
Richard Chang2243e0e2021-08-03 01:15:05 +08001072
Markus Liu481eccd2021-04-21 14:36:15 +08001073def three_way_calling_mo_and_mt_with_hangup_once(
1074 log,
1075 ads,
1076 phone_setups,
1077 verify_funcs,
1078 reject_once=False):
1079 """Use 3 phones to make MO call and MT call.
1080
1081 Call from PhoneA to PhoneB, accept on PhoneB.
1082 Call from PhoneC to PhoneA, accept on PhoneA.
1083
1084 Args:
1085 ads: list of ad object.
1086 The list should have three objects.
1087 phone_setups: list of phone setup functions.
1088 The list should have three objects.
1089 verify_funcs: list of phone call verify functions.
1090 The list should have three objects.
1091
1092 Returns:
1093 If success, return 'call_AB' id in PhoneA.
1094 if fail, return None.
1095 """
1096
1097 class _CallException(Exception):
1098 pass
1099
1100 try:
1101 verify_func_a, verify_func_b, verify_func_c = verify_funcs
1102 tasks = []
1103 for ad, setup_func in zip(ads, phone_setups):
1104 if setup_func is not None:
1105 tasks.append((setup_func, (log, ad, get_incoming_voice_sub_id(ad))))
1106 if tasks != [] and not multithread_func(log, tasks):
1107 log.error("Phone Failed to Set Up Properly.")
1108 raise _CallException("Setup failed.")
1109 for ad in ads:
1110 ad.droid.telecomCallClearCallList()
1111 if num_active_calls(log, ad) != 0:
1112 ad.log.error("Phone Call List is not empty.")
1113 raise _CallException("Clear call list failed.")
1114
1115 log.info("Step1: Call From PhoneA to PhoneB.")
1116 if not call_setup_teardown(
1117 log,
1118 ads[0],
1119 ads[1],
1120 ad_hangup=None,
1121 verify_caller_func=verify_func_a,
1122 verify_callee_func=verify_func_b):
1123 raise _CallException("PhoneA call PhoneB failed.")
1124
1125 calls = ads[0].droid.telecomCallGetCallIds()
1126 ads[0].log.info("Calls in PhoneA %s", calls)
1127 if num_active_calls(log, ads[0]) != 1:
1128 raise _CallException("Call list verify failed.")
1129 call_ab_id = calls[0]
1130
1131 log.info("Step2: Call From PhoneC to PhoneA.")
1132 if reject_once:
1133 log.info("Step2-1: Reject incoming call once.")
1134 if not initiate_call(
1135 log,
1136 ads[2],
1137 ads[0].telephony['subscription'][get_incoming_voice_sub_id(
1138 ads[0])]['phone_num']):
1139 ads[2].log.error("Initiate call failed.")
1140 raise _CallException("Failed to initiate call.")
1141
1142 if not wait_and_reject_call_for_subscription(
1143 log,
1144 ads[0],
1145 get_incoming_voice_sub_id(ads[0]),
1146 incoming_number= \
1147 ads[2].telephony['subscription'][
1148 get_incoming_voice_sub_id(
1149 ads[2])]['phone_num']):
1150 ads[0].log.error("Reject call fail.")
1151 raise _CallException("Failed to reject call.")
1152
1153 hangup_call(log, ads[2])
1154 time.sleep(15)
1155
1156 if not call_setup_teardown(
1157 log,
1158 ads[2],
1159 ads[0],
1160 ad_hangup=None,
1161 verify_caller_func=verify_func_c,
1162 verify_callee_func=verify_func_a):
1163 raise _CallException("PhoneA call PhoneC failed.")
1164 if not verify_incall_state(log, [ads[0], ads[1], ads[2]],
1165 True):
1166 raise _CallException("Not All phones are in-call.")
1167
1168 except Exception as e:
1169 setattr(ads[0], "exception", e)
1170 return None
1171
1172 return call_ab_id
1173
Richard Chang2243e0e2021-08-03 01:15:05 +08001174
Markus Liufdef3062021-06-27 15:08:29 +08001175def msim_message_test(
1176 log,
1177 ad_mo,
1178 ad_mt,
1179 mo_sub_id,
1180 mt_sub_id, msg="SMS",
1181 max_wait_time=MAX_WAIT_TIME_SMS_RECEIVE,
1182 expected_result=True):
1183 """Make MO/MT SMS/MMS at specific slot.
1184
1185 Args:
1186 ad_mo: Android object of the device sending SMS/MMS
1187 ad_mt: Android object of the device receiving SMS/MMS
1188 mo_sub_id: Sub ID of MO device
1189 mt_sub_id: Sub ID of MT device
1190 max_wait_time: Max wait time before SMS/MMS is received.
1191 expected_result: True for successful sending/receiving and False on
1192 the contrary
1193
1194 Returns:
1195 True if the result matches expected_result and False on the
1196 contrary.
1197 """
1198 message_lengths = (50, 160, 180)
1199 if msg == "SMS":
1200 for length in message_lengths:
1201 message_array = [rand_ascii_str(length)]
1202 if not sms_send_receive_verify_for_subscription(
1203 log,
1204 ad_mo,
1205 ad_mt,
1206 mo_sub_id,
1207 mt_sub_id,
1208 message_array,
1209 max_wait_time):
1210 ad_mo.log.warning(
1211 "%s of length %s test failed", msg, length)
1212 return False
1213 else:
1214 ad_mo.log.info(
1215 "%s of length %s test succeeded", msg, length)
1216 log.info("%s test of length %s characters succeeded.",
1217 msg, message_lengths)
1218
1219 elif msg == "MMS":
1220 for length in message_lengths:
1221 message_array = [("Test Message", rand_ascii_str(length), None)]
1222
1223 if not mms_send_receive_verify(
1224 log,
1225 ad_mo,
1226 ad_mt,
1227 message_array,
1228 max_wait_time,
1229 expected_result):
1230 log.warning("%s of body length %s test failed",
1231 msg, length)
1232 return False
1233 else:
1234 log.info(
1235 "%s of body length %s test succeeded", msg, length)
1236 log.info("%s test of body lengths %s succeeded",
1237 msg, message_lengths)
1238 return True
1239
Richard Chang2243e0e2021-08-03 01:15:05 +08001240
Markus Liu481eccd2021-04-21 14:36:15 +08001241def msim_call_forwarding(
1242 log,
1243 ads,
1244 caller_slot,
1245 callee_slot,
1246 forwarded_callee_slot,
1247 dds_slot,
1248 caller_rat=["", ""],
1249 callee_rat=["", ""],
1250 forwarded_callee_rat=["", ""],
1251 call_forwarding_type="unconditional"):
1252 """Make MO voice call to the primary device at specific slot in specific
1253 RAT with DDS at specific slot, and then forwarded to 3rd device with
1254 specific call forwarding type.
1255
1256 Test step:
1257 1. Get sub IDs of specific slots of both MO and MT devices.
1258 2. Switch DDS to specific slot.
1259 3. Check HTTP connection after DDS switch.
1260 4. Set up phones in desired RAT.
1261 5. Register and enable call forwarding with specifc type.
1262 5. Make voice call to the primary device and wait for being forwarded
1263 to 3rd device.
1264
1265 Args:
1266 caller_slot: Slot of 2nd device making MO call (0 or 1)
1267 callee_slot: Slot of primary device receiving and forwarding MT call
1268 (0 or 1)
1269 forwarded_callee_slot: Slot of 3rd device receiving forwarded call.
1270 dds_slot: Preferred data slot
1271 caller_rat: RAT for both slots of the 2nd device
1272 callee_rat: RAT for both slots of the primary device
1273 forwarded_callee_rat: RAT for both slots of the 3rd device
1274 call_forwarding_type:
1275 "unconditional"
1276 "busy"
1277 "not_answered"
1278 "not_reachable"
1279
1280 Returns:
1281 True or False
1282 """
1283 ad_caller = ads[1]
1284 ad_callee = ads[0]
1285 ad_forwarded_callee = ads[2]
1286
1287 if callee_slot is not None:
1288 callee_sub_id = get_subid_from_slot_index(
1289 log, ad_callee, callee_slot)
1290 if callee_sub_id == INVALID_SUB_ID:
1291 ad_callee.log.warning(
1292 "Failed to get sub ID at slot %s.", callee_slot)
1293 return False
1294 callee_other_sub_id = get_subid_from_slot_index(
1295 log, ad_callee, 1-callee_slot)
1296 set_voice_sub_id(ad_callee, callee_sub_id)
1297 else:
1298 callee_sub_id, _, _ = get_subid_on_same_network_of_host_ad(ads)
1299 if callee_sub_id == INVALID_SUB_ID:
1300 ad_callee.log.warning(
1301 "Failed to get sub ID at slot %s.", callee_slot)
1302 return False
1303 callee_slot = "auto"
1304 set_voice_sub_id(ad_callee, callee_sub_id)
1305 ad_callee.log.info(
1306 "Sub ID for incoming call at slot %s: %s",
1307 callee_slot, get_incoming_voice_sub_id(ad_callee))
1308
1309 if caller_slot is not None:
1310 caller_sub_id = get_subid_from_slot_index(
1311 log, ad_caller, caller_slot)
1312 if caller_sub_id == INVALID_SUB_ID:
1313 ad_caller.log.warning(
1314 "Failed to get sub ID at slot %s.", caller_slot)
1315 return False
1316 caller_other_sub_id = get_subid_from_slot_index(
1317 log, ad_caller, 1-caller_slot)
1318 set_voice_sub_id(ad_caller, caller_sub_id)
1319 else:
1320 _, caller_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1321 if caller_sub_id == INVALID_SUB_ID:
1322 ad_caller.log.warning(
1323 "Failed to get sub ID at slot %s.", caller_slot)
1324 return False
1325 caller_slot = "auto"
1326 set_voice_sub_id(ad_caller, caller_sub_id)
1327 ad_caller.log.info(
1328 "Sub ID for outgoing call at slot %s: %s",
1329 caller_slot, get_outgoing_voice_sub_id(ad_caller))
1330
1331 if forwarded_callee_slot is not None:
1332 forwarded_callee_sub_id = get_subid_from_slot_index(
1333 log, ad_forwarded_callee, forwarded_callee_slot)
1334 if forwarded_callee_sub_id == INVALID_SUB_ID:
1335 ad_forwarded_callee.log.warning(
1336 "Failed to get sub ID at slot %s.", forwarded_callee_slot)
1337 return False
1338 forwarded_callee_other_sub_id = get_subid_from_slot_index(
1339 log, ad_forwarded_callee, 1-forwarded_callee_slot)
1340 set_voice_sub_id(
1341 ad_forwarded_callee, forwarded_callee_sub_id)
1342 else:
1343 _, _, forwarded_callee_sub_id = \
1344 get_subid_on_same_network_of_host_ad(ads)
1345 if forwarded_callee_sub_id == INVALID_SUB_ID:
1346 ad_forwarded_callee.log.warning(
1347 "Failed to get sub ID at slot %s.", forwarded_callee_slot)
1348 return False
1349 forwarded_callee_slot = "auto"
1350 set_voice_sub_id(
1351 ad_forwarded_callee, forwarded_callee_sub_id)
1352 ad_forwarded_callee.log.info(
1353 "Sub ID for incoming call at slot %s: %s",
1354 forwarded_callee_slot,
1355 get_incoming_voice_sub_id(ad_forwarded_callee))
1356
1357 log.info("Step 1: Switch DDS.")
Markus Liufdef3062021-06-27 15:08:29 +08001358 if not set_dds_on_slot(ads[0], dds_slot):
1359 log.error(
1360 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1361 return False
Markus Liu481eccd2021-04-21 14:36:15 +08001362
1363 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liufdef3062021-06-27 15:08:29 +08001364 if not verify_http_connection(log, ads[0]):
Markus Liu481eccd2021-04-21 14:36:15 +08001365 log.error("Failed to verify http connection.")
1366 return False
1367 else:
1368 log.info("Verify http connection successfully.")
1369
1370 if caller_slot == 1:
1371 phone_setup_on_rat(
1372 log,
1373 ad_caller,
1374 caller_rat[0],
1375 caller_other_sub_id)
1376
1377 elif caller_slot == 0:
1378 phone_setup_on_rat(
1379 log,
1380 ad_caller,
1381 caller_rat[1],
1382 caller_other_sub_id)
1383 else:
1384 phone_setup_on_rat(
1385 log,
1386 ad_caller,
1387 'general')
1388
1389 if callee_slot == 1:
1390 phone_setup_on_rat(
1391 log,
1392 ad_callee,
1393 callee_rat[0],
1394 callee_other_sub_id)
1395
1396 elif callee_slot == 0:
1397 phone_setup_on_rat(
1398 log,
1399 ad_callee,
1400 callee_rat[1],
1401 callee_other_sub_id)
1402 else:
1403 phone_setup_on_rat(
1404 log,
1405 ad_callee,
1406 'general')
1407
1408 if forwarded_callee_slot == 1:
1409 phone_setup_on_rat(
1410 log,
1411 ad_forwarded_callee,
1412 forwarded_callee_rat[0],
1413 forwarded_callee_other_sub_id)
1414
1415 elif forwarded_callee_slot == 0:
1416 phone_setup_on_rat(
1417 log,
1418 ad_forwarded_callee,
1419 forwarded_callee_rat[1],
1420 forwarded_callee_other_sub_id)
1421 else:
1422 phone_setup_on_rat(
1423 log,
1424 ad_forwarded_callee,
1425 'general')
1426
1427 if caller_slot == 0 or caller_slot == 1:
1428 caller_phone_setup_func_argv = (log, ad_caller, caller_rat[caller_slot], caller_sub_id)
1429 else:
1430 caller_phone_setup_func_argv = (log, ad_caller, 'general')
1431
1432 callee_phone_setup_func_argv = (log, ad_callee, callee_rat[callee_slot], callee_sub_id)
1433
1434 if forwarded_callee_slot == 0 or forwarded_callee_slot == 1:
1435 forwarded_callee_phone_setup_func_argv = (
1436 log,
1437 ad_forwarded_callee,
1438 forwarded_callee_rat[forwarded_callee_slot],
1439 forwarded_callee_sub_id)
1440 else:
1441 forwarded_callee_phone_setup_func_argv = (
1442 log,
1443 ad_forwarded_callee,
1444 'general')
1445
1446 log.info("Step 3: Set up phones in desired RAT.")
1447 tasks = [(phone_setup_on_rat, caller_phone_setup_func_argv),
1448 (phone_setup_on_rat, callee_phone_setup_func_argv),
1449 (phone_setup_on_rat,
1450 forwarded_callee_phone_setup_func_argv)]
1451 if not multithread_func(log, tasks):
1452 log.error("Phone Failed to Set Up Properly.")
1453 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1454 raise signals.TestFailure("Failed",
1455 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1456
1457 is_callee_in_call = is_phone_in_call_on_rat(
1458 log, ad_callee, callee_rat[callee_slot], only_return_fn=True)
1459
1460 is_call_waiting = re.search(
1461 "call_waiting (True (\d)|False)", call_forwarding_type, re.I)
1462 if is_call_waiting:
1463 if is_call_waiting.group(1) == "False":
1464 call_waiting = False
1465 scenario = None
1466 else:
1467 call_waiting = True
1468 scenario = int(is_call_waiting.group(2))
1469
1470 log.info(
1471 "Step 4: Make voice call with call waiting enabled = %s.",
1472 call_waiting)
1473 result = three_phone_call_waiting_short_seq(
1474 log,
1475 ads[0],
1476 None,
1477 is_callee_in_call,
1478 ads[1],
1479 ads[2],
1480 call_waiting=call_waiting, scenario=scenario)
1481 else:
1482 log.info(
1483 "Step 4: Make voice call with call forwarding %s.",
1484 call_forwarding_type)
1485 result = three_phone_call_forwarding_short_seq(
1486 log,
1487 ads[0],
1488 None,
1489 is_callee_in_call,
1490 ads[1],
1491 ads[2],
1492 call_forwarding_type=call_forwarding_type)
1493
1494 if not result:
1495 if is_call_waiting:
1496 pass
1497 else:
1498 log.error(
1499 "Failed to make MO call from %s slot %s to %s slot %s"
1500 " and forward to %s slot %s",
1501 ad_caller.serial,
1502 caller_slot,
1503 ad_callee.serial,
1504 callee_slot,
1505 ad_forwarded_callee.serial,
1506 forwarded_callee_slot)
1507
1508 return result
1509
Richard Chang2243e0e2021-08-03 01:15:05 +08001510
Markus Liu481eccd2021-04-21 14:36:15 +08001511def msim_call_voice_conf(
1512 log,
1513 ads,
1514 host_slot,
1515 p1_slot,
1516 p2_slot,
1517 dds_slot,
1518 host_rat=["volte", "volte"],
1519 p1_rat="",
1520 p2_rat="",
1521 merge=True,
1522 disable_cw=False):
1523 """Make a voice conference call at specific slot in specific RAT with
1524 DDS at specific slot.
1525
1526 Test step:
1527 1. Get sub IDs of specific slots of both MO and MT devices.
1528 2. Switch DDS to specific slot.
1529 3. Check HTTP connection after DDS switch.
1530 4. Set up phones in desired RAT and make 3-way voice call.
1531 5. Swap calls.
1532 6. Merge calls.
1533
1534 Args:
1535 host_slot: Slot on the primary device to host the comference call.
1536 0 or 1 (0 for pSIM or 1 for eSIM)
1537 p1_slot: Slot on the participant device for the call
1538 p2_slot: Slot on another participant device for the call
1539 dds_slot: Preferred data slot
1540 host_rat: RAT for both slots of the primary device
1541 p1_rat: RAT for both slots of the participant device
1542 p2_rat: RAT for both slots of another participant device
1543 merge: True for merging 2 calls into the conference call. False for
1544 not merging 2 separated call.
1545 disable_cw: True for disabling call waiting and False on the
1546 contrary.
1547
1548 Returns:
Markus Liu3bedf212021-06-16 17:39:07 +08001549 True or False
Markus Liu481eccd2021-04-21 14:36:15 +08001550 """
1551 ad_host = ads[0]
1552 ad_p1 = ads[1]
1553 ad_p2 = ads[2]
1554
1555 if host_slot is not None:
1556 host_sub_id = get_subid_from_slot_index(
1557 log, ad_host, host_slot)
1558 if host_sub_id == INVALID_SUB_ID:
1559 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
1560 return False
1561 host_other_sub_id = get_subid_from_slot_index(
1562 log, ad_host, 1-host_slot)
1563 set_voice_sub_id(ad_host, host_sub_id)
1564 else:
1565 host_sub_id, _, _ = get_subid_on_same_network_of_host_ad(ads)
1566 if host_sub_id == INVALID_SUB_ID:
1567 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
1568 return False
1569 host_slot = "auto"
1570 set_voice_sub_id(ad_host, host_sub_id)
1571
1572 ad_host.log.info("Sub ID for outgoing call at slot %s: %s",
1573 host_slot, get_outgoing_voice_sub_id(ad_host))
1574
1575 if p1_slot is not None:
1576 p1_sub_id = get_subid_from_slot_index(log, ad_p1, p1_slot)
1577 if p1_sub_id == INVALID_SUB_ID:
1578 ad_p1.log.warning("Failed to get sub ID at slot %s.", p1_slot)
1579 return False
1580 set_voice_sub_id(ad_p1, p1_sub_id)
1581 else:
1582 _, p1_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1583 if p1_sub_id == INVALID_SUB_ID:
1584 ad_p1.log.warning("Failed to get sub ID at slot %s.", p1_slot)
1585 return False
1586 p1_slot = "auto"
1587 set_voice_sub_id(ad_p1, p1_sub_id)
1588 ad_p1.log.info("Sub ID for incoming call at slot %s: %s",
1589 p1_slot, get_incoming_voice_sub_id(ad_p1))
1590
1591 if p2_slot is not None:
1592 p2_sub_id = get_subid_from_slot_index(log, ad_p2, p2_slot)
1593 if p2_sub_id == INVALID_SUB_ID:
1594 ad_p2.log.warning("Failed to get sub ID at slot %s.", p2_slot)
1595 return False
1596 set_voice_sub_id(ad_p2, p2_sub_id)
1597 else:
1598 _, _, p2_sub_id = get_subid_on_same_network_of_host_ad(ads)
1599 if p2_sub_id == INVALID_SUB_ID:
1600 ad_p2.log.warning("Failed to get sub ID at slot %s.", p2_slot)
1601 return False
1602 p2_slot = "auto"
1603 set_voice_sub_id(ad_p2, p2_sub_id)
1604 ad_p2.log.info("Sub ID for incoming call at slot %s: %s",
1605 p2_slot, get_incoming_voice_sub_id(ad_p2))
1606
1607 log.info("Step 1: Switch DDS.")
Markus Liufdef3062021-06-27 15:08:29 +08001608 if not set_dds_on_slot(ads[0], dds_slot):
1609 log.error(
1610 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1611 return False
Markus Liu481eccd2021-04-21 14:36:15 +08001612
1613 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liufdef3062021-06-27 15:08:29 +08001614 if not verify_http_connection(log, ads[0]):
Markus Liu481eccd2021-04-21 14:36:15 +08001615 log.error("Failed to verify http connection.")
1616 return False
1617 else:
1618 log.info("Verify http connection successfully.")
1619
1620 if disable_cw:
1621 if not set_call_waiting(log, ad_host, enable=0):
1622 return False
1623 else:
1624 if not set_call_waiting(log, ad_host, enable=1):
1625 return False
1626
1627 if host_slot == 1:
1628 phone_setup_on_rat(
1629 log,
1630 ad_host,
1631 host_rat[0],
1632 host_other_sub_id)
1633
1634 elif host_slot == 0:
1635 phone_setup_on_rat(
1636 log,
1637 ad_host,
1638 host_rat[1],
1639 host_other_sub_id)
1640
1641 if host_slot == 0 or host_slot == 1:
1642 host_phone_setup_func_argv = (log, ad_host, host_rat[host_slot], host_sub_id)
1643 is_host_in_call = is_phone_in_call_on_rat(
1644 log, ad_host, host_rat[host_slot], only_return_fn=True)
1645 else:
1646 host_phone_setup_func_argv = (log, ad_host, 'general')
1647 is_host_in_call = is_phone_in_call_on_rat(
1648 log, ad_host, 'general', only_return_fn=True)
1649
1650 if p1_rat:
1651 p1_phone_setup_func_argv = (log, ad_p1, p1_rat, p1_sub_id)
1652 is_p1_in_call = is_phone_in_call_on_rat(
1653 log, ad_p1, p1_rat, only_return_fn=True)
1654 else:
1655 p1_phone_setup_func_argv = (log, ad_p1, 'general')
1656 is_p1_in_call = is_phone_in_call_on_rat(
1657 log, ad_p1, 'general', only_return_fn=True)
1658
1659 if p2_rat:
1660 p2_phone_setup_func_argv = (log, ad_p2, p2_rat, p2_sub_id)
1661 is_p2_in_call = is_phone_in_call_on_rat(
1662 log, ad_p2, p2_rat, only_return_fn=True)
1663 else:
1664 p2_phone_setup_func_argv = (log, ad_p2, 'general')
1665 is_p2_in_call = is_phone_in_call_on_rat(
1666 log, ad_p2, 'general', only_return_fn=True)
1667
1668 log.info("Step 3: Set up phone in desired RAT and make 3-way"
1669 " voice call.")
1670
1671 tasks = [(phone_setup_on_rat, host_phone_setup_func_argv),
1672 (phone_setup_on_rat, p1_phone_setup_func_argv),
1673 (phone_setup_on_rat, p2_phone_setup_func_argv)]
1674 if not multithread_func(log, tasks):
1675 log.error("Phone Failed to Set Up Properly.")
1676 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1677 raise signals.TestFailure("Failed",
1678 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1679
1680 call_ab_id = three_way_calling_mo_and_mt_with_hangup_once(
1681 log,
1682 [ad_host, ad_p1, ad_p2],
1683 [None, None, None], [
1684 is_host_in_call, is_p1_in_call,
1685 is_p2_in_call
1686 ])
1687
1688 if call_ab_id is None:
1689 if disable_cw:
1690 set_call_waiting(log, ad_host, enable=1)
1691 if str(getattr(ad_host, "exception", None)) == \
1692 "PhoneA call PhoneC failed.":
1693 ads[0].log.info("PhoneA failed to call PhoneC due to call"
1694 " waiting being disabled.")
1695 delattr(ad_host, "exception")
1696 return True
1697 log.error("Failed to get call_ab_id")
1698 return False
1699 else:
1700 if disable_cw:
1701 return False
1702
1703 calls = ads[0].droid.telecomCallGetCallIds()
1704 ads[0].log.info("Calls in PhoneA %s", calls)
1705 if num_active_calls(log, ads[0]) != 2:
1706 return False
1707 if calls[0] == call_ab_id:
1708 call_ac_id = calls[1]
1709 else:
1710 call_ac_id = calls[0]
1711
1712 if call_ac_id is None:
1713 log.error("Failed to get call_ac_id")
1714 return False
1715
1716 num_swaps = 2
1717 log.info("Step 4: Begin Swap x%s test.", num_swaps)
1718 if not swap_calls(log, ads, call_ab_id, call_ac_id,
1719 num_swaps):
1720 log.error("Swap test failed.")
1721 return False
1722
1723 if not merge:
1724 result = True
1725 if not hangup_call(log, ads[1]):
1726 result = False
1727 if not hangup_call(log, ads[2]):
1728 result = False
1729 return result
1730 else:
1731 log.info("Step 5: Merge calls.")
1732 if host_rat[host_slot] == "volte":
1733 return _test_ims_conference_merge_drop_second_call_from_participant(
1734 log, ads, call_ab_id, call_ac_id)
1735 else:
1736 return _test_wcdma_conference_merge_drop(
Markus Liu3bedf212021-06-16 17:39:07 +08001737 log, ads, call_ab_id, call_ac_id)
1738
Richard Chang2243e0e2021-08-03 01:15:05 +08001739
Markus Liu3bedf212021-06-16 17:39:07 +08001740def msim_volte_wfc_call_forwarding(
1741 log,
1742 ads,
1743 callee_slot,
1744 dds_slot,
1745 callee_rat=["5g_wfc", "5g_wfc"],
1746 call_forwarding_type="unconditional",
1747 is_airplane_mode=False,
1748 is_wifi_connected=False,
1749 wfc_mode=[
1750 WFC_MODE_CELLULAR_PREFERRED,
1751 WFC_MODE_CELLULAR_PREFERRED],
1752 wifi_network_ssid=None,
1753 wifi_network_pass=None):
1754 """Make VoLTE/WFC call to the primary device at specific slot with DDS
1755 at specific slot, and then forwarded to 3rd device with specific call
1756 forwarding type.
1757
1758 Test step:
1759 1. Get sub IDs of specific slots of both MO and MT devices.
1760 2. Switch DDS to specific slot.
1761 3. Check HTTP connection after DDS switch.
1762 4. Set up phones in desired RAT.
1763 5. Register and enable call forwarding with specifc type.
1764 6. Make VoLTE/WFC call to the primary device and wait for being
1765 forwarded to 3rd device.
1766
1767 Args:
1768 callee_slot: Slot of primary device receiving and forwarding MT call
1769 (0 or 1)
1770 dds_slot: Preferred data slot
1771 callee_rat: RAT for both slots of the primary device
1772 call_forwarding_type:
1773 "unconditional"
1774 "busy"
1775 "not_answered"
1776 "not_reachable"
1777 is_airplane_mode: True or False for WFC setup
1778 wfc_mode: Cellular preferred or Wi-Fi preferred.
1779 wifi_network_ssid: SSID of Wi-Fi AP
1780 wifi_network_pass: Password of Wi-Fi AP SSID
1781
1782 Returns:
1783 True or False
1784 """
1785 ad_caller = ads[1]
1786 ad_callee = ads[0]
1787 ad_forwarded_callee = ads[2]
1788
1789 if not toggle_airplane_mode(log, ad_callee, False):
1790 ad_callee.log.error("Failed to disable airplane mode.")
1791 return False
1792
1793 # Set up callee (primary device)
1794 callee_sub_id = get_subid_from_slot_index(
1795 log, ad_callee, callee_slot)
1796 if callee_sub_id == INVALID_SUB_ID:
1797 log.warning(
1798 "Failed to get sub ID at slot %s.", callee_slot)
1799 return
1800 callee_other_sub_id = get_subid_from_slot_index(
1801 log, ad_callee, 1-callee_slot)
1802 set_voice_sub_id(ad_callee, callee_sub_id)
1803 ad_callee.log.info(
1804 "Sub ID for incoming call at slot %s: %s",
1805 callee_slot, get_incoming_voice_sub_id(ad_callee))
1806
1807 # Set up caller
1808 _, caller_sub_id, _ = get_subid_on_same_network_of_host_ad(ads)
1809 if caller_sub_id == INVALID_SUB_ID:
1810 ad_caller.log.warning("Failed to get proper sub ID of the caller")
1811 return
1812 set_voice_sub_id(ad_caller, caller_sub_id)
1813 ad_caller.log.info(
1814 "Sub ID for outgoing call of the caller: %s",
1815 get_outgoing_voice_sub_id(ad_caller))
1816
1817 # Set up forwarded callee
1818 _, _, forwarded_callee_sub_id = get_subid_on_same_network_of_host_ad(
1819 ads)
1820 if forwarded_callee_sub_id == INVALID_SUB_ID:
1821 ad_forwarded_callee.log.warning(
1822 "Failed to get proper sub ID of the forwarded callee.")
1823 return
1824 set_voice_sub_id(ad_forwarded_callee, forwarded_callee_sub_id)
1825 ad_forwarded_callee.log.info(
1826 "Sub ID for incoming call of the forwarded callee: %s",
1827 get_incoming_voice_sub_id(ad_forwarded_callee))
1828
Markus Liufdef3062021-06-27 15:08:29 +08001829 log.info("Step 1: Switch DDS.")
1830 if not set_dds_on_slot(ads[0], dds_slot):
1831 log.error(
1832 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
1833 return False
Markus Liu3bedf212021-06-16 17:39:07 +08001834
Markus Liufdef3062021-06-27 15:08:29 +08001835 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liu3bedf212021-06-16 17:39:07 +08001836 if not verify_http_connection(log, ad_callee):
1837 ad_callee.log.error("Failed to verify http connection.")
1838 return False
1839 else:
1840 ad_callee.log.info("Verify http connection successfully.")
1841
1842 is_callee_in_call = is_phone_in_call_on_rat(
1843 log, ad_callee, callee_rat[callee_slot], only_return_fn=True)
1844
1845 if is_airplane_mode:
1846 set_call_forwarding_by_mmi(log, ad_callee, ad_forwarded_callee)
1847
Markus Liufdef3062021-06-27 15:08:29 +08001848 log.info("Step 3: Set up phones in desired RAT.")
Markus Liu3bedf212021-06-16 17:39:07 +08001849 if callee_slot == 1:
1850 phone_setup_on_rat(
1851 log,
1852 ad_callee,
1853 callee_rat[0],
1854 callee_other_sub_id,
1855 is_airplane_mode,
1856 wfc_mode[0],
1857 wifi_network_ssid,
1858 wifi_network_pass)
1859
1860 elif callee_slot == 0:
1861 phone_setup_on_rat(
1862 log,
1863 ad_callee,
1864 callee_rat[1],
1865 callee_other_sub_id,
1866 is_airplane_mode,
1867 wfc_mode[1],
1868 wifi_network_ssid,
1869 wifi_network_pass)
1870
1871 argv = (
1872 log,
1873 ad_callee,
1874 callee_rat[callee_slot],
1875 callee_sub_id,
1876 is_airplane_mode,
1877 wfc_mode[callee_slot],
1878 wifi_network_ssid,
1879 wifi_network_pass)
1880
1881 tasks = [(phone_setup_voice_general, (log, ad_caller)),
1882 (phone_setup_on_rat, argv),
1883 (phone_setup_voice_general, (log, ad_forwarded_callee))]
1884
1885 if not multithread_func(log, tasks):
1886 log.error("Phone Failed to Set Up Properly.")
1887 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
1888 raise signals.TestFailure("Failed",
1889 extras={"fail_reason": "Phone Failed to Set Up Properly."})
1890
1891 if is_wifi_connected:
1892 if not ensure_wifi_connected(
1893 log,
1894 ad_callee,
1895 wifi_network_ssid,
1896 wifi_network_pass,
1897 apm=is_airplane_mode):
1898 return False
1899 time.sleep(5)
1900
1901 if "wfc" not in callee_rat[callee_slot]:
1902 if not toggle_wfc_for_subscription(
1903 log,
1904 ad_callee,
1905 new_state=True,
1906 sub_id=callee_sub_id):
1907 return False
1908 if not set_wfc_mode_for_subscription(
1909 ad_callee, wfc_mode[callee_slot], sub_id=callee_sub_id):
1910 return False
1911
1912 log.info(
1913 "Step 4: Make voice call with call forwarding %s.",
1914 call_forwarding_type)
1915 result = three_phone_call_forwarding_short_seq(
1916 log,
1917 ad_callee,
1918 None,
1919 is_callee_in_call,
1920 ad_caller,
1921 ad_forwarded_callee,
1922 call_forwarding_type=call_forwarding_type)
1923
1924 if not result:
1925 log.error(
1926 "Failed to make MO call from %s to %s slot %s and forward"
1927 " to %s.",
1928 ad_caller.serial,
1929 ad_callee.serial,
1930 callee_slot,
1931 ad_forwarded_callee.serial)
1932 return result
1933
Richard Chang2243e0e2021-08-03 01:15:05 +08001934
Markus Liu3bedf212021-06-16 17:39:07 +08001935def msim_volte_wfc_call_voice_conf(
1936 log,
1937 ads,
1938 host_slot,
1939 dds_slot,
1940 host_rat=["5g_wfc", "5g_wfc"],
1941 merge=True,
1942 disable_cw=False,
1943 is_airplane_mode=False,
1944 is_wifi_connected=False,
1945 wfc_mode=[WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_CELLULAR_PREFERRED],
1946 reject_once=False,
1947 wifi_network_ssid=None,
1948 wifi_network_pass=None):
1949 """Make a VoLTE/WFC conference call at specific slot with DDS at
1950 specific slot.
1951
1952 Test step:
1953 1. Get sub IDs of specific slots of both MO and MT devices.
1954 2. Set up phones in desired RAT
1955 3. Enable VoLTE/WFC.
1956 4. Switch DDS to specific slot.
1957 5. Check HTTP connection after DDS switch.
1958 6. Make 3-way VoLTE/WFC call.
1959 7. Swap calls.
1960 8. Merge calls.
1961
1962 Args:
1963 host_slot: Slot on the primary device to host the comference call.
1964 0 or 1 (0 for pSIM or 1 for eSIM)call
1965 dds_slot: Preferred data slot
1966 host_rat: RAT for both slots of the primary devicevice
1967 merge: True for merging 2 calls into the conference call. False for
1968 not merging 2 separated call.
1969 disable_cw: True for disabling call waiting and False on the
1970 contrary.
1971 enable_volte: True for enabling and False for disabling VoLTE for
1972 each slot on the primary device
1973 enable_wfc: True for enabling and False for disabling WFC for
1974 each slot on the primary device
1975 is_airplane_mode: True or False for WFC setup
1976 wfc_mode: Cellular preferred or Wi-Fi preferred.
1977 reject_once: True for rejecting the 2nd call once from the 3rd
1978 device (Phone C) to the primary device (Phone A).
1979 wifi_network_ssid: SSID of Wi-Fi AP
1980 wifi_network_pass: Password of Wi-Fi AP SSID
1981
1982 Returns:
1983 True or False
1984 """
1985 ad_host = ads[0]
1986 ad_p1 = ads[1]
1987 ad_p2 = ads[2]
1988
1989 host_sub_id = get_subid_from_slot_index(log, ad_host, host_slot)
1990 if host_sub_id == INVALID_SUB_ID:
1991 ad_host.log.warning("Failed to get sub ID at slot.", host_slot)
1992 return
1993 host_other_sub_id = get_subid_from_slot_index(
1994 log, ad_host, 1-host_slot)
1995 set_voice_sub_id(ad_host, host_sub_id)
1996 ad_host.log.info(
1997 "Sub ID for outgoing call at slot %s: %s",
1998 host_slot, get_outgoing_voice_sub_id(ad_host))
1999
2000 _, p1_sub_id, p2_sub_id = get_subid_on_same_network_of_host_ad(ads)
2001
2002 if p1_sub_id == INVALID_SUB_ID:
2003 ad_p1.log.warning("Failed to get proper sub ID.")
2004 return
2005 set_voice_sub_id(ad_p1, p1_sub_id)
2006 ad_p1.log.info(
2007 "Sub ID for incoming call: %s",
2008 get_incoming_voice_sub_id(ad_p1))
2009
2010 if p2_sub_id == INVALID_SUB_ID:
2011 ad_p2.log.warning("Failed to get proper sub ID.")
2012 return
2013 set_voice_sub_id(ad_p2, p2_sub_id)
2014 ad_p2.log.info(
2015 "Sub ID for incoming call: %s", get_incoming_voice_sub_id(ad_p2))
2016
Markus Liufdef3062021-06-27 15:08:29 +08002017 log.info("Step 1: Switch DDS.")
2018 if not set_dds_on_slot(ads[0], dds_slot):
2019 log.error(
2020 "Failed to set DDS at slot %s on %s",(dds_slot, ads[0].serial))
2021 return False
Markus Liu3bedf212021-06-16 17:39:07 +08002022
Markus Liufdef3062021-06-27 15:08:29 +08002023 log.info("Step 2: Check HTTP connection after DDS switch.")
Markus Liu3bedf212021-06-16 17:39:07 +08002024 if not verify_http_connection(log, ads[0]):
2025 ad_host.log.error("Failed to verify http connection.")
2026 return False
2027 else:
2028 ad_host.log.info("Verify http connection successfully.")
2029
2030 if disable_cw:
2031 if not set_call_waiting(log, ad_host, enable=0):
2032 return False
2033
Markus Liufdef3062021-06-27 15:08:29 +08002034 log.info("Step 3: Set up phones in desired RAT.")
Markus Liu3bedf212021-06-16 17:39:07 +08002035 if host_slot == 1:
2036 phone_setup_on_rat(
2037 log,
2038 ad_host,
2039 host_rat[0],
2040 host_other_sub_id,
2041 is_airplane_mode,
2042 wfc_mode[0],
2043 wifi_network_ssid,
2044 wifi_network_pass)
2045
2046 elif host_slot == 0:
2047 phone_setup_on_rat(
2048 log,
2049 ad_host,
2050 host_rat[1],
2051 host_other_sub_id,
2052 is_airplane_mode,
2053 wfc_mode[1],
2054 wifi_network_ssid,
2055 wifi_network_pass)
2056
2057 argv = (
2058 log,
2059 ad_host,
2060 host_rat[host_slot],
2061 host_sub_id,
2062 is_airplane_mode,
2063 wfc_mode[host_slot],
2064 wifi_network_ssid,
2065 wifi_network_pass)
2066
2067 tasks = [(phone_setup_voice_general, (log, ad_p1)),
2068 (phone_setup_on_rat, argv),
2069 (phone_setup_voice_general, (log, ad_p2))]
2070
2071 if not multithread_func(log, tasks):
2072 log.error("Phone Failed to Set Up Properly.")
2073 tel_logger.set_result(CallResult("CALL_SETUP_FAILURE"))
2074 raise signals.TestFailure("Failed",
2075 extras={"fail_reason": "Phone Failed to Set Up Properly."})
2076
2077 if is_wifi_connected:
2078 if not ensure_wifi_connected(
2079 log,
2080 ad_host,
2081 wifi_network_ssid,
2082 wifi_network_pass,
2083 apm=is_airplane_mode):
2084 return False
2085 time.sleep(5)
2086
2087 if "wfc" not in host_rat[host_slot]:
2088 if not toggle_wfc_for_subscription(
2089 log,
2090 ad_host,
2091 new_state=True,
2092 sub_id=host_sub_id):
2093 return False
2094 if not set_wfc_mode_for_subscription(
2095 ad_host, wfc_mode[host_slot], sub_id=host_sub_id):
2096 return False
2097
2098 log.info("Step 4: Make 3-way voice call.")
2099 is_host_in_call = is_phone_in_call_on_rat(
2100 log, ad_host, host_rat[host_slot], only_return_fn=True)
2101 call_ab_id = _three_phone_call_mo_add_mt(
2102 log,
2103 [ad_host, ad_p1, ad_p2],
2104 [None, None, None],
2105 [is_host_in_call, None, None],
2106 reject_once=reject_once)
2107
2108 if call_ab_id is None:
2109 if disable_cw:
2110 set_call_waiting(log, ad_host, enable=1)
2111 if str(getattr(ad_host, "exception", None)) == \
2112 "PhoneA call PhoneC failed.":
2113 ads[0].log.info("PhoneA failed to call PhoneC due to call"
2114 " waiting being disabled.")
2115 delattr(ad_host, "exception")
2116 return True
2117 log.error("Failed to get call_ab_id")
2118 return False
2119 else:
2120 if disable_cw:
2121 set_call_waiting(log, ad_host, enable=0)
2122 return False
2123
2124 calls = ads[0].droid.telecomCallGetCallIds()
2125 ads[0].log.info("Calls in PhoneA %s", calls)
2126 if num_active_calls(log, ads[0]) != 2:
2127 return False
2128 if calls[0] == call_ab_id:
2129 call_ac_id = calls[1]
2130 else:
2131 call_ac_id = calls[0]
2132
2133 if call_ac_id is None:
2134 log.error("Failed to get call_ac_id")
2135 return False
2136
2137 num_swaps = 2
Markus Liufdef3062021-06-27 15:08:29 +08002138 log.info("Step 5: Begin Swap x%s test.", num_swaps)
Markus Liu3bedf212021-06-16 17:39:07 +08002139 if not swap_calls(log, ads, call_ab_id, call_ac_id,
2140 num_swaps):
2141 ad_host.log.error("Swap test failed.")
2142 return False
2143
2144 if not merge:
2145 result = True
2146 if not hangup_call(log, ads[1]):
2147 result = False
2148 if not hangup_call(log, ads[2]):
2149 result = False
2150 return result
2151 else:
Markus Liufdef3062021-06-27 15:08:29 +08002152 log.info("Step 6: Merge calls.")
Markus Liu3bedf212021-06-16 17:39:07 +08002153
2154 if re.search('csfb|2g|3g', host_rat[host_slot].lower(), re.I):
2155 return _test_wcdma_conference_merge_drop(
2156 log, ads, call_ab_id, call_ac_id)
2157 else:
2158 return _test_ims_conference_merge_drop_second_call_from_participant(
Markus Liu481eccd2021-04-21 14:36:15 +08002159 log, ads, call_ab_id, call_ac_id)