Home | History | Annotate | Download | only in live
      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 
     20 import time
     21 from acts.test_decorators import test_tracker_info
     22 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     23 from acts.test_utils.tel.tel_defines import DEFAULT_DEVICE_PASSWORD
     24 from acts.test_utils.tel.tel_test_utils import abort_all_tests
     25 from acts.test_utils.tel.tel_test_utils import dumpsys_telecom_call_info
     26 from acts.test_utils.tel.tel_test_utils import get_service_state_by_adb
     27 from acts.test_utils.tel.tel_test_utils import fastboot_wipe
     28 from acts.test_utils.tel.tel_test_utils import hangup_call_by_adb
     29 from acts.test_utils.tel.tel_test_utils import initiate_call
     30 from acts.test_utils.tel.tel_test_utils import initiate_emergency_dialer_call_by_adb
     31 from acts.test_utils.tel.tel_test_utils import reset_device_password
     32 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
     33 from acts.test_utils.tel.tel_test_utils import unlock_sim
     34 from acts.test_utils.tel.tel_test_utils import wait_for_sim_ready_by_adb
     35 
     36 
     37 class TelLiveEmergencyTest(TelephonyBaseTest):
     38     def __init__(self, controllers):
     39         TelephonyBaseTest.__init__(self, controllers)
     40 
     41         self.dut = self.android_devices[0]
     42         self.number_of_devices = 1
     43         fake_number = self.user_params.get("fake_emergency_number", "800")
     44         self.fake_emergency_number = fake_number.strip("+").replace("-", "")
     45         self.wifi_network_ssid = self.user_params.get(
     46             "wifi_network_ssid") or self.user_params.get(
     47                 "wifi_network_ssid_2g")
     48         self.wifi_network_pass = self.user_params.get(
     49             "wifi_network_pass") or self.user_params.get(
     50                 "wifi_network_pass_2g")
     51 
     52     def setup_test(self):
     53         if not unlock_sim(self.dut):
     54             abort_all_tests(self.dut.log, "unable to unlock SIM")
     55         self.expected_call_result = True
     56 
     57     def teardown_test(self):
     58         self.dut.ensure_screen_on()
     59         reset_device_password(self.dut, None)
     60 
     61     def change_emergency_number_list(self):
     62         for _ in range(5):
     63             existing = self.dut.adb.getprop("ril.ecclist")
     64             self.dut.log.info("Existing ril.ecclist is: %s", existing)
     65             if self.fake_emergency_number in existing:
     66                 return True
     67             emergency_numbers = "%s,%s" % (existing,
     68                                            self.fake_emergency_number)
     69             cmd = "setprop ril.ecclist %s" % emergency_numbers
     70             self.dut.log.info(cmd)
     71             self.dut.adb.shell(cmd)
     72             # After some system events, ril.ecclist might change
     73             # wait sometime for it to settle
     74             time.sleep(10)
     75             if self.fake_emergency_number in existing:
     76                 return True
     77         return False
     78 
     79     def change_qcril_emergency_source_mcc_table(self):
     80         # This will add the fake number into emergency number list for a mcc
     81         # in qcril. Please note, the fake number will be send as an emergency
     82         # number by modem and reach the real 911 by this
     83         qcril_database_path = self.dut.adb.shell("find /data -iname  qcril.db")
     84         if not qcril_database_path: return
     85         mcc = self.dut.droid.telephonyGetNetworkOperator()
     86         mcc = mcc[:3]
     87         self.dut.log.info("Add %s mcc %s in qcril_emergency_source_mcc_table")
     88         self.dut.adb.shell(
     89             "sqlite3 %s \"INSERT INTO qcril_emergency_source_mcc_table VALUES('%s','%s','','')\""
     90             % (qcril_database_path, mcc, self.fake_emergency_number))
     91 
     92     def fake_emergency_call_test(self, by_emergency_dialer=True, attemps=3):
     93         self.dut.log.info("ServiceState is in %s",
     94                           get_service_state_by_adb(self.log, self.dut))
     95         if by_emergency_dialer:
     96             dialing_func = initiate_emergency_dialer_call_by_adb
     97             callee = self.fake_emergency_number
     98         else:
     99             dialing_func = initiate_call
    100             # Initiate_call method has to have "+" in front
    101             # otherwise the number will be in dialer without dial out
    102             # with sl4a fascade. Need further investigation
    103             callee = "+%s" % self.fake_emergency_number
    104         for i in range(attemps):
    105             result = True
    106             if not self.change_emergency_number_list():
    107                 self.dut.log.error("Unable to add number to ril.ecclist")
    108                 return False
    109             time.sleep(1)
    110             call_numbers = len(dumpsys_telecom_call_info(self.dut))
    111             dial_result = dialing_func(self.log, self.dut, callee)
    112             hangup_call_by_adb(self.dut)
    113             self.dut.send_keycode("BACK")
    114             self.dut.send_keycode("BACK")
    115             calls_info = dumpsys_telecom_call_info(self.dut)
    116             if len(calls_info) <= call_numbers:
    117                 self.dut.log.error("New call is not in sysdump telecom")
    118                 result = False
    119             else:
    120                 self.dut.log.info("New call info = %s", calls_info[-1])
    121 
    122             if dial_result == self.expected_call_result:
    123                 self.dut.log.info("Call to %s returns %s as expected", callee,
    124                                   self.expected_call_result)
    125             else:
    126                 self.dut.log.info("Call to %s returns %s", callee,
    127                                   not self.expected_call_result)
    128                 result = False
    129             if result:
    130                 return True
    131             ecclist = self.dut.adb.getprop("ril.ecclist")
    132             self.dut.log.info("ril.ecclist = %s", ecclist)
    133             if self.fake_emergency_number in ecclist:
    134                 if i == attemps - 1:
    135                     self.dut.log.error("%s is in ril-ecclist, but call failed",
    136                                        self.fake_emergency_number)
    137                 else:
    138                     self.dut.log.warning(
    139                         "%s is in ril-ecclist, but call failed, try again",
    140                         self.fake_emergency_number)
    141             else:
    142                 if i == attemps - 1:
    143                     self.dut.log.error("Fail to write %s to ril-ecclist",
    144                                        self.fake_emergency_number)
    145                 else:
    146                     self.dut.log.info("%s is not in ril-ecclist",
    147                                       self.fake_emergency_number)
    148         self.dut.log.info("fake_emergency_call_test result is %s", result)
    149         import pdb
    150         pdb.set_trace()
    151         return result
    152 
    153     """ Tests Begin """
    154 
    155     @test_tracker_info(uuid="fe75ba2c-e4ea-4fc1-881b-97e7a9a7f48e")
    156     @TelephonyBaseTest.tel_test_wrap
    157     def test_fake_emergency_call_by_emergency_dialer(self):
    158         """Test emergency call with emergency dialer in user account.
    159 
    160         Add system emergency number list with storyline number.
    161         Use the emergency dialer to call storyline.
    162         Verify DUT has in call activity.
    163 
    164         Returns:
    165             True if success.
    166             False if failed.
    167         """
    168         return self.fake_emergency_call_test()
    169 
    170     @test_tracker_info(uuid="8a0978a8-d93e-4f6a-99fe-d0e28bf1be2a")
    171     @TelephonyBaseTest.tel_test_wrap
    172     def test_fake_emergency_call_by_dialer(self):
    173         """Test emergency call with dialer.
    174 
    175         Add system emergency number list with storyline number.
    176         Call storyline by dialer.
    177         Verify DUT has in call activity.
    178 
    179         Returns:
    180             True if success.
    181             False if failed.
    182         """
    183         return self.fake_emergency_call_test(by_emergency_dialer=False)
    184 
    185     @test_tracker_info(uuid="2e6fcc75-ff9e-47b1-9ae8-ed6f9966d0f5")
    186     @TelephonyBaseTest.tel_test_wrap
    187     def test_fake_emergency_call_in_apm(self):
    188         """Test emergency call with emergency dialer in airplane mode.
    189 
    190         Enable airplane mode.
    191         Add system emergency number list with storyline number.
    192         Use the emergency dialer to call storyline.
    193         Verify DUT has in call activity.
    194 
    195         Returns:
    196             True if success.
    197             False if failed.
    198         """
    199         try:
    200             toggle_airplane_mode_by_adb(self.log, self.dut, True)
    201             if self.fake_emergency_call_test():
    202                 return True
    203             else:
    204                 return False
    205         finally:
    206             toggle_airplane_mode_by_adb(self.log, self.dut, False)
    207 
    208     @test_tracker_info(uuid="469bfa60-6e8f-4159-af1f-ab6244073079")
    209     @TelephonyBaseTest.tel_test_wrap
    210     def test_fake_emergency_call_in_screen_lock(self):
    211         """Test emergency call with emergency dialer in screen lock phase.
    212 
    213         Enable device password and then reboot upto password query window.
    214         Add system emergency number list with storyline.
    215         Use the emergency dialer to call storyline.
    216         Verify DUT has in call activity.
    217 
    218         Returns:
    219             True if success.
    220             False if failed.
    221         """
    222         toggle_airplane_mode_by_adb(self.log, self.dut, False)
    223         reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
    224         if not wait_for_sim_ready_by_adb(self.log, self.dut):
    225             self.dut.log.error("SIM is not ready")
    226             return False
    227         self.dut.reboot(stop_at_lock_screen=True)
    228         if self.fake_emergency_call_test():
    229             return True
    230         else:
    231             return False
    232 
    233     @test_tracker_info(uuid="17401c57-0dc2-49b5-b954-a94dbb2d5ad0")
    234     @TelephonyBaseTest.tel_test_wrap
    235     def test_fake_emergency_call_in_screen_lock_apm(self):
    236         """Test emergency call with emergency dialer in screen lock phase.
    237 
    238         Enable device password and then reboot upto password query window.
    239         Add system emergency number list with storyline.
    240         Use the emergency dialer to call storyline.
    241         Verify DUT has in call activity.
    242 
    243         Returns:
    244             True if success.
    245             False if failed.
    246         """
    247         try:
    248             toggle_airplane_mode_by_adb(self.log, self.dut, True)
    249             reset_device_password(self.dut, DEFAULT_DEVICE_PASSWORD)
    250             self.dut.reboot(stop_at_lock_screen=True)
    251             if not wait_for_sim_ready_by_adb(self.log, self.dut):
    252                 self.dut.log.error("SIM is not ready")
    253                 return False
    254             if self.fake_emergency_call_test():
    255                 return True
    256             else:
    257                 return False
    258         finally:
    259             toggle_airplane_mode_by_adb(self.log, self.dut, False)
    260 
    261     @test_tracker_info(uuid="ccea13ae-6951-4790-a5f7-b5b7a2451c6c")
    262     @TelephonyBaseTest.tel_test_wrap
    263     def test_fake_emergency_call_in_setupwizard(self):
    264         """Test emergency call with emergency dialer in setupwizard.
    265 
    266         Wipe the device and then reboot upto setupwizard.
    267         Add system emergency number list with storyline number.
    268         Use the emergency dialer to call storyline.
    269         Verify DUT has in call activity.
    270 
    271         Returns:
    272             True if success.
    273             False if failed.
    274         """
    275         try:
    276             if not fastboot_wipe(self.dut, skip_setup_wizard=False):
    277                 return False
    278             if not wait_for_sim_ready_by_adb(self.log, self.dut):
    279                 self.dut.log.error("SIM is not ready")
    280                 return False
    281             if self.fake_emergency_call_test():
    282                 return True
    283             else:
    284                 return False
    285         finally:
    286             self.dut.exit_setup_wizard()
    287 
    288 
    289 """ Tests End """
    290