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 acts.test_utils.power.PowerBTBaseTest as PBtBT
18from acts.test_decorators import test_tracker_info
19
20
21class PowerBTscanTest(PBtBT.PowerBTBaseTest):
22    def ble_scan_base_func(self):
23        """Base function to start a generic BLE scan and measures the power
24
25        Steps:
26        1. Sets the phone in airplane mode, disables gestures and location
27        2. Turns ON/OFF BT, BLE and screen according to test conditions
28        3. Sends the adb shell command to PMC to start scan
29        4. Measures the power consumption
30        5. Asserts pass/fail criteria based on measured power
31        """
32        # Decode the test params from test name
33        attrs = ['screen_status', 'bt_status', 'ble_status', 'scan_mode']
34        indices = [2, 4, 6, -1]
35        self.decode_test_configs(attrs, indices)
36        if self.test_configs.scan_mode == 'lowpower':
37            scan_mode = 'low_power'
38        elif self.test_configs.scan_mode == 'lowlatency':
39            scan_mode = 'low_latency'
40        else:
41            scan_mode = self.test_configs.scan_mode
42        self.phone_setup_for_BT(self.test_configs.bt_status,
43                                self.test_configs.ble_status,
44                                self.test_configs.screen_status)
45        self.start_pmc_ble_scan(scan_mode, self.mon_info.offset,
46                                self.mon_info.duration)
47        self.measure_power_and_validate()
48
49    # Test Cases: BLE Scans + Filtered scans
50    @test_tracker_info(uuid='e9a36161-1d0c-4b9a-8bd8-80fef8cdfe28')
51    def test_screen_ON_bt_ON_ble_ON_default_scan_balanced(self):
52        self.ble_scan_base_func()
53
54    @test_tracker_info(uuid='5fa61bf4-5f04-40bf-af52-6644b534d02e')
55    def test_screen_OFF_bt_ON_ble_ON_filter_scan_opportunistic(self):
56        self.ble_scan_base_func()
57
58    @test_tracker_info(uuid='512b6cde-be83-43b0-b799-761380ba69ff')
59    def test_screen_OFF_bt_ON_ble_ON_filter_scan_lowpower(self):
60        self.ble_scan_base_func()
61
62    @test_tracker_info(uuid='3a526838-ae7b-4cdb-bc29-89a5503d2306')
63    def test_screen_OFF_bt_ON_ble_ON_filter_scan_balanced(self):
64        self.ble_scan_base_func()
65
66    @test_tracker_info(uuid='03a57cfd-4269-4a09-8544-84f878d2e801')
67    def test_screen_OFF_bt_ON_ble_ON_filter_scan_lowlatency(self):
68        self.ble_scan_base_func()
69
70    # Test Cases: Background scans
71    @test_tracker_info(uuid='20145317-e362-4bfd-9860-4ceddf764784')
72    def test_screen_ON_bt_OFF_ble_ON_background_scan_lowlatency(self):
73        self.ble_scan_base_func()
74
75    @test_tracker_info(uuid='00a53dc3-2c33-43c4-b356-dba93249b823')
76    def test_screen_ON_bt_OFF_ble_ON_background_scan_lowpower(self):
77        self.ble_scan_base_func()
78
79    @test_tracker_info(uuid='b7185d64-631f-4b18-8d0b-4e14b80db375')
80    def test_screen_OFF_bt_OFF_ble_ON_background_scan_lowlatency(self):
81        self.ble_scan_base_func()
82
83    @test_tracker_info(uuid='93eb05da-a577-409c-8208-6af1899a10c2')
84    def test_screen_OFF_bt_OFF_ble_ON_background_scan_lowpower(self):
85        self.ble_scan_base_func()
86