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