• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <VtsCoreUtil.h>
18 #include <aidl/Gtest.h>
19 #include <aidl/Vintf.h>
20 #include <aidl/android/hardware/wifi/supplicant/BnSupplicant.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_status.h>
23 #include <binder/IServiceManager.h>
24 #include <binder/ProcessState.h>
25 #include <cutils/properties.h>
26 
27 #include "supplicant_test_utils.h"
28 #include "wifi_aidl_test_utils.h"
29 
30 using aidl::android::hardware::wifi::supplicant::DebugLevel;
31 using aidl::android::hardware::wifi::supplicant::IfaceType;
32 using aidl::android::hardware::wifi::supplicant::ISupplicantP2pNetwork;
33 using aidl::android::hardware::wifi::supplicant::MacAddress;
34 using android::ProcessState;
35 
36 class SupplicantP2pNetworkAidlTest : public testing::TestWithParam<std::string> {
37   public:
SetUp()38     void SetUp() override {
39         initializeService();
40         supplicant_ = getSupplicant(GetParam().c_str());
41         ASSERT_NE(supplicant_, nullptr);
42         ASSERT_TRUE(supplicant_->setDebugParams(DebugLevel::EXCESSIVE, true, true).isOk());
43 
44         bool p2pEnabled = testing::deviceSupportsFeature("android.hardware.wifi.direct");
45         if (!p2pEnabled) {
46             GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
47         }
48 
49         EXPECT_TRUE(supplicant_->getP2pInterface(getP2pIfaceName(), &p2p_iface_).isOk());
50         ASSERT_NE(p2p_iface_, nullptr);
51 
52         // Create a persistent group to bring up a network
53         EXPECT_TRUE(p2p_iface_->addGroup(true /* persistent */, -1).isOk());
54         sleep(2);
55 
56         std::vector<int32_t> networkList;
57         EXPECT_TRUE(p2p_iface_->listNetworks(&networkList).isOk());
58         ASSERT_FALSE(networkList.empty());
59 
60         network_id_ = networkList[0];
61         EXPECT_TRUE(p2p_iface_->getNetwork(network_id_, &p2p_network_).isOk());
62         ASSERT_NE(p2p_network_, nullptr);
63     }
64 
TearDown()65     void TearDown() override {
66         if (p2p_iface_ != nullptr) {
67             EXPECT_TRUE(p2p_iface_->removeNetwork(network_id_).isOk());
68         }
69         stopSupplicantService();
70         startWifiFramework();
71     }
72 
73   protected:
74     std::shared_ptr<ISupplicant> supplicant_;
75     std::shared_ptr<ISupplicantP2pIface> p2p_iface_;
76     std::shared_ptr<ISupplicantP2pNetwork> p2p_network_;
77     int network_id_;
78 };
79 
80 /*
81  * GetBssid
82  */
TEST_P(SupplicantP2pNetworkAidlTest,GetBssid)83 TEST_P(SupplicantP2pNetworkAidlTest, GetBssid) {
84     std::vector<uint8_t> bssid;
85     EXPECT_TRUE(p2p_network_->getBssid(&bssid).isOk());
86 }
87 
88 /*
89  * GetClientList
90  */
TEST_P(SupplicantP2pNetworkAidlTest,GetClientList)91 TEST_P(SupplicantP2pNetworkAidlTest, GetClientList) {
92     // Expect failure if there are no clients
93     std::vector<MacAddress> clientList;
94     EXPECT_FALSE(p2p_network_->getClientList(&clientList).isOk());
95 }
96 
97 /*
98  * GetId
99  */
TEST_P(SupplicantP2pNetworkAidlTest,GetId)100 TEST_P(SupplicantP2pNetworkAidlTest, GetId) {
101     int networkId;
102     EXPECT_TRUE(p2p_network_->getId(&networkId).isOk());
103 }
104 
105 /*
106  * GetInterfaceName
107  */
TEST_P(SupplicantP2pNetworkAidlTest,GetInterfaceName)108 TEST_P(SupplicantP2pNetworkAidlTest, GetInterfaceName) {
109     std::string expectedName = getP2pIfaceName();
110     std::string retrievedName;
111     EXPECT_TRUE(p2p_network_->getInterfaceName(&retrievedName).isOk());
112     EXPECT_EQ(retrievedName, expectedName);
113 }
114 
115 /*
116  * GetSsid
117  */
TEST_P(SupplicantP2pNetworkAidlTest,GetSsid)118 TEST_P(SupplicantP2pNetworkAidlTest, GetSsid) {
119     std::vector<uint8_t> ssid;
120     EXPECT_TRUE(p2p_network_->getSsid(&ssid).isOk());
121 }
122 
123 /*
124  * GetType
125  */
TEST_P(SupplicantP2pNetworkAidlTest,GetType)126 TEST_P(SupplicantP2pNetworkAidlTest, GetType) {
127     IfaceType ifaceType;
128     EXPECT_TRUE(p2p_network_->getType(&ifaceType).isOk());
129     EXPECT_EQ(ifaceType, IfaceType::P2P);
130 }
131 
132 /*
133  * IsCurrent
134  */
TEST_P(SupplicantP2pNetworkAidlTest,IsCurrent)135 TEST_P(SupplicantP2pNetworkAidlTest, IsCurrent) {
136     bool isCurrent;
137     EXPECT_TRUE(p2p_network_->isCurrent(&isCurrent).isOk());
138     EXPECT_FALSE(isCurrent);
139 }
140 
141 /*
142  * IsGroupOwner
143  */
TEST_P(SupplicantP2pNetworkAidlTest,IsGroupOwner)144 TEST_P(SupplicantP2pNetworkAidlTest, IsGroupOwner) {
145     bool isGroupOwner;
146     EXPECT_TRUE(p2p_network_->isGroupOwner(&isGroupOwner).isOk());
147     // Configured network is a group owner
148     EXPECT_TRUE(isGroupOwner);
149 }
150 
151 /*
152  * IsPersistent
153  */
TEST_P(SupplicantP2pNetworkAidlTest,IsPersistent)154 TEST_P(SupplicantP2pNetworkAidlTest, IsPersistent) {
155     bool isPersistent;
156     EXPECT_TRUE(p2p_network_->isPersistent(&isPersistent).isOk());
157     // Configured network is persistent
158     EXPECT_TRUE(isPersistent);
159 }
160 
161 /*
162  * SetClientList
163  */
TEST_P(SupplicantP2pNetworkAidlTest,SetClientList)164 TEST_P(SupplicantP2pNetworkAidlTest, SetClientList) {
165     MacAddress client = {{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}};
166     std::vector clientList = {client};
167     EXPECT_TRUE(p2p_network_->setClientList(clientList).isOk());
168 }
169 
170 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pNetworkAidlTest);
171 INSTANTIATE_TEST_SUITE_P(
172         Supplicant, SupplicantP2pNetworkAidlTest,
173         testing::ValuesIn(android::getAidlHalInstanceNames(ISupplicant::descriptor)),
174         android::PrintInstanceNameToString);
175 
main(int argc,char ** argv)176 int main(int argc, char** argv) {
177     ::testing::InitGoogleTest(&argc, argv);
178     ProcessState::self()->setThreadPoolMaxThreadCount(1);
179     ProcessState::self()->startThreadPool();
180     return RUN_ALL_TESTS();
181 }
182