1#!/usr/bin/env python3 2# 3# Copyright 2016 - The Android Open Source Project 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""" 17Sanity tests for voice tests in telephony 18""" 19 20from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError 21from acts.controllers.anritsu_lib.md8475a import MD8475A 22from acts.controllers.anritsu_lib.md8475a import CBCHSetup 23from acts.controllers.anritsu_lib.md8475a import CTCHSetup 24from acts_contrib.test_utils.tel.anritsu_utils import ETWS_WARNING_EARTHQUAKETSUNAMI 25from acts_contrib.test_utils.tel.anritsu_utils import ETWS_WARNING_OTHER_EMERGENCY 26from acts_contrib.test_utils.tel.anritsu_utils import cb_serial_number 27from acts_contrib.test_utils.tel.anritsu_utils import etws_receive_verify_message_lte_wcdma 28from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_gsm 29from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte 30from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_wcdma 31from acts_contrib.test_utils.tel.anritsu_utils import set_usim_parameters 32from acts_contrib.test_utils.tel.anritsu_utils import set_post_sim_params 33from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_CDMA 34from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY 35from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS 36from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA 37from acts_contrib.test_utils.tel.tel_defines import RAT_1XRTT 38from acts_contrib.test_utils.tel.tel_defines import RAT_GSM 39from acts_contrib.test_utils.tel.tel_defines import RAT_LTE 40from acts_contrib.test_utils.tel.tel_defines import RAT_WCDMA 41from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000 42from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_GSM 43from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_LTE 44from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_UMTS 45from acts_contrib.test_utils.tel.tel_logging_utils import start_qxdm_loggers 46from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_rat 47from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_idle 48from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode 49from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 50from acts.test_decorators import test_tracker_info 51 52WAIT_TIME_BETWEEN_REG_AND_MSG = 15 # default 15 sec 53 54 55class TelLabEtwsTest(TelephonyBaseTest): 56 SERIAL_NO = cb_serial_number() 57 58 def setup_class(self): 59 super().setup_class() 60 self.ad = self.android_devices[0] 61 self.ad.sim_card = getattr(self.ad, "sim_card", None) 62 self.md8475a_ip_address = self.user_params[ 63 "anritsu_md8475a_ip_address"] 64 self.wlan_option = self.user_params.get("anritsu_wlan_option", False) 65 self.md8475_version = self.user_params.get("md8475", "A") 66 self.ad.adb.shell("settings put secure cmas_additional_broadcast_pkg " 67 "com.googlecode.android_scripting") 68 self.wait_time_between_reg_and_msg = self.user_params.get( 69 "wait_time_between_reg_and_msg", WAIT_TIME_BETWEEN_REG_AND_MSG) 70 71 try: 72 self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option, 73 self.md8475_version) 74 except AnritsuError: 75 self.log.error("Error in connecting to Anritsu Simulator") 76 return False 77 return True 78 79 def setup_test(self): 80 if getattr(self, "qxdm_log", True): 81 start_qxdm_loggers(self.log, self.android_devices) 82 ensure_phones_idle(self.log, self.android_devices) 83 toggle_airplane_mode(self.log, self.ad, True) 84 return True 85 86 def teardown_test(self): 87 self.log.info("Stopping Simulation") 88 self.anritsu.stop_simulation() 89 toggle_airplane_mode(self.log, self.ad, True) 90 91 def teardown_class(self): 92 self.anritsu.disconnect() 93 return True 94 95 def _send_receive_etws_message(self, set_simulation_func, rat, message_id, 96 warning_message): 97 try: 98 [self.bts1] = set_simulation_func(self.anritsu, self.user_params, 99 self.ad.sim_card) 100 set_usim_parameters(self.anritsu, self.ad.sim_card) 101 if rat == RAT_LTE: 102 set_post_sim_params(self.anritsu, self.user_params, 103 self.ad.sim_card) 104 self.anritsu.start_simulation() 105 106 if rat == RAT_LTE: 107 preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA 108 rat_family = RAT_FAMILY_LTE 109 elif rat == RAT_WCDMA: 110 self.bts1.wcdma_ctch = CTCHSetup.CTCH_ENABLE 111 self.ad.droid.telephonyToggleDataConnection(False) 112 preferred_network_setting = NETWORK_MODE_GSM_UMTS 113 rat_family = RAT_FAMILY_UMTS 114 elif rat == RAT_GSM: 115 self.bts1.gsm_cbch = CBCHSetup.CBCH_ENABLE 116 self.ad.droid.telephonyToggleDataConnection(False) 117 preferred_network_setting = NETWORK_MODE_GSM_ONLY 118 rat_family = RAT_FAMILY_GSM 119 elif rat == RAT_1XRTT: 120 preferred_network_setting = NETWORK_MODE_CDMA 121 rat_family = RAT_FAMILY_CDMA2000 122 else: 123 self.log.error("No valid RAT provided for ETWS test.") 124 return False 125 126 if not ensure_network_rat(self.log, 127 self.ad, 128 preferred_network_setting, 129 rat_family, 130 toggle_apm_after_setting=True): 131 self.log.error( 132 "Failed to set rat family {}, preferred network:{}".format( 133 rat_family, preferred_network_setting)) 134 return False 135 136 self.anritsu.wait_for_registration_state() 137 if not etws_receive_verify_message_lte_wcdma( 138 self.log, self.ad, self.anritsu, 139 next(TelLabEtwsTest.SERIAL_NO), message_id, 140 warning_message): 141 self.log.error( 142 "Phone {} Failed to receive ETWS message".format( 143 self.ad.serial)) 144 return False 145 except AnritsuError as e: 146 self.log.error("Error in connection with Anritsu Simulator: " + 147 str(e)) 148 return False 149 except Exception as e: 150 self.log.error("Exception during ETWS send/receive: " + str(e)) 151 return False 152 return True 153 154 def test_carrier_tmobile(self): 155 """ Sets the Carrier to TMO. 156 Returns: None 157 """ 158 setattr(self.ad, "sim_card", "FiTMO") 159 160 def test_carrier_sprint(self): 161 """ Sets the Carrier to SPR. 162 Returns: None 163 """ 164 setattr(self.ad, "sim_card", "FiSPR") 165 166 def test_carrier_uscc(self): 167 """ Sets the Carrier to USCC. 168 Returns: None 169 """ 170 setattr(self.ad, "sim_card", "FiUSCC") 171 172 """ Tests Begin """ 173 174 @test_tracker_info(uuid="af4a00d0-9a91-45d5-9f65-9541e64a57f2") 175 @TelephonyBaseTest.tel_test_wrap 176 def test_etws_earthquake_tsunami_lte(self): 177 """ETWS Earthquake and Tsunami warning message reception on LTE 178 179 Tests the capability of device to receive and inform the user 180 about the ETWS Earthquake and Tsunami warning message when camped on 181 LTE newtork 182 183 Steps: 184 1. Make Sure Phone is camped on LTE network 185 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 186 187 Expected Result: 188 Phone receives ETWS Earthquake and Tsunami warning message 189 190 Returns: 191 True if pass; False if fail 192 """ 193 return self._send_receive_etws_message(set_system_model_lte, RAT_LTE, 194 ETWS_WARNING_EARTHQUAKETSUNAMI, 195 "LTE Earthquake and Tsunami") 196 197 @test_tracker_info(uuid="03785878-0319-413c-9190-d4e08f0edc33") 198 @TelephonyBaseTest.tel_test_wrap 199 def test_etws_other_emergency_lte(self): 200 """ETWS Other emergency warning message reception on LTE 201 202 Tests the capability of device to receive and inform the user 203 about the ETWS Other emergency warning message when camped on 204 LTE newtork 205 206 Steps: 207 1. Make Sure Phone is camped on LTE network 208 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 209 210 Expected Result: 211 Phone receives ETWS Earthquake and Tsunami warning message 212 213 Returns: 214 True if pass; False if fail 215 """ 216 return self._send_receive_etws_message(set_system_model_lte, RAT_LTE, 217 ETWS_WARNING_OTHER_EMERGENCY, 218 "LTE ETWS Other Emergency") 219 220 @test_tracker_info(uuid="1ef4a5d7-9ceb-49eb-8ec7-5538625c8bd4") 221 @TelephonyBaseTest.tel_test_wrap 222 def test_etws_earthquake_tsunami_wcdma(self): 223 """ETWS Earthquake and Tsunami warning message reception on WCDMA 224 225 Tests the capability of device to receive and inform the user 226 about the ETWS Earthquake and Tsunami warning message when camped on 227 WCDMA newtork 228 229 Steps: 230 1. Make Sure Phone is camped on WCDMA network 231 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 232 233 Expected Result: 234 Phone receives ETWS Earthquake and Tsunami warning message 235 236 Returns: 237 True if pass; False if fail 238 """ 239 return self._send_receive_etws_message(set_system_model_wcdma, 240 RAT_WCDMA, 241 ETWS_WARNING_EARTHQUAKETSUNAMI, 242 "WCDMA Earthquake and Tsunami") 243 244 @test_tracker_info(uuid="71dc9650-d00a-4533-99f5-5cc301c21334") 245 @TelephonyBaseTest.tel_test_wrap 246 def test_etws_other_emergency_wcdma(self): 247 """ETWS Other emergency warning message reception on WCDMA 248 249 Tests the capability of device to receive and inform the user 250 about the ETWS Other emergency warning message when camped on 251 WCDMA newtork 252 253 Steps: 254 1. Make Sure Phone is camped on WCDMA network 255 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 256 257 Expected Result: 258 Phone receives ETWS Earthquake and Tsunami warning message 259 260 Returns: 261 True if pass; False if fail 262 """ 263 return self._send_receive_etws_message(set_system_model_wcdma, 264 RAT_WCDMA, 265 ETWS_WARNING_OTHER_EMERGENCY, 266 "WCDMA ETWS Other Emergency") 267 268 @test_tracker_info(uuid="a9fd9c0e-21bf-41d1-81d2-c34679052fe0") 269 @TelephonyBaseTest.tel_test_wrap 270 def test_etws_earthquake_tsunami_gsm(self): 271 """ETWS Earthquake and Tsunami warning message reception on GSM 272 273 Tests the capability of device to receive and inform the user 274 about the ETWS Earthquake and Tsunami warning message when camped on 275 GSM newtork 276 277 Steps: 278 1. Make Sure Phone is camped on GSM network 279 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 280 281 Expected Result: 282 Phone receives ETWS Earthquake and Tsunami warning message 283 284 Returns: 285 True if pass; False if fail 286 """ 287 return self._send_receive_etws_message(set_system_model_gsm, RAT_GSM, 288 ETWS_WARNING_EARTHQUAKETSUNAMI, 289 "GSM Earthquake and Tsunami") 290 291 @test_tracker_info(uuid="0ae42f8d-1720-449c-9200-e88f7f1d2cbe") 292 @TelephonyBaseTest.tel_test_wrap 293 def test_etws_other_emergency_gsm(self): 294 """ETWS Other emergency warning message reception on GSM 295 296 Tests the capability of device to receive and inform the user 297 about the ETWS Other emergency warning message when camped on 298 GSM newtork 299 300 Steps: 301 1. Make Sure Phone is camped on GSM network 302 2. Send ETWS Earthquake and Tsunami warning message from Anritsu 303 304 Expected Result: 305 Phone receives ETWS Earthquake and Tsunami warning message 306 307 Returns: 308 True if pass; False if fail 309 """ 310 return self._send_receive_etws_message(set_system_model_gsm, RAT_GSM, 311 ETWS_WARNING_OTHER_EMERGENCY, 312 "GSM ETWS Other Emergency") 313 314 """ Tests End """ 315