summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSohani Rao2017-07-11 20:02:24 -0500
committerSohani Rao2017-08-11 19:21:44 -0500
commit7439bcacc8805ae85bf1440d5f28df88dd1aee56 (patch)
tree785d94839d790b928ecf803fd12ebd01e0315cce
parente15c0edc98c9e6e906b9c53d1691a6bcfae5c61d (diff)
downloadsystem-connectivity-wificond-7439bcacc8805ae85bf1440d5f28df88dd1aee56.tar.gz
system-connectivity-wificond-7439bcacc8805ae85bf1440d5f28df88dd1aee56.tar.xz
system-connectivity-wificond-7439bcacc8805ae85bf1440d5f28df88dd1aee56.zip
Wificond: Make Offload HAL service nonblocking
Offload HAL getService() is a blocking call which can cause a deadlock. Replace it with non blocking call tryGetService() which returns null if the service is not running instead of waiting on the service to start. This implies that the client needs to be able to get a reference to the service at a later time. The design choice is to use tryGetService() API to get the handle when a disconnected mode PNO scan is requested if this was not available before. Bug: 62807929 Test: Unit test, sanity test Change-Id: I344fd93c4afe2381c356e626e83311af49a5ad49
-rw-r--r--scanning/offload/offload_scan_manager.cpp61
-rw-r--r--scanning/offload/offload_scan_manager.h5
-rw-r--r--scanning/offload/offload_service_utils.cpp2
-rw-r--r--tests/offload_scan_manager_test.cpp2
4 files changed, 53 insertions, 17 deletions
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp
index 5c73362..420c2fa 100644
--- a/scanning/offload/offload_scan_manager.cpp
+++ b/scanning/offload/offload_scan_manager.cpp
@@ -74,39 +74,64 @@ OffloadScanManager::OffloadScanManager(
74 shared_ptr<OffloadScanCallbackInterface> callback) 74 shared_ptr<OffloadScanCallbackInterface> callback)
75 : wifi_offload_hal_(nullptr), 75 : wifi_offload_hal_(nullptr),
76 wifi_offload_callback_(nullptr), 76 wifi_offload_callback_(nullptr),
77 death_recipient_(nullptr),
77 offload_status_(OffloadScanManager::kError), 78 offload_status_(OffloadScanManager::kError),
79 service_available_(false),
80 offload_service_utils_(utils),
78 offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), 81 offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)),
79 event_callback_(callback) { 82 event_callback_(callback) {
80 auto offload_scan_utils = utils.lock(); 83 if (InitService()) {
81 wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); 84 offload_status_ = OffloadScanManager::kNoError;
85 }
86}
87
88bool OffloadScanManager::InitService() {
89 wifi_offload_hal_ = offload_service_utils_.lock()->GetOffloadService();
82 if (wifi_offload_hal_ == nullptr) { 90 if (wifi_offload_hal_ == nullptr) {
83 LOG(ERROR) << "No Offload Service available"; 91 LOG(ERROR) << "No Offload Service available";
84 return; 92 return false;
85 } 93 }
86 94
87 death_recipient_ = offload_scan_utils->GetOffloadDeathRecipient( 95 death_recipient_ = offload_service_utils_.lock()->GetOffloadDeathRecipient(
88 std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); 96 std::bind(&OffloadScanManager::OnObjectDeath, this, _1));
89 uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); 97 uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get());
98
90 auto link_to_death_status = 99 auto link_to_death_status =
91 wifi_offload_hal_->linkToDeath(death_recipient_, cookie); 100 wifi_offload_hal_->linkToDeath(death_recipient_, cookie);
92 if (!link_to_death_status.isOk()) { 101 if (!link_to_death_status.isOk()) {
93 LOG(ERROR) << "Unable to register death handler " 102 LOG(ERROR) << "Unable to register death handler "
94 << link_to_death_status.description(); 103 << link_to_death_status.description();
95 return; 104 return false;
96 } 105 }
97 106
98 wifi_offload_callback_ = 107 wifi_offload_callback_ = offload_service_utils_.lock()->GetOffloadCallback(
99 offload_scan_utils->GetOffloadCallback(offload_callback_handlers_.get()); 108 offload_callback_handlers_.get());
100 if (wifi_offload_callback_ == nullptr) { 109 if (wifi_offload_callback_ == nullptr) {
101 LOG(ERROR) << "Invalid Offload callback object"; 110 LOG(ERROR) << "Invalid Offload callback object";
102 return; 111 return false;
112 }
113
114 auto set_callback_status =
115 wifi_offload_hal_->setEventCallback(wifi_offload_callback_);
116 if (!set_callback_status.isOk()) {
117 LOG(ERROR) << "Unable to set event callback for Offload HAL";
118 return false;
119 }
120
121 service_available_ = true;
122 return true;
123}
124
125bool OffloadScanManager::InitServiceIfNeeded() {
126 if (!service_available_) {
127 return InitService();
103 } 128 }
104 wifi_offload_hal_->setEventCallback(wifi_offload_callback_); 129 return true;
105 offload_status_ = OffloadScanManager::kNoError;
106} 130}
107 131
108bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { 132bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) {
109 if (getOffloadStatus() != OffloadScanManager::kNoError) { 133 if (!InitServiceIfNeeded() ||
134 (getOffloadStatus() != OffloadScanManager::kNoError)) {
110 *reason_code = OffloadScanManager::kNotAvailable; 135 *reason_code = OffloadScanManager::kNotAvailable;
111 return false; 136 return false;
112 } 137 }
@@ -160,7 +185,8 @@ bool OffloadScanManager::startScan(
160 const vector<vector<uint8_t>>& match_ssids, 185 const vector<vector<uint8_t>>& match_ssids,
161 const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, 186 const vector<uint8_t>& match_security, const vector<uint32_t>& freqs,
162 OffloadScanManager::ReasonCode* reason_code) { 187 OffloadScanManager::ReasonCode* reason_code) {
163 if (getOffloadStatus() != OffloadScanManager::kNoError) { 188 if (!InitServiceIfNeeded() ||
189 getOffloadStatus() != OffloadScanManager::kNoError) {
164 *reason_code = OffloadScanManager::kNotAvailable; 190 *reason_code = OffloadScanManager::kNotAvailable;
165 LOG(WARNING) << "Offload HAL scans are not available"; 191 LOG(WARNING) << "Offload HAL scans are not available";
166 return false; 192 return false;
@@ -206,7 +232,7 @@ bool OffloadScanManager::SubscribeScanResults(
206} 232}
207 233
208OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { 234OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const {
209 if (wifi_offload_hal_ == nullptr) { 235 if (!service_available_) {
210 return OffloadScanManager::kNoService; 236 return OffloadScanManager::kNoService;
211 } 237 }
212 return offload_status_; 238 return offload_status_;
@@ -221,6 +247,10 @@ bool OffloadScanManager::getScanResults(
221} 247}
222 248
223bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { 249bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) {
250 if (!InitServiceIfNeeded()) {
251 LOG(ERROR) << "Offload HAL service unavailable";
252 return false;
253 }
224 if (getOffloadStatus() != OffloadScanManager::kNoError) { 254 if (getOffloadStatus() != OffloadScanManager::kNoError) {
225 LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; 255 LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error";
226 return false; 256 return false;
@@ -280,6 +310,7 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) {
280 310
281void OffloadScanManager::OnObjectDeath(uint64_t cookie) { 311void OffloadScanManager::OnObjectDeath(uint64_t cookie) {
282 if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { 312 if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) {
313 LOG(ERROR) << "Death Notification for Wifi Offload HAL";
283 wifi_offload_hal_.clear(); 314 wifi_offload_hal_.clear();
284 if (event_callback_ != nullptr) { 315 if (event_callback_ != nullptr) {
285 event_callback_->OnOffloadError( 316 event_callback_->OnOffloadError(
@@ -288,8 +319,8 @@ void OffloadScanManager::OnObjectDeath(uint64_t cookie) {
288 LOG(WARNING) 319 LOG(WARNING)
289 << "No callback to report Offload HAL Binder death to wificond"; 320 << "No callback to report Offload HAL Binder death to wificond";
290 } 321 }
291 322 service_available_ = false;
292 LOG(ERROR) << "Death Notification for Wifi Offload HAL"; 323 death_recipient_.clear();
293 } 324 }
294} 325}
295 326
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h
index c928ba9..9cc3d47 100644
--- a/scanning/offload/offload_scan_manager.h
+++ b/scanning/offload/offload_scan_manager.h
@@ -132,6 +132,9 @@ class OffloadScanManager {
132 bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, 132 bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam,
133 android::hardware::wifi::offload::V1_0::ScanFilter, 133 android::hardware::wifi::offload::V1_0::ScanFilter,
134 OffloadScanManager::ReasonCode* reason_code); 134 OffloadScanManager::ReasonCode* reason_code);
135 bool InitServiceIfNeeded();
136 bool InitService();
137
135 /* Handle binder death */ 138 /* Handle binder death */
136 void OnObjectDeath(uint64_t /* cookie */); 139 void OnObjectDeath(uint64_t /* cookie */);
137 140
@@ -142,7 +145,9 @@ class OffloadScanManager {
142 StatusCode offload_status_; 145 StatusCode offload_status_;
143 std::vector<::com::android::server::wifi::wificond::NativeScanResult> 146 std::vector<::com::android::server::wifi::wificond::NativeScanResult>
144 cached_scan_results_; 147 cached_scan_results_;
148 bool service_available_;
145 149
150 const std::weak_ptr<OffloadServiceUtils> offload_service_utils_;
146 const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; 151 const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_;
147 std::shared_ptr<OffloadScanCallbackInterface> event_callback_; 152 std::shared_ptr<OffloadScanCallbackInterface> event_callback_;
148 153
diff --git a/scanning/offload/offload_service_utils.cpp b/scanning/offload/offload_service_utils.cpp
index da26b71..a4a2474 100644
--- a/scanning/offload/offload_service_utils.cpp
+++ b/scanning/offload/offload_service_utils.cpp
@@ -25,7 +25,7 @@ namespace android {
25namespace wificond { 25namespace wificond {
26 26
27android::sp<IOffload> OffloadServiceUtils::GetOffloadService() { 27android::sp<IOffload> OffloadServiceUtils::GetOffloadService() {
28 return IOffload::getService(); 28 return IOffload::tryGetService();
29} 29}
30 30
31android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback( 31android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback(
diff --git a/tests/offload_scan_manager_test.cpp b/tests/offload_scan_manager_test.cpp
index 9c612ae..9e586cb 100644
--- a/tests/offload_scan_manager_test.cpp
+++ b/tests/offload_scan_manager_test.cpp
@@ -252,7 +252,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) {
252 * Offload HAL when service is not available 252 * Offload HAL when service is not available
253 */ 253 */
254TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { 254TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) {
255 EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); 255 EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()).Times(2);
256 ON_CALL(*mock_offload_service_utils_, GetOffloadService()) 256 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
257 .WillByDefault(testing::Return(nullptr)); 257 .WillByDefault(testing::Return(nullptr));
258 offload_scan_manager_.reset(new OffloadScanManager( 258 offload_scan_manager_.reset(new OffloadScanManager(