1#!/usr/bin/env python3 2# 3# Copyright (C) 2019 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 17import acts_contrib.test_utils.bt.bt_test_utils as btutils 18from acts_contrib.test_utils.bt.A2dpBaseTest import A2dpBaseTest 19from acts_contrib.test_utils.bt.bt_constants import ble_scan_settings_modes 20from acts_contrib.test_utils.bt.bt_test_utils import generate_ble_scan_objects 21from acts_contrib.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 22from acts_contrib.test_utils.bt.bt_constants import scan_result 23 24INIT_ATTEN = 0 25 26 27class BtA2dpRangeWithBleScanTest(A2dpBaseTest): 28 default_timeout = 10 29 30 def __init__(self, configs): 31 super().__init__(configs) 32 req_params = ['attenuation_vector', 'codecs'] 33 #'attenuation_vector' is a dict containing: start, stop and step of 34 #attenuation changes 35 #'codecs' is a list containing all codecs required in the tests 36 self.unpack_userparams(req_params) 37 for codec_config in self.codecs: 38 # Loop all BLE Scan modes 39 for scan_mode in ble_scan_settings_modes.items(): 40 self.generate_test_case(codec_config, scan_mode) 41 42 def setup_class(self): 43 super().setup_class() 44 opt_params = ['gain_mismatch', 'dual_chain'] 45 self.unpack_userparams(opt_params, dual_chain=None, gain_mismatch=None) 46 return setup_multiple_devices_for_bt_test(self.android_devices) 47 # Enable BQR on all android devices 48 btutils.enable_bqr(self.android_devices) 49 if hasattr(self, 'dual_chain') and self.dual_chain == 1: 50 self.atten_c0 = self.attenuators[0] 51 self.atten_c1 = self.attenuators[1] 52 self.atten_c0.set_atten(INIT_ATTEN) 53 self.atten_c1.set_atten(INIT_ATTEN) 54 55 def teardown_class(self): 56 super().teardown_class() 57 if hasattr(self, 'atten_c0') and hasattr(self, 'atten_c1'): 58 self.atten_c0.set_atten(INIT_ATTEN) 59 self.atten_c1.set_atten(INIT_ATTEN) 60 61 def generate_test_case(self, codec_config, scan_mode): 62 """ Below are the list of test case's user can choose to run. 63 Test case list: 64 "test_bt_a2dp_range_codec_AAC_with_BLE_scan_balanced" 65 "test_bt_a2dp_range_codec_AAC_with_BLE_scan_low_latency" 66 "test_bt_a2dp_range_codec_AAC_with_BLE_scan_low_power" 67 "test_bt_a2dp_range_codec_AAC_with_BLE_scan_opportunistic" 68 "test_bt_a2dp_range_codec_SBC_with_BLE_scan_balanced" 69 "test_bt_a2dp_range_codec_SBC_with_BLE_scan_low_latency" 70 "test_bt_a2dp_range_codec_SBC_with_BLE_scan_low_power" 71 "test_bt_a2dp_range_codec_SBC_with_BLE_scan_opportunistic" 72 """ 73 def test_case_fn(): 74 scan_callback = self.start_ble_scan(scan_mode[1]) 75 self.run_a2dp_to_max_range(codec_config) 76 self.dut.droid.bleStopBleScan(scan_callback) 77 self.log.info("BLE Scan stopped succssfully") 78 79 if hasattr(self, 'dual_chain') and self.dual_chain == 1: 80 test_case_name = 'test_dual_bt_a2dp_range_codec_{}_gainmimatch_{}dB'.format( 81 codec_config['codec_type'], self.gain_mismatch) 82 else: 83 test_case_name = 'test_bt_a2dp_range_codec_{}_with_BLE_scan_{}'.format( 84 codec_config['codec_type'], scan_mode[0]) 85 setattr(self, test_case_name, test_case_fn) 86 87 def start_ble_scan(self, scan_mode): 88 """ This function will start Ble Scan with different scan mode. 89 90 Args: 91 Scan_mode: Ble scan setting modes 92 93 returns: 94 Scan_callback: Ble scan callback 95 """ 96 97 self.dut.droid.bleSetScanSettingsScanMode(scan_mode) 98 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 99 self.dut.droid) 100 self.dut.droid.bleStartBleScan(filter_list, scan_settings, 101 scan_callback) 102 self.log.info("BLE Scanning started succssfully") 103 return scan_callback 104