!959 定位时延优化

Merge pull request !959 from liuxinbing/master
This commit is contained in:
openharmony_ci 2024-10-22 09:36:59 +00:00 committed by Gitee
commit b37a0b9304
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 198 additions and 111 deletions

View File

@ -435,8 +435,18 @@ void GenerateExecuteContext(SingleLocationAsyncContext* context)
}
g_locatorProxy->StopLocating(callbackPtr);
if (callbackHost->GetCount() != 0 && callbackHost->GetSingleLocation() == nullptr) {
std::unique_ptr<Location> location = nullptr;
#ifdef ENABLE_NAPI_MANAGER
g_locatorProxy->GetCachedLocationV9(location);
#else
location = g_locatorProxy->GetCachedLocation();
#endif
if (location != nullptr) {
callbackHost->SetSingleLocation(location);
} else {
context->errCode = ERRCODE_LOCATING_FAIL;
}
}
callbackHost->SetCount(1);
#ifndef ENABLE_NAPI_MANAGER
} else {

View File

@ -23,7 +23,7 @@
"*Location*WriteAppLocatingStateEvent*";
"*ExecuteHookWhenAddWorkRecord*";
"*LOCATOR_SA_LOCATION_PERMISSION_CHECK*";
"*ExecuteHookWhenCheckAppForCacheTime*";
local:
*;
};

View File

@ -317,6 +317,13 @@ int64_t CommonUtils::GetCurrentTimeStamp()
return static_cast<int64_t>(currentTime.tv_sec);
}
int64_t CommonUtils::GetCurrentTimeStampMs()
{
struct timeval currentTime;
gettimeofday(&currentTime, nullptr);
return static_cast<int64_t>(currentTime.tv_sec * MILLI_PER_SEC + currentTime.tv_usec / MICRO_PER_MILLI);
}
std::vector<std::string> CommonUtils::Split(std::string str, std::string pattern)
{
std::vector<std::string> result;

View File

@ -135,5 +135,15 @@ bool HookUtils::CheckGnssLocationValidity(const std::unique_ptr<Location>& locat
LocationProcessStage::CHECK_GNSS_LOCATION_VALIDITY, (void *)&gnssLocationValidStruct, nullptr);
return gnssLocationValidStruct.result;
}
bool HookUtils::ExecuteHookWhenCheckAppForCacheTime(std::string packageName)
{
LocatorRequestStruct locatorRequestStruct;
locatorRequestStruct.bundleName = packageName;
locatorRequestStruct.result = false;
ExecuteHook(
LocationProcessStage::LOCATOR_SA_LOCATION_CACHE_TIME_CHECK, (void *)&locatorRequestStruct, nullptr);
return locatorRequestStruct.result;
}
} // namespace Location
} // namespace OHOS

View File

@ -172,6 +172,7 @@ public:
static bool CheckAppInstalled(const std::string& bundleName);
static int64_t GetCurrentTime();
static int64_t GetCurrentTimeStamp();
static int64_t GetCurrentTimeStampMs();
static std::vector<std::string> Split(std::string str, std::string pattern);
static errno_t GetMacArray(const std::string& strMac, uint8_t mac[MAC_LEN]);
static unsigned char ConvertStringToDigit(std::string str);

View File

@ -43,6 +43,7 @@ enum class LocationProcessStage {
ADD_REQUEST_TO_WORK_RECORD,
LOCATOR_SA_LOCATION_PERMISSION_CHECK,
LOCATOR_SA_COMMAND_PROCESS,
LOCATOR_SA_LOCATION_CACHE_TIME_CHECK,
};
typedef struct {
@ -98,6 +99,7 @@ public:
std::string bundleName);
static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location);
static bool ExecuteHookWhenCheckAppForUser(std::string packageName);
static bool ExecuteHookWhenCheckAppForCacheTime(std::string packageName);
};
} // namespace Location
} // namespace OHOS

View File

@ -24,6 +24,8 @@
#include "app_state_data.h"
#include "application_state_observer_stub.h"
#include "common_event_subscriber.h"
#include "event_handler.h"
#include "event_runner.h"
#include "system_ability_status_change_stub.h"
#include "i_locator_callback.h"
@ -39,6 +41,13 @@ public:
void OnForegroundApplicationChanged(const AppExecFwk::AppStateData& appStateData) override;
};
class LocatorBackgroundHandler : public AppExecFwk::EventHandler {
public:
explicit LocatorBackgroundHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
~LocatorBackgroundHandler() override;
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
};
class LocatorBackgroundProxy {
public:
static LocatorBackgroundProxy* GetInstance();
@ -54,11 +63,11 @@ public:
bool UnregisterAppStateObserver();
bool IsAppInLocationContinuousTasks(pid_t uid, pid_t pid);
bool IsAppHasFormVisible(uint32_t tokenId, uint64_t tokenIdEx);
private:
void StartLocator();
void StopLocator();
void StartLocatorThread();
void StopLocatorThread();
private:
void OnUserSwitch(int32_t userId);
void OnUserRemove(int32_t userId);
void UpdateListOnSuspend(const std::shared_ptr<Request>& request, bool active);
@ -116,6 +125,7 @@ private:
static std::mutex locatorMutex_;
sptr<AppExecFwk::IAppMgr> iAppMgr_ = nullptr;
sptr<AppStateChangeCallback> appStateObserver_ = nullptr;
std::shared_ptr<LocatorBackgroundHandler> locatorBackgroundHandler_;
};
} // namespace Location
} // namespace OHOS

View File

@ -200,6 +200,12 @@ public:
__attribute__((no_sanitize("cfi"))) void StartWifiScan(int fixNumber, bool flag);
bool IsConnecting();
static LocatorRequiredDataManager* GetInstance();
void SyncStillMovementState(bool state);
void SendWifiScanEvent();
void SendGetWifiListEvent(int timeout);
void SetToObtainCellinfo();
void UpdateWifiScanCompleteTimestamp();
int64_t GetWifiScanCompleteTimestamp();
private:
int timeInterval_ = 0;
@ -215,7 +221,6 @@ private:
void WifiInfoInit();
bool IsWifiCallbackRegistered();
void SetIsWifiCallbackRegistered(bool isWifiCallbackRegistered);
std::shared_ptr<Wifi::WifiScan> wifiScanPtr_;
bool isWifiCallbackRegistered_ = false;
std::mutex wifiRegisteredMutex_;
WifiEvent wifiScanEventCallback_ = {0};
@ -224,6 +229,13 @@ 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;
int64_t getWifiScanInfoTimestamp_ = 0;
std::mutex lastStillTimeMutex_;
int64_t lastStillTime_ = 0;
std::vector<Wifi::WifiScanInfo> wifiScanInfo_;
};
} // namespace Location
} // namespace OHOS

View File

@ -96,7 +96,7 @@ const uint32_t EVENT_SET_SWITCH_STATE_TO_DB_BY_USERID = 0x0026;
const uint32_t RETRY_INTERVAL_UNITE = 1000;
const uint32_t RETRY_INTERVAL_OF_INIT_REQUEST_MANAGER = 5 * RETRY_INTERVAL_UNITE;
const uint32_t RETRY_INTERVAL_OF_UNLOAD_SA = 30 * RETRY_INTERVAL_UNITE;
const uint32_t RETRY_INTERVAL_OF_UNLOAD_SA = 30 * 60 * RETRY_INTERVAL_UNITE;
const int COMMON_SA_ID = 4353;
const int COMMON_SWITCH_STATE_ID = 30;
const std::u16string COMMON_DESCRIPTION = u"location.IHifenceAbility";
@ -171,6 +171,7 @@ void LocatorAbility::OnStop()
LBSLOGD(LOCATOR, "LocatorAbility::reset LocationWorkingState failed.");
}
SetLocationhubStateToSyspara(LOCATIONHUB_STATE_UNLOAD);
LocatorRequiredDataManager::GetInstance()->UnregisterWifiCallBack();
LBSLOGI(LOCATOR, "LocatorAbility::OnStop ability stopped.");
}
@ -958,13 +959,14 @@ LocationErrCode LocatorAbility::StartLocating(std::unique_ptr<RequestConfig>& re
Security::AccessToken::AccessTokenKit::GetPermissionUsedType(request->GetTokenId(),
ACCESS_APPROXIMATELY_LOCATION);
request->SetPermUsedType(static_cast<int>(type));
LocatorRequiredDataManager::GetInstance()->SendWifiScanEvent();
#ifdef EMULATOR_ENABLED
// for emulator, report cache location is unnecessary
HandleStartLocating(request, callback);
#else
if (NeedReportCacheLocation(request, callback)) {
LBSLOGI(LOCATOR, "report cache location to %{public}s", identity.GetBundleName().c_str());
LocatorBackgroundProxy::GetInstance()->StartLocator();
callback->AsObject()->RemoveDeathRecipient(death);
} else {
HandleStartLocating(request, callback);
@ -1096,6 +1098,7 @@ LocationErrCode LocatorAbility::StopLocating(sptr<ILocatorCallback>& callback)
LocationErrCode LocatorAbility::GetCacheLocation(std::unique_ptr<Location>& loc, AppIdentity &identity)
{
LocatorBackgroundProxy::GetInstance()->StartLocator();
if (locatorHandler_ == nullptr) {
return ERRCODE_SERVICE_UNAVAILABLE;
}

View File

@ -34,6 +34,7 @@
#include "accesstoken_kit.h"
#include "tokenid_kit.h"
#include "ipc_skeleton.h"
#ifdef BGTASKMGR_SUPPORT
#include "background_mode.h"
@ -48,6 +49,9 @@ namespace OHOS {
namespace Location {
std::mutex LocatorBackgroundProxy::requestListMutex_;
std::mutex LocatorBackgroundProxy::locatorMutex_;
const uint32_t EVENT_STARTLOCATING = 0x0100;
const uint32_t EVENT_STOPLOCATING = 0x0200;
LocatorBackgroundProxy* LocatorBackgroundProxy::GetInstance()
{
static LocatorBackgroundProxy data;
@ -57,6 +61,8 @@ LocatorBackgroundProxy* LocatorBackgroundProxy::GetInstance()
LocatorBackgroundProxy::LocatorBackgroundProxy()
{
InitArgsFromProp();
locatorBackgroundHandler_ = std::make_shared<LocatorBackgroundHandler>(AppExecFwk::EventRunner::Create(true,
AppExecFwk::ThreadMode::FFRT));
if (!featureSwitch_) {
return;
}
@ -66,7 +72,7 @@ LocatorBackgroundProxy::LocatorBackgroundProxy()
requestsMap_->insert(make_pair(curUserId_, requestsList_));
auto requestConfig = std::make_unique<RequestConfig>();
requestConfig->SetPriority(PRIORITY_LOW_POWER);
requestConfig->SetPriority(PRIORITY_FAST_FIRST_FIX);
requestConfig->SetTimeInterval(timeInterval_);
callback_ = sptr<mLocatorCallback>(new (std::nothrow) LocatorBackgroundProxy::mLocatorCallback());
if (callback_ == nullptr) {
@ -81,9 +87,12 @@ LocatorBackgroundProxy::LocatorBackgroundProxy()
request_->SetPackageName(PROC_NAME);
request_->SetRequestConfig(*requestConfig);
request_->SetLocatorCallBack(callback_);
request_->SetUuid(PROC_NAME);
request_->SetTokenId(IPCSkeleton::GetCallingTokenID());
request_->SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID());
SubscribeSaStatusChangeListerner();
isUserSwitchSubscribed_ = LocatorBackgroundProxy::UserSwitchSubscriber::Subscribe();
proxySwtich_ = (LocationConfigManager::GetInstance()->GetLocationSwitchState() == ENABLED);
proxySwtich_ = (LocationDataRdbManager::QuerySwitchState() == ENABLED);
RegisterAppStateObserver();
}
@ -122,12 +131,9 @@ void LocatorBackgroundProxy::SubscribeSaStatusChangeListerner()
void LocatorBackgroundProxy::StartLocatorThread()
{
auto requestManager = RequestManager::GetInstance();
auto locatorAbility = LocatorAbility::GetInstance();
std::this_thread::sleep_for(std::chrono::seconds(timeInterval_));
std::unique_lock<std::mutex> lock(locatorMutex_, std::defer_lock);
lock.lock();
isWating_ = false;
if (isLocating_ || !proxySwtich_ || requestsList_->empty()) {
if (isLocating_ || !proxySwtich_) {
LBSLOGD(LOCATOR_BACKGROUND_PROXY, "cancel locating");
lock.unlock();
return;
@ -136,7 +142,6 @@ void LocatorBackgroundProxy::StartLocatorThread()
lock.unlock();
LBSLOGI(LOCATOR_BACKGROUND_PROXY, "real start locating");
requestManager->HandleStartLocating(request_);
locatorAbility->ReportLocationStatus(callback_, SESSION_START);
}
void LocatorBackgroundProxy::StopLocatorThread()
@ -156,10 +161,13 @@ void LocatorBackgroundProxy::StopLocatorThread()
void LocatorBackgroundProxy::StopLocator()
{
locatorBackgroundHandler_->SendHighPriorityEvent(EVENT_STOPLOCATING, 0, 0);
}
void LocatorBackgroundProxy::StartLocator()
{
locatorBackgroundHandler_->SendHighPriorityEvent(EVENT_STARTLOCATING, 0, 0);
locatorBackgroundHandler_->SendHighPriorityEvent(EVENT_STOPLOCATING, 0, DEFAULT_TIMEOUT_5S);
}
void LocatorBackgroundProxy::UpdateListOnRequestChange(const std::shared_ptr<Request>& request)
@ -178,38 +186,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 +256,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 +290,7 @@ 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);
}
LocatorBackgroundProxy::GetInstance()->StopLocator();
}
void LocatorBackgroundProxy::mLocatorCallback::OnLocatingStatusChange(const int status)
@ -526,5 +492,28 @@ void AppStateChangeCallback::OnForegroundApplicationChanged(const AppExecFwk::Ap
"The state of App changed, uid = %{public}d, pid = %{public}d, state = %{public}d", uid, pid, state);
requestManager->HandlePowerSuspendChanged(pid, uid, state);
}
LocatorBackgroundHandler::LocatorBackgroundHandler(
const std::shared_ptr<AppExecFwk::EventRunner>& runner) : EventHandler(runner) {}
LocatorBackgroundHandler::~LocatorBackgroundHandler() {}
void LocatorBackgroundHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
{
auto locatorBackgroundProxy = LocatorBackgroundProxy::GetInstance();
uint32_t eventId = event->GetInnerEventId();
switch (eventId) {
case EVENT_STARTLOCATING: {
locatorBackgroundProxy->StartLocatorThread();
break;
}
case EVENT_STOPLOCATING: {
locatorBackgroundProxy->StopLocatorThread();
break;
}
default:
break;
}
}
} // namespace OHOS
} // namespace Location

View File

@ -29,14 +29,15 @@ const uint32_t EVENT_GET_WIFI_LIST = 0x0300;
const uint32_t EVENT_REGISTER_WIFI_CALLBACK = 0x0400;
const uint32_t EVENT_UNREGISTER_WIFI_CALLBACK = 0x0500;
const int32_t DEFAULT_TIMEOUT_4S = 4000;
const int32_t DEFAULT_TIMEOUT_MS = 1500;
LocatorRequiredDataManager::LocatorRequiredDataManager()
{
#ifdef WIFI_ENABLE
WifiInfoInit();
#endif
scanHandler_ = std::make_shared<ScanHandler>(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT));
wifiSdkHandler_ =
std::make_shared<WifiSdkHandler>(AppExecFwk::EventRunner::Create(true, AppExecFwk::ThreadMode::FFRT));
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendEvent(EVENT_REGISTER_WIFI_CALLBACK, 0, 0);
}
}
LocatorRequiredDataManager* LocatorRequiredDataManager::GetInstance()
@ -47,6 +48,44 @@ LocatorRequiredDataManager* LocatorRequiredDataManager::GetInstance()
LocatorRequiredDataManager::~LocatorRequiredDataManager()
{
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendEvent(EVENT_UNREGISTER_WIFI_CALLBACK, 0, 0);
}
}
void LocatorRequiredDataManager::SyncStillMovementState(bool state)
{
std::unique_lock<std::mutex> lock(lastStillTimeMutex_);
if (state) {
lastStillTime_ = CommonUtils::GetCurrentTimeStampMs();
SendWifiScanEvent();
} else {
lastStillTime_ = 0;
}
}
void LocatorRequiredDataManager::SetToObtainCellinfo()
{
bool needScan = false;
wifiScanTimestamp_ = CommonUtils::GetCurrentTimeStampMs();
std::unique_lock<std::mutex> lock(wifiScanCompleteTimestampMutex_);
wifiScanCompleteTimestamp_ = wifiScanTimestamp_ + 1;
}
void LocatorRequiredDataManager::SendWifiScanEvent()
{
if (scanHandler_ != nullptr) {
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(
EVENT_START_SCAN, 1);
scanHandler_->SendEvent(event);
}
}
void LocatorRequiredDataManager::SendGetWifiListEvent(int timeout)
{
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendHighPriorityEvent(EVENT_GET_WIFI_LIST, 0, timeout);
}
}
__attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::RegisterCallback(
@ -59,21 +98,20 @@ __attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::
callbacksMap_[callback] = identity;
LBSLOGD(LOCATOR, "after RegisterCallback, callback size:%{public}s",
std::to_string(callbacksMap_.size()).c_str());
if (!IsWifiCallbackRegistered() && wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendEvent(EVENT_REGISTER_WIFI_CALLBACK, 0, 0);
}
bool needScan = false;
if (config->GetNeedStartScan() && (callbacksMap_.size() == 1 || !IsWifiCallbackRegistered())) {
if (config->GetNeedStartScan()) {
needScan = true;
}
lock.unlock();
if (needScan) {
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendEvent(EVENT_REGISTER_WIFI_CALLBACK, 0, 0);
}
timeInterval_ = config->GetScanIntervalMs();
if (scanHandler_ != nullptr) {
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(
EVENT_START_SCAN, config->GetFixNumber());
scanHandler_->SendEvent(event);
}
SendWifiScanEvent();
SendGetWifiListEvent(DEFAULT_TIMEOUT_4S >= config->GetScanTimeoutMs() ?
config->GetScanTimeoutMs() : DEFAULT_TIMEOUT_4S);
} else {
SendGetWifiListEvent(0);
}
#endif
} else if (config->GetType() == LocatingRequiredDataType::BLUE_TOOTH) {
@ -97,12 +135,6 @@ LocationErrCode LocatorRequiredDataManager::UnregisterCallback(const sptr<IRemot
return ERRCODE_SUCCESS;
}
lock.unlock();
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendEvent(EVENT_UNREGISTER_WIFI_CALLBACK, 0, 0);
}
if (scanHandler_ != nullptr) {
scanHandler_->SendEvent(EVENT_STOP_SCAN, 0, 0);
}
#endif
return ERRCODE_SUCCESS;
}
@ -178,11 +210,6 @@ void LocatorBleCallbackWapper::OnNotifyMsgReportFromLpDevice(const Bluetooth::UU
#endif
#ifdef WIFI_ENABLE
void LocatorRequiredDataManager::WifiInfoInit()
{
wifiScanPtr_ = Wifi::WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
}
bool LocatorRequiredDataManager::IsWifiCallbackRegistered()
{
std::unique_lock<std::mutex> lock(wifiRegisteredMutex_);
@ -237,6 +264,8 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::GetWifiScan
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
}
wifiScanInfo_ = wifiScanInfo;
getWifiScanInfoTimestamp_ = CommonUtils::GetCurrentTimeStampMs();
}
std::vector<std::shared_ptr<LocatingRequiredData>> LocatorRequiredDataManager::GetLocatingRequiredDataByWifi(
@ -258,6 +287,18 @@ std::vector<std::shared_ptr<LocatingRequiredData>> LocatorRequiredDataManager::G
return res;
}
void LocatorRequiredDataManager::UpdateWifiScanCompleteTimestamp()
{
std::unique_lock<std::mutex> lock(wifiScanCompleteTimestampMutex_);
wifiScanCompleteTimestamp_ = CommonUtils::GetCurrentTimeStampMs();
}
int64_t LocatorRequiredDataManager::GetWifiScanCompleteTimestamp()
{
std::unique_lock<std::mutex> lock(wifiScanCompleteTimestampMutex_);
return wifiScanCompleteTimestamp_;
}
void LocatorWifiScanEventCallback::OnWifiScanStateChanged(int state, int size)
{
LBSLOGD(LOCATOR, "OnWifiScanStateChanged state=%{public}d", state);
@ -265,6 +306,7 @@ void LocatorWifiScanEventCallback::OnWifiScanStateChanged(int state, int size)
LBSLOGE(LOCATOR, "OnWifiScanStateChanged false");
}
auto dataManager = LocatorRequiredDataManager::GetInstance();
dataManager->UpdateWifiScanCompleteTimestamp();
if (!dataManager->IsConnecting()) {
LBSLOGE(LOCATOR, "%{public}s no valid callback, return", __func__);
return;
@ -307,38 +349,27 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiSc
LBSLOGE(LOCATOR, "%{public}s no valid callback, return", __func__);
return;
}
if (!IsConnecting()) {
if (scanHandler_ != nullptr) {
scanHandler_->RemoveEvent(EVENT_START_SCAN);
}
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->RemoveEvent(EVENT_GET_WIFI_LIST);
}
return;
}
#ifdef WIFI_ENABLE
if (wifiScanPtr_ == nullptr) {
bool needScan = false;
// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>ɨ<EFBFBD><EFBFBD><E8B3AC>1.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>ɨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int64_t time = CommonUtils::GetCurrentTimeStampMs();
if ((time - wifiScanTimestamp_ > DEFAULT_TIMEOUT_MS &&
GetWifiScanCompleteTimestamp() > wifiScanTimestamp_)) {
needScan = true;
}
if (!needScan) {
if (GetWifiScanCompleteTimestamp() > wifiScanTimestamp_) {
SendGetWifiListEvent(0);
}
return;
}
int ret = wifiScanPtr_->Scan();
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);
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendHighPriorityEvent(EVENT_GET_WIFI_LIST, 0, 0);
}
} else {
if (wifiSdkHandler_ != nullptr) {
wifiSdkHandler_->SendHighPriorityEvent(EVENT_GET_WIFI_LIST, 0, DEFAULT_TIMEOUT_4S);
}
SendGetWifiListEvent(0);
}
#endif
if (fixNumber == 1) {
return;
}
LBSLOGD(LOCATOR, "StartWifiScan timeInterval_=%{public}d", timeInterval_);
if (scanHandler_ != nullptr) {
scanHandler_->SendHighPriorityEvent(EVENT_START_SCAN, 0, timeInterval_);
}
}
bool LocatorRequiredDataManager::IsConnecting()

View File

@ -37,6 +37,7 @@ static constexpr double MAXIMUM_FUZZY_LOCATION_DISTANCE = 4000.0; // Unit m
static constexpr double MINIMUM_FUZZY_LOCATION_DISTANCE = 3000.0; // Unit m
static constexpr int GNSS_FIX_CACHED_TIME = 25;
static constexpr int NLP_FIX_CACHED_TIME = 25;
static constexpr int WHITE_FIX_CACHED_TIME = 60;
ReportManager* ReportManager::GetInstance()
{
@ -343,6 +344,16 @@ std::unique_ptr<Location> ReportManager::GetCacheLocation(const std::shared_ptr<
{
int64_t curTime = CommonUtils::GetCurrentTimeStamp();
std::unique_ptr<Location> cacheLocation = nullptr;
std::string packageName = request->GetPackageName();
if (HookUtils::ExecuteHookWhenCheckAppForCacheTime(packageName)) {
if (!CommonUtils::DoubleEqual(cacheGnssLocation_.GetLatitude(), MIN_LATITUDE - 1) &&
(curTime - cacheGnssLocation_.GetTimeStamp() / MILLI_PER_SEC) <= WHITE_FIX_CACHED_TIME) {
cacheLocation = std::make_unique<Location>(cacheGnssLocation_);
} else if (!CommonUtils::DoubleEqual(cacheNlpLocation_.GetLatitude(), MIN_LATITUDE - 1) &&
(curTime - cacheNlpLocation_.GetTimeStamp() / MILLI_PER_SEC) <= WHITE_FIX_CACHED_TIME) {
cacheLocation = std::make_unique<Location>(cacheNlpLocation_);
}
} else {
if (!CommonUtils::DoubleEqual(cacheGnssLocation_.GetLatitude(), MIN_LATITUDE - 1) &&
(curTime - cacheGnssLocation_.GetTimeStamp() / MILLI_PER_SEC) <= GNSS_FIX_CACHED_TIME) {
cacheLocation = std::make_unique<Location>(cacheGnssLocation_);
@ -350,6 +361,7 @@ std::unique_ptr<Location> ReportManager::GetCacheLocation(const std::shared_ptr<
(curTime - cacheNlpLocation_.GetTimeStamp() / MILLI_PER_SEC) <= NLP_FIX_CACHED_TIME) {
cacheLocation = std::make_unique<Location>(cacheNlpLocation_);
}
}
std::unique_ptr<Location> finalLocation = GetPermittedLocation(request, cacheLocation);
if (!ResultCheck(finalLocation, request)) {
return nullptr;