blob: f28ca832743ef5c7ee3b5a33bcfb993a624263fa [file] [log] [blame]
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -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 Agarwalc96b9cc2016-08-18 12:01:04 -070016"""
17Test script to test the pairing scenarios and setting priorities.
18"""
19
20import time
21
tturneyb72742f2017-08-29 17:46:50 -070022from acts.test_decorators import test_tracker_info
tturneye3934a22016-10-20 15:47:34 -070023from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070024from acts.base_test import BaseTestClass
25from acts.test_utils.bt import bt_test_utils
26from acts.test_utils.car import car_bt_utils
27from acts.test_utils.bt import BtEnum
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070028
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070029# Timed wait between Bonding happens and Android actually gets the list of
30# supported services (and subsequently updates the priorities)
31BOND_TO_SDP_WAIT = 3
tturney34ee54d2016-11-16 15:29:02 -080032UNBOND_TIMEOUT = 3
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070033
tturneye3934a22016-10-20 15:47:34 -070034
35class BtCarPairingTest(BluetoothBaseTest):
36 def __init__(self, controllers):
37 BluetoothBaseTest.__init__(self, controllers)
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070038 self.car = self.android_devices[0]
39 self.ph = self.android_devices[1]
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070040
Timofey Protopopove1192232018-05-02 15:04:42 -070041 def teardown_test(self):
42 for ad in self.android_devices:
43 bt_test_utils.clear_bonded_devices(ad)
44 # Give the stack time to unbond.
45 time.sleep(UNBOND_TIMEOUT)
46
tturneyb72742f2017-08-29 17:46:50 -070047 @test_tracker_info(uuid='f56e915-eef7-45cd-b5a6-771f6ef72602')
tturneye3934a22016-10-20 15:47:34 -070048 @BluetoothBaseTest.bt_test_wrap
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070049 def test_simple_pairing(self):
50 """
Phillip Walker827112a2016-09-08 16:27:19 -070051 Tests if after first pairing the remote device has the default
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070052 priorities for A2DP and HFP.
53
54 Steps:
55 1. Pair the devices (do not connect)
56 2. Check the priorities.
57
58 Returns:
59 Pass if True
60 Fail if False
61
62 Priority: 0
63 """
64 # Pair the devices.
tturney46060782016-11-14 16:44:38 -080065 if not bt_test_utils.pair_pri_to_sec(
66 self.car, self.ph, attempts=1, auto_confirm=False):
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070067 self.log.error("cannot pair")
68 return False
69
Sanket Agarwalbd9689b2016-08-24 11:14:53 -070070 # Sleep because priorities are not event driven.
71 time.sleep(BOND_TO_SDP_WAIT)
72
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070073 # Check that the default priority for HFP and A2DP is ON.
74 ph_hfp_p = self.car.droid.bluetoothHfpClientGetPriority(
75 self.ph.droid.bluetoothGetLocalAddress())
76 if ph_hfp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
77 self.log.error("hfp {} priority {} expected {}".format(
tturney45962522016-11-16 13:12:44 -080078 self.ph.serial, ph_hfp_p,
79 BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070080 return False
81
82 ph_a2dp_p = self.car.droid.bluetoothA2dpSinkGetPriority(
83 self.ph.droid.bluetoothGetLocalAddress())
84 if ph_a2dp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
85 self.log.error("a2dp {} priority {} expected {}".format(
tturney45962522016-11-16 13:12:44 -080086 self.ph.serial, ph_a2dp_p,
87 BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070088 return False
89
90 ph_pbap_p = self.car.droid.bluetoothPbapClientGetPriority(
91 self.ph.droid.bluetoothGetLocalAddress())
92 if ph_pbap_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
93 self.log.error("pbap {} priority {} expected {}".format(
tturney45962522016-11-16 13:12:44 -080094 self.ph.serial, ph_pbap_p,
95 BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -070096 return False
97 return True
98
tturneyb72742f2017-08-29 17:46:50 -070099 @test_tracker_info(uuid='be4db211-10a0-479a-8958-dff0ccadca1a')
tturneye3934a22016-10-20 15:47:34 -0700100 @BluetoothBaseTest.bt_test_wrap
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700101 def test_repairing(self):
102 """
103 Tests that even if we modify the priorities, on unpair and pair
104 we will reset the priorities.
105
106 Steps:
107 1. Pair the devices (do not connect)
108 2. Unset the priorities for HFP and A2DP
109 3. Pair again
110 4. Check the priorities, they should be set to default.
111
112 Returns:
113 Pass if True
114 Fail if False
115
116 Priority: 0
117 """
118 # Pair the devices.
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700119 self.log.info("Pairing the devices ...")
tturney46060782016-11-14 16:44:38 -0800120 if not bt_test_utils.pair_pri_to_sec(
121 self.car, self.ph, attempts=1, auto_confirm=False):
tturney34ee54d2016-11-16 15:29:02 -0800122 self.log.error("Failed to pair devices.")
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700123 return False
124
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700125 # Timed wait for the profile priorities to propagate.
126 time.sleep(BOND_TO_SDP_WAIT)
127
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700128 # Set the priority to OFF for ALL car profiles.
tturney34ee54d2016-11-16 15:29:02 -0800129 self.car.log.info("Set priorities off ...")
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700130 car_bt_utils.set_car_profile_priorities_off(self.car, self.ph)
131
132 # Now unpair the devices.
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700133 self.log.info("Resetting the devices ...")
tturney34ee54d2016-11-16 15:29:02 -0800134 for ad in self.android_devices:
135 bt_test_utils.clear_bonded_devices(ad)
136 # Give the stack time to unbond.
137 time.sleep(UNBOND_TIMEOUT)
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700138
139 # Pair them again!
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700140 self.log.info("Pairing them again ...")
tturney46060782016-11-14 16:44:38 -0800141 if not bt_test_utils.pair_pri_to_sec(
142 self.car, self.ph, attempts=1, auto_confirm=False):
tturney34ee54d2016-11-16 15:29:02 -0800143 self.log.error("Faild to pair devices.")
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700144 return False
145
Sanket Agarwalbd9689b2016-08-24 11:14:53 -0700146 # Timed wait for the profile priorities to propagate.
147 time.sleep(BOND_TO_SDP_WAIT)
148
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700149 # Check the default priorities.
150 ph_hfp_p = self.car.droid.bluetoothHfpClientGetPriority(
151 self.ph.droid.bluetoothGetLocalAddress())
152 if ph_hfp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
tturney34ee54d2016-11-16 15:29:02 -0800153 self.hf.log.error("HFP priority found: {}, expected: {}.".format(
154 ph_hfp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700155 return False
156
157 ph_a2dp_p = self.car.droid.bluetoothA2dpSinkGetPriority(
158 self.ph.droid.bluetoothGetLocalAddress())
159 if ph_a2dp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
tturney34ee54d2016-11-16 15:29:02 -0800160 self.ph.log.error("A2DP priority found: {}, expected {}.".format(
161 ph_a2dp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
Sanket Agarwalc96b9cc2016-08-18 12:01:04 -0700162 return False
163
164 return True