[CountryCode] Modify test scripts to use country code params

Bug: 171251719
Test: Verified the changes
Change-Id: Ied2160adfbd2cd96d42bfec3c1a40602922889d4
diff --git a/acts_tests/acts_contrib/test_utils/wifi/WifiBaseTest.py b/acts_tests/acts_contrib/test_utils/wifi/WifiBaseTest.py
index 8938086..ab87f88 100644
--- a/acts_tests/acts_contrib/test_utils/wifi/WifiBaseTest.py
+++ b/acts_tests/acts_contrib/test_utils/wifi/WifiBaseTest.py
@@ -55,7 +55,7 @@
         if hasattr(self, 'attenuators') and self.attenuators:
             for attenuator in self.attenuators:
                 attenuator.set_atten(0)
-        opt_param = ["pixel_models", "cnss_diag_file"]
+        opt_param = ["pixel_models", "cnss_diag_file", "country_code_file"]
         self.unpack_userparams(opt_param_names=opt_param)
         if hasattr(self, "cnss_diag_file"):
             if isinstance(self.cnss_diag_file, list):
@@ -68,6 +68,19 @@
             self.packet_logger = self.packet_capture[0]
             self.packet_logger.configure_monitor_mode("2G", self.packet_log_2g)
             self.packet_logger.configure_monitor_mode("5G", self.packet_log_5g)
+        if hasattr(self, "android_devices"):
+            for ad in self.android_devices:
+                wutils.wifi_test_device_init(ad)
+                if hasattr(self, "country_code_file"):
+                    if isinstance(self.country_code_file, list):
+                        self.country_code_file = self.country_code_file[0]
+                    if not os.path.isfile(self.country_code_file):
+                        self.country_code_file = os.path.join(
+                            self.user_params[Config.key_config_path.value],
+                            self.country_code_file)
+                    self.country_code = utils.load_config(
+                        self.country_code_file)["country"]
+                    wutils.set_wifi_country_code(ad, self.country_code)
 
     def setup_test(self):
         if (hasattr(self, "android_devices")
diff --git a/acts_tests/tests/google/wifi/WifiDppTest.py b/acts_tests/tests/google/wifi/WifiDppTest.py
index aab5007..85601b7 100644
--- a/acts_tests/tests/google/wifi/WifiDppTest.py
+++ b/acts_tests/tests/google/wifi/WifiDppTest.py
@@ -97,8 +97,6 @@
     # constrain).
     utils.require_sl4a((self.dut,))
     utils.sync_device_time(self.dut)
-    for ad in self.android_devices:
-      wutils.wifi_test_device_init(ad)
 
     req_params = ["dpp_r1_test_only"]
     opt_param = ["wifi_psk_network", "wifi_sae_network"]
diff --git a/acts_tests/tests/google/wifi/WifiEnterpriseRoamingTest.py b/acts_tests/tests/google/wifi/WifiEnterpriseRoamingTest.py
index 5a3c323..6eea512 100644
--- a/acts_tests/tests/google/wifi/WifiEnterpriseRoamingTest.py
+++ b/acts_tests/tests/google/wifi/WifiEnterpriseRoamingTest.py
@@ -37,7 +37,6 @@
         super().setup_class()
 
         self.dut = self.android_devices[0]
-        wutils.wifi_test_device_init(self.dut)
         req_params = (
             "roaming_attn",
             # Expected time within which roaming should finish, in seconds.
diff --git a/acts_tests/tests/google/wifi/WifiEnterpriseTest.py b/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
index ce6acfa..2cb3f28 100644
--- a/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
+++ b/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
@@ -39,7 +39,6 @@
         self.enable_packet_log = True
 
         self.dut = self.android_devices[0]
-        wutils.wifi_test_device_init(self.dut)
         # If running in a setup with attenuators, set attenuation on all
         # channels to zero.
         if getattr(self, "attenuators", []):
diff --git a/acts_tests/tests/google/wifi/WifiHiddenSSIDTest.py b/acts_tests/tests/google/wifi/WifiHiddenSSIDTest.py
index 88736f8..1435dab 100644
--- a/acts_tests/tests/google/wifi/WifiHiddenSSIDTest.py
+++ b/acts_tests/tests/google/wifi/WifiHiddenSSIDTest.py
@@ -37,7 +37,6 @@
         super().setup_class()
 
         self.dut = self.android_devices[0]
-        wutils.wifi_test_device_init(self.dut)
 
         if "AccessPoint" in self.user_params:
             self.legacy_configure_ap_and_start(hidden=True)
diff --git a/acts_tests/tests/google/wifi/WifiNetworkSuggestionTest.py b/acts_tests/tests/google/wifi/WifiNetworkSuggestionTest.py
index d300079..f782760 100644
--- a/acts_tests/tests/google/wifi/WifiNetworkSuggestionTest.py
+++ b/acts_tests/tests/google/wifi/WifiNetworkSuggestionTest.py
@@ -68,7 +68,6 @@
         super().setup_class()
 
         self.dut = self.android_devices[0]
-        wutils.wifi_test_device_init(self.dut)
         opt_param = [
             "open_network", "reference_networks", "hidden_networks", "radius_conf_2g",
             "radius_conf_5g", "ca_cert", "eap_identity", "eap_password", "passpoint_networks",
diff --git a/acts_tests/tests/google/wifi/WifiRoamingTest.py b/acts_tests/tests/google/wifi/WifiRoamingTest.py
index cdb810b..0b49f7c 100644
--- a/acts_tests/tests/google/wifi/WifiRoamingTest.py
+++ b/acts_tests/tests/google/wifi/WifiRoamingTest.py
@@ -16,11 +16,13 @@
 import time
 from acts import asserts
 from acts import utils
+from acts.keys import Config
 from acts.test_decorators import test_tracker_info
 from acts_contrib.test_utils.net import connectivity_const as cconsts
 from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
 from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
 from acts_contrib.test_utils.wifi.aware import aware_test_utils as autils
+import os
 
 WifiEnums = wutils.WifiEnums
 
@@ -33,9 +35,18 @@
 
         self.dut = self.android_devices[0]
         self.dut_client = self.android_devices[1]
-        wutils.wifi_test_device_init(self.dut)
         req_params = ["roaming_attn",]
         self.unpack_userparams(req_param_names=req_params,)
+        self.country_code = wutils.WifiEnums.CountryCode.US
+        if hasattr(self, "country_code_file"):
+            if isinstance(self.country_code_file, list):
+                self.country_code_file = self.country_code_file[0]
+            if not os.path.isfile(self.country_code_file):
+                self.country_code_file = os.path.join(
+                    self.user_params[Config.key_config_path.value],
+                    self.country_code_file)
+            self.country_code = utils.load_config(
+                self.country_code_file)["country"]
 
         if "AccessPoint" in self.user_params:
             self.legacy_configure_ap_and_start(ap_count=2)
@@ -59,8 +70,7 @@
         wutils.reset_wifi(self.dut)
         wutils.set_attns(self.attenuators, "default")
         for ad in self.android_devices:
-            wutils.set_wifi_country_code(
-                    ad, wutils.WifiEnums.CountryCode.US)
+            wutils.set_wifi_country_code(ad, self.country_code)
         if "OpenWrtAP" in self.user_params:
             for ap in self.access_points:
                 ap.close()
diff --git a/acts_tests/tests/google/wifi/WifiSoftApAcsTest.py b/acts_tests/tests/google/wifi/WifiSoftApAcsTest.py
index bd443c2..974a784 100644
--- a/acts_tests/tests/google/wifi/WifiSoftApAcsTest.py
+++ b/acts_tests/tests/google/wifi/WifiSoftApAcsTest.py
@@ -50,14 +50,9 @@
 
         self.dut = self.android_devices[0]
         self.dut_client = self.android_devices[1]
-        wutils.wifi_test_device_init(self.dut)
-        wutils.wifi_test_device_init(self.dut_client)
         utils.require_sl4a((self.dut, self.dut_client))
         utils.sync_device_time(self.dut)
         utils.sync_device_time(self.dut_client)
-        # Set country code explicitly to "US".
-        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
-        wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
         # Enable verbose logging on the duts
         self.dut.droid.wifiEnableVerboseLogging(1)
         asserts.assert_equal(self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
diff --git a/acts_tests/tests/google/wifi/WifiSoftApTest.py b/acts_tests/tests/google/wifi/WifiSoftApTest.py
index 5a3bfed..a7a338c 100644
--- a/acts_tests/tests/google/wifi/WifiSoftApTest.py
+++ b/acts_tests/tests/google/wifi/WifiSoftApTest.py
@@ -14,10 +14,12 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
+import os
 import time
 
 from acts import asserts
 from acts import utils
+from acts.keys import Config
 from acts.test_decorators import test_tracker_info
 from acts_contrib.test_utils.tel import tel_test_utils as tel_utils
 from acts_contrib.test_utils.wifi import wifi_constants
@@ -63,9 +65,6 @@
         utils.require_sl4a((self.dut, self.dut_client))
         utils.sync_device_time(self.dut)
         utils.sync_device_time(self.dut_client)
-        # Set country code explicitly to "US".
-        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
-        wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
         # Enable verbose logging on the duts
         self.dut.droid.wifiEnableVerboseLogging(1)
         asserts.assert_equal(self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
@@ -82,11 +81,20 @@
             self.AP_IFACE = 'wlan2'
         if len(self.android_devices) > 2:
             utils.sync_device_time(self.android_devices[2])
-            wutils.set_wifi_country_code(self.android_devices[2], wutils.WifiEnums.CountryCode.US)
             self.android_devices[2].droid.wifiEnableVerboseLogging(1)
             asserts.assert_equal(self.android_devices[2].droid.wifiGetVerboseLoggingLevel(), 1,
                 "Failed to enable WiFi verbose logging on the client dut.")
             self.dut_client_2 = self.android_devices[2]
+        self.country_code = wutils.WifiEnums.CountryCode.US
+        if hasattr(self, "country_code_file"):
+            if isinstance(self.country_code_file, list):
+                self.country_code_file = self.country_code_file[0]
+            if not os.path.isfile(self.country_code_file):
+                self.country_code_file = os.path.join(
+                    self.user_params[Config.key_config_path.value],
+                    self.country_code_file)
+            self.country_code = utils.load_config(
+                self.country_code_file)["country"]
 
     def teardown_class(self):
         if self.dut.droid.wifiIsApEnabled():
@@ -117,14 +125,12 @@
                             "Can not turn off airplane mode: %s" % self.dut.serial)
         if self.dut.droid.wifiIsApEnabled():
             wutils.stop_wifi_tethering(self.dut)
-        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
         if "chan_13" in self.test_name and "OpenWrtAP" in self.user_params:
             self.access_points[0].close()
             self.configure_openwrt_ap_and_start(wpa_network=True)
             self.wifi_network = self.reference_networks[0]["2g"]
             for ad in self.android_devices:
-                wutils.set_wifi_country_code(
-                        ad, wutils.WifiEnums.CountryCode.US)
+                wutils.set_wifi_country_code(ad, self.country_code)
 
     """ Helper Functions """
     def create_softap_config(self):
diff --git a/acts_tests/tests/google/wifi/WifiWpa3OweTest.py b/acts_tests/tests/google/wifi/WifiWpa3OweTest.py
index 4d970e7..97a6881 100644
--- a/acts_tests/tests/google/wifi/WifiWpa3OweTest.py
+++ b/acts_tests/tests/google/wifi/WifiWpa3OweTest.py
@@ -35,7 +35,6 @@
         super().setup_class()
 
         self.dut = self.android_devices[0]
-        wutils.wifi_test_device_init(self.dut)
         opt_params = ["owe_networks", "sae_networks"]
         req_params = ["wpa3_sae_gcmp_128", "wpa3_sae_gcmp_256", "wifi6_models"]
         self.unpack_userparams(opt_param_names=opt_params,