blob: 187848b3daaf54e80c1e3afe291589dafb00a50f [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
Ang Li73697b32015-12-03 00:41:53 +00002#
tturney1bdf77d2015-12-28 17:46:13 -08003# Copyright 2016 - Google
Ang Li73697b32015-12-03 00:41:53 +00004#
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
Ang Li73697b32015-12-03 00:41:53 +000021from queue import Empty
Yang Liu52cc0202015-12-28 14:08:52 -080022from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
Ang Li73697b32015-12-03 00:41:53 +000023from 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
Yang Liudf164e32016-01-07 16:49:32 -080030from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
Ang Li73697b32015-12-03 00:41:53 +000031from 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
Ang Li73697b32015-12-03 00:41:53 +000035from acts.test_utils.tel.tel_lookup_tables import device_capabilities
36from acts.test_utils.tel.tel_lookup_tables import operator_capabilities
Yang Liud7727092016-05-24 14:38:36 -070037from acts.test_utils.tel.tel_test_utils import WifiUtils
Yang Liu52cc0202015-12-28 14:08:52 -080038from acts.test_utils.tel.tel_test_utils import ensure_phones_default_state
Yang Liud7727092016-05-24 14:38:36 -070039from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
Yang Liu52cc0202015-12-28 14:08:52 -080040from acts.test_utils.tel.tel_test_utils import get_operator_name
Yang Liu52cc0202015-12-28 14:08:52 -080041from 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
Yang Liud7727092016-05-24 14:38:36 -070045from acts.test_utils.tel.tel_test_utils import verify_http_connection
Yang Liu52cc0202015-12-28 14:08:52 -080046from acts.test_utils.tel.tel_test_utils import wait_for_voice_attach_for_subscription
Yang Liud7727092016-05-24 14:38:36 -070047from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
Yang Liu52cc0202015-12-28 14:08:52 -080048from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
Ang Li73697b32015-12-03 00:41:53 +000049from acts.utils import load_config
Yang Liud7727092016-05-24 14:38:36 -070050from acts.asserts import abort_all
Ang Li73697b32015-12-03 00:41:53 +000051
Ang Li73697b32015-12-03 00:41:53 +000052
Nathan Harold0f76cf22015-12-30 16:33:25 -080053class TelLivePreflightTest(TelephonyBaseTest):
Ang Li73697b32015-12-03 00:41:53 +000054 def __init__(self, controllers):
55 TelephonyBaseTest.__init__(self, controllers)
Ang Li73697b32015-12-03 00:41:53 +000056
57 self.simconf = load_config(self.user_params["sim_conf_file"])
58
Yang Liud7727092016-05-24 14:38:36 -070059 self.wifi_network_ssid = self.user_params["wifi_network_ssid"]
60 try:
61 self.wifi_network_pass = self.user_params["wifi_network_pass"]
62 except KeyError:
63 self.wifi_network_pass = None
64
Ang Li73697b32015-12-03 00:41:53 +000065 """ Tests Begin """
Yang Liud7727092016-05-24 14:38:36 -070066 @TelephonyBaseTest.tel_test_wrap
67 def test_check_environment(self):
68 ad = self.android_devices[0]
69 # Check WiFi environment.
70 # 1. Connect to WiFi.
71 # 2. Check WiFi have Internet access.
72 toggle_airplane_mode(self.log, ad, True)
73 try:
74 if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
75 self.wifi_network_pass):
76 abort_all("WiFi connect fail.")
77 if (not wait_for_wifi_data_connection(self.log, ad, True) or
78 not verify_http_connection(self.log, ad)):
79 abort_all("Data not available on WiFi.")
80 finally:
81 WifiUtils.wifi_toggle_state(self.log, ad, False)
82 # TODO: add more environment check here.
83 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -080084
Ang Li73697b32015-12-03 00:41:53 +000085 @TelephonyBaseTest.tel_test_wrap
86 def test_pre_flight_check(self):
87 def droid_has_phone(log, ad):
88 #check for sim and service
89 subInfo = ad.droid.subscriptionGetAllSubInfoList()
90 if not subInfo or len(subInfo) < 1:
91 return False
92 toggle_airplane_mode(log, ad, False)
93 sub_id = ad.droid.subscriptionGetDefaultVoiceSubId()
Nathan Harold0f76cf22015-12-30 16:33:25 -080094 if not wait_for_voice_attach_for_subscription(
Yang Liudf164e32016-01-07 16:49:32 -080095 log, ad, sub_id, MAX_WAIT_TIME_NW_SELECTION):
Ang Li73697b32015-12-03 00:41:53 +000096 log.error("{} didn't find a cell network".format(ad.serial))
97 return False
98 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -080099
Ang Li73697b32015-12-03 00:41:53 +0000100 def droid_has_provisioning(log, ad):
101 if not ad.droid.imsIsVolteProvisionedOnDevice():
Nathan Harold0f76cf22015-12-30 16:33:25 -0800102 log.error("{}: VoLTE Not Provisioned on the Platform".format(
103 ad.serial))
Ang Li73697b32015-12-03 00:41:53 +0000104 return False
105 else:
106 log.info("{} VoLTE Provisioned".format(ad.serial))
107 return True
108
109 def droid_has_volte(log, ad):
110 if not ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform():
Nathan Harold0f76cf22015-12-30 16:33:25 -0800111 log.error("{}: VoLTE Not Enabled on the Platform".format(
112 ad.serial))
Ang Li73697b32015-12-03 00:41:53 +0000113 return False
114 else:
115 log.info("{} VoLTE Enabled by platform".format(ad.serial))
116 return True
117
118 def droid_has_wifi_calling(log, ad):
119 if not ad.droid.imsIsWfcEnabledByPlatform():
Nathan Harold0f76cf22015-12-30 16:33:25 -0800120 log.error("{}: WFC Not Enabled on the Platform".format(
121 ad.serial))
Ang Li73697b32015-12-03 00:41:53 +0000122 return False
123 else:
124 log.info("{} WFC Enabled by platform".format(ad.serial))
125 return True
126
127 def droid_has_vt(log, ad):
128 if not ad.droid.imsIsVtEnabledByPlatform():
Nathan Harold0f76cf22015-12-30 16:33:25 -0800129 log.error("{}: VT Not Enabled on the Platform".format(
130 ad.serial))
Ang Li73697b32015-12-03 00:41:53 +0000131 return False
132 else:
133 log.info("{} VT Enabled by platform".format(ad.serial))
134 return True
Ang Li73697b32015-12-03 00:41:53 +0000135 try:
136 for ad in self.android_devices:
137 model = ad.model
138 # Remove aosp prefix
139 if model.startswith(AOSP_PREFIX):
140 model = model[len(AOSP_PREFIX):]
141
142 # Special capability phone, needed to get SIM Operator
143 if not CAPABILITY_PHONE in device_capabilities[model]:
Nathan Harold0f76cf22015-12-30 16:33:25 -0800144 self.log.info("Skipping {}:{}: not a phone".format(
145 ad.serial, model))
Ang Li73697b32015-12-03 00:41:53 +0000146 return True
147
148 operator = get_operator_name(self.log, ad)
Nathan Harold0f76cf22015-12-30 16:33:25 -0800149 self.log.info(
150 "Pre-flight check for <{}>, <{}:{}>, build<{}>".format(
151 operator, model, ad.serial, ad.droid.getBuildID()))
Ang Li73697b32015-12-03 00:41:53 +0000152
Nathan Harold0f76cf22015-12-30 16:33:25 -0800153 if ("force_provisioning" in self.user_params and
154 CAPABILITY_OMADM in device_capabilities[model] and
155 CAPABILITY_OMADM in operator_capabilities[operator] and
156 not droid_has_provisioning(self.log, ad)):
Ang Li73697b32015-12-03 00:41:53 +0000157 self.log.info("{} not IMS Provisioned!!".format(ad.serial))
Nathan Harold0f76cf22015-12-30 16:33:25 -0800158 self.log.info("{} Forcing IMS Provisioning!".format(
159 ad.serial))
Ang Li73697b32015-12-03 00:41:53 +0000160 ad.droid.imsSetVolteProvisioning(True)
161 self.log.info("{} reboot!".format(ad.serial))
162 ad.reboot()
Nathan Harold0f76cf22015-12-30 16:33:25 -0800163 self.log.info("{} wait {}s for radio up.".format(
164 ad.serial, WAIT_TIME_AFTER_REBOOT))
Ang Li73697b32015-12-03 00:41:53 +0000165 # This sleep WAIT_TIME_AFTER_REBOOT seconds is waiting for
166 # radio to initiate after phone reboot.
167 time.sleep(WAIT_TIME_AFTER_REBOOT)
168
169 active_capabilities = [CAPABILITY_PHONE, CAPABILITY_OMADM,
170 CAPABILITY_VOLTE, CAPABILITY_WFC]
171 for capability in active_capabilities:
Nathan Harold0f76cf22015-12-30 16:33:25 -0800172 if (capability in device_capabilities[model] and
173 capability in operator_capabilities[operator]):
Ang Li73697b32015-12-03 00:41:53 +0000174 if not {
Nathan Harold0f76cf22015-12-30 16:33:25 -0800175 # TODO: b/26337715 make the check table global
176 CAPABILITY_PHONE: droid_has_phone,
177 CAPABILITY_OMADM: droid_has_provisioning,
178 CAPABILITY_VOLTE: droid_has_volte,
179 CAPABILITY_WFC: droid_has_wifi_calling,
180 CAPABILITY_VT: droid_has_vt
Ang Li73697b32015-12-03 00:41:53 +0000181 }[capability](self.log, ad):
Yang Liud7727092016-05-24 14:38:36 -0700182 abort_all(
Yang Liu08a580b2016-01-27 10:45:31 -0800183 "Pre-flight check FAILED for <{}>, <{}:{}>."
184 " Failed Check: <{}>".format(
185 operator, model, ad.serial, capability))
Ang Li73697b32015-12-03 00:41:53 +0000186 except Exception as e:
Yang Liud7727092016-05-24 14:38:36 -0700187 abort_all("Pre-flight check exception: {}".format(e))
Ang Li73697b32015-12-03 00:41:53 +0000188 return True
Nathan Harold0f76cf22015-12-30 16:33:25 -0800189
190
Ang Li73697b32015-12-03 00:41:53 +0000191""" Tests End """