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 Locked SIM Emergency Call Test
18"""
19
20import time
21from acts.base_test import BaseTestClass
22from acts.test_decorators import test_tracker_info
23from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
24from acts.test_utils.tel.tel_defines import DEFAULT_DEVICE_PASSWORD
25from acts.test_utils.tel.tel_test_utils import abort_all_tests
26from acts.test_utils.tel.tel_test_utils import fastboot_wipe
27from acts.test_utils.tel.tel_test_utils import is_sim_locked
28from acts.test_utils.tel.tel_test_utils import is_sim_ready_by_adb
29from acts.test_utils.tel.tel_test_utils import reset_device_password
30from acts.test_utils.tel.tel_test_utils import refresh_sl4a_session
31from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
32from acts.test_utils.tel.tel_test_utils import unlocking_device
33from acts.test_utils.tel.tel_test_utils import unlock_sim
34from acts.test_utils.tel.tel_test_utils import STORY_LINE
35from TelLiveEmergencyTest import TelLiveEmergencyTest
36
37EXPECTED_CALL_TEST_RESULT = False
38
39
40class TelLiveLockedSimTest(TelLiveEmergencyTest):
41    def __init__(self, controllers):
42        BaseTestClass.__init__(self, controllers)
43        self.logger_sessions = []
44        fake_number = self.user_params.get("fake_emergency_number", STORY_LINE)
45        self.fake_emergency_number = fake_number.strip("+").replace("-", "")
46        for ad in self.android_devices:
47            if not is_sim_locked(ad):
48                ad.log.info("SIM is not locked")
49            else:
50                ad.log.info("SIM is locked")
51                self.dut = ad
52                return
53        #if there is no locked SIM, reboot the device and check again
54        for ad in self.android_devices:
55            reset_device_password(ad, None)
56            ad.reboot(stop_at_lock_screen=True)
57            for _ in range(10):
58                if is_sim_ready_by_adb(self.log, ad):
59                    ad.log.info("SIM is not locked")
60                    break
61                elif is_sim_locked(ad):
62                    ad.log.info("SIM is locked")
63                    self.dut = ad
64                    ad.ensure_screen_on()
65                    ad.start_services(ad.skip_sl4a)
66                    return
67                else:
68                    time.sleep(5)
69        self.log.error("There is no locked SIM in this testbed")
70        abort_all_tests(self.log, "There is no locked SIM")
71
72    def setup_class(self):
73        self.android_devices = [self.dut]
74        pass
75
76    def setup_test(self):
77        self.expected_call_result = False
78        unlocking_device(self.dut)
79        refresh_sl4a_session(self.dut)
80        unlock_sim(self.dut)
81
82    """ Tests Begin """
83
84    @test_tracker_info(uuid="fd7fb69c-6fd4-4874-a4ca-769353b9db25")
85    @TelephonyBaseTest.tel_test_wrap
86    def test_fake_emergency_call_by_emergency_dialer(self):
87        """Test emergency call with emergency dialer in user account.
88
89        Enable SIM lock on the SIM. Reboot device to SIM pin request page.
90        Add storyline number to system emergency number list.
91        Use the emergency dialer to call "611".
92        Verify DUT has in call activity.
93
94        Returns:
95            True if success.
96            False if failed.
97        """
98        self.expected_call_result = True
99        toggle_airplane_mode_by_adb(self.log, self.dut, False)
100        return self.fake_emergency_call_test()
101
102    @test_tracker_info(uuid="669cf1d9-9513-4f90-b0fd-2f0e8f1cc941")
103    @TelephonyBaseTest.tel_test_wrap
104    def test_fake_emergency_call_by_dialer(self):
105        """Test emergency call with dialer.
106
107        Enable SIM lock on the SIM. Reboot device to SIM pin request page.
108        Add system emergency number list with storyline number.
109        Call storyline by dialer.
110        Verify DUT has in call activity.
111
112        Returns:
113            True if success.
114            False if failed.
115        """
116        self.expected_call_result = True
117        toggle_airplane_mode_by_adb(self.log, self.dut, False)
118        return self.fake_emergency_call_test(by_emergency_dialer=True)
119
120    @test_tracker_info(uuid="1990f166-66a7-4092-b448-c179a9194371")
121    @TelephonyBaseTest.tel_test_wrap
122    def test_fake_emergency_call_in_apm(self):
123        """Test emergency call with emergency dialer in airplane mode.
124
125        Enable airplane mode.
126        Enable SIM lock on the SIM. Reboot device to SIM pin request page.
127        Add system emergency number list with storyline number.
128        Use the emergency dialer to call storyline.
129        Verify DUT has in call activity.
130
131        Returns:
132            True if success.
133            False if failed.
134        """
135        self.expected_call_result = True
136        try:
137            toggle_airplane_mode_by_adb(self.log, self.dut, True)
138            if self.fake_emergency_call_test():
139                return True
140            else:
141                return False
142        finally:
143            toggle_airplane_mode_by_adb(self.log, self.dut, False)
144
145    @test_tracker_info(uuid="7ffdad34-b8fb-41b0-b0fd-2def5adc67bc")
146    @TelephonyBaseTest.tel_test_wrap
147    def test_fake_emergency_call_in_screen_lock(self):
148        """Test emergency call with emergency dialer in screen lock phase.
149
150        Enable SIM lock on the SIM.
151        Enable device password and then reboot upto password and pin query stage.
152        Add system emergency number list with storyline number.
153        Use the emergency dialer to call storyline.
154        Verify DUT has in call activity.
155
156        Returns:
157            True if success.
158            False if failed.
159        """
160        self.dut.log.info("Turn off airplane mode")
161        toggle_airplane_mode_by_adb(self.log, self.dut, False)
162        self.dut.log.info("Set screen lock pin")
163        reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
164        self.dut.log.info("Reboot device to screen lock screen")
165        self.dut.reboot(stop_at_lock_screen=True)
166        if self.fake_emergency_call_test():
167            return True
168        else:
169            return False
170
171    @test_tracker_info(uuid="12dc1eb6-50ed-4ad9-b195-5d96c6b6952e")
172    @TelephonyBaseTest.tel_test_wrap
173    def test_fake_emergency_call_in_screen_lock_apm(self):
174        """Test emergency call with emergency dialer in screen lock phase.
175
176        Enable device password and airplane mode
177        Enable SIM lock on the SIM.
178        Reboot upto pin query window.
179        Add system emergency number list with story line.
180        Use the emergency dialer to call story line.
181        Verify DUT has in call activity.
182
183        Returns:
184            True if success.
185            False if failed.
186        """
187        toggle_airplane_mode_by_adb(self.log, self.dut, True)
188        self.dut.log.info("Set screen lock pin")
189        reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
190        self.dut.log.info("Reboot device to screen lock screen")
191        self.dut.reboot(stop_at_lock_screen=True)
192        if self.fake_emergency_call_test():
193            return True
194        else:
195            return False
196
197    @test_tracker_info(uuid="1e01927a-a077-466d-8bf8-52dca87ab87c")
198    @TelephonyBaseTest.tel_test_wrap
199    def test_fake_emergency_call_in_setupwizard(self):
200        """Test emergency call with emergency dialer in setupwizard.
201
202        Enable SIM lock on the SIM.
203        Wipe the device and then reboot upto setupwizard.
204        Add system emergency number list with story line.
205        Use the emergency dialer to call story line.
206        Verify DUT has in call activity.
207
208        Returns:
209            True if success.
210            False if failed.
211        """
212        try:
213            if not fastboot_wipe(self.dut, skip_setup_wizard=False):
214                return False
215            if self.fake_emergency_call_test():
216                return True
217            else:
218                return False
219        finally:
220            self.dut.exit_setup_wizard()
221
222
223""" Tests End """
224