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.power.PowerBTBaseTest as PBtBT
19import acts.test_utils.bt.bt_test_utils as btutils
20
21SCREEN_OFF_WAIT_TIME = 2
22
23
24class PowerBTidleTest(PBtBT.PowerBTBaseTest):
25    def setup_class(self):
26
27        super().setup_class()
28        btutils.enable_bluetooth(self.dut.droid, self.dut.ed)
29
30    # Test cases- Baseline
31    def test_bt_on_unconnected_connectable(self):
32        """BT turned on connectable mode.
33
34        Page scan only.
35        """
36        self.dut.droid.bluetoothMakeConnectable()
37        self.dut.droid.goToSleepNow()
38        time.sleep(SCREEN_OFF_WAIT_TIME)
39        self.measure_power_and_validate()
40
41    def test_bt_on_unconnected_discoverable(self):
42        """BT turned on discoverable mode.
43
44        Page and inquiry scan.
45        """
46        self.dut.droid.bluetoothMakeConnectable()
47        self.dut.droid.bluetoothMakeDiscoverable()
48        self.dut.droid.goToSleepNow()
49        time.sleep(SCREEN_OFF_WAIT_TIME)
50        self.measure_power_and_validate()
51
52    def test_bt_connected_idle(self):
53        """BT idle after connecting to headset.
54
55        """
56        btutils.connect_phone_to_headset(self.dut, self.bt_device, 60)
57        self.dut.droid.goToSleepNow()
58        time.sleep(SCREEN_OFF_WAIT_TIME)
59        self.measure_power_and_validate()
60