diff options
author | Sohani Rao | 2017-06-22 12:43:27 -0500 |
---|---|---|
committer | android-build-merger | 2017-06-22 12:43:27 -0500 |
commit | 04559d12e90d2b6c639571c1e074c929ea38f498 (patch) | |
tree | 5fceb2b938d8fdbd73ec22b24a36766f72ef31fd | |
parent | 06366883886c30233eaeac1df96b9e7f38ad8077 (diff) | |
parent | e10ec9e1f15007331afe569d7c13790eae5b40de (diff) | |
download | system-connectivity-wificond-04559d12e90d2b6c639571c1e074c929ea38f498.tar.gz system-connectivity-wificond-04559d12e90d2b6c639571c1e074c929ea38f498.tar.xz system-connectivity-wificond-04559d12e90d2b6c639571c1e074c929ea38f498.zip |
Wificond: Offload HAL APIs return status
am: e10ec9e1f1
Change-Id: I7221e41b93d2ad1e1521d868694474e4b5fe70b7
-rw-r--r-- | scanning/offload/hidl_call_util.h | 128 | ||||
-rw-r--r-- | scanning/offload/offload_callback.cpp | 2 | ||||
-rw-r--r-- | scanning/offload/offload_callback.h | 3 | ||||
-rw-r--r-- | scanning/offload/offload_callback_handlers.h | 3 | ||||
-rw-r--r-- | scanning/offload/offload_scan_manager.cpp | 105 | ||||
-rw-r--r-- | scanning/offload/offload_scan_manager.h | 41 | ||||
-rw-r--r-- | scanning/offload/offload_scan_utils.h | 8 | ||||
-rw-r--r-- | tests/mock_offload.h | 18 | ||||
-rw-r--r-- | tests/mock_offload_callback_handlers.h | 3 | ||||
-rw-r--r-- | tests/offload_callback_test.cpp | 7 | ||||
-rw-r--r-- | tests/offload_hal_test_constants.cpp | 1 | ||||
-rw-r--r-- | tests/offload_hal_test_constants.h | 1 | ||||
-rw-r--r-- | tests/offload_scan_manager_test.cpp | 108 | ||||
-rw-r--r-- | tests/offload_test_utils.cpp | 10 | ||||
-rw-r--r-- | tests/offload_test_utils.h | 7 | ||||
-rw-r--r-- | tests/scan_stats_unittest.cpp | 21 |
16 files changed, 377 insertions, 89 deletions
diff --git a/scanning/offload/hidl_call_util.h b/scanning/offload/hidl_call_util.h new file mode 100644 index 0000000..6303f1a --- /dev/null +++ b/scanning/offload/hidl_call_util.h | |||
@@ -0,0 +1,128 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 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 | // This file is modified from | ||
18 | // hardware/interfaces/wifi/1.0/vts/functional/wifi_hidl_call_util.h | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <android-base/logging.h> | ||
23 | #include <functional> | ||
24 | #include <tuple> | ||
25 | #include <type_traits> | ||
26 | #include <utility> | ||
27 | |||
28 | namespace { | ||
29 | namespace detail { | ||
30 | template <typename> | ||
31 | struct functionArgSaver; | ||
32 | |||
33 | // Provides a std::function that takes one argument, and a buffer | ||
34 | // wherein the function will store its argument. The buffer has | ||
35 | // the same type as the argument, but with const and reference | ||
36 | // modifiers removed. | ||
37 | template <typename ArgT> | ||
38 | struct functionArgSaver<std::function<void(ArgT)>> final { | ||
39 | using StorageT = typename std::remove_const< | ||
40 | typename std::remove_reference<ArgT>::type>::type; | ||
41 | |||
42 | std::function<void(ArgT)> saveArgs = [this](ArgT arg) { | ||
43 | this->saved_values = arg; | ||
44 | }; | ||
45 | |||
46 | StorageT saved_values; | ||
47 | }; | ||
48 | |||
49 | // Provides a std::function that takes two arguments, and a buffer | ||
50 | // wherein the function will store its arguments. The buffer is a | ||
51 | // std::pair, whose elements have the same types as the arguments | ||
52 | // (but with const and reference modifiers removed). | ||
53 | template <typename Arg1T, typename Arg2T> | ||
54 | struct functionArgSaver<std::function<void(Arg1T, Arg2T)>> final { | ||
55 | using StorageT = | ||
56 | std::pair<typename std::remove_const< | ||
57 | typename std::remove_reference<Arg1T>::type>::type, | ||
58 | typename std::remove_const< | ||
59 | typename std::remove_reference<Arg2T>::type>::type>; | ||
60 | |||
61 | std::function<void(Arg1T, Arg2T)> saveArgs = [this](Arg1T arg1, Arg2T arg2) { | ||
62 | this->saved_values = {arg1, arg2}; | ||
63 | }; | ||
64 | |||
65 | StorageT saved_values; | ||
66 | }; | ||
67 | |||
68 | // Provides a std::function that takes three or more arguments, and a | ||
69 | // buffer wherein the function will store its arguments. The buffer is a | ||
70 | // std::tuple whose elements have the same types as the arguments (but | ||
71 | // with const and reference modifiers removed). | ||
72 | template <typename... ArgT> | ||
73 | struct functionArgSaver<std::function<void(ArgT...)>> final { | ||
74 | using StorageT = std::tuple<typename std::remove_const< | ||
75 | typename std::remove_reference<ArgT>::type>::type...>; | ||
76 | |||
77 | std::function<void(ArgT...)> saveArgs = [this](ArgT... arg) { | ||
78 | this->saved_values = {arg...}; | ||
79 | }; | ||
80 | |||
81 | StorageT saved_values; | ||
82 | }; | ||
83 | |||
84 | // Invokes |method| on |object|, providing |method| a CallbackT as the | ||
85 | // final argument. Returns a copy of the parameters that |method| provided | ||
86 | // to CallbackT. (The parameters are returned by value.) | ||
87 | template <typename CallbackT, typename MethodT, typename ObjectT, | ||
88 | typename... ArgT> | ||
89 | std::pair<typename functionArgSaver<CallbackT>::StorageT, bool> invokeMethod( | ||
90 | MethodT method, ObjectT object, ArgT&&... methodArg) { | ||
91 | functionArgSaver<CallbackT> result_buffer; | ||
92 | const auto& res = ((*object).*method)(std::forward<ArgT>(methodArg)..., | ||
93 | result_buffer.saveArgs); | ||
94 | bool transportStatus = true; | ||
95 | if (!res.isOk()) { | ||
96 | LOG(ERROR) << " Transport failed " << res.description(); | ||
97 | transportStatus = false; | ||
98 | } | ||
99 | return std::make_pair(result_buffer.saved_values, transportStatus); | ||
100 | } | ||
101 | } // namespace detail | ||
102 | } // namespace | ||
103 | |||
104 | // Invokes |method| on |strong_pointer|, passing provided arguments through to | ||
105 | // |method|. | ||
106 | // | ||
107 | // Returns either: | ||
108 | // - A copy of the result callback parameter (for callbacks with a single | ||
109 | // parameter), OR | ||
110 | // - A pair containing a copy of the result callback parameters (for callbacks | ||
111 | // with two parameters), OR | ||
112 | // - A tuple containing a copy of the result callback paramters (for callbacks | ||
113 | // with three or more parameters). | ||
114 | // | ||
115 | // Example usage: | ||
116 | // EXPECT_EQ(WifiStatusCode::SUCCESS, | ||
117 | // HIDL_INVOKE(strong_pointer, methodReturningWifiStatus).code); | ||
118 | // EXPECT_EQ(WifiStatusCode::SUCCESS, | ||
119 | // HIDL_INVOKE(strong_pointer, methodReturningWifiStatusAndOneMore) | ||
120 | // .first.code); | ||
121 | // EXPECT_EQ(WifiStatusCode::SUCCESS, std::get<0>( | ||
122 | // HIDL_INVOKE(strong_pointer, methodReturningWifiStatusAndTwoMore)) | ||
123 | // .code); | ||
124 | #define HIDL_INVOKE(strong_pointer, method, ...) \ | ||
125 | (detail::invokeMethod< \ | ||
126 | std::remove_reference<decltype(*strong_pointer)>::type::method##_cb>( \ | ||
127 | &std::remove_reference<decltype(*strong_pointer)>::type::method, \ | ||
128 | strong_pointer, ##__VA_ARGS__)) | ||
diff --git a/scanning/offload/offload_callback.cpp b/scanning/offload/offload_callback.cpp index 90d61ed..b92a1ed 100644 --- a/scanning/offload/offload_callback.cpp +++ b/scanning/offload/offload_callback.cpp | |||
@@ -46,7 +46,7 @@ Return<void> OffloadCallback::onScanResult( | |||
46 | return Void(); | 46 | return Void(); |
47 | } | 47 | } |
48 | 48 | ||
49 | Return<void> OffloadCallback::onError(OffloadStatus status) { | 49 | Return<void> OffloadCallback::onError(const OffloadStatus& status) { |
50 | if (handlers_ != nullptr) { | 50 | if (handlers_ != nullptr) { |
51 | handlers_->OnErrorHandler(status); | 51 | handlers_->OnErrorHandler(status); |
52 | } else { | 52 | } else { |
diff --git a/scanning/offload/offload_callback.h b/scanning/offload/offload_callback.h index aec82b6..ae0b2f4 100644 --- a/scanning/offload/offload_callback.h +++ b/scanning/offload/offload_callback.h | |||
@@ -37,7 +37,8 @@ class OffloadCallback | |||
37 | ::android::hardware::wifi::offload::V1_0::ScanResult>& scanResult) | 37 | ::android::hardware::wifi::offload::V1_0::ScanResult>& scanResult) |
38 | override; | 38 | override; |
39 | ::android::hardware::Return<void> onError( | 39 | ::android::hardware::Return<void> onError( |
40 | ::android::hardware::wifi::offload::V1_0::OffloadStatus status) override; | 40 | const ::android::hardware::wifi::offload::V1_0::OffloadStatus& status) |
41 | override; | ||
41 | // Methods from ::android::hidl::base::V1_0::IBase follow. | 42 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
42 | 43 | ||
43 | private: | 44 | private: |
diff --git a/scanning/offload/offload_callback_handlers.h b/scanning/offload/offload_callback_handlers.h index bda53c7..a202cda 100644 --- a/scanning/offload/offload_callback_handlers.h +++ b/scanning/offload/offload_callback_handlers.h | |||
@@ -30,7 +30,8 @@ class OffloadCallbackHandlers { | |||
30 | const std::vector<::android::hardware::wifi::offload::V1_0::ScanResult>& | 30 | const std::vector<::android::hardware::wifi::offload::V1_0::ScanResult>& |
31 | scanResult) = 0; | 31 | scanResult) = 0; |
32 | virtual void OnErrorHandler( | 32 | virtual void OnErrorHandler( |
33 | ::android::hardware::wifi::offload::V1_0::OffloadStatus status) = 0; | 33 | const ::android::hardware::wifi::offload::V1_0::OffloadStatus& |
34 | status) = 0; | ||
34 | }; | 35 | }; |
35 | 36 | ||
36 | } // namespace wificond | 37 | } // namespace wificond |
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp index df68239..dd4b6cf 100644 --- a/scanning/offload/offload_scan_manager.cpp +++ b/scanning/offload/offload_scan_manager.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include <android-base/logging.h> | 20 | #include <android-base/logging.h> |
21 | 21 | ||
22 | #include "wificond/scanning/offload/hidl_call_util.h" | ||
22 | #include "wificond/scanning/offload/offload_scan_utils.h" | 23 | #include "wificond/scanning/offload/offload_scan_utils.h" |
23 | #include "wificond/scanning/offload/offload_service_utils.h" | 24 | #include "wificond/scanning/offload/offload_service_utils.h" |
24 | #include "wificond/scanning/offload/scan_stats.h" | 25 | #include "wificond/scanning/offload/scan_stats.h" |
@@ -31,6 +32,7 @@ using android::hardware::wifi::offload::V1_0::ScanFilter; | |||
31 | using android::hardware::wifi::offload::V1_0::ScanParam; | 32 | using android::hardware::wifi::offload::V1_0::ScanParam; |
32 | using android::hardware::wifi::offload::V1_0::ScanStats; | 33 | using android::hardware::wifi::offload::V1_0::ScanStats; |
33 | using android::hardware::wifi::offload::V1_0::OffloadStatus; | 34 | using android::hardware::wifi::offload::V1_0::OffloadStatus; |
35 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | ||
34 | 36 | ||
35 | using android::wificond::OffloadCallback; | 37 | using android::wificond::OffloadCallback; |
36 | using android::wificond::OnNativeScanResultsReadyHandler; | 38 | using android::wificond::OnNativeScanResultsReadyHandler; |
@@ -59,7 +61,7 @@ void OffloadCallbackHandlersImpl::OnScanResultHandler( | |||
59 | } | 61 | } |
60 | } | 62 | } |
61 | 63 | ||
62 | void OffloadCallbackHandlersImpl::OnErrorHandler(OffloadStatus status) { | 64 | void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) { |
63 | if (offload_scan_manager_ != nullptr) { | 65 | if (offload_scan_manager_ != nullptr) { |
64 | offload_scan_manager_->ReportError(status); | 66 | offload_scan_manager_->ReportError(status); |
65 | } | 67 | } |
@@ -87,6 +89,7 @@ OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils, | |||
87 | LOG(ERROR) << "No Offload Service available"; | 89 | LOG(ERROR) << "No Offload Service available"; |
88 | return; | 90 | return; |
89 | } | 91 | } |
92 | |||
90 | wifi_offload_callback_ = | 93 | wifi_offload_callback_ = |
91 | utils->GetOffloadCallback(offload_callback_handlers_.get()); | 94 | utils->GetOffloadCallback(offload_callback_handlers_.get()); |
92 | if (wifi_offload_callback_ == nullptr) { | 95 | if (wifi_offload_callback_ == nullptr) { |
@@ -112,38 +115,92 @@ bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { | |||
112 | return true; | 115 | return true; |
113 | } | 116 | } |
114 | 117 | ||
118 | bool OffloadScanManager::GetScanStats(NativeScanStats* native_scan_stats) { | ||
119 | const auto& result = HIDL_INVOKE(wifi_offload_hal_, getScanStats); | ||
120 | const auto& offload_status_and_scan_stats = result.first; | ||
121 | bool transport_status = result.second; | ||
122 | if (!transport_status) { | ||
123 | return false; | ||
124 | } | ||
125 | OffloadStatus offload_status = offload_status_and_scan_stats.first; | ||
126 | ScanStats scan_stats = offload_status_and_scan_stats.second; | ||
127 | if (offload_status.code != OffloadStatusCode::OK) { | ||
128 | LOG(WARNING) << offload_status.description; | ||
129 | return false; | ||
130 | } | ||
131 | *native_scan_stats = OffloadScanUtils::convertToNativeScanStats(scan_stats); | ||
132 | return true; | ||
133 | } | ||
134 | |||
135 | bool OffloadScanManager::VerifyAndConvertHIDLStatus( | ||
136 | std::pair<OffloadStatus, bool> result, | ||
137 | OffloadScanManager::ReasonCode* reason_code) { | ||
138 | const auto& offload_status = result.first; | ||
139 | bool transport_status = result.second; | ||
140 | if (!transport_status) { | ||
141 | *reason_code = OffloadScanManager::kTransactionFailed; | ||
142 | return false; | ||
143 | } | ||
144 | if (offload_status.code != OffloadStatusCode::OK) { | ||
145 | LOG(WARNING) << offload_status.description; | ||
146 | *reason_code = OffloadScanManager::kOperationFailed; | ||
147 | return false; | ||
148 | } | ||
149 | return true; | ||
150 | } | ||
151 | |||
115 | bool OffloadScanManager::startScan( | 152 | bool OffloadScanManager::startScan( |
116 | uint32_t interval_ms, int32_t rssi_threshold, | 153 | uint32_t interval_ms, int32_t rssi_threshold, |
117 | const vector<vector<uint8_t>>& scan_ssids, | 154 | const vector<vector<uint8_t>>& scan_ssids, |
118 | const vector<vector<uint8_t>>& match_ssids, | 155 | const vector<vector<uint8_t>>& match_ssids, |
119 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, | 156 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, |
120 | OffloadScanManager::ReasonCode* reason_code) { | 157 | OffloadScanManager::ReasonCode* reason_code) { |
121 | if (!service_available_) { | 158 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
122 | *reason_code = OffloadScanManager::kNotSupported; | ||
123 | LOG(WARNING) << "Offload HAL scans are not supported"; | ||
124 | return false; | ||
125 | } else if (offload_status_ == OffloadScanManager::kNotConnected) { | ||
126 | LOG(WARNING) << "Offload HAL scans are not available"; | ||
127 | *reason_code = OffloadScanManager::kNotAvailable; | 159 | *reason_code = OffloadScanManager::kNotAvailable; |
160 | LOG(WARNING) << "Offload HAL scans are not available"; | ||
128 | return false; | 161 | return false; |
129 | } | 162 | } |
130 | |||
131 | ScanParam param = | 163 | ScanParam param = |
132 | OffloadScanUtils::createScanParam(scan_ssids, freqs, interval_ms); | 164 | OffloadScanUtils::createScanParam(scan_ssids, freqs, interval_ms); |
133 | ScanFilter filter = OffloadScanUtils::createScanFilter( | 165 | ScanFilter filter = OffloadScanUtils::createScanFilter( |
134 | match_ssids, match_security, rssi_threshold); | 166 | match_ssids, match_security, rssi_threshold); |
135 | 167 | ||
136 | wifi_offload_hal_->configureScans(param, filter); | 168 | if (!ConfigureScans(param, filter, reason_code)) { |
137 | if (!subscription_enabled_) { | 169 | return false; |
138 | wifi_offload_hal_->subscribeScanResults(kSubscriptionDelayMs); | 170 | } |
171 | |||
172 | if (!subscription_enabled_ && !SubscribeScanResults(reason_code)) { | ||
173 | return false; | ||
139 | } | 174 | } |
175 | |||
140 | subscription_enabled_ = true; | 176 | subscription_enabled_ = true; |
141 | *reason_code = OffloadScanManager::kNone; | 177 | *reason_code = OffloadScanManager::kNone; |
142 | return true; | 178 | return true; |
143 | } | 179 | } |
144 | 180 | ||
181 | bool OffloadScanManager::ConfigureScans( | ||
182 | ScanParam param, ScanFilter filter, | ||
183 | OffloadScanManager::ReasonCode* reason_code) { | ||
184 | const auto& result = | ||
185 | HIDL_INVOKE(wifi_offload_hal_, configureScans, param, filter); | ||
186 | if (!VerifyAndConvertHIDLStatus(result, reason_code)) { | ||
187 | return false; | ||
188 | } | ||
189 | return true; | ||
190 | } | ||
191 | |||
192 | bool OffloadScanManager::SubscribeScanResults( | ||
193 | OffloadScanManager::ReasonCode* reason_code) { | ||
194 | const auto& result = HIDL_INVOKE(wifi_offload_hal_, subscribeScanResults, | ||
195 | kSubscriptionDelayMs); | ||
196 | if (!VerifyAndConvertHIDLStatus(result, reason_code)) { | ||
197 | return false; | ||
198 | } | ||
199 | return true; | ||
200 | } | ||
201 | |||
145 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { | 202 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { |
146 | if (!service_available_) { | 203 | if (wifi_offload_hal_ == nullptr) { |
147 | return OffloadScanManager::kNoService; | 204 | return OffloadScanManager::kNoService; |
148 | } | 205 | } |
149 | return offload_status_; | 206 | return offload_status_; |
@@ -163,18 +220,13 @@ bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { | |||
163 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; | 220 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; |
164 | return false; | 221 | return false; |
165 | } | 222 | } |
166 | wifi_offload_hal_->getScanStats( | 223 | return GetScanStats(native_scan_stats); |
167 | [&native_scan_stats](ScanStats offload_scan_stats) -> void { | ||
168 | *native_scan_stats = | ||
169 | OffloadScanUtils::convertToNativeScanStats(offload_scan_stats); | ||
170 | }); | ||
171 | return true; | ||
172 | } | 224 | } |
173 | 225 | ||
174 | OffloadScanManager::~OffloadScanManager() {} | 226 | OffloadScanManager::~OffloadScanManager() {} |
175 | 227 | ||
176 | void OffloadScanManager::ReportScanResults( | 228 | void OffloadScanManager::ReportScanResults( |
177 | const vector<ScanResult> scanResult) { | 229 | const vector<ScanResult>& scanResult) { |
178 | if (scan_result_handler_ != nullptr) { | 230 | if (scan_result_handler_ != nullptr) { |
179 | scan_result_handler_( | 231 | scan_result_handler_( |
180 | OffloadScanUtils::convertToNativeScanResults(scanResult)); | 232 | OffloadScanUtils::convertToNativeScanResults(scanResult)); |
@@ -183,19 +235,20 @@ void OffloadScanManager::ReportScanResults( | |||
183 | } | 235 | } |
184 | } | 236 | } |
185 | 237 | ||
186 | void OffloadScanManager::ReportError(OffloadStatus status) { | 238 | void OffloadScanManager::ReportError(const OffloadStatus& status) { |
239 | OffloadStatusCode status_code = status.code; | ||
187 | OffloadScanManager::StatusCode status_result = OffloadScanManager::kNoError; | 240 | OffloadScanManager::StatusCode status_result = OffloadScanManager::kNoError; |
188 | switch (status) { | 241 | switch (status_code) { |
189 | case OffloadStatus::OFFLOAD_STATUS_OK: | 242 | case OffloadStatusCode::OK: |
190 | status_result = OffloadScanManager::kNoError; | 243 | status_result = OffloadScanManager::kNoError; |
191 | break; | 244 | break; |
192 | case OffloadStatus::OFFLOAD_STATUS_TIMEOUT: | 245 | case OffloadStatusCode::TIMEOUT: |
193 | status_result = OffloadScanManager::kTimeOut; | 246 | status_result = OffloadScanManager::kTimeOut; |
194 | break; | 247 | break; |
195 | case OffloadStatus::OFFLOAD_STATUS_NO_CONNECTION: | 248 | case OffloadStatusCode::NO_CONNECTION: |
196 | status_result = OffloadScanManager::kNotConnected; | 249 | status_result = OffloadScanManager::kNotConnected; |
197 | break; | 250 | break; |
198 | case OffloadStatus::OFFLOAD_STATUS_ERROR: | 251 | case OffloadStatusCode::ERROR: |
199 | status_result = OffloadScanManager::kError; | 252 | status_result = OffloadScanManager::kError; |
200 | break; | 253 | break; |
201 | default: | 254 | default: |
@@ -203,7 +256,7 @@ void OffloadScanManager::ReportError(OffloadStatus status) { | |||
203 | return; | 256 | return; |
204 | } | 257 | } |
205 | if (status_result != OffloadScanManager::kNoError) { | 258 | if (status_result != OffloadScanManager::kNoError) { |
206 | LOG(WARNING) << "Offload Error reported " << status_result; | 259 | LOG(WARNING) << "Offload Error reported " << status.description; |
207 | } | 260 | } |
208 | offload_status_ = status_result; | 261 | offload_status_ = status_result; |
209 | } | 262 | } |
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h index 413f5bc..1be1b8b 100644 --- a/scanning/offload/offload_scan_manager.h +++ b/scanning/offload/offload_scan_manager.h | |||
@@ -58,7 +58,8 @@ class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { | |||
58 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>& | 58 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>& |
59 | scanResult) override; | 59 | scanResult) override; |
60 | void OnErrorHandler( | 60 | void OnErrorHandler( |
61 | android::hardware::wifi::offload::V1_0::OffloadStatus status) override; | 61 | const android::hardware::wifi::offload::V1_0::OffloadStatus& status) |
62 | override; | ||
62 | 63 | ||
63 | private: | 64 | private: |
64 | OffloadScanManager* offload_scan_manager_; | 65 | OffloadScanManager* offload_scan_manager_; |
@@ -68,35 +69,29 @@ class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { | |||
68 | class OffloadScanManager { | 69 | class OffloadScanManager { |
69 | public: | 70 | public: |
70 | enum StatusCode { | 71 | enum StatusCode { |
71 | /* Corresponds to | 72 | /* Corresponds to OffloadStatusCode::OK */ |
72 | android::hardware::wifi::offload::V1_0::OffloadStatus::OFFLOAD_STATUS_OK | ||
73 | */ | ||
74 | kNoError, | 73 | kNoError, |
75 | /* Offload HAL service not avaialble */ | 74 | /* Offload HAL service not avaialble */ |
76 | kNoService, | 75 | kNoService, |
77 | /* Corresponds to | 76 | /* Corresponds to OffloadStatusCode::NO_CONNECTION */ |
78 | android::hardware::wifi::offload::V1_0::OffloadStatus::OFFLOAD_STATUS_NO_CONNECTION | ||
79 | */ | ||
80 | kNotConnected, | 77 | kNotConnected, |
81 | /* Corresponds to | 78 | /* Corresponds to OffloadStatusCode::TIMEOUT */ |
82 | android::hardware::wifi::offload::V1_0::OffloadStatus::OFFLOAD_STATUS_TIMEOUT | ||
83 | */ | ||
84 | kTimeOut, | 79 | kTimeOut, |
85 | /* Corresponds to | 80 | /* Corresponds to OffloadStatusCode::ERROR */ |
86 | android::hardware::wifi::offload::V1_0::OffloadStatus::OFFLOAD_STATUS_ERROR | ||
87 | */ | ||
88 | kError | 81 | kError |
89 | }; | 82 | }; |
90 | 83 | ||
91 | enum ReasonCode { | 84 | enum ReasonCode { |
92 | /* Default value */ | 85 | /* Default value */ |
93 | kNone, | 86 | kNone, |
94 | /* Offload HAL service not available */ | 87 | /* Offload HAL scans is not available */ |
95 | kNotSupported, | ||
96 | /* Offload HAL service is not connected */ | ||
97 | kNotAvailable, | 88 | kNotAvailable, |
98 | /* Offload HAL service is not subscribed to */ | 89 | /* Offload HAL service is not subscribed to */ |
99 | kNotSubscribed, | 90 | kNotSubscribed, |
91 | /* Offload HAL requested operation failure */ | ||
92 | kOperationFailed, | ||
93 | /* Binder failed to deliver message to Offload HAL*/ | ||
94 | kTransactionFailed, | ||
100 | }; | 95 | }; |
101 | 96 | ||
102 | explicit OffloadScanManager(OffloadServiceUtils* utils, | 97 | explicit OffloadScanManager(OffloadServiceUtils* utils, |
@@ -128,10 +123,20 @@ class OffloadScanManager { | |||
128 | 123 | ||
129 | private: | 124 | private: |
130 | void ReportScanResults( | 125 | void ReportScanResults( |
131 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult> | 126 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>& |
132 | scanResult); | 127 | scanResult); |
133 | void ReportError( | 128 | void ReportError( |
134 | android::hardware::wifi::offload::V1_0::OffloadStatus status); | 129 | const android::hardware::wifi::offload::V1_0::OffloadStatus& status); |
130 | bool VerifyAndConvertHIDLStatus( | ||
131 | std::pair<android::hardware::wifi::offload::V1_0::OffloadStatus, bool> | ||
132 | result, | ||
133 | OffloadScanManager::ReasonCode* reason_code); | ||
134 | bool GetScanStats( | ||
135 | ::com::android::server::wifi::wificond::NativeScanStats* stats); | ||
136 | bool SubscribeScanResults(OffloadScanManager::ReasonCode* reason_code); | ||
137 | bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, | ||
138 | android::hardware::wifi::offload::V1_0::ScanFilter, | ||
139 | OffloadScanManager::ReasonCode* reason_code); | ||
135 | 140 | ||
136 | android::sp<android::hardware::wifi::offload::V1_0::IOffload> | 141 | android::sp<android::hardware::wifi::offload::V1_0::IOffload> |
137 | wifi_offload_hal_; | 142 | wifi_offload_hal_; |
diff --git a/scanning/offload/offload_scan_utils.h b/scanning/offload/offload_scan_utils.h index c9f5898..ce4afa7 100644 --- a/scanning/offload/offload_scan_utils.h +++ b/scanning/offload/offload_scan_utils.h | |||
@@ -43,8 +43,8 @@ namespace wificond { | |||
43 | class OffloadScanUtils { | 43 | class OffloadScanUtils { |
44 | public: | 44 | public: |
45 | static std::vector<::com::android::server::wifi::wificond::NativeScanResult> | 45 | static std::vector<::com::android::server::wifi::wificond::NativeScanResult> |
46 | convertToNativeScanResults( | 46 | convertToNativeScanResults( |
47 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&); | 47 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&); |
48 | static android::hardware::wifi::offload::V1_0::ScanParam createScanParam( | 48 | static android::hardware::wifi::offload::V1_0::ScanParam createScanParam( |
49 | const std::vector<std::vector<uint8_t>>& ssid_list, | 49 | const std::vector<std::vector<uint8_t>>& ssid_list, |
50 | const std::vector<uint32_t>& frequency_list, uint32_t scan_interval_ms); | 50 | const std::vector<uint32_t>& frequency_list, uint32_t scan_interval_ms); |
@@ -58,8 +58,8 @@ class OffloadScanUtils { | |||
58 | const std::vector<std::vector<uint8_t>>& ssids, | 58 | const std::vector<std::vector<uint8_t>>& ssids, |
59 | const std::vector<uint8_t>& flags, int8_t rssi_threshold); | 59 | const std::vector<uint8_t>& flags, int8_t rssi_threshold); |
60 | static ::com::android::server::wifi::wificond::NativeScanStats | 60 | static ::com::android::server::wifi::wificond::NativeScanStats |
61 | convertToNativeScanStats( | 61 | convertToNativeScanStats( |
62 | const android::hardware::wifi::offload::V1_0::ScanStats& /* scanStats */); | 62 | const android::hardware::wifi::offload::V1_0::ScanStats& /* scanStats */); |
63 | }; | 63 | }; |
64 | 64 | ||
65 | } // namespace wificond | 65 | } // namespace wificond |
diff --git a/tests/mock_offload.h b/tests/mock_offload.h index 3f91d0a..399639c 100644 --- a/tests/mock_offload.h +++ b/tests/mock_offload.h | |||
@@ -25,29 +25,35 @@ namespace android { | |||
25 | namespace wificond { | 25 | namespace wificond { |
26 | 26 | ||
27 | typedef std::function<void( | 27 | typedef std::function<void( |
28 | const android::hardware::wifi::offload::V1_0::OffloadStatus& status, | ||
28 | const android::hardware::wifi::offload::V1_0::ScanStats& scanStats)> | 29 | const android::hardware::wifi::offload::V1_0::ScanStats& scanStats)> |
29 | OnScanStatsCallback; | 30 | OnScanStatsCallback; |
31 | typedef std::function<void( | ||
32 | const android::hardware::wifi::offload::V1_0::OffloadStatus& status)> | ||
33 | StatusCallback; | ||
30 | 34 | ||
31 | class MockOffload : public android::hardware::wifi::offload::V1_0::IOffload { | 35 | class MockOffload : public android::hardware::wifi::offload::V1_0::IOffload { |
32 | public: | 36 | public: |
33 | MockOffload(); | 37 | MockOffload(); |
34 | ~MockOffload() override = default; | 38 | ~MockOffload() override = default; |
35 | 39 | ||
36 | MOCK_METHOD2( | 40 | MOCK_METHOD3( |
37 | configureScans, | 41 | configureScans, |
38 | android::hardware::Return<void>( | 42 | android::hardware::Return<void>( |
39 | const android::hardware::wifi::offload::V1_0::ScanParam& param, | 43 | const android::hardware::wifi::offload::V1_0::ScanParam& param, |
40 | const android::hardware::wifi::offload::V1_0::ScanFilter& Filter)); | 44 | const android::hardware::wifi::offload::V1_0::ScanFilter& filter, |
45 | StatusCallback _hidl_cb)); | ||
41 | MOCK_METHOD1(getScanStats, | 46 | MOCK_METHOD1(getScanStats, |
42 | android::hardware::Return<void>(OnScanStatsCallback cb)); | 47 | android::hardware::Return<void>(OnScanStatsCallback cb)); |
43 | MOCK_METHOD1(subscribeScanResults, | 48 | MOCK_METHOD2(subscribeScanResults, |
44 | android::hardware::Return<void>(uint32_t delayMs)); | 49 | android::hardware::Return<void>(uint32_t delayMs, |
50 | StatusCallback _hidl_cb)); | ||
45 | MOCK_METHOD0(unsubscribeScanResults, android::hardware::Return<void>()); | 51 | MOCK_METHOD0(unsubscribeScanResults, android::hardware::Return<void>()); |
46 | MOCK_METHOD1( | 52 | MOCK_METHOD1( |
47 | setEventCallback, | 53 | setEventCallback, |
48 | android::hardware::Return<void>( | 54 | android::hardware::Return<void>( |
49 | const android::sp< | 55 | const android::sp< |
50 | ::android::hardware::wifi::offload::V1_0::IOffloadCallback>& cb)); | 56 | android::hardware::wifi::offload::V1_0::IOffloadCallback>& cb)); |
51 | }; | 57 | }; |
52 | 58 | ||
53 | } // namespace wificond | 59 | } // namespace wificond |
diff --git a/tests/mock_offload_callback_handlers.h b/tests/mock_offload_callback_handlers.h index 975eba5..e9b6285 100644 --- a/tests/mock_offload_callback_handlers.h +++ b/tests/mock_offload_callback_handlers.h | |||
@@ -36,7 +36,8 @@ class MockOffloadCallbackHandlers : public OffloadCallbackHandlers { | |||
36 | void(const std::vector< | 36 | void(const std::vector< |
37 | android::hardware::wifi::offload::V1_0::ScanResult>& scanResult)); | 37 | android::hardware::wifi::offload::V1_0::ScanResult>& scanResult)); |
38 | MOCK_METHOD1(OnErrorHandler, | 38 | MOCK_METHOD1(OnErrorHandler, |
39 | void(android::hardware::wifi::offload::V1_0::OffloadStatus)); | 39 | void(const android::hardware::wifi::offload::V1_0::OffloadStatus& |
40 | status)); | ||
40 | }; | 41 | }; |
41 | 42 | ||
42 | } // namespace wificond | 43 | } // namespace wificond |
diff --git a/tests/offload_callback_test.cpp b/tests/offload_callback_test.cpp index 7c0bae7..f55d281 100644 --- a/tests/offload_callback_test.cpp +++ b/tests/offload_callback_test.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | using android::hardware::wifi::offload::V1_0::ScanResult; | 29 | using android::hardware::wifi::offload::V1_0::ScanResult; |
30 | using android::hardware::wifi::offload::V1_0::OffloadStatus; | 30 | using android::hardware::wifi::offload::V1_0::OffloadStatus; |
31 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | ||
31 | using android::hardware::hidl_vec; | 32 | using android::hardware::hidl_vec; |
32 | using testing::NiceMock; | 33 | using testing::NiceMock; |
33 | 34 | ||
@@ -75,8 +76,10 @@ TEST_F(OffloadCallbackTest, checkErrorStatus) { | |||
75 | .WillByDefault(testing::Invoke( | 76 | .WillByDefault(testing::Invoke( |
76 | [&status_](OffloadStatus status) -> void { status_ = status; })); | 77 | [&status_](OffloadStatus status) -> void { status_ = status; })); |
77 | offload_callback_.reset(new OffloadCallback(handlers_.get())); | 78 | offload_callback_.reset(new OffloadCallback(handlers_.get())); |
78 | offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_ERROR); | 79 | OffloadStatus status = |
79 | EXPECT_EQ(status_, OffloadStatus::OFFLOAD_STATUS_ERROR); | 80 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
81 | offload_callback_->onError(status); | ||
82 | EXPECT_EQ(status_.code, OffloadStatusCode::ERROR); | ||
80 | } | 83 | } |
81 | 84 | ||
82 | } // namespace wificond | 85 | } // namespace wificond |
diff --git a/tests/offload_hal_test_constants.cpp b/tests/offload_hal_test_constants.cpp index c7e08a8..fd793d2 100644 --- a/tests/offload_hal_test_constants.cpp +++ b/tests/offload_hal_test_constants.cpp | |||
@@ -42,6 +42,7 @@ const uint32_t kDefaultNumScansRequestedByWifi = 2; | |||
42 | const uint32_t kDefaultNumScansServicedByWifi = 2; | 42 | const uint32_t kDefaultNumScansServicedByWifi = 2; |
43 | const uint64_t kScanDurationTotalMs = 2000; | 43 | const uint64_t kScanDurationTotalMs = 2000; |
44 | const uint32_t kNumChannelsTotalScanned = 20; | 44 | const uint32_t kNumChannelsTotalScanned = 20; |
45 | const uint32_t kNumChannelsInHistogram = 256; | ||
45 | 46 | ||
46 | } // namespace offload_hal_test_constants | 47 | } // namespace offload_hal_test_constants |
47 | } // namespace wificond | 48 | } // namespace wificond |
diff --git a/tests/offload_hal_test_constants.h b/tests/offload_hal_test_constants.h index 5d22c6c..86a42f2 100644 --- a/tests/offload_hal_test_constants.h +++ b/tests/offload_hal_test_constants.h | |||
@@ -46,6 +46,7 @@ extern const uint32_t kDefaultNumScansRequestedByWifi; | |||
46 | extern const uint32_t kDefaultNumScansServicedByWifi; | 46 | extern const uint32_t kDefaultNumScansServicedByWifi; |
47 | extern const uint64_t kScanDurationTotalMs; | 47 | extern const uint64_t kScanDurationTotalMs; |
48 | extern const uint32_t kNumChannelsTotalScanned; | 48 | extern const uint32_t kNumChannelsTotalScanned; |
49 | extern const uint32_t kNumChannelsInHistogram; | ||
49 | 50 | ||
50 | } // namespace offload_hal_test_constants | 51 | } // namespace offload_hal_test_constants |
51 | } // namespace wificond | 52 | } // namespace wificond |
diff --git a/tests/offload_scan_manager_test.cpp b/tests/offload_scan_manager_test.cpp index cde3a23..18a349a 100644 --- a/tests/offload_scan_manager_test.cpp +++ b/tests/offload_scan_manager_test.cpp | |||
@@ -32,17 +32,21 @@ | |||
32 | #include "wificond/scanning/offload/offload_scan_manager.h" | 32 | #include "wificond/scanning/offload/offload_scan_manager.h" |
33 | #include "wificond/scanning/scan_result.h" | 33 | #include "wificond/scanning/scan_result.h" |
34 | 34 | ||
35 | using android::hardware::Return; | ||
36 | using android::hardware::Void; | ||
37 | using android::hardware::wifi::offload::V1_0::IOffload; | ||
35 | using android::hardware::wifi::offload::V1_0::ScanResult; | 38 | using android::hardware::wifi::offload::V1_0::ScanResult; |
36 | using android::hardware::wifi::offload::V1_0::OffloadStatus; | 39 | using android::hardware::wifi::offload::V1_0::OffloadStatus; |
40 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | ||
37 | using android::hardware::wifi::offload::V1_0::ScanParam; | 41 | using android::hardware::wifi::offload::V1_0::ScanParam; |
38 | using android::hardware::wifi::offload::V1_0::ScanFilter; | 42 | using android::hardware::wifi::offload::V1_0::ScanFilter; |
39 | using android::hardware::wifi::offload::V1_0::ScanStats; | 43 | using android::hardware::wifi::offload::V1_0::ScanStats; |
44 | using android::sp; | ||
40 | using com::android::server::wifi::wificond::NativeScanResult; | 45 | using com::android::server::wifi::wificond::NativeScanResult; |
41 | using com::android::server::wifi::wificond::NativeScanStats; | 46 | using com::android::server::wifi::wificond::NativeScanStats; |
42 | using testing::NiceMock; | 47 | using testing::NiceMock; |
43 | using testing::_; | 48 | using testing::_; |
44 | using testing::Invoke; | 49 | using testing::Invoke; |
45 | using android::sp; | ||
46 | using std::unique_ptr; | 50 | using std::unique_ptr; |
47 | using std::vector; | 51 | using std::vector; |
48 | using std::bind; | 52 | using std::bind; |
@@ -59,21 +63,43 @@ sp<OffloadCallback> CaptureReturnValue(OffloadCallbackHandlers* handler, | |||
59 | return *offload_callback; | 63 | return *offload_callback; |
60 | } | 64 | } |
61 | 65 | ||
66 | Return<void> HidlStatusReturn(android::wificond::StatusCallback cb, | ||
67 | OffloadStatus* status) { | ||
68 | cb(*status); | ||
69 | return Void(); | ||
70 | } | ||
71 | |||
72 | Return<void> ScanStatusReturn(android::wificond::OnScanStatsCallback cb, | ||
73 | OffloadStatus* status) { | ||
74 | ScanStats stats; | ||
75 | cb(*status, stats); | ||
76 | return Void(); | ||
77 | } | ||
78 | |||
62 | class OffloadScanManagerTest : public ::testing::Test { | 79 | class OffloadScanManagerTest : public ::testing::Test { |
63 | protected: | 80 | protected: |
64 | virtual void SetUp() { | 81 | virtual void SetUp() { |
65 | ON_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)) | 82 | ON_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)) |
66 | .WillByDefault( | 83 | .WillByDefault(Invoke(bind(CaptureReturnValue, _1, &offload_callback_))); |
67 | Invoke(bind(CaptureReturnValue, _1, &offload_callback_))); | 84 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::OK); |
85 | ON_CALL(*mock_offload_, configureScans(_, _, _)) | ||
86 | .WillByDefault(Invoke(bind(HidlStatusReturn, _3, &status))); | ||
87 | ON_CALL(*mock_offload_, subscribeScanResults(_, _)) | ||
88 | .WillByDefault(Invoke(bind(HidlStatusReturn, _2, &status))); | ||
89 | ON_CALL(*mock_offload_, getScanStats(_)) | ||
90 | .WillByDefault(Invoke(bind(ScanStatusReturn, _1, &status))); | ||
68 | } | 91 | } |
69 | 92 | ||
70 | void TearDown() override { offload_callback_.clear(); } | 93 | void TearDown() override { |
94 | offload_callback_.clear(); | ||
95 | } | ||
71 | 96 | ||
72 | sp<NiceMock<MockOffload>> mock_offload_{new NiceMock<MockOffload>()}; | 97 | sp<NiceMock<MockOffload>> mock_offload_{new NiceMock<MockOffload>()}; |
73 | sp<OffloadCallback> offload_callback_; | 98 | sp<OffloadCallback> offload_callback_; |
74 | unique_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ | 99 | unique_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ |
75 | new NiceMock<MockOffloadServiceUtils>()}; | 100 | new NiceMock<MockOffloadServiceUtils>()}; |
76 | unique_ptr<OffloadScanManager> offload_scan_manager_; | 101 | unique_ptr<OffloadScanManager> offload_scan_manager_; |
102 | OffloadStatus status; | ||
77 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; | 103 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; |
78 | vector<vector<uint8_t>> match_ssids{kSsid1, kSsid2}; | 104 | vector<vector<uint8_t>> match_ssids{kSsid1, kSsid2}; |
79 | vector<uint8_t> security_flags{kNetworkFlags, kNetworkFlags}; | 105 | vector<uint8_t> security_flags{kNetworkFlags, kNetworkFlags}; |
@@ -150,7 +176,9 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) { | |||
150 | offload_scan_manager_.reset(new OffloadScanManager( | 176 | offload_scan_manager_.reset(new OffloadScanManager( |
151 | mock_offload_service_utils_.get(), | 177 | mock_offload_service_utils_.get(), |
152 | [](vector<NativeScanResult> scanResult) -> void {})); | 178 | [](vector<NativeScanResult> scanResult) -> void {})); |
153 | offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_ERROR); | 179 | OffloadStatus status = |
180 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | ||
181 | offload_callback_->onError(status); | ||
154 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), | 182 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), |
155 | OffloadScanManager::kError); | 183 | OffloadScanManager::kError); |
156 | } | 184 | } |
@@ -166,8 +194,8 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | |||
166 | offload_scan_manager_.reset(new OffloadScanManager( | 194 | offload_scan_manager_.reset(new OffloadScanManager( |
167 | mock_offload_service_utils_.get(), | 195 | mock_offload_service_utils_.get(), |
168 | [](vector<NativeScanResult> scanResult) -> void {})); | 196 | [](vector<NativeScanResult> scanResult) -> void {})); |
169 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_)); | 197 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
170 | EXPECT_CALL(*mock_offload_, configureScans(_, _)); | 198 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
171 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 199 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
172 | bool result = offload_scan_manager_->startScan( | 200 | bool result = offload_scan_manager_->startScan( |
173 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 201 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -191,7 +219,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { | |||
191 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 219 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
192 | security_flags, frequencies, &reason_code); | 220 | security_flags, frequencies, &reason_code); |
193 | EXPECT_EQ(result, false); | 221 | EXPECT_EQ(result, false); |
194 | EXPECT_EQ(reason_code, OffloadScanManager::kNotSupported); | 222 | EXPECT_EQ(reason_code, OffloadScanManager::kNotAvailable); |
195 | } | 223 | } |
196 | 224 | ||
197 | /** | 225 | /** |
@@ -205,7 +233,9 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) { | |||
205 | offload_scan_manager_.reset(new OffloadScanManager( | 233 | offload_scan_manager_.reset(new OffloadScanManager( |
206 | mock_offload_service_utils_.get(), | 234 | mock_offload_service_utils_.get(), |
207 | [](vector<NativeScanResult> scanResult) -> void {})); | 235 | [](vector<NativeScanResult> scanResult) -> void {})); |
208 | offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_NO_CONNECTION); | 236 | OffloadStatus status = |
237 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | ||
238 | offload_callback_->onError(status); | ||
209 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 239 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
210 | bool result = offload_scan_manager_->startScan( | 240 | bool result = offload_scan_manager_->startScan( |
211 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 241 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -225,8 +255,8 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) { | |||
225 | offload_scan_manager_.reset(new OffloadScanManager( | 255 | offload_scan_manager_.reset(new OffloadScanManager( |
226 | mock_offload_service_utils_.get(), | 256 | mock_offload_service_utils_.get(), |
227 | [](vector<NativeScanResult> scanResult) -> void {})); | 257 | [](vector<NativeScanResult> scanResult) -> void {})); |
228 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_)).Times(1); | 258 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1); |
229 | EXPECT_CALL(*mock_offload_, configureScans(_, _)).Times(2); | 259 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); |
230 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 260 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
231 | bool result = offload_scan_manager_->startScan( | 261 | bool result = offload_scan_manager_->startScan( |
232 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 262 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -249,8 +279,8 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | |||
249 | offload_scan_manager_.reset(new OffloadScanManager( | 279 | offload_scan_manager_.reset(new OffloadScanManager( |
250 | mock_offload_service_utils_.get(), | 280 | mock_offload_service_utils_.get(), |
251 | [](vector<NativeScanResult> scanResult) -> void {})); | 281 | [](vector<NativeScanResult> scanResult) -> void {})); |
252 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_)); | 282 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
253 | EXPECT_CALL(*mock_offload_, configureScans(_, _)); | 283 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
254 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | 284 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); |
255 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 285 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
256 | bool result = offload_scan_manager_->startScan( | 286 | bool result = offload_scan_manager_->startScan( |
@@ -289,15 +319,17 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | |||
289 | offload_scan_manager_.reset(new OffloadScanManager( | 319 | offload_scan_manager_.reset(new OffloadScanManager( |
290 | mock_offload_service_utils_.get(), | 320 | mock_offload_service_utils_.get(), |
291 | [](vector<NativeScanResult> scanResult) -> void {})); | 321 | [](vector<NativeScanResult> scanResult) -> void {})); |
292 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_)); | 322 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
293 | EXPECT_CALL(*mock_offload_, configureScans(_, _)); | 323 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
294 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | 324 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); |
295 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 325 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
296 | bool result = offload_scan_manager_->startScan( | 326 | bool result = offload_scan_manager_->startScan( |
297 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 327 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
298 | security_flags, frequencies, &reason_code); | 328 | security_flags, frequencies, &reason_code); |
299 | EXPECT_EQ(result, true); | 329 | EXPECT_EQ(result, true); |
300 | offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_NO_CONNECTION); | 330 | OffloadStatus status = |
331 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | ||
332 | offload_callback_->onError(status); | ||
301 | result = offload_scan_manager_->stopScan(&reason_code); | 333 | result = offload_scan_manager_->stopScan(&reason_code); |
302 | EXPECT_EQ(result, true); | 334 | EXPECT_EQ(result, true); |
303 | } | 335 | } |
@@ -330,12 +362,54 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) { | |||
330 | offload_scan_manager_.reset(new OffloadScanManager( | 362 | offload_scan_manager_.reset(new OffloadScanManager( |
331 | mock_offload_service_utils_.get(), | 363 | mock_offload_service_utils_.get(), |
332 | [](vector<NativeScanResult> scanResult) -> void {})); | 364 | [](vector<NativeScanResult> scanResult) -> void {})); |
333 | offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_NO_CONNECTION); | 365 | OffloadStatus status = |
366 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | ||
367 | offload_callback_->onError(status); | ||
334 | EXPECT_CALL(*mock_offload_, getScanStats(_)).Times(0); | 368 | EXPECT_CALL(*mock_offload_, getScanStats(_)).Times(0); |
335 | NativeScanStats stats; | 369 | NativeScanStats stats; |
336 | bool result = offload_scan_manager_->getScanStats(&stats); | 370 | bool result = offload_scan_manager_->getScanStats(&stats); |
337 | EXPECT_EQ(result, false); | 371 | EXPECT_EQ(result, false); |
338 | } | 372 | } |
339 | 373 | ||
374 | /** | ||
375 | * Testing OffloadScanManager for subscribing to the scan results from | ||
376 | * Offload HAL when service is running without errors, operation failure | ||
377 | */ | ||
378 | TEST_F(OffloadScanManagerTest, StartScanFailedTest) { | ||
379 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | ||
380 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | ||
381 | .WillByDefault(testing::Return(mock_offload_)); | ||
382 | offload_scan_manager_.reset(new OffloadScanManager( | ||
383 | mock_offload_service_utils_.get(), | ||
384 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
385 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); | ||
386 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); | ||
387 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | ||
388 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | ||
389 | bool result = offload_scan_manager_->startScan( | ||
390 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | ||
391 | security_flags, frequencies, &reason_code); | ||
392 | EXPECT_EQ(result, false); | ||
393 | EXPECT_EQ(reason_code, OffloadScanManager::kOperationFailed); | ||
394 | } | ||
395 | |||
396 | /** | ||
397 | * Testing OffloadScanManager for getting scan statistics when the | ||
398 | * Offload HAL service is running without errors, getting scan stats failure | ||
399 | */ | ||
400 | TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) { | ||
401 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | ||
402 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | ||
403 | .WillByDefault(testing::Return(mock_offload_)); | ||
404 | offload_scan_manager_.reset(new OffloadScanManager( | ||
405 | mock_offload_service_utils_.get(), | ||
406 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
407 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); | ||
408 | EXPECT_CALL(*mock_offload_, getScanStats(_)); | ||
409 | NativeScanStats stats; | ||
410 | bool result = offload_scan_manager_->getScanStats(&stats); | ||
411 | EXPECT_EQ(result, false); | ||
412 | } | ||
413 | |||
340 | } // namespace wificond | 414 | } // namespace wificond |
341 | } // namespace android | 415 | } // namespace android |
diff --git a/tests/offload_test_utils.cpp b/tests/offload_test_utils.cpp index a137976..2b2acd8 100644 --- a/tests/offload_test_utils.cpp +++ b/tests/offload_test_utils.cpp | |||
@@ -23,6 +23,7 @@ using android::hardware::wifi::offload::V1_0::ScanResult; | |||
23 | using android::hardware::wifi::offload::V1_0::ScanStats; | 23 | using android::hardware::wifi::offload::V1_0::ScanStats; |
24 | using android::hardware::wifi::offload::V1_0::ScanRecord; | 24 | using android::hardware::wifi::offload::V1_0::ScanRecord; |
25 | using android::hardware::wifi::offload::V1_0::OffloadStatus; | 25 | using android::hardware::wifi::offload::V1_0::OffloadStatus; |
26 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | ||
26 | 27 | ||
27 | using ::com::android::server::wifi::wificond::NativeScanResult; | 28 | using ::com::android::server::wifi::wificond::NativeScanResult; |
28 | using ::com::android::server::wifi::wificond::NativeScanStats; | 29 | using ::com::android::server::wifi::wificond::NativeScanStats; |
@@ -87,5 +88,14 @@ ScanStats OffloadTestUtils::createScanStats(NativeScanStats* nativeScanStats) { | |||
87 | return scan_stats; | 88 | return scan_stats; |
88 | } | 89 | } |
89 | 90 | ||
91 | OffloadStatus OffloadTestUtils::createOffloadStatus(OffloadStatusCode code) { | ||
92 | return createOffloadStatus(code, ""); | ||
93 | } | ||
94 | |||
95 | OffloadStatus OffloadTestUtils::createOffloadStatus(OffloadStatusCode code, | ||
96 | const std::string& desc) { | ||
97 | return {code, desc}; | ||
98 | } | ||
99 | |||
90 | } // namespace wificond | 100 | } // namespace wificond |
91 | } // namespace android | 101 | } // namespace android |
diff --git a/tests/offload_test_utils.h b/tests/offload_test_utils.h index 620033e..f2370e2 100644 --- a/tests/offload_test_utils.h +++ b/tests/offload_test_utils.h | |||
@@ -33,6 +33,13 @@ class OffloadTestUtils { | |||
33 | static android::hardware::wifi::offload::V1_0::ScanStats createScanStats( | 33 | static android::hardware::wifi::offload::V1_0::ScanStats createScanStats( |
34 | ::com::android::server::wifi::wificond:: | 34 | ::com::android::server::wifi::wificond:: |
35 | NativeScanStats* /* nativeScanStats */); | 35 | NativeScanStats* /* nativeScanStats */); |
36 | static android::hardware::wifi::offload::V1_0::OffloadStatus | ||
37 | createOffloadStatus( | ||
38 | android::hardware::wifi::offload::V1_0::OffloadStatusCode code); | ||
39 | static android::hardware::wifi::offload::V1_0::OffloadStatus | ||
40 | createOffloadStatus( | ||
41 | android::hardware::wifi::offload::V1_0::OffloadStatusCode code, | ||
42 | const std::string& desc); | ||
36 | }; | 43 | }; |
37 | 44 | ||
38 | } // namespace wificond | 45 | } // namespace wificond |
diff --git a/tests/scan_stats_unittest.cpp b/tests/scan_stats_unittest.cpp index a867378..6eb72d6 100644 --- a/tests/scan_stats_unittest.cpp +++ b/tests/scan_stats_unittest.cpp | |||
@@ -27,20 +27,17 @@ using namespace android::wificond::offload_hal_test_constants; | |||
27 | namespace android { | 27 | namespace android { |
28 | namespace wificond { | 28 | namespace wificond { |
29 | 29 | ||
30 | class ScanStatsTest : public ::testing::Test { | 30 | class ScanStatsTest : public ::testing::Test {}; |
31 | }; | ||
32 | 31 | ||
33 | TEST_F(ScanStatsTest, ParcelableTest) { | 32 | TEST_F(ScanStatsTest, ParcelableTest) { |
34 | std::vector<uint8_t> histogram_channels; | 33 | std::vector<uint8_t> histogram_channels; |
35 | for(size_t i = 0; i < 256; i++) { | 34 | for (size_t i = 0; i < kNumChannelsInHistogram; i++) { |
36 | histogram_channels.push_back(255 - i); | 35 | histogram_channels.push_back(kNumChannelsInHistogram - 1 - i); |
37 | } | 36 | } |
38 | NativeScanStats scan_stats_in(kDefaultNumScansRequestedByWifi, | 37 | NativeScanStats scan_stats_in(kDefaultNumScansRequestedByWifi, |
39 | kDefaultNumScansServicedByWifi, | 38 | kDefaultNumScansServicedByWifi, |
40 | kScanDurationTotalMs, | 39 | kScanDurationTotalMs, kSubscriptionDurationMs, |
41 | kSubscriptionDurationMs, | 40 | kNumChannelsTotalScanned, histogram_channels); |
42 | kNumChannelsTotalScanned, | ||
43 | histogram_channels); | ||
44 | Parcel parcel; | 41 | Parcel parcel; |
45 | EXPECT_EQ(::android::OK, scan_stats_in.writeToParcel(&parcel)); | 42 | EXPECT_EQ(::android::OK, scan_stats_in.writeToParcel(&parcel)); |
46 | NativeScanStats scan_stats_out; | 43 | NativeScanStats scan_stats_out; |
@@ -49,5 +46,5 @@ TEST_F(ScanStatsTest, ParcelableTest) { | |||
49 | EXPECT_TRUE(scan_stats_in == scan_stats_out); | 46 | EXPECT_TRUE(scan_stats_in == scan_stats_out); |
50 | } | 47 | } |
51 | 48 | ||
52 | } // namespace wificond | 49 | } // namespace wificond |
53 | } // namespace android | 50 | } // namespace android |