mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-23 23:10:05 +00:00
commit
300c60f7db
@ -41,6 +41,7 @@ static std::random_device g_randomDevice;
|
||||
static std::mt19937 g_gen(g_randomDevice());
|
||||
static std::uniform_int_distribution<> g_dis(0, 15); // random between 0 and 15
|
||||
static std::uniform_int_distribution<> g_dis2(8, 11); // random between 8 and 11
|
||||
const int64_t SEC_TO_NANO = 1000 * 1000 * 1000;
|
||||
|
||||
int CommonUtils::AbilityConvertToId(const std::string ability)
|
||||
{
|
||||
@ -420,5 +421,17 @@ bool CommonUtils::CheckAppForUser(int32_t uid)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t CommonUtils::GetSinceBootTime()
|
||||
{
|
||||
int result;
|
||||
struct timespec ts;
|
||||
result = clock_gettime(CLOCK_BOOTTIME, &ts);
|
||||
if (result == 0) {
|
||||
return ts.tv_sec * SEC_TO_NANO + ts.tv_nsec;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -177,6 +177,7 @@ public:
|
||||
static bool GetEdmPolicy(std::string& name);
|
||||
static std::string GenerateUuid();
|
||||
static bool CheckAppForUser(int32_t uid);
|
||||
static int64_t GetSinceBootTime();
|
||||
};
|
||||
|
||||
class CountDownLatch {
|
||||
|
@ -1430,6 +1430,9 @@ int32_t GnssAbility::ReportMockedLocation(const std::shared_ptr<Location> locati
|
||||
LBSLOGE(GNSS, "location mock is enabled, do not report gnss location!");
|
||||
return ERR_OK;
|
||||
}
|
||||
location->SetTimeSinceBoot(CommonUtils::GetSinceBootTime());
|
||||
location->SetTimeStamp(CommonUtils::GetCurrentTimeStamp() * MICRO_PER_MILLI);
|
||||
location->SetLocationSourceType(LocationSourceType::GNSS_TYPE);
|
||||
ReportLocationInfo(GNSS_ABILITY, location);
|
||||
#ifdef FEATURE_PASSIVE_SUPPORT
|
||||
ReportLocationInfo(PASSIVE_ABILITY, location);
|
||||
|
@ -77,12 +77,12 @@ bool ReportManager::OnReportLocation(const std::unique_ptr<Location>& location,
|
||||
for (auto iter = requestList.begin(); iter != requestList.end(); iter++) {
|
||||
auto request = *iter;
|
||||
WriteNetWorkReportEvent(abilityName, request, location);
|
||||
if (abilityName == NETWORK_ABILITY && (request->GetUuid() == location->GetUuid())) {
|
||||
ProcessRequestForReport(request, deadRequests, location, abilityName);
|
||||
break;
|
||||
} else if (abilityName == NETWORK_ABILITY && (request->GetUuid() != location->GetUuid())) {
|
||||
continue;
|
||||
} else {
|
||||
if (abilityName == NETWORK_ABILITY) {
|
||||
if (request->GetUuid() == location->GetUuid() || location->GetIsFromMock()) {
|
||||
ProcessRequestForReport(request, deadRequests, location, abilityName);
|
||||
break;
|
||||
}
|
||||
} else if (abilityName == GNSS_ABILITY || abilityName == PASSIVE_ABILITY) {
|
||||
ProcessRequestForReport(request, deadRequests, location, abilityName);
|
||||
}
|
||||
}
|
||||
@ -276,7 +276,8 @@ bool ReportManager::ResultCheck(const std::unique_ptr<Location>& location,
|
||||
LBSLOGE(REPORT_MANAGER, "accuracy check fail, do not report location");
|
||||
return false;
|
||||
}
|
||||
if (CommonUtils::DoubleEqual(request->GetLastLocation()->GetLatitude(), MIN_LATITUDE - 1)) {
|
||||
if (CommonUtils::DoubleEqual(request->GetLastLocation()->GetLatitude(), MIN_LATITUDE - 1) ||
|
||||
request->GetLastLocation()->GetIsFromMock() != location->GetIsFromMock()) {
|
||||
LBSLOGD(REPORT_MANAGER, "no valid cache location, no need to check");
|
||||
return true;
|
||||
}
|
||||
|
@ -407,6 +407,9 @@ int32_t NetworkAbility::ReportMockedLocation(const std::shared_ptr<Location> loc
|
||||
LBSLOGE(NETWORK, "location mock is enabled, do not report network location!");
|
||||
return ERR_OK;
|
||||
}
|
||||
location->SetTimeSinceBoot(CommonUtils::GetSinceBootTime());
|
||||
location->SetTimeStamp(CommonUtils::GetCurrentTimeStamp() * MICRO_PER_MILLI);
|
||||
location->SetLocationSourceType(LocationSourceType::NETWORK_TYPE);
|
||||
ReportLocationInfo(NETWORK_ABILITY, location);
|
||||
#ifdef FEATURE_PASSIVE_SUPPORT
|
||||
ReportLocationInfo(PASSIVE_ABILITY, location);
|
||||
|
@ -63,9 +63,20 @@ int NetworkCallbackHost::OnRemoteRequest(
|
||||
void NetworkCallbackHost::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
LBSLOGD(NETWORK, "NetworkCallbackHost::OnLocationReport");
|
||||
auto networkAbility = NetworkAbility::GetInstance();
|
||||
if (networkAbility == nullptr) {
|
||||
LBSLOGE(NETWORK, "ReportLocation: network ability is nullptr.");
|
||||
return;
|
||||
}
|
||||
if (networkAbility->IsMockEnabled()) {
|
||||
LBSLOGE(NETWORK, "location mock is enabled, do not report network location!");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Location> locationNew = std::make_shared<Location>(*location);
|
||||
NetworkAbility::GetInstance()->ReportLocationInfo(NETWORK_ABILITY, locationNew);
|
||||
NetworkAbility::GetInstance()->ReportLocationInfo(PASSIVE_ABILITY, locationNew);
|
||||
if (locationNew->GetLocationSourceType() == LocationSourceType::NETWORK_TYPE) {
|
||||
NetworkAbility::GetInstance()->ReportLocationInfo(PASSIVE_ABILITY, locationNew);
|
||||
}
|
||||
WriteLocationInnerEvent(NETWORK_CALLBACK_LOCATION, {"speed", std::to_string(location->GetSpeed()),
|
||||
"accuracy", std::to_string(location->GetAccuracy()),
|
||||
"locationTimestamp", std::to_string(location->GetTimeStamp() / MILLI_PER_SEC),
|
||||
|
Loading…
Reference in New Issue
Block a user