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