• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <VtsCoreUtil.h>
20 #include <android-base/logging.h>
21 #include <android/hardware/wifi/1.0/IWifi.h>
22 #include <hidl/ServiceManagement.h>
23 #include <supplicant_hidl_test_utils.h>
24 #include <wifi_system/supplicant_manager.h>
25 
26 using android::wifi_system::SupplicantManager;
27 
28 // Helper methods to interact with supplicant_hidl_test_utils
29 namespace SupplicantLegacyTestUtils {
getWifiInstanceName()30 std::string getWifiInstanceName() {
31     const std::vector<std::string> instances = android::hardware::getAllHalInstanceNames(
32             ::android::hardware::wifi::V1_0::IWifi::descriptor);
33     EXPECT_NE(0, instances.size());
34     return instances.size() != 0 ? instances[0] : "";
35 }
36 
stopSupplicantService()37 void stopSupplicantService() {
38     stopSupplicant(getWifiInstanceName());
39 }
40 
startSupplicant()41 void startSupplicant() {
42     initializeDriverAndFirmware(getWifiInstanceName());
43     SupplicantManager supplicant_manager;
44     ASSERT_TRUE(supplicant_manager.StartSupplicant());
45     ASSERT_TRUE(supplicant_manager.IsSupplicantRunning());
46 }
47 
initializeService()48 void initializeService() {
49     ASSERT_TRUE(stopWifiFramework(getWifiInstanceName()));
50     std::system("/system/bin/start");
51     ASSERT_TRUE(waitForFrameworkReady());
52     stopSupplicantService();
53     startSupplicant();
54 }
55 }  // namespace SupplicantLegacyTestUtils
56