blob: d5d6f7659fca83012a6319096a1169aaa493165a [file] [log] [blame]
Jaineel388ca742020-11-24 15:10:31 -08001#!/usr/bin/env python3
2#
3# Copyright 2020 - Google
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import time
18import random
19import re
20
Jaineel Mehta23590712020-12-24 00:49:54 +000021from queue import Empty
Jaineel388ca742020-11-24 15:10:31 -080022from acts.utils import rand_ascii_str
23from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_NR_LTE_GSM_WCDMA
24from acts_contrib.test_utils.tel.tel_defines import OverrideNetworkContainer
25from acts_contrib.test_utils.tel.tel_defines import DisplayInfoContainer
26from acts_contrib.test_utils.tel.tel_defines import EventDisplayInfoChanged
Jaineel78a57152020-12-08 17:03:00 -080027from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
28from acts_contrib.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
Jaineel388ca742020-11-24 15:10:31 -080029from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_network_mode_pref
30from acts_contrib.test_utils.tel.tel_test_utils import is_event_match
Jaineel78a57152020-12-08 17:03:00 -080031from acts_contrib.test_utils.tel.tel_test_utils import multithread_func
32from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected
33from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
34from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_volte
35from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_iwlan
Pei Huang47d6a0b2021-04-05 23:35:49 +080036from acts_contrib.test_utils.tel.tel_voice_utils import phone_setup_csfb
Jaineel388ca742020-11-24 15:10:31 -080037
38
39def is_current_network_5g_nsa(ad, timeout=30):
40 """Verifies 5G NSA override network type
41
42 Args:
43 ad: android device object.
44 timeout: max time to wait for event
45
46 Returns:
47 True: if data is on nsa5g NSA
48 False: if data is not on nsa5g NSA
49 """
50 ad.ed.clear_events(EventDisplayInfoChanged)
51 ad.droid.telephonyStartTrackingDisplayInfoChange()
52 try:
53 event = ad.ed.wait_for_event(
54 EventDisplayInfoChanged,
55 is_event_match,
56 timeout=timeout,
57 field=DisplayInfoContainer.OVERRIDE,
58 value=OverrideNetworkContainer.OVERRIDE_NETWORK_TYPE_NR_NSA)
59 ad.log.info("Got expected event %s", event)
60 return True
61 except Empty:
62 ad.log.info("No event for display info change")
63 return False
64 finally:
65 ad.droid.telephonyStopTrackingDisplayInfoChange()
66 return None
67
68
Pratik Shethaec72b72021-02-09 15:44:28 -080069def provision_device_for_5g(log, ad):
70 # Mode Pref
71 set_preferred_mode_for_5g(ad)
72
73 # Attach nsa5g
74 if not is_current_network_5g_nsa(ad):
75 ad.log.error("Phone not attached on nsa 5g")
76 return False
77 return True
78
Jaineel78a57152020-12-08 17:03:00 -080079def provision_both_devices_for_5g(log, ads):
80 # Mode Pref
81 tasks = [(set_preferred_mode_for_5g, [ad]) for ad in ads]
82 if not multithread_func(log, tasks):
83 log.error("failed to set preferred network mode on 5g")
84 return False
85 # Attach
86 tasks = [(is_current_network_5g_nsa, [ad]) for ad in ads]
87 if not multithread_func(log, tasks):
88 log.error("phone not on 5g nsa")
89 return False
90 return True
91
92
93def provision_both_devices_for_volte(log, ads):
94 # LTE attach and enable VoLTE on both phones
95 tasks = [(phone_setup_volte, (log, ads[0])),
96 (phone_setup_volte, (log, ads[1]))]
97 if not multithread_func(log, tasks):
98 log.error("phone failed to set up in volte")
99 return False
100 return True
101
102
Pei Huang47d6a0b2021-04-05 23:35:49 +0800103def provision_both_devices_for_csfb(log, ads):
104 tasks = [(phone_setup_csfb, (log, ads[0])),
105 (phone_setup_csfb, (log, ads[1]))]
106 if not multithread_func(log, tasks):
107 log.error("Phone Failed to Set Up in csfb.")
108 return False
109 return True
110
111
Jaineel78a57152020-12-08 17:03:00 -0800112def verify_5g_attach_for_both_devices(log, ads):
113 # Attach
114 tasks = [(is_current_network_5g_nsa, [ad]) for ad in ads]
115 if not multithread_func(log, tasks):
116 log.error("phone not on 5g nsa")
117 return False
118 return True
119
120
121def provision_both_devices_for_wfc_cell_pref(log,
122 ads,
123 wifi_ssid,
124 wifi_pass,
125 apm_mode=False):
126 tasks = [(phone_setup_iwlan,
127 (log, ads[0], apm_mode, WFC_MODE_CELLULAR_PREFERRED,
128 wifi_ssid, wifi_pass)),
129 (phone_setup_iwlan,
130 (log, ads[1], apm_mode, WFC_MODE_CELLULAR_PREFERRED,
131 wifi_ssid, wifi_pass))]
132 if not multithread_func(log, tasks):
133 log.error("failed to setup in wfc_cell_pref mode")
134 return False
135 return True
136
137
138def provision_both_devices_for_wfc_wifi_pref(log,
139 ads,
140 wifi_ssid,
141 wifi_pass,
142 apm_mode=False):
143 tasks = [(phone_setup_iwlan,
144 (log, ads[0], apm_mode, WFC_MODE_WIFI_PREFERRED,
145 wifi_ssid, wifi_pass)),
146 (phone_setup_iwlan,
147 (log, ads[1], apm_mode, WFC_MODE_WIFI_PREFERRED,
148 wifi_ssid, wifi_pass))]
149 if not multithread_func(log, tasks):
150 log.error("failed to setup in wfc_wifi_pref mode")
151 return False
152 return True
153
154
155def disable_apm_mode_both_devices(log, ads):
156 # Turn off airplane mode
157 log.info("Turn off apm mode on both devices")
158 tasks = [(toggle_airplane_mode, (log, ads[0], False)),
159 (toggle_airplane_mode, (log, ads[1], False))]
160 if not multithread_func(log, tasks):
161 log.error("Failed to turn off airplane mode")
162 return False
163 return True
164
165
166def connect_both_devices_to_wifi(log,
167 ads,
168 wifi_ssid,
169 wifi_pass):
170 tasks = [(ensure_wifi_connected, (log, ad, wifi_ssid, wifi_pass))
171 for ad in ads]
172 if not multithread_func(log, tasks):
173 log.error("phone failed to connect to wifi.")
174 return False
175 return True
176
177
Jaineel388ca742020-11-24 15:10:31 -0800178def set_preferred_mode_for_5g(ad, sub_id=None, mode=None):
179 """Set Preferred Network Mode for 5G NSA
180 Args:
181 ad: Android device object.
182 sub_id: Subscription ID.
183 mode: 5G Network Mode Type
184 """
185 if sub_id is None:
186 sub_id = ad.droid.subscriptionGetDefaultSubId()
187 if mode is None:
188 mode = NETWORK_MODE_NR_LTE_GSM_WCDMA
Pei Huang1c8f8522020-12-21 19:39:20 +0800189 return set_preferred_network_mode_pref(ad.log, ad, sub_id, mode)
190
191
Pei Huang1c8f8522020-12-21 19:39:20 +0800192
Pei Huang1c8f8522020-12-21 19:39:20 +0800193