Add strict_checking argument in toggle_airplane_mode method.

In TelephonyBaseTest, call toggle_airplane_mode with strict_checking False.
Work around for https://buganizer.corp.google.com/issues/32341648.
Before getting the sim card phone number, make sure airplane mode is off.

Bug: 33178263
Test: None

Change-Id: I0a2845681870549bd96b4084e6469789549a5669
diff --git a/acts/framework/acts/test_utils/tel/TelephonyBaseTest.py b/acts/framework/acts/test_utils/tel/TelephonyBaseTest.py
index a3dae6d..98c21f8 100644
--- a/acts/framework/acts/test_utils/tel/TelephonyBaseTest.py
+++ b/acts/framework/acts/test_utils/tel/TelephonyBaseTest.py
@@ -156,6 +156,7 @@
         sim_conf_file = self.user_params["sim_conf_file"]
         # If the sim_conf_file is not a full path, attempt to find it
         # relative to the config file.
+
         if not os.path.isfile(sim_conf_file):
             sim_conf_file = os.path.join(
                 self.user_params[Config.key_config_path], sim_conf_file)
@@ -169,12 +170,13 @@
                 self.register_controller(acts.controllers.diag_logger,
                                          required=False))
         for ad in self.android_devices:
+            # Ensure the phone is not in airplane mode before setup_droid_properties
+            toggle_airplane_mode(self.log, ad, False, strict_checking=False)
             setup_droid_properties(self.log, ad, sim_conf_file)
 
             # Ensure that a test class starts from a consistent state that
             # improves chances of valid network selection and facilitates
             # logging.
-            toggle_airplane_mode(self.log, ad, True)
             if not set_phone_screen_on(self.log, ad):
                 self.log.error("Failed to set phone screen-on time.")
                 return False
@@ -217,7 +219,7 @@
         finally:
             for ad in self.android_devices:
                 try:
-                    toggle_airplane_mode(self.log, ad, True)
+                    toggle_airplane_mode(self.log, ad, True, strict_checking=False)
                 except BrokenPipeError:
                     # Broken Pipe, can not call SL4A API to turn on Airplane Mode.
                     # Use adb command to turn on Airplane Mode.
diff --git a/acts/framework/acts/test_utils/tel/tel_test_utils.py b/acts/framework/acts/test_utils/tel/tel_test_utils.py
index b29e39d..c840a94 100644
--- a/acts/framework/acts/test_utils/tel/tel_test_utils.py
+++ b/acts/framework/acts/test_utils/tel/tel_test_utils.py
@@ -166,6 +166,9 @@
             except KeyError:
                 number = ad.droid.telephonyGetLine1NumberForSubscription(
                     sub_id)
+            except Except as e:
+                log.error("Failed to setup_droid_property with {}".format(e))
+                raise
             if not number or number == "":
                 raise TelTestUtilsError(
                     "Failed to find valid phone number for {}"
@@ -239,18 +242,21 @@
     return len(valid_sims.keys())
 
 
-def toggle_airplane_mode(log, ad, new_state=None):
+def toggle_airplane_mode(log, ad, new_state=None, strict_checking=True):
     """ Toggle the state of airplane mode.
 
     Args:
+        log: log handler.
         ad: android_device object.
         new_state: Airplane mode state to set to.
             If None, opposite of the current state.
+        strict_checking: Whether to turn on strict checking that checks all features.
 
     Returns:
         result: True if operation succeed. False if error happens.
     """
-    return toggle_airplane_mode_msim(log, ad, new_state)
+    return toggle_airplane_mode_msim(log, ad, new_state,
+                                     strict_checking=strict_checking)
 
 
 def is_expected_event(event_to_check, events_list):
@@ -356,13 +362,15 @@
                 state)
 
 
-def toggle_airplane_mode_msim(log, ad, new_state=None):
+def toggle_airplane_mode_msim(log, ad, new_state=None, strict_checking=True):
     """ Toggle the state of airplane mode.
 
     Args:
+        log: log handler.
         ad: android_device object.
         new_state: Airplane mode state to set to.
             If None, opposite of the current state.
+        strict_checking: Whether to turn on strict checking that checks all features.
 
     Returns:
         result: True if operation succeed. False if error happens.
@@ -437,8 +445,11 @@
             log.error(
                   "Failed waiting for bluetooth during airplane mode toggle on {}".
                   format(ad.serial))
+            if strict_checking: return False
     except Exception as e:
-        log.error("Failed to waiting for bluetooth during airplane mode due to %s" % e)
+        log.error("Failed to check bluetooth state due to {}".format(e))
+        if strict_checking:
+            raise
 
     # APM on (new_state=True) will turn off wifi but may not turn it on
     if new_state and not _wait_for_wifi_in_state(log, ad, False,
@@ -3586,7 +3597,7 @@
                             WifiUtils.SSID_KEY]))
                     return False
             except Exception as e:
-                log.error("WifiUtils.wifi_connect not connected, no event.")
+                log.error("WifiUtils.wifi_connect failed with {}.".format(e))
                 return False
         except Exception as e:
             log.error("WifiUtils.wifi_connect exception: {}".format(e))