• 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 MAX_WAIT_TIME_NW_SELECTION
31from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND
32from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND
33from acts.test_utils.tel.tel_defines import PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING
34from acts.test_utils.tel.tel_defines import WAIT_TIME_AFTER_REBOOT
35from acts.test_utils.tel.tel_lookup_tables import device_capabilities
36from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
37from acts.test_utils.tel.tel_test_utils import WifiUtils
38from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
39from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
40from acts.test_utils.tel.tel_test_utils import get_operator_name
41from acts.test_utils.tel.tel_test_utils import setup_droid_properties
42from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
43from acts.test_utils.tel.tel_test_utils import set_phone_silent_mode
44from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
45from acts.test_utils.tel.tel_test_utils import verify_http_connection
46from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
47from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
48from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
49from acts.utils import load_config
50from acts.asserts import abort_all
51
52
53class TelLivePreflightTest(TelephonyBaseTest):
54    def __init__(self, controllers):
55        TelephonyBaseTest.__init__(self, controllers)
56        self.tests = ("test_pre_flight_check", )
57
58        self.simconf = load_config(self.user_params["sim_conf_file"])
59
60        self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
61        try:
62            self.wifi_network_pass = self.user_params["wifi_network_pass"]
63        except KeyError:
64            self.wifi_network_pass = None
65
66    """ Tests Begin """
67    @TelephonyBaseTest.tel_test_wrap
68    def test_check_environment(self):
69        ad = self.android_devices[0]
70        # Check WiFi environment.
71        # 1. Connect to WiFi.
72        # 2. Check WiFi have Internet access.
73        toggle_airplane_mode(self.log, ad, True)
74        try:
75            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
76                                         self.wifi_network_pass):
77                abort_all("WiFi connect fail.")
78            if (not wait_for_wifi_data_connection(self.log, ad, True) or
79                    not verify_http_connection(self.log, ad)):
80                abort_all("Data not available on WiFi.")
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        def droid_has_phone(log, ad):
89            #check for sim and service
90            subInfo = ad.droid.subscriptionGetAllSubInfoList()
91            if not subInfo or len(subInfo) < 1:
92                return False
93            toggle_airplane_mode(log, ad, False)
94            sub_id = ad.droid.subscriptionGetDefaultVoiceSubId()
95            if not wait_for_voice_attach_for_subscription(
96                    log, ad, sub_id, MAX_WAIT_TIME_NW_SELECTION):
97                log.error("{} didn't find a cell network".format(ad.serial))
98                return False
99            return True
100
101        def droid_has_provisioning(log, ad):
102            if not ad.droid.imsIsVolteProvisionedOnDevice():
103                log.error("{}: VoLTE Not Provisioned on the Platform".format(
104                    ad.serial))
105                return False
106            else:
107                log.info("{} VoLTE Provisioned".format(ad.serial))
108            return True
109
110        def droid_has_volte(log, ad):
111            if not ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform():
112                log.error("{}: VoLTE Not Enabled on the Platform".format(
113                    ad.serial))
114                return False
115            else:
116                log.info("{} VoLTE Enabled by platform".format(ad.serial))
117            return True
118
119        def droid_has_wifi_calling(log, ad):
120            if not ad.droid.imsIsWfcEnabledByPlatform():
121                log.error("{}: WFC Not Enabled on the Platform".format(
122                    ad.serial))
123                return False
124            else:
125                log.info("{} WFC Enabled by platform".format(ad.serial))
126            return True
127
128        def droid_has_vt(log, ad):
129            if not ad.droid.imsIsVtEnabledByPlatform():
130                log.error("{}: VT Not Enabled on the Platform".format(
131                    ad.serial))
132                return False
133            else:
134                log.info("{} VT Enabled by platform".format(ad.serial))
135            return True
136        try:
137            for ad in self.android_devices:
138                model = ad.model
139                # Remove aosp prefix
140                if model.startswith(AOSP_PREFIX):
141                    model = model[len(AOSP_PREFIX):]
142
143                # Special capability phone, needed to get SIM Operator
144                if not CAPABILITY_PHONE in device_capabilities[model]:
145                    self.log.info("Skipping {}:{}: not a phone".format(
146                        ad.serial, model))
147                    return True
148
149                operator = get_operator_name(self.log, ad)
150                self.log.info(
151                    "Pre-flight check for <{}>, <{}:{}>, build<{}>".format(
152                        operator, model, ad.serial, ad.droid.getBuildID()))
153
154                if ("force_provisioning" in self.user_params and
155                        CAPABILITY_OMADM in device_capabilities[model] and
156                        CAPABILITY_OMADM in operator_capabilities[operator] and
157                        not droid_has_provisioning(self.log, ad)):
158                    self.log.info("{} not IMS Provisioned!!".format(ad.serial))
159                    self.log.info("{} Forcing IMS Provisioning!".format(
160                        ad.serial))
161                    ad.droid.imsSetVolteProvisioning(True)
162                    self.log.info("{} reboot!".format(ad.serial))
163                    ad.reboot()
164                    self.log.info("{} wait {}s for radio up.".format(
165                        ad.serial, WAIT_TIME_AFTER_REBOOT))
166                    # This sleep WAIT_TIME_AFTER_REBOOT seconds is waiting for
167                    # radio to initiate after phone reboot.
168                    time.sleep(WAIT_TIME_AFTER_REBOOT)
169
170                active_capabilities = [CAPABILITY_PHONE, CAPABILITY_OMADM,
171                                       CAPABILITY_VOLTE, CAPABILITY_WFC]
172                for capability in active_capabilities:
173                    if (capability in device_capabilities[model] and
174                            capability in operator_capabilities[operator]):
175                        if not {
176                                # TODO: b/26337715 make the check table global
177                                CAPABILITY_PHONE: droid_has_phone,
178                                CAPABILITY_OMADM: droid_has_provisioning,
179                                CAPABILITY_VOLTE: droid_has_volte,
180                                CAPABILITY_WFC: droid_has_wifi_calling,
181                                CAPABILITY_VT: droid_has_vt
182                        }[capability](self.log, ad):
183                            abort_all(
184                                "Pre-flight check FAILED for <{}>, <{}:{}>."
185                                " Failed Check: <{}>".format(
186                                    operator, model, ad.serial, capability))
187        except Exception as e:
188            abort_all("Pre-flight check exception: {}".format(e))
189        return True
190
191
192""" Tests End """
193