• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#/usr/bin/env python3.4
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Test script to test various airplane mode scenarios and how it
18affects Bluetooth state.
19"""
20from queue import Empty
21import time
22from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
23from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
24
25
26class BtAirplaneModeTest(BluetoothBaseTest):
27    default_timeout = 10
28    grace_timeout = 4
29
30    def __init__(self, controllers):
31        BluetoothBaseTest.__init__(self, controllers)
32        self.dut = self.android_devices[0]
33
34    @BluetoothBaseTest.bt_test_wrap
35    def test_bt_on_toggle_airplane_mode_on(self):
36        """Test that toggles airplane mode on while BT on
37
38        Turning airplane mode on should toggle Bluetooth off
39        successfully.
40
41        Steps:
42        1. Verify that Bluetooth state is on
43        2. Turn airplane mode on
44        3. Verify that Bluetooth state is off
45
46        Expected Result:
47        Bluetooth should toggle off successfully.
48
49        Returns:
50          Pass if True
51          Fail if False
52
53        TAGS: Bluetooth, Airplane
54        Priority: 3
55        """
56        if not bluetooth_enabled_check(self.dut):
57            self.log.error("Failed to set Bluetooth state to enabled")
58            return False
59        self.dut.droid.connectivityToggleAirplaneMode(True)
60        # Since there is no callback for airplane mode toggling we need
61        # to give the connectivity manger grace time to turn off the radios.
62        time.sleep(self.grace_timeout)
63        return not self.dut.droid.bluetoothCheckState()
64
65    @BluetoothBaseTest.bt_test_wrap
66    def test_bt_on_toggle_airplane_mode_on_bt_remains_off(self):
67        """Test that verifies BT remains off after airplane mode toggles
68
69        Turning airplane mode on should toggle Bluetooth off
70        successfully and Bluetooth state should remain off. For
71        this test we will use 60 seconds as a baseline.
72
73        Steps:
74        1. Verify that Bluetooth state is on
75        2. Turn airplane mode on
76        3. Verify that Bluetooth state is off
77        3. Verify tat Bluetooth state remains off for 60 seconds
78
79        Expected Result:
80        Bluetooth should remain toggled off.
81
82        Returns:
83          Pass if True
84          Fail if False
85
86        TAGS: Bluetooth, Airplane
87        Priority: 3
88        """
89        if not bluetooth_enabled_check(self.dut):
90            self.log.error("Failed to set Bluetooth state to enabled")
91            return False
92        self.dut.droid.connectivityToggleAirplaneMode(True)
93        toggle_timeout = 60
94        self.log.info(
95            "Waiting {} seconds until verifying Bluetooth state.".format(
96                toggle_timeout))
97        time.sleep(toggle_timeout)
98        return not self.dut.droid.bluetoothCheckState()
99
100    @BluetoothBaseTest.bt_test_wrap
101    def test_bt_on_toggle_airplane_mode_on_then_off(self):
102        """Test that toggles airplane mode both on and off
103
104        Turning airplane mode on should toggle Bluetooth off
105        successfully. Turning airplane mode off should toggle
106        Bluetooth back on.
107
108        Steps:
109        1. Verify that Bluetooth state is on
110        2. Turn airplane mode on
111        3. Verify that Bluetooth state is off
112        4. Turn airplane mode off
113        5. Verify that Bluetooth state is on
114
115        Expected Result:
116        Bluetooth should toggle off successfully.
117
118        Returns:
119          Pass if True
120          Fail if False
121
122        TAGS: Bluetooth, Airplane
123        Priority: 3
124        """
125        if not bluetooth_enabled_check(self.dut):
126            self.log.error("Failed to set Bluetooth state to enabled")
127            return False
128        self.dut.droid.connectivityToggleAirplaneMode(True)
129        self.dut.droid.connectivityToggleAirplaneMode(False)
130        # Since there is no callback for airplane mode toggling off we need
131        # to give the connectivity manger grace time to turn on the radios.
132        time.sleep(self.grace_timeout)
133        return self.dut.droid.bluetoothCheckState()
134