Merge pull request !991 from liuxinbing/master
This commit is contained in:
openharmony_ci 2024-11-21 02:44:35 +00:00 committed by Gitee
commit 326686dfbd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 35 additions and 5 deletions

View File

@ -55,6 +55,7 @@ private:
Location cacheGnssLocation_;
Location cacheNlpLocation_;
std::mutex lastLocationMutex_;
std::atomic<int64_t> lastResetRecordTime_;
std::unique_ptr<Location> ApproximatelyLocation(const std::unique_ptr<Location>& location);
bool ProcessRequestForReport(std::shared_ptr<Request>& request,
std::unique_ptr<std::list<std::shared_ptr<Request>>>& deadRequests,
@ -64,6 +65,8 @@ private:
std::unique_ptr<Location> ExecuteReportProcess(std::shared_ptr<Request>& request,
std::unique_ptr<Location>& location, std::string abilityName);
void UpdateLastLocation(const std::unique_ptr<Location>& location);
void LocationReportDelayTimeCheck(const std::unique_ptr<Location>& location,
const std::shared_ptr<Request>& request);
};
} // namespace OHOS
} // namespace Location

View File

@ -112,6 +112,7 @@ const int LOCATIONHUB_STATE_UNLOAD = 0;
const int LOCATIONHUB_STATE_LOAD = 1;
const int MAX_SIZE = 100;
const int TIMEOUT_WATCHDOG = 60; // s
const int INVALID_REQUESTS_SIZE = 20;
LocatorAbility* LocatorAbility::GetInstance()
{
@ -1597,6 +1598,9 @@ LocationErrCode LocatorAbility::RemoveInvalidRequests()
#endif
}
LBSLOGI(LOCATOR, "request num : %{public}d, invalid request num: %{public}d", requestNum, invalidRequestNum);
if (invalidRequestList.size() > INVALID_REQUESTS_SIZE) {
return ERRCODE_SUCCESS;
}
for (auto& item : invalidRequestList) {
sptr<ILocatorCallback> callback = item->GetLocatorCallBack();
StopLocating(callback);

View File

@ -26,7 +26,6 @@
#include "location_log_event_ids.h"
#include "common_hisysevent.h"
#include "permission_manager.h"
#include "hook_utils.h"
namespace OHOS {
@ -37,6 +36,8 @@ 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 CACHED_TIME = 25;
static constexpr int LONG_CACHE_DURATION = 60;
static constexpr int MAX_LOCATION_REPORT_DELAY_TIME = 30000; // Unit ms
static constexpr int MIN_RESET_TIME_THRESHOLD = 1 * 60 * 60 * 1000; // Unit ms
ReportManager* ReportManager::GetInstance()
{
@ -48,6 +49,7 @@ ReportManager::ReportManager()
{
clock_gettime(CLOCK_REALTIME, &lastUpdateTime_);
offsetRandom_ = CommonUtils::DoubleRandom(0, 1);
lastResetRecordTime_ = CommonUtils::GetSinceBootTime();
}
ReportManager::~ReportManager() {}
@ -133,6 +135,7 @@ bool ReportManager::ProcessRequestForReport(std::shared_ptr<Request>& request,
ACCESS_APPROXIMATELY_LOCATION, permUsedType, 0, 1);
return false;
}
LocationReportDelayTimeCheck(finalLocation, request);
UpdateLocationByRequest(request->GetTokenId(), request->GetTokenIdEx(), finalLocation);
finalLocation = ExecuteReportProcess(request, finalLocation, abilityName);
if (finalLocation == nullptr) {
@ -165,6 +168,26 @@ bool ReportManager::ProcessRequestForReport(std::shared_ptr<Request>& request,
return true;
}
void ReportManager::LocationReportDelayTimeCheck(const std::unique_ptr<Location>& location,
const std::shared_ptr<Request>& request)
{
if (location == nullptr || request == nullptr) {
return;
}
int64_t currentTime = CommonUtils::GetSinceBootTime();
long deltaMs = (currentTime - location->GetTimeSinceBoot()) / NANOS_PER_MILLI;
if (deltaMs > MAX_LOCATION_REPORT_DELAY_TIME) {
long recordDeltaMs = (currentTime - lastResetRecordTime_) / NANOS_PER_MILLI;
if (recordDeltaMs < MIN_RESET_TIME_THRESHOLD) {
return;
}
LBSLOGE(REPORT_MANAGER, "%{public}s: %{public}d check fail, current deltaMs = %{public}ld", __func__,
request->GetTokenId(), deltaMs);
lastResetRecordTime_ = currentTime;
_exit(0);
}
}
std::unique_ptr<Location> ReportManager::ExecuteReportProcess(std::shared_ptr<Request>& request,
std::unique_ptr<Location>& location, std::string abilityName)
{

View File

@ -227,8 +227,8 @@ bool RequestManager::RestorRequest(std::shared_ptr<Request> newRequest)
}
sptr<RequestConfig> newConfig = newRequest->GetRequestConfig();
std::list<std::shared_ptr<Request>> requestWithSameCallback = iterator->second;
for (auto iter = requestWithSameCallback.begin(); iter != requestWithSameCallback.end(); ++iter) {
auto requestWithSameCallback = &(iterator->second);
for (auto iter = requestWithSameCallback->begin(); iter != requestWithSameCallback->end(); ++iter) {
auto request = *iter;
if (request == nullptr) {
continue;
@ -243,7 +243,7 @@ bool RequestManager::RestorRequest(std::shared_ptr<Request> newRequest)
return false;
}
}
requestWithSameCallback.push_back(newRequest);
requestWithSameCallback->push_back(newRequest);
LBSLOGD(REQUEST_MANAGER, "add new receiver with old callback");
return true;
}
@ -340,7 +340,7 @@ void RequestManager::HandleStopLocating(sptr<ILocatorCallback> callback)
LBSLOGD(REQUEST_MANAGER, "stop callback");
auto iterator = receivers->find(deadCallback);
if (iterator == receivers->end()) {
LBSLOGD(REQUEST_MANAGER, "this callback has no record in receiver map");
LBSLOGE(REQUEST_MANAGER, "this callback has no record in receiver map");
lock.unlock();
return;
}