blob: 1548f7156f62b4593d27781b5df2769a6e806da6 [file] [log] [blame]
Sanket Agarwald09c7d82016-05-17 20:24:51 -07001#/usr/bin/env python3.4
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
Sanket Agarwald09c7d82016-05-17 20:24:51 -070016"""
17Test the HFP profile for basic calling functionality.
18"""
19
20import time
Sanket Agarwald09c7d82016-05-17 20:24:51 -070021from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
tturneye3934a22016-10-20 15:47:34 -070022from acts.test_utils.bt.BluetoothCarHfpBaseTest import BluetoothCarHfpBaseTest
Sanket Agarwald09c7d82016-05-17 20:24:51 -070023from acts.test_utils.bt import BtEnum
24from acts.test_utils.bt import bt_test_utils
tturneye3934a22016-10-20 15:47:34 -070025from acts.test_utils.car import car_telecom_utils
Sanket Agarwal54ad6232016-05-17 20:24:51 -070026from acts.test_utils.car import tel_telecom_utils
Sanket Agarwald09c7d82016-05-17 20:24:51 -070027from acts.test_utils.tel import tel_defines
28
29BLUETOOTH_PKG_NAME = "com.android.bluetooth"
30CALL_TYPE_OUTGOING = "CALL_TYPE_OUTGOING"
31CALL_TYPE_INCOMING = "CALL_TYPE_INCOMING"
tturneye3934a22016-10-20 15:47:34 -070032SHORT_TIMEOUT = 5
Sanket Agarwald09c7d82016-05-17 20:24:51 -070033
Sanket Agarwal54ad6232016-05-17 20:24:51 -070034
tturneye3934a22016-10-20 15:47:34 -070035class BtCarHfpTest(BluetoothCarHfpBaseTest):
Sanket Agarwald09c7d82016-05-17 20:24:51 -070036 def setup_class(self):
tturneye3934a22016-10-20 15:47:34 -070037 if not super(BtCarHfpTest, self).setup_class():
Sanket Agarwal54ad6232016-05-17 20:24:51 -070038 return False
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070039 # Disable the A2DP profile.
40 bt_test_utils.set_profile_priority(
41 self.hf, self.ag, [BtEnum.BluetoothProfile.PBAP_CLIENT.value,
Sanket Agarwal99f300a2016-09-07 17:06:33 -070042 BtEnum.BluetoothProfile.A2DP_SINK.value],
43 BtEnum.BluetoothPriorityLevel.PRIORITY_OFF)
tturneye3934a22016-10-20 15:47:34 -070044 bt_test_utils.set_profile_priority(
45 self.hf, self.ag, [BtEnum.BluetoothProfile.HEADSET_CLIENT.value],
46 BtEnum.BluetoothPriorityLevel.PRIORITY_ON)
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070047
tturneye3934a22016-10-20 15:47:34 -070048 if not bt_test_utils.connect_pri_to_sec(self.hf, self.ag, set(
49 [BtEnum.BluetoothProfile.HEADSET_CLIENT.value])):
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070050 self.log.error("Failed to connect")
tturneye3934a22016-10-20 15:47:34 -070051 # Additional profile connection check
52 if bt_test_utils.is_hfp_client_device_connected(
53 self.hf, self.ag.droid.bluetoothGetLocalAddress()):
54 self.log.info(
55 "HFP Client connected even though connection state changed "
56 + " event not found")
57 else:
58 return False
59 return True
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070060
Phillip Walker827112a2016-09-08 16:27:19 -070061 #@BluetoothTest(UUID=4ce2195a-b70a-4584-912e-cbd20d20e19d)
Sanket Agarwald09c7d82016-05-17 20:24:51 -070062 @BluetoothBaseTest.bt_test_wrap
63 def test_default_calling_account(self):
64 """
65 Tests if the default calling account is coming from the
66 bluetooth pacakge.
67
68 Precondition:
69 1. Devices are connected.
70
71 Steps:
72 1. Check if the default calling account is via Bluetooth package.
73
74 Returns:
75 Pass if True
76 Fail if False
77
78 Priority: 0
79 """
80 selected_acc = \
81 self.hf.droid.telecomGetUserSelectedOutgoingPhoneAccount()
82 if not selected_acc:
83 self.log.info("No default account found.")
84 return False
85
86 # Check if the default account is from the Bluetooth package. This is a
87 # light weight check.
88 try:
89 acc_component_id = selected_acc['ComponentName']
90 except KeyError:
Sanket Agarwal54ad6232016-05-17 20:24:51 -070091 self.log.info("No component name for account {}".format(
92 selected_acc))
Sanket Agarwald09c7d82016-05-17 20:24:51 -070093 return False
94 if not acc_component_id.startswith(BLUETOOTH_PKG_NAME):
Sanket Agarwal54ad6232016-05-17 20:24:51 -070095 self.log.info("Component name does not start with pkg name {}".
96 format(selected_acc))
Sanket Agarwald09c7d82016-05-17 20:24:51 -070097 return False
tturneye3934a22016-10-20 15:47:34 -070098 return True
Sanket Agarwald09c7d82016-05-17 20:24:51 -070099
Phillip Walker827112a2016-09-08 16:27:19 -0700100 #@BluetoothTest(UUID=e579009d-05f3-4236-a698-5de8c11d73a9)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700101 @BluetoothBaseTest.bt_test_wrap
102 def test_outgoing_call_hf(self):
103 """
104 Tests if we can make a phone call from HF role and disconnect from HF
105 role.
106
107 Precondition:
108 1. Devices are connected.
109
110 Steps:
111 1. Make a call from HF role.
112 2. Wait for the HF, AG to be dialing and RE to see the call ringing.
113 3. Hangup the call on HF role.
114 4. Wait for all devices to hangup the call.
115
116 Returns:
117 Pass if True
118 Fail if False
119
120 Priority: 0
121 """
122 return self.dial_a_hangup_b(self.hf, self.hf)
123
Phillip Walker827112a2016-09-08 16:27:19 -0700124 #@BluetoothTest(UUID=c9d5f9cd-f275-4adf-b212-c2e9a70d4cac)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700125 @BluetoothBaseTest.bt_test_wrap
126 def test_outgoing_call_ag(self):
127 """
128 Tests if we can make a phone call from AG role and disconnect from AG
129 role.
130
131 Precondition:
132 1. Devices are connected.
133
134 Steps:
135 1. Make a call from AG role.
136 2. Wait for the HF, AG to be in dialing and RE to see the call ringing.
137 3. Hangup the call on AG role.
138 4. Wait for all devices to hangup the call.
139
140 Returns:
141 Pass if True
142 Fail if False
143
144 Priority: 0
145 """
146 return self.dial_a_hangup_b(self.ag, self.ag)
147
Phillip Walker827112a2016-09-08 16:27:19 -0700148 #@BluetoothTest(UUID=908c199b-ca65-4694-821d-1b864ee3fe69)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700149 @BluetoothBaseTest.bt_test_wrap
150 def test_outgoing_dial_ag_hangup_hf(self):
151 """
152 Tests if we can make a phone call from AG role and disconnect from HF
153 role.
154
155 Precondition:
156 1. Devices are connected.
157
158 Steps:
159 1. Make a call from AG role.
160 2. Wait for the HF, AG to show dialing and RE to see the call ringing.
161 3. Hangup the call on HF role.
162 4. Wait for all devices to hangup the call.
163
164 Returns:
165 Pass if True
166 Fail if False
167
168 Priority: 0
169 """
170 return self.dial_a_hangup_b(self.ag, self.hf)
171
Phillip Walker827112a2016-09-08 16:27:19 -0700172 #@BluetoothTest(UUID=5d1d52c7-51d8-4c82-b437-2e91a6220db3)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700173 @BluetoothBaseTest.bt_test_wrap
174 def test_outgoing_dial_hf_hangup_ag(self):
175 """
176 Tests if we can make a phone call from HF role and disconnect from AG
177 role.
178
179 Precondition:
180 1. Devices are connected.
181
182 Steps:
183 1. Make a call from HF role.
184 2. Wait for the HF, AG to show dialing and RE to see the call ringing.
185 3. Hangup the call on AG role.
186 4. Wait for all devices to hangup the call.
187
188 Returns:
189 Pass if True
190 Fail if False
191
192 Priority: 0
193 """
194 return self.dial_a_hangup_b(self.hf, self.ag)
195
Phillip Walker827112a2016-09-08 16:27:19 -0700196 #@BluetoothTest(UUID=a718e238-7e31-40c9-a45b-72081210cc73)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700197 @BluetoothBaseTest.bt_test_wrap
198 def test_incoming_dial_re_hangup_re(self):
199 """
200 Tests if we can make a phone call from remote and disconnect from
201 remote.
202
203 Precondition:
204 1. Devices are connected.
205
206 Steps:
207 1. Make a call from RE role.
208 2. Wait for the HF, AG to show ringing and RE to see the call dialing.
209 3. Hangup the call on RE role.
210 4. Wait for all devices to hangup the call.
211
212 Returns:
213 Pass if True
214 Fail if False
215
216 Priority: 0
217 """
218 return self.dial_a_hangup_b(self.re, self.re, self.ag_phone_number)
219
tturneye3934a22016-10-20 15:47:34 -0700220 def dial_a_hangup_b(self, caller, callee, ph=""):
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700221 """
222 a, b and c can be either of AG, HF or Remote.
223 1. Make a call from 'a' on a fixed number.
224 2. Wait for the call to get connected (check on both 'a' and 'b')
225 Check that 'c' is in ringing state.
226 3. Hangup the call on 'b'.
227 4. Wait for call to get completely disconnected
228 (check on both 'a' and 'b')
229 It is assumed that scenarios will not go into voice mail.
230 """
231 if ph == "": ph = self.re_phone_number
232
233 # Determine if this is outgoing or incoming call.
234 call_type = None
tturneye3934a22016-10-20 15:47:34 -0700235 if caller == self.ag or caller == self.hf:
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700236 call_type = CALL_TYPE_OUTGOING
tturneye3934a22016-10-20 15:47:34 -0700237 if callee != self.ag and callee != self.hf:
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700238 self.log.info("outgoing call should terminate at AG or HF")
239 return False
tturneye3934a22016-10-20 15:47:34 -0700240 elif caller == self.re:
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700241 call_type = CALL_TYPE_INCOMING
tturneye3934a22016-10-20 15:47:34 -0700242 if callee != self.re:
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700243 self.log.info("Incoming call should terminate at Re")
244 return False
245
246 self.log.info("Call type is {}".format(call_type))
247
248 # make a call on 'a'
tturneye3934a22016-10-20 15:47:34 -0700249 if not tel_telecom_utils.dial_number(self.log, caller, ph):
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700250 return False
251
tturneye3934a22016-10-20 15:47:34 -0700252 # Give time for state to update due to carrier limitations
253 time.sleep(SHORT_TIMEOUT)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700254 # Check that everyone is in dialing/ringing state.
255 ret = True
256 if call_type == CALL_TYPE_OUTGOING:
Sanket Agarwal54ad6232016-05-17 20:24:51 -0700257 ret &= tel_telecom_utils.wait_for_dialing(self.log, self.hf)
258 ret &= tel_telecom_utils.wait_for_dialing(self.log, self.ag)
259 ret &= tel_telecom_utils.wait_for_ringing(self.log, self.re)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700260 else:
Sanket Agarwal54ad6232016-05-17 20:24:51 -0700261 ret &= tel_telecom_utils.wait_for_ringing(self.log, self.hf)
262 ret &= tel_telecom_utils.wait_for_ringing(self.log, self.ag)
263 ret &= tel_telecom_utils.wait_for_dialing(self.log, self.re)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700264 if not ret:
265 return False
266
tturneye3934a22016-10-20 15:47:34 -0700267 # Give time for state to update due to carrier limitations
268 time.sleep(SHORT_TIMEOUT)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700269 # Check if we have any calls with dialing or active state on 'b'.
270 # We assume we never disconnect from 'ringing' state since it will lead
271 # to voicemail.
272 call_state_dialing_or_active = \
273 [tel_defines.CALL_STATE_CONNECTING,
274 tel_defines.CALL_STATE_DIALING,
275 tel_defines.CALL_STATE_ACTIVE]
276
Sanket Agarwal54ad6232016-05-17 20:24:51 -0700277 calls_in_dialing_or_active = tel_telecom_utils.get_calls_in_states(
tturneye3934a22016-10-20 15:47:34 -0700278 self.log, callee, call_state_dialing_or_active)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700279
280 # Make sure there is only one!
281 if len(calls_in_dialing_or_active) != 1:
282 self.log.info("Call State in dialing or active failed {}".format(
283 calls_in_dialing_or_active))
284 return False
285
286 # Hangup the *only* call on 'b'
tturneye3934a22016-10-20 15:47:34 -0700287 if not car_telecom_utils.hangup_call(self.log, caller,
Sanket Agarwal54ad6232016-05-17 20:24:51 -0700288 calls_in_dialing_or_active[0]):
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700289 return False
290
291 # Make sure everyone got out of in call state.
292 for d in self.android_devices:
Sanket Agarwal54ad6232016-05-17 20:24:51 -0700293 ret &= tel_telecom_utils.wait_for_not_in_call(self.log, d)
Sanket Agarwald09c7d82016-05-17 20:24:51 -0700294 return ret