blob: bacf4c4acc90d58b892c5b7c0a3dfb8e83073831 [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
tturneye3934a22016-10-20 15:47:34 -070019import os
tturney46060782016-11-14 16:44:38 -080020import time
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070021
tturneye3934a22016-10-20 15:47:34 -070022from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080023from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070024from acts.base_test import BaseTestClass
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070025from acts.test_utils.bt import bt_contacts_utils
Joseph Pirozzof304d362016-06-17 15:15:40 -070026from acts.test_utils.bt import bt_test_utils
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070027from acts.test_utils.car import car_bt_utils
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070028from acts.utils import exe_cmd
Joseph Pirozzof304d362016-06-17 15:15:40 -070029import acts.test_utils.bt.BtEnum as BtEnum
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070030
Joseph Pirozzof304d362016-06-17 15:15:40 -070031# Offset call logs by 1 minute
32CALL_LOG_TIME_OFFSET_IN_MSEC = 60000
tturneye3934a22016-10-20 15:47:34 -070033PSE_CONTACTS_FILE = "psecontacts.vcf"
34PCE_CONTACTS_FILE = "pcecontacts.vcf"
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080035MERGED_CONTACTS_FILE = "psecombined.vcf"
36STANDART_CONTACT_COUNT = 100
Joseph Pirozzof304d362016-06-17 15:15:40 -070037
tturneye3934a22016-10-20 15:47:34 -070038
39class BtCarPbapTest(BluetoothBaseTest):
40 contacts_destination_path = ""
41
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070042 def __init__(self, controllers):
43 BaseTestClass.__init__(self, controllers)
44 self.pce = self.android_devices[0]
45 self.pse = self.android_devices[1]
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080046 self.pse2 = self.android_devices[2]
tturneye3934a22016-10-20 15:47:34 -070047 self.contacts_destination_path = self.log_path + "/"
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070048
49 def setup_class(self):
tturneye3934a22016-10-20 15:47:34 -070050 if not super(BtCarPbapTest, self).setup_class():
51 return False
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080052 permissions_list = [
53 "android.permission.READ_CONTACTS",
54 "android.permission.WRITE_CONTACTS",
55 "android.permission.READ_EXTERNAL_STORAGE"
56 ]
tturney1f7b7b52016-11-17 15:28:22 -080057 for permission in permissions_list:
58 self.pse.adb.shell(
59 "pm grant com.google.android.contacts {}".format(permission))
60 for permission in permissions_list:
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080061 self.pce.adb.shell("pm grant com.android.contacts {}".format(
62 permission))
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070063
64 # Pair the devices.
65 # This call may block until some specified timeout in bt_test_utils.py.
tturney46060782016-11-14 16:44:38 -080066 # Grace time inbetween stack state changes
67
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080068 setup_multiple_devices_for_bt_test(self.android_devices)
69 if not bt_test_utils.pair_pri_to_sec(self.pce, self.pse):
70 self.log.error("Failed to pair.")
71 return False
72 time.sleep(3)
73 if not bt_test_utils.pair_pri_to_sec(self.pce, self.pse2):
74 self.log.error("Failed to pair.")
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070075 return False
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -070076
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070077 # Disable the HFP and A2DP profiles. This will ensure only PBAP
78 # gets connected. Also, this will eliminate the auto-connect loop.
79 car_bt_utils.set_car_profile_priorities_off(self.pce, self.pse)
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080080 car_bt_utils.set_car_profile_priorities_off(self.pce, self.pse2)
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070081
82 # Enable PBAP on PSE & PCE.
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070083
Joseph Pirozzof304d362016-06-17 15:15:40 -070084 self.pse.droid.bluetoothChangeProfileAccessPermission(
85 self.pce.droid.bluetoothGetLocalAddress(),
86 BtEnum.BluetoothProfile.PBAP_SERVER.value,
87 BtEnum.BluetoothAccessLevel.ACCESS_ALLOWED.value)
88
Joseph Pirozzo8ce09592017-01-05 13:57:37 -080089 self.pse2.droid.bluetoothChangeProfileAccessPermission(
90 self.pce.droid.bluetoothGetLocalAddress(),
91 BtEnum.BluetoothProfile.PBAP_SERVER.value,
92 BtEnum.BluetoothAccessLevel.ACCESS_ALLOWED.value)
93
94 bt_test_utils.set_profile_priority(
95 self.pce, self.pse, [BtEnum.BluetoothProfile.PBAP_CLIENT],
96 BtEnum.BluetoothPriorityLevel.PRIORITY_ON)
97 bt_test_utils.set_profile_priority(
98 self.pce, self.pse2, [BtEnum.BluetoothProfile.PBAP_CLIENT],
99 BtEnum.BluetoothPriorityLevel.PRIORITY_ON)
100
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700101 return True
102
103 def setup_test(self):
tturneye3934a22016-10-20 15:47:34 -0700104 if not super(BtCarPbapTest, self).setup_test():
105 return False
Joseph Pirozzof304d362016-06-17 15:15:40 -0700106 self.pse.droid.callLogsEraseAll()
107 if not (bt_contacts_utils.erase_contacts(self.pse) and
108 bt_contacts_utils.erase_contacts(self.pce)):
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700109 return False
Joseph Pirozzof304d362016-06-17 15:15:40 -0700110 # Allow all content providers to synchronize.
tturney46060782016-11-14 16:44:38 -0800111 time.sleep(1)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700112 return True
113
114 def teardown_test(self):
tturneye3934a22016-10-20 15:47:34 -0700115 if not super(BtCarPbapTest, self).teardown_test():
116 return False
Joseph Pirozzof304d362016-06-17 15:15:40 -0700117 self.pce.droid.bluetoothPbapClientDisconnect(
118 self.pse.droid.bluetoothGetLocalAddress())
119 bt_contacts_utils.erase_contacts(self.pse)
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700120 return True
121
Joseph Pirozzof304d362016-06-17 15:15:40 -0700122 def verify_contacts_match(self):
tturneye3934a22016-10-20 15:47:34 -0700123 bt_contacts_utils.export_device_contacts_to_vcf(
124 self.pce, self.contacts_destination_path, PCE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700125 return bt_contacts_utils.count_contacts_with_differences(
tturneye3934a22016-10-20 15:47:34 -0700126 self.contacts_destination_path, PCE_CONTACTS_FILE,
127 PSE_CONTACTS_FILE) == 0
Joseph Pirozzof304d362016-06-17 15:15:40 -0700128
129 def connect_and_verify(self, count):
130 bt_test_utils.connect_pri_to_sec(
tturneye3934a22016-10-20 15:47:34 -0700131 self.pce, self.pse,
Joseph Pirozzof304d362016-06-17 15:15:40 -0700132 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
133 bt_contacts_utils.wait_for_phone_number_update_complete(self.pce,
134 count)
135 contacts_added = self.verify_contacts_match()
136 self.pce.droid.bluetoothPbapClientDisconnect(
137 self.pse.droid.bluetoothGetLocalAddress())
138 contacts_removed = bt_contacts_utils.wait_for_phone_number_update_complete(
139 self.pce, 0)
140 return contacts_added and contacts_removed
141
Phillip Walker827112a2016-09-08 16:27:19 -0700142 #@BluetoothTest(UUID=7dcdecfc-42d1-4f41-b66e-823c8f161356)
tturneye3934a22016-10-20 15:47:34 -0700143 @BluetoothBaseTest.bt_test_wrap
Joseph Pirozzof304d362016-06-17 15:15:40 -0700144 def test_pbap_connect_and_disconnect(self):
145 """Test Connectivity
146
147 Test connecting with the server enabled and disabled
148
149 Precondition:
150 1. Devices are paired.
151
152 Steps:
153 1. Disable permission on PSE to prevent PCE from connecting
154 2. Attempt to connect PCE to PSE
155 3. Verify connection failed
156 4. Enable permission on PSE to allow PCE to connect
157 5. Attempt to connect PCE to PSE
158 6. Verify connection succeeded
159
160 Returns:
161 Pass if True
162 Fail if False
163 """
164 self.pse.droid.bluetoothChangeProfileAccessPermission(
165 self.pce.droid.bluetoothGetLocalAddress(),
166 BtEnum.BluetoothProfile.PBAP_SERVER.value,
167 BtEnum.BluetoothAccessLevel.ACCESS_DENIED.value)
168 if bt_test_utils.connect_pri_to_sec(
tturneye3934a22016-10-20 15:47:34 -0700169 self.pce, self.pse,
Joseph Pirozzof304d362016-06-17 15:15:40 -0700170 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value])):
Joseph Pirozzo8ce09592017-01-05 13:57:37 -0800171 self.log.error("Client connected and shouldn't be.")
Joseph Pirozzof304d362016-06-17 15:15:40 -0700172 return False
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700173
Joseph Pirozzof304d362016-06-17 15:15:40 -0700174 self.pce.droid.bluetoothPbapClientDisconnect(
175 self.pse.droid.bluetoothGetLocalAddress())
176
177 self.pse.droid.bluetoothChangeProfileAccessPermission(
178 self.pce.droid.bluetoothGetLocalAddress(),
179 BtEnum.BluetoothProfile.PBAP_SERVER.value,
180 BtEnum.BluetoothAccessLevel.ACCESS_ALLOWED.value)
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700181
Joseph Pirozzo8ce09592017-01-05 13:57:37 -0800182 if not bt_test_utils.connect_pri_to_sec(
183 self.pce, self.pse,
184 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value])):
185 self.log.error("No client connected and should be.")
Joseph Pirozzof304d362016-06-17 15:15:40 -0700186 return False
187
188 return True
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700189
Phillip Walker827112a2016-09-08 16:27:19 -0700190 #@BluetoothTest(UUID=1733efb9-71af-4956-bd3a-0d3167d94d0c)
tturneye3934a22016-10-20 15:47:34 -0700191 @BluetoothBaseTest.bt_test_wrap
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700192 def test_contact_download(self):
193 """Test Contact Download
194
195 Test download of contacts from a clean state.
196
Joseph Pirozzof304d362016-06-17 15:15:40 -0700197 Precondition:
198 1. Devices are paired.
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700199
Joseph Pirozzof304d362016-06-17 15:15:40 -0700200 Steps:
201 1. Erase contacts from PSE and PCE.
202 2. Add a predefined list of contacts to PSE.
203 3. Connect PCE to PSE to perform transfer.
204 4. Compare transfered contacts.
205 5. Disconnect.
206 6. Verify PCE cleaned up contact list.
207
208 Returns:
209 Pass if True
210 Fail if False
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700211 """
tturneye3934a22016-10-20 15:47:34 -0700212 bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
213 PSE_CONTACTS_FILE, 100)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700214 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
tturneye3934a22016-10-20 15:47:34 -0700215 self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700216 bt_test_utils.connect_pri_to_sec(
tturneye3934a22016-10-20 15:47:34 -0700217 self.pce, self.pse,
Joseph Pirozzof304d362016-06-17 15:15:40 -0700218 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
219 bt_contacts_utils.wait_for_phone_number_update_complete(
220 self.pce, phone_numbers_added)
221 if not self.verify_contacts_match():
222 return False
Phillip Walker827112a2016-09-08 16:27:19 -0700223 return bt_contacts_utils.erase_contacts(self.pce)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700224
Phillip Walker827112a2016-09-08 16:27:19 -0700225 #@BluetoothTest(UUID=99dc6ac6-b7cf-45ce-927b-8c4ebf8ab664)
tturneye3934a22016-10-20 15:47:34 -0700226 @BluetoothBaseTest.bt_test_wrap
Joseph Pirozzof304d362016-06-17 15:15:40 -0700227 def test_modify_phonebook(self):
228 """Test Modify Phonebook
229
230 Test changing contacts and reconnecting PBAP.
231
232 Precondition:
233 1. Devices are paired.
234
235 Steps:
236 1. Add a predefined list of contacts to PSE.
237 2. Connect PCE to PSE to perform transfer.
238 3. Verify that contacts match.
239 4. Change some contacts on the PSE.
240 5. Reconnect PCE to PSE to perform transfer.
241 6. Verify that new contacts match.
242
243 Returns:
244 Pass if True
245 Fail if False
246 """
tturneye3934a22016-10-20 15:47:34 -0700247 bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
248 PSE_CONTACTS_FILE, 100)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700249 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
tturneye3934a22016-10-20 15:47:34 -0700250 self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700251 if not self.connect_and_verify(phone_numbers_added):
252 return False
253
Joseph Pirozzo66fb3f62016-05-31 16:57:39 -0700254 bt_contacts_utils.erase_contacts(self.pse)
tturneye3934a22016-10-20 15:47:34 -0700255 bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
256 PSE_CONTACTS_FILE, 110, 2)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700257 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
tturneye3934a22016-10-20 15:47:34 -0700258 self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700259 return self.connect_and_verify(phone_numbers_added)
260
Phillip Walker827112a2016-09-08 16:27:19 -0700261 #@BluetoothTest(UUID=bbe31bf5-51e8-4175-b266-1c7750e44f5b)
tturneye3934a22016-10-20 15:47:34 -0700262 @BluetoothBaseTest.bt_test_wrap
Joseph Pirozzof304d362016-06-17 15:15:40 -0700263 def test_special_contacts(self):
264 """Test Special Contacts
265
266 Test numerous special cases of contacts that could cause errors.
267
268 Precondition:
269 1. Devices are paired.
270
271 Steps:
272 1. Add a predefined list of contacts to PSE that includes special cases:
273 2. Connect PCE to PSE to perform transfer.
274 3. Verify that contacts match.
275
276 Returns:
277 Pass if True
278 Fail if False
279 """
280
281 vcards = []
282
283 # Generate a contact with no email address
284 current_contact = bt_contacts_utils.VCard()
285 current_contact.first_name = "Mr."
286 current_contact.last_name = "Smiley"
287 current_contact.add_phone_number(
288 bt_contacts_utils.generate_random_phone_number())
289 vcards.append(current_contact)
290
291 # Generate a 2nd contact with the same name but different phone number
292 current_contact = bt_contacts_utils.VCard()
293 current_contact.first_name = "Mr."
294 current_contact.last_name = "Smiley"
295 current_contact.add_phone_number(
296 bt_contacts_utils.generate_random_phone_number())
297 vcards.append(current_contact)
298
299 # Generate a contact with no name
300 current_contact = bt_contacts_utils.VCard()
301 current_contact.email = "{}@gmail.com".format(
302 bt_contacts_utils.generate_random_string())
303 current_contact.add_phone_number(
304 bt_contacts_utils.generate_random_phone_number())
305 vcards.append(current_contact)
306
307 # Generate a contact with random characters in its name
308 current_contact = bt_contacts_utils.VCard()
309 current_contact.first_name = bt_contacts_utils.generate_random_string()
310 current_contact.last_name = bt_contacts_utils.generate_random_string()
311 current_contact.add_phone_number(
312 bt_contacts_utils.generate_random_phone_number())
313 vcards.append(current_contact)
314
315 # Generate a contact with only a phone number
316 current_contact = bt_contacts_utils.VCard()
317 current_contact.add_phone_number(
318 bt_contacts_utils.generate_random_phone_number())
319 vcards.append(current_contact)
320
321 # Generate a 2nd contact with only a phone number
322 current_contact = bt_contacts_utils.VCard()
323 current_contact.add_phone_number(
324 bt_contacts_utils.generate_random_phone_number())
325 vcards.append(current_contact)
326
327 bt_contacts_utils.create_new_contacts_vcf_from_vcards(
tturneye3934a22016-10-20 15:47:34 -0700328 self.contacts_destination_path, PSE_CONTACTS_FILE, vcards)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700329
330 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
tturneye3934a22016-10-20 15:47:34 -0700331 self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700332
333 return self.connect_and_verify(phone_numbers_added)
334
Phillip Walker827112a2016-09-08 16:27:19 -0700335 #@BluetoothTest(UUID=2aa2bd00-86cc-4f39-a06a-90b17ea5b320)
tturneye3934a22016-10-20 15:47:34 -0700336 @BluetoothBaseTest.bt_test_wrap
Joseph Pirozzof304d362016-06-17 15:15:40 -0700337 def test_call_log(self):
338 """Test Call Log
339
340 Test that Call Logs are transfered
341
342 Precondition:
343 1. Devices are paired.
344
345 Steps:
346 1. Add a predefined list of calls to the PSE call log.
347 2. Connect PCE to PSE to allow call log transfer
348 3. Verify the Missed, Incoming, and Outgoing Call History
349
350 Returns:
351 Pass if True
352 Fail if False
353 """
354
355 bt_contacts_utils.add_call_log(
356 self.pse, bt_contacts_utils.INCOMMING_CALL_TYPE,
357 bt_contacts_utils.generate_random_phone_number().phone_number,
tturney46060782016-11-14 16:44:38 -0800358 int(time.time() * 1000))
Joseph Pirozzof304d362016-06-17 15:15:40 -0700359 bt_contacts_utils.add_call_log(
360 self.pse, bt_contacts_utils.INCOMMING_CALL_TYPE,
361 bt_contacts_utils.generate_random_phone_number().phone_number,
tturney46060782016-11-14 16:44:38 -0800362 int(time.time()) * 1000 - 4 * CALL_LOG_TIME_OFFSET_IN_MSEC)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700363 bt_contacts_utils.add_call_log(
364 self.pse, bt_contacts_utils.OUTGOING_CALL_TYPE,
365 bt_contacts_utils.generate_random_phone_number().phone_number,
tturney46060782016-11-14 16:44:38 -0800366 int(time.time()) * 1000 - CALL_LOG_TIME_OFFSET_IN_MSEC)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700367 bt_contacts_utils.add_call_log(
368 self.pse, bt_contacts_utils.MISSED_CALL_TYPE,
369 bt_contacts_utils.generate_random_phone_number().phone_number,
tturney46060782016-11-14 16:44:38 -0800370 int(time.time()) * 1000 - 2 * CALL_LOG_TIME_OFFSET_IN_MSEC)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700371 bt_contacts_utils.add_call_log(
372 self.pse, bt_contacts_utils.MISSED_CALL_TYPE,
373 bt_contacts_utils.generate_random_phone_number().phone_number,
tturney46060782016-11-14 16:44:38 -0800374 int(time.time()) * 1000 - 2 * CALL_LOG_TIME_OFFSET_IN_MSEC)
Joseph Pirozzof304d362016-06-17 15:15:40 -0700375
Joseph Pirozzo8ce09592017-01-05 13:57:37 -0800376 self.pce.droid.bluetoothPbapClientDisconnect(
377 self.pse.droid.bluetoothGetLocalAddress())
378 self.pce.droid.bluetoothPbapClientDisconnect(
379 self.pse2.droid.bluetoothGetLocalAddress())
380
Joseph Pirozzof304d362016-06-17 15:15:40 -0700381 bt_test_utils.connect_pri_to_sec(
tturneye3934a22016-10-20 15:47:34 -0700382 self.pce, self.pse,
Joseph Pirozzof304d362016-06-17 15:15:40 -0700383 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
384 pse_call_log_count = self.pse.droid.callLogGetCount()
Joseph Pirozzo8ce09592017-01-05 13:57:37 -0800385 self.log.info("Waiting for {} call logs to be transfered".format(
Joseph Pirozzof304d362016-06-17 15:15:40 -0700386 pse_call_log_count))
387 bt_contacts_utils.wait_for_call_log_update_complete(self.pce,
388 pse_call_log_count)
389
390 if not bt_contacts_utils.get_and_compare_call_logs(
391 self.pse, self.pce, bt_contacts_utils.INCOMMING_CALL_TYPE):
392 return False
393 if not bt_contacts_utils.get_and_compare_call_logs(
394 self.pse, self.pce, bt_contacts_utils.OUTGOING_CALL_TYPE):
395 return False
396 if not bt_contacts_utils.get_and_compare_call_logs(
397 self.pse, self.pce, bt_contacts_utils.MISSED_CALL_TYPE):
398 return False
399
400 return True
Joseph Pirozzo8ce09592017-01-05 13:57:37 -0800401
402 def test_multiple_phones(self):
403 """Test Multiple Phones
404
405 Test that connects two phones and confirms contacts are transfered
406 and merged while still being associated with their original phone.
407
408 Precondition:
409 1. Devices are paired.
410
411 Steps:
412 1. Add a unique list of contacts to PSE on each phone.
413 2. Connect PCE to PSE 1 to perform transfer.
414 3. Verify contacts match.
415 4. Connect PCE to PSE 2 to perform transfer.
416 5. Verify that the PCE has a union set of contacts from
417 PSE 1 and PSE 2.
418 6. Disconnect PCE from PSE 1 to clean up contacts.
419 7. Verify that only PSE 2 contacts remain on PCE and they match.
420 8. Disconnect PCE from PSE 2 to clean up contacts.
421
422 Returns:
423 Pass if True
424 Fail if False
425 """
426
427 PSE1_CONTACTS_FILE = "{}{}".format(PSE_CONTACTS_FILE, "1")
428 PSE2_CONTACTS_FILE = "{}{}".format(PSE_CONTACTS_FILE, "2")
429
430 bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
431 PSE1_CONTACTS_FILE, 100)
432 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
433 self.pse, self.contacts_destination_path, PSE1_CONTACTS_FILE)
434 bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
435 PSE2_CONTACTS_FILE, 100)
436 phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
437 self.pse2, self.contacts_destination_path, PSE2_CONTACTS_FILE)
438
439 self.pce.droid.bluetoothPbapClientDisconnect(
440 self.pse.droid.bluetoothGetLocalAddress())
441 self.pce.droid.bluetoothPbapClientDisconnect(
442 self.pse2.droid.bluetoothGetLocalAddress())
443
444 bt_test_utils.connect_pri_to_sec(
445 self.pce, self.pse,
446 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
447 bt_contacts_utils.wait_for_phone_number_update_complete(self.pce, 100)
448 bt_contacts_utils.export_device_contacts_to_vcf(
449 self.pce, self.contacts_destination_path, PCE_CONTACTS_FILE)
450 pse1_matches = bt_contacts_utils.count_contacts_with_differences(
451 self.contacts_destination_path, PCE_CONTACTS_FILE,
452 PSE1_CONTACTS_FILE) == 0
453
454 bt_test_utils.connect_pri_to_sec(
455 self.pce, self.pse2,
456 set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
457
458 bt_contacts_utils.wait_for_phone_number_update_complete(self.pce, 200)
459
460 bt_contacts_utils.export_device_contacts_to_vcf(
461 self.pce, self.contacts_destination_path, PCE_CONTACTS_FILE)
462
463 merged_file = open('{}{}'.format(self.contacts_destination_path,
464 MERGED_CONTACTS_FILE), 'w')
465 for contacts_file in [PSE1_CONTACTS_FILE, PSE2_CONTACTS_FILE]:
466 infile = open(self.contacts_destination_path + contacts_file)
467 merged_file.write(infile.read())
468
469 self.log.info("Checking combined phonebook.")
470 pse1andpse2_matches = bt_contacts_utils.count_contacts_with_differences(
471 self.contacts_destination_path, PCE_CONTACTS_FILE,
472 MERGED_CONTACTS_FILE) == 0
473
474 self.pce.droid.bluetoothPbapClientDisconnect(
475 self.pse.droid.bluetoothGetLocalAddress())
476 bt_contacts_utils.wait_for_phone_number_update_complete(self.pce, 100)
477
478 self.log.info("Checking phonebook after disconnecting first device.")
479 bt_contacts_utils.export_device_contacts_to_vcf(
480 self.pce, self.contacts_destination_path, PCE_CONTACTS_FILE)
481 pse2_matches = bt_contacts_utils.count_contacts_with_differences(
482 self.contacts_destination_path, PCE_CONTACTS_FILE,
483 PSE2_CONTACTS_FILE) == 0
484
485 bt_contacts_utils.erase_contacts(self.pse)
486 bt_contacts_utils.erase_contacts(self.pse2)
487 return pse1_matches and pse2_matches and pse1andpse2_matches