• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 <android-base/logging.h>
18 #include <gtest/gtest.h>
19 #include <hidl/GtestPrinter.h>
20 #include <hidl/ServiceManagement.h>
21 
22 #include <VtsCoreUtil.h>
23 #include <android/hardware/wifi/1.0/IWifi.h>
24 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h>
25 
26 #include "supplicant_hidl_call_util.h"
27 #include "supplicant_hidl_test_utils.h"
28 
29 using ::android::sp;
30 using ::android::hardware::hidl_array;
31 using ::android::hardware::hidl_string;
32 using ::android::hardware::hidl_vec;
33 using ::android::hardware::Return;
34 using ::android::hardware::Void;
35 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
36 using ::android::hardware::wifi::supplicant::V1_0::ISupplicant;
37 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface;
38 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIfaceCallback;
39 using ::android::hardware::wifi::supplicant::V1_0::SupplicantNetworkId;
40 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
41 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
42 using ::android::hardware::wifi::V1_0::IWifi;
43 
44 namespace {
45 constexpr uint8_t kTestSsidPostfix[] = {'t', 'e', 's', 't'};
46 constexpr uint8_t kTestMacAddr[] = {0x56, 0x67, 0x67, 0xf4, 0x56, 0x92};
47 constexpr uint8_t kTestPeerMacAddr[] = {0x56, 0x67, 0x55, 0xf4, 0x56, 0x92};
48 constexpr uint8_t kTestBonjourServiceQuery[] = {'t', 'e', 's', 't', 'q',
49                                                 'u', 'e', 'r', 'y'};
50 constexpr uint8_t kTestBonjourServiceResponse[] = {
51     't', 'e', 's', 't', 'r', 'e', 's', 'p', 'o', 'n', 's', 'e'};
52 constexpr uint8_t kTestWfdDeviceInfo[] = {[0 ... 5] = 0x01};
53 constexpr char kTestConnectPin[] = "34556665";
54 constexpr char kTestGroupIfName[] = "TestGroup";
55 constexpr char kTestWpsDeviceName[] = "TestWpsDeviceName";
56 constexpr char kTestWpsManufacturer[] = "TestManufacturer";
57 constexpr char kTestWpsModelName[] = "TestModelName";
58 constexpr char kTestWpsModelNumber[] = "TestModelNumber";
59 constexpr char kTestWpsSerialNumber[] = "TestSerialNumber";
60 constexpr char kTestUpnpServiceName[] = "TestServiceName";
61 constexpr uint8_t kTestWpsDeviceType[] = {[0 ... 7] = 0x01};
62 constexpr uint16_t kTestWpsConfigMethods = 0xffff;
63 constexpr uint32_t kTestConnectGoIntent = 6;
64 constexpr uint32_t kTestFindTimeout = 5;
65 constexpr uint32_t kTestSetGroupIdleTimeout = 6;
66 constexpr uint32_t kTestChannel = 1;
67 constexpr uint32_t kTestOperatingClass = 81;
68 constexpr uint32_t kTestFreqRange[] = {2412, 2432};
69 constexpr uint32_t kTestExtListenPeriod = 400;
70 constexpr uint32_t kTestExtListenInterval = 400;
71 constexpr SupplicantNetworkId kTestNetworkId = 5;
72 }  // namespace
73 
74 class SupplicantP2pIfaceHidlTest : public SupplicantHidlTestBaseV1_0 {
75    public:
SetUp()76     virtual void SetUp() override {
77         SupplicantHidlTestBaseV1_0::SetUp();
78         if (!isP2pOn_) {
79             GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
80         }
81         p2p_iface_ = getSupplicantP2pIface(supplicant_);
82         ASSERT_NE(p2p_iface_.get(), nullptr);
83 
84         memcpy(mac_addr_.data(), kTestMacAddr, mac_addr_.size());
85         memcpy(peer_mac_addr_.data(), kTestPeerMacAddr, peer_mac_addr_.size());
86     }
87 
88    protected:
89     sp<ISupplicantP2pIface> p2p_iface_;
90     // MAC address to use for various tests.
91     std::array<uint8_t, 6> mac_addr_;
92     std::array<uint8_t, 6> peer_mac_addr_;
93 };
94 
95 class IfaceCallback : public ISupplicantP2pIfaceCallback {
onNetworkAdded(uint32_t)96     Return<void> onNetworkAdded(uint32_t /* id */) override { return Void(); }
onNetworkRemoved(uint32_t)97     Return<void> onNetworkRemoved(uint32_t /* id */) override { return Void(); }
onDeviceFound(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,8> &,const hidl_string &,uint16_t,uint8_t,uint32_t,const hidl_array<uint8_t,6> &)98     Return<void> onDeviceFound(
99         const hidl_array<uint8_t, 6>& /* srcAddress */,
100         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */,
101         const hidl_array<uint8_t, 8>& /* primaryDeviceType */,
102         const hidl_string& /* deviceName */, uint16_t /* configMethods */,
103         uint8_t /* deviceCapabilities */, uint32_t /* groupCapabilities */,
104         const hidl_array<uint8_t, 6>& /* wfdDeviceInfo */) override {
105         return Void();
106     }
onDeviceLost(const hidl_array<uint8_t,6> &)107     Return<void> onDeviceLost(
108         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
109         return Void();
110     }
onFindStopped()111     Return<void> onFindStopped() override { return Void(); }
onGoNegotiationRequest(const hidl_array<uint8_t,6> &,ISupplicantP2pIfaceCallback::WpsDevPasswordId)112     Return<void> onGoNegotiationRequest(
113         const hidl_array<uint8_t, 6>& /* srcAddress */,
114         ISupplicantP2pIfaceCallback::WpsDevPasswordId /* passwordId */)
115         override {
116         return Void();
117     }
onGoNegotiationCompleted(ISupplicantP2pIfaceCallback::P2pStatusCode)118     Return<void> onGoNegotiationCompleted(
119         ISupplicantP2pIfaceCallback::P2pStatusCode /* status */) override {
120         return Void();
121     }
onGroupFormationSuccess()122     Return<void> onGroupFormationSuccess() override { return Void(); }
onGroupFormationFailure(const hidl_string &)123     Return<void> onGroupFormationFailure(
124         const hidl_string& /* failureReason */) override {
125         return Void();
126     }
onGroupStarted(const hidl_string &,bool,const hidl_vec<uint8_t> &,uint32_t,const hidl_array<uint8_t,32> &,const hidl_string &,const hidl_array<uint8_t,6> &,bool)127     Return<void> onGroupStarted(
128         const hidl_string& /* groupIfname */, bool /* isGo */,
129         const hidl_vec<uint8_t>& /* ssid */, uint32_t /* frequency */,
130         const hidl_array<uint8_t, 32>& /* psk */,
131         const hidl_string& /* passphrase */,
132         const hidl_array<uint8_t, 6>& /* goDeviceAddress */,
133         bool /* isPersistent */) override {
134         return Void();
135     }
onGroupRemoved(const hidl_string &,bool)136     Return<void> onGroupRemoved(const hidl_string& /* groupIfname */,
137                                 bool /* isGo */) override {
138         return Void();
139     }
onInvitationReceived(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &,uint32_t,uint32_t)140     Return<void> onInvitationReceived(
141         const hidl_array<uint8_t, 6>& /* srcAddress */,
142         const hidl_array<uint8_t, 6>& /* goDeviceAddress */,
143         const hidl_array<uint8_t, 6>& /* bssid */,
144         uint32_t /* persistentNetworkId */,
145         uint32_t /* operatingFrequency */) override {
146         return Void();
147     }
onInvitationResult(const hidl_array<uint8_t,6> &,ISupplicantP2pIfaceCallback::P2pStatusCode)148     Return<void> onInvitationResult(
149         const hidl_array<uint8_t, 6>& /* bssid */,
150         ISupplicantP2pIfaceCallback::P2pStatusCode /* status */) override {
151         return Void();
152     }
onProvisionDiscoveryCompleted(const hidl_array<uint8_t,6> &,bool,ISupplicantP2pIfaceCallback::P2pProvDiscStatusCode,uint16_t,const hidl_string &)153     Return<void> onProvisionDiscoveryCompleted(
154         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */,
155         bool /* isRequest */,
156         ISupplicantP2pIfaceCallback::P2pProvDiscStatusCode /* status */,
157         uint16_t /* configMethods */,
158         const hidl_string& /* generatedPin */) override {
159         return Void();
160     }
onServiceDiscoveryResponse(const hidl_array<uint8_t,6> &,uint16_t,const hidl_vec<uint8_t> &)161     Return<void> onServiceDiscoveryResponse(
162         const hidl_array<uint8_t, 6>& /* srcAddress */,
163         uint16_t /* updateIndicator */,
164         const hidl_vec<uint8_t>& /* tlvs */) override {
165         return Void();
166     }
onStaAuthorized(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &)167     Return<void> onStaAuthorized(
168         const hidl_array<uint8_t, 6>& /* srcAddress */,
169         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
170         return Void();
171     }
onStaDeauthorized(const hidl_array<uint8_t,6> &,const hidl_array<uint8_t,6> &)172     Return<void> onStaDeauthorized(
173         const hidl_array<uint8_t, 6>& /* srcAddress */,
174         const hidl_array<uint8_t, 6>& /* p2pDeviceAddress */) override {
175         return Void();
176     }
177 };
178 
179 /*
180  * Create:
181  * Ensures that an instance of the ISupplicantP2pIface proxy object is
182  * successfully created.
183  */
TEST_P(SupplicantP2pIfaceHidlTest,Create)184 TEST_P(SupplicantP2pIfaceHidlTest, Create) {
185     stopSupplicant(wifi_v1_0_instance_name_);
186     startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_,
187                                          supplicant_instance_name_);
188     sp<ISupplicantP2pIface> p2p_iface = getSupplicantP2pIface(
189         getSupplicant(supplicant_instance_name_, isP2pOn_));
190 
191     EXPECT_NE(nullptr, p2p_iface.get());
192 }
193 
194 /*
195  * RegisterCallback
196  */
TEST_P(SupplicantP2pIfaceHidlTest,RegisterCallback)197 TEST_P(SupplicantP2pIfaceHidlTest, RegisterCallback) {
198     p2p_iface_->registerCallback(
199         new IfaceCallback(), [](const SupplicantStatus& status) {
200             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
201         });
202 }
203 
204 /*
205  * GetName
206  */
TEST_P(SupplicantP2pIfaceHidlTest,GetName)207 TEST_P(SupplicantP2pIfaceHidlTest, GetName) {
208     const auto& status_and_interface_name = HIDL_INVOKE(p2p_iface_, getName);
209     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
210               status_and_interface_name.first.code);
211     EXPECT_FALSE(std::string(status_and_interface_name.second).empty());
212 }
213 
214 /*
215  * GetType
216  */
TEST_P(SupplicantP2pIfaceHidlTest,GetType)217 TEST_P(SupplicantP2pIfaceHidlTest, GetType) {
218     const auto& status_and_interface_type = HIDL_INVOKE(p2p_iface_, getType);
219     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
220               status_and_interface_type.first.code);
221     EXPECT_EQ(status_and_interface_type.second, IfaceType::P2P);
222 }
223 
224 /*
225  * GetDeviceAddress
226  */
TEST_P(SupplicantP2pIfaceHidlTest,GetDeviceAddress)227 TEST_P(SupplicantP2pIfaceHidlTest, GetDeviceAddress) {
228     p2p_iface_->getDeviceAddress(
229         [](const SupplicantStatus& status,
230            const hidl_array<uint8_t, 6>& /* mac_addr */) {
231             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
232         });
233 }
234 
235 /*
236  * SetSsidPostfix
237  */
TEST_P(SupplicantP2pIfaceHidlTest,SetSsidPostfix)238 TEST_P(SupplicantP2pIfaceHidlTest, SetSsidPostfix) {
239     std::vector<uint8_t> ssid(kTestSsidPostfix,
240                               kTestSsidPostfix + sizeof(kTestSsidPostfix));
241     p2p_iface_->setSsidPostfix(ssid, [](const SupplicantStatus& status) {
242         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
243     });
244 }
245 
246 /*
247  * Find
248  */
TEST_P(SupplicantP2pIfaceHidlTest,Find)249 TEST_P(SupplicantP2pIfaceHidlTest, Find) {
250     p2p_iface_->find(kTestFindTimeout, [](const SupplicantStatus& status) {
251         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
252     });
253 }
254 
255 /*
256  * StopFind
257  */
TEST_P(SupplicantP2pIfaceHidlTest,StopFind)258 TEST_P(SupplicantP2pIfaceHidlTest, StopFind) {
259     p2p_iface_->find(kTestFindTimeout, [](const SupplicantStatus& status) {
260         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
261     });
262 
263     p2p_iface_->stopFind([](const SupplicantStatus& status) {
264         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
265     });
266 }
267 
268 /*
269  * Flush
270  */
TEST_P(SupplicantP2pIfaceHidlTest,Flush)271 TEST_P(SupplicantP2pIfaceHidlTest, Flush) {
272     p2p_iface_->flush([](const SupplicantStatus& status) {
273         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
274     });
275 }
276 
277 /*
278  * Connect
279  */
TEST_P(SupplicantP2pIfaceHidlTest,Connect)280 TEST_P(SupplicantP2pIfaceHidlTest, Connect) {
281     p2p_iface_->connect(
282         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
283         kTestConnectPin, false, false, kTestConnectGoIntent,
284         [](const SupplicantStatus& status, const hidl_string& /* pin */) {
285             /*
286              * Before R, auto-join is not enabled and it is not going to work
287              * with fake values. After enabling auto-join, it will succeed
288              * always.
289              */
290             LOG(INFO) << "ISupplicantP2pIface::connect() ret: "
291                       << toString(status);
292             if (SupplicantStatusCode::FAILURE_UNKNOWN != status.code &&
293                 SupplicantStatusCode::SUCCESS != status.code) {
294                 FAIL();
295             }
296         });
297 }
298 
299 /*
300  * CancelConnect
301  */
TEST_P(SupplicantP2pIfaceHidlTest,CancelConnect)302 TEST_P(SupplicantP2pIfaceHidlTest, CancelConnect) {
303     p2p_iface_->connect(
304         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
305         kTestConnectPin, false, false, kTestConnectGoIntent,
306         [](const SupplicantStatus& status, const hidl_string& /* pin */) {
307             /*
308              * Before R, auto-join is not enabled and it is not going to work
309              * with fake values. After enabling auto-join, it will succeed
310              * always.
311              */
312             LOG(INFO) << "ISupplicantP2pIface::connect() ret: "
313                       << toString(status);
314             if (SupplicantStatusCode::FAILURE_UNKNOWN != status.code &&
315                 SupplicantStatusCode::SUCCESS != status.code) {
316                 FAIL();
317             }
318         });
319 
320     p2p_iface_->cancelConnect([](const SupplicantStatus& status) {
321         LOG(INFO) << "ISupplicantP2pIface::cancelConnect() ret: "
322                   << toString(status);
323         if (SupplicantStatusCode::FAILURE_UNKNOWN != status.code &&
324             SupplicantStatusCode::SUCCESS != status.code) {
325             FAIL();
326         }
327     });
328 }
329 
330 /*
331  * ProvisionDiscovery
332  */
TEST_P(SupplicantP2pIfaceHidlTest,ProvisionDiscovery)333 TEST_P(SupplicantP2pIfaceHidlTest, ProvisionDiscovery) {
334     p2p_iface_->provisionDiscovery(
335         mac_addr_, ISupplicantP2pIface::WpsProvisionMethod::PBC,
336         [](const SupplicantStatus& status) {
337             // This is not going to work with fake values.
338             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
339         });
340 }
341 
342 /*
343  * AddGroup
344  */
TEST_P(SupplicantP2pIfaceHidlTest,AddGroup)345 TEST_P(SupplicantP2pIfaceHidlTest, AddGroup) {
346     p2p_iface_->addGroup(false, kTestNetworkId,
347                          [](const SupplicantStatus& /* status */) {
348                              // TODO: Figure out the initialization sequence for
349                              // this to work.
350                              // EXPECT_EQ(SupplicantStatusCode::SUCCESS,
351                              // status.code);
352                          });
353 }
354 
355 /*
356  * RemoveGroup
357  */
TEST_P(SupplicantP2pIfaceHidlTest,RemoveGroup)358 TEST_P(SupplicantP2pIfaceHidlTest, RemoveGroup) {
359     // This is not going to work with fake values.
360     EXPECT_NE(SupplicantStatusCode::SUCCESS,
361               HIDL_INVOKE(p2p_iface_, removeGroup, kTestGroupIfName).code);
362 }
363 
364 /*
365  * Reject
366  */
TEST_P(SupplicantP2pIfaceHidlTest,Reject)367 TEST_P(SupplicantP2pIfaceHidlTest, Reject) {
368     p2p_iface_->reject(mac_addr_, [](const SupplicantStatus& status) {
369         // This is not going to work with fake values.
370         EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
371     });
372 }
373 
374 /*
375  * Invite
376  */
TEST_P(SupplicantP2pIfaceHidlTest,Invite)377 TEST_P(SupplicantP2pIfaceHidlTest, Invite) {
378     p2p_iface_->invite(kTestGroupIfName, mac_addr_, peer_mac_addr_,
379                        [](const SupplicantStatus& status) {
380                            // This is not going to work with fake values.
381                            EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN,
382                                      status.code);
383                        });
384 }
385 
386 /*
387  * Reinvoke
388  */
TEST_P(SupplicantP2pIfaceHidlTest,Reinvoke)389 TEST_P(SupplicantP2pIfaceHidlTest, Reinvoke) {
390     p2p_iface_->reinvoke(
391         kTestNetworkId, mac_addr_, [](const SupplicantStatus& status) {
392             // This is not going to work with fake values.
393             EXPECT_EQ(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN,
394                       status.code);
395         });
396 }
397 
398 /*
399  * ConfigureExtListen
400  */
TEST_P(SupplicantP2pIfaceHidlTest,ConfigureExtListen)401 TEST_P(SupplicantP2pIfaceHidlTest, ConfigureExtListen) {
402     p2p_iface_->configureExtListen(kTestExtListenPeriod, kTestExtListenInterval,
403                                    [](const SupplicantStatus& status) {
404                                        EXPECT_EQ(SupplicantStatusCode::SUCCESS,
405                                                  status.code);
406                                    });
407 }
408 
409 /*
410  * SetListenChannel
411  */
TEST_P(SupplicantP2pIfaceHidlTest,SetListenChannel)412 TEST_P(SupplicantP2pIfaceHidlTest, SetListenChannel) {
413     p2p_iface_->setListenChannel(
414         kTestChannel, kTestOperatingClass, [](const SupplicantStatus& status) {
415             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
416         });
417 }
418 
419 /*
420  * SetDisallowedFrequencies
421  */
TEST_P(SupplicantP2pIfaceHidlTest,SetDisallowedFrequencies)422 TEST_P(SupplicantP2pIfaceHidlTest, SetDisallowedFrequencies) {
423     std::vector<ISupplicantP2pIface::FreqRange> ranges = {
424         {kTestFreqRange[0], kTestFreqRange[1]}};
425     p2p_iface_->setDisallowedFrequencies(
426         ranges, [](const SupplicantStatus& status) {
427             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
428         });
429 }
430 
431 /*
432  * GetSsid
433  */
TEST_P(SupplicantP2pIfaceHidlTest,GetSsid)434 TEST_P(SupplicantP2pIfaceHidlTest, GetSsid) {
435     std::array<uint8_t, 6> mac_addr;
436     memcpy(mac_addr.data(), kTestMacAddr, mac_addr.size());
437     p2p_iface_->getSsid(mac_addr, [](const SupplicantStatus& status,
438                                      const hidl_vec<uint8_t>& /* ssid */) {
439         // This is not going to work with fake values.
440         EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
441     });
442 }
443 
444 /*
445  * GetGroupCapability
446  */
TEST_P(SupplicantP2pIfaceHidlTest,GetGroupCapability)447 TEST_P(SupplicantP2pIfaceHidlTest, GetGroupCapability) {
448     std::array<uint8_t, 6> mac_addr;
449     memcpy(mac_addr.data(), kTestMacAddr, mac_addr.size());
450     p2p_iface_->getGroupCapability(
451         mac_addr, [](const SupplicantStatus& status, uint32_t /* caps */) {
452             // This is not going to work with fake values.
453             EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
454         });
455 }
456 
457 /*
458  * FlushServices
459  */
TEST_P(SupplicantP2pIfaceHidlTest,FlushServices)460 TEST_P(SupplicantP2pIfaceHidlTest, FlushServices) {
461     p2p_iface_->flushServices([](const SupplicantStatus& status) {
462         EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
463     });
464 }
465 
466 /*
467  * SetMiracastMode
468  */
TEST_P(SupplicantP2pIfaceHidlTest,SetMiracastMode)469 TEST_P(SupplicantP2pIfaceHidlTest, SetMiracastMode) {
470     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::DISABLED,
471                                 [](const SupplicantStatus& status) {
472                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
473                                               status.code);
474                                 });
475     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::SOURCE,
476                                 [](const SupplicantStatus& status) {
477                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
478                                               status.code);
479                                 });
480     p2p_iface_->setMiracastMode(ISupplicantP2pIface::MiracastMode::SINK,
481                                 [](const SupplicantStatus& status) {
482                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
483                                               status.code);
484                                 });
485 }
486 
487 /*
488  * SetGroupIdle
489  */
TEST_P(SupplicantP2pIfaceHidlTest,SetGroupIdle)490 TEST_P(SupplicantP2pIfaceHidlTest, SetGroupIdle) {
491     // This is not going to work with fake values.
492     EXPECT_NE(SupplicantStatusCode::SUCCESS,
493               HIDL_INVOKE(p2p_iface_, setGroupIdle, kTestGroupIfName,
494                           kTestSetGroupIdleTimeout)
495                   .code);
496 }
497 
498 /*
499  * SetPowerSave
500  */
TEST_P(SupplicantP2pIfaceHidlTest,SetPowerSave)501 TEST_P(SupplicantP2pIfaceHidlTest, SetPowerSave) {
502     // This is not going to work with fake values.
503     EXPECT_NE(
504         SupplicantStatusCode::SUCCESS,
505         HIDL_INVOKE(p2p_iface_, setPowerSave, kTestGroupIfName, true).code);
506     // This is not going to work with fake values.
507     EXPECT_NE(
508         SupplicantStatusCode::SUCCESS,
509         HIDL_INVOKE(p2p_iface_, setPowerSave, kTestGroupIfName, false).code);
510 }
511 
512 /*
513  * SetWpsDeviceName
514  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsDeviceName)515 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsDeviceName) {
516     EXPECT_EQ(
517         SupplicantStatusCode::SUCCESS,
518         HIDL_INVOKE(p2p_iface_, setWpsDeviceName, kTestWpsDeviceName).code);
519 }
520 
521 /*
522  * SetWpsDeviceType
523  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsDeviceType)524 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsDeviceType) {
525     EXPECT_EQ(
526         SupplicantStatusCode::SUCCESS,
527         HIDL_INVOKE(p2p_iface_, setWpsDeviceType, kTestWpsDeviceType).code);
528 }
529 
530 /*
531  * SetWpsManufacturer
532  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsManufacturer)533 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsManufacturer) {
534     EXPECT_EQ(
535         SupplicantStatusCode::SUCCESS,
536         HIDL_INVOKE(p2p_iface_, setWpsManufacturer, kTestWpsManufacturer).code);
537 }
538 
539 /*
540  * SetWpsModelName
541  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsModelName)542 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsModelName) {
543     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
544               HIDL_INVOKE(p2p_iface_, setWpsModelName, kTestWpsModelName).code);
545 }
546 
547 /*
548  * SetWpsModelNumber
549  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsModelNumber)550 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsModelNumber) {
551     EXPECT_EQ(
552         SupplicantStatusCode::SUCCESS,
553         HIDL_INVOKE(p2p_iface_, setWpsModelNumber, kTestWpsModelNumber).code);
554 }
555 
556 /*
557  * SetWpsSerialNumber
558  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsSerialNumber)559 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsSerialNumber) {
560     EXPECT_EQ(
561         SupplicantStatusCode::SUCCESS,
562         HIDL_INVOKE(p2p_iface_, setWpsSerialNumber, kTestWpsSerialNumber).code);
563 }
564 
565 /*
566  * SetWpsConfigMethods
567  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWpsConfigMethods)568 TEST_P(SupplicantP2pIfaceHidlTest, SetWpsConfigMethods) {
569     EXPECT_EQ(
570         SupplicantStatusCode::SUCCESS,
571         HIDL_INVOKE(p2p_iface_, setWpsConfigMethods, kTestWpsConfigMethods)
572             .code);
573 }
574 
575 /*
576  * AddAndRemoveBonjourService
577  * This tests that we are able to add a bonjour service, and we can remove it
578  * by using the same query data.
579  * This also tests that removeBonjourSerive() returns error when there is no
580  * existing bonjour service with the same query data.
581  */
TEST_P(SupplicantP2pIfaceHidlTest,AddAndRemoveBonjourService)582 TEST_P(SupplicantP2pIfaceHidlTest, AddAndRemoveBonjourService) {
583     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
584               HIDL_INVOKE(
585                   p2p_iface_, addBonjourService,
586                   std::vector<uint8_t>(kTestBonjourServiceQuery,
587                                        kTestBonjourServiceQuery +
588                                            sizeof(kTestBonjourServiceQuery)),
589                   std::vector<uint8_t>(kTestBonjourServiceResponse,
590                                        kTestBonjourServiceResponse +
591                                            sizeof(kTestBonjourServiceResponse)))
592                   .code);
593     EXPECT_EQ(
594         SupplicantStatusCode::SUCCESS,
595         HIDL_INVOKE(p2p_iface_, removeBonjourService,
596                     std::vector<uint8_t>(kTestBonjourServiceQuery,
597                                          kTestBonjourServiceQuery +
598                                              sizeof(kTestBonjourServiceQuery)))
599             .code);
600     // This will fail because boujour service with kTestBonjourServiceQuery was
601     // already removed.
602     EXPECT_NE(
603         SupplicantStatusCode::SUCCESS,
604         HIDL_INVOKE(p2p_iface_, removeBonjourService,
605                     std::vector<uint8_t>(kTestBonjourServiceQuery,
606                                          kTestBonjourServiceQuery +
607                                              sizeof(kTestBonjourServiceQuery)))
608             .code);
609 }
610 
611 /*
612  * AddAndRemoveUpnpService
613  * This tests that we are able to add a upnp service, and we can remove it
614  * by using the same service name.
615  * This also tests that removeUpnpService() returns error when there is no
616  * exsiting upnp service with the same service name.
617  */
TEST_P(SupplicantP2pIfaceHidlTest,AddAndRemoveUpnpService)618 TEST_P(SupplicantP2pIfaceHidlTest, AddAndRemoveUpnpService) {
619     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
620               HIDL_INVOKE(p2p_iface_, addUpnpService, 0 /* version */,
621                           kTestUpnpServiceName)
622                   .code);
623     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
624               HIDL_INVOKE(p2p_iface_, removeUpnpService, 0 /* version */,
625                           kTestUpnpServiceName)
626                   .code);
627     // This will fail because Upnp service with kTestUpnpServiceName was
628     // already removed.
629     EXPECT_NE(SupplicantStatusCode::SUCCESS,
630               HIDL_INVOKE(p2p_iface_, removeUpnpService, 0 /* version */,
631                           kTestUpnpServiceName)
632                   .code);
633 }
634 
635 /*
636  * EnableWfd
637  */
TEST_P(SupplicantP2pIfaceHidlTest,EnableWfd)638 TEST_P(SupplicantP2pIfaceHidlTest, EnableWfd) {
639     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
640               HIDL_INVOKE(p2p_iface_, enableWfd, true).code);
641     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
642               HIDL_INVOKE(p2p_iface_, enableWfd, false).code);
643 }
644 
645 /*
646  * SetWfdDeviceInfo
647  */
TEST_P(SupplicantP2pIfaceHidlTest,SetWfdDeviceInfo)648 TEST_P(SupplicantP2pIfaceHidlTest, SetWfdDeviceInfo) {
649     EXPECT_EQ(
650         SupplicantStatusCode::SUCCESS,
651         HIDL_INVOKE(p2p_iface_, setWfdDeviceInfo, kTestWfdDeviceInfo).code);
652 }
653 
654 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pIfaceHidlTest);
655 INSTANTIATE_TEST_CASE_P(
656     PerInstance, SupplicantP2pIfaceHidlTest,
657     testing::Combine(
658         testing::ValuesIn(
659             android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
660         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
661             ISupplicant::descriptor))),
662     android::hardware::PrintInstanceTupleNameToString<>);
663