Merge "Making preferred RAT type setting non-blocking"
diff --git a/acts/framework/acts/controllers/amarisoft_lib/config_utils.py b/acts/framework/acts/controllers/amarisoft_lib/config_utils.py
index 3dad7a3..bafe144 100644
--- a/acts/framework/acts/controllers/amarisoft_lib/config_utils.py
+++ b/acts/framework/acts/controllers/amarisoft_lib/config_utils.py
@@ -1,4 +1,4 @@
-!/usr/bin/env python3
+#!/usr/bin/env python3
 #
 #   Copyright 2022 - Google
 #
diff --git a/acts/framework/acts/controllers/cellular_lib/LteSimulation.py b/acts/framework/acts/controllers/cellular_lib/LteSimulation.py
index 96c4416..ef2aa60 100644
--- a/acts/framework/acts/controllers/cellular_lib/LteSimulation.py
+++ b/acts/framework/acts/controllers/cellular_lib/LteSimulation.py
@@ -211,7 +211,8 @@
         41: 39650,
         42: 41590,
         43: 45590,
-        66: 66436
+        66: 66436,
+        67: 67336
     }
 
     # Peak throughput lookup tables for each TDD subframe
diff --git a/acts/framework/acts/controllers/fuchsia_lib/utils_lib.py b/acts/framework/acts/controllers/fuchsia_lib/utils_lib.py
index 3fc1813..16c7e8c 100644
--- a/acts/framework/acts/controllers/fuchsia_lib/utils_lib.py
+++ b/acts/framework/acts/controllers/fuchsia_lib/utils_lib.py
@@ -15,14 +15,13 @@
 #   limitations under the License.
 
 import backoff
-import itertools
 import os
 import logging
 import paramiko
 import psutil
-import shutil
 import socket
 import tarfile
+import tempfile
 import time
 import usbinfo
 
@@ -254,26 +253,33 @@
     else:
         raise ValueError('A suitable build could not be found.')
 
-    tmp_path = '/tmp/%s_%s' % (str(int(
-        time.time() * 10000)), fuchsia_device.board_type)
-    os.mkdir(tmp_path)
-    if file_download_needed:
-        job.run('gsutil cp %s %s' % (file_to_download, tmp_path))
-        logging.info('Downloading %s to %s' % (file_to_download, tmp_path))
-        image_tgz = os.path.basename(file_to_download)
-    else:
-        job.run('cp %s %s' % (fuchsia_device.specific_image, tmp_path))
-        logging.info('Copying %s to %s' % (file_to_download, tmp_path))
-        image_tgz = os.path.basename(fuchsia_device.specific_image)
+    tmp_dir = tempfile.TemporaryDirectory(suffix=fuchsia_device.board_type)
+    with tmp_dir as tmp_path:
+        if file_download_needed:
+            logging.info('Downloading %s to %s' % (file_to_download, tmp_path))
+            job.run('gsutil cp %s %s' % (file_to_download, tmp_dir.name))
+            image_tgz = os.path.join(tmp_path,
+                                     os.path.basename(file_to_download))
+        else:
+            image_tgz = file_to_download
 
-    job.run('tar xfvz %s/%s -C %s' % (tmp_path, image_tgz, tmp_path))
-    all_files = []
-    for root, _dirs, files in itertools.islice(os.walk(tmp_path), 1, None):
-        for filename in files:
-            all_files.append(os.path.join(root, filename))
-    for filename in all_files:
-        shutil.move(filename, tmp_path)
+        tar = tarfile.open(image_tgz, 'r:gz')
+        tar.extractall(tmp_path)
+        tar.close()
 
+        reboot_to_bootloader(fuchsia_device, use_ssh,
+                             fuchsia_reconnect_after_reboot_time)
+
+        logging.info(
+            f'Flashing {fuchsia_device.orig_ip} with {image_tgz} using authorized keys "{fuchsia_device.authorized_file}".'
+        )
+        run_flash_script(fuchsia_device, tmp_path)
+    return True
+
+
+def reboot_to_bootloader(fuchsia_device,
+                         use_ssh=False,
+                         fuchsia_reconnect_after_reboot_time=5):
     if use_ssh:
         logging.info('Sending reboot command via SSH to '
                      'get into bootloader.')
@@ -327,16 +333,17 @@
                 flash_process_found = True
         if not flash_process_found:
             break
-    logging.info(f'Flashing {fuchsia_device.orig_ip} with {tmp_path}/{image_tgz} using authorized keys "{fuchsia_device.authorized_file}".')
+
+
+def run_flash_script(fuchsia_device, flash_dir):
     try:
-        flash_output = job.run(f'bash {tmp_path}/flash.sh --ssh-key={fuchsia_device.authorized_file} -s {fuchsia_device.serial_number}', timeout=120)
+        flash_output = job.run(
+            f'bash {flash_dir}/flash.sh --ssh-key={fuchsia_device.authorized_file} -s {fuchsia_device.serial_number}',
+            timeout=120)
         logging.debug(flash_output.stderr)
     except job.TimeoutError as err:
         raise TimeoutError(err)
-    try:
-        os.rmdir(tmp_path)
-    except Exception:
-        job.run('rm -fr %s' % tmp_path)
+
     logging.info('Waiting %s seconds for device'
                  ' to come back up after flashing.' % AFTER_FLASH_BOOT_TIME)
     time.sleep(AFTER_FLASH_BOOT_TIME)
@@ -361,4 +368,3 @@
     else:
         raise ValueError('Invalid IP: %s after flashing.' %
                          fuchsia_device.orig_ip)
-    return True
diff --git a/acts_tests/acts_contrib/test_utils/cellular/cellular_base_test.py b/acts_tests/acts_contrib/test_utils/cellular/cellular_base_test.py
index 87f04fd..7314514 100644
--- a/acts_tests/acts_contrib/test_utils/cellular/cellular_base_test.py
+++ b/acts_tests/acts_contrib/test_utils/cellular/cellular_base_test.py
@@ -41,6 +41,7 @@
     PARAM_SIM_TYPE_LTE = "lte"
     PARAM_SIM_TYPE_LTE_CA = "lteca"
     PARAM_SIM_TYPE_LTE_IMS = "lteims"
+    PARAM_SIM_TYPE_NR = "nr"
     PARAM_SIM_TYPE_UMTS = "umts"
     PARAM_SIM_TYPE_GSM = "gsm"
 
@@ -220,6 +221,8 @@
             self.init_simulation(self.PARAM_SIM_TYPE_LTE_CA)
         elif self.consume_parameter(self.PARAM_SIM_TYPE_LTE_IMS):
             self.init_simulation(self.PARAM_SIM_TYPE_LTE_IMS)
+        elif self.consume_parameter(self.PARAM_SIM_TYPE_NR):
+            self.init_simulation(self.PARAM_SIM_TYPE_NR)
         elif self.consume_parameter(self.PARAM_SIM_TYPE_UMTS):
             self.init_simulation(self.PARAM_SIM_TYPE_UMTS)
         elif self.consume_parameter(self.PARAM_SIM_TYPE_GSM):
@@ -333,6 +336,9 @@
         simulation_dictionary = {
             self.PARAM_SIM_TYPE_LTE: lte_sim.LteSimulation,
             self.PARAM_SIM_TYPE_LTE_CA: lte_sim.LteSimulation,
+            # The LteSimulation class is able to handle NR cells as well.
+            # The long-term goal is to consolidate all simulation classes.
+            self.PARAM_SIM_TYPE_NR: lte_sim.LteSimulation,
             self.PARAM_SIM_TYPE_UMTS: umts_sim.UmtsSimulation,
             self.PARAM_SIM_TYPE_GSM: gsm_sim.GsmSimulation,
             self.PARAM_SIM_TYPE_LTE_IMS: lteims_sim.LteImsSimulation
diff --git a/acts_tests/acts_contrib/test_utils/tel/tel_5g_test_utils.py b/acts_tests/acts_contrib/test_utils/tel/tel_5g_test_utils.py
index 5b81979..c6e20bc 100644
--- a/acts_tests/acts_contrib/test_utils/tel/tel_5g_test_utils.py
+++ b/acts_tests/acts_contrib/test_utils/tel/tel_5g_test_utils.py
@@ -108,10 +108,10 @@
         return True
 
 
-def provision_both_devices_for_volte(log, ads):
-    # LTE attach and enable VoLTE on both phones
-    tasks = [(phone_setup_volte, (log, ads[0])),
-             (phone_setup_volte, (log, ads[1]))]
+def provision_both_devices_for_volte(log, ads, nw_gen, nr_type=None):
+    # LTE or NR attach and enable VoLTE on both phones
+    tasks = [(phone_setup_volte, (log, ads[0], nw_gen, nr_type)),
+             (phone_setup_volte, (log, ads[1], nw_gen, nr_type))]
     if not multithread_func(log, tasks):
         log.error("phone failed to set up in volte")
         return False
diff --git a/acts_tests/acts_contrib/test_utils/tel/tel_data_utils.py b/acts_tests/acts_contrib/test_utils/tel/tel_data_utils.py
index 05808f9..ec6398c 100644
--- a/acts_tests/acts_contrib/test_utils/tel/tel_data_utils.py
+++ b/acts_tests/acts_contrib/test_utils/tel/tel_data_utils.py
@@ -77,6 +77,7 @@
 from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_default_state
 from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_idle_iwlan
 from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_iwlan
+from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_on_rat
 from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_voice_general
 from acts_contrib.test_utils.tel.tel_phone_setup_utils import wait_for_voice_attach_for_subscription
 from acts_contrib.test_utils.tel.tel_test_utils import _check_file_existence
@@ -847,7 +848,7 @@
 def test_data_connectivity_multi_bearer(
         log,
         android_devices,
-        nw_gen=None,
+        rat=None,
         simultaneous_voice_data=True,
         call_direction=DIRECTION_MOBILE_ORIGINATED,
         nr_type=None):
@@ -875,19 +876,17 @@
     ad_list = [android_devices[0], android_devices[1]]
     ensure_phones_idle(log, ad_list)
 
-    if nw_gen == GEN_5G:
-        if not provision_device_for_5g(log, android_devices, nr_type=nr_type):
-            return False
-    elif nw_gen:
-        if not ensure_network_generation_for_subscription(
-                log, android_devices[0], android_devices[0]
-                .droid.subscriptionGetDefaultDataSubId(), nw_gen,
-                MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA):
-            log.error("Device failed to reselect in {}s.".format(
-                MAX_WAIT_TIME_NW_SELECTION))
+    if rat:
+        if not phone_setup_on_rat(log,
+                                  android_devices[0],
+                                  rat,
+                                  sub_id=android_devices[0]
+                                  .droid.subscriptionGetDefaultDataSubId(),
+                                  nr_type=nr_type):
             return False
     else:
-        log.debug("Skipping network generation since it is None")
+        android_devices[0].log.debug(
+            "Skipping setup network rat since it is None")
 
     if not wait_for_voice_attach_for_subscription(
             log, android_devices[0], android_devices[0]
@@ -1213,24 +1212,34 @@
 def test_call_setup_in_active_data_transfer(
         log,
         ads,
-        nw_gen=None,
+        rat=None,
+        is_airplane_mode=False,
+        wfc_mode=None,
+        wifi_ssid=None,
+        wifi_pwd=None,
+        nr_type=None,
         call_direction=DIRECTION_MOBILE_ORIGINATED,
-        allow_data_transfer_interruption=False,
-        nr_type=None):
+        allow_data_transfer_interruption=False):
     """Test call can be established during active data connection.
 
     Turn off airplane mode, disable WiFi, enable Cellular Data.
-    Make sure phone in <nw_gen>.
+    Make sure phone in <rat>.
     Starting downloading file from Internet.
     Initiate a voice call. Verify call can be established.
     Hangup Voice Call, verify file is downloaded successfully.
     Note: file download will be suspended when call is initiated if voice
           is using voice channel and voice channel and data channel are
           on different RATs.
+
     Args:
         log: log object.
         ads: list of android objects, this list should have two ad.
-        nw_gen: network generation.
+        rat: network rat.
+        is_airplane_mode: True to turn APM on during WFC, False otherwise.
+        wfc_mode: Calling preference of WFC, e.g., Wi-Fi/mobile network.
+        wifi_ssid: Wi-Fi ssid to connect with.
+        wifi_pwd: Password of target Wi-Fi AP.
+        nr_type: 'sa' for 5G standalone, 'nsa' for 5G non-standalone.
         call_direction: MO(DIRECTION_MOBILE_ORIGINATED) or MT(DIRECTION_MOBILE_TERMINATED) call.
         allow_data_transfer_interruption: if allow to interrupt data transfer.
 
@@ -1248,23 +1257,18 @@
                                    caller_verifier, callee_verifier,
                                    wait_time_in_call)
 
-    if nw_gen == GEN_5G:
-        if not provision_device_for_5g(log, ads[0], nr_type=nr_type):
-            return False
-    elif nw_gen:
-        if not ensure_network_generation(log, ads[0], nw_gen,
-                                         MAX_WAIT_TIME_NW_SELECTION,
-                                         NETWORK_SERVICE_DATA):
-            ads[0].log.error("Device failed to reselect in %s.",
-                             MAX_WAIT_TIME_NW_SELECTION)
-            return False
-
-        ads[0].droid.telephonyToggleDataConnection(True)
-        if not wait_for_cell_data_connection(log, ads[0], True):
-            ads[0].log.error("Data connection is not on cell")
+    if rat:
+        if not phone_setup_on_rat(log,
+                                  ads[0],
+                                  rat,
+                                  is_airplane_mode=is_airplane_mode,
+                                  wfc_mode=wfc_mode,
+                                  wifi_ssid=wifi_ssid,
+                                  wifi_pwd=wifi_pwd,
+                                  nr_type=nr_type):
             return False
     else:
-        ads[0].log.debug("Skipping network generation since it is None")
+        ads[0].log.debug("Skipping setup network rat since it is None")
 
     if not verify_internet_connection(log, ads[0]):
         ads[0].log.error("Internet connection is not available")
@@ -1304,8 +1308,8 @@
             return False
     # Disable airplane mode if test under apm on.
     toggle_airplane_mode(log, ads[0], False)
-    if nw_gen == GEN_5G and not check_current_network_5g(ads[0],
-                                                         nr_type=nr_type):
+    if rat and '5g' in rat and not check_current_network_5g(ads[0],
+                                                            nr_type=nr_type):
         ads[0].log.error("Phone not attached on 5G after call.")
         return False
     return True
@@ -1314,40 +1318,44 @@
 def test_call_setup_in_active_youtube_video(
         log,
         ads,
-        nw_gen=None,
-        call_direction=DIRECTION_MOBILE_ORIGINATED,
-        allow_data_transfer_interruption=False,
-        nr_type=None):
+        rat=None,
+        is_airplane_mode=False,
+        wfc_mode=None,
+        wifi_ssid=None,
+        wifi_pwd=None,
+        nr_type=None,
+        call_direction=DIRECTION_MOBILE_ORIGINATED):
     """Test call can be established during active data connection.
 
     Turn off airplane mode, disable WiFi, enable Cellular Data.
-    Make sure phone in <nw_gen>.
+    Make sure phone in <rat>.
     Starting playing youtube video.
     Initiate a voice call. Verify call can be established.
+
     Args:
         log: log object.
         ads: list of android objects, this list should have two ad.
-        nw_gen: network generation.
+        rat: network rat.
+        is_airplane_mode: True to turn APM on during WFC, False otherwise.
+        wfc_mode: Calling preference of WFC, e.g., Wi-Fi/mobile network.
+        wifi_ssid: Wi-Fi ssid to connect with.
+        wifi_pwd: Password of target Wi-Fi AP.
+        nr_type: 'sa' for 5G standalone, 'nsa' for 5G non-standalone.
         call_direction: MO(DIRECTION_MOBILE_ORIGINATED) or MT(DIRECTION_MOBILE_TERMINATED) call.
-        allow_data_transfer_interruption: if allow to interrupt data transfer.
 
     Returns:
         True if success.
         False if failed.
     """
-    if nw_gen == GEN_5G:
-        if not provision_device_for_5g(log, ads[0], nr_type=nr_type):
-            return False
-    elif nw_gen:
-        if not ensure_network_generation(log, ads[0], nw_gen,
-                                         MAX_WAIT_TIME_NW_SELECTION,
-                                         NETWORK_SERVICE_DATA):
-            ads[0].log.error("Device failed to reselect in %s.",
-                             MAX_WAIT_TIME_NW_SELECTION)
-            return False
-        ads[0].droid.telephonyToggleDataConnection(True)
-        if not wait_for_cell_data_connection(log, ads[0], True):
-            ads[0].log.error("Data connection is not on cell")
+    if rat:
+        if not phone_setup_on_rat(log,
+                                  ads[0],
+                                  rat,
+                                  is_airplane_mode=is_airplane_mode,
+                                  wfc_mode=wfc_mode,
+                                  wifi_ssid=wifi_ssid,
+                                  wifi_pwd=wifi_pwd,
+                                  nr_type=nr_type):
             return False
     else:
         ensure_phones_default_state(log, ads)
@@ -1383,8 +1391,8 @@
     ad_download.force_stop_apk("com.google.android.youtube")
     # Disable airplane mode if test under apm on.
     toggle_airplane_mode(log, ads[0], False)
-    if nw_gen == GEN_5G and not check_current_network_5g(ads[0],
-                                                         nr_type=nr_type):
+    if rat and '5g' in rat and not check_current_network_5g(ads[0],
+                                                            nr_type=nr_type):
         ads[0].log.error("Phone not attached on 5G after call.")
         result = False
     return result
diff --git a/acts_tests/acts_contrib/test_utils/wifi/wifi_test_utils.py b/acts_tests/acts_contrib/test_utils/wifi/wifi_test_utils.py
index 1729a7c..3c5d2d5 100755
--- a/acts_tests/acts_contrib/test_utils/wifi/wifi_test_utils.py
+++ b/acts_tests/acts_contrib/test_utils/wifi/wifi_test_utils.py
@@ -49,6 +49,8 @@
 SHORT_TIMEOUT = 30
 ROAMING_TIMEOUT = 30
 WIFI_CONNECTION_TIMEOUT_DEFAULT = 30
+DEFAULT_SCAN_TRIES = 3
+DEFAULT_CONNECT_TRIES = 3
 # Speed of light in m/s.
 SPEED_OF_LIGHT = 299792458
 
@@ -1474,7 +1476,8 @@
 
 def connect_to_wifi_network(ad, network, assert_on_fail=True,
                             check_connectivity=True, hidden=False,
-                            num_of_scan_tries=3, num_of_connect_tries=3):
+                            num_of_scan_tries=DEFAULT_SCAN_TRIES,
+                            num_of_connect_tries=DEFAULT_CONNECT_TRIES):
     """Connection logic for open and psk wifi networks.
 
     Args:
@@ -2039,11 +2042,12 @@
     Returns:
         ping output if successful, NULL otherwise.
     """
+    android_version = ad.adb.shell("getprop ro.vendor.build.version.release")
     # wait_time to allow for DHCP to complete.
     for i in range(wait_time):
-        if ad.droid.connectivityNetworkIsConnected(
-        ) and ad.droid.connectivityGetIPv4DefaultGateway():
-            break
+        if ad.droid.connectivityNetworkIsConnected():
+            if (android_version > 10 and ad.droid.connectivityGetIPv4DefaultGateway()) or android_version < 11:
+                break
         time.sleep(1)
     ping = False
     try:
@@ -2051,7 +2055,7 @@
         ad.log.info("Http ping result: %s.", ping)
     except:
         pass
-    if not ping and ping_gateway:
+    if android_version > 10 and not ping and ping_gateway:
         ad.log.info("Http ping failed. Pinging default gateway")
         gw = ad.droid.connectivityGetIPv4DefaultGateway()
         result = ad.adb.shell("ping -c 6 {}".format(gw))
diff --git a/acts_tests/tests/google/fuchsia/flash/FlashTest.py b/acts_tests/tests/google/fuchsia/flash/FlashTest.py
index 572a431..03662f2 100644
--- a/acts_tests/tests/google/fuchsia/flash/FlashTest.py
+++ b/acts_tests/tests/google/fuchsia/flash/FlashTest.py
@@ -18,15 +18,13 @@
 the Sponge test result properties. Uses the built in flashing tool for
 fuchsia_devices.
 """
-import time
-
-import acts.libs.proc.job as job
-
-from acts import signals
+from acts import asserts
 from acts.base_test import BaseTestClass
 from acts.controllers.fuchsia_lib.base_lib import DeviceOffline
 from acts.utils import get_device
 
+MAX_FLASH_ATTEMPTS = 3
+
 
 class FlashTest(BaseTestClass):
     def setup_class(self):
@@ -56,36 +54,35 @@
         return super().teardown_class()
 
     def test_flash_devices(self):
-        flash_retry_max = 3
-        flash_counter = 0
-        for fuchsia_device in self.fuchsia_devices:
-            while flash_counter < flash_retry_max:
-                try:
-                    fuchsia_device.reboot(reboot_type='flash',
-                                          use_ssh=True,
-                                          unreachable_timeout=120,
-                                          ping_timeout=120)
-                    flash_counter = flash_retry_max
-                except Exception as err:
-                    if fuchsia_device.device_pdu_config:
-                        self.log.info(
-                            'Flashing failed with error: {}'.format(err))
-                        self.log.info('Hard rebooting fuchsia_device({}) and '
-                                      'retrying.'.format(
-                                          fuchsia_device.orig_ip))
-                        fuchsia_device.reboot(reboot_type='hard',
-                                              testbed_pdus=self.pdu_devices)
-                        flash_counter = flash_counter + 1
-                        if flash_counter == flash_retry_max:
-                            raise err
-                        time.sleep(1)
-                    else:
-                        raise err
-                self.log.info("fuchsia_device(%s) has been flashed." %
-                              fuchsia_device.orig_ip)
+        for device in self.fuchsia_devices:
             flash_counter = 0
+            while True:
+                try:
+                    device.reboot(reboot_type='flash',
+                                  use_ssh=True,
+                                  unreachable_timeout=120,
+                                  ping_timeout=120)
+                    self.log.info(f'{device.orig_ip} has been flashed.')
+                    break
+                except Exception as err:
+                    self.log.error(
+                        f'Failed to flash {device.orig_ip} with error:\n{err}')
 
-        return True
+                    if not device.device_pdu_config:
+                        asserts.abort_all(
+                            f'Failed to flash {device.orig_ip} and no PDU available for hard reboot'
+                        )
+
+                    flash_counter = flash_counter + 1
+                    if flash_counter == MAX_FLASH_ATTEMPTS:
+                        asserts.abort_all(
+                            f'Failed to flash {device.orig_ip} after {MAX_FLASH_ATTEMPTS} attempts'
+                        )
+
+                    self.log.info(
+                        f'Hard rebooting {device.orig_ip} and retrying flash.')
+                    device.reboot(reboot_type='hard',
+                                  testbed_pdus=self.pdu_devices)
 
     def test_report_dut_version(self):
         """Empty test to ensure the version of the DUT is reported in the Sponge
diff --git a/acts_tests/tests/google/net/CaptivePortalTest.py b/acts_tests/tests/google/net/CaptivePortalTest.py
index c44ff9b..9772fed 100644
--- a/acts_tests/tests/google/net/CaptivePortalTest.py
+++ b/acts_tests/tests/google/net/CaptivePortalTest.py
@@ -32,6 +32,7 @@
 CONNECTED = "Connected"
 SIGN_IN_NOTIFICATION = "Sign in to network"
 FAS_FDQN = "netsplashpage.net"
+NETWORK_AND_INTERNET = ["Network & internet", "Network and Internet"]
 
 
 class CaptivePortalTest(WifiBaseTest):
@@ -83,10 +84,15 @@
     def _go_to_wifi_settings(self):
         """Go to wifi settings to perform UI actions for Captive portal."""
         self.dut.adb.shell("am start -a android.settings.SETTINGS")
-        asserts.assert_true(
-            uutils.has_element(self.dut, text="Network & internet"),
-            "Failed to find 'Network & internet' icon")
-        uutils.wait_and_click(self.dut, text="Network & internet")
+
+        access_internet_setting = False
+        for text in NETWORK_AND_INTERNET:
+            if uutils.has_element(self.dut, text=text):
+                uutils.wait_and_click(self.dut, text=text)
+                access_internet_setting = True
+                break
+        asserts.assert_true(access_internet_setting,
+                            "Fail to find button NETWORK_AND_INTERNET from UI.")
         android_version = self.dut.adb.getprop("ro.build.version.release")
         if int(android_version) < 12:
             uutils.wait_and_click(self.dut, text="Wi‑Fi")
diff --git a/acts_tests/tests/google/nr/nsa5g/Nsa5gDataTest.py b/acts_tests/tests/google/nr/nsa5g/Nsa5gDataTest.py
index 8dfc5a6..3c8068a 100755
--- a/acts_tests/tests/google/nr/nsa5g/Nsa5gDataTest.py
+++ b/acts_tests/tests/google/nr/nsa5g/Nsa5gDataTest.py
@@ -369,11 +369,8 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_volte(ads[0].log, ads[0]):
-            ads[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_data_connectivity_multi_bearer(self.log, ads, GEN_5G, nr_type='nsa')
+        return test_data_connectivity_multi_bearer(
+            self.log, self.android_devices, '5g_volte', nr_type='nsa')
 
 
     @test_tracker_info(uuid="e88b226e-3842-4c45-a33e-d4fee7d8f6f0")
diff --git a/acts_tests/tests/google/nr/nsa5g/Nsa5gVoiceTest.py b/acts_tests/tests/google/nr/nsa5g/Nsa5gVoiceTest.py
index 38cbe45..230f4c5 100644
--- a/acts_tests/tests/google/nr/nsa5g/Nsa5gVoiceTest.py
+++ b/acts_tests/tests/google/nr/nsa5g/Nsa5gVoiceTest.py
@@ -119,10 +119,8 @@
             TestFailure if not success.
         """
         ads = self.android_devices
-        if not provision_both_devices_for_volte(self.log, ads):
-            return False
-
-        if not provision_device_for_5g(self.log, ads, nr_type='nsa'):
+        if not provision_both_devices_for_volte(self.log, ads, GEN_5G,
+                                                nr_type='nsa'):
             return False
 
         # VoLTE calls
@@ -157,15 +155,12 @@
         ads = self.android_devices
 
         # LTE attach
-        tasks = [(phone_setup_volte, (self.log, ads[0])),
+        tasks = [(phone_setup_volte, (self.log, ads[0], GEN_5G, 'nsa')),
                  (phone_setup_voice_3g, (self.log, ads[1]))]
         if not multithread_func(self.log, tasks):
             self.log.error("Phone failed to set up in volte/3g")
             return False
 
-        if not provision_device_for_5g(self.log, ads[0], nr_type='nsa'):
-            return False
-
         # VoLTE to 3G
         result = two_phone_call_short_seq(
             self.log, ads[0], None, is_phone_in_call_volte, ads[1],
@@ -200,10 +195,8 @@
             TestFailure if not success.
         """
         ads = self.android_devices
-        if not provision_both_devices_for_volte(self.log, ads):
-            return False
-
-        if not provision_device_for_5g(self.log, ads, nr_type='nsa'):
+        if not provision_both_devices_for_volte(self.log, ads, GEN_5G,
+                                                nr_type='nsa'):
             return False
 
         if not phone_setup_call_hold_unhold_test(self.log,
@@ -232,10 +225,8 @@
             TestFailure if not success.
         """
         ads = self.android_devices
-        if not provision_both_devices_for_volte(self.log, ads):
-            return False
-
-        if not provision_device_for_5g(self.log, ads, nr_type='nsa'):
+        if not provision_both_devices_for_volte(self.log, ads, GEN_5G,
+                                                nr_type='nsa'):
             return False
 
         if not phone_setup_call_hold_unhold_test(self.log,
@@ -267,14 +258,12 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_volte(self.log, ads[0]):
-            ads[0].log.error("failed to setup volte")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_volte',
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
 
     @test_tracker_info(uuid="aaa98e51-0bde-472a-abc3-5dc180f56a08")
@@ -295,14 +284,12 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_volte(self.log, ads[0]):
-            ads[0].log.error("failed to setup volte")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_volte',
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
 
     @test_tracker_info(uuid="96b7d8c9-d32a-4abf-8326-6b060d116ac2")
@@ -346,14 +333,12 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_volte(self.log, ads[0]):
-            ads[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_volte',
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="4e138477-3536-48bd-ab8a-7fb7c228b3e6")
     @TelephonyBaseTest.tel_test_wrap
@@ -371,14 +356,12 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_volte(self.log, ads[0]):
-            ads[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_volte',
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
 
     @test_tracker_info(uuid="0d477f6f-3464-4b32-a5e5-0fd134f2753d")
@@ -398,19 +381,16 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_iwlan(self.log, ads[0], False,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            ads[0].log.error(
-                "Failed to setup iwlan with APM off and WIFI and WFC on")
-            return False
-
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=False,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
 
     @test_tracker_info(uuid="4d1d7dd9-b373-4361-8301-8517ef77b57b")
@@ -430,19 +410,16 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
-        if not phone_setup_iwlan(self.log, ads[0], False,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            ads[0].log.error(
-                "Failed to setup iwlan with APM off and WIFI and WFC on")
-            return False
-
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       ads,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=False,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
 
     @test_tracker_info(uuid="e360bc3a-96b3-4fdf-9bf3-fe3aa08b1af5")
@@ -713,10 +690,11 @@
             TestFailure if not success.
         """
         ads = self.android_devices
-        if not provision_both_devices_for_volte(self.log, ads):
-            return False
 
-        if not provision_device_for_5g(self.log, ads[1], nr_type='nsa'):
+        tasks = [(phone_setup_volte, (self.log, ads[0])),
+                (phone_setup_volte, (self.log, ads[1], GEN_5G, 'nsa'))]
+        if not multithread_func(self.log, tasks):
+            self.log.error("phone failed to set up in volte")
             return False
 
         result = two_phone_call_long_seq(
@@ -749,10 +727,10 @@
         MINIMUM_SUCCESS_RATE = .95
         ads = self.android_devices
 
-        if not provision_both_devices_for_volte(self.log, ads):
-            return False
-
-        if not provision_device_for_5g(self.log, ads[1], nr_type='nsa'):
+        tasks = [(phone_setup_volte, (self.log, ads[0])),
+                (phone_setup_volte, (self.log, ads[1], GEN_5G, 'nsa'))]
+        if not multithread_func(self.log, tasks):
+            self.log.error("phone failed to set up in volte")
             return False
 
         success_count = 0
@@ -948,17 +926,16 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_iwlan(self.log, self.android_devices[0], False,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup IWLAN with NON-APM WIFI WFC on")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=False,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="f827a8b5-039c-4cc1-b030-78a09119acfc")
     @TelephonyBaseTest.tel_test_wrap
@@ -973,17 +950,16 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_iwlan(self.log, self.android_devices[0], False,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup iwlan with APM off and WIFI and WFC on")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_5G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=False,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="af3254d0-a84a-47c8-8ebc-11517b7b4944")
     @TelephonyBaseTest.tel_test_wrap
@@ -999,21 +975,16 @@
             True if success.
             False if failed.
         """
-        if not provision_device_for_5g(self.log, self.android_devices[0], nr_type='nsa'):
-            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
-            return False
-
-        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup iwlan with APM, WIFI and WFC on")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=True,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="5c58af94-8c24-481b-a555-bdbf36db5f6e")
     @TelephonyBaseTest.tel_test_wrap
@@ -1029,21 +1000,16 @@
             True if success.
             False if failed.
         """
-        if not provision_device_for_5g(self.log, self.android_devices[0], nr_type='nsa'):
-            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
-            return False
-
-        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup iwlan with APM, WIFI and WFC on")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=True,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="bcd874ae-58e1-4954-88af-bb3dd54d4abf")
     @TelephonyBaseTest.tel_test_wrap
@@ -1058,21 +1024,16 @@
             True if success.
             False if failed.
         """
-        if not provision_device_for_5g(self.log, self.android_devices[0], nr_type='nsa'):
-            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
-            return False
-
-        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup iwlan with APM, WIFI and WFC on")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=True,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="ad96f1cf-0d17-4a39-86cf-cacb5f4cc81c")
     @TelephonyBaseTest.tel_test_wrap
@@ -1087,21 +1048,16 @@
             True if success.
             False if failed.
         """
-        if not provision_device_for_5g(self.log, self.android_devices[0], nr_type='nsa'):
-            self.android_devices[0].log.error("Phone not attached on 5G NSA before call.")
-            return False
-
-        if not phone_setup_iwlan(self.log, self.android_devices[0], True,
-                                 WFC_MODE_WIFI_PREFERRED,
-                                 self.wifi_network_ssid,
-                                 self.wifi_network_pass):
-            self.android_devices[0].log.error(
-                "Failed to setup iwlan with APM, WIFI and WFC on")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='5g_wfc',
+            is_airplane_mode=True,
+            wfc_mode=WFC_MODE_WIFI_PREFERRED,
+            wifi_ssid=self.wifi_network_ssid,
+            wifi_pwd=self.wifi_network_pass,
+            nr_type='nsa',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="9d1121c1-aae4-428b-9167-09d4efdb7e37")
     @TelephonyBaseTest.tel_test_wrap
diff --git a/acts_tests/tests/google/tel/live/TelLiveDataTest.py b/acts_tests/tests/google/tel/live/TelLiveDataTest.py
index cd297ba..b5c8d69 100755
--- a/acts_tests/tests/google/tel/live/TelLiveDataTest.py
+++ b/acts_tests/tests/google/tel/live/TelLiveDataTest.py
@@ -329,13 +329,10 @@
             True if success.
             False if failed.
         """
-        ads = self.android_devices
         self.number_of_devices = 1
 
-        if not phone_setup_volte(self.log, self.android_devices[0]):
-            self.log.error("Failed to setup VoLTE")
-            return False
-        return test_data_connectivity_multi_bearer(self.log, ads, GEN_4G)
+        return test_data_connectivity_multi_bearer(
+            self.log, self.android_devices, 'volte')
 
     @test_tracker_info(uuid="5c9cb076-0c26-4517-95dc-2ec4974e8ce3")
     @TelephonyBaseTest.tel_test_wrap
@@ -354,7 +351,8 @@
             False if failed.
         """
 
-        return test_data_connectivity_multi_bearer(self.log, self.android_devices, GEN_3G)
+        return test_data_connectivity_multi_bearer(
+            self.log, self.android_devices, '3g')
 
     @test_tracker_info(uuid="314bbf1c-073f-4d48-9817-a6e14f96f3c0")
     @TelephonyBaseTest.tel_test_wrap
@@ -371,8 +369,8 @@
             False if failed.
         """
 
-        return test_data_connectivity_multi_bearer(self.log, self.android_devices,
-            GEN_2G, False, DIRECTION_MOBILE_ORIGINATED)
+        return test_data_connectivity_multi_bearer(self.log,
+            self.android_devices, '2g', False, DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="549271ff-1034-4d02-8d92-b9d1b2bb912e")
     @TelephonyBaseTest.tel_test_wrap
@@ -389,8 +387,8 @@
             False if failed.
         """
 
-        return test_data_connectivity_multi_bearer(self.log, self.android_devices,
-            GEN_2G, False, DIRECTION_MOBILE_TERMINATED)
+        return test_data_connectivity_multi_bearer(self.log,
+            self.android_devices, '2g', False, DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="111de471-559a-4bc3-9d3e-de18f098c162")
     @TelephonyBaseTest.tel_test_wrap
diff --git a/acts_tests/tests/google/tel/live/TelLiveVoiceTest.py b/acts_tests/tests/google/tel/live/TelLiveVoiceTest.py
index 2d055ea..0a1948f 100644
--- a/acts_tests/tests/google/tel/live/TelLiveVoiceTest.py
+++ b/acts_tests/tests/google/tel/live/TelLiveVoiceTest.py
@@ -3164,10 +3164,11 @@
             True if success.
             False if failed.
         """
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="d750d66b-2091-4e8d-baa2-084b9d2bbff5")
     @TelephonyBaseTest.tel_test_wrap
@@ -3187,10 +3188,11 @@
             True if success.
             False if failed.
         """
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="35703e83-b3e6-40af-aeaf-6b983d6205f4")
     @TelephonyBaseTest.tel_test_wrap
@@ -3210,13 +3212,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_volte(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='volte',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="a0f658d9-4212-44db-b3e8-7202f1eec04d")
     @TelephonyBaseTest.tel_test_wrap
@@ -3236,13 +3236,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_volte(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='volte',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="e0b264ec-fc29-411e-b018-684b7ff5a37e")
     @TelephonyBaseTest.tel_test_wrap
@@ -3262,14 +3260,12 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_csfb(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='csfb',
+            call_direction=DIRECTION_MOBILE_ORIGINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="98f04a27-74e1-474d-90d1-a4a45cdb6f5b")
     @TelephonyBaseTest.tel_test_wrap
@@ -3289,14 +3285,12 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_csfb(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='csfb',
+            call_direction=DIRECTION_MOBILE_TERMINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="359b1ee1-36a6-427b-9d9e-4d77231fcb09")
     @TelephonyBaseTest.tel_test_wrap
@@ -3317,14 +3311,12 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_3g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup 3G")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_3G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='3g',
+            call_direction=DIRECTION_MOBILE_ORIGINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="b172bbb4-2d6e-4d83-a381-ebfdf23bc30e")
     @TelephonyBaseTest.tel_test_wrap
@@ -3345,14 +3337,12 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_3g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup 3G")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_3G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='3g',
+            call_direction=DIRECTION_MOBILE_TERMINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="f5d9bfd0-0996-4c18-b11e-c6113dc201e2")
     @TelephonyBaseTest.tel_test_wrap
@@ -3373,14 +3363,12 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_2g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup voice in 2G")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_2G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='2g',
+            call_direction=DIRECTION_MOBILE_ORIGINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="99cfd1be-b992-48bf-a50e-fc3eec8e5a67")
     @TelephonyBaseTest.tel_test_wrap
@@ -3401,14 +3389,12 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_2g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup voice in 2G")
-            return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       GEN_2G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat='2g',
+            call_direction=DIRECTION_MOBILE_TERMINATED,
+            allow_data_transfer_interruption=True)
 
     @test_tracker_info(uuid="12677cf2-40d3-4bb1-8afa-91ebcbd0f862")
     @TelephonyBaseTest.tel_test_wrap
@@ -3431,10 +3417,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup IWLAN with NON-APM WIFI WFC on")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="84adcc19-43bb-4ea3-9284-7322ab139aac")
     @TelephonyBaseTest.tel_test_wrap
@@ -3457,10 +3444,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM off and WIFI and WFC on")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="42566255-c33f-406c-abab-932a0aaa01a8")
     @TelephonyBaseTest.tel_test_wrap
@@ -3488,10 +3476,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="fbf52f60-449b-46f2-9486-36d338a1b070")
     @TelephonyBaseTest.tel_test_wrap
@@ -3519,10 +3508,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="d1bf0739-ffb7-4bf8-ab94-570619f812a8")
     @TelephonyBaseTest.tel_test_wrap
@@ -3547,10 +3537,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="76b2cdaf-b783-4c1a-b91b-207f82ffa816")
     @TelephonyBaseTest.tel_test_wrap
@@ -3575,10 +3566,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_data_transfer(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_data_transfer(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="1dc9f03f-1b6c-4c17-993b-3acafdc26ea3")
     @TelephonyBaseTest.tel_test_wrap
@@ -3594,10 +3586,11 @@
             True if success.
             False if failed.
         """
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="32bc8fab-a0b9-4d47-8afb-940d1fdcde02")
     @TelephonyBaseTest.tel_test_wrap
@@ -3613,10 +3606,11 @@
             True if success.
             False if failed.
         """
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="72204212-e0c8-4447-be3f-ae23b2a63a1c")
     @TelephonyBaseTest.tel_test_wrap
@@ -3632,13 +3626,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_volte(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='volte',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="84cd3ab9-a2b2-4ef9-b531-ee6201bec128")
     @TelephonyBaseTest.tel_test_wrap
@@ -3654,13 +3646,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_volte(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='volte',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="a8dca8d3-c44c-40a6-be56-931b4be5499b")
     @TelephonyBaseTest.tel_test_wrap
@@ -3676,14 +3666,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_csfb(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='csfb',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="d11f7263-f51d-4ea3-916a-0df4f52023ce")
     @TelephonyBaseTest.tel_test_wrap
@@ -3699,14 +3686,11 @@
             True if success.
             False if failed.
         """
-        if not phone_setup_csfb(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup VoLTE")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_4G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='csfb',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="676378b4-94b7-4ad7-8242-7ccd2bf1efba")
     @TelephonyBaseTest.tel_test_wrap
@@ -3723,14 +3707,11 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_3g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup 3G")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_3G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='3g',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="6216fc6d-2aa2-4eb9-90e2-5791cb31c12e")
     @TelephonyBaseTest.tel_test_wrap
@@ -3747,14 +3728,11 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_3g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup 3G")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_3G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='3g',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="58ec9783-6f8e-49f6-8dae-9dd33108b6f9")
     @TelephonyBaseTest.tel_test_wrap
@@ -3771,14 +3749,11 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_2g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup voice in 2G")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_2G,
-                                                       DIRECTION_MOBILE_ORIGINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='2g',
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="e8ba7c0c-48a3-4fc6-aa34-a2e1c570521a")
     @TelephonyBaseTest.tel_test_wrap
@@ -3795,14 +3770,11 @@
             False if failed.
         """
         self.check_band_support(self.android_devices[0])
-        if not phone_setup_voice_2g(self.log, self.android_devices[0]):
-            self.android_devices[0].log.error("Failed to setup voice in 2G")
-            return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       GEN_2G,
-                                                       DIRECTION_MOBILE_TERMINATED,
-                                                       allow_data_transfer_interruption=True)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat='2g',
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="eb8971c1-b34a-430f-98df-0d4554c7ab12")
     @TelephonyBaseTest.tel_test_wrap
@@ -3824,10 +3796,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup IWLAN with NON-APM WIFI WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="275a93d6-1f39-40c8-893f-ff77afd09e54")
     @TelephonyBaseTest.tel_test_wrap
@@ -3849,10 +3822,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM off and WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="ea087709-d4df-4223-b80c-1b33bacbd5a2")
     @TelephonyBaseTest.tel_test_wrap
@@ -3879,10 +3853,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="44cc14e0-60c7-4fdb-ad26-31fdc4e52aaf")
     @TelephonyBaseTest.tel_test_wrap
@@ -3909,10 +3884,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="e115e8a6-25bf-41fc-aeb8-8f4c922c50e4")
     @TelephonyBaseTest.tel_test_wrap
@@ -3934,10 +3910,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="d754d3dd-0b02-4f13-bc65-fdafa254196b")
     @TelephonyBaseTest.tel_test_wrap
@@ -3959,10 +3936,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="88822edf-4c4a-4bc4-9280-2f27ee9e28d5")
     @TelephonyBaseTest.tel_test_wrap
@@ -3986,10 +3964,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_ORIGINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_ORIGINATED)
 
     @test_tracker_info(uuid="c4b066b0-3cfd-4831-9c61-5d6b132648c4")
     @TelephonyBaseTest.tel_test_wrap
@@ -4013,10 +3992,11 @@
             self.android_devices[0].log.error(
                 "Failed to setup iwlan with APM, WIFI and WFC on")
             return False
-        return test_call_setup_in_active_youtube_video(self.log,
-                                                       self.android_devices,
-                                                       None,
-                                                       DIRECTION_MOBILE_TERMINATED)
+        return test_call_setup_in_active_youtube_video(
+            self.log,
+            self.android_devices,
+            rat=None,
+            call_direction=DIRECTION_MOBILE_TERMINATED)
 
     @test_tracker_info(uuid="f367de12-1fd8-488d-816f-091deaacb791")
     @TelephonyBaseTest.tel_test_wrap
diff --git a/acts_tests/tests/google/wifi/WifiStaApConcurrencyTest.py b/acts_tests/tests/google/wifi/WifiStaApConcurrencyTest.py
index 4775c15..1c2b3c2 100644
--- a/acts_tests/tests/google/wifi/WifiStaApConcurrencyTest.py
+++ b/acts_tests/tests/google/wifi/WifiStaApConcurrencyTest.py
@@ -229,7 +229,9 @@
         asserts.assert_true(self.dut.droid.wifiIsApEnabled(),
                             "SoftAp is not reported as running")
 
-    def start_softap_and_connect_to_wifi_network(self, nw_params, softap_band):
+    def start_softap_and_connect_to_wifi_network(
+            self, nw_params, softap_band,
+            num_of_scan_tries=wutils.DEFAULT_SCAN_TRIES):
         """Test concurrent wifi connection and softap.
 
         This helper method first starts SoftAp and then makes a wifi connection.
@@ -242,9 +244,11 @@
         Args:
             nw_params: Params for network STA connection.
             softap_band: Band for the AP.
+            num_of_scan_tries: Number of tries to connect to wifi network
         """
         softap_config = self.start_softap_and_verify(softap_band, False)
-        wutils.connect_to_wifi_network(self.dut, nw_params)
+        wutils.connect_to_wifi_network(
+            self.dut, nw_params, num_of_scan_tries=num_of_scan_tries)
         wutils.verify_11ax_wifi_connection(
             self.dut, self.wifi6_models, "wifi6_ap" in self.user_params)
         self.run_iperf_client((nw_params, self.dut))
@@ -388,8 +392,14 @@
     def test_softap_5G_wifi_connection_5G_DFS(self):
         """Test SoftAp on 5G followed by connection to 5G DFS network."""
         self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS)
+        # Set scan tries to 10 to fit the 32ms limitation.
+        # SoftAp uses CTS2SELF frame to go offchannel for scan, and max duration
+        # we can set in CTS2SELF frame is 32ms.
+        # Since DUT SAP is enabled and clients are connect to the SAP, firmware
+        # is allocating only 28ms for passive scan in DFS channel for offchannel
+        # scan operation. We need to increase scan tries to get beacons from AP.
         self.start_softap_and_connect_to_wifi_network(
-            self.open_5g, WIFI_CONFIG_APBAND_5G)
+            self.open_5g, WIFI_CONFIG_APBAND_5G, num_of_scan_tries=10)
 
     @test_tracker_info(uuid="5e28e8b5-3faa-4cff-a782-13a796d7f572")
     def test_softap_5G_wifi_connection_2G(self):