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