Home | History | Annotate | Download | only in live
      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 Telephony Pre Flight check.
     18 """
     19 
     20 import time
     21 from queue import Empty
     22 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     23 from acts.test_utils.tel.tel_defines import AOSP_PREFIX
     24 from acts.test_utils.tel.tel_defines import CAPABILITY_PHONE
     25 from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
     26 from acts.test_utils.tel.tel_defines import CAPABILITY_VT
     27 from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
     28 from acts.test_utils.tel.tel_defines import CAPABILITY_MSIM
     29 from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
     30 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
     31 from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND
     32 from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND
     33 from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING
     34 from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
     35 from acts.test_utils.tel.tel_lookup_tables import device_capabilities
     36 from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
     37 from acts.test_utils.tel.tel_test_utils import WifiUtils
     38 from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
     39 from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
     40 from acts.test_utils.tel.tel_test_utils import get_operator_name
     41 from acts.test_utils.tel.tel_test_utils import setup_droid_properties
     42 from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
     43 from acts.test_utils.tel.tel_test_utils import set_phone_silent_mode
     44 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
     45 from acts.test_utils.tel.tel_test_utils import verify_http_connection
     46 from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
     47 from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
     48 from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
     49 from acts.asserts import abort_all
     50 
     51 
     52 class TelLivePreflightTest(TelephonyBaseTest):
     53     def __init__(self, controllers):
     54         TelephonyBaseTest.__init__(self, controllers)
     55 
     56         self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
     57         try:
     58             self.wifi_network_pass = self.user_params["wifi_network_pass"]
     59         except KeyError:
     60             self.wifi_network_pass = None
     61 
     62     """ Tests Begin """
     63 
     64     @TelephonyBaseTest.tel_test_wrap
     65     def test_check_environment(self):
     66         ad = self.android_devices[0]
     67         # Check WiFi environment.
     68         # 1. Connect to WiFi.
     69         # 2. Check WiFi have Internet access.
     70         toggle_airplane_mode(self.log, ad, True)
     71         try:
     72             if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
     73                                          self.wifi_network_pass):
     74                 self._preflight_fail("WiFi connect fail.")
     75             if (not wait_for_wifi_data_connection(self.log, ad, True) or
     76                     not verify_http_connection(self.log, ad)):
     77                 self._preflight_fail("Data not available on WiFi.")
     78         finally:
     79             WifiUtils.wifi_toggle_state(self.log, ad, False)
     80         # TODO: add more environment check here.
     81         return True
     82 
     83     @TelephonyBaseTest.tel_test_wrap
     84     def test_pre_flight_check(self):
     85         for ad in self.android_devices:
     86             #check for sim and service
     87             subInfo = ad.droid.subscriptionGetAllSubInfoList()
     88             if not subInfo or len(subInfo) < 1:
     89                 self._preflight_fail("Unable to find A valid subscription!")
     90             toggle_airplane_mode(self.log, ad, False)
     91             sub_id = ad.droid.subscriptionGetDefaultVoiceSubId()
     92             if not wait_for_voice_attach_for_subscription(
     93                     self.log, ad, sub_id, MAX_WAIT_TIME_NW_SELECTION):
     94                 self._preflight_fail("{} didn't find a cell network".format(
     95                     ad.serial))
     96         return True
     97 
     98     def _preflight_fail(self, message):
     99         self.log.error(
    100             "Aborting all ongoing tests due to preflight check failure.")
    101         abort_all(message)
    102 
    103 
    104 """ Tests End """
    105