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 <vector>
18
19 #include <android-base/logging.h>
20 #include <gtest/gtest.h>
21 #include <utils/StrongPointer.h>
22
23 #include "android/net/wifi/IClientInterface.h"
24 #include "android/net/wifi/IWificond.h"
25 #include "wificond/tests/integration/process_utils.h"
26
27 using android::net::wifi::IClientInterface;
28 using android::net::wifi::IWificond;
29 using android::net::wifi::IWifiScannerImpl;
30 using android::wificond::tests::integration::ScopedDevModeWificond;
31 using std::unique_ptr;
32 using std::vector;
33
34 namespace android {
35 namespace wificond {
36 namespace {
37
InitInterfaceAndReturnScanner(sp<IWificond> service)38 sp<IWifiScannerImpl> InitInterfaceAndReturnScanner(sp<IWificond> service) {
39 sp<IWifiScannerImpl> scanner;
40 sp<IClientInterface> client_interface;
41 if (!service->createClientInterface(&client_interface).isOk()) {
42 LOG(FATAL) << "Failed to create client interface";
43 return nullptr;
44 }
45 if (client_interface == nullptr) {
46 LOG(FATAL) << "Failed to get a valid client interface handler";
47 return nullptr;
48 }
49 if (!client_interface->getWifiScannerImpl(&scanner).isOk()) {
50 LOG(FATAL) << "Failed to get a WifiScannerImpl handler";
51 return nullptr;
52 }
53 return scanner;
54 }
55
56 } // namespace
57
TEST(ScannerTest,CanGetValidWifiScannerImpl)58 TEST(ScannerTest, CanGetValidWifiScannerImpl) {
59 ScopedDevModeWificond dev_mode;
60 sp<IWificond> service = dev_mode.EnterDevModeOrDie();
61 EXPECT_NE(nullptr, InitInterfaceAndReturnScanner(service).get());
62 }
63
TEST(ScannerTest,CanGetAvailableChannels)64 TEST(ScannerTest, CanGetAvailableChannels) {
65 ScopedDevModeWificond dev_mode;
66 sp<IWificond> service = dev_mode.EnterDevModeOrDie();
67 sp<IWifiScannerImpl> scanner = InitInterfaceAndReturnScanner(service);
68 ASSERT_NE(nullptr, scanner.get());
69
70 unique_ptr<vector<int32_t>> freqs_2g;
71 ASSERT_TRUE(scanner->getAvailable2gChannels(&freqs_2g).isOk());
72 EXPECT_TRUE(freqs_2g->size() != 0);
73
74 unique_ptr<vector<int32_t>> freqs_5g;
75 ASSERT_TRUE(scanner->getAvailable5gNonDFSChannels(&freqs_5g).isOk());
76 EXPECT_TRUE(freqs_5g->size() != 0);
77
78 unique_ptr<vector<int32_t>> freqs_dfs;
79 ASSERT_TRUE(scanner->getAvailableDFSChannels(&freqs_dfs).isOk());
80 // DFS support should be enabled explicitly, so we don't expect a non-empty
81 // DFS frequency list here.
82 }
83
84 } // namespace wificond
85 } // namespace android
86