mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-27 00:51:30 +00:00
bugfix
Signed-off-by: 李文龙 <liwenlong22@huawei.com>
This commit is contained in:
parent
40bfe10a87
commit
7b02c81235
@ -303,7 +303,7 @@ void JsObjToLocatingRequiredDataConfig(const napi_env& env, const napi_value& ob
|
||||
config->SetScanIntervalMs(valueInt < MIN_WIFI_SCAN_TIME ? MIN_WIFI_SCAN_TIME : valueInt);
|
||||
}
|
||||
if (JsObjectToInt(env, object, "scanTimeout", valueInt) == SUCCESS) {
|
||||
config->SetScanTimeoutMs(valueInt < 0 ? DEFAULT_TIMEOUT_5S : valueInt);
|
||||
config->SetScanTimeoutMs(valueInt < MIN_WIFI_SCAN_TIME ? MIN_WIFI_SCAN_TIME : valueInt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,6 +206,7 @@ public:
|
||||
void UpdateWifiScanCompleteTimestamp();
|
||||
int64_t GetWifiScanCompleteTimestamp();
|
||||
int64_t GetlastStillTime();
|
||||
bool IsStill();
|
||||
|
||||
private:
|
||||
int timeInterval_ = 0;
|
||||
@ -229,7 +230,6 @@ private:
|
||||
std::map<sptr<IRemoteObject>, AppIdentity> callbacksMap_;
|
||||
std::shared_ptr<ScanHandler> scanHandler_;
|
||||
std::shared_ptr<WifiSdkHandler> wifiSdkHandler_;
|
||||
int64_t wifiScanTimestamp_ = 0;
|
||||
std::mutex wifiScanCompleteTimestampMutex_;
|
||||
int64_t wifiScanCompleteTimestamp_ = 0;
|
||||
std::mutex lastStillTimeMutex_;
|
||||
|
@ -1123,7 +1123,6 @@ LocationErrCode LocatorAbility::StopLocating(sptr<ILocatorCallback>& callback)
|
||||
|
||||
LocationErrCode LocatorAbility::GetCacheLocation(std::unique_ptr<Location>& loc, AppIdentity &identity)
|
||||
{
|
||||
SelfRequestManager::GetInstance()->StartSelfRequest();
|
||||
if (locatorHandler_ == nullptr) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
@ -178,38 +178,11 @@ void LocatorBackgroundProxy::OnSuspend(const std::shared_ptr<Request>& request,
|
||||
// when switch off, stop proxy
|
||||
void LocatorBackgroundProxy::OnSaStateChange(bool enable)
|
||||
{
|
||||
if (proxySwtich_ == enable || !featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnSaStateChange %{public}d", enable);
|
||||
proxySwtich_ = enable;
|
||||
if (enable && !requestsList_->empty()) {
|
||||
StartLocator();
|
||||
} else {
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
// called when deleteRequest called from locator ability (e.g. app stop locating)
|
||||
void LocatorBackgroundProxy::OnDeleteRequestRecord(const std::shared_ptr<Request>& request)
|
||||
{
|
||||
if (!featureSwitch_) {
|
||||
return;
|
||||
}
|
||||
bool listEmpty = false;
|
||||
std::unique_lock<std::mutex> lock(requestListMutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
auto it = find(requestsList_->begin(), requestsList_->end(), request);
|
||||
if (it != requestsList_->end()) {
|
||||
requestsList_->remove(request);
|
||||
if (requestsList_->empty()) {
|
||||
listEmpty = true;
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
if (listEmpty) {
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
bool LocatorBackgroundProxy::CheckPermission(const std::shared_ptr<Request>& request) const
|
||||
@ -275,12 +248,6 @@ void LocatorBackgroundProxy::OnUserSwitch(int32_t userId)
|
||||
if (locatorAbility != nullptr) {
|
||||
locatorAbility->ApplyRequests(0);
|
||||
}
|
||||
if (!requestsList_->empty()) {
|
||||
StartLocator();
|
||||
} else {
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "OnUserSwitch stoplocator");
|
||||
StopLocator();
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::OnUserRemove(int32_t userId)
|
||||
@ -315,16 +282,6 @@ bool LocatorBackgroundProxy::CheckMaxRequestNum(pid_t uid, const std::string& pa
|
||||
void LocatorBackgroundProxy::mLocatorCallback::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "locator background OnLocationReport");
|
||||
auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
|
||||
auto requestsList = locatorBackgroundProxy->GetRequestsInProxy();
|
||||
if (requestsList.empty()) {
|
||||
locatorBackgroundProxy->StopLocator();
|
||||
return;
|
||||
}
|
||||
// call the callback of each proxy app
|
||||
for (auto request : requestsList) {
|
||||
request->GetLocatorCallBack()->OnLocationReport(location);
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorBackgroundProxy::mLocatorCallback::OnLocatingStatusChange(const int status)
|
||||
|
@ -24,7 +24,6 @@
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const uint32_t EVENT_START_SCAN = 0x0100;
|
||||
const uint32_t EVENT_STOP_SCAN = 0x0200;
|
||||
const uint32_t EVENT_GET_WIFI_LIST = 0x0300;
|
||||
const uint32_t EVENT_REGISTER_WIFI_CALLBACK = 0x0400;
|
||||
const uint32_t EVENT_UNREGISTER_WIFI_CALLBACK = 0x0500;
|
||||
@ -70,6 +69,12 @@ int64_t LocatorRequiredDataManager::GetlastStillTime()
|
||||
return lastStillTime_;
|
||||
}
|
||||
|
||||
bool LocatorRequiredDataManager::IsStill()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(lastStillTimeMutex_);
|
||||
return lastStillTime_ > 0;
|
||||
}
|
||||
|
||||
void LocatorRequiredDataManager::SendWifiScanEvent()
|
||||
{
|
||||
if (scanHandler_ != nullptr) {
|
||||
@ -125,17 +130,12 @@ LocationErrCode LocatorRequiredDataManager::UnregisterCallback(const sptr<IRemot
|
||||
{
|
||||
#ifdef WIFI_ENABLE
|
||||
std::unique_lock<std::mutex> lock(mutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
auto iter = callbacksMap_.find(callback);
|
||||
if (iter != callbacksMap_.end()) {
|
||||
callbacksMap_.erase(iter);
|
||||
}
|
||||
LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s",
|
||||
std::to_string(callbacksMap_.size()).c_str());
|
||||
if (callbacksMap_.size() > 0) {
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
lock.unlock();
|
||||
#endif
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
@ -262,9 +262,6 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::GetWifiScan
|
||||
LBSLOGE(LOCATOR, "GetScanInfoList failed");
|
||||
return;
|
||||
}
|
||||
if (wifiSdkHandler_ != nullptr) {
|
||||
wifiSdkHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<LocatingRequiredData>> LocatorRequiredDataManager::GetLocatingRequiredDataByWifi(
|
||||
@ -279,7 +276,7 @@ std::vector<std::shared_ptr<LocatingRequiredData>> LocatorRequiredDataManager::G
|
||||
wifiData->SetBssid(wifiScanInfo[i].bssid);
|
||||
wifiData->SetRssi(wifiScanInfo[i].rssi);
|
||||
wifiData->SetFrequency(wifiScanInfo[i].frequency);
|
||||
if (GetlastStillTime() == 0) {
|
||||
if (IsStill()) {
|
||||
wifiData->SetTimestamp(wifiScanInfo[i].timestamp);
|
||||
} else {
|
||||
wifiData->SetTimestamp(sinceBootTime);
|
||||
@ -336,31 +333,12 @@ void LocatorRequiredDataManager::ReportData(const std::vector<std::shared_ptr<Lo
|
||||
|
||||
__attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiScan(int fixNumber, bool flag)
|
||||
{
|
||||
if (!flag) {
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->RemoveEvent(EVENT_START_SCAN);
|
||||
}
|
||||
if (wifiSdkHandler_ != nullptr) {
|
||||
wifiSdkHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
|
||||
}
|
||||
LBSLOGE(LOCATOR, "%{public}s no valid callback, return", __func__);
|
||||
return;
|
||||
}
|
||||
#ifdef WIFI_ENABLE
|
||||
int64_t currentTime = CommonUtils::GetCurrentTimeStampMs();
|
||||
if (wifiScanTimestamp_ != 0 && currentTime - wifiScanTimestamp_ < DEFAULT_TIMEOUT_MS &&
|
||||
GetWifiScanCompleteTimestamp() > wifiScanTimestamp_) {
|
||||
if (IsStill() && GetWifiScanCompleteTimestamp() > GetlastStillTime()) {
|
||||
SendGetWifiListEvent(0);
|
||||
return;
|
||||
}
|
||||
if (GetlastStillTime() > 0 && GetWifiScanCompleteTimestamp() > GetlastStillTime()) {
|
||||
if (GetWifiScanCompleteTimestamp() > 0 &&
|
||||
GetWifiScanCompleteTimestamp() - currentTime < DEFAULT_TIMEOUT_6MIN) {
|
||||
SendGetWifiListEvent(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
wifiScanTimestamp_ = CommonUtils::GetCurrentTimeStampMs();
|
||||
int ret = Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID)->Scan();
|
||||
if (ret != Wifi::WIFI_OPT_SUCCESS) {
|
||||
LBSLOGE(LOCATOR, "%{public}s WifiScan failed, ret=%{public}d", __func__, ret);
|
||||
@ -393,10 +371,6 @@ void ScanHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
|
||||
dataManager->StartWifiScan(fixNumber, true);
|
||||
break;
|
||||
}
|
||||
case EVENT_STOP_SCAN: {
|
||||
dataManager->StartWifiScan(fixNumber, false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user