• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20import time
21from queue import Empty
22from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
23from acts.test_utils.tel.tel_defines import AOSP_PREFIX
24from acts.test_utils.tel.tel_defines import CAPABILITY_PHONE
25from acts.test_utils.tel.tel_defines import CAPABILITY_VOLTE
26from acts.test_utils.tel.tel_defines import CAPABILITY_VT
27from acts.test_utils.tel.tel_defines import CAPABILITY_WFC
28from acts.test_utils.tel.tel_defines import CAPABILITY_MSIM
29from acts.test_utils.tel.tel_defines import CAPABILITY_OMADM
30from acts.test_utils.tel.tel_defines import INVALID_SUB_ID
31from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
32from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND
33from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND
34from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING
35from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
36from acts.test_utils.tel.tel_lookup_tables import device_capabilities
37from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
38from acts.test_utils.tel.tel_test_utils import WifiUtils
39from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
40from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
41from acts.test_utils.tel.tel_test_utils import get_operator_name
42from acts.test_utils.tel.tel_test_utils import setup_droid_properties
43from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
44from acts.test_utils.tel.tel_test_utils import set_phone_silent_mode
45from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
46from acts.test_utils.tel.tel_test_utils import verify_http_connection
47from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
48from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
49from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
50from acts.asserts import abort_all
51
52
53class TelLivePreflightTest(TelephonyBaseTest):
54    def __init__(self, controllers):
55        TelephonyBaseTest.__init__(self, controllers)
56
57        self.wifi_network_ssid = self.user_params.get(
58              "wifi_network_ssid") or self.user_params.get("wifi_network_ssid_2g")
59        self.wifi_network_pass = self.user_params.get(
60              "wifi_network_pass") or self.user_params.get("wifi_network_pass_2g")
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, False, strict_checking=False)
71
72        try:
73            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
74                                         self.wifi_network_pass):
75                self._preflight_fail("{}: WiFi connect fail.".format(
76                    ad.serial))
77            if (not wait_for_wifi_data_connection(self.log, ad, True) or
78                    not verify_http_connection(self.log, ad)):
79                self._preflight_fail("{}: Data not available on WiFi.".format(
80                    ad.serial))
81        finally:
82            WifiUtils.wifi_toggle_state(self.log, ad, False)
83        # TODO: add more environment check here.
84        return True
85
86    @TelephonyBaseTest.tel_test_wrap
87    def test_pre_flight_check(self):
88        for ad in self.android_devices:
89            #check for sim and service
90            subInfo = ad.droid.subscriptionGetAllSubInfoList()
91            if not subInfo or len(subInfo) < 1:
92                self._preflight_fail(
93                    "{}: Unable to find A valid subscription!".format(
94                        ad.serial))
95            toggle_airplane_mode(self.log, ad, False, strict_checking=False)
96            if ad.droid.subscriptionGetDefaultDataSubId() <= INVALID_SUB_ID:
97                self._preflight_fail("{}: No Default Data Sub ID".format(
98                    ad.serial))
99            elif ad.droid.subscriptionGetDefaultVoiceSubId() <= INVALID_SUB_ID:
100                self._preflight_fail("{}: No Valid Voice Sub ID".format(
101                    ad.serial))
102            sub_id = ad.droid.subscriptionGetDefaultVoiceSubId()
103            if not wait_for_voice_attach_for_subscription(
104                    self.log, ad, sub_id, MAX_WAIT_TIME_NW_SELECTION):
105                self._preflight_fail(
106                    "{}: Did Not Attach For Voice Services".format(ad.serial))
107        return True
108
109    def _preflight_fail(self, message):
110        self.log.error(
111            "Aborting all ongoing tests due to preflight check failure.")
112        abort_all(message)
113
114
115""" Tests End """
116