blob: cdf271a96bec64887667fac1ef3deb0f5a2470f6 [file] [log] [blame]
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -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.
16"""Test script to test PBAP contact download between two devices which can run SL4A.
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070017"""
18
Joseph Pirozzof304d362016-06-17 15:15:40 -070019from time import sleep
20from time import time
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070021
22from acts.base_test import BaseTestClass
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070023from acts.test_utils.bt import bt_contacts_utils
Joseph Pirozzof304d362016-06-17 15:15:40 -070024from acts.test_utils.bt import bt_test_utils
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070025from acts.test_utils.car import car_bt_utils
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070026from acts.utils import exe_cmd
Joseph Pirozzof304d362016-06-17 15:15:40 -070027import acts.test_utils.bt.BtEnum as BtEnum
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070028
Joseph Pirozzof304d362016-06-17 15:15:40 -070029# Offset call logs by 1 minute
30CALL_LOG_TIME_OFFSET_IN_MSEC = 60000
31
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070032class BtCarPbapTest(BaseTestClass):
33 def __init__(self, controllers):
34 BaseTestClass.__init__(self, controllers)
35 self.pce = self.android_devices[0]
36 self.pse = self.android_devices[1]
Phillip Walker827112a2016-09-08 16:27:19 -070037 # Names for temporary files for contacts cards for import and export from PSE and PCE
38 global PSE_CONTACTS_FILE
39 global PCE_CONTACTS_FILE
40 global CONTACTS_DESTINATION_PATH
41 CONTACTS_DESTINATION_PATH = self.log_path + "/"
42 PSE_CONTACTS_FILE = "psecontacts.vcf"
43 PCE_CONTACTS_FILE = "pcecontacts.vcf"
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070044
45 def setup_class(self):
46 # Reset the devices in a clean state.
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070047 bt_test_utils.setup_multiple_devices_for_bt_test([self.pce, self.pse])
Joseph Pirozzof304d362016-06-17 15:15:40 -070048 bt_test_utils.reset_bluetooth(self.android_devices)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070049
50 for a in self.android_devices:
51 a.ed.clear_all_events()
52
53 # Pair the devices.
54 # This call may block until some specified timeout in bt_test_utils.py.
Joseph Pirozzof304d362016-06-17 15:15:40 -070055 if not bt_test_utils.pair_pri_to_sec(self.pce.droid, self.pse.droid):
56 self.log.error("Failed to pair.")
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070057 return False
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070058
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070059 # Disable the HFP and A2DP profiles. This will ensure only PBAP
60 # gets connected. Also, this will eliminate the auto-connect loop.
61 car_bt_utils.set_car_profile_priorities_off(self.pce, self.pse)
62
63 # Enable PBAP on PSE & PCE.
64 bt_test_utils.set_profile_priority(
65 self.pce, self.pse, [BtEnum.BluetoothProfile.PBAP_CLIENT],
66 BtEnum.BluetoothPriorityLevel.PRIORITY_ON)
67
Joseph Pirozzof304d362016-06-17 15:15:40 -070068 self.pse.droid.bluetoothChangeProfileAccessPermission(
69 self.pce.droid.bluetoothGetLocalAddress(),
70 BtEnum.BluetoothProfile.PBAP_SERVER.value,
71 BtEnum.BluetoothAccessLevel.ACCESS_ALLOWED.value)
72
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070073 return True
74
75 def setup_test(self):
76 bt_contacts_utils.set_logger(self.log)
Joseph Pirozzof304d362016-06-17 15:15:40 -070077 self.pse.droid.callLogsEraseAll()
78 if not (bt_contacts_utils.erase_contacts(self.pse) and
79 bt_contacts_utils.erase_contacts(self.pce)):
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070080 return False
Joseph Pirozzof304d362016-06-17 15:15:40 -070081 # Allow all content providers to synchronize.
82 sleep(1)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070083 return True
84
85 def teardown_test(self):
Joseph Pirozzof304d362016-06-17 15:15:40 -070086 self.pce.droid.bluetoothPbapClientDisconnect(
87 self.pse.droid.bluetoothGetLocalAddress())
88 bt_contacts_utils.erase_contacts(self.pse)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070089 return True
90
91 def on_fail(self, test_name, begin_time):
Phillip Walker827112a2016-09-08 16:27:19 -070092 bt_test_utils.take_btsnoop_logs(self.android_devices, self, test_name, begin_time)
93 bt_test_utils.take_bugreport_logs(self.android_devices, self, test_name, begin_time)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070094
Joseph Pirozzof304d362016-06-17 15:15:40 -070095 def verify_contacts_match(self):
96 bt_contacts_utils.export_device_contacts_to_vcf(self.pce,
Phillip Walker827112a2016-09-08 16:27:19 -070097 CONTACTS_DESTINATION_PATH,
Joseph Pirozzof304d362016-06-17 15:15:40 -070098 PCE_CONTACTS_FILE)
99 return bt_contacts_utils.count_contacts_with_differences(
Phillip Walker827112a2016-09-08 16:27:19 -0700100 CONTACTS_DESTINATION_PATH, PCE_CONTACTS_FILE, PSE_CONTACTS_FILE) == 0
Joseph Pirozzof304d362016-06-17 15:15:40 -0700101
102 def connect_and_verify(self, count):
103 bt_test_utils.connect_pri_to_sec(
104 self.log, self.pce, self.pse.droid,
105 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
106 bt_contacts_utils.wait_for_phone_number_update_complete(self.pce,
107 count)
108 contacts_added = self.verify_contacts_match()
109 self.pce.droid.bluetoothPbapClientDisconnect(
110 self.pse.droid.bluetoothGetLocalAddress())
111 contacts_removed = bt_contacts_utils.wait_for_phone_number_update_complete(
112 self.pce, 0)
113 return contacts_added and contacts_removed
114
Phillip Walker827112a2016-09-08 16:27:19 -0700115 #@BluetoothTest(UUID=7dcdecfc-42d1-4f41-b66e-823c8f161356)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700116 def test_pbap_connect_and_disconnect(self):
117 """Test Connectivity
118
119 Test connecting with the server enabled and disabled
120
121 Precondition:
122 1. Devices are paired.
123
124 Steps:
125 1. Disable permission on PSE to prevent PCE from connecting
126 2. Attempt to connect PCE to PSE
127 3. Verify connection failed
128 4. Enable permission on PSE to allow PCE to connect
129 5. Attempt to connect PCE to PSE
130 6. Verify connection succeeded
131
132 Returns:
133 Pass if True
134 Fail if False
135 """
136 self.pse.droid.bluetoothChangeProfileAccessPermission(
137 self.pce.droid.bluetoothGetLocalAddress(),
138 BtEnum.BluetoothProfile.PBAP_SERVER.value,
139 BtEnum.BluetoothAccessLevel.ACCESS_DENIED.value)
140 if bt_test_utils.connect_pri_to_sec(
141 self.log, self.pce, self.pse.droid,
142 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value])):
143 self.log.error("Client connected and shouldn't be.")
144 return False
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700145
Joseph Pirozzof304d362016-06-17 15:15:40 -0700146 self.pce.droid.bluetoothPbapClientDisconnect(
147 self.pse.droid.bluetoothGetLocalAddress())
148
149 self.pse.droid.bluetoothChangeProfileAccessPermission(
150 self.pce.droid.bluetoothGetLocalAddress(),
151 BtEnum.BluetoothProfile.PBAP_SERVER.value,
152 BtEnum.BluetoothAccessLevel.ACCESS_ALLOWED.value)
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700153
Joseph Pirozzof304d362016-06-17 15:15:40 -0700154 if not bt_test_utils.connect_pri_to_sec(
155 self.log, self.pce, self.pse.droid,
156 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value])):
157 self.log.error("No client connected and should be.")
158 return False
159
160 return True
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700161
Phillip Walker827112a2016-09-08 16:27:19 -0700162 #@BluetoothTest(UUID=1733efb9-71af-4956-bd3a-0d3167d94d0c)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700163 def test_contact_download(self):
164 """Test Contact Download
165
166 Test download of contacts from a clean state.
167
Joseph Pirozzof304d362016-06-17 15:15:40 -0700168 Precondition:
169 1. Devices are paired.
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700170
Joseph Pirozzof304d362016-06-17 15:15:40 -0700171 Steps:
172 1. Erase contacts from PSE and PCE.
173 2. Add a predefined list of contacts to PSE.
174 3. Connect PCE to PSE to perform transfer.
175 4. Compare transfered contacts.
176 5. Disconnect.
177 6. Verify PCE cleaned up contact list.
178
179 Returns:
180 Pass if True
181 Fail if False
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700182 """
Phillip Walker827112a2016-09-08 16:27:19 -0700183 bt_contacts_utils.generate_contact_list(CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE, 100)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700184 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
Phillip Walker827112a2016-09-08 16:27:19 -0700185 self.pse, CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700186 bt_test_utils.connect_pri_to_sec(
187 self.log, self.pce, self.pse.droid,
188 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
189 bt_contacts_utils.wait_for_phone_number_update_complete(
190 self.pce, phone_numbers_added)
191 if not self.verify_contacts_match():
192 return False
Phillip Walker827112a2016-09-08 16:27:19 -0700193 return bt_contacts_utils.erase_contacts(self.pce)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700194
Phillip Walker827112a2016-09-08 16:27:19 -0700195 #@BluetoothTest(UUID=99dc6ac6-b7cf-45ce-927b-8c4ebf8ab664)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700196 def test_modify_phonebook(self):
197 """Test Modify Phonebook
198
199 Test changing contacts and reconnecting PBAP.
200
201 Precondition:
202 1. Devices are paired.
203
204 Steps:
205 1. Add a predefined list of contacts to PSE.
206 2. Connect PCE to PSE to perform transfer.
207 3. Verify that contacts match.
208 4. Change some contacts on the PSE.
209 5. Reconnect PCE to PSE to perform transfer.
210 6. Verify that new contacts match.
211
212 Returns:
213 Pass if True
214 Fail if False
215 """
Phillip Walker827112a2016-09-08 16:27:19 -0700216 bt_contacts_utils.generate_contact_list(CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE, 100)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700217 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
Phillip Walker827112a2016-09-08 16:27:19 -0700218 self.pse, CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700219 if not self.connect_and_verify(phone_numbers_added):
220 return False
221
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700222 bt_contacts_utils.erase_contacts(self.pse)
Phillip Walker827112a2016-09-08 16:27:19 -0700223 bt_contacts_utils.generate_contact_list(CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE, 110, 2)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700224 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
Phillip Walker827112a2016-09-08 16:27:19 -0700225 self.pse, CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700226 return self.connect_and_verify(phone_numbers_added)
227
Phillip Walker827112a2016-09-08 16:27:19 -0700228 #@BluetoothTest(UUID=bbe31bf5-51e8-4175-b266-1c7750e44f5b)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700229 def test_special_contacts(self):
230 """Test Special Contacts
231
232 Test numerous special cases of contacts that could cause errors.
233
234 Precondition:
235 1. Devices are paired.
236
237 Steps:
238 1. Add a predefined list of contacts to PSE that includes special cases:
239 2. Connect PCE to PSE to perform transfer.
240 3. Verify that contacts match.
241
242 Returns:
243 Pass if True
244 Fail if False
245 """
246
247 vcards = []
248
249 # Generate a contact with no email address
250 current_contact = bt_contacts_utils.VCard()
251 current_contact.first_name = "Mr."
252 current_contact.last_name = "Smiley"
253 current_contact.add_phone_number(
254 bt_contacts_utils.generate_random_phone_number())
255 vcards.append(current_contact)
256
257 # Generate a 2nd contact with the same name but different phone number
258 current_contact = bt_contacts_utils.VCard()
259 current_contact.first_name = "Mr."
260 current_contact.last_name = "Smiley"
261 current_contact.add_phone_number(
262 bt_contacts_utils.generate_random_phone_number())
263 vcards.append(current_contact)
264
265 # Generate a contact with no name
266 current_contact = bt_contacts_utils.VCard()
267 current_contact.email = "{}@gmail.com".format(
268 bt_contacts_utils.generate_random_string())
269 current_contact.add_phone_number(
270 bt_contacts_utils.generate_random_phone_number())
271 vcards.append(current_contact)
272
273 # Generate a contact with random characters in its name
274 current_contact = bt_contacts_utils.VCard()
275 current_contact.first_name = bt_contacts_utils.generate_random_string()
276 current_contact.last_name = bt_contacts_utils.generate_random_string()
277 current_contact.add_phone_number(
278 bt_contacts_utils.generate_random_phone_number())
279 vcards.append(current_contact)
280
281 # Generate a contact with only a phone number
282 current_contact = bt_contacts_utils.VCard()
283 current_contact.add_phone_number(
284 bt_contacts_utils.generate_random_phone_number())
285 vcards.append(current_contact)
286
287 # Generate a 2nd contact with only a phone number
288 current_contact = bt_contacts_utils.VCard()
289 current_contact.add_phone_number(
290 bt_contacts_utils.generate_random_phone_number())
291 vcards.append(current_contact)
292
293 bt_contacts_utils.create_new_contacts_vcf_from_vcards(
Phillip Walker827112a2016-09-08 16:27:19 -0700294 CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE, vcards)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700295
296 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
Phillip Walker827112a2016-09-08 16:27:19 -0700297 self.pse, CONTACTS_DESTINATION_PATH, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700298
299 return self.connect_and_verify(phone_numbers_added)
300
Phillip Walker827112a2016-09-08 16:27:19 -0700301 #@BluetoothTest(UUID=2aa2bd00-86cc-4f39-a06a-90b17ea5b320)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700302 def test_call_log(self):
303 """Test Call Log
304
305 Test that Call Logs are transfered
306
307 Precondition:
308 1. Devices are paired.
309
310 Steps:
311 1. Add a predefined list of calls to the PSE call log.
312 2. Connect PCE to PSE to allow call log transfer
313 3. Verify the Missed, Incoming, and Outgoing Call History
314
315 Returns:
316 Pass if True
317 Fail if False
318 """
319
320 bt_contacts_utils.add_call_log(
321 self.pse, bt_contacts_utils.INCOMMING_CALL_TYPE,
322 bt_contacts_utils.generate_random_phone_number().phone_number,
323 int(time()) * 1000)
324 bt_contacts_utils.add_call_log(
325 self.pse, bt_contacts_utils.INCOMMING_CALL_TYPE,
326 bt_contacts_utils.generate_random_phone_number().phone_number,
327 int(time()) * 1000 - 4 * CALL_LOG_TIME_OFFSET_IN_MSEC)
328 bt_contacts_utils.add_call_log(
329 self.pse, bt_contacts_utils.OUTGOING_CALL_TYPE,
330 bt_contacts_utils.generate_random_phone_number().phone_number,
331 int(time()) * 1000 - CALL_LOG_TIME_OFFSET_IN_MSEC)
332 bt_contacts_utils.add_call_log(
333 self.pse, bt_contacts_utils.MISSED_CALL_TYPE,
334 bt_contacts_utils.generate_random_phone_number().phone_number,
335 int(time()) * 1000 - 2 * CALL_LOG_TIME_OFFSET_IN_MSEC)
336 bt_contacts_utils.add_call_log(
337 self.pse, bt_contacts_utils.MISSED_CALL_TYPE,
338 bt_contacts_utils.generate_random_phone_number().phone_number,
339 int(time()) * 1000 - 2 * CALL_LOG_TIME_OFFSET_IN_MSEC)
340
341 bt_test_utils.connect_pri_to_sec(
342 self.log, self.pce, self.pse.droid,
343 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
344 pse_call_log_count = self.pse.droid.callLogGetCount()
345 self.log.info("Waiting for {} call logs to be transfered".format(
346 pse_call_log_count))
347 bt_contacts_utils.wait_for_call_log_update_complete(self.pce,
348 pse_call_log_count)
349
350 if not bt_contacts_utils.get_and_compare_call_logs(
351 self.pse, self.pce, bt_contacts_utils.INCOMMING_CALL_TYPE):
352 return False
353 if not bt_contacts_utils.get_and_compare_call_logs(
354 self.pse, self.pce, bt_contacts_utils.OUTGOING_CALL_TYPE):
355 return False
356 if not bt_contacts_utils.get_and_compare_call_logs(
357 self.pse, self.pce, bt_contacts_utils.MISSED_CALL_TYPE):
358 return False
359
360 return True