Merge changes from topic "switch-to-aidl-vendor-hal"

* changes:
  Update VTS test dependencies.
  Update Vendor HAL APEX to use the AIDL service.
This commit is contained in:
Gabriel Biren 2022-12-09 18:01:54 +00:00 committed by Android (Google) Code Review
commit f2efc21d5d
10 changed files with 289 additions and 49 deletions

View file

@ -214,3 +214,7 @@ int32_t getChipCapabilities(const std::shared_ptr<IWifiChip>& wifi_chip) {
}
return 0;
}
bool isAidlServiceAvailable(const char* instance_name) {
return AServiceManager_isDeclared(instance_name);
}

View file

@ -46,3 +46,4 @@ bool configureChipToSupportConcurrencyType(const std::shared_ptr<IWifiChip>& wif
void stopWifiService(const char* instance_name);
int32_t getChipCapabilities(const std::shared_ptr<IWifiChip>& wifi_chip);
bool checkStatusCode(ndk::ScopedAStatus* status, WifiStatusCode expected_code);
bool isAidlServiceAvailable(const char* instance_name);

View file

@ -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",
],
}

View file

@ -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

View file

@ -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",

View file

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/wifi/IWifi.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <android/hardware/wifi/hostapd/1.3/IHostapd.h>
@ -30,6 +31,8 @@
#include <wifi_hidl_test_utils.h>
#include <wifi_hidl_test_utils_1_5.h>
#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<uint8_t> 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<BandMask>(static_cast<int32_t>(a) |
@ -77,33 +82,70 @@ class HostapdAidl : public testing::TestWithParam<std::string> {
isBridgedSupport = testing::checkSubstringInCommandOutput(
"/system/bin/cmd wifi get-softap-supported-features",
"wifi_softap_bridged_ap_supported");
if (!isAidlServiceAvailable(kWifiAidlInstanceName)) {
const std::vector<std::string> instances = android::hardware::getAllHalInstanceNames(
::android::hardware::wifi::V1_0::IWifi::descriptor);
EXPECT_NE(0, instances.size());
wifiInstanceName = instances[0];
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<IHostapd> 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<IWifiApIface> 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());

View file

@ -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",

View file

@ -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 <VtsCoreUtil.h>
#include <aidl/android/hardware/wifi/IWifi.h>
#include <android-base/logging.h>
#include <wifi_system/supplicant_manager.h>
#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<IWifiChip> 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<IWifi> 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

View file

@ -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 <VtsCoreUtil.h>
#include <android-base/logging.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <hidl/ServiceManagement.h>
#include <supplicant_hidl_test_utils.h>
#include <wifi_system/supplicant_manager.h>
using android::wifi_system::SupplicantManager;
// Helper methods to interact with supplicant_hidl_test_utils
namespace SupplicantLegacyTestUtils {
std::string getWifiInstanceName() {
const std::vector<std::string> 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

View file

@ -14,22 +14,16 @@
* limitations under the License.
*/
#ifndef SUPPLICANT_TEST_UTILS_H
#define SUPPLICANT_TEST_UTILS_H
#pragma once
#include <VtsCoreUtil.h>
#include <android-base/logging.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <hidl/ServiceManagement.h>
#include <supplicant_hidl_test_utils.h>
#include <wifi_system/supplicant_manager.h>
#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<char, PROPERTY_VALUE_MAX> buffer;
@ -43,16 +37,7 @@ std::string getP2pIfaceName() {
return std::string(buffer.data());
}
std::string getWifiInstanceName() {
const std::vector<std::string> 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<ISupplicantStaIface> iface,
KeyMgmtMask expected) {
bool keyMgmtSupported(std::shared_ptr<ISupplicantStaIface> iface, KeyMgmtMask expected) {
KeyMgmtMask caps;
if (!iface->getKeyMgmtCapabilities(&caps).isOk()) {
return false;
@ -67,22 +52,22 @@ bool isFilsSupported(std::shared_ptr<ISupplicantStaIface> 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<ISupplicant> supplicant) {
@ -106,5 +91,3 @@ std::shared_ptr<ISupplicant> getSupplicant(const char* supplicant_name) {
}
return supplicant;
}
#endif // SUPPLICANT_TEST_UTILS_H