• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18from acts import utils
19import acts_contrib.test_utils.bt.BleEnum as bleenum
20import acts_contrib.test_utils.bt.bt_power_test_utils as btputils
21import acts_contrib.test_utils.bt.bt_test_utils as btutils
22import acts_contrib.test_utils.power.PowerBTBaseTest as PBtBT
23from acts_contrib.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
24
25BLE_LOCATION_SCAN_ENABLE = 'settings put secure location_mode 3'
26EXTRA_CON_TIME = 3
27SCAN_TAIL = 5
28
29
30class PowerBLEconnectionidleTest(PBtBT.PowerBTBaseTest):
31    def __init__(self, configs):
32        super().__init__(configs)
33        req_params = ['BLE_Connection_Priority']
34        self.unpack_userparams(req_params)
35        for con_priority in self.BLE_Connection_Priority:
36            self.generate_test_case_ble_idle_connection(con_priority)
37
38    def setup_class(self):
39        super().setup_class()
40        self.client_ad = self.android_devices[0]
41        utils.set_location_service(self.client_ad, True)
42        self.server_ad = self.android_devices[1]
43        self.Connection_duration = self.mon_info.duration + self.mon_offset + SCAN_TAIL + EXTRA_CON_TIME
44        setup_multiple_devices_for_bt_test(self.android_devices)
45
46    def setup_test(self):
47        super().setup_test()
48        time.sleep(5)
49        self.client_ad.adb.shell(BLE_LOCATION_SCAN_ENABLE)
50        btutils.enable_bluetooth(self.client_ad.droid, self.client_ad.ed)
51        if not self.server_ad.droid.bluetoothSetLocalName('advertiser'):
52            self.log.error("Failed rename the device")
53            return False
54        self.log.info("Renamed the BT device")
55        self.client_ad.droid.goToSleepNow()
56
57    def teardown_test(self):
58        self.client_ad.droid.bluetoothFactoryReset()
59        btutils.disable_bluetooth(self.client_ad.droid)
60        self.server_ad.droid.bluetoothFactoryReset()
61        btutils.disable_bluetooth(self.server_ad.droid)
62
63    def generate_test_case_ble_idle_connection(self, con_priority):
64        def test_case_fn():
65            self.measure_ble_connection_idle_power(con_priority)
66
67        test_case_name = ('test_BLE_{}_IDLE_CONNECTION'.format(
68            bleenum.BLEConnectionPriority(con_priority).name))
69        setattr(self, test_case_name, test_case_fn)
70
71    def measure_ble_connection_idle_power(self, con_priority):
72        btputils.establish_ble_connection(self.client_ad, self.server_ad,
73                                          con_priority)
74        time.sleep(EXTRA_CON_TIME)
75        self.measure_power_and_validate()
76