mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-23 23:10:05 +00:00
commit
fb76be727e
@ -186,6 +186,13 @@ public:
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
|
||||
};
|
||||
|
||||
class ScanListHandler : public AppExecFwk::EventHandler {
|
||||
public:
|
||||
explicit ScanListHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
|
||||
~ScanListHandler() override;
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
|
||||
};
|
||||
|
||||
class WifiServiceStatusChange : public SystemAbilityStatusChangeStub {
|
||||
public:
|
||||
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||
@ -226,6 +233,7 @@ private:
|
||||
std::mutex mutex_;
|
||||
std::vector<sptr<ILocatingRequiredDataCallback>> callbacks_;
|
||||
std::shared_ptr<ScanHandler> scanHandler_;
|
||||
std::shared_ptr<ScanListHandler> scanListHandler_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -31,6 +31,8 @@ LocatorRequiredDataManager::LocatorRequiredDataManager()
|
||||
WifiInfoInit();
|
||||
#endif
|
||||
scanHandler_ = std::make_shared<ScanHandler>(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT));
|
||||
scanListHandler_ =
|
||||
std::make_shared<ScanListHandler>(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT));
|
||||
}
|
||||
|
||||
LocatorRequiredDataManager* LocatorRequiredDataManager::GetInstance()
|
||||
@ -253,8 +255,8 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::GetWifiScan
|
||||
LBSLOGE(LOCATOR, "GetScanInfoList failed");
|
||||
return;
|
||||
}
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
if (scanListHandler_ != nullptr) {
|
||||
scanListHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,6 +291,10 @@ void LocatorWifiScanEventCallback::OnWifiScanStateChanged(int state)
|
||||
LBSLOGE(LOCATOR, "ProcessEvent: dataManager is nullptr");
|
||||
return;
|
||||
}
|
||||
if (!dataManager->IsConnecting()) {
|
||||
LBSLOGE(LOCATOR, "%{public}s no valid callback, return", __func__);
|
||||
return;
|
||||
}
|
||||
std::vector<Wifi::WifiScanInfo> wifiScanInfo;
|
||||
dataManager->GetWifiScanList(wifiScanInfo);
|
||||
std::vector<std::shared_ptr<LocatingRequiredData>> result =
|
||||
@ -311,7 +317,19 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiSc
|
||||
if (!flag) {
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->RemoveEvent(EVENT_START_SCAN);
|
||||
scanHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
if (scanListHandler_ != nullptr) {
|
||||
scanListHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
LBSLOGE(LOCATOR, "%{public}s no valid callback, return", __func__);
|
||||
return;
|
||||
}
|
||||
if (!IsConnecting()) {
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->RemoveEvent(EVENT_START_SCAN);
|
||||
}
|
||||
if (scanListHandler_ != nullptr) {
|
||||
scanListHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -319,8 +337,8 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiSc
|
||||
if (wifiScanPtr_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->SendHighPriorityEvent(EVENT_GET_WIFI_LIST, 0, DEFAULT_TIMEOUT_4S);
|
||||
if (scanListHandler_ != nullptr) {
|
||||
scanListHandler_->SendHighPriorityEvent(EVENT_GET_WIFI_LIST, 0, DEFAULT_TIMEOUT_4S);
|
||||
}
|
||||
int ret = wifiScanPtr_->Scan();
|
||||
if (ret != Wifi::WIFI_OPT_SUCCESS) {
|
||||
@ -364,6 +382,25 @@ void ScanHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
|
||||
dataManager->StartWifiScan(false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ScanListHandler::ScanListHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
|
||||
|
||||
ScanListHandler::~ScanListHandler() {}
|
||||
|
||||
void ScanListHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
|
||||
{
|
||||
auto dataManager = LocatorRequiredDataManager::GetInstance();
|
||||
if (dataManager == nullptr) {
|
||||
LBSLOGE(LOCATOR, "ProcessEvent: dataManager is nullptr");
|
||||
return;
|
||||
}
|
||||
uint32_t eventId = event->GetInnerEventId();
|
||||
LBSLOGD(LOCATOR, "ScanListHandler ProcessEvent event:%{public}d", eventId);
|
||||
switch (eventId) {
|
||||
case EVENT_GET_WIFI_LIST: {
|
||||
std::vector<Wifi::WifiScanInfo> wifiScanInfo;
|
||||
dataManager->GetWifiScanList(wifiScanInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user