• 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 acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
21from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
22from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
23from queue import Empty
24import time
25
26
27class BtAirplaneModeTest(BluetoothBaseTest):
28    default_timeout = 10
29    grace_timeout = 4
30    WAIT_TIME_ANDROID_STATE_SETTLING = 5
31
32    def __init__(self, controllers):
33        BluetoothBaseTest.__init__(self, controllers)
34        self.dut = self.android_devices[0]
35
36    def setup_test(self):
37        super(BluetoothBaseTest, self).setup_test()
38        # Ensure testcase starts with Airplane mode off
39        if not toggle_airplane_mode(self.log, self.dut, False):
40            return False
41        time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING)
42        return True
43
44    @BluetoothBaseTest.bt_test_wrap
45    def test_bt_on_toggle_airplane_mode_on(self):
46        """Test that toggles airplane mode on while BT on
47
48        Turning airplane mode on should toggle Bluetooth off
49        successfully.
50
51        Steps:
52        1. Verify that Bluetooth state is on
53        2. Turn airplane mode on
54        3. Verify that Bluetooth state is off
55
56        Expected Result:
57        Bluetooth should toggle off successfully.
58
59        Returns:
60          Pass if True
61          Fail if False
62
63        TAGS: Bluetooth, Airplane
64        Priority: 3
65        """
66        if not bluetooth_enabled_check(self.dut):
67            self.log.error("Failed to set Bluetooth state to enabled")
68            return False
69        if not toggle_airplane_mode(self.log, self.dut, True):
70            self.log.error("Failed to toggle airplane mode on")
71            return False
72        return not self.dut.droid.bluetoothCheckState()
73
74    @BluetoothBaseTest.bt_test_wrap
75    def test_bt_on_toggle_airplane_mode_on_bt_remains_off(self):
76        """Test that verifies BT remains off after airplane mode toggles
77
78        Turning airplane mode on should toggle Bluetooth off
79        successfully and Bluetooth state should remain off. For
80        this test we will use 60 seconds as a baseline.
81
82        Steps:
83        1. Verify that Bluetooth state is on
84        2. Turn airplane mode on
85        3. Verify that Bluetooth state is off
86        3. Verify tat Bluetooth state remains off for 60 seconds
87
88        Expected Result:
89        Bluetooth should remain toggled off.
90
91        Returns:
92          Pass if True
93          Fail if False
94
95        TAGS: Bluetooth, Airplane
96        Priority: 3
97        """
98        if not bluetooth_enabled_check(self.dut):
99            self.log.error("Failed to set Bluetooth state to enabled")
100            return False
101        if not toggle_airplane_mode(self.log, self.dut, True):
102            self.log.error("Failed to toggle airplane mode on")
103            return False
104        toggle_timeout = 60
105        self.log.info(
106            "Waiting {} seconds until verifying Bluetooth state.".format(
107                toggle_timeout))
108        time.sleep(toggle_timeout)
109        return not self.dut.droid.bluetoothCheckState()
110
111    @BluetoothBaseTest.bt_test_wrap
112    def test_bt_on_toggle_airplane_mode_on_then_off(self):
113        """Test that toggles airplane mode both on and off
114
115        Turning airplane mode on should toggle Bluetooth off
116        successfully. Turning airplane mode off should toggle
117        Bluetooth back on.
118
119        Steps:
120        1. Verify that Bluetooth state is on
121        2. Turn airplane mode on
122        3. Verify that Bluetooth state is off
123        4. Turn airplane mode off
124        5. Verify that Bluetooth state is on
125
126        Expected Result:
127        Bluetooth should toggle off successfully.
128
129        Returns:
130          Pass if True
131          Fail if False
132
133        TAGS: Bluetooth, Airplane
134        Priority: 3
135        """
136        if not bluetooth_enabled_check(self.dut):
137            self.log.error("Failed to set Bluetooth state to enabled")
138            return False
139        if not toggle_airplane_mode(self.log, self.dut, True):
140            self.log.error("Failed to toggle airplane mode on")
141            return False
142        if not toggle_airplane_mode(self.log, self.dut, False):
143            self.log.error("Failed to toggle airplane mode off")
144            return False
145        time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING)
146        return self.dut.droid.bluetoothCheckState()
147