1#!/usr/bin/env python3.4 2# 3# Copyright 2018 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of 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, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import time 18import acts.test_utils.bt.BleEnum as bleenum 19import acts.test_utils.bt.bt_power_test_utils as btputils 20import acts.test_utils.power.PowerBTBaseTest as PBtBT 21 22BLE_LOCATION_SCAN_ENABLE = 'settings put secure location_mode 3' 23EXTRA_SCAN_TIME = 3 24SCAN_TAIL = 5 25 26 27class PowerBLEscanTest(PBtBT.PowerBTBaseTest): 28 def __init__(self, configs): 29 super().__init__(configs) 30 req_params = ['scan_modes'] 31 self.unpack_userparams(req_params) 32 33 for scan_mode in self.scan_modes: 34 self.generate_test_case_no_devices_around(scan_mode) 35 36 def setup_class(self): 37 38 super().setup_class() 39 self.dut.adb.shell(BLE_LOCATION_SCAN_ENABLE) 40 # Make sure during power measurement, scan is always on 41 self.scan_duration = self.mon_info.duration + self.mon_offset + SCAN_TAIL + EXTRA_SCAN_TIME 42 43 def generate_test_case_no_devices_around(self, scan_mode): 44 def test_case_fn(): 45 46 self.measure_ble_scan_power(scan_mode) 47 48 test_case_name = ('test_BLE_{}_no_advertisers'.format( 49 bleenum.ScanSettingsScanMode(scan_mode).name)) 50 setattr(self, test_case_name, test_case_fn) 51 52 def measure_ble_scan_power(self, scan_mode): 53 54 btputils.start_apk_ble_scan(self.dut, scan_mode, self.scan_duration) 55 time.sleep(EXTRA_SCAN_TIME) 56 self.measure_power_and_validate() 57