From bc4ab17d27f5627194995015af2ba044c8d34749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=96=87=E9=BE=99?= <245252081@qq.com> Date: Mon, 17 Jun 2024 20:56:40 +0800 Subject: [PATCH 1/9] mult users location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李文龙 <245252081@qq.com> --- .../location_common/common/source/common_utils.cpp | 14 ++++++++++++++ .../common/source/location_data_rdb_manager.cpp | 13 +++++++++++++ interfaces/inner_api/include/common_utils.h | 1 + .../inner_api/include/location_data_rdb_manager.h | 1 + .../locator/source/locator_background_proxy.cpp | 11 +++++++++++ .../locator/source/report_manager.cpp | 6 ++++++ .../locator/source/request_manager.cpp | 6 ++++++ 7 files changed, 52 insertions(+) diff --git a/frameworks/location_common/common/source/common_utils.cpp b/frameworks/location_common/common/source/common_utils.cpp index 095464d4..b34c314e 100644 --- a/frameworks/location_common/common/source/common_utils.cpp +++ b/frameworks/location_common/common/source/common_utils.cpp @@ -28,6 +28,7 @@ #include "constant_definition.h" #include "parameter.h" #include "location_sa_load_manager.h" +#include "hook_utils.h" #include "accesstoken_kit.h" #include "os_account_manager.h" @@ -401,5 +402,18 @@ std::string CommonUtils::GenerateUuid() }; return ss.str(); } +bool CommonUtils::CheckAppForUser(int32_t uid) +{ + int currentUserId = 0; + int userId = 0; + if (!GetCurrentUserId(currentUserId)) { + return true; + } + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + if (userId != currentUserId) { + return false; + } + return true; +} } // namespace Location } // namespace OHOS diff --git a/frameworks/location_common/common/source/location_data_rdb_manager.cpp b/frameworks/location_common/common/source/location_data_rdb_manager.cpp index 10034635..ab222c68 100644 --- a/frameworks/location_common/common/source/location_data_rdb_manager.cpp +++ b/frameworks/location_common/common/source/location_data_rdb_manager.cpp @@ -127,6 +127,19 @@ bool LocationDataRdbManager::SetSwitchMode(int value) return true; } +bool LocationDataRdbManager::ClearSwitchMode() +{ + char valueArray[MAX_SIZE] = {0}; + (void)sprintf_s(valueArray, sizeof(valueArray), "%s", ""); + int res = SetParameter(LOCATION_SWITCH_MODE, valueArray); + LBSLOGE(COMMON_UTILS, "ClearSwitchMode valueArray value: %{public}s", valueArray); + if (res < 0) { + LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res); + return false; + } + return true; +} + bool LocationDataRdbManager::SetLocationEnhanceStatus(int32_t state) { Uri locationWorkingStateUri(GetLocationDataSecureUri(LOCATION_ENHANCE_STATUS)); diff --git a/interfaces/inner_api/include/common_utils.h b/interfaces/inner_api/include/common_utils.h index 273e9ad7..037b73a4 100644 --- a/interfaces/inner_api/include/common_utils.h +++ b/interfaces/inner_api/include/common_utils.h @@ -177,6 +177,7 @@ public: static bool GetStringParameter(const std::string& type, std::string& value); static bool GetEdmPolicy(std::string& name); static std::string GenerateUuid(); + static bool CheckAppForUser(int32_t uid); }; class CountDownLatch { diff --git a/interfaces/inner_api/include/location_data_rdb_manager.h b/interfaces/inner_api/include/location_data_rdb_manager.h index 2a9571e0..cc05faae 100644 --- a/interfaces/inner_api/include/location_data_rdb_manager.h +++ b/interfaces/inner_api/include/location_data_rdb_manager.h @@ -40,6 +40,7 @@ public: static bool GetLocationWorkingState(int32_t& state); static int GetSwitchMode(); static bool SetSwitchMode(int value); + static bool ClearSwitchMode(); static std::string GetLocationDataSecureUri(std::string key); static bool SetLocationEnhanceStatus(int32_t state); static bool GetLocationEnhanceStatus(int32_t& state); diff --git a/services/location_locator/locator/source/locator_background_proxy.cpp b/services/location_locator/locator/source/locator_background_proxy.cpp index 523abeb6..cdbb9e18 100644 --- a/services/location_locator/locator/source/locator_background_proxy.cpp +++ b/services/location_locator/locator/source/locator_background_proxy.cpp @@ -30,6 +30,7 @@ #include "locator_ability.h" #include "request_manager.h" #include "permission_manager.h" +#include "location_data_rdb_manager.h" #include "accesstoken_kit.h" #include "tokenid_kit.h" @@ -341,6 +342,11 @@ int32_t LocatorBackgroundProxy::GetUserId(int32_t uid) const void LocatorBackgroundProxy::OnUserSwitch(int32_t userId) { UpdateListOnUserSwitch(userId); + LocationDataRdbManager::ClearSwitchMode(); + auto requestManager = RequestManager::GetInstance(); + if (requestManager != nullptr) { + requestManager->HandleRequest(); + } if (!requestsList_->empty()) { StartLocator(); } else { @@ -353,6 +359,11 @@ void LocatorBackgroundProxy::OnUserRemove(int32_t userId) { // if user is removed, remove the requestList from the user in requestsMap std::unique_lock lock(requestListMutex_); + LocationDataRdbManager::ClearSwitchMode(); + auto requestManager = RequestManager::GetInstance(); + if (requestManager != nullptr) { + requestManager->HandleRequest(); + } auto iter = requestsMap_->find(userId); if (iter != requestsMap_->end()) { requestsMap_->erase(iter); diff --git a/services/location_locator/locator/source/report_manager.cpp b/services/location_locator/locator/source/report_manager.cpp index 1b712caf..e30c50de 100644 --- a/services/location_locator/locator/source/report_manager.cpp +++ b/services/location_locator/locator/source/report_manager.cpp @@ -208,6 +208,12 @@ std::unique_ptr ReportManager::GetPermittedLocation(const std::shared_ } return nullptr; } + if (!PermissionManager::CheckSystemPermission(tokenId, tokenIdEx) && + !CommonUtils::CheckAppForUser(uid)) { + PrivacyKit::StopUsingPermission(tokenId, ACCESS_APPROXIMATELY_LOCATION); + LBSLOGE(REPORT_MANAGER, "GetPermittedLocation uid: %{public}d CheckAppForUser fail", tokenId); + return nullptr; + } std::unique_ptr finalLocation = std::make_unique(*location); // for api8 and previous version, only ACCESS_LOCATION permission granted also report original location info. if (PermissionManager::CheckLocationPermission(tokenId, firstTokenId)) { diff --git a/services/location_locator/locator/source/request_manager.cpp b/services/location_locator/locator/source/request_manager.cpp index 09d7497a..939b3bcf 100644 --- a/services/location_locator/locator/source/request_manager.cpp +++ b/services/location_locator/locator/source/request_manager.cpp @@ -469,6 +469,12 @@ bool RequestManager::AddRequestToWorkRecord(std::shared_ptr& request, if (requestConfig == nullptr) { return false; } + if (!PermissionManager::CheckSystemPermission(tokenId, request->GetTokenIdEx()) && + !CommonUtils::CheckAppForUser(uid)) { + PrivacyKit::StopUsingPermission(tokenId, ACCESS_APPROXIMATELY_LOCATION); + LBSLOGE(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid); + return false; + } // add request info to work record if (workRecord != nullptr) { request->SetNlpRequestType(); From b065e9bb12195b9d0f1345e3f57de4ffdcf2f762 Mon Sep 17 00:00:00 2001 From: smilebear <245252081@qq.com> Date: Tue, 18 Jun 2024 00:15:54 +0000 Subject: [PATCH 2/9] update interfaces/inner_api/include/location_data_rdb_manager.h. Signed-off-by: smilebear <245252081@qq.com> --- interfaces/inner_api/include/location_data_rdb_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/include/location_data_rdb_manager.h b/interfaces/inner_api/include/location_data_rdb_manager.h index cc05faae..9e8189ba 100644 --- a/interfaces/inner_api/include/location_data_rdb_manager.h +++ b/interfaces/inner_api/include/location_data_rdb_manager.h @@ -40,7 +40,7 @@ public: static bool GetLocationWorkingState(int32_t& state); static int GetSwitchMode(); static bool SetSwitchMode(int value); - static bool ClearSwitchMode(); + static bool ClearSwitchMode(); static std::string GetLocationDataSecureUri(std::string key); static bool SetLocationEnhanceStatus(int32_t state); static bool GetLocationEnhanceStatus(int32_t& state); From b3bd3c10473ade29f708e38702bb48bfb31cf7a6 Mon Sep 17 00:00:00 2001 From: smilebear <245252081@qq.com> Date: Tue, 18 Jun 2024 01:17:11 +0000 Subject: [PATCH 3/9] =?UTF-8?q?update=20services/location=5Flocator/locato?= =?UTF-8?q?r/source/request=5Fmanager.cpp.=20=E5=9C=88=E8=BF=8720=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E8=BE=BE=E5=88=B021?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: smilebear <245252081@qq.com> --- .../location_locator/locator/source/request_manager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/location_locator/locator/source/request_manager.cpp b/services/location_locator/locator/source/request_manager.cpp index f8370843..8f182734 100644 --- a/services/location_locator/locator/source/request_manager.cpp +++ b/services/location_locator/locator/source/request_manager.cpp @@ -437,13 +437,9 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared return false; } UpdateUsingPermission(request); - if (!request->GetIsRequesting()) { + if (!request->GetIsRequesting() || !IsRequestAvailable(request) { return false; } - if (!IsRequestAvailable(request)) { - return false; - } - auto locationErrorCallback = request->GetLocationErrorCallBack(); int switchState = DISABLED; auto locatorAbility = LocatorAbility::GetInstance(); From a738b5263e9cbcbb2f0c876ff171508644396768 Mon Sep 17 00:00:00 2001 From: smilebear <245252081@qq.com> Date: Tue, 18 Jun 2024 02:26:17 +0000 Subject: [PATCH 4/9] update services/location_locator/locator/source/request_manager.cpp. Signed-off-by: smilebear <245252081@qq.com> --- .../common/source/common_utils.cpp | 10 ++-- .../source/location_data_rdb_manager.cpp | 10 ++-- .../include/location_data_rdb_manager.h | 3 ++ .../locator/include/locator_skeleton.h | 2 + .../locator/include/report_manager.h | 5 +- .../locator/include/request_manager.h | 1 + .../source/locator_background_proxy.cpp | 11 ++-- .../locator/source/locator_skeleton.cpp | 52 +++++++++++++------ .../locator/source/report_manager.cpp | 35 +++++++++---- .../locator/source/request_manager.cpp | 43 ++++++++++++--- 10 files changed, 125 insertions(+), 47 deletions(-) diff --git a/frameworks/location_common/common/source/common_utils.cpp b/frameworks/location_common/common/source/common_utils.cpp index b34c314e..6610c438 100644 --- a/frameworks/location_common/common/source/common_utils.cpp +++ b/frameworks/location_common/common/source/common_utils.cpp @@ -128,7 +128,7 @@ bool CommonUtils::GetCurrentUserId(int &userId) std::vector activeIds; int ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); if (ret != 0) { - LBSLOGE(COMMON_UTILS, "QueryActiveOsAccountIds failed ret:%{public}d", ret); + LBSLOGI(COMMON_UTILS, "GetCurrentUserId failed ret:%{public}d", ret); return false; } if (activeIds.empty()) { @@ -402,14 +402,18 @@ std::string CommonUtils::GenerateUuid() }; return ss.str(); } + bool CommonUtils::CheckAppForUser(int32_t uid) { int currentUserId = 0; int userId = 0; if (!GetCurrentUserId(currentUserId)) { - return true; + currentUserId = 100; + } + auto result = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + if (result != ERR_OK) { + return false; } - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (userId != currentUserId) { return false; } diff --git a/frameworks/location_common/common/source/location_data_rdb_manager.cpp b/frameworks/location_common/common/source/location_data_rdb_manager.cpp index ab222c68..b3228870 100644 --- a/frameworks/location_common/common/source/location_data_rdb_manager.cpp +++ b/frameworks/location_common/common/source/location_data_rdb_manager.cpp @@ -21,10 +21,11 @@ namespace OHOS { namespace Location { const int DEFAULT_USERID = 100; +const int DEFAULT_SWITCHMODE = 2; const int UNKNOW_ERROR = -1; const int MAX_SIZE = 100; const char* LOCATION_SWITCH_MODE = "persist.location.switch_mode"; - +std::mutex LocationDataRdbManager::mutex_; std::string LocationDataRdbManager::GetLocationDataUri(std::string key) { int userId = 0; @@ -97,6 +98,7 @@ int LocationDataRdbManager::GetSwitchMode() { char result[MAX_SIZE] = {0}; std::string value = ""; + std::unique_lock lock(mutex_); auto res = GetParameter(LOCATION_SWITCH_MODE, "", result, MAX_SIZE); if (res <= 0 || strlen(result) == 0) { LBSLOGE(COMMON_UTILS, "%{public}s get para value failed, res: %{public}d", __func__, res); @@ -119,6 +121,7 @@ bool LocationDataRdbManager::SetSwitchMode(int value) { char valueArray[MAX_SIZE] = {0}; (void)sprintf_s(valueArray, sizeof(valueArray), "%d", value); + std::unique_lock lock(mutex_); int res = SetParameter(LOCATION_SWITCH_MODE, valueArray); if (res < 0) { LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res); @@ -130,11 +133,10 @@ bool LocationDataRdbManager::SetSwitchMode(int value) bool LocationDataRdbManager::ClearSwitchMode() { char valueArray[MAX_SIZE] = {0}; - (void)sprintf_s(valueArray, sizeof(valueArray), "%s", ""); + (void)sprintf_s(valueArray, sizeof(valueArray), "%d", DEFAULT_SWITCHMODE); + std::unique_lock lock(mutex_); int res = SetParameter(LOCATION_SWITCH_MODE, valueArray); - LBSLOGE(COMMON_UTILS, "ClearSwitchMode valueArray value: %{public}s", valueArray); if (res < 0) { - LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res); return false; } return true; diff --git a/interfaces/inner_api/include/location_data_rdb_manager.h b/interfaces/inner_api/include/location_data_rdb_manager.h index 9e8189ba..7c5bd9e9 100644 --- a/interfaces/inner_api/include/location_data_rdb_manager.h +++ b/interfaces/inner_api/include/location_data_rdb_manager.h @@ -17,6 +17,7 @@ #define LOCATION_DATA_RDB_MANAGER_H #include #include +#include #include "constant_definition.h" @@ -44,6 +45,8 @@ public: static std::string GetLocationDataSecureUri(std::string key); static bool SetLocationEnhanceStatus(int32_t state); static bool GetLocationEnhanceStatus(int32_t& state); +private: + static std::mutex mutex_; }; } // namespace Location } // namespace OHOS diff --git a/services/location_locator/locator/include/locator_skeleton.h b/services/location_locator/locator/include/locator_skeleton.h index 884ef7fb..4162eef2 100644 --- a/services/location_locator/locator/include/locator_skeleton.h +++ b/services/location_locator/locator/include/locator_skeleton.h @@ -114,6 +114,8 @@ private: LocatorInterfaceCode code, MessageParcel &data, MessageParcel &reply, AppIdentity &identity); void ConstructLocatorHandleMap(); void ConstructGeocodeHandleMap(); + bool IsStopAction(uint32_t code); + bool CheckRequestAvailable(uint32_t code, AppIdentity &identity); void ConstructGnssHandleMap(); sptr scanRecipient_ = new (std::nothrow) ScanCallbackDeathRecipient(); }; diff --git a/services/location_locator/locator/include/report_manager.h b/services/location_locator/locator/include/report_manager.h index c9474dd5..8ba75462 100644 --- a/services/location_locator/locator/include/report_manager.h +++ b/services/location_locator/locator/include/report_manager.h @@ -24,6 +24,7 @@ #include "i_locator_callback.h" #include "location.h" #include "request.h" +#include namespace OHOS { namespace Location { @@ -49,9 +50,10 @@ public: private: struct timespec lastUpdateTime_; double offsetRandom_; - Location lastLocation_; + std::map> lastLocationsMap_; Location cacheGnssLocation_; Location cacheNlpLocation_; + std::mutex lastLocationMutex_; std::unique_ptr ApproximatelyLocation(const std::unique_ptr& location); bool ProcessRequestForReport(std::shared_ptr& request, std::unique_ptr>>& deadRequests, @@ -60,6 +62,7 @@ private: const std::unique_ptr& location); std::unique_ptr ExecuteReportProcess(std::shared_ptr& request, std::unique_ptr& location, std::string abilityName); + void UpdateLastLocation(const std::unique_ptr& location); }; } // namespace OHOS } // namespace Location diff --git a/services/location_locator/locator/include/request_manager.h b/services/location_locator/locator/include/request_manager.h index 00efe4e8..51af9a19 100644 --- a/services/location_locator/locator/include/request_manager.h +++ b/services/location_locator/locator/include/request_manager.h @@ -57,6 +57,7 @@ private: sptr GetRemoteObject(std::string abilityName); bool IsUidInProcessing(int32_t uid); void UpdateUsingApproximatelyPermission(std::shared_ptr request); + void UpdateUsingApproximatelyStatus(std::shared_ptr request, bool isActive); bool ActiveLocatingStrategies(const std::shared_ptr& request); bool AddRequestToWorkRecord(std::string abilityName, std::shared_ptr& request, std::shared_ptr& workRecord); diff --git a/services/location_locator/locator/source/locator_background_proxy.cpp b/services/location_locator/locator/source/locator_background_proxy.cpp index cdbb9e18..2a812890 100644 --- a/services/location_locator/locator/source/locator_background_proxy.cpp +++ b/services/location_locator/locator/source/locator_background_proxy.cpp @@ -343,9 +343,9 @@ void LocatorBackgroundProxy::OnUserSwitch(int32_t userId) { UpdateListOnUserSwitch(userId); LocationDataRdbManager::ClearSwitchMode(); - auto requestManager = RequestManager::GetInstance(); - if (requestManager != nullptr) { - requestManager->HandleRequest(); + auto locatorAbility = LocatorAbility::GetInstance(); + if (locatorAbility != nullptr) { + locatorAbility->ApplyRequests(1); } if (!requestsList_->empty()) { StartLocator(); @@ -359,11 +359,6 @@ void LocatorBackgroundProxy::OnUserRemove(int32_t userId) { // if user is removed, remove the requestList from the user in requestsMap std::unique_lock lock(requestListMutex_); - LocationDataRdbManager::ClearSwitchMode(); - auto requestManager = RequestManager::GetInstance(); - if (requestManager != nullptr) { - requestManager->HandleRequest(); - } auto iter = requestsMap_->find(userId); if (iter != requestsMap_->end()) { requestsMap_->erase(iter); diff --git a/services/location_locator/locator/source/locator_skeleton.cpp b/services/location_locator/locator/source/locator_skeleton.cpp index 1672cd1c..58d1942d 100644 --- a/services/location_locator/locator/source/locator_skeleton.cpp +++ b/services/location_locator/locator/source/locator_skeleton.cpp @@ -1177,25 +1177,45 @@ int LocatorAbilityStub::PreReportLocationError(MessageParcel &data, MessageParce return ERRCODE_SUCCESS; } +bool LocatorAbilityStub::IsStopAction(uint32_t code) +{ + if (code == static_cast(LocatorInterfaceCode::UNREG_SWITCH_CALLBACK) || + code == static_cast(LocatorInterfaceCode::STOP_LOCATING) || + code == static_cast(LocatorInterfaceCode::STOP_LOCATING) || + code == static_cast(LocatorInterfaceCode::DISABLE_LOCATION_MOCK) || + code == static_cast(LocatorInterfaceCode::UNREG_LOCATION_ERROR) || + code == static_cast(LocatorInterfaceCode::UNREG_LOCATING_REQUIRED_DATA_CALLBACK)) { + return true; + } + return false; +} + +bool LocatorAbilityStub::CheckRequestAvailable(uint32_t code, AppIdentity &identity) +{ + if (IsStopAction(code)) { + return true; + } + if (PermissionManager::CheckSystemPermission(identity.GetTokenId(), identity.GetTokenIdEx())) { + return true; + } + if (!CommonUtils::CheckAppForUser(identity.GetUid())) { + return false; + } + return true; +} int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { int ret = ERRCODE_SUCCESS; - pid_t callingPid = IPCSkeleton::GetCallingPid(); - pid_t callingUid = IPCSkeleton::GetCallingUid(); - uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID(); - uint64_t callingTokenIdEx = IPCSkeleton::GetCallingFullTokenID(); - uint32_t callingFirstTokenid = IPCSkeleton::GetFirstTokenID(); - AppIdentity identity; - identity.SetPid(callingPid); - identity.SetUid(callingUid); - identity.SetTokenId(callingTokenId); - identity.SetTokenIdEx(callingTokenIdEx); - identity.SetFirstTokenId(callingFirstTokenid); + identity.SetPid(IPCSkeleton::GetCallingPid()); + identity.SetUid(IPCSkeleton::GetCallingUid()); + identity.SetTokenId(IPCSkeleton::GetCallingTokenID()); + identity.SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID()); + identity.SetFirstTokenId(IPCSkeleton::GetFirstTokenID()); std::string bundleName = ""; - if (!CommonUtils::GetBundleNameByUid(callingUid, bundleName)) { - LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", callingUid); + if (!CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) { + LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid()); } identity.SetBundleName(bundleName); if (code != static_cast(LocatorInterfaceCode::PROXY_PID_FOR_FREEZE)) { @@ -1205,7 +1225,6 @@ int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, std::to_string(CommonUtils::GetCurrentTimeStamp()).c_str()); } std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); - if (data.ReadInterfaceToken() != GetDescriptor()) { LBSLOGE(LOCATOR, "invalid token."); IPCSkeleton::SetCallingIdentity(callingIdentity); @@ -1213,7 +1232,10 @@ int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, return ERRCODE_SERVICE_UNAVAILABLE; } RemoveUnloadTask(code); - + if (!CheckRequestAvailable(code, identity)) { + reply.WriteInt32(ERRCODE_PERMISSION_DENIED); + return ERRCODE_PERMISSION_DENIED; + } auto handleFunc = locatorHandleMap_.find(static_cast(code)); if (handleFunc != locatorHandleMap_.end() && handleFunc->second != nullptr) { auto memberFunc = handleFunc->second; diff --git a/services/location_locator/locator/source/report_manager.cpp b/services/location_locator/locator/source/report_manager.cpp index e30c50de..4dee1000 100644 --- a/services/location_locator/locator/source/report_manager.cpp +++ b/services/location_locator/locator/source/report_manager.cpp @@ -210,8 +210,6 @@ std::unique_ptr ReportManager::GetPermittedLocation(const std::shared_ } if (!PermissionManager::CheckSystemPermission(tokenId, tokenIdEx) && !CommonUtils::CheckAppForUser(uid)) { - PrivacyKit::StopUsingPermission(tokenId, ACCESS_APPROXIMATELY_LOCATION); - LBSLOGE(REPORT_MANAGER, "GetPermittedLocation uid: %{public}d CheckAppForUser fail", tokenId); return nullptr; } std::unique_ptr finalLocation = std::make_unique(*location); @@ -306,25 +304,42 @@ void ReportManager::UpdateCacheLocation(const std::unique_ptr& locatio if (abilityName == GNSS_ABILITY) { if (HookUtils::CheckGnssLocationValidity(location)) { cacheGnssLocation_ = *location; - lastLocation_ = *location; + UpdateLastLocation(location); } } else if (abilityName == NETWORK_ABILITY && location->GetLocationSourceType() != LocationSourceType::INDOOR_TYPE) { cacheNlpLocation_ = *location; - lastLocation_ = *location; + UpdateLastLocation(location); } else { - lastLocation_ = *location; + UpdateLastLocation(location); + } +} + +void ReportManager::UpdateLastLocation(const std::unique_ptr& location) +{ + int currentUserId = 0; + if (CommonUtils::GetCurrentUserId(currentUserId)) { + std::unique_lock lock(lastLocationMutex_); + lastLocationsMap_.insert(std::make_pair(currentUserId, std::make_shared(*location))); } } std::unique_ptr ReportManager::GetLastLocation() { - auto lastLocation = std::make_unique(lastLocation_); - if (CommonUtils::DoubleEqual(lastLocation->GetLatitude(), MIN_LATITUDE - 1)) { - LBSLOGE(REPORT_MANAGER, "%{public}s no valid cache location", __func__); - return nullptr; + int currentUserId = 0; + if (CommonUtils::GetCurrentUserId(currentUserId)) { + std::unique_lock lock(lastLocationMutex_); + auto iter = lastLocationsMap_.find(currentUserId); + if (iter == lastLocationsMap_.end()) { + return nullptr; + } + std::unique_ptr lastLocation = std::make_unique(*(iter->second)); + if (CommonUtils::DoubleEqual(lastLocation->GetLatitude(), MIN_LATITUDE - 1)) { + return nullptr; + } + return lastLocation; } - return lastLocation; + return nullptr; } std::unique_ptr ReportManager::GetCacheLocation(const std::shared_ptr& request) diff --git a/services/location_locator/locator/source/request_manager.cpp b/services/location_locator/locator/source/request_manager.cpp index 8f182734..a25ab8e7 100644 --- a/services/location_locator/locator/source/request_manager.cpp +++ b/services/location_locator/locator/source/request_manager.cpp @@ -111,6 +111,31 @@ void RequestManager::UpdateUsingApproximatelyPermission(std::shared_ptr } } +void RequestManager::UpdateUsingApproximatelyStatus(std::shared_ptr request, bool isActive) +{ + std::unique_lock lock(permissionRecordMutex_, std::defer_lock); + lock.lock(); + if (request == nullptr) { + LBSLOGE(REQUEST_MANAGER, "request is null"); + lock.unlock(); + return; + } + uint32_t callingTokenId = request->GetTokenId(); + if (isActive) { + if (!request->GetApproximatelyPermState()) { + PrivacyKit::StartUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); + request->SetApproximatelyPermState(true); + } + } else { + if (request->GetApproximatelyPermState()) { + PrivacyKit::StopUsingPermission(callingTokenId, ACCESS_APPROXIMATELY_LOCATION); + request->SetApproximatelyPermState(false); + } + } + lock.unlock(); +} + + void RequestManager::HandleStartLocating(std::shared_ptr request) { auto locatorAbility = LocatorAbility::GetInstance(); @@ -360,9 +385,10 @@ void RequestManager::HandleRequest(std::string abilityName, std::listGetPackageName(), - "abilityName", abilityName, "requestAddress", request->GetUuid()}); + UpdateUsingApproximatelyStatus(request, false); continue; + } else { + UpdateUsingApproximatelyStatus(request, true); } if (!ActiveLocatingStrategies(request)) { continue; @@ -401,6 +427,9 @@ bool RequestManager::ActiveLocatingStrategies(const std::shared_ptr& re */ bool RequestManager::IsRequestAvailable(std::shared_ptr& request) { + if (!request->GetIsRequesting()) { + return false; + } // for frozen app, do not add to workRecord if (LocatorAbility::GetInstance()->IsProxyPid(request->GetPid())) { return false; @@ -436,8 +465,11 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared if (request == nullptr) { return false; } - UpdateUsingPermission(request); - if (!request->GetIsRequesting() || !IsRequestAvailable(request) { + + if (!request->GetIsRequesting()) { + return false; + } + if (!IsRequestAvailable(request)) { return false; } auto locationErrorCallback = request->GetLocationErrorCallBack(); @@ -486,8 +518,7 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared if (!PermissionManager::CheckSystemPermission(tokenId, request->GetTokenIdEx()) && !CommonUtils::CheckAppForUser(uid)) { - PrivacyKit::StopUsingPermission(tokenId, ACCESS_APPROXIMATELY_LOCATION); - LBSLOGE(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid); + LBSLOGD(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid); return false; } From 26e781a054aee123a102e4899af6616080c8838e Mon Sep 17 00:00:00 2001 From: z30025928 <734222381@qq.com> Date: Thu, 27 Jun 2024 14:25:00 +0800 Subject: [PATCH 5/9] adapter for car parking Signed-off-by: z30025928 <734222381@qq.com> --- services/etc/init/locationsa.cfg | 2 ++ .../location_locator/locator/source/locator_skeleton.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/services/etc/init/locationsa.cfg b/services/etc/init/locationsa.cfg index 4c797537..22fc00de 100644 --- a/services/etc/init/locationsa.cfg +++ b/services/etc/init/locationsa.cfg @@ -20,6 +20,8 @@ "ohos.permission.MANAGE_SECURE_SETTINGS", "ohos.permission.GET_TELEPHONY_STATE", "ohos.permission.LOCATION", + "ohos.permission.APPROXIMATELY_LOCATION", + "ohos.permission.LOCATION_IN_BACKGROUND", "ohos.permission.GET_WIFI_INFO", "ohos.permission.SET_WIFI_INFO", "ohos.permission.GET_RUNNING_INFO", diff --git a/services/location_locator/locator/source/locator_skeleton.cpp b/services/location_locator/locator/source/locator_skeleton.cpp index 1672cd1c..1f51c95f 100644 --- a/services/location_locator/locator/source/locator_skeleton.cpp +++ b/services/location_locator/locator/source/locator_skeleton.cpp @@ -1186,6 +1186,11 @@ int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID(); uint64_t callingTokenIdEx = IPCSkeleton::GetCallingFullTokenID(); uint32_t callingFirstTokenid = IPCSkeleton::GetFirstTokenID(); + // first token id is invalid + if (callingUid == callingFirstTokenid && callingUid == static_cast(getuid()) + && callingPid == getpid()) { + callingFirstTokenid = 0; + } AppIdentity identity; identity.SetPid(callingPid); From a07672ac2cc44ae220b0475952293a1683d19979 Mon Sep 17 00:00:00 2001 From: liuyuanyuan Date: Fri, 26 Jul 2024 11:21:16 +0800 Subject: [PATCH 6/9] update version code Signed-off-by: liuyuanyuan --- services/location_ui/AppScope/app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/location_ui/AppScope/app.json b/services/location_ui/AppScope/app.json index 1ac7cc86..3d9a92cd 100644 --- a/services/location_ui/AppScope/app.json +++ b/services/location_ui/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.locationdialog", "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", + "versionCode": 1000001, + "versionName": "1.0.1", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true, From 29822775aa918a2336eb9d0528045e4500df42cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=96=87=E9=BE=99?= Date: Sat, 27 Jul 2024 11:57:33 +0800 Subject: [PATCH 7/9] =?UTF-8?q?geo=20=E8=B0=83=E6=95=B4geo=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=96=AD=E5=BC=80=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李文龙 --- .../location_geocode/geocode/source/geo_convert_service.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/location_geocode/geocode/source/geo_convert_service.cpp b/services/location_geocode/geocode/source/geo_convert_service.cpp index 792c83c0..2936eaed 100644 --- a/services/location_geocode/geocode/source/geo_convert_service.cpp +++ b/services/location_geocode/geocode/source/geo_convert_service.cpp @@ -413,6 +413,10 @@ void GeoConvertService::UnloadGeoConvertSystemAbility() if (!CheckIfGeoConvertConnecting()) { LocationSaLoadManager::UnInitLocationSa(LOCATION_GEO_CONVERT_SA_ID); } + if (conn_ != nullptr) { + AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_); + LBSLOGD(GEO_CONVERT, "DisableReverseGeocodingMock::OnStop and disconnect"); + } } bool GeoConvertService::CheckIfGeoConvertConnecting() From 9e714386832e86cf7d7c8022e8233f6c5a54da52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=96=87=E9=BE=99?= Date: Sat, 27 Jul 2024 17:09:00 +0800 Subject: [PATCH 8/9] bugfix:codecheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李文龙 --- .../geocode/include/geo_convert_request.h | 2 +- .../geocode/source/geo_convert_request.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/services/location_geocode/geocode/include/geo_convert_request.h b/services/location_geocode/geocode/include/geo_convert_request.h index 6a91fa05..9add252b 100644 --- a/services/location_geocode/geocode/include/geo_convert_request.h +++ b/services/location_geocode/geocode/include/geo_convert_request.h @@ -81,7 +81,7 @@ private: double minLatitude_; double minLongitude_; std::string bundleName_; - sptr callback_ = nullptr; + sptr callback_; std::string transId_; std::string country_; GeoCodeType requestType_; diff --git a/services/location_geocode/geocode/source/geo_convert_request.cpp b/services/location_geocode/geocode/source/geo_convert_request.cpp index b4551e26..a78d0638 100644 --- a/services/location_geocode/geocode/source/geo_convert_request.cpp +++ b/services/location_geocode/geocode/source/geo_convert_request.cpp @@ -18,7 +18,23 @@ namespace OHOS { namespace Location { -GeoConvertRequest::GeoConvertRequest() {} +GeoConvertRequest::GeoConvertRequest() +{ + locale_ = ""; + latitude_ = 0.0; + longitude_ = 0.0; + maxItems_ = 0; + description_ = ""; + maxLatitude_ = 0.0; + maxLongitude_ = 0.0; + minLatitude_ = 0.0; + minLongitude_ = 0.0; + bundleName_ = ""; + callback_ = nullptr; + transId_ = ""; + country_ = ""; + requestType_ = GeoCodeType::REQUEST_GEOCODE; +} GeoConvertRequest::~GeoConvertRequest() {} From 38dd2b934fb25ca75bc5a8e809d052b763c667f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=96=87=E9=BE=99?= Date: Mon, 29 Jul 2024 15:44:34 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=B0=83=E6=95=B4geo=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李文龙 --- .../location_geocode/geocode/source/geo_convert_service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/location_geocode/geocode/source/geo_convert_service.cpp b/services/location_geocode/geocode/source/geo_convert_service.cpp index 66fcc1ce..4a3ebb54 100644 --- a/services/location_geocode/geocode/source/geo_convert_service.cpp +++ b/services/location_geocode/geocode/source/geo_convert_service.cpp @@ -34,7 +34,8 @@ const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( const uint32_t EVENT_SEND_GEOREQUEST = 0x0100; const char* UNLOAD_GEOCONVERT_TASK = "geoconvert_sa_unload"; const int GEOCONVERT_CONNECT_TIME_OUT = 1; -const int UNLOAD_GEOCONVERT_DELAY_TIME = 5; +const uint32_t EVENT_INTERVAL_UNITE = 1000; +const int UNLOAD_GEOCONVERT_DELAY_TIME = 5 * EVENT_INTERVAL_UNITE; GeoConvertService* GeoConvertService::GetInstance() { static GeoConvertService data;