Use common airplane mode functionality

Bug: b/31457256
Change-Id: I1758b38558c152ff8e6117185639d31d2670c819
(cherry picked from commit f50dc6033df404a85dda9a1b719b290bead657c1)
diff --git a/acts/framework/acts/test_utils/bt/bt_test_utils.py b/acts/framework/acts/test_utils/bt/bt_test_utils.py
index 29e34ca..5f03908 100644
--- a/acts/framework/acts/test_utils/bt/bt_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_test_utils.py
@@ -507,7 +507,7 @@
                 return True
         time.sleep(1)
     # Timed out trying to bond.
-    log.debug("Failed to bond devices.")
+    log.info("Failed to bond devices.")
     return False
 
 
diff --git a/acts/tests/google/bt/BtAirplaneModeTest.py b/acts/tests/google/bt/BtAirplaneModeTest.py
index be97126..c0e137c 100644
--- a/acts/tests/google/bt/BtAirplaneModeTest.py
+++ b/acts/tests/google/bt/BtAirplaneModeTest.py
@@ -17,20 +17,30 @@
 Test script to test various airplane mode scenarios and how it
 affects Bluetooth state.
 """
-from queue import Empty
-import time
 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
 from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
+from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
+from queue import Empty
+import time
 
 
 class BtAirplaneModeTest(BluetoothBaseTest):
     default_timeout = 10
     grace_timeout = 4
+    WAIT_TIME_ANDROID_STATE_SETTLING = 5
 
     def __init__(self, controllers):
         BluetoothBaseTest.__init__(self, controllers)
         self.dut = self.android_devices[0]
 
+    def setup_test(self):
+        super().setup_test()
+        # Ensure testcase starts with Airplane mode off
+        if not toggle_airplane_mode(self.log, self.dut, False):
+            return False
+        time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING)
+        return True
+
     @BluetoothBaseTest.bt_test_wrap
     def test_bt_on_toggle_airplane_mode_on(self):
         """Test that toggles airplane mode on while BT on
@@ -56,10 +66,9 @@
         if not bluetooth_enabled_check(self.dut):
             self.log.error("Failed to set Bluetooth state to enabled")
             return False
-        self.dut.droid.connectivityToggleAirplaneMode(True)
-        # Since there is no callback for airplane mode toggling we need
-        # to give the connectivity manger grace time to turn off the radios.
-        time.sleep(self.grace_timeout)
+        if not toggle_airplane_mode(self.log, self.dut, True):
+            self.log.error("Failed to toggle airplane mode on")
+            return False
         return not self.dut.droid.bluetoothCheckState()
 
     @BluetoothBaseTest.bt_test_wrap
@@ -89,7 +98,9 @@
         if not bluetooth_enabled_check(self.dut):
             self.log.error("Failed to set Bluetooth state to enabled")
             return False
-        self.dut.droid.connectivityToggleAirplaneMode(True)
+        if not toggle_airplane_mode(self.log, self.dut, True):
+            self.log.error("Failed to toggle airplane mode on")
+            return False
         toggle_timeout = 60
         self.log.info(
             "Waiting {} seconds until verifying Bluetooth state.".format(
@@ -125,9 +136,11 @@
         if not bluetooth_enabled_check(self.dut):
             self.log.error("Failed to set Bluetooth state to enabled")
             return False
-        self.dut.droid.connectivityToggleAirplaneMode(True)
-        self.dut.droid.connectivityToggleAirplaneMode(False)
-        # Since there is no callback for airplane mode toggling off we need
-        # to give the connectivity manger grace time to turn on the radios.
-        time.sleep(self.grace_timeout)
+        if not toggle_airplane_mode(self.log, self.dut, True):
+            self.log.error("Failed to toggle airplane mode on")
+            return False
+        if not toggle_airplane_mode(self.log, self.dut, False):
+            self.log.error("Failed to toggle airplane mode off")
+            return False
+        time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING)
         return self.dut.droid.bluetoothCheckState()
diff --git a/acts/tests/google/bt/pan/BtPanTest.py b/acts/tests/google/bt/pan/BtPanTest.py
index d28526f..609176b 100644
--- a/acts/tests/google/bt/pan/BtPanTest.py
+++ b/acts/tests/google/bt/pan/BtPanTest.py
@@ -22,11 +22,12 @@
 
 This device was not intended to run in a sheild box.
 """
-
+import time
 from queue import Empty
 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
 from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
 from acts.test_utils.bt.bt_test_utils import pair_pri_to_sec
+from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
 from acts.test_utils.tel.tel_test_utils import verify_http_connection
 
 
@@ -61,7 +62,9 @@
         TAGS: Classic, PAN, tethering
         Priority: 1
         """
-        self.panu_dut.droid.connectivityToggleAirplaneMode(True)
+        if not toggle_airplane_mode(self.log, self.panu_dut, True):
+            self.log.error("Failed to toggle airplane mode on")
+            return False
         if not bluetooth_enabled_check(self.panu_dut):
             return False
         self.pan_dut.droid.bluetoothPanSetBluetoothTethering(True)
@@ -80,3 +83,4 @@
             return False
         self.pan_dut.droid.bluetoothPanSetBluetoothTethering(False)
         return True
+