1#!/usr/bin/env python3.4
2#
3#   Copyright 2017 - 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 Telephony Pre Check In Sanity
18"""
19
20from acts import signals
21from acts.test_decorators import test_tracker_info
22from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_defines import DEFAULT_DEVICE_PASSWORD
24from acts.test_utils.tel.tel_defines import GEN_2G
25from acts.test_utils.tel.tel_defines import GEN_3G
26from acts.test_utils.tel.tel_defines import GEN_4G
27from acts.test_utils.tel.tel_defines import SIM_STATE_ABSENT
28from acts.test_utils.tel.tel_defines import SIM_STATE_UNKNOWN
29from acts.test_utils.tel.tel_test_utils import fastboot_wipe
30from acts.test_utils.tel.tel_test_utils import get_sim_state
31from acts.test_utils.tel.tel_lookup_tables import \
32    network_preference_for_generation
33from acts.test_utils.tel.tel_test_utils import reset_device_password
34from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
35from TelLiveEmergencyBase import TelLiveEmergencyBase
36
37
38class TelLiveNoSimTest(TelLiveEmergencyBase):
39    def setup_class(self):
40        for ad in self.my_devices:
41            sim_state = get_sim_state(ad)
42            ad.log.info("Sim state is %s", sim_state)
43            if sim_state in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
44                ad.log.info("Device has no or unknown SIM in it, set as DUT")
45                self.setup_dut(ad)
46                return True
47        self.log.error("No device meets SIM absent or unknown requirement")
48        raise signals.TestAbortClass(
49            "No device meets SIM absent or unknown requirement")
50
51    def setup_test(self):
52        self.expected_call_result = False
53
54    def teardown_test(self):
55        self.dut.ensure_screen_on()
56        self.dut.exit_setup_wizard()
57        reset_device_password(self.dut, None)
58
59    """ Tests Begin """
60
61    @test_tracker_info(uuid="91bc0c02-c1f2-4112-a7f8-c91617bff53e")
62    @TelephonyBaseTest.tel_test_wrap
63    def test_fake_emergency_call_by_emergency_dialer_no_sim(self):
64        """Test fake emergency call with emergency dialer in user account.
65
66        Add fake emergency number to system emergency number list.
67        Use the emergency dialer to call storyline.
68        Verify DUT has in call activity.
69
70        Returns:
71            True if success.
72            False if failed.
73        """
74        toggle_airplane_mode_by_adb(self.log, self.dut, False)
75        return self.fake_emergency_call_test()
76
77    @test_tracker_info(uuid="fccb7d1d-279d-4933-8ffe-528bd7fdf5f1")
78    @TelephonyBaseTest.tel_test_wrap
79    def test_fake_emergency_call_by_emergency_dialer_csfb_no_sim(self):
80        """Change network preference to use 4G.
81
82        Add system emergency number list with fake emergency number.
83        Turn off emergency call IMS first.
84        Use the emergency dialer to call fake emergency number.
85        Verify DUT has in call activity.
86
87        Returns:
88            True if success.
89            False if failed.
90        """
91        network_preference = network_preference_for_generation(
92            GEN_4G, None, self.dut.droid.telephonyGetPhoneType())
93        self.dut.log.info("Set network preference to %s", network_preference)
94        self.dut.droid.telephonySetPreferredNetworkTypes(network_preference)
95
96        return self.fake_emergency_call_test()
97
98    @test_tracker_info(uuid="de6332f9-9682-45ee-b8fd-99a24c821ca9")
99    @TelephonyBaseTest.tel_test_wrap
100    def test_fake_emergency_call_by_emergency_dialer_3g_no_sim(self):
101        """Change network preference to use 3G.
102
103        Add system emergency number list with fake emergency number.
104        Turn off emergency call IMS first.
105        Use the emergency dialer to call fake emergency number.
106        Verify DUT has in call activity.
107
108        Returns:
109            True if success.
110            False if failed.
111        """
112        network_preference = network_preference_for_generation(
113            GEN_3G, None, self.dut.droid.telephonyGetPhoneType())
114        self.dut.log.info("Set network preference to %s", network_preference)
115        self.dut.droid.telephonySetPreferredNetworkTypes(network_preference)
116
117        return self.fake_emergency_call_test()
118
119    @test_tracker_info(uuid="d173f152-a43a-4be8-a289-affc0817ca8e")
120    @TelephonyBaseTest.tel_test_wrap
121    def test_fake_emergency_call_by_emergency_dialer_2g_no_sim(self):
122        """Change network preference to use 2G.
123
124        Add system emergency number list with fake emergency number.
125        Turn off emergency call IMS first.
126        Use the emergency dialer to call fake emergency number.
127        Verify DUT has in call activity.
128
129        Returns:
130            True if success.
131            False if failed.
132        """
133        network_preference = network_preference_for_generation(
134            GEN_2G, None, self.dut.droid.telephonyGetPhoneType())
135        self.dut.log.info("Set network preference to %s", network_preference)
136        self.dut.droid.telephonySetPreferredNetworkTypes(network_preference)
137
138        return self.fake_emergency_call_test()
139
140    @test_tracker_info(uuid="cdf7ddad-480f-4757-83bd-a74321b799f7")
141    @TelephonyBaseTest.tel_test_wrap
142    def test_fake_emergency_call_by_dialer_no_sim(self):
143        """Test emergency call with dialer.
144
145        Add storyline number to system emergency number list.
146        Call storyline by dialer.
147        Verify DUT has in call activity.
148
149        Returns:
150            True if success.
151            False if failed.
152        """
153        return self.fake_emergency_call_test(by_emergency_dialer=False)
154
155    @test_tracker_info(uuid="e147960a-4227-41e2-bd06-65001ad5e0cd")
156    @TelephonyBaseTest.tel_test_wrap
157    def test_fake_emergency_call_in_apm_no_sim(self):
158        """Test emergency call with emergency dialer in airplane mode.
159
160        Enable airplane mode.
161        Add storyline number to system emergency number list.
162        Use the emergency dialer to call storyline.
163        Verify DUT has in call activity.
164
165        Returns:
166            True if success.
167            False if failed.
168        """
169        toggle_airplane_mode_by_adb(self.log, self.dut, True)
170        return self.fake_emergency_call_test()
171
172    @test_tracker_info(uuid="34068bc8-bfa0-4c7b-9450-e189a0b93c8a")
173    @TelephonyBaseTest.tel_test_wrap
174    def test_fake_emergency_call_in_screen_lock_no_sim(self):
175        """Test emergency call with emergency dialer in screen lock phase.
176
177        Enable device password and then reboot upto password query window.
178        Add storyline number to system emergency number list.
179        Use the emergency dialer to call storyline.
180        Verify DUT has in call activity.
181
182        Returns:
183            True if success.
184            False if failed.
185        """
186        reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
187        self.dut.reboot(stop_at_lock_screen=True)
188        return self.fake_emergency_call_test()
189
190    @test_tracker_info(uuid="1ef97f8a-eb3d-45b7-b947-ac409bb70587")
191    @TelephonyBaseTest.tel_test_wrap
192    def test_fake_emergency_call_in_screen_lock_apm_no_sim(self):
193        """Test emergency call with emergency dialer in screen lock phase.
194
195        Enable device password and then reboot upto password query window.
196        Add storyline number to system emergency number list.
197        Use the emergency dialer to call storyline.
198        Verify DUT has in call activity.
199
200        Returns:
201            True if success.
202            False if failed.
203        """
204        toggle_airplane_mode_by_adb(self.log, self.dut, True)
205        reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
206        self.dut.reboot(stop_at_lock_screen=True)
207        return self.fake_emergency_call_test()
208
209    @test_tracker_info(uuid="50f8b3d9-b126-4419-b5e5-b37b850deb8e")
210    @TelephonyBaseTest.tel_test_wrap
211    def test_fake_emergency_call_in_setupwizard_no_sim(self):
212        """Test emergency call with emergency dialer in setupwizard.
213
214        Wipe the device and then reboot upto setupwizard.
215        Add storyline number to system emergency number list.
216        Use the emergency dialer to call storyline.
217        Verify DUT has in call activity.
218
219        Returns:
220            True if success.
221            False if failed.
222        """
223        if not fastboot_wipe(self.dut, skip_setup_wizard=False):
224            return False
225        return self.fake_emergency_call_test()
226
227
228""" Tests End """
229