1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - 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"""
17    Test Script for epdg RF shield box related tests.
18"""
19
20import time
21from acts.test_decorators import test_tracker_info
22from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_atten_utils import set_rssi
24from acts.test_utils.tel.tel_defines import CELL_WEAK_RSSI_VALUE
25from acts.test_utils.tel.tel_defines import INVALID_WIFI_RSSI
26from acts.test_utils.tel.tel_defines import MAX_RSSI_RESERVED_VALUE
27from acts.test_utils.tel.tel_defines import MIN_RSSI_RESERVED_VALUE
28from acts.test_utils.tel.tel_defines import WAIT_TIME_WIFI_RSSI_CALIBRATION_SCREEN_ON
29from acts.test_utils.tel.tel_defines import WAIT_TIME_WIFI_RSSI_CALIBRATION_WIFI_CONNECTED
30from acts.test_utils.tel.tel_defines import WFC_MODE_CELLULAR_PREFERRED
31from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
32from acts.test_utils.tel.tel_defines import WIFI_WEAK_RSSI_VALUE
33from acts.test_utils.tel.tel_defines import SignalStrengthContainer
34from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
35from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
36from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
37from acts.test_utils.tel.tel_test_utils import set_wfc_mode
38from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
39from acts.test_utils.tel.tel_test_utils import verify_internet_connection
40from TelLiveConnectivityMonitorBaseTest import TelLiveConnectivityMonitorBaseTest
41
42# Attenuator name
43ATTEN_NAME_FOR_WIFI_2G = 'wifi0'
44ATTEN_NAME_FOR_WIFI_5G = 'wifi1'
45ATTEN_NAME_FOR_CELL_3G = 'cell0'
46ATTEN_NAME_FOR_CELL_4G = 'cell1'
47
48# WiFi RSSI settings for ROVE_IN test
49WIFI_RSSI_FOR_ROVE_IN_TEST_PHONE_ROVE_IN = -60
50WIFI_RSSI_FOR_ROVE_IN_TEST_PHONE_NOT_ROVE_IN = -70
51
52# WiFi RSSI settings for ROVE_OUT test
53WIFI_RSSI_FOR_ROVE_OUT_TEST_PHONE_INITIAL_STATE = -60
54WIFI_RSSI_FOR_ROVE_OUT_TEST_PHONE_NOT_ROVE_OUT = -70
55WIFI_RSSI_FOR_ROVE_OUT_TEST_PHONE_ROVE_OUT = -90
56
57# WiFi RSSI settings for HAND_IN test
58WIFI_RSSI_FOR_HAND_IN_TEST_PHONE_NOT_HAND_IN = -80
59WIFI_RSSI_FOR_HAND_IN_TEST_PHONE_HAND_IN = -50
60
61# WiFi RSSI settings for HAND_OUT test
62WIFI_RSSI_FOR_HAND_OUT_TEST_PHONE_NOT_HAND_OUT = -60
63WIFI_RSSI_FOR_HAND_OUT_TEST_PHONE_HAND_OUT = -85
64
65CS_LINK_LOST = "Radio Link Lost"
66IMS_LINK_LOST = "Media Timeout"
67
68
69class TelLiveConnectivityMonitorMobilityTest(
70        TelLiveConnectivityMonitorBaseTest):
71    def setup_class(self):
72        TelLiveConnectivityMonitorBaseTest.setup_class(self)
73
74        self.attens = {}
75        for atten in self.attenuators:
76            self.attens[atten.path] = atten
77            atten.set_atten(atten.get_max_atten())  # Default all attens to max
78
79
80        # Do WiFi RSSI calibration.
81        self.set_wifi_strong_cell_strong()
82
83        if not ensure_phone_subscription(self.log, self.dut):
84            self.dut.log.error("Failed to find valid subscription")
85            return False
86        if not ensure_wifi_connected(self.log, self.dut,
87                                     self.wifi_network_ssid,
88                                     self.wifi_network_pass):
89            self.dut.log.error("Fail to connect to WiFI")
90            return False
91        if (not wait_for_wifi_data_connection(self.log, self.dut, True)
92                or not verify_internet_connection(self.log, self.dut)):
93            self.dut.log.error("No Data on Wifi")
94            return False
95
96        # Delay WAIT_TIME_WIFI_RSSI_CALIBRATION_WIFI_CONNECTED after WiFi
97        # Connected to make sure WiFi RSSI reported value is correct.
98        time.sleep(WAIT_TIME_WIFI_RSSI_CALIBRATION_WIFI_CONNECTED)
99        # Turn On Screen and delay WAIT_TIME_WIFI_RSSI_CALIBRATION_SCREEN_ON
100        # then get WiFi RSSI to avoid WiFi RSSI report -127(invalid value).
101        self.dut.droid.wakeUpNow()
102        time.sleep(WAIT_TIME_WIFI_RSSI_CALIBRATION_SCREEN_ON)
103
104        setattr(self, "wifi_rssi_with_no_atten",
105                self.dut.droid.wifiGetConnectionInfo()['rssi'])
106        if self.wifi_rssi_with_no_atten == INVALID_WIFI_RSSI:
107            self.dut.log.error(
108                "Initial WiFi RSSI calibration value is wrong: -127.")
109            return False
110        self.dut.log.info("WiFi RSSI calibration info: atten=0, RSSI=%s",
111                          self.wifi_rssi_with_no_atten)
112        ensure_phones_default_state(self.log, [self.dut])
113
114        # Do Cellular RSSI calibration.
115        setattr(self, "cell_rssi_with_no_atten",
116                self.dut.droid.telephonyGetSignalStrength()[
117                    SignalStrengthContainer.SIGNAL_STRENGTH_LTE_DBM])
118        self.dut.log.info("Cellular RSSI calibration info: atten=0, RSSI=%s",
119                          self.cell_rssi_with_no_atten)
120        return True
121
122    def teardown_class(self):
123        self.dut.droid.telephonyStopTrackingSignalStrengthChange()
124        super().teardown_class()
125        return True
126
127    def setup_test(self):
128        super().setup_test()
129        self.set_wifi_strong_cell_strong()
130        return True
131
132    def teardown_test(self):
133        super().teardown_test()
134        self.set_wifi_strong_cell_strong()
135        return True
136
137    def set_wifi_strong_cell_strong(self):
138        self.log.info("--->Setting WiFi strong cell strong<---")
139        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
140                 MAX_RSSI_RESERVED_VALUE)
141        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
142                 MAX_RSSI_RESERVED_VALUE)
143        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
144                 MAX_RSSI_RESERVED_VALUE)
145        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
146                 MAX_RSSI_RESERVED_VALUE)
147        return True
148
149    def set_wifi_strong_cell_weak(self):
150        self.log.info("--->Setting WiFi strong cell weak<---")
151        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
152                 MAX_RSSI_RESERVED_VALUE)
153        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
154                 MAX_RSSI_RESERVED_VALUE)
155        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G],
156                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
157        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G],
158                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
159        return True
160
161    def set_wifi_strong_cell_absent(self):
162        self.log.info("--->Setting WiFi strong cell absent<---")
163        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
164                 MAX_RSSI_RESERVED_VALUE)
165        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
166                 MAX_RSSI_RESERVED_VALUE)
167        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
168                 MIN_RSSI_RESERVED_VALUE)
169        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
170                 MIN_RSSI_RESERVED_VALUE)
171        return True
172
173    def set_wifi_weak_cell_strong(self):
174        self.log.info("--->Setting WiFi weak cell strong<---")
175        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G],
176                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
177        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G],
178                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
179        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
180                 MAX_RSSI_RESERVED_VALUE)
181        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
182                 MAX_RSSI_RESERVED_VALUE)
183        return True
184
185    def set_wifi_weak_cell_weak(self):
186        self.log.info("--->Setting WiFi weak cell weak<---")
187        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G],
188                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
189        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G],
190                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
191        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G],
192                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
193        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G],
194                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
195        return True
196
197    def set_wifi_weak_cell_absent(self):
198        self.log.info("--->Setting WiFi weak cell absent<---")
199        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G],
200                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
201        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G],
202                 self.wifi_rssi_with_no_atten, WIFI_WEAK_RSSI_VALUE)
203        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
204                 MIN_RSSI_RESERVED_VALUE)
205        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
206                 MIN_RSSI_RESERVED_VALUE)
207        return True
208
209    def set_wifi_absent_cell_strong(self):
210        self.log.info("--->Setting WiFi absent cell strong<---")
211        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
212                 MIN_RSSI_RESERVED_VALUE)
213        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
214                 MIN_RSSI_RESERVED_VALUE)
215        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
216                 MAX_RSSI_RESERVED_VALUE)
217        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
218                 MAX_RSSI_RESERVED_VALUE)
219        return True
220
221    def set_wifi_absent_cell_weak(self):
222        self.log.info("--->Setting WiFi absent cell weak<---")
223        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
224                 MIN_RSSI_RESERVED_VALUE)
225        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
226                 MIN_RSSI_RESERVED_VALUE)
227        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G],
228                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
229        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G],
230                 self.cell_rssi_with_no_atten, CELL_WEAK_RSSI_VALUE)
231        return True
232
233    def set_wifi_absent_cell_absent(self):
234        self.log.info("--->Setting WiFi absent cell absent<---")
235        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
236                 MIN_RSSI_RESERVED_VALUE)
237        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
238                 MIN_RSSI_RESERVED_VALUE)
239        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
240                 MIN_RSSI_RESERVED_VALUE)
241        set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
242                 MIN_RSSI_RESERVED_VALUE)
243        return True
244
245    """ Tests Begin """
246
247    @test_tracker_info(uuid="d474725b-c34d-4686-8b5f-c0d4733a0cc1")
248    @TelephonyBaseTest.tel_test_wrap
249    def test_volte_call_drop_by_poor_signals(self):
250        return self.forced_call_drop_test(
251            setup="volte",
252            triggers=[
253                "set_wifi_absent_cell_absent", "set_wifi_strong_cell_strong"
254            ],
255            expected_drop_reason=IMS_LINK_LOST)
256
257    @test_tracker_info(uuid="7f62f1c0-6d9e-4e7e-812f-b1c60d2f4b41")
258    @TelephonyBaseTest.tel_test_wrap
259    def test_csfb_call_drop_by_poor_signals(self):
260        return self.forced_call_drop_test(
261            setup="csfb",
262            triggers=[
263                "set_wifi_absent_cell_absent", "set_wifi_strong_cell_strong"
264            ],
265            expected_drop_reason=CS_LINK_LOST)
266
267    @test_tracker_info(uuid="8d1c8c44-be54-43ec-892c-c3f41855c7c8")
268    @TelephonyBaseTest.tel_test_wrap
269    def test_3g_call_drop_by_poor_signal(self):
270        return self.forced_call_drop_test(
271            setup="3g",
272            triggers=[
273                "set_wifi_absent_cell_absent", "set_wifi_strong_cell_strong"
274            ],
275            expected_drop_reason=CS_LINK_LOST)
276
277    @test_tracker_info(uuid="66e01cb3-3bea-4d08-9ab4-7f22790c57b1")
278    @TelephonyBaseTest.tel_test_wrap
279    def test_wfc_apm_call_drop_by_poor_signal(self):
280        return self.forced_call_drop_test(
281            setup="wfc_apm",
282            triggers=[
283                "set_wifi_absent_cell_absent", "set_wifi_strong_cell_strong"
284            ],
285            expected_drop_reason=IMS_LINK_LOST)
286
287    @test_tracker_info(uuid="669e9f97-6931-403a-a13d-4f179bd4406f")
288    @TelephonyBaseTest.tel_test_wrap
289    def test_wfc_non_apm_call_drop_by_poor_signal(self):
290        self.setup_wfc_non_apm()
291        return self.forced_call_drop_test(
292            setup="wfc_non_apm",
293            triggers=[
294                "set_wifi_absent_cell_absent", "set_wifi_strong_cell_strong"
295            ],
296            expected_drop_reason=IMS_LINK_LOST)
297
298    @test_tracker_info(uuid="c7619788-2357-4c49-a754-50ffaf433d59")
299    @TelephonyBaseTest.tel_test_wrap
300    def test_volte_handover_to_wfc_then_hangup(self):
301        self.connect_to_wifi()
302        self.enable_wfc()
303        set_wfc_mode(self.log, self.dut, WFC_MODE_CELLULAR_PREFERRED)
304        self.setup_volte()
305        return self.call_setup_and_connectivity_monitor_checking(
306            setup="volte",
307            handover="wfc_non_apm",
308            triggers=["set_wifi_strong_cell_absent"],
309            expected_drop_reason=None,
310            expected_trouble=None,
311            expected_action=None)
312
313    @test_tracker_info(uuid="c10c8406-6a0c-4039-b2ce-3782593774f2")
314    @TelephonyBaseTest.tel_test_wrap
315    def test_csfb_handover_to_wfc_then_hangup(self):
316        self.setup_csfb()
317        self.connect_to_wifi()
318        self.enable_wfc()
319        self.set_wifi_absent_cell_strong()
320        return self.call_setup_and_connectivity_monitor_checking(
321            setup="csfb",
322            handover="wfc_non_apm",
323            triggers=[
324                "set_wifi_strong_cell_strong", "connect_to_wifi",
325                "is_wfc_enabled", "set_wifi_strong_cell_absent"
326            ],
327            expected_drop_reason=None,
328            expected_trouble=None,
329            expected_action=None)
330
331    @test_tracker_info(uuid="fcb62ea3-3a39-407c-90d8-21896c981ef4")
332    @TelephonyBaseTest.tel_test_wrap
333    def test_3g_handover_to_wfc_then_hangup(self):
334        self.setup_3g()
335        self.connect_to_wifi()
336        self.enable_wfc()
337        set_wfc_mode(self.log, self.dut, WFC_MODE_CELLULAR_PREFERRED)
338        if not self.is_wfc_enabled():
339            self.dut.log.error("WFC is not enabled")
340            return False
341        return self.call_setup_and_connectivity_monitor_checking(
342            setup="3g",
343            handover="wfc_non_apm",
344            triggers=["set_wifi_strong_cell_absent"],
345            expected_drop_reason=None,
346            expected_trouble=None,
347            expected_action=None)
348
349    @test_tracker_info(uuid="85f32373-d1b2-4763-8812-d7ff43a9b3e6")
350    @TelephonyBaseTest.tel_test_wrap
351    def test_wfc_handover_to_volte_then_hangup(self):
352        self.setup_volte()
353        self.connect_to_wifi()
354        self.enable_wfc()
355        self.set_wifi_strong_cell_absent()
356        if not self.is_wfc_enabled():
357            self.dut.log.error("WFC is not enabled")
358            return False
359        return self.call_setup_and_connectivity_monitor_checking(
360            setup="wfc_non_apm",
361            handover="volte",
362            triggers=[
363                "set_wifi_strong_cell_strong", "set_wifi_absent_cell_strong"
364            ],
365            expected_drop_reason=None,
366            expected_trouble=None,
367            expected_action=None)
368
369    @test_tracker_info(uuid="c3dee2ba-1637-4382-97a7-ec9ca795f3dc")
370    @TelephonyBaseTest.tel_test_wrap
371    def test_wfc_handover_to_volte_then_call_drop(self):
372        self.setup_volte()
373        self.connect_to_wifi()
374        self.enable_wfc()
375        self.set_wifi_strong_cell_absent()
376        if not self.is_wfc_enabled():
377            self.dut.log.error("WFC is not enabled")
378            return False
379        return self.call_drop_test(
380            setup="wfc_non_apm",
381            handover="volte",
382            count=1,
383            triggers=[
384                "set_wifi_strong_cell_strong", "set_wifi_absent_cell_strong",
385                "set_wifi_absent_cell_absent"
386            ],
387            expected_drop_reason=IMS_LINK_LOST,
388            expected_trouble=None,
389            expected_action=None)
390
391    @test_tracker_info(uuid="90bc318a-b8ba-45c9-8d8f-e642eeb00460")
392    @TelephonyBaseTest.tel_test_wrap
393    def test_wfc_handover_to_csfb_then_call_drop(self):
394        self.setup_csfb()
395        self.set_wifi_strong_cell_absent()
396        self.connect_to_wifi()
397        self.enable_wfc()
398        if not self.is_wfc_enabled():
399            self.dut.log.error("WFC is not enabled")
400            return False
401        return self.call_drop_test(
402            setup="wfc_apm",
403            handover="csfb",
404            count=1,
405            triggers=[
406                "set_wifi_strong_cell_strong", "set_wifi_absent_cell_strong",
407                "set_wifi_absent_cell_absent"
408            ],
409            expected_drop_reason=CS_LINK_LOST,
410            expected_trouble=None,
411            expected_action=None)
412
413    @test_tracker_info(uuid="0557709e-6d82-4c66-b622-6f36db8bdcc2")
414    @TelephonyBaseTest.tel_test_wrap
415    def test_volte_handover_to_wfc_then_call_drop(self):
416        self.setup_volte()
417        self.connect_to_wifi()
418        self.enable_wfc()
419        self.set_wifi_absent_cell_strong()
420        return self.call_drop_test(
421            setup="volte",
422            handover="wfc_non_apm",
423            count=1,
424            triggers=[
425                "set_wifi_strong_cell_strong", "connect_to_wifi",
426                "is_wfc_enabled", "set_wifi_strong_cell_absent",
427                "set_wifi_absent_cell_absent"
428            ],
429            expected_drop_reason=IMS_LINK_LOST,
430            expected_trouble=None,
431            expected_action=None)
432
433    @test_tracker_info(uuid="3453ed14-8227-4050-96f1-e9ac7973df3b")
434    @TelephonyBaseTest.tel_test_wrap
435    def test_csfb_handover_to_wfc_then_call_drop(self):
436        self.setup_csfb()
437        self.connect_to_wifi()
438        self.enable_wfc()
439        self.set_wifi_absent_cell_strong()
440        return self.call_drop_test(
441            setup="csfb",
442            handover="wfc",
443            count=1,
444            triggers=[
445                "set_wifi_strong_cell_strong", "connect_to_wifi",
446                "is_wfc_enabled", "set_wifi_strong_cell_absent",
447                "set_wifi_absent_cell_absent"
448            ],
449            expected_drop_reason=IMS_LINK_LOST,
450            expected_trouble=None,
451            expected_action=None)
452
453    @test_tracker_info(uuid="68cc68db-c60b-4c4a-a974-8e0d1fa211f2")
454    @TelephonyBaseTest.tel_test_wrap
455    def test_3g_handover_to_wfc_then_call_drop(self):
456        self.setup_3g()
457        self.connect_to_wifi()
458        self.enable_wfc()
459        self.set_wifi_absent_cell_strong()
460        return self.call_drop_test(
461            setup="3g",
462            handover="wfc_non_apm",
463            count=1,
464            triggers=[
465                "set_wifi_strong_cell_strong", "connect_to_wifi",
466                "is_wfc_enabled", "set_wifi_strong_cell_absent",
467                "set_wifi_absent_cell_absent"
468            ],
469            expected_drop_reason=IMS_LINK_LOST,
470            expected_trouble=None,
471            expected_action=None)
472
473
474""" Tests End """
475