diff --git a/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp b/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp index 6722f36dc9..463545bbe0 100644 --- a/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp +++ b/wifi/aidl/vts/functional/wifi_aidl_test_utils.cpp @@ -214,3 +214,7 @@ int32_t getChipCapabilities(const std::shared_ptr& wifi_chip) { } return 0; } + +bool isAidlServiceAvailable(const char* instance_name) { + return AServiceManager_isDeclared(instance_name); +} diff --git a/wifi/aidl/vts/functional/wifi_aidl_test_utils.h b/wifi/aidl/vts/functional/wifi_aidl_test_utils.h index ad16603dd3..2eac9509e3 100644 --- a/wifi/aidl/vts/functional/wifi_aidl_test_utils.h +++ b/wifi/aidl/vts/functional/wifi_aidl_test_utils.h @@ -46,3 +46,4 @@ bool configureChipToSupportConcurrencyType(const std::shared_ptr& wif void stopWifiService(const char* instance_name); int32_t getChipCapabilities(const std::shared_ptr& wifi_chip); bool checkStatusCode(ndk::ScopedAStatus* status, WifiStatusCode expected_code); +bool isAidlServiceAvailable(const char* instance_name); diff --git a/wifi/apex/Android.bp b/wifi/apex/Android.bp index 0afb96b85d..e1fefb9575 100644 --- a/wifi/apex/Android.bp +++ b/wifi/apex/Android.bp @@ -15,7 +15,7 @@ android_app_certificate { genrule { name: "gen-android.hardware.wifi.rc", - srcs: [":default-android.hardware.wifi@1.0-service.rc"], + srcs: [":default-android.hardware.wifi-service.rc"], out: ["com.android.hardware.wifi-service.rc"], cmd: "sed -e 's@/vendor/bin/@/apex/com.android.hardware.wifi/bin/@' $(in) > $(out)", } @@ -28,7 +28,7 @@ prebuilt_etc { prebuilt_etc { name: "com.android.hardware.wifi.xml", - src: ":default-android.hardware.wifi@1.0-service.xml", + src: ":default-android.hardware.wifi-service.xml", installable: false, } @@ -43,13 +43,13 @@ apex { updatable: false, soc_specific: true, binaries: [ - "android.hardware.wifi@1.0-service", + "android.hardware.wifi-service", ], prebuilts: [ "com.android.hardware.wifi.rc", "com.android.hardware.wifi.xml", ], overrides: [ - "android.hardware.wifi@1.0-service", + "android.hardware.wifi-service", ], } diff --git a/wifi/apex/file_contexts b/wifi/apex/file_contexts index 812d51db58..6368729c9a 100644 --- a/wifi/apex/file_contexts +++ b/wifi/apex/file_contexts @@ -1,3 +1,3 @@ (/.*)? u:object_r:vendor_file:s0 -/bin/hw/android\.hardware\.wifi@1.0-service u:object_r:hal_wifi_default_exec:s0 +/bin/hw/android\.hardware\.wifi-service u:object_r:hal_wifi_default_exec:s0 diff --git a/wifi/hostapd/aidl/vts/functional/Android.bp b/wifi/hostapd/aidl/vts/functional/Android.bp index e61d3975bb..1942db176c 100644 --- a/wifi/hostapd/aidl/vts/functional/Android.bp +++ b/wifi/hostapd/aidl/vts/functional/Android.bp @@ -34,6 +34,9 @@ cc_test { "android.hardware.wifi@1.3", "android.hardware.wifi@1.4", "android.hardware.wifi@1.5", + "android.hardware.wifi-V1-ndk", + "libwifi-system-iface", + "VtsHalWifiTargetTestUtil", ], test_suites: [ "general-tests", diff --git a/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp b/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp index bd2649fc50..69f1b762a7 100644 --- a/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp +++ b/wifi/hostapd/aidl/vts/functional/VtsHalHostapdTargetTest.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include @@ -30,6 +31,8 @@ #include #include +#include "wifi_aidl_test_utils.h" + using aidl::android::hardware::wifi::hostapd::BandMask; using aidl::android::hardware::wifi::hostapd::BnHostapdCallback; using aidl::android::hardware::wifi::hostapd::ChannelBandwidth; @@ -54,6 +57,8 @@ const int kIfaceInvalidChannel = 567; const std::vector kTestZeroMacAddr(6, 0x0); const Ieee80211ReasonCode kTestDisconnectReasonCode = Ieee80211ReasonCode::WLAN_REASON_UNSPECIFIED; +const std::string kWifiAidlInstanceNameStr = std::string() + IWifi::descriptor + "/default"; +const char* kWifiAidlInstanceName = kWifiAidlInstanceNameStr.c_str(); inline BandMask operator|(BandMask a, BandMask b) { return static_cast(static_cast(a) | @@ -77,33 +82,70 @@ class HostapdAidl : public testing::TestWithParam { isBridgedSupport = testing::checkSubstringInCommandOutput( "/system/bin/cmd wifi get-softap-supported-features", "wifi_softap_bridged_ap_supported"); - const std::vector instances = android::hardware::getAllHalInstanceNames( - ::android::hardware::wifi::V1_0::IWifi::descriptor); - EXPECT_NE(0, instances.size()); - wifiInstanceName = instances[0]; + if (!isAidlServiceAvailable(kWifiAidlInstanceName)) { + const std::vector instances = android::hardware::getAllHalInstanceNames( + ::android::hardware::wifi::V1_0::IWifi::descriptor); + EXPECT_NE(0, instances.size()); + wifiHidlInstanceName = instances[0]; + } } virtual void TearDown() override { - if (getWifi(wifiInstanceName) != nullptr) { - stopWifi(wifiInstanceName); - } + stopVendorHal(); hostapd->terminate(); // Wait 3 seconds to allow terminate to complete sleep(3); } std::shared_ptr hostapd; - std::string wifiInstanceName; + std::string wifiHidlInstanceName; bool isAcsSupport; bool isWpa3SaeSupport; bool isBridgedSupport; + void stopVendorHal() { + if (isAidlServiceAvailable(kWifiAidlInstanceName)) { + // HIDL and AIDL versions of getWifi() take different arguments + // i.e. const char* vs string + if (getWifi(kWifiAidlInstanceName) != nullptr) { + stopWifiService(kWifiAidlInstanceName); + } + } else { + if (getWifi(wifiHidlInstanceName) != nullptr) { + stopWifi(wifiHidlInstanceName); + } + } + } + std::string setupApIfaceAndGetName(bool isBridged) { + if (isAidlServiceAvailable(kWifiAidlInstanceName)) { + return setupApIfaceAndGetNameAidl(isBridged); + } else { + return setupApIfaceAndGetNameHidl(isBridged); + } + } + + std::string setupApIfaceAndGetNameAidl(bool isBridged) { + std::shared_ptr wifi_ap_iface; + if (isBridged) { + wifi_ap_iface = getBridgedWifiApIface(kWifiAidlInstanceName); + } else { + wifi_ap_iface = getWifiApIface(kWifiAidlInstanceName); + } + EXPECT_NE(nullptr, wifi_ap_iface.get()); + + std::string ap_iface_name; + auto status = wifi_ap_iface->getName(&ap_iface_name); + EXPECT_TRUE(status.isOk()); + return ap_iface_name; + } + + std::string setupApIfaceAndGetNameHidl(bool isBridged) { android::sp<::android::hardware::wifi::V1_0::IWifiApIface> wifi_ap_iface; if (isBridged) { - wifi_ap_iface = getBridgedWifiApIface_1_5(wifiInstanceName); + wifi_ap_iface = getBridgedWifiApIface_1_5(wifiHidlInstanceName); } else { - wifi_ap_iface = getWifiApIface_1_5(wifiInstanceName); + wifi_ap_iface = getWifiApIface_1_5(wifiHidlInstanceName); } EXPECT_NE(nullptr, wifi_ap_iface.get()); diff --git a/wifi/supplicant/aidl/vts/functional/Android.bp b/wifi/supplicant/aidl/vts/functional/Android.bp index b959c7504d..f7c619ab51 100644 --- a/wifi/supplicant/aidl/vts/functional/Android.bp +++ b/wifi/supplicant/aidl/vts/functional/Android.bp @@ -50,6 +50,8 @@ cc_test { "VtsHalWifiV1_0TargetTestUtil", "VtsHalWifiV1_5TargetTestUtil", "VtsHalWifiSupplicantV1_0TargetTestUtil", + "android.hardware.wifi-V1-ndk", + "VtsHalWifiTargetTestUtil", ], test_suites: [ "general-tests", @@ -84,6 +86,8 @@ cc_test { "VtsHalWifiV1_0TargetTestUtil", "VtsHalWifiV1_5TargetTestUtil", "VtsHalWifiSupplicantV1_0TargetTestUtil", + "android.hardware.wifi-V1-ndk", + "VtsHalWifiTargetTestUtil", ], test_suites: [ "general-tests", @@ -118,6 +122,8 @@ cc_test { "VtsHalWifiV1_0TargetTestUtil", "VtsHalWifiV1_5TargetTestUtil", "VtsHalWifiSupplicantV1_0TargetTestUtil", + "android.hardware.wifi-V1-ndk", + "VtsHalWifiTargetTestUtil", ], test_suites: [ "general-tests", diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_aidl_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_aidl_test_utils.h new file mode 100644 index 0000000000..a850e507f0 --- /dev/null +++ b/wifi/supplicant/aidl/vts/functional/supplicant_aidl_test_utils.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include "wifi_aidl_test_utils.h" + +using android::wifi_system::SupplicantManager; + +// Helper methods to interact with wifi_aidl_test_utils +namespace SupplicantAidlTestUtils { +const std::string kWifiInstanceNameStr = std::string() + IWifi::descriptor + "/default"; +const char* kWifiInstanceName = kWifiInstanceNameStr.c_str(); + +// Initialize the driver and firmware to STA mode using the vendor HAL. +void initializeDriverAndFirmware(const std::string& wifi_instance_name) { + // Skip if wifi instance is not set. + if (wifi_instance_name == "") { + return; + } + if (getWifi(wifi_instance_name.c_str()) != nullptr) { + std::shared_ptr wifi_chip = getWifiChip(wifi_instance_name.c_str()); + int mode_id; + EXPECT_TRUE(configureChipToSupportConcurrencyType(wifi_chip, IfaceConcurrencyType::STA, + &mode_id)); + } else { + LOG(WARNING) << __func__ << ": Vendor HAL not supported"; + } +} + +// Deinitialize the driver and firmware using the vendor HAL. +void deInitializeDriverAndFirmware(const std::string& wifi_instance_name) { + // Skip if wifi instance is not set. + if (wifi_instance_name == "") { + return; + } + if (getWifi(wifi_instance_name.c_str()) != nullptr) { + stopWifiService(wifi_instance_name.c_str()); + } else { + LOG(WARNING) << __func__ << ": Vendor HAL not supported"; + } +} + +bool waitForSupplicantState(bool is_running) { + SupplicantManager supplicant_manager; + int count = 50; /* wait at most 5 seconds for completion */ + while (count-- > 0) { + if (supplicant_manager.IsSupplicantRunning() == is_running) { + return true; + } + usleep(100000); + } + LOG(ERROR) << "Unable to " << (is_running ? "start" : "stop") << " supplicant"; + return false; +} + +bool waitForSupplicantStart() { + return waitForSupplicantState(true); +} + +bool waitForSupplicantStop() { + return waitForSupplicantState(false); +} + +bool waitForWifiHalStop(const std::string& wifi_instance_name) { + std::shared_ptr wifi = getWifi(wifi_instance_name.c_str()); + int count = 50; /* wait at most 5 seconds for completion */ + while (count-- > 0) { + if (wifi != nullptr) { + bool started = false; + auto status = wifi->isStarted(&started); + if (status.isOk() && !started) { + return true; + } + } + usleep(100000); + wifi = getWifi(wifi_instance_name.c_str()); + } + LOG(ERROR) << "Wifi HAL was not stopped"; + return false; +} + +bool waitForFrameworkReady() { + int waitCount = 15; + do { + // Check whether package service is ready or not. + if (!testing::checkSubstringInCommandOutput("/system/bin/service check package", + ": not found")) { + return true; + } + LOG(INFO) << "Framework is not ready"; + sleep(1); + } while (waitCount-- > 0); + return false; +} + +bool useAidlService() { + return isAidlServiceAvailable(kWifiInstanceName); +} + +void startSupplicant() { + initializeDriverAndFirmware(kWifiInstanceName); + SupplicantManager supplicant_manager; + ASSERT_TRUE(supplicant_manager.StartSupplicant()); + ASSERT_TRUE(supplicant_manager.IsSupplicantRunning()); +} + +void stopSupplicantService() { + SupplicantManager supplicant_manager; + ASSERT_TRUE(supplicant_manager.StopSupplicant()); + deInitializeDriverAndFirmware(kWifiInstanceName); + ASSERT_FALSE(supplicant_manager.IsSupplicantRunning()); +} + +bool stopWifiFramework(const std::string& wifi_instance_name) { + std::system("svc wifi disable"); + std::system("cmd wifi set-scan-always-available disabled"); + return waitForSupplicantStop() && waitForWifiHalStop(wifi_instance_name); +} + +void initializeService() { + ASSERT_TRUE(stopWifiFramework(kWifiInstanceName)); + std::system("/system/bin/start"); + ASSERT_TRUE(waitForFrameworkReady()); + stopSupplicantService(); + startSupplicant(); +} +} // namespace SupplicantAidlTestUtils diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_legacy_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_legacy_test_utils.h new file mode 100644 index 0000000000..a20a45846b --- /dev/null +++ b/wifi/supplicant/aidl/vts/functional/supplicant_legacy_test_utils.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +using android::wifi_system::SupplicantManager; + +// Helper methods to interact with supplicant_hidl_test_utils +namespace SupplicantLegacyTestUtils { +std::string getWifiInstanceName() { + const std::vector instances = android::hardware::getAllHalInstanceNames( + ::android::hardware::wifi::V1_0::IWifi::descriptor); + EXPECT_NE(0, instances.size()); + return instances.size() != 0 ? instances[0] : ""; +} + +void stopSupplicantService() { + stopSupplicant(getWifiInstanceName()); +} + +void startSupplicant() { + initializeDriverAndFirmware(getWifiInstanceName()); + SupplicantManager supplicant_manager; + ASSERT_TRUE(supplicant_manager.StartSupplicant()); + ASSERT_TRUE(supplicant_manager.IsSupplicantRunning()); +} + +void initializeService() { + ASSERT_TRUE(stopWifiFramework(getWifiInstanceName())); + std::system("/system/bin/start"); + ASSERT_TRUE(waitForFrameworkReady()); + stopSupplicantService(); + startSupplicant(); +} +} // namespace SupplicantLegacyTestUtils diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h index 31042a2b7c..7eeab6870d 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h +++ b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h @@ -14,22 +14,16 @@ * limitations under the License. */ -#ifndef SUPPLICANT_TEST_UTILS_H -#define SUPPLICANT_TEST_UTILS_H +#pragma once -#include -#include -#include -#include -#include -#include +#include "supplicant_aidl_test_utils.h" +#include "supplicant_legacy_test_utils.h" using aidl::android::hardware::wifi::supplicant::IfaceInfo; using aidl::android::hardware::wifi::supplicant::ISupplicant; using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface; using aidl::android::hardware::wifi::supplicant::ISupplicantStaIface; using aidl::android::hardware::wifi::supplicant::KeyMgmtMask; -using android::wifi_system::SupplicantManager; std::string getStaIfaceName() { std::array buffer; @@ -43,16 +37,7 @@ std::string getP2pIfaceName() { return std::string(buffer.data()); } -std::string getWifiInstanceName() { - const std::vector instances = - android::hardware::getAllHalInstanceNames( - ::android::hardware::wifi::V1_0::IWifi::descriptor); - EXPECT_NE(0, instances.size()); - return instances.size() != 0 ? instances[0] : ""; -} - -bool keyMgmtSupported(std::shared_ptr iface, - KeyMgmtMask expected) { +bool keyMgmtSupported(std::shared_ptr iface, KeyMgmtMask expected) { KeyMgmtMask caps; if (!iface->getKeyMgmtCapabilities(&caps).isOk()) { return false; @@ -67,22 +52,22 @@ bool isFilsSupported(std::shared_ptr iface) { return keyMgmtSupported(iface, filsMask); } -void startSupplicant() { - initializeDriverAndFirmware(getWifiInstanceName()); - SupplicantManager supplicant_manager; - ASSERT_TRUE(supplicant_manager.StartSupplicant()); - ASSERT_TRUE(supplicant_manager.IsSupplicantRunning()); +void stopSupplicantService() { + // Select method based on whether the HIDL or AIDL + // Vendor HAL is available. + if (SupplicantAidlTestUtils::useAidlService()) { + SupplicantAidlTestUtils::stopSupplicantService(); + } else { + SupplicantLegacyTestUtils::stopSupplicantService(); + } } -// Wrapper around the implementation in supplicant_hidl_test_util. -void stopSupplicantService() { stopSupplicant(getWifiInstanceName()); } - void initializeService() { - ASSERT_TRUE(stopWifiFramework(getWifiInstanceName())); - std::system("/system/bin/start"); - ASSERT_TRUE(waitForFrameworkReady()); - stopSupplicantService(); - startSupplicant(); + if (SupplicantAidlTestUtils::useAidlService()) { + SupplicantAidlTestUtils::stopSupplicantService(); + } else { + SupplicantLegacyTestUtils::stopSupplicantService(); + } } void addStaIface(const std::shared_ptr supplicant) { @@ -106,5 +91,3 @@ std::shared_ptr getSupplicant(const char* supplicant_name) { } return supplicant; } - -#endif // SUPPLICANT_TEST_UTILS_H \ No newline at end of file