1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - The Android Open Source Project
48
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
18import acts.test_utils.power.PowerWiFiBaseTest as PWBT
19from acts import utils
20from acts.test_utils.wifi import wifi_test_utils as wutils
21
22
23class PowerCoexBaseTest(PBtBT.PowerBTBaseTest, PWBT.PowerWiFiBaseTest):
24    """Base class for BT power related tests.
25
26    Inherited from the PowerBaseTest class
27    """
28    def coex_test_phone_setup(self, Screen_status, WiFi_status, WiFi_band,
29                              BT_status, BLE_status, Cellular_status,
30                              Celluar_band):
31        """Setup the phone in desired state for coex tests.
32
33        Args:
34            Screen_status: 'ON' or 'OFF'
35            WiFi_status: 'ON', 'Connected', 'Disconnected', or 'OFF'
36            WiFi_band: '2g', '5g' or None, the band of AP
37            BT_status: 'ON' or 'OFF'
38            BLE_status: 'ON' or 'OFF'
39            Cellular_status: 'ON' or 'OFF'
40            Celluar_band: 'Verizon', 'Tmobile', or 'ATT' for live network,
41                actual band for callbox setup; 'None' when celluar is OFF
42        """
43        # Setup WiFi
44        if WiFi_status == 'ON':
45            wutils.wifi_toggle_state(self.dut, True)
46        elif WiFi_status == 'Connected':
47            self.setup_ap_connection(self.main_network[WiFi_band])
48        elif WiFi_status == 'Disconnected':
49            self.setup_ap_connection(self.main_network[WiFi_band],
50                                     connect=False)
51
52        # Setup BT/BLE
53        self.phone_setup_for_BT(BT_status, BLE_status, Screen_status)
54
55        # Setup Cellular
56        if Cellular_status == 'ON':
57            self.dut.droid.connectivityToggleAirplaneMode(False)
58            utils.set_mobile_data_always_on(self.dut, True)
59
60    def coex_scan_setup(self, WiFi_scan, BLE_scan_mode, wifi_scan_command):
61        """Setup for scan activities on WiFi, BT/BLE, and cellular.
62
63        Args:
64            WiFi_scan: 'ON', 'OFF' or 'PNO'
65            BLE_scan_mode: 'balanced', 'opportunistic', 'low_power', or 'low_latency'
66        """
67        if WiFi_scan == 'ON':
68            self.dut.adb.shell(wifi_scan_command)
69        if WiFi_scan == 'PNO':
70            self.log.info(
71                'Set attenuation so device loses connection to trigger PNO scans'
72            )
73            # Set to maximum attenuation 95 dB to cut down connection
74            [self.attenuators[i].set_atten(95) for i in range(self.num_atten)]
75        if BLE_scan_mode is not None:
76            self.start_pmc_ble_scan(BLE_scan_mode, self.mon_info.offset,
77                                    self.mon_info.duration)
78