!924 新增startUsingPermission返回值判断

Merge pull request !924 from liuxinbing/master
This commit is contained in:
openharmony_ci 2024-09-23 10:49:25 +00:00 committed by Gitee
commit bd2710dc6a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 56 additions and 56 deletions

View File

@ -18,6 +18,7 @@
#include "accesstoken_kit.h"
#include "event_runner.h"
#include "privacy_kit.h"
#include "privacy_error.h"
#include "system_ability_definition.h"
#include "uri.h"
@ -96,7 +97,6 @@ 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 float_t PRECISION = 0.000001;
const int COMMON_SA_ID = 4353;
const int COMMON_SWITCH_STATE_ID = 30;
const std::u16string COMMON_DESCRIPTION = u"location.IHifenceAbility";
@ -1009,55 +1009,55 @@ int LocatorAbility::UpdatePermissionUsedRecord(uint32_t tokenId, std::string per
bool LocatorAbility::NeedReportCacheLocation(const std::shared_ptr<Request>& request, sptr<ILocatorCallback>& callback)
{
if (reportManager_ == nullptr || request == nullptr) {
if (reportManager_ == nullptr || request == nullptr || callback == nullptr ||
!IsCacheVaildScenario(request->GetRequestConfig())) {
return false;
}
// report cache location
if (IsSingleRequest(request->GetRequestConfig()) && IsCacheVaildScenario(request->GetRequestConfig())) {
auto cacheLocation = reportManager_->GetCacheLocation(request);
if (cacheLocation != nullptr && callback != nullptr) {
auto workRecordStatistic = WorkRecordStatistic::GetInstance();
if (!workRecordStatistic->Update("CacheLocation", 1)) {
LBSLOGE(LOCATOR, "%{public}s line:%{public}d workRecordStatistic::Update failed", __func__, __LINE__);
}
int ret = PrivacyKit::StartUsingPermission(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION);
if (ret != ERRCODE_SUCCESS && IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "StartUsingPermission failed ret=%{public}d", ret);
return false;
}
// add location permission using record
ret = UpdatePermissionUsedRecord(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION,
request->GetPermUsedType(), 1, 0);
if (ret != ERRCODE_SUCCESS && IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "UpdatePermissionUsedRecord failed ret=%{public}d", ret);
return false;
}
callback->OnLocationReport(cacheLocation);
PrivacyKit::StopUsingPermission(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION);
if (locatorHandler_ != nullptr &&
locatorHandler_->SendHighPriorityEvent(EVENT_UPDATE_LASTLOCATION_REQUESTNUM, 0, 1)) {
LBSLOGD(LOCATOR, "%{public}s: EVENT_UPDATE_LASTLOCATION_REQUESTNUM Send Success", __func__);
}
return true;
}
} else if (!IsSingleRequest(request->GetRequestConfig()) && IsCacheVaildScenario(request->GetRequestConfig())) {
auto cacheLocation = reportManager_->GetCacheLocation(request);
if (cacheLocation != nullptr && callback != nullptr) {
auto workRecordStatistic = WorkRecordStatistic::GetInstance();
if (!workRecordStatistic->Update("CacheLocation", 1)) {
LBSLOGE(LOCATOR, "%{public}s line:%{public}d workRecordStatistic::Update failed", __func__, __LINE__);
}
// add location permission using record
int ret = UpdatePermissionUsedRecord(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION,
request->GetPermUsedType(), 1, 0);
if (ret != ERRCODE_SUCCESS && IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "UpdatePermissionUsedRecord failed ret=%{public}d", ret);
return false;
}
callback->OnLocationReport(cacheLocation);
}
auto cacheLocation = reportManager_->GetCacheLocation(request);
if (cacheLocation == nullptr) {
return false;
}
if (IsSingleRequest(request->GetRequestConfig())) {
auto workRecordStatistic = WorkRecordStatistic::GetInstance();
if (!workRecordStatistic->Update("CacheLocation", 1)) {
LBSLOGE(LOCATOR, "%{public}s line:%{public}d workRecordStatistic::Update failed", __func__, __LINE__);
}
int ret = PrivacyKit::StartUsingPermission(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION);
if (ret != ERRCODE_SUCCESS && ret != Security::AccessToken::ERR_PERMISSION_ALREADY_START_USING &&
IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "StartUsingPermission failed ret=%{public}d", ret);
return false;
}
// add location permission using record
ret = UpdatePermissionUsedRecord(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION,
request->GetPermUsedType(), 1, 0);
if (ret != ERRCODE_SUCCESS && IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "UpdatePermissionUsedRecord failed ret=%{public}d", ret);
return false;
}
callback->OnLocationReport(cacheLocation);
PrivacyKit::StopUsingPermission(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION);
if (locatorHandler_ != nullptr &&
locatorHandler_->SendHighPriorityEvent(EVENT_UPDATE_LASTLOCATION_REQUESTNUM, 0, 1)) {
LBSLOGD(LOCATOR, "%{public}s: EVENT_UPDATE_LASTLOCATION_REQUESTNUM Send Success", __func__);
}
return true;
} else {
auto workRecordStatistic = WorkRecordStatistic::GetInstance();
if (!workRecordStatistic->Update("CacheLocation", 1)) {
LBSLOGE(LOCATOR, "%{public}s line:%{public}d workRecordStatistic::Update failed", __func__, __LINE__);
}
// add location permission using record
int ret = UpdatePermissionUsedRecord(request->GetTokenId(), ACCESS_APPROXIMATELY_LOCATION,
request->GetPermUsedType(), 1, 0);
if (ret != ERRCODE_SUCCESS && IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "UpdatePermissionUsedRecord failed ret=%{public}d", ret);
return false;
}
callback->OnLocationReport(cacheLocation);
return true;
}
return false;
}
void LocatorAbility::HandleStartLocating(const std::shared_ptr<Request>& request, sptr<ILocatorCallback>& callback)
@ -1110,7 +1110,8 @@ LocationErrCode LocatorAbility::GetCacheLocation(std::unique_ptr<Location>& loc,
loc = reportManager_->GetPermittedLocation(request, lastLocation);
reportManager_->UpdateLocationByRequest(identity.GetTokenId(), identity.GetTokenIdEx(), loc);
int ret = PrivacyKit::StartUsingPermission(identity.GetTokenId(), ACCESS_APPROXIMATELY_LOCATION);
if (ret != ERRCODE_SUCCESS && IsHapCaller(identity.GetTokenId())) {
if (ret != ERRCODE_SUCCESS && ret != Security::AccessToken::ERR_PERMISSION_ALREADY_START_USING &&
IsHapCaller(request->GetTokenId())) {
LBSLOGE(LOCATOR, "StartUsingPermission failed ret=%{public}d", ret);
loc = nullptr;
}
@ -1118,14 +1119,9 @@ LocationErrCode LocatorAbility::GetCacheLocation(std::unique_ptr<Location>& loc,
locatorHandler_->SendHighPriorityEvent(EVENT_GET_CACHED_LOCATION_FAILED, identity.GetTokenId(), 0);
return ERRCODE_LOCATING_FAIL;
}
if (fabs(loc->GetLatitude() - 0.0) > PRECISION
&& fabs(loc->GetLongitude() - 0.0) > PRECISION) {
// add location permission using record
locatorHandler_->SendHighPriorityEvent(EVENT_GET_CACHED_LOCATION_SUCCESS, identity.GetTokenId(), 0);
return ERRCODE_SUCCESS;
}
locatorHandler_->SendHighPriorityEvent(EVENT_GET_CACHED_LOCATION_FAILED, identity.GetTokenId(), 0);
return ERRCODE_LOCATING_FAIL;
// add location permission using record
locatorHandler_->SendHighPriorityEvent(EVENT_GET_CACHED_LOCATION_SUCCESS, identity.GetTokenId(), 0);
return ERRCODE_SUCCESS;
}
LocationErrCode LocatorAbility::ReportLocation(

View File

@ -147,6 +147,7 @@ bool ReportManager::ProcessRequestForReport(std::shared_ptr<Request>& request,
ACCESS_APPROXIMATELY_LOCATION, request->GetPermUsedType(), 1, 0);
if (ret != ERRCODE_SUCCESS && locatorAbility->IsHapCaller(request->GetTokenId())) {
LBSLOGE(REPORT_MANAGER, "UpdatePermissionUsedRecord failed ret=%{public}d", ret);
RequestManager::GetInstance()->ReportLocationError(LOCATING_FAILED_LOCATION_PERMISSION_DENIED, request);
return false;
}
LBSLOGI(REPORT_MANAGER, "report location to %{public}d, TimeSinceBoot : %{public}s, SourceType : %{public}d",

View File

@ -16,6 +16,7 @@
#include "request_manager.h"
#include "privacy_kit.h"
#include "privacy_error.h"
#include "common_utils.h"
#include "constant_definition.h"
@ -100,7 +101,8 @@ bool RequestManager::UpdateUsingApproximatelyPermission(std::shared_ptr<Request>
uint32_t callingTokenId = request->GetTokenId();
if (isStart && !request->GetApproximatelyPermState()) {
int ret = PrivacyKit::StartUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION);
if (ret != ERRCODE_SUCCESS && locatorAbility->IsHapCaller(callingTokenId)) {
if (ret != ERRCODE_SUCCESS && ret != Security::AccessToken::ERR_PERMISSION_ALREADY_START_USING &&
locatorAbility->IsHapCaller(request->GetTokenId())) {
LBSLOGE(REQUEST_MANAGER, "StartUsingPermission failed ret=%{public}d", ret);
return false;
}
@ -486,6 +488,7 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared
return false;
}
if (!UpdateUsingPermission(request, true)) {
RequestManager::GetInstance()->ReportLocationError(LOCATING_FAILED_LOCATION_PERMISSION_DENIED, request);
return false;
}
// add request info to work record