1# Copyright (C) 2022 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""CTS-V Nearby Mainline Fast Pair end-to-end test case: seeker can discover the provider.""" 16 17from test_helper import constants 18from test_helper import fast_pair_base_test 19 20# The model ID to simulate on provider side. 21PROVIDER_SIMULATOR_MODEL_ID = constants.DEFAULT_MODEL_ID 22# The public key to simulate as registered headsets. 23PROVIDER_SIMULATOR_ANTI_SPOOFING_KEY = constants.DEFAULT_ANTI_SPOOFING_KEY 24 25# Time in seconds for events waiting. 26BECOME_DISCOVERABLE_TIMEOUT_SEC = constants.BECOME_DISCOVERABLE_TIMEOUT_SEC 27START_ADVERTISING_TIMEOUT_SEC = constants.START_ADVERTISING_TIMEOUT_SEC 28SCAN_TIMEOUT_SEC = constants.SCAN_TIMEOUT_SEC 29 30 31class SeekerDiscoverProviderTest(fast_pair_base_test.FastPairBaseTest): 32 """Fast Pair seeker discover provider test.""" 33 34 def setup_test(self) -> None: 35 super().setup_test() 36 self._provider.start_model_id_advertising( 37 PROVIDER_SIMULATOR_MODEL_ID, PROVIDER_SIMULATOR_ANTI_SPOOFING_KEY) 38 self._provider.wait_for_discoverable_mode(BECOME_DISCOVERABLE_TIMEOUT_SEC) 39 self._provider.wait_for_advertising_start(START_ADVERTISING_TIMEOUT_SEC) 40 self._seeker.start_scan() 41 42 def teardown_test(self) -> None: 43 self._seeker.stop_scan() 44 self._provider.teardown_provider_simulator() 45 super().teardown_test() 46 47 def test_seeker_start_scanning_find_provider(self) -> None: 48 provider_ble_mac_address = self._provider.get_ble_mac_address() 49 self._seeker.wait_and_assert_provider_found( 50 timeout_seconds=SCAN_TIMEOUT_SEC, 51 expected_model_id=PROVIDER_SIMULATOR_MODEL_ID, 52 expected_ble_mac_address=provider_ble_mac_address) 53