Merge "Define vintf fragment as a module" into main
diff --git a/hostapd/Android.bp b/hostapd/Android.bp
index 54047f2..8fb93db 100644
--- a/hostapd/Android.bp
+++ b/hostapd/Android.bp
@@ -66,37 +66,8 @@
     ],
 }
 
-soong_config_module_type {
-    name: "hostapd_cflags_cc_defaults",
-    module_type: "cc_defaults",
-    config_namespace: "hostapd",
-    value_variables: [
-        "platform_version",
-        "nl80211_driver",
-    ],
-    properties: ["cflags"],
-}
-
-hostapd_cflags_cc_defaults {
+cc_defaults {
     name: "hostapd_cflags_defaults",
-    soong_config_variables: {
-        // Devices that include this module should set these soong config vars appropriately.
-        // For example:
-        //   $(call add_soong_config_namespace, wpa_supplicant)
-        //   $(call add_soong_config_var_value, wpa_supplicant, platform_version, $(PLATFORM_VERSION))
-        //   $(call add_soong_config_var_value, wpa_supplicant, nl80211_driver, CONFIG_DRIVER_NL80211_QCA)
-        platform_version: {
-            cflags: ["-DVERSION_STR_POSTFIX=\"-%s\""],
-            conditions_default: {
-                // Default value
-                cflags: ["-DVERSION_STR_POSTFIX=\"-Android\""],
-            },
-        },
-        nl80211_driver: {
-            cflags: ["-D%s"],
-            // Flag is optional, so no default value provided.
-        },
-    },
     // Generated by building hostapd and printing LOCAL_CFLAGS.
     cflags: [
         "-DWPA_IGNORE_CONFIG_ERRORS",
@@ -166,7 +137,21 @@
         "-Wno-unused-parameter",
         "-Wno-unused-variable",
         "-Wno-macro-redefined",
-    ],
+    ] +
+        // Devices that include this module should set these soong config vars appropriately.
+        // For example:
+        //   $(call soong_config_set, hostapd, platform_version, $(PLATFORM_VERSION))
+        //   $(call soong_config_set, hostapd, nl80211_driver, CONFIG_DRIVER_NL80211_QCA)
+        select(soong_config_variable("hostapd", "platform_version"), {
+            any @ version: ["-DVERSION_STR_POSTFIX=\"-" + version + "\""],
+            default: ["-DVERSION_STR_POSTFIX=\"-Android\""],
+        }) +
+        select(soong_config_variable("hostapd", "nl80211_driver"), {
+            any @ driver: ["-D" + driver],
+            // Flag is optional, so no default value provided.
+            default: [],
+        }),
+
     // Similar to suppressing clang compiler warnings, here we
     // suppress clang-tidy warnings to reduce noises in Android build.log.
     tidy_checks: [
diff --git a/wpa_supplicant/Android.bp b/wpa_supplicant/Android.bp
index e6ba165..c0835ae 100644
--- a/wpa_supplicant/Android.bp
+++ b/wpa_supplicant/Android.bp
@@ -91,37 +91,8 @@
     ],
 }
 
-soong_config_module_type {
-    name: "wpa_supplicant_cflags_cc_defaults",
-    module_type: "cc_defaults",
-    config_namespace: "wpa_supplicant",
-    value_variables: [
-        "platform_version",
-        "nl80211_driver",
-    ],
-    properties: ["cflags"],
-}
-
-wpa_supplicant_cflags_cc_defaults {
+cc_defaults {
     name: "wpa_supplicant_cflags_defaults",
-    soong_config_variables: {
-        // Devices that include this module should set these soong config vars appropriately.
-        // For example:
-        //   $(call add_soong_config_namespace, wpa_supplicant)
-        //   $(call add_soong_config_var_value, wpa_supplicant, platform_version, $(PLATFORM_VERSION))
-        //   $(call add_soong_config_var_value, wpa_supplicant, nl80211_driver, CONFIG_DRIVER_NL80211_QCA)
-        platform_version: {
-            cflags: ["-DVERSION_STR_POSTFIX=\"-%s\""],
-            conditions_default: {
-                // Default value
-                cflags: ["-DVERSION_STR_POSTFIX=\"-Android\""],
-            },
-        },
-        nl80211_driver: {
-            cflags: ["-D%s"],
-            // Flag is optional, so no default value provided.
-        },
-    },
     // Generated by building wpa_supplicant and printing LOCAL_CFLAGS.
     cflags: [
         "-DANDROID_LOG_NAME=\"wpa_supplicant\"",
@@ -215,7 +186,20 @@
         "-Wno-unused-function",
         "-Wno-unused-parameter",
         "-Wno-unused-variable",
-    ],
+    ] +
+        // Devices that include this module should set these soong config vars appropriately.
+        // For example:
+        //   $(call soong_config_set, wpa_supplicant, platform_version, $(PLATFORM_VERSION))
+        //   $(call soong_config_set, wpa_supplicant, nl80211_driver, CONFIG_DRIVER_NL80211_QCA)
+        select(soong_config_variable("wpa_supplicant", "platform_version"), {
+            any @ version: ["-DVERSION_STR_POSTFIX=\"-" + version + "\""],
+            default: ["-DVERSION_STR_POSTFIX=\"-Android\""],
+        }) +
+        select(soong_config_variable("wpa_supplicant", "nl80211_driver"), {
+            any @ driver: ["-D" + driver],
+            // Flag is optional, so no default value provided.
+            default: [],
+        }),
     // Similar to suppressing clang compiler warnings, here we
     // suppress clang-tidy warnings to reduce noises in Android build.log.
     tidy_checks: [
diff --git a/wpa_supplicant/aidl/aidl_return_util.h b/wpa_supplicant/aidl/aidl_return_util.h
index 109723a..2cb8b5a 100644
--- a/wpa_supplicant/aidl/aidl_return_util.h
+++ b/wpa_supplicant/aidl/aidl_return_util.h
@@ -10,6 +10,12 @@
 #define AIDL_RETURN_UTIL_H_
 
 #include <aidl/android/hardware/wifi/supplicant/SupplicantStatusCode.h>
+#include <mutex>
+
+namespace {
+	// Mutex serializes requests when this process is called by multiple clients
+	std::mutex aidl_return_mutex;
+}
 
 namespace aidl {
 namespace android {
@@ -33,6 +39,7 @@
 	ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
 	Args&&... args)
 {
+	std::lock_guard<std::mutex> guard(aidl_return_mutex);
 	if (obj->isValid()) {
 		return (obj->*work)(std::forward<Args>(args)...);
 	} else {
@@ -47,6 +54,7 @@
 	ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
 	ReturnT* ret_val, Args&&... args)
 {
+	std::lock_guard<std::mutex> guard(aidl_return_mutex);
 	if (obj->isValid()) {
 		auto call_pair = (obj->*work)(std::forward<Args>(args)...);
 		*ret_val = call_pair.first;
diff --git a/wpa_supplicant/wpa_supplicant/Android.bp b/wpa_supplicant/wpa_supplicant/Android.bp
index 3f76ae8..6623454 100644
--- a/wpa_supplicant/wpa_supplicant/Android.bp
+++ b/wpa_supplicant/wpa_supplicant/Android.bp
@@ -23,24 +23,13 @@
     ],
 }
 
-soong_config_module_type_import {
-    from: "frameworks/opt/net/wifi/libwifi_hal/Android.bp",
-    module_types: ["wifi_cc_defaults"],
-}
-
-wifi_cc_defaults {
+cc_defaults {
     name: "lib_vendor_wpa_supplicant",
-    soong_config_variables: {
-        board_wlan_device: {
-            emulator: {
-                static_libs: ["lib_driver_cmd_simulated_cf_bp"],
-            },
-            // TODO(b/295186835): Convert lib_driver_cmd_* to soong
-            conditions_default: {
-                static_libs: ["lib_driver_cmd_fallback"],
-            },
-        },
-    },
+    static_libs: select(soong_config_variable("wifi", "board_wlan_device"), {
+        "emulator": ["lib_driver_cmd_simulated_cf_bp"],
+        // TODO(b/295186835): Convert lib_driver_cmd_* to soong
+        default: ["lib_driver_cmd_fallback"],
+    }),
 }
 
 cc_binary {