Add mutex to the supplicant aidl_return_util
to support multiple clients to the service.
Some OEMs have additional clients to the
supplicant service, aside from the Wifi
framework. This can lead to contention
in the HAL.
Bug: 358741598
Test: Manual test - connect to Wifi
Test: atest VtsHalWifiSupplicantStaIfaceTargetTest \
VtsHalWifiSupplicantStaNetworkTargetTest \
VtsHalWifiSupplicantP2pIfaceTargetTest
Change-Id: Ice7bb5dec5ebf618ebb603a996b80954710eb78b
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;