diff options
32 files changed, 897 insertions, 478 deletions
@@ -14,9 +14,6 @@ | |||
14 | 14 | ||
15 | LOCAL_PATH := $(call my-dir) | 15 | LOCAL_PATH := $(call my-dir) |
16 | wificond_cpp_flags := -Wall -Werror -Wno-unused-parameter | 16 | wificond_cpp_flags := -Wall -Werror -Wno-unused-parameter |
17 | ifdef WIFI_OFFLOAD_SCANS | ||
18 | wificond_cpp_flags += -DWIFI_OFFLOAD_SCANS=\"$(WIFI_OFFLOAD_SCANS)\" | ||
19 | endif | ||
20 | wificond_parent_dir := $(LOCAL_PATH)/../ | 17 | wificond_parent_dir := $(LOCAL_PATH)/../ |
21 | wificond_includes := \ | 18 | wificond_includes := \ |
22 | $(wificond_parent_dir) | 19 | $(wificond_parent_dir) |
@@ -62,10 +59,9 @@ LOCAL_SRC_FILES := \ | |||
62 | client_interface_impl.cpp \ | 59 | client_interface_impl.cpp \ |
63 | logging_utils.cpp \ | 60 | logging_utils.cpp \ |
64 | looper_backed_event_loop.cpp \ | 61 | looper_backed_event_loop.cpp \ |
65 | rtt/rtt_controller_binder.cpp \ | ||
66 | rtt/rtt_controller_impl.cpp \ | ||
67 | scanning/channel_settings.cpp \ | 62 | scanning/channel_settings.cpp \ |
68 | scanning/hidden_network.cpp \ | 63 | scanning/hidden_network.cpp \ |
64 | scanning/offload_scan_callback_interface_impl.cpp \ | ||
69 | scanning/pno_network.cpp \ | 65 | scanning/pno_network.cpp \ |
70 | scanning/pno_settings.cpp \ | 66 | scanning/pno_settings.cpp \ |
71 | scanning/scan_result.cpp \ | 67 | scanning/scan_result.cpp \ |
@@ -124,8 +120,6 @@ LOCAL_SRC_FILES := \ | |||
124 | aidl/android/net/wifi/IClientInterface.aidl \ | 120 | aidl/android/net/wifi/IClientInterface.aidl \ |
125 | aidl/android/net/wifi/IInterfaceEventCallback.aidl \ | 121 | aidl/android/net/wifi/IInterfaceEventCallback.aidl \ |
126 | aidl/android/net/wifi/IPnoScanEvent.aidl \ | 122 | aidl/android/net/wifi/IPnoScanEvent.aidl \ |
127 | aidl/android/net/wifi/IRttClient.aidl \ | ||
128 | aidl/android/net/wifi/IRttController.aidl \ | ||
129 | aidl/android/net/wifi/IScanEvent.aidl \ | 123 | aidl/android/net/wifi/IScanEvent.aidl \ |
130 | aidl/android/net/wifi/IWificond.aidl \ | 124 | aidl/android/net/wifi/IWificond.aidl \ |
131 | aidl/android/net/wifi/IWifiScannerImpl.aidl \ | 125 | aidl/android/net/wifi/IWifiScannerImpl.aidl \ |
@@ -175,6 +169,9 @@ LOCAL_SRC_FILES := \ | |||
175 | tests/mock_netlink_utils.cpp \ | 169 | tests/mock_netlink_utils.cpp \ |
176 | tests/mock_offload.cpp \ | 170 | tests/mock_offload.cpp \ |
177 | tests/mock_offload_callback_handlers.cpp \ | 171 | tests/mock_offload_callback_handlers.cpp \ |
172 | tests/mock_offload_scan_callback_interface.cpp \ | ||
173 | tests/mock_offload_scan_callback_interface_impl.cpp \ | ||
174 | tests/mock_offload_scan_manager.cpp \ | ||
178 | tests/mock_offload_service_utils.cpp \ | 175 | tests/mock_offload_service_utils.cpp \ |
179 | tests/mock_scan_utils.cpp \ | 176 | tests/mock_scan_utils.cpp \ |
180 | tests/netlink_manager_unittest.cpp \ | 177 | tests/netlink_manager_unittest.cpp \ |
diff --git a/aidl/android/net/wifi/IPnoScanEvent.aidl b/aidl/android/net/wifi/IPnoScanEvent.aidl index 6488c19..50c1918 100644 --- a/aidl/android/net/wifi/IPnoScanEvent.aidl +++ b/aidl/android/net/wifi/IPnoScanEvent.aidl | |||
@@ -18,6 +18,15 @@ package android.net.wifi; | |||
18 | 18 | ||
19 | // A callback for receiving pno scanning events. | 19 | // A callback for receiving pno scanning events. |
20 | interface IPnoScanEvent { | 20 | interface IPnoScanEvent { |
21 | const int PNO_SCAN_OVER_OFFLOAD_BINDER_FAILURE = 0; | ||
22 | const int PNO_SCAN_OVER_OFFLOAD_REMOTE_FAILURE = 1; | ||
23 | |||
21 | oneway void OnPnoNetworkFound(); | 24 | oneway void OnPnoNetworkFound(); |
22 | oneway void OnPnoScanFailed(); | 25 | oneway void OnPnoScanFailed(); |
26 | // Callback notifying the framework that PNO scan is started over Offload HAL | ||
27 | // interface, this is meant for metrics collection only | ||
28 | oneway void OnPnoScanOverOffloadStarted(); | ||
29 | // Callback notifying the framework that a PNO scan running over Offload HAL | ||
30 | // has failed, this is meant for metrics collection only | ||
31 | oneway void OnPnoScanOverOffloadFailed(int reason); | ||
23 | } | 32 | } |
diff --git a/aidl/android/net/wifi/IWifiScannerImpl.aidl b/aidl/android/net/wifi/IWifiScannerImpl.aidl index da0ca2d..e83b79c 100644 --- a/aidl/android/net/wifi/IWifiScannerImpl.aidl +++ b/aidl/android/net/wifi/IWifiScannerImpl.aidl | |||
@@ -35,9 +35,13 @@ interface IWifiScannerImpl { | |||
35 | // Returrns null on failure. | 35 | // Returrns null on failure. |
36 | @nullable int[] getAvailableDFSChannels(); | 36 | @nullable int[] getAvailableDFSChannels(); |
37 | 37 | ||
38 | // Get the latest scan results from kernel. | 38 | // Get the latest single scan results from kernel. |
39 | NativeScanResult[] getScanResults(); | 39 | NativeScanResult[] getScanResults(); |
40 | 40 | ||
41 | // Get the latest pno scan results from the interface which has most recently | ||
42 | // completed disconnected mode PNO scans | ||
43 | NativeScanResult[] getPnoScanResults(); | ||
44 | |||
41 | // Request a single scan using a SingleScanSettings parcelable object. | 45 | // Request a single scan using a SingleScanSettings parcelable object. |
42 | boolean scan(in SingleScanSettings scanSettings); | 46 | boolean scan(in SingleScanSettings scanSettings); |
43 | 47 | ||
diff --git a/aidl/android/net/wifi/IWificond.aidl b/aidl/android/net/wifi/IWificond.aidl index 48e2924..0b303ad 100644 --- a/aidl/android/net/wifi/IWificond.aidl +++ b/aidl/android/net/wifi/IWificond.aidl | |||
@@ -19,8 +19,6 @@ package android.net.wifi; | |||
19 | import android.net.wifi.IApInterface; | 19 | import android.net.wifi.IApInterface; |
20 | import android.net.wifi.IClientInterface; | 20 | import android.net.wifi.IClientInterface; |
21 | import android.net.wifi.IInterfaceEventCallback; | 21 | import android.net.wifi.IInterfaceEventCallback; |
22 | import android.net.wifi.IRttClient; | ||
23 | import android.net.wifi.IRttController; | ||
24 | 22 | ||
25 | // Service interface that exposes primitives for controlling the WiFi | 23 | // Service interface that exposes primitives for controlling the WiFi |
26 | // subsystems of a device. | 24 | // subsystems of a device. |
@@ -57,14 +55,4 @@ interface IWificond { | |||
57 | // | 55 | // |
58 | // @param callback object to remove from the set of registered callbacks. | 56 | // @param callback object to remove from the set of registered callbacks. |
59 | oneway void UnregisterCallback(IInterfaceEventCallback callback); | 57 | oneway void UnregisterCallback(IInterfaceEventCallback callback); |
60 | |||
61 | // Obtain a reference to a IRttController that can be used to | ||
62 | // request ranging information. | ||
63 | // Results will be returned via the registered IRttClient. | ||
64 | IRttController registerRttClient(IRttClient rttClient); | ||
65 | |||
66 | // Remove an IRttClient from the set of registered IRttClient callbacks. | ||
67 | // @param rttClient object to remove from the set of registered | ||
68 | // IRttClient callbacks. | ||
69 | void unregisterRttClient(IRttClient rttClient); | ||
70 | } | 58 | } |
@@ -139,7 +139,9 @@ int main(int argc, char** argv) { | |||
139 | &OnHwBinderReadReady)) << "Failed to watch Hw Binder FD"; | 139 | &OnHwBinderReadReady)) << "Failed to watch Hw Binder FD"; |
140 | 140 | ||
141 | android::wificond::NetlinkManager netlink_manager(event_dispatcher.get()); | 141 | android::wificond::NetlinkManager netlink_manager(event_dispatcher.get()); |
142 | CHECK(netlink_manager.Start()) << "Failed to start netlink manager"; | 142 | if (!netlink_manager.Start()) { |
143 | LOG(ERROR) << "Failed to start netlink manager"; | ||
144 | } | ||
143 | android::wificond::NetlinkUtils netlink_utils(&netlink_manager); | 145 | android::wificond::NetlinkUtils netlink_utils(&netlink_manager); |
144 | android::wificond::ScanUtils scan_utils(&netlink_manager); | 146 | android::wificond::ScanUtils scan_utils(&netlink_manager); |
145 | 147 | ||
diff --git a/rtt/rtt_controller_impl.cpp b/rtt/rtt_controller_impl.cpp deleted file mode 100644 index 197faca..0000000 --- a/rtt/rtt_controller_impl.cpp +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
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 "wificond/rtt/rtt_controller_impl.h" | ||
18 | |||
19 | #include <android-base/logging.h> | ||
20 | |||
21 | #include "wificond/rtt/rtt_controller_binder.h" | ||
22 | |||
23 | using android::net::wifi::IRttClient; | ||
24 | using android::net::wifi::IRttController; | ||
25 | using android::sp; | ||
26 | |||
27 | namespace android { | ||
28 | namespace wificond { | ||
29 | |||
30 | RttControllerImpl::RttControllerImpl() | ||
31 | : binder_(new RttControllerBinder(this)) { | ||
32 | // TODO(nywang): create a HAL RttController object. | ||
33 | } | ||
34 | |||
35 | RttControllerImpl::~RttControllerImpl() { | ||
36 | binder_->NotifyImplDead(); | ||
37 | } | ||
38 | |||
39 | sp<IRttController> RttControllerImpl::GetBinder() const { | ||
40 | return binder_; | ||
41 | } | ||
42 | |||
43 | bool RttControllerImpl::RegisterRttClient(android::sp<IRttClient> client) { | ||
44 | for (auto& it : clients_) { | ||
45 | if (IRttClient::asBinder(client) == IRttClient::asBinder(it)) { | ||
46 | LOG(WARNING) << "Ignore duplicate RttClient registration"; | ||
47 | return false; | ||
48 | } | ||
49 | } | ||
50 | clients_.push_back(client); | ||
51 | return true; | ||
52 | |||
53 | } | ||
54 | |||
55 | bool RttControllerImpl::UnregisterRttClient(android::sp<IRttClient> client) { | ||
56 | for (auto it = clients_.begin(); it != clients_.end(); it++) { | ||
57 | if (IRttClient::asBinder(client) == IRttClient::asBinder(*it)) { | ||
58 | clients_.erase(it); | ||
59 | return true; | ||
60 | } | ||
61 | } | ||
62 | LOG(WARNING) << "Failed to find registered RttClient to unregister"; | ||
63 | return false; | ||
64 | } | ||
65 | |||
66 | size_t RttControllerImpl::GetClientCount() const { | ||
67 | return clients_.size(); | ||
68 | } | ||
69 | |||
70 | } // namespace wificond | ||
71 | } // namespace android | ||
diff --git a/rtt/rtt_controller_impl.h b/rtt/rtt_controller_impl.h deleted file mode 100644 index da650ef..0000000 --- a/rtt/rtt_controller_impl.h +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
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 | #ifndef WIFICOND_RTT_CONTROLLER_IMPL_H_ | ||
18 | #define WIFICOND_RTT_CONTROLLER_IMPL_H_ | ||
19 | |||
20 | #include <vector> | ||
21 | |||
22 | #include <android-base/macros.h> | ||
23 | |||
24 | #include "android/net/wifi/IRttController.h" | ||
25 | #include "android/net/wifi/IRttClient.h" | ||
26 | |||
27 | namespace android { | ||
28 | namespace wificond { | ||
29 | |||
30 | class RttControllerBinder; | ||
31 | |||
32 | class RttControllerImpl { | ||
33 | public: | ||
34 | RttControllerImpl(); | ||
35 | ~RttControllerImpl(); | ||
36 | |||
37 | bool RegisterRttClient(android::sp<android::net::wifi::IRttClient> client); | ||
38 | bool UnregisterRttClient(android::sp<android::net::wifi::IRttClient> client); | ||
39 | size_t GetClientCount() const; | ||
40 | |||
41 | // Get a pointer to the binder representing this RttControllerImpl. | ||
42 | android::sp<android::net::wifi::IRttController> GetBinder() const; | ||
43 | |||
44 | private: | ||
45 | const android::sp<RttControllerBinder> binder_; | ||
46 | std::vector<android::sp<android::net::wifi::IRttClient>> clients_; | ||
47 | |||
48 | DISALLOW_COPY_AND_ASSIGN(RttControllerImpl); | ||
49 | }; | ||
50 | |||
51 | } // namespace wificond | ||
52 | } // namespace android | ||
53 | |||
54 | #endif // WIFICOND_RTT_CONTROLLER_IMPL_H_ | ||
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp index 5e3d90d..2592aee 100644 --- a/scanning/offload/offload_scan_manager.cpp +++ b/scanning/offload/offload_scan_manager.cpp | |||
@@ -35,11 +35,11 @@ using android::hardware::wifi::offload::V1_0::OffloadStatus; | |||
35 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | 35 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; |
36 | 36 | ||
37 | using android::wificond::OffloadCallback; | 37 | using android::wificond::OffloadCallback; |
38 | using android::wificond::OnNativeScanResultsReadyHandler; | ||
39 | using ::com::android::server::wifi::wificond::NativeScanResult; | 38 | using ::com::android::server::wifi::wificond::NativeScanResult; |
40 | using ::com::android::server::wifi::wificond::NativeScanStats; | 39 | using ::com::android::server::wifi::wificond::NativeScanStats; |
41 | using std::vector; | 40 | using std::vector; |
42 | using std::weak_ptr; | 41 | using std::weak_ptr; |
42 | using std::shared_ptr; | ||
43 | 43 | ||
44 | using namespace std::placeholders; | 44 | using namespace std::placeholders; |
45 | 45 | ||
@@ -69,55 +69,78 @@ void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) { | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils, | 72 | OffloadScanManager::OffloadScanManager( |
73 | OnNativeScanResultsReadyHandler handler) | 73 | weak_ptr<OffloadServiceUtils> utils, |
74 | shared_ptr<OffloadScanCallbackInterface> callback) | ||
74 | : wifi_offload_hal_(nullptr), | 75 | : wifi_offload_hal_(nullptr), |
75 | wifi_offload_callback_(nullptr), | 76 | wifi_offload_callback_(nullptr), |
77 | death_recipient_(nullptr), | ||
76 | offload_status_(OffloadScanManager::kError), | 78 | offload_status_(OffloadScanManager::kError), |
77 | subscription_enabled_(false), | 79 | cached_scan_results_(new std::vector<NativeScanResult>()), |
80 | service_available_(false), | ||
81 | offload_service_utils_(utils), | ||
78 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), | 82 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), |
79 | scan_result_handler_(handler) { | 83 | event_callback_(callback) { |
80 | auto offload_scan_utils = utils.lock(); | 84 | if (InitService()) { |
81 | if (scan_result_handler_ == nullptr) { | 85 | offload_status_ = OffloadScanManager::kNoError; |
82 | LOG(ERROR) << "Invalid Offload scan result handler"; | ||
83 | return; | ||
84 | } | 86 | } |
85 | wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); | 87 | } |
88 | |||
89 | bool OffloadScanManager::InitService() { | ||
90 | wifi_offload_hal_ = offload_service_utils_.lock()->GetOffloadService(); | ||
86 | if (wifi_offload_hal_ == nullptr) { | 91 | if (wifi_offload_hal_ == nullptr) { |
87 | LOG(ERROR) << "No Offload Service available"; | 92 | LOG(ERROR) << "No Offload Service available"; |
88 | return; | 93 | return false; |
89 | } | 94 | } |
90 | 95 | ||
91 | death_recipient_ = offload_scan_utils->GetOffloadDeathRecipient( | 96 | death_recipient_ = offload_service_utils_.lock()->GetOffloadDeathRecipient( |
92 | std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); | 97 | std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); |
93 | uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); | 98 | uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); |
99 | |||
94 | auto link_to_death_status = | 100 | auto link_to_death_status = |
95 | wifi_offload_hal_->linkToDeath(death_recipient_, cookie); | 101 | wifi_offload_hal_->linkToDeath(death_recipient_, cookie); |
96 | if (!link_to_death_status.isOk()) { | 102 | if (!link_to_death_status.isOk()) { |
97 | LOG(ERROR) << "Unable to register death handler " | 103 | LOG(ERROR) << "Unable to register death handler " |
98 | << link_to_death_status.description(); | 104 | << link_to_death_status.description(); |
99 | return; | 105 | return false; |
100 | } | 106 | } |
101 | 107 | ||
102 | wifi_offload_callback_ = | 108 | wifi_offload_callback_ = offload_service_utils_.lock()->GetOffloadCallback( |
103 | offload_scan_utils->GetOffloadCallback(offload_callback_handlers_.get()); | 109 | offload_callback_handlers_.get()); |
104 | if (wifi_offload_callback_ == nullptr) { | 110 | if (wifi_offload_callback_ == nullptr) { |
105 | LOG(ERROR) << "Invalid Offload callback object"; | 111 | LOG(ERROR) << "Invalid Offload callback object"; |
106 | return; | 112 | return false; |
107 | } | 113 | } |
108 | wifi_offload_hal_->setEventCallback(wifi_offload_callback_); | 114 | |
109 | offload_status_ = OffloadScanManager::kNoError; | 115 | auto set_callback_status = |
116 | wifi_offload_hal_->setEventCallback(wifi_offload_callback_); | ||
117 | if (!set_callback_status.isOk()) { | ||
118 | LOG(ERROR) << "Unable to set event callback for Offload HAL"; | ||
119 | return false; | ||
120 | } | ||
121 | |||
122 | service_available_ = true; | ||
123 | return true; | ||
124 | } | ||
125 | |||
126 | bool OffloadScanManager::InitServiceIfNeeded() { | ||
127 | if (!service_available_) { | ||
128 | return InitService(); | ||
129 | } | ||
130 | return true; | ||
110 | } | 131 | } |
111 | 132 | ||
112 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { | 133 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { |
113 | if (!subscription_enabled_) { | 134 | if (!InitServiceIfNeeded() || |
114 | LOG(VERBOSE) << "Scans are not subscribed over Offload HAL"; | 135 | (getOffloadStatus() != OffloadScanManager::kNoError)) { |
115 | *reason_code = OffloadScanManager::kNotSubscribed; | 136 | *reason_code = OffloadScanManager::kNotAvailable; |
116 | return false; | 137 | return false; |
117 | } | 138 | } |
118 | if (wifi_offload_hal_ != nullptr) { | 139 | const auto& res = wifi_offload_hal_->unsubscribeScanResults(); |
119 | wifi_offload_hal_->unsubscribeScanResults(); | 140 | if (!res.isOk()) { |
120 | subscription_enabled_ = false; | 141 | *reason_code = OffloadScanManager::kTransactionFailed; |
142 | LOG(WARNING) << "unsubscribeScanResults() failed " << res.description(); | ||
143 | return false; | ||
121 | } | 144 | } |
122 | *reason_code = OffloadScanManager::kNone; | 145 | *reason_code = OffloadScanManager::kNone; |
123 | return true; | 146 | return true; |
@@ -163,7 +186,8 @@ bool OffloadScanManager::startScan( | |||
163 | const vector<vector<uint8_t>>& match_ssids, | 186 | const vector<vector<uint8_t>>& match_ssids, |
164 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, | 187 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, |
165 | OffloadScanManager::ReasonCode* reason_code) { | 188 | OffloadScanManager::ReasonCode* reason_code) { |
166 | if (getOffloadStatus() != OffloadScanManager::kNoError) { | 189 | if (!InitServiceIfNeeded() || |
190 | getOffloadStatus() != OffloadScanManager::kNoError) { | ||
167 | *reason_code = OffloadScanManager::kNotAvailable; | 191 | *reason_code = OffloadScanManager::kNotAvailable; |
168 | LOG(WARNING) << "Offload HAL scans are not available"; | 192 | LOG(WARNING) << "Offload HAL scans are not available"; |
169 | return false; | 193 | return false; |
@@ -177,11 +201,10 @@ bool OffloadScanManager::startScan( | |||
177 | return false; | 201 | return false; |
178 | } | 202 | } |
179 | 203 | ||
180 | if (!subscription_enabled_ && !SubscribeScanResults(reason_code)) { | 204 | if (!SubscribeScanResults(reason_code)) { |
181 | return false; | 205 | return false; |
182 | } | 206 | } |
183 | 207 | ||
184 | subscription_enabled_ = true; | ||
185 | *reason_code = OffloadScanManager::kNone; | 208 | *reason_code = OffloadScanManager::kNone; |
186 | return true; | 209 | return true; |
187 | } | 210 | } |
@@ -208,13 +231,25 @@ bool OffloadScanManager::SubscribeScanResults( | |||
208 | } | 231 | } |
209 | 232 | ||
210 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { | 233 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { |
211 | if (wifi_offload_hal_ == nullptr) { | 234 | if (!service_available_) { |
212 | return OffloadScanManager::kNoService; | 235 | return OffloadScanManager::kNoService; |
213 | } | 236 | } |
214 | return offload_status_; | 237 | return offload_status_; |
215 | } | 238 | } |
216 | 239 | ||
240 | bool OffloadScanManager::getScanResults( | ||
241 | std::vector<NativeScanResult>* out_scan_results) { | ||
242 | for (auto scan_result : *cached_scan_results_) { | ||
243 | out_scan_results->push_back(scan_result); | ||
244 | } | ||
245 | return true; | ||
246 | } | ||
247 | |||
217 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { | 248 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { |
249 | if (!InitServiceIfNeeded()) { | ||
250 | LOG(ERROR) << "Offload HAL service unavailable"; | ||
251 | return false; | ||
252 | } | ||
218 | if (getOffloadStatus() != OffloadScanManager::kNoError) { | 253 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
219 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; | 254 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; |
220 | return false; | 255 | return false; |
@@ -226,15 +261,22 @@ OffloadScanManager::~OffloadScanManager() { | |||
226 | if (wifi_offload_hal_ != nullptr) { | 261 | if (wifi_offload_hal_ != nullptr) { |
227 | wifi_offload_hal_->unlinkToDeath(death_recipient_); | 262 | wifi_offload_hal_->unlinkToDeath(death_recipient_); |
228 | } | 263 | } |
264 | delete cached_scan_results_; | ||
229 | } | 265 | } |
230 | 266 | ||
231 | void OffloadScanManager::ReportScanResults( | 267 | void OffloadScanManager::ReportScanResults( |
232 | const vector<ScanResult>& scanResult) { | 268 | const vector<ScanResult>& scanResult) { |
233 | if (scan_result_handler_ != nullptr) { | 269 | cached_scan_results_->clear(); |
234 | scan_result_handler_( | 270 | if (!OffloadScanUtils::convertToNativeScanResults(scanResult, |
235 | OffloadScanUtils::convertToNativeScanResults(scanResult)); | 271 | cached_scan_results_)) { |
272 | LOG(WARNING) << "Unable to convert scan results to native format"; | ||
273 | return; | ||
274 | } | ||
275 | if (event_callback_ != nullptr) { | ||
276 | event_callback_->OnOffloadScanResult(); | ||
236 | } else { | 277 | } else { |
237 | LOG(ERROR) << "No scan result handler for Offload ScanManager"; | 278 | LOG(WARNING) |
279 | << "No callback to report Offload HAL's scan results to wificond"; | ||
238 | } | 280 | } |
239 | } | 281 | } |
240 | 282 | ||
@@ -260,14 +302,29 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) { | |||
260 | } | 302 | } |
261 | if (status_result != OffloadScanManager::kNoError) { | 303 | if (status_result != OffloadScanManager::kNoError) { |
262 | LOG(WARNING) << "Offload Error reported " << status.description; | 304 | LOG(WARNING) << "Offload Error reported " << status.description; |
305 | if (event_callback_ != nullptr) { | ||
306 | event_callback_->OnOffloadError( | ||
307 | OffloadScanCallbackInterface::REMOTE_FAILURE); | ||
308 | } else { | ||
309 | LOG(WARNING) << "No callback to report Offload HAL Errors to wificond"; | ||
310 | } | ||
263 | } | 311 | } |
264 | offload_status_ = status_result; | 312 | offload_status_ = status_result; |
265 | } | 313 | } |
266 | 314 | ||
267 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { | 315 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { |
268 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { | 316 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { |
269 | wifi_offload_hal_.clear(); | ||
270 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; | 317 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; |
318 | wifi_offload_hal_.clear(); | ||
319 | if (event_callback_ != nullptr) { | ||
320 | event_callback_->OnOffloadError( | ||
321 | OffloadScanCallbackInterface::BINDER_DEATH); | ||
322 | } else { | ||
323 | LOG(WARNING) | ||
324 | << "No callback to report Offload HAL Binder death to wificond"; | ||
325 | } | ||
326 | service_available_ = false; | ||
327 | death_recipient_.clear(); | ||
271 | } | 328 | } |
272 | } | 329 | } |
273 | 330 | ||
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h index e2c2b0c..6be3ec0 100644 --- a/scanning/offload/offload_scan_manager.h +++ b/scanning/offload/offload_scan_manager.h | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <android/hardware/wifi/offload/1.0/IOffload.h> | 19 | #include <android/hardware/wifi/offload/1.0/IOffload.h> |
20 | #include "wificond/scanning/offload/offload_callback.h" | 20 | #include "wificond/scanning/offload/offload_callback.h" |
21 | #include "wificond/scanning/offload/offload_callback_handlers.h" | 21 | #include "wificond/scanning/offload/offload_callback_handlers.h" |
22 | #include "wificond/scanning/offload/offload_service_utils.h" | 22 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" |
23 | 23 | ||
24 | #include <vector> | 24 | #include <vector> |
25 | 25 | ||
@@ -42,11 +42,8 @@ namespace android { | |||
42 | namespace wificond { | 42 | namespace wificond { |
43 | 43 | ||
44 | class OffloadScanManager; | 44 | class OffloadScanManager; |
45 | 45 | class OffloadDeathRecipient; | |
46 | typedef std::function<void( | 46 | class OffloadServiceUtils; |
47 | const std::vector<::com::android::server::wifi::wificond::NativeScanResult> | ||
48 | scanResult)> | ||
49 | OnNativeScanResultsReadyHandler; | ||
50 | 47 | ||
51 | // Provides callback interface implementation from Offload HAL | 48 | // Provides callback interface implementation from Offload HAL |
52 | class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { | 49 | class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { |
@@ -86,38 +83,40 @@ class OffloadScanManager { | |||
86 | kNone, | 83 | kNone, |
87 | /* Offload HAL scans is not available */ | 84 | /* Offload HAL scans is not available */ |
88 | kNotAvailable, | 85 | kNotAvailable, |
89 | /* Offload HAL service is not subscribed to */ | ||
90 | kNotSubscribed, | ||
91 | /* Offload HAL requested operation failure */ | 86 | /* Offload HAL requested operation failure */ |
92 | kOperationFailed, | 87 | kOperationFailed, |
93 | /* Binder failed to deliver message to Offload HAL*/ | 88 | /* Binder failed to deliver message to Offload HAL*/ |
94 | kTransactionFailed, | 89 | kTransactionFailed, |
95 | }; | 90 | }; |
96 | 91 | ||
97 | explicit OffloadScanManager(std::weak_ptr<OffloadServiceUtils> utils, | 92 | explicit OffloadScanManager( |
98 | OnNativeScanResultsReadyHandler handler); | 93 | std::weak_ptr<OffloadServiceUtils> utils, |
94 | std::shared_ptr<OffloadScanCallbackInterface> callback); | ||
99 | virtual ~OffloadScanManager(); | 95 | virtual ~OffloadScanManager(); |
100 | /* Request start of offload scans with scan parameters and scan filter | 96 | /* Request start of offload scans with scan parameters and scan filter |
101 | * settings. Internally calls Offload HAL service with configureScans() | 97 | * settings. Internally calls Offload HAL service with configureScans() |
102 | * and subscribeScanResults() APIs. If already subscribed, it updates | 98 | * and subscribeScanResults() APIs. Reason code indicates failure reason. |
103 | * the scan configuration only. Reason code is updated in failure case | ||
104 | */ | 99 | */ |
105 | bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */, | 100 | virtual bool startScan( |
106 | const std::vector<std::vector<uint8_t>>& /* scan_ssids */, | 101 | uint32_t /* interval_ms */, int32_t /* rssi_threshold */, |
107 | const std::vector<std::vector<uint8_t>>& /* match_ssids */, | 102 | const std::vector<std::vector<uint8_t>>& /* scan_ssids */, |
108 | const std::vector<uint8_t>& /* match_security */, | 103 | const std::vector<std::vector<uint8_t>>& /* match_ssids */, |
109 | const std::vector<uint32_t>& /* freqs */, | 104 | const std::vector<uint8_t>& /* match_security */, |
110 | ReasonCode* /* failure reason */); | 105 | const std::vector<uint32_t>& /* freqs */, |
111 | /* Request stop of offload scans, returns true if scans were subscribed | 106 | ReasonCode* /* failure reason */); |
112 | * to from the Offload HAL service. Otherwise, returns false. Reason code | 107 | /* Request stop of offload scans, returns true if the operation succeeds |
113 | * is updated in case of failure. | 108 | * Otherwise, returns false. Reason code is updated in case of failure. |
114 | */ | 109 | */ |
115 | bool stopScan(ReasonCode* /* failure reason */); | 110 | virtual bool stopScan(ReasonCode* /* failure reason */); |
116 | /* Get statistics for scans performed by Offload HAL */ | 111 | /* Get statistics for scans performed by Offload HAL */ |
117 | bool getScanStats( | 112 | virtual bool getScanStats( |
118 | ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); | 113 | ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); |
119 | /* Otain status of the Offload HAL service */ | 114 | /* Otain status of the Offload HAL service */ |
120 | StatusCode getOffloadStatus() const; | 115 | virtual StatusCode getOffloadStatus() const; |
116 | /* Returns the most recent scan result available from Offload HAL */ | ||
117 | virtual bool getScanResults( | ||
118 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>* | ||
119 | out_scan_results); | ||
121 | 120 | ||
122 | private: | 121 | private: |
123 | void ReportScanResults( | 122 | void ReportScanResults( |
@@ -131,10 +130,15 @@ class OffloadScanManager { | |||
131 | OffloadScanManager::ReasonCode* reason_code); | 130 | OffloadScanManager::ReasonCode* reason_code); |
132 | bool GetScanStats( | 131 | bool GetScanStats( |
133 | ::com::android::server::wifi::wificond::NativeScanStats* stats); | 132 | ::com::android::server::wifi::wificond::NativeScanStats* stats); |
134 | bool SubscribeScanResults(OffloadScanManager::ReasonCode* reason_code); | 133 | bool SubscribeScanResults( |
135 | bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, | 134 | OffloadScanManager::ReasonCode* reason_code); |
136 | android::hardware::wifi::offload::V1_0::ScanFilter, | 135 | bool ConfigureScans( |
137 | OffloadScanManager::ReasonCode* reason_code); | 136 | android::hardware::wifi::offload::V1_0::ScanParam, |
137 | android::hardware::wifi::offload::V1_0::ScanFilter, | ||
138 | OffloadScanManager::ReasonCode* reason_code); | ||
139 | bool InitServiceIfNeeded(); | ||
140 | bool InitService(); | ||
141 | |||
138 | /* Handle binder death */ | 142 | /* Handle binder death */ |
139 | void OnObjectDeath(uint64_t /* cookie */); | 143 | void OnObjectDeath(uint64_t /* cookie */); |
140 | 144 | ||
@@ -143,10 +147,13 @@ class OffloadScanManager { | |||
143 | android::sp<OffloadCallback> wifi_offload_callback_; | 147 | android::sp<OffloadCallback> wifi_offload_callback_; |
144 | android::sp<OffloadDeathRecipient> death_recipient_; | 148 | android::sp<OffloadDeathRecipient> death_recipient_; |
145 | StatusCode offload_status_; | 149 | StatusCode offload_status_; |
146 | bool subscription_enabled_; | 150 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>* |
151 | cached_scan_results_; | ||
152 | bool service_available_; | ||
147 | 153 | ||
148 | const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; | 154 | const std::weak_ptr<OffloadServiceUtils> offload_service_utils_; |
149 | OnNativeScanResultsReadyHandler scan_result_handler_; | 155 | const std::shared_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; |
156 | std::shared_ptr<OffloadScanCallbackInterface> event_callback_; | ||
150 | 157 | ||
151 | friend class OffloadCallbackHandlersImpl; | 158 | friend class OffloadCallbackHandlersImpl; |
152 | }; | 159 | }; |
diff --git a/scanning/offload/offload_scan_utils.cpp b/scanning/offload/offload_scan_utils.cpp index 9127632..1446f76 100644 --- a/scanning/offload/offload_scan_utils.cpp +++ b/scanning/offload/offload_scan_utils.cpp | |||
@@ -16,6 +16,7 @@ | |||
16 | #include "wificond/scanning/offload/offload_scan_utils.h" | 16 | #include "wificond/scanning/offload/offload_scan_utils.h" |
17 | 17 | ||
18 | #include <android-base/logging.h> | 18 | #include <android-base/logging.h> |
19 | #include <utils/Timers.h> | ||
19 | 20 | ||
20 | #include "wificond/scanning/offload/scan_stats.h" | 21 | #include "wificond/scanning/offload/scan_stats.h" |
21 | #include "wificond/scanning/scan_result.h" | 22 | #include "wificond/scanning/scan_result.h" |
@@ -33,23 +34,25 @@ using std::vector; | |||
33 | namespace android { | 34 | namespace android { |
34 | namespace wificond { | 35 | namespace wificond { |
35 | 36 | ||
36 | vector<NativeScanResult> OffloadScanUtils::convertToNativeScanResults( | 37 | bool OffloadScanUtils::convertToNativeScanResults( |
37 | const vector<ScanResult>& scan_result) { | 38 | const vector<ScanResult>& scan_result, |
38 | vector<NativeScanResult> native_scan_result; | 39 | vector<NativeScanResult>* native_scan_result) { |
39 | native_scan_result.reserve(scan_result.size()); | 40 | if (native_scan_result == nullptr) return false; |
40 | for (size_t i = 0; i < scan_result.size(); i++) { | 41 | for (size_t i = 0; i < scan_result.size(); i++) { |
41 | NativeScanResult single_scan_result; | 42 | NativeScanResult single_scan_result; |
42 | single_scan_result.ssid = scan_result[i].networkInfo.ssid; | 43 | single_scan_result.ssid.assign(scan_result[i].networkInfo.ssid.begin(), |
43 | single_scan_result.bssid.assign(scan_result[i].networkInfo.ssid.begin(), | 44 | scan_result[i].networkInfo.ssid.end()); |
44 | scan_result[i].networkInfo.ssid.end()); | 45 | for (size_t j = 0; j < scan_result[i].bssid.elementCount(); j++) { |
46 | single_scan_result.bssid.push_back(scan_result[i].bssid[j]); | ||
47 | } | ||
45 | single_scan_result.frequency = scan_result[i].frequency; | 48 | single_scan_result.frequency = scan_result[i].frequency; |
46 | single_scan_result.signal_mbm = scan_result[i].rssi; | 49 | single_scan_result.signal_mbm = scan_result[i].rssi; |
47 | single_scan_result.tsf = scan_result[i].tsf; | 50 | single_scan_result.tsf = systemTime(SYSTEM_TIME_MONOTONIC) / 1000; |
48 | single_scan_result.capability = scan_result[i].capability; | 51 | single_scan_result.capability = scan_result[i].capability; |
49 | single_scan_result.associated = false; | 52 | single_scan_result.associated = false; |
50 | native_scan_result.emplace_back(single_scan_result); | 53 | native_scan_result->push_back(std::move(single_scan_result)); |
51 | } | 54 | } |
52 | return native_scan_result; | 55 | return true; |
53 | } | 56 | } |
54 | 57 | ||
55 | ScanParam OffloadScanUtils::createScanParam( | 58 | ScanParam OffloadScanUtils::createScanParam( |
diff --git a/scanning/offload/offload_scan_utils.h b/scanning/offload/offload_scan_utils.h index ce4afa7..22ba8ea 100644 --- a/scanning/offload/offload_scan_utils.h +++ b/scanning/offload/offload_scan_utils.h | |||
@@ -42,9 +42,9 @@ namespace wificond { | |||
42 | // Provides utility methods for Offload Scan Manager | 42 | // Provides utility methods for Offload Scan Manager |
43 | class OffloadScanUtils { | 43 | class OffloadScanUtils { |
44 | public: | 44 | public: |
45 | static std::vector<::com::android::server::wifi::wificond::NativeScanResult> | 45 | static bool convertToNativeScanResults( |
46 | convertToNativeScanResults( | 46 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&, |
47 | const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&); | 47 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>*); |
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); |
diff --git a/scanning/offload/offload_service_utils.cpp b/scanning/offload/offload_service_utils.cpp index 2a14a32..ce25d85 100644 --- a/scanning/offload/offload_service_utils.cpp +++ b/scanning/offload/offload_service_utils.cpp | |||
@@ -14,7 +14,11 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | #include "wificond/scanning/offload/offload_service_utils.h" | 16 | #include "wificond/scanning/offload/offload_service_utils.h" |
17 | |||
18 | #include <android-base/logging.h> | ||
19 | |||
17 | #include "wificond/scanning/offload/offload_scan_manager.h" | 20 | #include "wificond/scanning/offload/offload_scan_manager.h" |
21 | #include "wificond/scanning/scanner_impl.h" | ||
18 | 22 | ||
19 | using ::android::hardware::wifi::offload::V1_0::IOffload; | 23 | using ::android::hardware::wifi::offload::V1_0::IOffload; |
20 | 24 | ||
@@ -22,7 +26,7 @@ namespace android { | |||
22 | namespace wificond { | 26 | namespace wificond { |
23 | 27 | ||
24 | android::sp<IOffload> OffloadServiceUtils::GetOffloadService() { | 28 | android::sp<IOffload> OffloadServiceUtils::GetOffloadService() { |
25 | return IOffload::getService(); | 29 | return IOffload::tryGetService(); |
26 | } | 30 | } |
27 | 31 | ||
28 | android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback( | 32 | android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback( |
@@ -36,12 +40,18 @@ OffloadDeathRecipient* OffloadServiceUtils::GetOffloadDeathRecipient( | |||
36 | } | 40 | } |
37 | 41 | ||
38 | bool OffloadServiceUtils::IsOffloadScanSupported() const { | 42 | bool OffloadServiceUtils::IsOffloadScanSupported() const { |
39 | bool result = false; | 43 | return false; |
40 | #ifdef WIFI_OFFLOAD_SCANS | 44 | } |
41 | LOG(VERBOSE) << "Offload HAL supported"; | 45 | |
42 | result = true; | 46 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> |
43 | #endif | 47 | OffloadServiceUtils::GetOffloadScanCallbackInterface(ScannerImpl* parent) { |
44 | return result; | 48 | return std::make_shared<OffloadScanCallbackInterfaceImpl>(parent); |
49 | } | ||
50 | |||
51 | std::shared_ptr<OffloadScanManager> OffloadServiceUtils::GetOffloadScanManager( | ||
52 | std::weak_ptr<OffloadServiceUtils> service_utils, | ||
53 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> callback_interface) { | ||
54 | return std::make_shared<OffloadScanManager>(service_utils, callback_interface); | ||
45 | } | 55 | } |
46 | 56 | ||
47 | OffloadDeathRecipient::OffloadDeathRecipient( | 57 | OffloadDeathRecipient::OffloadDeathRecipient( |
diff --git a/scanning/offload/offload_service_utils.h b/scanning/offload/offload_service_utils.h index cff5575..42268de 100644 --- a/scanning/offload/offload_service_utils.h +++ b/scanning/offload/offload_service_utils.h | |||
@@ -19,11 +19,15 @@ | |||
19 | #include <android/hardware/wifi/offload/1.0/IOffload.h> | 19 | #include <android/hardware/wifi/offload/1.0/IOffload.h> |
20 | #include "wificond/scanning/offload/offload_callback.h" | 20 | #include "wificond/scanning/offload/offload_callback.h" |
21 | #include "wificond/scanning/offload/offload_callback_handlers.h" | 21 | #include "wificond/scanning/offload/offload_callback_handlers.h" |
22 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
22 | 23 | ||
23 | namespace android { | 24 | namespace android { |
24 | namespace wificond { | 25 | namespace wificond { |
25 | 26 | ||
26 | typedef std::function<void(uint64_t)> OffloadDeathRecipientHandler; | 27 | typedef std::function<void(uint64_t)> OffloadDeathRecipientHandler; |
28 | class ScannerImpl; | ||
29 | class OffloadServiceUtils; | ||
30 | class OffloadScanManager; | ||
27 | 31 | ||
28 | class OffloadDeathRecipient : public android::hardware::hidl_death_recipient { | 32 | class OffloadDeathRecipient : public android::hardware::hidl_death_recipient { |
29 | public: | 33 | public: |
@@ -52,6 +56,11 @@ class OffloadServiceUtils { | |||
52 | OffloadCallbackHandlers* handlers); | 56 | OffloadCallbackHandlers* handlers); |
53 | virtual OffloadDeathRecipient* GetOffloadDeathRecipient( | 57 | virtual OffloadDeathRecipient* GetOffloadDeathRecipient( |
54 | OffloadDeathRecipientHandler handler); | 58 | OffloadDeathRecipientHandler handler); |
59 | virtual std::shared_ptr<OffloadScanCallbackInterfaceImpl> | ||
60 | GetOffloadScanCallbackInterface(ScannerImpl* parent); | ||
61 | virtual std::shared_ptr<OffloadScanManager> GetOffloadScanManager( | ||
62 | std::weak_ptr<OffloadServiceUtils> service_utils, | ||
63 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> callback_interface); | ||
55 | }; | 64 | }; |
56 | 65 | ||
57 | } // namespace wificond | 66 | } // namespace wificond |
diff --git a/scanning/offload/scan_stats.cpp b/scanning/offload/scan_stats.cpp index 4a963cb..bd5c793 100644 --- a/scanning/offload/scan_stats.cpp +++ b/scanning/offload/scan_stats.cpp | |||
@@ -46,6 +46,7 @@ NativeScanStats::NativeScanStats() | |||
46 | : num_scans_requested_by_wifi_(0), | 46 | : num_scans_requested_by_wifi_(0), |
47 | num_scans_serviced_by_wifi_(0), | 47 | num_scans_serviced_by_wifi_(0), |
48 | subscription_duration_ms_(0), | 48 | subscription_duration_ms_(0), |
49 | scan_duration_ms_(0), | ||
49 | num_channels_scanned_(0), | 50 | num_channels_scanned_(0), |
50 | time_stamp_(0) {} | 51 | time_stamp_(0) {} |
51 | 52 | ||
@@ -87,6 +88,20 @@ status_t NativeScanStats::readFromParcel(const ::android::Parcel* parcel) { | |||
87 | return ::android::OK; | 88 | return ::android::OK; |
88 | } | 89 | } |
89 | 90 | ||
91 | void NativeScanStats::DebugLog() { | ||
92 | LOG(INFO) << "num_scans_requested_by_wifi=" << num_scans_requested_by_wifi_; | ||
93 | LOG(INFO) << "num_scans_serviced_by_wifi=" << num_scans_serviced_by_wifi_; | ||
94 | LOG(INFO) << "subscription_duration=" << subscription_duration_ms_; | ||
95 | LOG(INFO) << "scan_duration_ms_=" << scan_duration_ms_; | ||
96 | LOG(INFO) << "num_channels_scanned=" << num_channels_scanned_; | ||
97 | for (size_t i = 0; i < histogram_channels_.size(); i++) { | ||
98 | if (histogram_channels_[i] > 0) { | ||
99 | LOG(INFO) << "Channel=" << i << " ScannedTimes=" | ||
100 | << static_cast<uint32_t>(histogram_channels_[i]); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
90 | } // namespace wificond | 105 | } // namespace wificond |
91 | } // namespace wifi | 106 | } // namespace wifi |
92 | } // namespace server | 107 | } // namespace server |
diff --git a/scanning/offload/scan_stats.h b/scanning/offload/scan_stats.h index eb1d16a..05220b9 100644 --- a/scanning/offload/scan_stats.h +++ b/scanning/offload/scan_stats.h | |||
@@ -40,6 +40,7 @@ class NativeScanStats : public ::android::Parcelable { | |||
40 | bool operator==(const NativeScanStats&) const; | 40 | bool operator==(const NativeScanStats&) const; |
41 | ::android::status_t writeToParcel(::android::Parcel* parcel) const override; | 41 | ::android::status_t writeToParcel(::android::Parcel* parcel) const override; |
42 | ::android::status_t readFromParcel(const ::android::Parcel* parcel) override; | 42 | ::android::status_t readFromParcel(const ::android::Parcel* parcel) override; |
43 | void DebugLog(); | ||
43 | 44 | ||
44 | uint32_t num_scans_requested_by_wifi_; | 45 | uint32_t num_scans_requested_by_wifi_; |
45 | uint32_t num_scans_serviced_by_wifi_; | 46 | uint32_t num_scans_serviced_by_wifi_; |
diff --git a/scanning/offload_scan_callback_interface.h b/scanning/offload_scan_callback_interface.h new file mode 100644 index 0000000..507a69f --- /dev/null +++ b/scanning/offload_scan_callback_interface.h | |||
@@ -0,0 +1,42 @@ | |||
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 | #ifndef ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
17 | #define ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
18 | |||
19 | #include <vector> | ||
20 | |||
21 | #include "wificond/scanning/scan_result.h" | ||
22 | |||
23 | namespace android { | ||
24 | namespace wificond { | ||
25 | |||
26 | class OffloadScanCallbackInterface { | ||
27 | public: | ||
28 | enum AsyncErrorReason { | ||
29 | BINDER_DEATH = 0, | ||
30 | REMOTE_FAILURE, | ||
31 | }; | ||
32 | |||
33 | virtual ~OffloadScanCallbackInterface() {} | ||
34 | |||
35 | virtual void OnOffloadScanResult() = 0; | ||
36 | virtual void OnOffloadError(AsyncErrorReason) = 0; | ||
37 | }; | ||
38 | |||
39 | } // namespace wificond | ||
40 | } // namespace android | ||
41 | |||
42 | #endif // ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
diff --git a/scanning/offload_scan_callback_interface_impl.cpp b/scanning/offload_scan_callback_interface_impl.cpp new file mode 100644 index 0000000..a3e39da --- /dev/null +++ b/scanning/offload_scan_callback_interface_impl.cpp | |||
@@ -0,0 +1,42 @@ | |||
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 "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
18 | |||
19 | #include <android-base/logging.h> | ||
20 | |||
21 | using com::android::server::wifi::wificond::NativeScanResult; | ||
22 | |||
23 | namespace android { | ||
24 | namespace wificond { | ||
25 | |||
26 | OffloadScanCallbackInterfaceImpl::OffloadScanCallbackInterfaceImpl( | ||
27 | ScannerImpl* parent) | ||
28 | : scanner_impl_(parent) {} | ||
29 | |||
30 | OffloadScanCallbackInterfaceImpl::~OffloadScanCallbackInterfaceImpl() {} | ||
31 | |||
32 | void OffloadScanCallbackInterfaceImpl::OnOffloadScanResult() { | ||
33 | scanner_impl_->OnOffloadScanResult(); | ||
34 | } | ||
35 | |||
36 | void OffloadScanCallbackInterfaceImpl::OnOffloadError( | ||
37 | OffloadScanCallbackInterface::AsyncErrorReason error_code) { | ||
38 | scanner_impl_->OnOffloadError(error_code); | ||
39 | } | ||
40 | |||
41 | } // namespace wificond | ||
42 | } // namespace android | ||
diff --git a/rtt/rtt_controller_binder.h b/scanning/offload_scan_callback_interface_impl.h index ed8ce81..0f500a4 100644 --- a/rtt/rtt_controller_binder.h +++ b/scanning/offload_scan_callback_interface_impl.h | |||
@@ -14,36 +14,31 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef WIFICOND_RTT_CONTROLLER_BINDER_H_ | 17 | #ifndef WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ |
18 | #define WIFICOND_RTT_CONTROLLER_BINDER_H_ | 18 | #define WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ |
19 | 19 | ||
20 | #include <android-base/macros.h> | 20 | #include "wificond/scanning/offload_scan_callback_interface.h" |
21 | #include <binder/Status.h> | 21 | #include "wificond/scanning/scanner_impl.h" |
22 | |||
23 | #include "android/net/wifi/BnRttController.h" | ||
24 | 22 | ||
25 | namespace android { | 23 | namespace android { |
26 | namespace wificond { | 24 | namespace wificond { |
27 | 25 | ||
28 | class RttControllerImpl; | 26 | class ScannerImpl; |
29 | 27 | ||
30 | class RttControllerBinder : public android::net::wifi::BnRttController { | 28 | class OffloadScanCallbackInterfaceImpl |
29 | : public android::wificond::OffloadScanCallbackInterface { | ||
31 | public: | 30 | public: |
32 | explicit RttControllerBinder(RttControllerImpl* impl); | 31 | OffloadScanCallbackInterfaceImpl(ScannerImpl* parent); |
33 | ~RttControllerBinder() override; | 32 | ~OffloadScanCallbackInterfaceImpl() override; |
34 | 33 | ||
35 | // Called by |impl_| its destruction. | 34 | void OnOffloadScanResult() override; |
36 | // This informs the binder proxy that no future manipulations of |impl_| | 35 | void OnOffloadError(OffloadScanCallbackInterface::AsyncErrorReason) override; |
37 | // by remote processes are possible. | ||
38 | void NotifyImplDead() { impl_ = nullptr; } | ||
39 | 36 | ||
40 | private: | 37 | private: |
41 | RttControllerImpl* impl_; | 38 | ScannerImpl* scanner_impl_; |
42 | |||
43 | DISALLOW_COPY_AND_ASSIGN(RttControllerBinder); | ||
44 | }; | 39 | }; |
45 | 40 | ||
46 | } // namespace wificond | 41 | } // namespace wificond |
47 | } // namespace android | 42 | } // namespace android |
48 | 43 | ||
49 | #endif // WIFICOND_RTT_CONTROLLER_BINDER_H_ | 44 | #endif // WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ |
diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp index 9bf13b3..0f6ab52 100644 --- a/scanning/scanner_impl.cpp +++ b/scanning/scanner_impl.cpp | |||
@@ -22,9 +22,9 @@ | |||
22 | #include <android-base/logging.h> | 22 | #include <android-base/logging.h> |
23 | 23 | ||
24 | #include "wificond/client_interface_impl.h" | 24 | #include "wificond/client_interface_impl.h" |
25 | #include "wificond/scanning/scan_utils.h" | ||
26 | #include "wificond/scanning/offload/offload_service_utils.h" | ||
27 | #include "wificond/scanning/offload/offload_scan_manager.h" | 25 | #include "wificond/scanning/offload/offload_scan_manager.h" |
26 | #include "wificond/scanning/offload/offload_service_utils.h" | ||
27 | #include "wificond/scanning/scan_utils.h" | ||
28 | 28 | ||
29 | using android::binder::Status; | 29 | using android::binder::Status; |
30 | using android::net::wifi::IPnoScanEvent; | 30 | using android::net::wifi::IPnoScanEvent; |
@@ -39,24 +39,25 @@ using std::pair; | |||
39 | using std::string; | 39 | using std::string; |
40 | using std::vector; | 40 | using std::vector; |
41 | using std::weak_ptr; | 41 | using std::weak_ptr; |
42 | using std::shared_ptr; | ||
42 | 43 | ||
43 | using namespace std::placeholders; | 44 | using namespace std::placeholders; |
44 | 45 | ||
45 | namespace android { | 46 | namespace android { |
46 | namespace wificond { | 47 | namespace wificond { |
47 | 48 | ||
48 | ScannerImpl::ScannerImpl(uint32_t wiphy_index, | 49 | ScannerImpl::ScannerImpl(uint32_t wiphy_index, uint32_t interface_index, |
49 | uint32_t interface_index, | ||
50 | const ScanCapabilities& scan_capabilities, | 50 | const ScanCapabilities& scan_capabilities, |
51 | const WiphyFeatures& wiphy_features, | 51 | const WiphyFeatures& wiphy_features, |
52 | ClientInterfaceImpl* client_interface, | 52 | ClientInterfaceImpl* client_interface, |
53 | NetlinkUtils* netlink_utils, | 53 | NetlinkUtils* netlink_utils, ScanUtils* scan_utils, |
54 | ScanUtils* scan_utils, | ||
55 | weak_ptr<OffloadServiceUtils> offload_service_utils) | 54 | weak_ptr<OffloadServiceUtils> offload_service_utils) |
56 | : valid_(true), | 55 | : valid_(true), |
57 | scan_started_(false), | 56 | scan_started_(false), |
58 | pno_scan_started_(false), | 57 | pno_scan_started_(false), |
59 | offload_scan_supported_(false), | 58 | offload_scan_supported_(false), |
59 | pno_scan_running_over_offload_(false), | ||
60 | pno_scan_results_from_offload_(false), | ||
60 | wiphy_index_(wiphy_index), | 61 | wiphy_index_(wiphy_index), |
61 | interface_index_(interface_index), | 62 | interface_index_(interface_index), |
62 | scan_capabilities_(scan_capabilities), | 63 | scan_capabilities_(scan_capabilities), |
@@ -70,25 +71,22 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index, | |||
70 | << (int)interface_index_; | 71 | << (int)interface_index_; |
71 | scan_utils_->SubscribeScanResultNotification( | 72 | scan_utils_->SubscribeScanResultNotification( |
72 | interface_index_, | 73 | interface_index_, |
73 | std::bind(&ScannerImpl::OnScanResultsReady, | 74 | std::bind(&ScannerImpl::OnScanResultsReady, this, _1, _2, _3, _4)); |
74 | this, | ||
75 | _1, _2, _3, _4)); | ||
76 | // Subscribe scheduled scan result notification from kernel. | 75 | // Subscribe scheduled scan result notification from kernel. |
77 | scan_utils_->SubscribeSchedScanResultNotification( | 76 | scan_utils_->SubscribeSchedScanResultNotification( |
78 | interface_index_, | 77 | interface_index_, |
79 | std::bind(&ScannerImpl::OnSchedScanResultsReady, | 78 | std::bind(&ScannerImpl::OnSchedScanResultsReady, |
80 | this, | 79 | this, |
81 | _1, _2)); | 80 | _1, _2)); |
82 | offload_scan_manager_.reset( | 81 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> |
83 | new OffloadScanManager( | 82 | offload_scan_callback_interface = |
84 | offload_service_utils, | 83 | offload_service_utils.lock()->GetOffloadScanCallbackInterface(this); |
85 | std::bind(&ScannerImpl::OnOffloadScanResult, | 84 | offload_scan_manager_ = offload_service_utils.lock()->GetOffloadScanManager( |
86 | this, _1))); | 85 | offload_service_utils, offload_scan_callback_interface); |
87 | offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported(); | 86 | offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported(); |
88 | } | 87 | } |
89 | 88 | ||
90 | ScannerImpl::~ScannerImpl() { | 89 | ScannerImpl::~ScannerImpl() {} |
91 | } | ||
92 | 90 | ||
93 | void ScannerImpl::Invalidate() { | 91 | void ScannerImpl::Invalidate() { |
94 | LOG(INFO) << "Unsubscribe scan result for interface with index: " | 92 | LOG(INFO) << "Unsubscribe scan result for interface with index: " |
@@ -111,17 +109,15 @@ Status ScannerImpl::getAvailable2gChannels( | |||
111 | return Status::ok(); | 109 | return Status::ok(); |
112 | } | 110 | } |
113 | BandInfo band_info; | 111 | BandInfo band_info; |
114 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 112 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
115 | &band_info, | 113 | &scan_capabilities_, &wiphy_features_)) { |
116 | &scan_capabilities_, | ||
117 | &wiphy_features_)) { | ||
118 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 114 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
119 | out_frequencies->reset(nullptr); | 115 | out_frequencies->reset(nullptr); |
120 | return Status::ok(); | 116 | return Status::ok(); |
121 | } | 117 | } |
122 | 118 | ||
123 | out_frequencies->reset(new vector<int32_t>(band_info.band_2g.begin(), | 119 | out_frequencies->reset( |
124 | band_info.band_2g.end())); | 120 | new vector<int32_t>(band_info.band_2g.begin(), band_info.band_2g.end())); |
125 | return Status::ok(); | 121 | return Status::ok(); |
126 | } | 122 | } |
127 | 123 | ||
@@ -131,17 +127,15 @@ Status ScannerImpl::getAvailable5gNonDFSChannels( | |||
131 | return Status::ok(); | 127 | return Status::ok(); |
132 | } | 128 | } |
133 | BandInfo band_info; | 129 | BandInfo band_info; |
134 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 130 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
135 | &band_info, | 131 | &scan_capabilities_, &wiphy_features_)) { |
136 | &scan_capabilities_, | ||
137 | &wiphy_features_)) { | ||
138 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 132 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
139 | out_frequencies->reset(nullptr); | 133 | out_frequencies->reset(nullptr); |
140 | return Status::ok(); | 134 | return Status::ok(); |
141 | } | 135 | } |
142 | 136 | ||
143 | out_frequencies->reset(new vector<int32_t>(band_info.band_5g.begin(), | 137 | out_frequencies->reset( |
144 | band_info.band_5g.end())); | 138 | new vector<int32_t>(band_info.band_5g.begin(), band_info.band_5g.end())); |
145 | return Status::ok(); | 139 | return Status::ok(); |
146 | } | 140 | } |
147 | 141 | ||
@@ -151,10 +145,8 @@ Status ScannerImpl::getAvailableDFSChannels( | |||
151 | return Status::ok(); | 145 | return Status::ok(); |
152 | } | 146 | } |
153 | BandInfo band_info; | 147 | BandInfo band_info; |
154 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 148 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
155 | &band_info, | 149 | &scan_capabilities_, &wiphy_features_)) { |
156 | &scan_capabilities_, | ||
157 | &wiphy_features_)) { | ||
158 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 150 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
159 | out_frequencies->reset(nullptr); | 151 | out_frequencies->reset(nullptr); |
160 | return Status::ok(); | 152 | return Status::ok(); |
@@ -175,6 +167,23 @@ Status ScannerImpl::getScanResults(vector<NativeScanResult>* out_scan_results) { | |||
175 | return Status::ok(); | 167 | return Status::ok(); |
176 | } | 168 | } |
177 | 169 | ||
170 | Status ScannerImpl::getPnoScanResults( | ||
171 | vector<NativeScanResult>* out_scan_results) { | ||
172 | if (!CheckIsValid()) { | ||
173 | return Status::ok(); | ||
174 | } | ||
175 | if (pno_scan_results_from_offload_) { | ||
176 | if (!offload_scan_manager_->getScanResults(out_scan_results)) { | ||
177 | LOG(ERROR) << "Failed to get scan results via Offload HAL"; | ||
178 | } | ||
179 | } else { | ||
180 | if (!scan_utils_->GetScanResult(interface_index_, out_scan_results)) { | ||
181 | LOG(ERROR) << "Failed to get scan results via NL80211"; | ||
182 | } | ||
183 | } | ||
184 | return Status::ok(); | ||
185 | } | ||
186 | |||
178 | Status ScannerImpl::scan(const SingleScanSettings& scan_settings, | 187 | Status ScannerImpl::scan(const SingleScanSettings& scan_settings, |
179 | bool* out_success) { | 188 | bool* out_success) { |
180 | if (!CheckIsValid()) { | 189 | if (!CheckIsValid()) { |
@@ -186,8 +195,8 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings, | |||
186 | LOG(WARNING) << "Scan already started"; | 195 | LOG(WARNING) << "Scan already started"; |
187 | } | 196 | } |
188 | // Only request MAC address randomization when station is not associated. | 197 | // Only request MAC address randomization when station is not associated. |
189 | bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan && | 198 | bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan && |
190 | !client_interface_->IsAssociated(); | 199 | !client_interface_->IsAssociated(); |
191 | 200 | ||
192 | // Initialize it with an empty ssid for a wild card scan. | 201 | // Initialize it with an empty ssid for a wild card scan. |
193 | vector<vector<uint8_t>> ssids = {{}}; | 202 | vector<vector<uint8_t>> ssids = {{}}; |
@@ -222,11 +231,14 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings, | |||
222 | 231 | ||
223 | Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings, | 232 | Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings, |
224 | bool* out_success) { | 233 | bool* out_success) { |
225 | if (!offload_scan_supported_ || !StartPnoScanOffload(pno_settings)) { | 234 | pno_settings_ = pno_settings; |
226 | *out_success = StartPnoScanDefault(pno_settings); | 235 | pno_scan_results_from_offload_ = false; |
227 | } else { | 236 | LOG(VERBOSE) << "startPnoScan"; |
237 | if (offload_scan_supported_ && StartPnoScanOffload(pno_settings)) { | ||
228 | // scanning over offload succeeded | 238 | // scanning over offload succeeded |
229 | *out_success = true; | 239 | *out_success = true; |
240 | } else { | ||
241 | *out_success = StartPnoScanDefault(pno_settings); | ||
230 | } | 242 | } |
231 | return Status::ok(); | 243 | return Status::ok(); |
232 | } | 244 | } |
@@ -239,25 +251,27 @@ bool ScannerImpl::StartPnoScanOffload(const PnoSettings& pno_settings) { | |||
239 | // Empty frequency list: scan all frequencies. | 251 | // Empty frequency list: scan all frequencies. |
240 | vector<uint32_t> freqs; | 252 | vector<uint32_t> freqs; |
241 | 253 | ||
242 | ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, &match_security); | 254 | ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, |
243 | 255 | &match_security); | |
244 | bool success = offload_scan_manager_->startScan( | 256 | pno_scan_running_over_offload_ = offload_scan_manager_->startScan( |
245 | pno_settings.interval_ms_, | 257 | pno_settings.interval_ms_, |
246 | // TODO: honor both rssi thresholds. | 258 | // TODO: honor both rssi thresholds. |
247 | pno_settings.min_5g_rssi_, | 259 | pno_settings.min_5g_rssi_, scan_ssids, match_ssids, match_security, freqs, |
248 | scan_ssids, | 260 | &reason_code); |
249 | match_ssids, | 261 | if (pno_scan_running_over_offload_) { |
250 | match_security, | 262 | LOG(VERBOSE) << "Pno scans requested over Offload HAL"; |
251 | freqs, | 263 | if (pno_scan_event_handler_ != nullptr) { |
252 | &reason_code); | 264 | pno_scan_event_handler_->OnPnoScanOverOffloadStarted(); |
253 | return success; | 265 | } |
266 | } | ||
267 | return pno_scan_running_over_offload_; | ||
254 | } | 268 | } |
255 | 269 | ||
256 | void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | 270 | void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, |
257 | vector<vector<uint8_t>>* scan_ssids, | 271 | vector<vector<uint8_t>>* scan_ssids, |
258 | vector<vector<uint8_t>>* match_ssids, | 272 | vector<vector<uint8_t>>* match_ssids, |
259 | vector<uint32_t>* freqs, | 273 | vector<uint32_t>* freqs, |
260 | vector<uint8_t>* match_security) { | 274 | vector<uint8_t>* match_security) { |
261 | // TODO provide actionable security match parameters | 275 | // TODO provide actionable security match parameters |
262 | const uint8_t kNetworkFlagsDefault = 0; | 276 | const uint8_t kNetworkFlagsDefault = 0; |
263 | vector<vector<uint8_t>> skipped_scan_ssids; | 277 | vector<vector<uint8_t>> skipped_scan_ssids; |
@@ -266,7 +280,8 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | |||
266 | // Add hidden network ssid. | 280 | // Add hidden network ssid. |
267 | if (network.is_hidden_) { | 281 | if (network.is_hidden_) { |
268 | // TODO remove pruning for Offload Scans | 282 | // TODO remove pruning for Offload Scans |
269 | if (scan_ssids->size() + 1 > scan_capabilities_.max_num_sched_scan_ssids) { | 283 | if (scan_ssids->size() + 1 > |
284 | scan_capabilities_.max_num_sched_scan_ssids) { | ||
270 | skipped_scan_ssids.emplace_back(network.ssid_); | 285 | skipped_scan_ssids.emplace_back(network.ssid_); |
271 | continue; | 286 | continue; |
272 | } | 287 | } |
@@ -287,7 +302,7 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | |||
287 | 302 | ||
288 | bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { | 303 | bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { |
289 | if (!CheckIsValid()) { | 304 | if (!CheckIsValid()) { |
290 | return false; | 305 | return false; |
291 | } | 306 | } |
292 | if (pno_scan_started_) { | 307 | if (pno_scan_started_) { |
293 | LOG(WARNING) << "Pno scan already started"; | 308 | LOG(WARNING) << "Pno scan already started"; |
@@ -324,18 +339,27 @@ bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { | |||
324 | } | 339 | } |
325 | 340 | ||
326 | Status ScannerImpl::stopPnoScan(bool* out_success) { | 341 | Status ScannerImpl::stopPnoScan(bool* out_success) { |
327 | if (!offload_scan_supported_ || !StopPnoScanOffload()) { | 342 | if (offload_scan_supported_ && StopPnoScanOffload()) { |
328 | *out_success = StopPnoScanDefault(); | ||
329 | } else { | ||
330 | // Pno scans over offload stopped successfully | 343 | // Pno scans over offload stopped successfully |
331 | *out_success = true; | 344 | *out_success = true; |
345 | } else { | ||
346 | // Pno scans were not requested over offload | ||
347 | *out_success = StopPnoScanDefault(); | ||
332 | } | 348 | } |
333 | return Status::ok(); | 349 | return Status::ok(); |
334 | } | 350 | } |
335 | 351 | ||
336 | bool ScannerImpl::StopPnoScanOffload() { | 352 | bool ScannerImpl::StopPnoScanOffload() { |
337 | OffloadScanManager::ReasonCode reason_code; | 353 | OffloadScanManager::ReasonCode reason_code; |
338 | return(offload_scan_manager_->stopScan(&reason_code)); | 354 | if (!pno_scan_running_over_offload_) { |
355 | return false; | ||
356 | } | ||
357 | if (!offload_scan_manager_->stopScan(&reason_code)) { | ||
358 | LOG(WARNING) << "Unable to unsubscribe to Offload scan results"; | ||
359 | } | ||
360 | pno_scan_running_over_offload_ = false; | ||
361 | LOG(VERBOSE) << "Pno scans over Offload stopped"; | ||
362 | return true; | ||
339 | } | 363 | } |
340 | 364 | ||
341 | bool ScannerImpl::StopPnoScanDefault() { | 365 | bool ScannerImpl::StopPnoScanDefault() { |
@@ -387,7 +411,6 @@ Status ScannerImpl::unsubscribeScanEvents() { | |||
387 | return Status::ok(); | 411 | return Status::ok(); |
388 | } | 412 | } |
389 | 413 | ||
390 | |||
391 | Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) { | 414 | Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) { |
392 | if (!CheckIsValid()) { | 415 | if (!CheckIsValid()) { |
393 | return Status::ok(); | 416 | return Status::ok(); |
@@ -407,11 +430,9 @@ Status ScannerImpl::unsubscribePnoScanEvents() { | |||
407 | return Status::ok(); | 430 | return Status::ok(); |
408 | } | 431 | } |
409 | 432 | ||
410 | void ScannerImpl::OnScanResultsReady( | 433 | void ScannerImpl::OnScanResultsReady(uint32_t interface_index, bool aborted, |
411 | uint32_t interface_index, | 434 | vector<vector<uint8_t>>& ssids, |
412 | bool aborted, | 435 | vector<uint32_t>& frequencies) { |
413 | vector<vector<uint8_t>>& ssids, | ||
414 | vector<uint32_t>& frequencies) { | ||
415 | if (!scan_started_) { | 436 | if (!scan_started_) { |
416 | LOG(INFO) << "Received external scan result notification from kernel."; | 437 | LOG(INFO) << "Received external scan result notification from kernel."; |
417 | } | 438 | } |
@@ -443,6 +464,7 @@ void ScannerImpl::OnSchedScanResultsReady(uint32_t interface_index, | |||
443 | pno_scan_started_ = false; | 464 | pno_scan_started_ = false; |
444 | } else { | 465 | } else { |
445 | LOG(INFO) << "Pno scan result ready event"; | 466 | LOG(INFO) << "Pno scan result ready event"; |
467 | pno_scan_results_from_offload_ = false; | ||
446 | pno_scan_event_handler_->OnPnoNetworkFound(); | 468 | pno_scan_event_handler_->OnPnoNetworkFound(); |
447 | } | 469 | } |
448 | } | 470 | } |
@@ -476,6 +498,62 @@ SchedScanIntervalSetting ScannerImpl::GenerateIntervalSetting( | |||
476 | } | 498 | } |
477 | } | 499 | } |
478 | 500 | ||
501 | void ScannerImpl::OnOffloadScanResult() { | ||
502 | if (!pno_scan_running_over_offload_) { | ||
503 | LOG(WARNING) << "Scan results from Offload HAL but scan not requested over " | ||
504 | "this interface"; | ||
505 | return; | ||
506 | } | ||
507 | LOG(INFO) << "Offload Scan results received"; | ||
508 | pno_scan_results_from_offload_ = true; | ||
509 | if (pno_scan_event_handler_ != nullptr) { | ||
510 | pno_scan_event_handler_->OnPnoNetworkFound(); | ||
511 | } else { | ||
512 | LOG(WARNING) << "No scan event handler Offload Scan result"; | ||
513 | } | ||
514 | } | ||
515 | |||
516 | void ScannerImpl::OnOffloadError( | ||
517 | OffloadScanCallbackInterface::AsyncErrorReason error_code) { | ||
518 | if (!pno_scan_running_over_offload_) { | ||
519 | // Ignore irrelevant error notifications | ||
520 | LOG(WARNING) << "Offload HAL Async Error occured but Offload HAL is not " | ||
521 | "subscribed to"; | ||
522 | return; | ||
523 | } | ||
524 | LOG(ERROR) << "Offload Service Async Failure error_code=" << error_code; | ||
525 | switch (error_code) { | ||
526 | case OffloadScanCallbackInterface::AsyncErrorReason::BINDER_DEATH: | ||
527 | LOG(ERROR) << "Binder death"; | ||
528 | if (pno_scan_event_handler_ != nullptr) { | ||
529 | pno_scan_event_handler_->OnPnoScanOverOffloadFailed( | ||
530 | net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_BINDER_FAILURE); | ||
531 | } | ||
532 | break; | ||
533 | case OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE: | ||
534 | LOG(ERROR) << "Remote failure"; | ||
535 | if (pno_scan_event_handler_ != nullptr) { | ||
536 | pno_scan_event_handler_->OnPnoScanOverOffloadFailed( | ||
537 | net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_REMOTE_FAILURE); | ||
538 | } | ||
539 | break; | ||
540 | default: | ||
541 | LOG(WARNING) << "Invalid Error code"; | ||
542 | break; | ||
543 | } | ||
544 | bool success = false; | ||
545 | // Stop scans over Offload HAL and request them over netlink | ||
546 | stopPnoScan(&success); | ||
547 | if (success) { | ||
548 | LOG(INFO) << "Pno scans stopped"; | ||
549 | } | ||
550 | // Restart PNO scans over netlink interface | ||
551 | success = StartPnoScanDefault(pno_settings_); | ||
552 | if (success) { | ||
553 | LOG(INFO) << "Pno scans restarted"; | ||
554 | } | ||
555 | } | ||
556 | |||
479 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, | 557 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, |
480 | string prefix) { | 558 | string prefix) { |
481 | if (ssid_list.empty()) { | 559 | if (ssid_list.empty()) { |
@@ -491,15 +569,5 @@ void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, | |||
491 | LOG(WARNING) << prefix << ": " << ssid_list_string; | 569 | LOG(WARNING) << prefix << ": " << ssid_list_string; |
492 | } | 570 | } |
493 | 571 | ||
494 | void ScannerImpl::OnOffloadScanResult( | ||
495 | std::vector<NativeScanResult> scanResult) { | ||
496 | LOG(INFO) << "Offload Scan results received"; | ||
497 | if (pno_scan_event_handler_ != nullptr) { | ||
498 | pno_scan_event_handler_->OnPnoNetworkFound(); | ||
499 | } else { | ||
500 | LOG(WARNING) << "No scan event handler Offload Scan result"; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | } // namespace wificond | 572 | } // namespace wificond |
505 | } // namespace android | 573 | } // namespace android |
diff --git a/scanning/scanner_impl.h b/scanning/scanner_impl.h index 2bb9262..8e1f832 100644 --- a/scanning/scanner_impl.h +++ b/scanning/scanner_impl.h | |||
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "android/net/wifi/BnWifiScannerImpl.h" | 25 | #include "android/net/wifi/BnWifiScannerImpl.h" |
26 | #include "wificond/net/netlink_utils.h" | 26 | #include "wificond/net/netlink_utils.h" |
27 | #include "wificond/scanning/offload/offload_scan_manager.h" | 27 | #include "wificond/scanning/offload_scan_callback_interface.h" |
28 | #include "wificond/scanning/scan_utils.h" | 28 | #include "wificond/scanning/scan_utils.h" |
29 | 29 | ||
30 | namespace android { | 30 | namespace android { |
@@ -32,16 +32,17 @@ namespace wificond { | |||
32 | 32 | ||
33 | class ClientInterfaceImpl; | 33 | class ClientInterfaceImpl; |
34 | class OffloadServiceUtils; | 34 | class OffloadServiceUtils; |
35 | class ScanUtils; | ||
36 | class OffloadScanCallbackInterfaceImpl; | ||
37 | class OffloadScanManager; | ||
35 | 38 | ||
36 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | 39 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { |
37 | public: | 40 | public: |
38 | ScannerImpl(uint32_t wiphy_index, | 41 | ScannerImpl(uint32_t wiphy_index, uint32_t interface_index, |
39 | uint32_t interface_index, | ||
40 | const ScanCapabilities& scan_capabilities, | 42 | const ScanCapabilities& scan_capabilities, |
41 | const WiphyFeatures& wiphy_features, | 43 | const WiphyFeatures& wiphy_features, |
42 | ClientInterfaceImpl* client_interface, | 44 | ClientInterfaceImpl* client_interface, |
43 | NetlinkUtils* netlink_utils, | 45 | NetlinkUtils* netlink_utils, ScanUtils* scan_utils, |
44 | ScanUtils* scan_utils, | ||
45 | std::weak_ptr<OffloadServiceUtils> offload_service_utils); | 46 | std::weak_ptr<OffloadServiceUtils> offload_service_utils); |
46 | ~ScannerImpl(); | 47 | ~ScannerImpl(); |
47 | // Returns a vector of available frequencies for 2.4GHz channels. | 48 | // Returns a vector of available frequencies for 2.4GHz channels. |
@@ -53,10 +54,15 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
53 | // Returns a vector of available frequencies for DFS channels. | 54 | // Returns a vector of available frequencies for DFS channels. |
54 | ::android::binder::Status getAvailableDFSChannels( | 55 | ::android::binder::Status getAvailableDFSChannels( |
55 | ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override; | 56 | ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override; |
56 | // Get the latest scan results from kernel. | 57 | // Get the latest single scan results from kernel. |
57 | ::android::binder::Status getScanResults( | 58 | ::android::binder::Status getScanResults( |
58 | std::vector<com::android::server::wifi::wificond::NativeScanResult>* | 59 | std::vector<com::android::server::wifi::wificond::NativeScanResult>* |
59 | out_scan_results) override; | 60 | out_scan_results) override; |
61 | // Get the latest pno scan results from the interface that most recently | ||
62 | // completed PNO scans | ||
63 | ::android::binder::Status getPnoScanResults( | ||
64 | std::vector<com::android::server::wifi::wificond::NativeScanResult>* | ||
65 | out_scan_results) override; | ||
60 | ::android::binder::Status scan( | 66 | ::android::binder::Status scan( |
61 | const ::com::android::server::wifi::wificond::SingleScanSettings& | 67 | const ::com::android::server::wifi::wificond::SingleScanSettings& |
62 | scan_settings, | 68 | scan_settings, |
@@ -71,19 +77,19 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
71 | const ::android::sp<::android::net::wifi::IScanEvent>& handler) override; | 77 | const ::android::sp<::android::net::wifi::IScanEvent>& handler) override; |
72 | ::android::binder::Status unsubscribeScanEvents() override; | 78 | ::android::binder::Status unsubscribeScanEvents() override; |
73 | ::android::binder::Status subscribePnoScanEvents( | 79 | ::android::binder::Status subscribePnoScanEvents( |
74 | const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) override; | 80 | const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) |
81 | override; | ||
75 | ::android::binder::Status unsubscribePnoScanEvents() override; | 82 | ::android::binder::Status unsubscribePnoScanEvents() override; |
83 | void OnOffloadScanResult(); | ||
84 | void OnOffloadError( | ||
85 | OffloadScanCallbackInterface::AsyncErrorReason error_code); | ||
76 | void Invalidate(); | 86 | void Invalidate(); |
77 | 87 | ||
78 | private: | 88 | private: |
79 | bool CheckIsValid(); | 89 | bool CheckIsValid(); |
80 | void OnOffloadScanResult( | 90 | void OnScanResultsReady(uint32_t interface_index, bool aborted, |
81 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>); | 91 | std::vector<std::vector<uint8_t>>& ssids, |
82 | void OnScanResultsReady( | 92 | std::vector<uint32_t>& frequencies); |
83 | uint32_t interface_index, | ||
84 | bool aborted, | ||
85 | std::vector<std::vector<uint8_t>>& ssids, | ||
86 | std::vector<uint32_t>& frequencies); | ||
87 | void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); | 93 | void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); |
88 | void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, | 94 | void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, |
89 | std::string prefix); | 95 | std::string prefix); |
@@ -94,11 +100,10 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
94 | bool StopPnoScanDefault(); | 100 | bool StopPnoScanDefault(); |
95 | bool StopPnoScanOffload(); | 101 | bool StopPnoScanOffload(); |
96 | void ParsePnoSettings( | 102 | void ParsePnoSettings( |
97 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, | 103 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, |
98 | std::vector<std::vector<uint8_t>>* scan_ssids, | 104 | std::vector<std::vector<uint8_t>>* scan_ssids, |
99 | std::vector<std::vector<uint8_t>>* match_ssids, | 105 | std::vector<std::vector<uint8_t>>* match_ssids, |
100 | std::vector<uint32_t>* freqs, | 106 | std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security); |
101 | std::vector<uint8_t>* match_security); | ||
102 | SchedScanIntervalSetting GenerateIntervalSetting( | 107 | SchedScanIntervalSetting GenerateIntervalSetting( |
103 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; | 108 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; |
104 | 109 | ||
@@ -107,6 +112,9 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
107 | bool scan_started_; | 112 | bool scan_started_; |
108 | bool pno_scan_started_; | 113 | bool pno_scan_started_; |
109 | bool offload_scan_supported_; | 114 | bool offload_scan_supported_; |
115 | bool pno_scan_running_over_offload_; | ||
116 | bool pno_scan_results_from_offload_; | ||
117 | ::com::android::server::wifi::wificond::PnoSettings pno_settings_; | ||
110 | 118 | ||
111 | const uint32_t wiphy_index_; | 119 | const uint32_t wiphy_index_; |
112 | const uint32_t interface_index_; | 120 | const uint32_t interface_index_; |
@@ -120,7 +128,7 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
120 | ScanUtils* const scan_utils_; | 128 | ScanUtils* const scan_utils_; |
121 | ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_; | 129 | ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_; |
122 | ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_; | 130 | ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_; |
123 | std::unique_ptr<OffloadScanManager> offload_scan_manager_; | 131 | std::shared_ptr<OffloadScanManager> offload_scan_manager_; |
124 | 132 | ||
125 | DISALLOW_COPY_AND_ASSIGN(ScannerImpl); | 133 | DISALLOW_COPY_AND_ASSIGN(ScannerImpl); |
126 | }; | 134 | }; |
@@ -35,8 +35,6 @@ using android::IBinder; | |||
35 | using android::net::wifi::IApInterface; | 35 | using android::net::wifi::IApInterface; |
36 | using android::net::wifi::IClientInterface; | 36 | using android::net::wifi::IClientInterface; |
37 | using android::net::wifi::IInterfaceEventCallback; | 37 | using android::net::wifi::IInterfaceEventCallback; |
38 | using android::net::wifi::IRttClient; | ||
39 | using android::net::wifi::IRttController; | ||
40 | using android::wifi_system::HostapdManager; | 38 | using android::wifi_system::HostapdManager; |
41 | using android::wifi_system::InterfaceTool; | 39 | using android::wifi_system::InterfaceTool; |
42 | using android::wifi_system::SupplicantManager; | 40 | using android::wifi_system::SupplicantManager; |
@@ -96,25 +94,6 @@ Status Server::UnregisterCallback(const sp<IInterfaceEventCallback>& callback) { | |||
96 | return Status::ok(); | 94 | return Status::ok(); |
97 | } | 95 | } |
98 | 96 | ||
99 | Status Server::registerRttClient(const sp<IRttClient>& rtt_client, | ||
100 | sp<IRttController>* out_rtt_controller) { | ||
101 | if (rtt_controller_ == nullptr) { | ||
102 | rtt_controller_.reset(new RttControllerImpl()); | ||
103 | } | ||
104 | rtt_controller_->RegisterRttClient(rtt_client); | ||
105 | |||
106 | *out_rtt_controller = rtt_controller_->GetBinder(); | ||
107 | return Status::ok(); | ||
108 | } | ||
109 | |||
110 | Status Server::unregisterRttClient(const sp<IRttClient>& rttClient) { | ||
111 | rtt_controller_->UnregisterRttClient(rttClient); | ||
112 | if (rtt_controller_->GetClientCount() == 0) { | ||
113 | rtt_controller_.reset(); | ||
114 | } | ||
115 | return Status::ok(); | ||
116 | } | ||
117 | |||
118 | Status Server::createApInterface(sp<IApInterface>* created_interface) { | 97 | Status Server::createApInterface(sp<IApInterface>* created_interface) { |
119 | InterfaceInfo interface; | 98 | InterfaceInfo interface; |
120 | if (!SetupInterface(&interface)) { | 99 | if (!SetupInterface(&interface)) { |
@@ -31,7 +31,6 @@ | |||
31 | 31 | ||
32 | #include "wificond/ap_interface_impl.h" | 32 | #include "wificond/ap_interface_impl.h" |
33 | #include "wificond/client_interface_impl.h" | 33 | #include "wificond/client_interface_impl.h" |
34 | #include "wificond/rtt/rtt_controller_impl.h" | ||
35 | 34 | ||
36 | namespace android { | 35 | namespace android { |
37 | namespace wificond { | 36 | namespace wificond { |
@@ -58,15 +57,6 @@ class Server : public android::net::wifi::BnWificond { | |||
58 | const android::sp<android::net::wifi::IInterfaceEventCallback>& | 57 | const android::sp<android::net::wifi::IInterfaceEventCallback>& |
59 | callback) override; | 58 | callback) override; |
60 | 59 | ||
61 | android::binder::Status registerRttClient( | ||
62 | const ::android::sp<::android::net::wifi::IRttClient>& rtt_client, | ||
63 | ::android::sp<::android::net::wifi::IRttController>* | ||
64 | out_rtt_controller) override; | ||
65 | |||
66 | android::binder::Status unregisterRttClient( | ||
67 | const ::android::sp<::android::net::wifi::IRttClient>& | ||
68 | rttClient) override; | ||
69 | |||
70 | android::binder::Status createApInterface( | 60 | android::binder::Status createApInterface( |
71 | android::sp<android::net::wifi::IApInterface>* | 61 | android::sp<android::net::wifi::IApInterface>* |
72 | created_interface) override; | 62 | created_interface) override; |
@@ -120,8 +110,6 @@ class Server : public android::net::wifi::BnWificond { | |||
120 | std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>> | 110 | std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>> |
121 | interface_event_callbacks_; | 111 | interface_event_callbacks_; |
122 | 112 | ||
123 | std::unique_ptr<RttControllerImpl> rtt_controller_; | ||
124 | |||
125 | // Cached interface list from kernel. | 113 | // Cached interface list from kernel. |
126 | std::vector<InterfaceInfo> interfaces_; | 114 | std::vector<InterfaceInfo> interfaces_; |
127 | 115 | ||
diff --git a/rtt/rtt_controller_binder.cpp b/tests/mock_offload_scan_callback_interface.cpp index ba37018..cb76e45 100644 --- a/rtt/rtt_controller_binder.cpp +++ b/tests/mock_offload_scan_callback_interface.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2016 The Android Open Source Project | 2 | * Copyright (C) 2017 The Android Open Source Project |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
@@ -14,18 +14,12 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "wificond/rtt/rtt_controller_binder.h" | 17 | #include "wificond/tests/mock_offload_scan_callback_interface.h" |
18 | |||
19 | #include "wificond/rtt/rtt_controller_impl.h" | ||
20 | 18 | ||
21 | namespace android { | 19 | namespace android { |
22 | namespace wificond { | 20 | namespace wificond { |
23 | 21 | ||
24 | RttControllerBinder::RttControllerBinder(RttControllerImpl* impl) : impl_{impl} { | 22 | MockOffloadScanCallbackInterface::MockOffloadScanCallbackInterface() {} |
25 | } | ||
26 | |||
27 | RttControllerBinder::~RttControllerBinder() { | ||
28 | } | ||
29 | 23 | ||
30 | } // namespace wificond | 24 | } // namespace wificond |
31 | } // namespace android | 25 | } // namespace android |
diff --git a/tests/mock_offload_scan_callback_interface.h b/tests/mock_offload_scan_callback_interface.h new file mode 100644 index 0000000..e4f8df9 --- /dev/null +++ b/tests/mock_offload_scan_callback_interface.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_H_ | ||
18 | #define WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_H_ | ||
19 | |||
20 | #include <gmock/gmock.h> | ||
21 | #include <gtest/gtest.h> | ||
22 | |||
23 | #include "wificond/scanning/offload_scan_callback_interface.h" | ||
24 | |||
25 | namespace android { | ||
26 | namespace wificond { | ||
27 | |||
28 | class MockOffloadScanCallbackInterface : public OffloadScanCallbackInterface { | ||
29 | public: | ||
30 | MockOffloadScanCallbackInterface(); | ||
31 | ~MockOffloadScanCallbackInterface() override = default; | ||
32 | |||
33 | MOCK_METHOD0(OnOffloadScanResult, void()); | ||
34 | MOCK_METHOD1(OnOffloadError, | ||
35 | void(OffloadScanCallbackInterface::AsyncErrorReason)); | ||
36 | }; | ||
37 | |||
38 | } // namespace wificond | ||
39 | } // namespace android | ||
40 | |||
41 | #endif // WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_H_ | ||
diff --git a/aidl/android/net/wifi/IRttClient.aidl b/tests/mock_offload_scan_callback_interface_impl.cpp index b58fdca..b9dffc5 100644 --- a/aidl/android/net/wifi/IRttClient.aidl +++ b/tests/mock_offload_scan_callback_interface_impl.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2016 The Android Open Source Project | 2 | * Copyright (C) 2017 The Android Open Source Project |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
@@ -14,8 +14,15 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | package android.net.wifi; | 17 | #include "wificond/tests/mock_offload_scan_callback_interface_impl.h" |
18 | #include "wificond/scanning/scanner_impl.h" | ||
18 | 19 | ||
19 | interface IRttClient { | 20 | namespace android { |
20 | // TODO(nywang) add functions | 21 | namespace wificond { |
21 | } | 22 | |
23 | MockOffloadScanCallbackInterfaceImpl::MockOffloadScanCallbackInterfaceImpl( | ||
24 | ScannerImpl* parent) | ||
25 | : OffloadScanCallbackInterfaceImpl(parent) {} | ||
26 | |||
27 | } // namespace wificond | ||
28 | } // namespace android | ||
diff --git a/tests/mock_offload_scan_callback_interface_impl.h b/tests/mock_offload_scan_callback_interface_impl.h new file mode 100644 index 0000000..8b76388 --- /dev/null +++ b/tests/mock_offload_scan_callback_interface_impl.h | |||
@@ -0,0 +1,44 @@ | |||
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 | #ifndef WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_IMPL_H__ | ||
18 | #define WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_IMPL_H__ | ||
19 | |||
20 | #include <gmock/gmock.h> | ||
21 | #include <gtest/gtest.h> | ||
22 | |||
23 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
24 | |||
25 | namespace android { | ||
26 | namespace wificond { | ||
27 | |||
28 | class ScannerImpl; | ||
29 | |||
30 | class MockOffloadScanCallbackInterfaceImpl | ||
31 | : public OffloadScanCallbackInterfaceImpl { | ||
32 | public: | ||
33 | MockOffloadScanCallbackInterfaceImpl(ScannerImpl*); | ||
34 | ~MockOffloadScanCallbackInterfaceImpl() override = default; | ||
35 | |||
36 | MOCK_METHOD0(OnOffloadScanResult, void()); | ||
37 | MOCK_METHOD1(OnOffloadError, | ||
38 | void(OffloadScanCallbackInterface::AsyncErrorReason)); | ||
39 | }; | ||
40 | |||
41 | } // namespace wificond | ||
42 | } // namespace android | ||
43 | |||
44 | #endif // WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_CALLBACK_INTERFACE_IMPL_H__ | ||
diff --git a/aidl/android/net/wifi/IRttController.aidl b/tests/mock_offload_scan_manager.cpp index 30f8d0d..8943524 100644 --- a/aidl/android/net/wifi/IRttController.aidl +++ b/tests/mock_offload_scan_manager.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2016 The Android Open Source Project | 2 | * Copyright (C) 2017 The Android Open Source Project |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
@@ -14,8 +14,15 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | package android.net.wifi; | 17 | #include "wificond/tests/mock_offload_scan_manager.h" |
18 | 18 | ||
19 | interface IRttController { | 19 | namespace android { |
20 | // TODO(nywang) add functions | 20 | namespace wificond { |
21 | } | 21 | |
22 | MockOffloadScanManager::MockOffloadScanManager( | ||
23 | std::weak_ptr<OffloadServiceUtils> service_utils, | ||
24 | std::shared_ptr<OffloadScanCallbackInterface> callback_interface) | ||
25 | : OffloadScanManager(service_utils, callback_interface) {} | ||
26 | |||
27 | } // namespace wificond | ||
28 | } // namespace android | ||
diff --git a/tests/mock_offload_scan_manager.h b/tests/mock_offload_scan_manager.h new file mode 100644 index 0000000..71d5e79 --- /dev/null +++ b/tests/mock_offload_scan_manager.h | |||
@@ -0,0 +1,56 @@ | |||
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 | #ifndef WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_MANAGER_H_ | ||
18 | #define WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_MANAGER_H_ | ||
19 | |||
20 | #include <gmock/gmock.h> | ||
21 | #include <gtest/gtest.h> | ||
22 | |||
23 | #include "wificond/scanning/offload/offload_scan_manager.h" | ||
24 | |||
25 | namespace android { | ||
26 | namespace wificond { | ||
27 | |||
28 | class MockOffloadScanManager : public OffloadScanManager { | ||
29 | public: | ||
30 | MockOffloadScanManager( | ||
31 | std::weak_ptr<OffloadServiceUtils> service_utils, | ||
32 | std::shared_ptr<OffloadScanCallbackInterface> callback_interface); | ||
33 | ~MockOffloadScanManager() override = default; | ||
34 | |||
35 | MOCK_METHOD7(startScan, | ||
36 | bool(uint32_t interval_ms, int32_t rssi_threshold, | ||
37 | const std::vector<std::vector<uint8_t>>& scan_ssids, | ||
38 | const std::vector<std::vector<uint8_t>>& match_ssids, | ||
39 | const std::vector<uint8_t>& match_security, | ||
40 | const std::vector<uint32_t>& frequencies, | ||
41 | OffloadScanManager::ReasonCode* reason_code)); | ||
42 | MOCK_METHOD1(stopScan, bool(OffloadScanManager::ReasonCode* reason_code)); | ||
43 | MOCK_METHOD1(getScanStats, | ||
44 | bool(::com::android::server::wifi::wificond::NativeScanStats* | ||
45 | scan_stats)); | ||
46 | MOCK_CONST_METHOD0(getOffloadStatus, OffloadScanManager::StatusCode()); | ||
47 | MOCK_METHOD1( | ||
48 | getScanResults, | ||
49 | bool(std::vector< | ||
50 | ::com::android::server::wifi::wificond::NativeScanResult>*)); | ||
51 | }; | ||
52 | |||
53 | } // namespace wificond | ||
54 | } // namespace android | ||
55 | |||
56 | #endif // WIFICOND_TESTS_MOCK_OFFLOAD_SCAN_MANAGER_H_ | ||
diff --git a/tests/mock_offload_service_utils.h b/tests/mock_offload_service_utils.h index fd9fd34..76d022d 100644 --- a/tests/mock_offload_service_utils.h +++ b/tests/mock_offload_service_utils.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "wificond/scanning/offload/offload_callback.h" | 24 | #include "wificond/scanning/offload/offload_callback.h" |
25 | #include "wificond/scanning/offload/offload_callback_handlers.h" | 25 | #include "wificond/scanning/offload/offload_callback_handlers.h" |
26 | #include "wificond/scanning/offload/offload_service_utils.h" | 26 | #include "wificond/scanning/offload/offload_service_utils.h" |
27 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
27 | 28 | ||
28 | namespace android { | 29 | namespace android { |
29 | namespace wificond { | 30 | namespace wificond { |
@@ -40,6 +41,14 @@ class MockOffloadServiceUtils : public OffloadServiceUtils { | |||
40 | MOCK_METHOD1(GetOffloadDeathRecipient, | 41 | MOCK_METHOD1(GetOffloadDeathRecipient, |
41 | android::wificond::OffloadDeathRecipient*( | 42 | android::wificond::OffloadDeathRecipient*( |
42 | OffloadDeathRecipientHandler handler)); | 43 | OffloadDeathRecipientHandler handler)); |
44 | MOCK_METHOD1( | ||
45 | GetOffloadScanCallbackInterface, | ||
46 | std::shared_ptr<OffloadScanCallbackInterfaceImpl>(ScannerImpl* scanner)); | ||
47 | MOCK_METHOD2(GetOffloadScanManager, | ||
48 | std::shared_ptr<OffloadScanManager>( | ||
49 | std::weak_ptr<OffloadServiceUtils> service_utils, | ||
50 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> | ||
51 | callback_interface)); | ||
43 | }; | 52 | }; |
44 | 53 | ||
45 | } // namespace wificond | 54 | } // namespace wificond |
diff --git a/tests/offload_scan_manager_test.cpp b/tests/offload_scan_manager_test.cpp index 2dbf953..9e586cb 100644 --- a/tests/offload_scan_manager_test.cpp +++ b/tests/offload_scan_manager_test.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <gtest/gtest.h> | 23 | #include <gtest/gtest.h> |
24 | 24 | ||
25 | #include "wificond/tests/mock_offload.h" | 25 | #include "wificond/tests/mock_offload.h" |
26 | #include "wificond/tests/mock_offload_scan_callback_interface.h" | ||
26 | #include "wificond/tests/mock_offload_service_utils.h" | 27 | #include "wificond/tests/mock_offload_service_utils.h" |
27 | #include "wificond/tests/offload_hal_test_constants.h" | 28 | #include "wificond/tests/offload_hal_test_constants.h" |
28 | #include "wificond/tests/offload_test_utils.h" | 29 | #include "wificond/tests/offload_test_utils.h" |
@@ -112,6 +113,9 @@ class OffloadScanManagerTest : public ::testing::Test { | |||
112 | sp<OffloadDeathRecipient> death_recipient_; | 113 | sp<OffloadDeathRecipient> death_recipient_; |
113 | shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ | 114 | shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ |
114 | new NiceMock<MockOffloadServiceUtils>()}; | 115 | new NiceMock<MockOffloadServiceUtils>()}; |
116 | shared_ptr<NiceMock<MockOffloadScanCallbackInterface>> | ||
117 | mock_offload_scan_callback_interface_{ | ||
118 | new NiceMock<MockOffloadScanCallbackInterface>()}; | ||
115 | unique_ptr<OffloadScanManager> offload_scan_manager_; | 119 | unique_ptr<OffloadScanManager> offload_scan_manager_; |
116 | OffloadStatus status; | 120 | OffloadStatus status; |
117 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; | 121 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; |
@@ -131,8 +135,8 @@ TEST_F(OffloadScanManagerTest, BinderDeathRegisteredCookieAndService) { | |||
131 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 135 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
132 | .WillByDefault(testing::Return(mock_offload_)); | 136 | .WillByDefault(testing::Return(mock_offload_)); |
133 | offload_scan_manager_.reset(new OffloadScanManager( | 137 | offload_scan_manager_.reset(new OffloadScanManager( |
134 | mock_offload_service_utils_, | 138 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
135 | [](vector<NativeScanResult> scanResult) -> void {})); | 139 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_)); |
136 | death_recipient_->serviceDied(cookie_, mock_offload_); | 140 | death_recipient_->serviceDied(cookie_, mock_offload_); |
137 | EXPECT_EQ(OffloadScanManager::kNoService, | 141 | EXPECT_EQ(OffloadScanManager::kNoService, |
138 | offload_scan_manager_->getOffloadStatus()); | 142 | offload_scan_manager_->getOffloadStatus()); |
@@ -147,8 +151,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) { | |||
147 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 151 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
148 | .WillByDefault(testing::Return(mock_offload_)); | 152 | .WillByDefault(testing::Return(mock_offload_)); |
149 | offload_scan_manager_.reset(new OffloadScanManager( | 153 | offload_scan_manager_.reset(new OffloadScanManager( |
150 | mock_offload_service_utils_, | 154 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
151 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
152 | death_recipient_->serviceDied(kDeathCode, mock_offload_); | 155 | death_recipient_->serviceDied(kDeathCode, mock_offload_); |
153 | EXPECT_FALSE(OffloadScanManager::kNoService == | 156 | EXPECT_FALSE(OffloadScanManager::kNoService == |
154 | offload_scan_manager_->getOffloadStatus()); | 157 | offload_scan_manager_->getOffloadStatus()); |
@@ -163,8 +166,7 @@ TEST_F(OffloadScanManagerTest, ServiceNotAvailableTest) { | |||
163 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 166 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
164 | .WillByDefault(testing::Return(nullptr)); | 167 | .WillByDefault(testing::Return(nullptr)); |
165 | offload_scan_manager_.reset(new OffloadScanManager( | 168 | offload_scan_manager_.reset(new OffloadScanManager( |
166 | mock_offload_service_utils_, | 169 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
167 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
168 | EXPECT_EQ(OffloadScanManager::kNoService, | 170 | EXPECT_EQ(OffloadScanManager::kNoService, |
169 | offload_scan_manager_->getOffloadStatus()); | 171 | offload_scan_manager_->getOffloadStatus()); |
170 | } | 172 | } |
@@ -180,8 +182,7 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) { | |||
180 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 182 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
181 | .WillByDefault(testing::Return(mock_offload_)); | 183 | .WillByDefault(testing::Return(mock_offload_)); |
182 | offload_scan_manager_.reset(new OffloadScanManager( | 184 | offload_scan_manager_.reset(new OffloadScanManager( |
183 | mock_offload_service_utils_, | 185 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
184 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
185 | EXPECT_EQ(OffloadScanManager::kNoError, | 186 | EXPECT_EQ(OffloadScanManager::kNoError, |
186 | offload_scan_manager_->getOffloadStatus()); | 187 | offload_scan_manager_->getOffloadStatus()); |
187 | } | 188 | } |
@@ -192,21 +193,17 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) { | |||
192 | * scan results are available | 193 | * scan results are available |
193 | */ | 194 | */ |
194 | TEST_F(OffloadScanManagerTest, CallbackInvokedTest) { | 195 | TEST_F(OffloadScanManagerTest, CallbackInvokedTest) { |
195 | bool callback_invoked = false; | ||
196 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 196 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); |
197 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); | 197 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); |
198 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); | 198 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); |
199 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 199 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
200 | .WillByDefault(testing::Return(mock_offload_)); | 200 | .WillByDefault(testing::Return(mock_offload_)); |
201 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadScanResult()); | ||
201 | offload_scan_manager_.reset(new OffloadScanManager( | 202 | offload_scan_manager_.reset(new OffloadScanManager( |
202 | mock_offload_service_utils_, | 203 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
203 | [&callback_invoked](vector<NativeScanResult> scanResult) -> void { | ||
204 | callback_invoked = true; | ||
205 | })); | ||
206 | vector<ScanResult> dummy_scan_results_ = | 204 | vector<ScanResult> dummy_scan_results_ = |
207 | OffloadTestUtils::createOffloadScanResults(); | 205 | OffloadTestUtils::createOffloadScanResults(); |
208 | offload_callback_->onScanResult(dummy_scan_results_); | 206 | offload_callback_->onScanResult(dummy_scan_results_); |
209 | EXPECT_EQ(true, callback_invoked); | ||
210 | } | 207 | } |
211 | 208 | ||
212 | /** | 209 | /** |
@@ -220,10 +217,10 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) { | |||
220 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 217 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
221 | .WillByDefault(testing::Return(mock_offload_)); | 218 | .WillByDefault(testing::Return(mock_offload_)); |
222 | offload_scan_manager_.reset(new OffloadScanManager( | 219 | offload_scan_manager_.reset(new OffloadScanManager( |
223 | mock_offload_service_utils_, | 220 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
224 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
225 | OffloadStatus status = | 221 | OffloadStatus status = |
226 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | 222 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
223 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_)); | ||
227 | offload_callback_->onError(status); | 224 | offload_callback_->onError(status); |
228 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), | 225 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), |
229 | OffloadScanManager::kError); | 226 | OffloadScanManager::kError); |
@@ -240,8 +237,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | |||
240 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 237 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
241 | .WillByDefault(testing::Return(mock_offload_)); | 238 | .WillByDefault(testing::Return(mock_offload_)); |
242 | offload_scan_manager_.reset(new OffloadScanManager( | 239 | offload_scan_manager_.reset(new OffloadScanManager( |
243 | mock_offload_service_utils_, | 240 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
244 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
245 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 241 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
246 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 242 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
247 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 243 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
@@ -256,12 +252,11 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | |||
256 | * Offload HAL when service is not available | 252 | * Offload HAL when service is not available |
257 | */ | 253 | */ |
258 | TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { | 254 | TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { |
259 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 255 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()).Times(2); |
260 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 256 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
261 | .WillByDefault(testing::Return(nullptr)); | 257 | .WillByDefault(testing::Return(nullptr)); |
262 | offload_scan_manager_.reset(new OffloadScanManager( | 258 | offload_scan_manager_.reset(new OffloadScanManager( |
263 | mock_offload_service_utils_, | 259 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
264 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
265 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 260 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
266 | bool result = offload_scan_manager_->startScan( | 261 | bool result = offload_scan_manager_->startScan( |
267 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 262 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -281,8 +276,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) { | |||
281 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 276 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
282 | .WillByDefault(testing::Return(mock_offload_)); | 277 | .WillByDefault(testing::Return(mock_offload_)); |
283 | offload_scan_manager_.reset(new OffloadScanManager( | 278 | offload_scan_manager_.reset(new OffloadScanManager( |
284 | mock_offload_service_utils_, | 279 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
285 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
286 | OffloadStatus status = | 280 | OffloadStatus status = |
287 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 281 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
288 | offload_callback_->onError(status); | 282 | offload_callback_->onError(status); |
@@ -305,9 +299,8 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) { | |||
305 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 299 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
306 | .WillByDefault(testing::Return(mock_offload_)); | 300 | .WillByDefault(testing::Return(mock_offload_)); |
307 | offload_scan_manager_.reset(new OffloadScanManager( | 301 | offload_scan_manager_.reset(new OffloadScanManager( |
308 | mock_offload_service_utils_, | 302 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
309 | [](vector<NativeScanResult> scanResult) -> void {})); | 303 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(2); |
310 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1); | ||
311 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); | 304 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); |
312 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 305 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
313 | bool result = offload_scan_manager_->startScan( | 306 | bool result = offload_scan_manager_->startScan( |
@@ -331,8 +324,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | |||
331 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 324 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
332 | .WillByDefault(testing::Return(mock_offload_)); | 325 | .WillByDefault(testing::Return(mock_offload_)); |
333 | offload_scan_manager_.reset(new OffloadScanManager( | 326 | offload_scan_manager_.reset(new OffloadScanManager( |
334 | mock_offload_service_utils_, | 327 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
335 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
336 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 328 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
337 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 329 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
338 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | 330 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); |
@@ -347,26 +339,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | |||
347 | 339 | ||
348 | /** | 340 | /** |
349 | * Testing OffloadScanManager for unsubscribing to the scan results from | 341 | * Testing OffloadScanManager for unsubscribing to the scan results from |
350 | * Offload HAL without first subscribing | 342 | * when service is not connected to the hardware |
351 | */ | ||
352 | TEST_F(OffloadScanManagerTest, StopScanTestWithoutStartWhenServiceIsOk) { | ||
353 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | ||
354 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); | ||
355 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); | ||
356 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | ||
357 | .WillByDefault(testing::Return(mock_offload_)); | ||
358 | offload_scan_manager_.reset(new OffloadScanManager( | ||
359 | mock_offload_service_utils_, | ||
360 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
361 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | ||
362 | bool result = offload_scan_manager_->stopScan(&reason_code); | ||
363 | EXPECT_EQ(result, false); | ||
364 | EXPECT_EQ(reason_code, OffloadScanManager::kNotSubscribed); | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * Testing OffloadScanManager for unsubscribing to the scan results from | ||
369 | * Offload HAL without first subscribing when service is not working correctly | ||
370 | */ | 343 | */ |
371 | TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | 344 | TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { |
372 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 345 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); |
@@ -374,11 +347,9 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | |||
374 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 347 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
375 | .WillByDefault(testing::Return(mock_offload_)); | 348 | .WillByDefault(testing::Return(mock_offload_)); |
376 | offload_scan_manager_.reset(new OffloadScanManager( | 349 | offload_scan_manager_.reset(new OffloadScanManager( |
377 | mock_offload_service_utils_, | 350 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
378 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
379 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 351 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
380 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 352 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
381 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | ||
382 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 353 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
383 | bool result = offload_scan_manager_->startScan( | 354 | bool result = offload_scan_manager_->startScan( |
384 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 355 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -388,7 +359,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | |||
388 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 359 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
389 | offload_callback_->onError(status); | 360 | offload_callback_->onError(status); |
390 | result = offload_scan_manager_->stopScan(&reason_code); | 361 | result = offload_scan_manager_->stopScan(&reason_code); |
391 | EXPECT_EQ(result, true); | 362 | EXPECT_EQ(result, false); |
392 | } | 363 | } |
393 | 364 | ||
394 | /** | 365 | /** |
@@ -402,8 +373,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsOk) { | |||
402 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 373 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
403 | .WillByDefault(testing::Return(mock_offload_)); | 374 | .WillByDefault(testing::Return(mock_offload_)); |
404 | offload_scan_manager_.reset(new OffloadScanManager( | 375 | offload_scan_manager_.reset(new OffloadScanManager( |
405 | mock_offload_service_utils_, | 376 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
406 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
407 | EXPECT_CALL(*mock_offload_, getScanStats(_)); | 377 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
408 | NativeScanStats stats; | 378 | NativeScanStats stats; |
409 | bool result = offload_scan_manager_->getScanStats(&stats); | 379 | bool result = offload_scan_manager_->getScanStats(&stats); |
@@ -421,8 +391,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) { | |||
421 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 391 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
422 | .WillByDefault(testing::Return(mock_offload_)); | 392 | .WillByDefault(testing::Return(mock_offload_)); |
423 | offload_scan_manager_.reset(new OffloadScanManager( | 393 | offload_scan_manager_.reset(new OffloadScanManager( |
424 | mock_offload_service_utils_, | 394 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
425 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
426 | OffloadStatus status = | 395 | OffloadStatus status = |
427 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 396 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
428 | offload_callback_->onError(status); | 397 | offload_callback_->onError(status); |
@@ -443,8 +412,7 @@ TEST_F(OffloadScanManagerTest, StartScanFailedTest) { | |||
443 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 412 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
444 | .WillByDefault(testing::Return(mock_offload_)); | 413 | .WillByDefault(testing::Return(mock_offload_)); |
445 | offload_scan_manager_.reset(new OffloadScanManager( | 414 | offload_scan_manager_.reset(new OffloadScanManager( |
446 | mock_offload_service_utils_, | 415 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
447 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
448 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); | 416 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); |
449 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); | 417 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); |
450 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | 418 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
@@ -467,8 +435,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) { | |||
467 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 435 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
468 | .WillByDefault(testing::Return(mock_offload_)); | 436 | .WillByDefault(testing::Return(mock_offload_)); |
469 | offload_scan_manager_.reset(new OffloadScanManager( | 437 | offload_scan_manager_.reset(new OffloadScanManager( |
470 | mock_offload_service_utils_, | 438 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
471 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
472 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); | 439 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); |
473 | EXPECT_CALL(*mock_offload_, getScanStats(_)); | 440 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
474 | NativeScanStats stats; | 441 | NativeScanStats stats; |
diff --git a/tests/offload_scan_utils_test.cpp b/tests/offload_scan_utils_test.cpp index d75143a..15c7e86 100644 --- a/tests/offload_scan_utils_test.cpp +++ b/tests/offload_scan_utils_test.cpp | |||
@@ -50,13 +50,13 @@ class OffloadScanUtilsTest : public ::testing::Test { | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | TEST_F(OffloadScanUtilsTest, verifyConversion) { | 52 | TEST_F(OffloadScanUtilsTest, verifyConversion) { |
53 | vector<NativeScanResult> native_scan_results = | 53 | vector<NativeScanResult> native_scan_results; |
54 | OffloadScanUtils::convertToNativeScanResults(dummy_scan_results_); | 54 | EXPECT_TRUE(OffloadScanUtils::convertToNativeScanResults( |
55 | dummy_scan_results_, &native_scan_results)); | ||
55 | EXPECT_EQ(native_scan_results.size(), dummy_scan_results_.size()); | 56 | EXPECT_EQ(native_scan_results.size(), dummy_scan_results_.size()); |
56 | for (size_t i = 0; i < native_scan_results.size(); i++) { | 57 | for (size_t i = 0; i < native_scan_results.size(); i++) { |
57 | EXPECT_EQ(native_scan_results[i].frequency, | 58 | EXPECT_EQ(native_scan_results[i].frequency, |
58 | dummy_scan_results_[i].frequency); | 59 | dummy_scan_results_[i].frequency); |
59 | EXPECT_EQ(native_scan_results[i].tsf, dummy_scan_results_[i].tsf); | ||
60 | EXPECT_EQ(native_scan_results[i].signal_mbm, dummy_scan_results_[i].rssi); | 60 | EXPECT_EQ(native_scan_results[i].signal_mbm, dummy_scan_results_[i].rssi); |
61 | EXPECT_EQ(native_scan_results[i].ssid.size(), | 61 | EXPECT_EQ(native_scan_results[i].ssid.size(), |
62 | dummy_scan_results_[i].networkInfo.ssid.size()); | 62 | dummy_scan_results_[i].networkInfo.ssid.size()); |
diff --git a/tests/scanner_unittest.cpp b/tests/scanner_unittest.cpp index bbaeffd..d69e8b1 100644 --- a/tests/scanner_unittest.cpp +++ b/tests/scanner_unittest.cpp | |||
@@ -21,12 +21,16 @@ | |||
21 | #include <wifi_system_test/mock_interface_tool.h> | 21 | #include <wifi_system_test/mock_interface_tool.h> |
22 | #include <wifi_system_test/mock_supplicant_manager.h> | 22 | #include <wifi_system_test/mock_supplicant_manager.h> |
23 | 23 | ||
24 | #include "wificond/scanning/offload/offload_scan_utils.h" | ||
24 | #include "wificond/scanning/scanner_impl.h" | 25 | #include "wificond/scanning/scanner_impl.h" |
25 | #include "wificond/tests/mock_client_interface_impl.h" | 26 | #include "wificond/tests/mock_client_interface_impl.h" |
26 | #include "wificond/tests/mock_netlink_manager.h" | 27 | #include "wificond/tests/mock_netlink_manager.h" |
27 | #include "wificond/tests/mock_netlink_utils.h" | 28 | #include "wificond/tests/mock_netlink_utils.h" |
29 | #include "wificond/tests/mock_offload_scan_callback_interface_impl.h" | ||
30 | #include "wificond/tests/mock_offload_scan_manager.h" | ||
28 | #include "wificond/tests/mock_offload_service_utils.h" | 31 | #include "wificond/tests/mock_offload_service_utils.h" |
29 | #include "wificond/tests/mock_scan_utils.h" | 32 | #include "wificond/tests/mock_scan_utils.h" |
33 | #include "wificond/tests/offload_test_utils.h" | ||
30 | 34 | ||
31 | using ::android::binder::Status; | 35 | using ::android::binder::Status; |
32 | using ::android::wifi_system::MockInterfaceTool; | 36 | using ::android::wifi_system::MockInterfaceTool; |
@@ -34,6 +38,7 @@ using ::android::wifi_system::MockSupplicantManager; | |||
34 | using ::com::android::server::wifi::wificond::SingleScanSettings; | 38 | using ::com::android::server::wifi::wificond::SingleScanSettings; |
35 | using ::com::android::server::wifi::wificond::PnoSettings; | 39 | using ::com::android::server::wifi::wificond::PnoSettings; |
36 | using ::com::android::server::wifi::wificond::NativeScanResult; | 40 | using ::com::android::server::wifi::wificond::NativeScanResult; |
41 | using android::hardware::wifi::offload::V1_0::ScanResult; | ||
37 | using ::testing::Invoke; | 42 | using ::testing::Invoke; |
38 | using ::testing::NiceMock; | 43 | using ::testing::NiceMock; |
39 | using ::testing::Return; | 44 | using ::testing::Return; |
@@ -84,21 +89,36 @@ bool CaptureSchedScanIntervalSetting( | |||
84 | return true; | 89 | return true; |
85 | } | 90 | } |
86 | 91 | ||
92 | bool ReturnOffloadScanResults( | ||
93 | std::vector<NativeScanResult>* native_scan_results_, | ||
94 | const std::vector<ScanResult>& offload_scan_results) { | ||
95 | return OffloadScanUtils::convertToNativeScanResults(offload_scan_results, | ||
96 | native_scan_results_); | ||
97 | } | ||
98 | |||
99 | bool ReturnNetlinkScanResults( | ||
100 | uint32_t interface_index, | ||
101 | std::vector<NativeScanResult>* native_scan_results_, | ||
102 | const std::vector<ScanResult>& offload_scan_results) { | ||
103 | return OffloadScanUtils::convertToNativeScanResults(offload_scan_results, | ||
104 | native_scan_results_); | ||
105 | } | ||
106 | |||
87 | } // namespace | 107 | } // namespace |
88 | 108 | ||
89 | class ScannerTest : public ::testing::Test { | 109 | class ScannerTest : public ::testing::Test { |
90 | protected: | 110 | protected: |
91 | void SetUp() override { | 111 | void SetUp() override { |
92 | ON_CALL(*offload_service_utils_, IsOffloadScanSupported()).WillByDefault( | 112 | ON_CALL(*offload_service_utils_, GetOffloadScanManager(_, _)) |
93 | Return(false)); | 113 | .WillByDefault(Return(offload_scan_manager_)); |
94 | netlink_scanner_.reset(new ScannerImpl( | 114 | ON_CALL(*offload_service_utils_, GetOffloadScanCallbackInterface(_)) |
95 | kFakeWiphyIndex, kFakeInterfaceIndex, | 115 | .WillByDefault(Return(offload_scan_callback_interface_)); |
96 | scan_capabilities_, wiphy_features_, | 116 | dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults(); |
97 | &client_interface_impl_, | ||
98 | &netlink_utils_, &scan_utils_, offload_service_utils_)); | ||
99 | } | 117 | } |
100 | 118 | ||
101 | unique_ptr<ScannerImpl> netlink_scanner_; | 119 | void TearDown() override { dummy_scan_results_.clear(); } |
120 | |||
121 | unique_ptr<ScannerImpl> scanner_impl_; | ||
102 | NiceMock<MockNetlinkManager> netlink_manager_; | 122 | NiceMock<MockNetlinkManager> netlink_manager_; |
103 | NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_}; | 123 | NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_}; |
104 | NiceMock<MockScanUtils> scan_utils_{&netlink_manager_}; | 124 | NiceMock<MockScanUtils> scan_utils_{&netlink_manager_}; |
@@ -108,18 +128,34 @@ class ScannerTest : public ::testing::Test { | |||
108 | &if_tool_, &supplicant_manager_, &netlink_utils_, &scan_utils_}; | 128 | &if_tool_, &supplicant_manager_, &netlink_utils_, &scan_utils_}; |
109 | shared_ptr<NiceMock<MockOffloadServiceUtils>> offload_service_utils_{ | 129 | shared_ptr<NiceMock<MockOffloadServiceUtils>> offload_service_utils_{ |
110 | new NiceMock<MockOffloadServiceUtils>()}; | 130 | new NiceMock<MockOffloadServiceUtils>()}; |
131 | shared_ptr<NiceMock<MockOffloadScanCallbackInterfaceImpl>> | ||
132 | offload_scan_callback_interface_{ | ||
133 | new NiceMock<MockOffloadScanCallbackInterfaceImpl>( | ||
134 | scanner_impl_.get())}; | ||
135 | std::shared_ptr<NiceMock<MockOffloadScanManager>> offload_scan_manager_{ | ||
136 | new NiceMock<MockOffloadScanManager>(offload_service_utils_, | ||
137 | offload_scan_callback_interface_)}; | ||
111 | ScanCapabilities scan_capabilities_; | 138 | ScanCapabilities scan_capabilities_; |
112 | WiphyFeatures wiphy_features_; | 139 | WiphyFeatures wiphy_features_; |
140 | std::vector<ScanResult> dummy_scan_results_; | ||
113 | }; | 141 | }; |
114 | 142 | ||
115 | TEST_F(ScannerTest, TestSingleScan) { | 143 | TEST_F(ScannerTest, TestSingleScan) { |
116 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); | 144 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); |
117 | bool success = false; | 145 | bool success = false; |
118 | EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); | 146 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, |
147 | scan_capabilities_, wiphy_features_, | ||
148 | &client_interface_impl_, &netlink_utils_, | ||
149 | &scan_utils_, offload_service_utils_)); | ||
150 | EXPECT_TRUE(scanner_impl_->scan(SingleScanSettings(), &success).isOk()); | ||
119 | EXPECT_TRUE(success); | 151 | EXPECT_TRUE(success); |
120 | } | 152 | } |
121 | 153 | ||
122 | TEST_F(ScannerTest, TestSingleScanFailure) { | 154 | TEST_F(ScannerTest, TestSingleScanFailure) { |
155 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
156 | scan_capabilities_, wiphy_features_, | ||
157 | &client_interface_impl_, &netlink_utils_, | ||
158 | &scan_utils_, offload_service_utils_)); | ||
123 | EXPECT_CALL( | 159 | EXPECT_CALL( |
124 | scan_utils_, | 160 | scan_utils_, |
125 | Scan(_, _, _, _, _)). | 161 | Scan(_, _, _, _, _)). |
@@ -127,11 +163,15 @@ TEST_F(ScannerTest, TestSingleScanFailure) { | |||
127 | ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5))); | 163 | ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5))); |
128 | 164 | ||
129 | bool success = false; | 165 | bool success = false; |
130 | EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); | 166 | EXPECT_TRUE(scanner_impl_->scan(SingleScanSettings(), &success).isOk()); |
131 | EXPECT_FALSE(success); | 167 | EXPECT_FALSE(success); |
132 | } | 168 | } |
133 | 169 | ||
134 | TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) { | 170 | TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) { |
171 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
172 | scan_capabilities_, wiphy_features_, | ||
173 | &client_interface_impl_, &netlink_utils_, | ||
174 | &scan_utils_, offload_service_utils_)); | ||
135 | ON_CALL( | 175 | ON_CALL( |
136 | scan_utils_, | 176 | scan_utils_, |
137 | Scan(_, _, _, _, _)). | 177 | Scan(_, _, _, _, _)). |
@@ -139,47 +179,202 @@ TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) { | |||
139 | ReturnErrorCodeForScanRequest, ENODEV, _1, _2, _3, _4, _5))); | 179 | ReturnErrorCodeForScanRequest, ENODEV, _1, _2, _3, _4, _5))); |
140 | 180 | ||
141 | bool success_ignored; | 181 | bool success_ignored; |
142 | EXPECT_DEATH( | 182 | EXPECT_DEATH(scanner_impl_->scan(SingleScanSettings(), &success_ignored), |
143 | netlink_scanner_->scan(SingleScanSettings(), &success_ignored), | 183 | "Driver is in a bad state*"); |
144 | "Driver is in a bad state*"); | ||
145 | } | 184 | } |
146 | 185 | ||
147 | TEST_F(ScannerTest, TestAbortScan) { | 186 | TEST_F(ScannerTest, TestAbortScan) { |
148 | bool single_scan_success = false; | 187 | bool single_scan_success = false; |
188 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
189 | scan_capabilities_, wiphy_features_, | ||
190 | &client_interface_impl_, &netlink_utils_, | ||
191 | &scan_utils_, offload_service_utils_)); | ||
149 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); | 192 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); |
150 | EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), | 193 | EXPECT_TRUE( |
151 | &single_scan_success).isOk()); | 194 | scanner_impl_->scan(SingleScanSettings(), &single_scan_success).isOk()); |
152 | EXPECT_TRUE(single_scan_success); | 195 | EXPECT_TRUE(single_scan_success); |
153 | 196 | ||
154 | EXPECT_CALL(scan_utils_, AbortScan(_)); | 197 | EXPECT_CALL(scan_utils_, AbortScan(_)); |
155 | EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); | 198 | EXPECT_TRUE(scanner_impl_->abortScan().isOk()); |
156 | } | 199 | } |
157 | 200 | ||
158 | TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) { | 201 | TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) { |
202 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
203 | scan_capabilities_, wiphy_features_, | ||
204 | &client_interface_impl_, &netlink_utils_, | ||
205 | &scan_utils_, offload_service_utils_)); | ||
159 | EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0); | 206 | EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0); |
160 | EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); | 207 | EXPECT_TRUE(scanner_impl_->abortScan().isOk()); |
161 | } | 208 | } |
162 | 209 | ||
163 | TEST_F(ScannerTest, TestGetScanResults) { | 210 | TEST_F(ScannerTest, TestGetScanResults) { |
164 | vector<NativeScanResult> scan_results; | 211 | vector<NativeScanResult> scan_results; |
212 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
213 | scan_capabilities_, wiphy_features_, | ||
214 | &client_interface_impl_, &netlink_utils_, | ||
215 | &scan_utils_, offload_service_utils_)); | ||
165 | EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true)); | 216 | EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true)); |
166 | EXPECT_TRUE(netlink_scanner_->getScanResults(&scan_results).isOk()); | 217 | EXPECT_TRUE(scanner_impl_->getScanResults(&scan_results).isOk()); |
167 | } | 218 | } |
168 | 219 | ||
169 | TEST_F(ScannerTest, TestStartPnoScanViaNetlink) { | 220 | TEST_F(ScannerTest, TestStartPnoScanViaNetlink) { |
170 | bool success = false; | 221 | bool success = false; |
222 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
223 | .Times(1) | ||
224 | .WillRepeatedly(Return(false)); | ||
225 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
226 | scan_capabilities_, wiphy_features_, | ||
227 | &client_interface_impl_, &netlink_utils_, | ||
228 | &scan_utils_, offload_service_utils_)); | ||
171 | EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)). | 229 | EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)). |
172 | WillOnce(Return(true)); | 230 | WillOnce(Return(true)); |
173 | EXPECT_TRUE(netlink_scanner_->startPnoScan(PnoSettings(), &success).isOk()); | 231 | EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk()); |
174 | EXPECT_TRUE(success); | 232 | EXPECT_TRUE(success); |
175 | } | 233 | } |
176 | 234 | ||
177 | TEST_F(ScannerTest, TestStopPnoScanViaNetlink) { | 235 | TEST_F(ScannerTest, TestStopPnoScanViaNetlink) { |
178 | bool success = false; | 236 | bool success = false; |
237 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
238 | .Times(1) | ||
239 | .WillRepeatedly(Return(false)); | ||
240 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
241 | scan_capabilities_, wiphy_features_, | ||
242 | &client_interface_impl_, &netlink_utils_, | ||
243 | &scan_utils_, offload_service_utils_)); | ||
179 | // StopScheduledScan() will be called no matter if there is an ongoing | 244 | // StopScheduledScan() will be called no matter if there is an ongoing |
180 | // scheduled scan or not. This is for making the system more robust. | 245 | // scheduled scan or not. This is for making the system more robust. |
181 | EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); | 246 | EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); |
182 | EXPECT_TRUE(netlink_scanner_->stopPnoScan(&success).isOk()); | 247 | EXPECT_TRUE(scanner_impl_->stopPnoScan(&success).isOk()); |
248 | EXPECT_TRUE(success); | ||
249 | } | ||
250 | |||
251 | TEST_F(ScannerTest, TestStartScanOverOffload) { | ||
252 | bool success = false; | ||
253 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
254 | .Times(1) | ||
255 | .WillRepeatedly(Return(true)); | ||
256 | EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _)) | ||
257 | .Times(1) | ||
258 | .WillRepeatedly(Return(true)); | ||
259 | EXPECT_CALL(*offload_scan_manager_, stopScan(_)) | ||
260 | .Times(1) | ||
261 | .WillRepeatedly(Return(true)); | ||
262 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
263 | scan_capabilities_, wiphy_features_, | ||
264 | &client_interface_impl_, &netlink_utils_, | ||
265 | &scan_utils_, offload_service_utils_)); | ||
266 | scanner_impl_->startPnoScan(PnoSettings(), &success); | ||
267 | EXPECT_TRUE(success); | ||
268 | scanner_impl_->stopPnoScan(&success); | ||
269 | EXPECT_TRUE(success); | ||
270 | } | ||
271 | |||
272 | TEST_F(ScannerTest, TestStartScanOverNetlinkFallback) { | ||
273 | bool success = false; | ||
274 | ON_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
275 | .WillByDefault(Return(true)); | ||
276 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
277 | scan_capabilities_, wiphy_features_, | ||
278 | &client_interface_impl_, &netlink_utils_, | ||
279 | &scan_utils_, offload_service_utils_)); | ||
280 | EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _)) | ||
281 | .WillOnce(Return(false)); | ||
282 | EXPECT_CALL(*offload_scan_manager_, stopScan(_)).Times(0); | ||
283 | EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)) | ||
284 | .WillOnce(Return(true)); | ||
285 | EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); | ||
286 | EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk()); | ||
287 | EXPECT_TRUE(success == true); | ||
288 | scanner_impl_->stopPnoScan(&success); | ||
289 | EXPECT_TRUE(success); | ||
290 | } | ||
291 | |||
292 | TEST_F(ScannerTest, TestAsyncErrorOverOffload) { | ||
293 | bool success = false; | ||
294 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
295 | .Times(1) | ||
296 | .WillRepeatedly(Return(true)); | ||
297 | EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _)) | ||
298 | .Times(1) | ||
299 | .WillRepeatedly(Return(true)); | ||
300 | EXPECT_CALL(*offload_scan_manager_, stopScan(_)) | ||
301 | .Times(1) | ||
302 | .WillRepeatedly(Return(true)); | ||
303 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
304 | scan_capabilities_, wiphy_features_, | ||
305 | &client_interface_impl_, &netlink_utils_, | ||
306 | &scan_utils_, offload_service_utils_)); | ||
307 | EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)) | ||
308 | .WillOnce(Return(true)); | ||
309 | EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); | ||
310 | scanner_impl_->startPnoScan(PnoSettings(), &success); | ||
311 | EXPECT_TRUE(success); | ||
312 | scanner_impl_->OnOffloadError( | ||
313 | OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE); | ||
314 | scanner_impl_->stopPnoScan(&success); | ||
315 | EXPECT_TRUE(success); | ||
316 | } | ||
317 | |||
318 | TEST_F(ScannerTest, TestGetScanResultsFromOffload) { | ||
319 | bool success = false; | ||
320 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
321 | .Times(1) | ||
322 | .WillRepeatedly(Return(true)); | ||
323 | EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _)) | ||
324 | .Times(1) | ||
325 | .WillRepeatedly(Return(true)); | ||
326 | EXPECT_CALL(*offload_scan_manager_, getScanResults(_)) | ||
327 | .Times(1) | ||
328 | .WillOnce( | ||
329 | Invoke(bind(ReturnOffloadScanResults, _1, dummy_scan_results_))); | ||
330 | EXPECT_CALL(*offload_scan_manager_, stopScan(_)) | ||
331 | .Times(1) | ||
332 | .WillRepeatedly(Return(true)); | ||
333 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
334 | scan_capabilities_, wiphy_features_, | ||
335 | &client_interface_impl_, &netlink_utils_, | ||
336 | &scan_utils_, offload_service_utils_)); | ||
337 | scanner_impl_->startPnoScan(PnoSettings(), &success); | ||
338 | EXPECT_TRUE(success); | ||
339 | scanner_impl_->OnOffloadScanResult(); | ||
340 | std::vector<NativeScanResult> scan_results; | ||
341 | EXPECT_TRUE(scanner_impl_->getPnoScanResults(&scan_results).isOk()); | ||
342 | EXPECT_FALSE(scan_results.empty()); | ||
343 | scanner_impl_->stopPnoScan(&success); | ||
344 | EXPECT_TRUE(success); | ||
345 | } | ||
346 | |||
347 | TEST_F(ScannerTest, TestGetScanResultsWhenOffloadFails) { | ||
348 | bool success = false; | ||
349 | EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported()) | ||
350 | .Times(1) | ||
351 | .WillRepeatedly(Return(true)); | ||
352 | EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _)) | ||
353 | .Times(1) | ||
354 | .WillRepeatedly(Return(true)); | ||
355 | EXPECT_CALL(*offload_scan_manager_, stopScan(_)) | ||
356 | .Times(1) | ||
357 | .WillRepeatedly(Return(true)); | ||
358 | EXPECT_CALL(*offload_scan_manager_, getScanResults(_)).Times(0); | ||
359 | EXPECT_CALL(scan_utils_, GetScanResult(_, _)) | ||
360 | .Times(1) | ||
361 | .WillOnce( | ||
362 | Invoke(bind(ReturnNetlinkScanResults, _1, _2, dummy_scan_results_))); | ||
363 | scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex, | ||
364 | scan_capabilities_, wiphy_features_, | ||
365 | &client_interface_impl_, &netlink_utils_, | ||
366 | &scan_utils_, offload_service_utils_)); | ||
367 | EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)) | ||
368 | .WillOnce(Return(true)); | ||
369 | EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); | ||
370 | EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk()); | ||
371 | EXPECT_TRUE(success); | ||
372 | scanner_impl_->OnOffloadError( | ||
373 | OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE); | ||
374 | std::vector<NativeScanResult> scan_results; | ||
375 | EXPECT_TRUE(scanner_impl_->getPnoScanResults(&scan_results).isOk()); | ||
376 | EXPECT_FALSE(scan_results.empty()); | ||
377 | scanner_impl_->stopPnoScan(&success); | ||
183 | EXPECT_TRUE(success); | 378 | EXPECT_TRUE(success); |
184 | } | 379 | } |
185 | 380 | ||