wifi(vts): Use blocking getService to wait for service to come up
Switch away from using wifi's custom implementation to block for
supplicant/hostapd daemon to come up.
Bug: 161682236
Test:
vts-tradefed run commandAndExit vts --module VtsHalWifiHostapdV1_0Target
vts-tradefed run commandAndExit vts --module VtsHalWifiSupplicantV1_0Host
Change-Id: Ia05f93ba4a28c036315558edbba30f19c2e6ac95
Merged-In: Ia05f93ba4a28c036315558edbba30f19c2e6ac95
(cherry picked from commit 6d0af445ee
)
This commit is contained in:
parent
7cc876ee02
commit
2329bba9fe
2 changed files with 4 additions and 116 deletions
|
@ -17,7 +17,6 @@
|
|||
#include <android-base/logging.h>
|
||||
|
||||
#include <android/hidl/manager/1.0/IServiceManager.h>
|
||||
#include <android/hidl/manager/1.0/IServiceNotification.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include <wifi_system/hostapd_manager.h>
|
||||
|
@ -39,7 +38,6 @@ using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
|
|||
using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
|
||||
using ::android::hardware::wifi::V1_0::ChipModeId;
|
||||
using ::android::hardware::wifi::V1_0::IWifiChip;
|
||||
using ::android::hidl::manager::V1_0::IServiceNotification;
|
||||
using ::android::wifi_system::HostapdManager;
|
||||
using ::android::wifi_system::SupplicantManager;
|
||||
|
||||
|
@ -68,55 +66,6 @@ void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
// Utility class to wait for wpa_hostapd's HIDL service registration.
|
||||
class ServiceNotificationListener : public IServiceNotification {
|
||||
public:
|
||||
Return<void> onRegistration(const hidl_string& fully_qualified_name,
|
||||
const hidl_string& instance_name,
|
||||
bool pre_existing) override {
|
||||
if (pre_existing) {
|
||||
return Void();
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
registered_.push_back(std::string(fully_qualified_name.c_str()) + "/" +
|
||||
instance_name.c_str());
|
||||
lock.unlock();
|
||||
condition_.notify_one();
|
||||
return Void();
|
||||
}
|
||||
|
||||
bool registerForHidlServiceNotifications(const std::string& instance_name) {
|
||||
if (!IHostapd::registerForNotifications(instance_name, this)) {
|
||||
return false;
|
||||
}
|
||||
configureRpcThreadpool(2, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool waitForHidlService(uint32_t timeout_in_millis,
|
||||
const std::string& instance_name) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
condition_.wait_for(lock, std::chrono::milliseconds(timeout_in_millis),
|
||||
[&]() { return registered_.size() >= 1; });
|
||||
if (registered_.size() != 1) {
|
||||
return false;
|
||||
}
|
||||
std::string expected_registered =
|
||||
std::string(IHostapd::descriptor) + "/" + instance_name;
|
||||
if (registered_[0] != expected_registered) {
|
||||
LOG(ERROR) << "Expected: " << expected_registered
|
||||
<< ", Got: " << registered_[0];
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> registered_{};
|
||||
std::mutex mutex_;
|
||||
std::condition_variable condition_;
|
||||
};
|
||||
|
||||
void stopSupplicantIfNeeded(const std::string& instance_name) {
|
||||
SupplicantManager supplicant_manager;
|
||||
if (supplicant_manager.IsSupplicantRunning()) {
|
||||
|
@ -139,16 +88,11 @@ void startHostapdAndWaitForHidlService(
|
|||
const std::string& hostapd_instance_name) {
|
||||
initilializeDriverAndFirmware(wifi_instance_name);
|
||||
|
||||
android::sp<ServiceNotificationListener> notification_listener =
|
||||
new ServiceNotificationListener();
|
||||
ASSERT_TRUE(notification_listener->registerForHidlServiceNotifications(
|
||||
hostapd_instance_name));
|
||||
|
||||
HostapdManager hostapd_manager;
|
||||
ASSERT_TRUE(hostapd_manager.StartHostapd());
|
||||
|
||||
ASSERT_TRUE(
|
||||
notification_listener->waitForHidlService(500, hostapd_instance_name));
|
||||
// Wait for hostapd service to come up.
|
||||
IHostapd::getService(hostapd_instance_name);
|
||||
}
|
||||
|
||||
bool is_1_1(const sp<IHostapd>& hostapd) {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <cutils/properties.h>
|
||||
|
||||
#include <android/hidl/manager/1.0/IServiceManager.h>
|
||||
#include <android/hidl/manager/1.0/IServiceNotification.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include <wifi_system/interface_tool.h>
|
||||
|
@ -45,7 +44,6 @@ using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface;
|
|||
using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
|
||||
using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
|
||||
using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
|
||||
using ::android::hidl::manager::V1_0::IServiceNotification;
|
||||
using ::android::wifi_system::InterfaceTool;
|
||||
using ::android::wifi_system::SupplicantManager;
|
||||
|
||||
|
@ -120,55 +118,6 @@ std::string getP2pIfaceName() {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
// Utility class to wait for wpa_supplicant's HIDL service registration.
|
||||
class ServiceNotificationListener : public IServiceNotification {
|
||||
public:
|
||||
Return<void> onRegistration(const hidl_string& fully_qualified_name,
|
||||
const hidl_string& instance_name,
|
||||
bool pre_existing) override {
|
||||
if (pre_existing) {
|
||||
return Void();
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
registered_.push_back(std::string(fully_qualified_name.c_str()) + "/" +
|
||||
instance_name.c_str());
|
||||
lock.unlock();
|
||||
condition_.notify_one();
|
||||
return Void();
|
||||
}
|
||||
|
||||
bool registerForHidlServiceNotifications(const std::string& instance_name) {
|
||||
if (!ISupplicant::registerForNotifications(instance_name, this)) {
|
||||
return false;
|
||||
}
|
||||
configureRpcThreadpool(2, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool waitForHidlService(uint32_t timeout_in_millis,
|
||||
const std::string& instance_name) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
condition_.wait_for(lock, std::chrono::milliseconds(timeout_in_millis),
|
||||
[&]() { return registered_.size() >= 1; });
|
||||
if (registered_.size() != 1) {
|
||||
return false;
|
||||
}
|
||||
std::string exptected_registered =
|
||||
std::string(ISupplicant::descriptor) + "/" + instance_name;
|
||||
if (registered_[0] != exptected_registered) {
|
||||
LOG(ERROR) << "Expected: " << exptected_registered
|
||||
<< ", Got: " << registered_[0];
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> registered_{};
|
||||
std::mutex mutex_;
|
||||
std::condition_variable condition_;
|
||||
};
|
||||
|
||||
void stopSupplicant() { stopSupplicant(""); }
|
||||
|
||||
void stopSupplicant(const std::string& wifi_instance_name) {
|
||||
|
@ -184,17 +133,12 @@ void startSupplicantAndWaitForHidlService(
|
|||
const std::string& supplicant_instance_name) {
|
||||
initilializeDriverAndFirmware(wifi_instance_name);
|
||||
|
||||
android::sp<ServiceNotificationListener> notification_listener =
|
||||
new ServiceNotificationListener();
|
||||
ASSERT_TRUE(notification_listener->registerForHidlServiceNotifications(
|
||||
supplicant_instance_name));
|
||||
|
||||
SupplicantManager supplicant_manager;
|
||||
ASSERT_TRUE(supplicant_manager.StartSupplicant());
|
||||
ASSERT_TRUE(supplicant_manager.IsSupplicantRunning());
|
||||
|
||||
ASSERT_TRUE(notification_listener->waitForHidlService(
|
||||
500, supplicant_instance_name));
|
||||
// Wait for supplicant service to come up.
|
||||
ISupplicant::getService(supplicant_instance_name);
|
||||
}
|
||||
|
||||
bool is_1_1(const sp<ISupplicant>& supplicant) {
|
||||
|
|
Loading…
Reference in a new issue