diff --git a/frameworks/location_common/common/source/common_utils.cpp b/frameworks/location_common/common/source/common_utils.cpp index cb48c4d5..b0af6c03 100644 --- a/frameworks/location_common/common/source/common_utils.cpp +++ b/frameworks/location_common/common/source/common_utils.cpp @@ -42,7 +42,7 @@ 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; - +const int DEFAULT_USERID = 100; int CommonUtils::AbilityConvertToId(const std::string ability) { if (GNSS_ABILITY.compare(ability) == 0) { @@ -404,17 +404,21 @@ std::string CommonUtils::GenerateUuid() return ss.str(); } -bool CommonUtils::CheckAppForUser(int32_t uid) + +bool CommonUtils::CheckAppForUser(int32_t uid, std::string bundleName) { + if (HookUtils::ExecuteHookWhenCheckAppForUser(bundleName)) { + return true; + } int currentUserId = 0; int userId = 0; - bool ret = GetCurrentUserId(currentUserId); - if (!ret) { - return true; + if (!GetCurrentUserId(currentUserId)) { + currentUserId = DEFAULT_USERID; } auto result = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (result != ERR_OK) { - return true; + LBSLOGE(COMMON_UTILS, "CheckAppForUser GetOsAccountLocalIdFromUid fail"); + return false; } if (userId != currentUserId) { return false; diff --git a/frameworks/location_common/common/source/hook_utils.cpp b/frameworks/location_common/common/source/hook_utils.cpp index 8bdc8f70..bcc64174 100644 --- a/frameworks/location_common/common/source/hook_utils.cpp +++ b/frameworks/location_common/common/source/hook_utils.cpp @@ -116,6 +116,16 @@ bool HookUtils::ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, st return locatorRequestStruct.result; } +bool HookUtils::ExecuteHookWhenCheckAppForUser(std::string packageName) +{ + LocatorRequestStruct locatorRequestStruct; + locatorRequestStruct.bundleName = packageName; + locatorRequestStruct.result = false; + ExecuteHook( + LocationProcessStage::LOCATOR_SA_LOCATION_PERMISSION_CHECK, (void *)&locatorRequestStruct, nullptr); + return locatorRequestStruct.result; +} + bool HookUtils::CheckGnssLocationValidity(const std::unique_ptr& location) { GnssLocationValidStruct gnssLocationValidStruct; 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 a1407129..bcd80b3c 100644 --- a/frameworks/location_common/common/source/location_data_rdb_manager.cpp +++ b/frameworks/location_common/common/source/location_data_rdb_manager.cpp @@ -24,9 +24,9 @@ const int DEFAULT_USERID = 100; const int DEFAULT_SWITCHMODE = 2; const int UNKNOW_ERROR = -1; const int MAX_SIZE = 100; -std::mutex LocationDataRdbManager::mutex_; -const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status"; +const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status"; +std::mutex LocationDataRdbManager::locationSwitchModeMutex_; std::string LocationDataRdbManager::GetLocationDataUri(std::string key) { int userId = 0; @@ -106,7 +106,7 @@ int LocationDataRdbManager::GetSwitchMode() { char result[MAX_SIZE] = {0}; std::string value = ""; - std::unique_lock lock(mutex_); + std::unique_lock lock(locationSwitchModeMutex_); 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); @@ -129,7 +129,7 @@ bool LocationDataRdbManager::SetSwitchStateToSyspara(int value) { char valueArray[MAX_SIZE] = {0}; (void)sprintf_s(valueArray, sizeof(valueArray), "%d", value); - std::unique_lock lock(mutex_); + std::unique_lock lock(locationSwitchModeMutex_); int res = SetParameter(LOCATION_SWITCH_MODE, valueArray); if (res < 0) { LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res); @@ -162,9 +162,10 @@ bool LocationDataRdbManager::ClearSwitchMode() if (code <= 0) { return false; } - std::unique_lock lock(mutex_); + std::unique_lock lock(locationSwitchModeMutex_); int res = SetParameter(LOCATION_SWITCH_MODE, valueArray); if (res < 0) { + LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res); return false; } return true; diff --git a/frameworks/location_common/common/source/permission_manager.cpp b/frameworks/location_common/common/source/permission_manager.cpp index 96df0e1a..17e951ab 100644 --- a/frameworks/location_common/common/source/permission_manager.cpp +++ b/frameworks/location_common/common/source/permission_manager.cpp @@ -127,5 +127,14 @@ bool PermissionManager::CheckSystemPermission(uint32_t callerTokenId, uint64_t c bool isSysApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerTokenIdEx); return isSysApp; } + +bool PermissionManager::CheckIsSystemSA(uint32_t tokenId) +{ + auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + return true; + } + return false; +} } // namespace Location } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/locator_sdk/source/country_code_manager.cpp b/frameworks/native/locator_sdk/source/country_code_manager.cpp index 662c0e34..0d2e236b 100644 --- a/frameworks/native/locator_sdk/source/country_code_manager.cpp +++ b/frameworks/native/locator_sdk/source/country_code_manager.cpp @@ -28,6 +28,7 @@ #include "location_log.h" #include "locator_impl.h" #include "lbs_res_loader.h" +#include "permission_manager.h" namespace OHOS { namespace Location { @@ -58,14 +59,28 @@ void CountryCodeManager::NotifyAllListener() return; } auto country = std::make_shared(*lastCountry_); - for (auto callback : countryCodeCallbacks_) { - if (callback) { + for (const auto& pair : countryCodeCallbacksMap_) { + auto callback = pair.first; + AppIdentity identity = pair.second; + if (CheckPermissionforUser(identity)) { callback->OnCountryCodeChange(country); } } } -void CountryCodeManager::RegisterCountryCodeCallback(const sptr& callback, pid_t uid) +bool CountryCodeManager::CheckPermissionforUser(AppIdentity &identity) +{ + if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) { + return true; + } + if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) { + return true; + } + return false; +} + + +void CountryCodeManager::RegisterCountryCodeCallback(const sptr& callback, AppIdentity &identity) { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); @@ -74,23 +89,16 @@ void CountryCodeManager::RegisterCountryCodeCallback(const sptr& lock.unlock(); return; } - for (auto item : countryCodeCallbacks_) { - if (item && item->AsObject() == callback) { - LBSLOGE(COUNTRY_CODE, "callback has registered"); - lock.unlock(); - return; - } - } sptr countryCodeCallback = iface_cast(callback); if (countryCodeCallback == nullptr) { LBSLOGE(COUNTRY_CODE, "iface_cast ICountryCodeCallback failed!"); lock.unlock(); return; } - countryCodeCallbacks_.push_back(countryCodeCallback); - LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallbacks_ size:%{public}s", - uid, std::to_string(countryCodeCallbacks_.size()).c_str()); - if (countryCodeCallbacks_.size() != 1) { + countryCodeCallbacksMap_.insert(std::make_pair(countryCodeCallback, identity)); + LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallbacksMap_ size:%{public}s", + identity.GetUid(), std::to_string(countryCodeCallbacksMap_.size()).c_str()); + if (countryCodeCallbacksMap_.size() != 1) { lock.unlock(); return; } @@ -108,8 +116,8 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr lock.unlock(); return; } - if (countryCodeCallbacks_.size() <= 0) { - LBSLOGE(COUNTRY_CODE, "countryCodeCallbacks_ size <= 0"); + if (countryCodeCallbacksMap_.size() <= 0) { + LBSLOGE(COUNTRY_CODE, "countryCodeCallbacksMap_ size <= 0"); lock.unlock(); return; } @@ -119,25 +127,19 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr lock.unlock(); return; } - size_t i = 0; - for (; i < countryCodeCallbacks_.size(); i++) { - if (countryCodeCallbacks_[i] == nullptr) { - continue; - } - sptr remoteObject = countryCodeCallbacks_[i]->AsObject(); + std::map, AppIdentity>::iterator iter; + for (iter = countryCodeCallbacksMap_.begin(); iter != countryCodeCallbacksMap_.end(); iter++) { + sptr remoteObject = iter->first->AsObject(); if (remoteObject == callback) { break; } } - if (i >= countryCodeCallbacks_.size()) { - LBSLOGD(GNSS, "countryCode callback is not in vector"); - lock.unlock(); - return; + if (iter != countryCodeCallbacksMap_.end()) { + countryCodeCallbacksMap_.erase(iter); } - countryCodeCallbacks_.erase(countryCodeCallbacks_.begin() + i); - LBSLOGD(COUNTRY_CODE, "after unregister, countryCodeCallbacks_ size:%{public}s", - std::to_string(countryCodeCallbacks_.size()).c_str()); - if (countryCodeCallbacks_.size() != 0) { + LBSLOGD(COUNTRY_CODE, "after unregister, countryCodeCallbacksMap_ size:%{public}s", + std::to_string(countryCodeCallbacksMap_.size()).c_str()); + if (countryCodeCallbacksMap_.size() != 0) { lock.unlock(); return; } @@ -149,7 +151,7 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr bool CountryCodeManager::IsCountryCodeRegistered() { std::unique_lock lock(countryCodeCallbackMutex_); - return countryCodeCallbacks_.size() != 0; + return countryCodeCallbacksMap_.size() != 0; } std::string CountryCodeManager::GetCountryCodeByLastLocation() @@ -431,7 +433,7 @@ void CountryCodeManager::ReSubscribeEvent() { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (countryCodeCallbacks_.size() <= 0) { + if (countryCodeCallbacksMap_.size() <= 0) { LBSLOGD(COUNTRY_CODE, "no valid callback registed, no need to subscribe"); lock.unlock(); return; @@ -445,7 +447,7 @@ void CountryCodeManager::ReUnsubscribeEvent() { std::unique_lock lock(countryCodeCallbackMutex_, std::defer_lock); lock.lock(); - if (countryCodeCallbacks_.size() <= 0) { + if (countryCodeCallbacksMap_.size() <= 0) { LBSLOGE(COUNTRY_CODE, "no valid callback registed, no need to unsubscribe"); lock.unlock(); return; diff --git a/frameworks/native/locator_sdk/source/locator_impl.cpp b/frameworks/native/locator_sdk/source/locator_impl.cpp index 8fcb962d..8fb48ea9 100644 --- a/frameworks/native/locator_sdk/source/locator_impl.cpp +++ b/frameworks/native/locator_sdk/source/locator_impl.cpp @@ -274,7 +274,18 @@ bool LocatorImpl::RegisterCountryCodeCallback(const sptr& callbac LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__); return false; } - countryCodeManager->RegisterCountryCodeCallback(callback, uid); + AppIdentity identity; + 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(identity.GetUid(), bundleName)) { + LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid()); + } + identity.SetBundleName(bundleName); + countryCodeManager->RegisterCountryCodeCallback(callback, identity); return true; } @@ -785,7 +796,18 @@ LocationErrCode LocatorImpl::RegisterCountryCodeCallbackV9(const sptrRegisterCountryCodeCallback(callback, 0); + AppIdentity identity; + 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(identity.GetUid(), bundleName)) { + LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid()); + } + identity.SetBundleName(bundleName); + countryCodeManager->RegisterCountryCodeCallback(callback, identity); return ERRCODE_SUCCESS; } diff --git a/frameworks/native/locator_sdk/source/locator_proxy.cpp b/frameworks/native/locator_sdk/source/locator_proxy.cpp index 1e3f7cd0..aa4ea6d3 100644 --- a/frameworks/native/locator_sdk/source/locator_proxy.cpp +++ b/frameworks/native/locator_sdk/source/locator_proxy.cpp @@ -590,7 +590,7 @@ LocationErrCode LocatorProxy::UnregisterNmeaMessageCallbackV9(const sptr(callback); LocationErrCode errorCode = SendMsgWithDataReplyV9(static_cast(LocatorInterfaceCode::UNREG_NMEA_CALLBACK_V9), data, reply); - LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode); + LBSLOGD(LOCATOR_STANDARD, "Proxy::UnRegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode); return errorCode; } diff --git a/interfaces/inner_api/include/app_identity.h b/interfaces/inner_api/include/app_identity.h index ab6302bd..fe67d8de 100644 --- a/interfaces/inner_api/include/app_identity.h +++ b/interfaces/inner_api/include/app_identity.h @@ -17,10 +17,11 @@ #define APP_IDENTITY_H #include +#include namespace OHOS { namespace Location { -class AppIdentity { +class AppIdentity : public Parcelable { public: AppIdentity(); explicit AppIdentity(pid_t uid, pid_t pid, uint32_t tokenId, uint64_t tokenIdEx, uint32_t firstTokenId); @@ -85,6 +86,32 @@ public: { bundleName_ = bundleName; } + void ReadFromParcel(Parcel& parcel) + { + uid_ = parcel.ReadInt32(); + pid_ = parcel.ReadInt32(); + tokenId_ = parcel.ReadInt32(); + tokenIdEx_ = parcel.ReadInt64(); + firstTokenId_ = parcel.ReadInt32(); + bundleName_ = parcel.ReadString(); + } + + bool Marshalling(Parcel& parcel) const + { + return parcel.WriteInt32(uid_) && + parcel.WriteInt32(pid_) && + parcel.WriteInt32(tokenId_) && + parcel.WriteInt64(tokenIdEx_) && + parcel.WriteInt32(firstTokenId_) && + parcel.WriteString(bundleName_); + } + + static std::shared_ptr Unmarshalling(Parcel& parcel) + { + auto identity = std::make_shared(); + identity->ReadFromParcel(parcel); + return identity; + } std::string ToString() const; private: diff --git a/interfaces/inner_api/include/common_utils.h b/interfaces/inner_api/include/common_utils.h index e8e244a0..a8e1c50e 100644 --- a/interfaces/inner_api/include/common_utils.h +++ b/interfaces/inner_api/include/common_utils.h @@ -176,7 +176,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); + static bool CheckAppForUser(int32_t uid, std::string packageName); static int64_t GetSinceBootTime(); }; diff --git a/interfaces/inner_api/include/country_code_manager.h b/interfaces/inner_api/include/country_code_manager.h index 4be3ad2e..37e998e0 100644 --- a/interfaces/inner_api/include/country_code_manager.h +++ b/interfaces/inner_api/include/country_code_manager.h @@ -28,6 +28,7 @@ #include "i_locator_callback.h" #include "i_country_code_callback.h" #include "location.h" +#include "app_identity.h" namespace OHOS { namespace Location { @@ -37,7 +38,7 @@ public: ~CountryCodeManager(); std::shared_ptr GetIsoCountryCode(); void UnregisterCountryCodeCallback(const sptr& callback); - void RegisterCountryCodeCallback(const sptr& callback, pid_t uid); + void RegisterCountryCodeCallback(const sptr& callback, AppIdentity &identity); void ReSubscribeEvent(); void ReUnsubscribeEvent(); bool IsCountryCodeRegistered(); @@ -54,6 +55,7 @@ private: bool SubscribeLocaleConfigEvent(); bool UnsubscribeSimEvent(); bool UnsubscribeNetworkStatusEvent(); + bool CheckPermissionforUser(AppIdentity &identity); class LocatorCallback : public IRemoteStub { public: @@ -80,7 +82,7 @@ private: std::shared_ptr lastCountryByLocation_; std::shared_ptr lastCountry_; - std::vector> countryCodeCallbacks_; + std::map, AppIdentity> countryCodeCallbacksMap_; std::shared_ptr simSubscriber_; std::shared_ptr networkSubscriber_; std::mutex simSubscriberMutex_; diff --git a/interfaces/inner_api/include/hook_utils.h b/interfaces/inner_api/include/hook_utils.h index d528c3c9..e6f4ed90 100644 --- a/interfaces/inner_api/include/hook_utils.h +++ b/interfaces/inner_api/include/hook_utils.h @@ -41,6 +41,7 @@ enum class LocationProcessStage { LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS, WRITE_DFX_INNER_EVENT_PROCESS, ADD_REQUEST_TO_WORK_RECORD, + LOCATOR_SA_LOCATION_PERMISSION_CHECK, }; typedef struct { @@ -89,6 +90,7 @@ public: static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName, std::string bundleName); static bool CheckGnssLocationValidity(const std::unique_ptr& location); + static bool ExecuteHookWhenCheckAppForUser(std::string packageName); }; } // namespace Location } // namespace OHOS diff --git a/interfaces/inner_api/include/location_data_rdb_manager.h b/interfaces/inner_api/include/location_data_rdb_manager.h index 09bb6d5a..14549e0d 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 GetLocationEnhanceStatus(int32_t& state); static void SyncSwitchStatus(); private: - static std::mutex mutex_; + static std::mutex locationSwitchModeMutex_; }; } // namespace Location } // namespace OHOS diff --git a/interfaces/inner_api/include/permission_manager.h b/interfaces/inner_api/include/permission_manager.h index 77eb759d..fa09681a 100644 --- a/interfaces/inner_api/include/permission_manager.h +++ b/interfaces/inner_api/include/permission_manager.h @@ -45,6 +45,7 @@ public: static bool CheckRssProcessName(uint32_t tokenId); static bool CheckSystemPermission(uint32_t callerTokenId, uint64_t callerTokenIdEx); static int GetPermissionLevel(uint32_t tokenId, uint32_t firstTokenId); + static bool CheckIsSystemSA(uint32_t tokenId); }; } // namespace Location } // namespace OHOS diff --git a/services/location_gnss/gnss/include/gnss_ability.h b/services/location_gnss/gnss/include/gnss_ability.h index 82125bcd..bae5d492 100644 --- a/services/location_gnss/gnss/include/gnss_ability.h +++ b/services/location_gnss/gnss/include/gnss_ability.h @@ -159,9 +159,9 @@ public: LocationErrCode SendLocationRequest(WorkRecord &workrecord) override; LocationErrCode SetEnable(bool state) override; LocationErrCode RefrashRequirements() override; - LocationErrCode RegisterGnssStatusCallback(const sptr& callback, pid_t uid) override; + LocationErrCode RegisterGnssStatusCallback(const sptr& callback, AppIdentity &identity) override; LocationErrCode UnregisterGnssStatusCallback(const sptr& callback) override; - LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, pid_t uid) override; + LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, AppIdentity &identity) override; LocationErrCode UnregisterNmeaMessageCallback(const sptr& callback) override; LocationErrCode RegisterCachedCallback(const std::unique_ptr& request, const sptr& callback) override; @@ -240,6 +240,7 @@ private: bool IsGnssfenceRequestMapExist(); bool CheckBundleNameInGnssGeofenceRequestMap(const std::string& bundleName, int fenceId); bool ConnectGnssHdi(); + bool CheckGnssPermissionforUser(AppIdentity &identity); #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE bool ConnectAgnssHdi(); #endif @@ -258,8 +259,8 @@ private: ffrt::mutex nmeaMutex_; ffrt::mutex hdiMutex_; ffrt::mutex statusMutex_; - std::vector> gnssStatusCallback_; - std::vector> nmeaCallback_; + std::map, AppIdentity> gnssStatusCallbackMap_; + std::map, AppIdentity> nmeaCallbackMap_; sptr gnssCallback_; Location nlpLocation_; #ifdef TIME_SERVICE_ENABLE diff --git a/services/location_gnss/gnss/include/gnss_ability_skeleton.h b/services/location_gnss/gnss/include/gnss_ability_skeleton.h index 87164d39..ae66482c 100644 --- a/services/location_gnss/gnss/include/gnss_ability_skeleton.h +++ b/services/location_gnss/gnss/include/gnss_ability_skeleton.h @@ -34,9 +34,9 @@ class IGnssAbility : public ISubAbility { public: DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssAbility"); virtual LocationErrCode RefrashRequirements() = 0; - virtual LocationErrCode RegisterGnssStatusCallback(const sptr& callback, pid_t uid) = 0; + virtual LocationErrCode RegisterGnssStatusCallback(const sptr& callback, AppIdentity &identity) = 0; virtual LocationErrCode UnregisterGnssStatusCallback(const sptr& callback) = 0; - virtual LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, pid_t uid) = 0; + virtual LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, AppIdentity &identity) = 0; virtual LocationErrCode UnregisterNmeaMessageCallback(const sptr& callback) = 0; virtual LocationErrCode RegisterCachedCallback(const std::unique_ptr& request, const sptr& callback) = 0; diff --git a/services/location_gnss/gnss/source/gnss_ability.cpp b/services/location_gnss/gnss/source/gnss_ability.cpp index f613f16a..fd86757c 100644 --- a/services/location_gnss/gnss/source/gnss_ability.cpp +++ b/services/location_gnss/gnss/source/gnss_ability.cpp @@ -41,6 +41,7 @@ #include "locationhub_ipc_interface_code.h" #include "location_log_event_ids.h" #include "location_data_rdb_manager.h" +#include "permission_manager.h" #ifdef NOTIFICATION_ENABLE #include "notification_request.h" @@ -239,7 +240,8 @@ LocationErrCode GnssAbility::RefrashRequirements() return ERRCODE_SUCCESS; } -LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr& callback, pid_t uid) +LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr& callback, + AppIdentity &identity) { if (callback == nullptr) { LBSLOGE(GNSS, "register an invalid gnssStatus callback"); @@ -253,9 +255,9 @@ LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr lock(gnssMutex_); - gnssStatusCallback_.push_back(gnssStatusCallback); - LBSLOGD(GNSS, "after uid:%{public}d register, gnssStatusCallback size:%{public}s", - uid, std::to_string(gnssStatusCallback_.size()).c_str()); + gnssStatusCallbackMap_.insert(std::make_pair(gnssStatusCallback, identity)); + LBSLOGD(GNSS, "RegisterGnssStatusCallback uid:%{public}d register, gnssStatusCallback size:%{public}s", + identity.GetUid(), std::to_string(gnssStatusCallbackMap_.size()).c_str()); return ERRCODE_SUCCESS; } @@ -272,28 +274,29 @@ LocationErrCode GnssAbility::UnregisterGnssStatusCallback(const sptr lock(gnssMutex_); - if (gnssStatusCallback_.size() <= 0) { - LBSLOGE(COUNTRY_CODE, "gnssStatusCallback_ size <= 0"); + if (gnssStatusCallbackMap_.size() <= 0) { + LBSLOGE(COUNTRY_CODE, "gnssStatusCallbackMap_ size <= 0"); return ERRCODE_SUCCESS; } size_t i = 0; - for (; i < gnssStatusCallback_.size(); i++) { - sptr remoteObject = gnssStatusCallback_[i]->AsObject(); + std::map, AppIdentity>::iterator iter; + for (iter = gnssStatusCallbackMap_.begin(); iter != gnssStatusCallbackMap_.end(); iter++) { + sptr remoteObject = iter->first->AsObject(); + LBSLOGE(GNSS, "UnregisterGnssStatusCallback gnssStatusCallbackMap_"); if (remoteObject == callback) { break; } } - if (i >= gnssStatusCallback_.size()) { - LBSLOGD(GNSS, "gnssStatus callback is not in vector"); - return ERRCODE_SUCCESS; + if (iter != gnssStatusCallbackMap_.end()) { + gnssStatusCallbackMap_.erase(iter); } - gnssStatusCallback_.erase(gnssStatusCallback_.begin() + i); LBSLOGD(GNSS, "after unregister, gnssStatus callback size:%{public}s", - std::to_string(gnssStatusCallback_.size()).c_str()); + std::to_string(gnssStatusCallbackMap_.size()).c_str()); return ERRCODE_SUCCESS; } -LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr& callback, pid_t uid) +LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr& callback, + AppIdentity &identity) { if (callback == nullptr) { LBSLOGE(GNSS, "register an invalid nmea callback"); @@ -307,9 +310,9 @@ LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr lock(nmeaMutex_); - nmeaCallback_.push_back(nmeaCallback); + nmeaCallbackMap_.insert(std::make_pair(nmeaCallback, identity)); LBSLOGD(GNSS, "after uid:%{public}d register, nmeaCallback size:%{public}s", - uid, std::to_string(nmeaCallback_.size()).c_str()); + identity.GetUid(), std::to_string(nmeaCallbackMap_.size()).c_str()); return ERRCODE_SUCCESS; } @@ -326,24 +329,25 @@ LocationErrCode GnssAbility::UnregisterNmeaMessageCallback(const sptr lock(nmeaMutex_); - if (nmeaCallback_.size() <= 0) { - LBSLOGE(COUNTRY_CODE, "nmeaCallback_ size <= 0"); + if (nmeaCallbackMap_.size() <= 0) { + LBSLOGE(COUNTRY_CODE, "nmeaCallbackMap_ size <= 0"); return ERRCODE_SUCCESS; } - size_t i = 0; - for (; i < nmeaCallback_.size(); i++) { - sptr remoteObject = nmeaCallback_[i]->AsObject(); + + std::map, AppIdentity>::iterator iter; + for (iter = nmeaCallbackMap_.begin(); iter != nmeaCallbackMap_.end(); iter++) { + sptr remoteObject = iter->first->AsObject(); if (remoteObject == callback) { break; } } - if (i >= nmeaCallback_.size()) { - LBSLOGD(GNSS, "nmea callback is not in vector"); - return ERRCODE_SUCCESS; + if (iter != nmeaCallbackMap_.end()) { + AppIdentity nmeaIdentity = iter->second; + nmeaCallbackMap_.erase(iter); } - nmeaCallback_.erase(nmeaCallback_.begin() + i); + LBSLOGD(GNSS, "after unregister, nmea callback size:%{public}s", - std::to_string(nmeaCallback_.size()).c_str()); + std::to_string(nmeaCallbackMap_.size()).c_str()); return ERRCODE_SUCCESS; } @@ -948,16 +952,36 @@ void GnssAbility::ReportGnssSessionStatus(int status) void GnssAbility::ReportNmea(int64_t timestamp, const std::string &nmea) { std::unique_lock lock(nmeaMutex_); - for (auto nmeaCallback : nmeaCallback_) { - nmeaCallback->OnMessageChange(timestamp, nmea); + for (const auto& pair : nmeaCallbackMap_) { + auto nmeaCallback = pair.first; + AppIdentity nmeaIdentity = pair.second; + if (CheckGnssPermissionforUser(nmeaIdentity)) { + nmeaCallback->OnMessageChange(timestamp, nmea); + } } } +bool GnssAbility::CheckGnssPermissionforUser(AppIdentity &identity) +{ + if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) { + return true; + } + if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) { + return true; + } + LBSLOGE(LOCATOR, "CheckGnssPermissionforUser fail: %{public}d", identity.GetUid()); + return false; +} + void GnssAbility::ReportSv(const std::unique_ptr &sv) { std::unique_lock lock(gnssMutex_); - for (auto gnssStatusCallback : gnssStatusCallback_) { - gnssStatusCallback->OnStatusChange(sv); + for (const auto& pair : gnssStatusCallbackMap_) { + auto gnssStatusCallback = pair.first; + AppIdentity gnssStatusIdentity = pair.second; + if (CheckGnssPermissionforUser(gnssStatusIdentity)) { + gnssStatusCallback->OnStatusChange(sv); + } } } diff --git a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp index 97958574..b4b8364f 100644 --- a/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp +++ b/services/location_gnss/gnss/source/gnss_ability_skeleton.cpp @@ -172,8 +172,10 @@ int GnssAbilityStub::RegisterGnssStatusCallbackInner(MessageParcel &data, Messag if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) { return ERRCODE_PERMISSION_DENIED; } + AppIdentity appIdentity; + appIdentity.ReadFromParcel(data); sptr client = data.ReadObject(); - reply.WriteInt32(RegisterGnssStatusCallback(client, identity.GetUid())); + reply.WriteInt32(RegisterGnssStatusCallback(client, appIdentity)); return ERRCODE_SUCCESS; } @@ -193,8 +195,10 @@ int GnssAbilityStub::RegisterNmeaMessageCallbackInner(MessageParcel &data, Messa if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) { return ERRCODE_PERMISSION_DENIED; } + AppIdentity appIdentity; + appIdentity.ReadFromParcel(data); sptr client = data.ReadObject(); - reply.WriteInt32(RegisterNmeaMessageCallback(client, identity.GetUid())); + reply.WriteInt32(RegisterNmeaMessageCallback(client, appIdentity)); return ERRCODE_SUCCESS; } diff --git a/services/location_locator/locator/include/gnss_ability_proxy.h b/services/location_locator/locator/include/gnss_ability_proxy.h index f88073e6..aaabb054 100644 --- a/services/location_locator/locator/include/gnss_ability_proxy.h +++ b/services/location_locator/locator/include/gnss_ability_proxy.h @@ -34,9 +34,9 @@ public: LocationErrCode SendLocationRequest(WorkRecord &workrecord) override; LocationErrCode SetEnable(bool state) override; LocationErrCode RefrashRequirements() override; - LocationErrCode RegisterGnssStatusCallback(const sptr& callback, pid_t uid) override; + LocationErrCode RegisterGnssStatusCallback(const sptr& callback, AppIdentity &identity) override; LocationErrCode UnregisterGnssStatusCallback(const sptr& callback) override; - LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, pid_t uid) override; + LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, AppIdentity &identity) override; LocationErrCode UnregisterNmeaMessageCallback(const sptr& callback) override; LocationErrCode RegisterCachedCallback(const std::unique_ptr& request, const sptr& callback) override; diff --git a/services/location_locator/locator/include/locator_ability.h b/services/location_locator/locator/include/locator_ability.h index ebf55eef..ee6fec92 100644 --- a/services/location_locator/locator/include/locator_ability.h +++ b/services/location_locator/locator/include/locator_ability.h @@ -112,9 +112,9 @@ public: LocationErrCode RegisterSwitchCallback(const sptr& callback, pid_t uid); LocationErrCode UnregisterSwitchCallback(const sptr& callback); #ifdef FEATURE_GNSS_SUPPORT - LocationErrCode RegisterGnssStatusCallback(const sptr& callback, pid_t uid); + LocationErrCode RegisterGnssStatusCallback(const sptr& callback, AppIdentity &identity); LocationErrCode UnregisterGnssStatusCallback(const sptr& callback); - LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, pid_t uid); + LocationErrCode RegisterNmeaMessageCallback(const sptr& callback, AppIdentity &identity); LocationErrCode UnregisterNmeaMessageCallback(const sptr& callback); LocationErrCode RegisterCachedLocationCallback(std::unique_ptr& request, sptr& callback, std::string bundleName); diff --git a/services/location_locator/locator/include/locator_required_data_manager.h b/services/location_locator/locator/include/locator_required_data_manager.h index 15fb6d23..31e4cb59 100644 --- a/services/location_locator/locator/include/locator_required_data_manager.h +++ b/services/location_locator/locator/include/locator_required_data_manager.h @@ -33,6 +33,7 @@ #include "i_locating_required_data_callback.h" #include "locating_required_data_config.h" #include "system_ability_status_change_stub.h" +#include "app_identity.h" #ifdef WIFI_ENABLE #include "wifi_scan.h" #endif @@ -203,7 +204,7 @@ class LocatorRequiredDataManager { public: LocatorRequiredDataManager(); ~LocatorRequiredDataManager(); - __attribute__((no_sanitize("cfi"))) LocationErrCode RegisterCallback( + __attribute__((no_sanitize("cfi"))) LocationErrCode RegisterCallback(AppIdentity &identity, std::shared_ptr& config, const sptr& callback); LocationErrCode UnregisterCallback(const sptr& callback); void ReportData(const std::vector>& result); @@ -223,6 +224,7 @@ public: private: void WifiInfoInit(); bool isWifiCallbackRegistered(); + bool CheckDataPermissionforUser(AppIdentity &identity); std::shared_ptr wifiScanPtr_; sptr wifiScanEventCallback_; bool isWifiCallbackRegistered_ = false; @@ -231,7 +233,7 @@ private: sptr(new WifiServiceStatusChange()); #endif std::mutex mutex_; - std::vector> callbacks_; + std::map, AppIdentity> callbacksMap_; std::shared_ptr scanHandler_; std::shared_ptr scanListHandler_; }; diff --git a/services/location_locator/locator/source/gnss_ability_proxy.cpp b/services/location_locator/locator/source/gnss_ability_proxy.cpp index 2b5c2add..b1ab32a0 100644 --- a/services/location_locator/locator/source/gnss_ability_proxy.cpp +++ b/services/location_locator/locator/source/gnss_ability_proxy.cpp @@ -84,7 +84,7 @@ LocationErrCode GnssAbilityProxy::RefrashRequirements() return LocationErrCode(reply.ReadInt32()); } -LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptr& callback, pid_t uid) +LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptr& callback, AppIdentity &identity) { MessageParcel data; MessageParcel reply; @@ -93,6 +93,9 @@ LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptrSendRequest(static_cast(GnssInterfaceCode::REG_GNSS_STATUS), data, reply, option); @@ -120,7 +123,8 @@ LocationErrCode GnssAbilityProxy::UnregisterGnssStatusCallback(const sptr& callback, pid_t uid) +LocationErrCode GnssAbilityProxy::RegisterNmeaMessageCallback(const sptr& callback, + AppIdentity &identity) { MessageParcel data; MessageParcel reply; @@ -129,6 +133,9 @@ LocationErrCode GnssAbilityProxy::RegisterNmeaMessageCallback(const sptrSendRequest(static_cast(GnssInterfaceCode::REG_NMEA), data, reply, option); LBSLOGI(GNSS, "%{public}s Transact Error = %{public}d", __func__, error); diff --git a/services/location_locator/locator/source/locator_ability.cpp b/services/location_locator/locator/source/locator_ability.cpp index a675fc69..3ea64747 100644 --- a/services/location_locator/locator/source/locator_ability.cpp +++ b/services/location_locator/locator/source/locator_ability.cpp @@ -531,14 +531,16 @@ LocationErrCode LocatorAbility::SendGnssRequest(int type, MessageParcel &data, M #endif #ifdef FEATURE_GNSS_SUPPORT -LocationErrCode LocatorAbility::RegisterGnssStatusCallback(const sptr& callback, pid_t uid) +LocationErrCode LocatorAbility::RegisterGnssStatusCallback(const sptr& callback, + AppIdentity &identity) { - LBSLOGD(LOCATOR, "uid is: %{public}d", uid); + LBSLOGD(LOCATOR, "uid is: %{public}d", identity.GetUid()); MessageParcel dataToStub; MessageParcel replyToStub; if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) { return ERRCODE_SERVICE_UNAVAILABLE; } + identity.Marshalling(dataToStub); dataToStub.WriteRemoteObject(callback); return SendGnssRequest(static_cast(GnssInterfaceCode::REG_GNSS_STATUS), dataToStub, replyToStub); } @@ -558,13 +560,15 @@ LocationErrCode LocatorAbility::UnregisterGnssStatusCallback(const sptr& callback, pid_t uid) +LocationErrCode LocatorAbility::RegisterNmeaMessageCallback(const sptr& callback, + AppIdentity &identity) { MessageParcel dataToStub; MessageParcel replyToStub; if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) { return ERRCODE_SERVICE_UNAVAILABLE; } + identity.Marshalling(dataToStub); dataToStub.WriteRemoteObject(callback); return SendGnssRequest(static_cast(GnssInterfaceCode::REG_NMEA), dataToStub, replyToStub); } diff --git a/services/location_locator/locator/source/locator_background_proxy.cpp b/services/location_locator/locator/source/locator_background_proxy.cpp index fa5c94b8..ee5aecd4 100644 --- a/services/location_locator/locator/source/locator_background_proxy.cpp +++ b/services/location_locator/locator/source/locator_background_proxy.cpp @@ -288,7 +288,7 @@ void LocatorBackgroundProxy::OnUserSwitch(int32_t userId) LocationDataRdbManager::ClearSwitchMode(); auto locatorAbility = LocatorAbility::GetInstance(); if (locatorAbility != nullptr) { - locatorAbility->ApplyRequests(1); + locatorAbility->ApplyRequests(0); } if (!requestsList_->empty()) { StartLocator(); diff --git a/services/location_locator/locator/source/locator_required_data_manager.cpp b/services/location_locator/locator/source/locator_required_data_manager.cpp index 28e2767f..6963e1df 100644 --- a/services/location_locator/locator/source/locator_required_data_manager.cpp +++ b/services/location_locator/locator/source/locator_required_data_manager.cpp @@ -18,6 +18,8 @@ #include "wifi_errcode.h" #endif #include "iservice_registry.h" +#include "common_utils.h" +#include "permission_manager.h" namespace OHOS { namespace Location { @@ -46,7 +48,7 @@ LocatorRequiredDataManager::~LocatorRequiredDataManager() } __attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::RegisterCallback( - std::shared_ptr& config, const sptr& callback) + AppIdentity &identity, std::shared_ptr& config, const sptr& callback) { sptr dataCallback = iface_cast(callback); if (dataCallback == nullptr) { @@ -64,9 +66,8 @@ __attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager:: } std::unique_lock lock(mutex_, std::defer_lock); lock.lock(); - callbacks_.push_back(dataCallback); - LBSLOGD(LOCATOR, "after RegisterCallback, callback size:%{public}s", std::to_string(callbacks_.size()).c_str()); - if (config->GetNeedStartScan() && callbacks_.size() == 1) { + callbacksMap_.insert(std::make_pair(dataCallback, identity)); + if (config->GetNeedStartScan() && callbacksMap_.size() == 1) { timeInterval_ = config->GetScanIntervalMs(); if (scanHandler_ != nullptr) { scanHandler_->SendEvent(EVENT_START_SCAN, 0, 0); @@ -88,22 +89,23 @@ LocationErrCode LocatorRequiredDataManager::UnregisterCallback(const sptr lock(mutex_); - size_t i = 0; - for (; i < callbacks_.size(); i++) { - sptr remoteObject = callbacks_[i]->AsObject(); + if (callbacksMap_.size() <= 0) { + LBSLOGD(GNSS, "scan callback is not in vector"); + return ERRCODE_SUCCESS; + } + std::map, AppIdentity>::iterator iter; + for (iter = callbacksMap_.begin(); iter != callbacksMap_.end(); iter++) { + sptr remoteObject = iter->first->AsObject(); if (remoteObject == callback) { break; } } - if (callbacks_.size() <= i) { - LBSLOGD(GNSS, "scan callback is not in vector"); - return ERRCODE_SUCCESS; + if (iter != callbacksMap_.end()) { + callbacksMap_.erase(iter); } - if (callbacks_.size() > 0) { - callbacks_.erase(callbacks_.begin() + i); - } - LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s", std::to_string(callbacks_.size()).c_str()); - if (scanHandler_ != nullptr && callbacks_.size() == 0) { + LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s", + std::to_string(callbacksMap_.size()).c_str()); + if (scanHandler_ != nullptr && callbacksMap_.size() == 0) { scanHandler_->SendEvent(EVENT_STOP_SCAN, 0, 0); } return ERRCODE_SUCCESS; @@ -307,11 +309,28 @@ void LocatorWifiScanEventCallback::OnWifiScanStateChanged(int state) void LocatorRequiredDataManager::ReportData(const std::vector>& result) { std::unique_lock lock(mutex_); - for (size_t i = 0; i < callbacks_.size(); i++) { - callbacks_[i]->OnLocatingDataChange(result); + for (const auto& pair : callbacksMap_) { + auto locatingRequiredDataCallback = pair.first; + AppIdentity identity = pair.second; + if (CheckDataPermissionforUser(identity)) { + locatingRequiredDataCallback->OnLocatingDataChange(result); + } } } +bool LocatorRequiredDataManager::CheckDataPermissionforUser(AppIdentity &identity) +{ + if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) { + return true; + } + if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) { + return true; + } + LBSLOGE(LOCATOR, "CheckDataPermissionforUser fail: %{public}d", identity.GetUid()); + return false; +} + + __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiScan(bool flag) { if (!flag) { @@ -354,7 +373,7 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiSc bool LocatorRequiredDataManager::IsConnecting() { std::unique_lock lock(mutex_); - if (callbacks_.size() > 0) { + if (callbacksMap_.size() > 0) { return true; } return false; diff --git a/services/location_locator/locator/source/locator_skeleton.cpp b/services/location_locator/locator/source/locator_skeleton.cpp index 5bbcbaa2..b1b15473 100644 --- a/services/location_locator/locator/source/locator_skeleton.cpp +++ b/services/location_locator/locator/source/locator_skeleton.cpp @@ -33,6 +33,7 @@ #include "location_log_event_ids.h" #include "geofence_request.h" #include "permission_manager.h" +#include "hook_utils.h" namespace OHOS { namespace Location { @@ -487,7 +488,8 @@ int LocatorAbilityStub::PreRegisterGnssStatusCallback(MessageParcel &data, Messa return ERRCODE_SERVICE_UNAVAILABLE; } sptr client = data.ReadObject(); - reply.WriteInt32(locatorAbility->RegisterGnssStatusCallback(client, identity.GetUid())); + + reply.WriteInt32(locatorAbility->RegisterGnssStatusCallback(client, identity)); return ERRCODE_SUCCESS; } #endif @@ -528,7 +530,7 @@ int LocatorAbilityStub::PreRegisterNmeaMessageCallback(MessageParcel &data, return ERRCODE_SERVICE_UNAVAILABLE; } sptr client = data.ReadObject(); - reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity.GetUid())); + reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity)); return ERRCODE_SUCCESS; } #endif @@ -569,7 +571,7 @@ int LocatorAbilityStub::PreRegisterNmeaMessageCallbackV9(MessageParcel &data, reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE); return ERRCODE_SERVICE_UNAVAILABLE; } - reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity.GetUid())); + reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity)); return ERRCODE_SUCCESS; } #endif @@ -1104,7 +1106,7 @@ int LocatorAbilityStub::PreRegisterLocatingRequiredDataCallback(MessageParcel &d return ERRCODE_SERVICE_UNAVAILABLE; } client->AddDeathRecipient(scanRecipient_); - LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, client); + LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, client); reply.WriteInt32(errorCode); return ERRCODE_SUCCESS; @@ -1325,13 +1327,14 @@ bool LocatorAbilityStub::CheckRequestAvailable(uint32_t code, AppIdentity &ident if (IsStopAction(code)) { return true; } - if (PermissionManager::CheckSystemPermission(identity.GetTokenId(), identity.GetTokenIdEx())) { + if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) { return true; } - if (!CommonUtils::CheckAppForUser(identity.GetUid())) { - return false; + if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) { + return true; } - return true; + LBSLOGD(LOCATOR, "CheckRequestAvailable fail uid:%{public}d", identity.GetUid()); + return false; } int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) diff --git a/services/location_locator/locator/source/report_manager.cpp b/services/location_locator/locator/source/report_manager.cpp index c088d95f..10d231aa 100644 --- a/services/location_locator/locator/source/report_manager.cpp +++ b/services/location_locator/locator/source/report_manager.cpp @@ -208,8 +208,13 @@ std::unique_ptr ReportManager::GetPermittedLocation(const std::shared_ } return nullptr; } - if (!PermissionManager::CheckSystemPermission(tokenId, tokenIdEx) && - !CommonUtils::CheckAppForUser(uid)) { + if (!PermissionManager::CheckIsSystemSA(tokenId) && + !CommonUtils::CheckAppForUser(uid, bundleName)) { + LBSLOGI(REPORT_MANAGER, "GetPermittedLocation uid: %{public}d CheckAppForUser fail", tokenId); + auto locationErrorCallback = request->GetLocationErrorCallBack(); + if (locationErrorCallback != nullptr) { + locationErrorCallback->OnErrorReport(LOCATING_FAILED_LOCATION_PERMISSION_DENIED); + } return nullptr; } std::unique_ptr finalLocation = std::make_unique(*location); diff --git a/services/location_locator/locator/source/request_manager.cpp b/services/location_locator/locator/source/request_manager.cpp index f7c213fb..82f3fed8 100644 --- a/services/location_locator/locator/source/request_manager.cpp +++ b/services/location_locator/locator/source/request_manager.cpp @@ -492,9 +492,7 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared if (requestConfig == nullptr) { return false; } - - if (!PermissionManager::CheckSystemPermission(tokenId, request->GetTokenIdEx()) && - !CommonUtils::CheckAppForUser(uid)) { + if (!PermissionManager::CheckIsSystemSA(tokenId) && !CommonUtils::CheckAppForUser(uid, bundleName)) { LBSLOGD(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid); return false; } diff --git a/test/fuzztest/locator/countrycodemanager_fuzzer/countrycodemanager_fuzzer.cpp b/test/fuzztest/locator/countrycodemanager_fuzzer/countrycodemanager_fuzzer.cpp index ae3fda1c..c9231cd7 100644 --- a/test/fuzztest/locator/countrycodemanager_fuzzer/countrycodemanager_fuzzer.cpp +++ b/test/fuzztest/locator/countrycodemanager_fuzzer/countrycodemanager_fuzzer.cpp @@ -24,11 +24,14 @@ namespace OHOS { if (size == 0) { return true; } + AppIdentity identity; + int pid = 1; + identity.SetPid(pid); + identity.SetUid(pid); auto countryCodeManager = CountryCodeManager::GetInstance(); countryCodeManager->GetIsoCountryCode(); countryCodeManager->UnregisterCountryCodeCallback(nullptr); - int index = 0; - countryCodeManager->RegisterCountryCodeCallback(nullptr, data[index++]); + countryCodeManager->RegisterCountryCodeCallback(nullptr, identity); countryCodeManager->ReSubscribeEvent(); countryCodeManager->ReUnsubscribeEvent(); return true; diff --git a/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp b/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp index 29817498..41fe9244 100644 --- a/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp +++ b/test/fuzztest/locator/gnss_fuzzer/gnss_fuzzer.cpp @@ -58,13 +58,15 @@ namespace OHOS { std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); auto gnssCallbackHost = sptr(new (std::nothrow) GnssStatusCallbackNapi()); - proxy->RegisterGnssStatusCallback(gnssCallbackHost, data[index++]); + AppIdentity identity; + identity.SetPid(data[index++]); + proxy->RegisterGnssStatusCallback(gnssCallbackHost, identity); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); proxy->UnregisterGnssStatusCallback(gnssCallbackHost); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); auto nmeaCallbackHost = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); - proxy->RegisterNmeaMessageCallback(nmeaCallbackHost, data[index++]); + proxy->RegisterNmeaMessageCallback(nmeaCallbackHost, identity); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); proxy->UnregisterNmeaMessageCallback(nmeaCallbackHost); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES)); diff --git a/test/location_gnss/mock/include/mock_gnss_ability_stub.h b/test/location_gnss/mock/include/mock_gnss_ability_stub.h index 2ba1b4f2..bea082f8 100644 --- a/test/location_gnss/mock/include/mock_gnss_ability_stub.h +++ b/test/location_gnss/mock/include/mock_gnss_ability_stub.h @@ -38,9 +38,11 @@ public: ~MockGnssAbilityStub() {} MOCK_METHOD(void, SendMessage, (uint32_t code, MessageParcel &data, MessageParcel &reply)); MOCK_METHOD(LocationErrCode, RefrashRequirements, ()); - MOCK_METHOD(LocationErrCode, RegisterGnssStatusCallback, (const sptr& callback, pid_t uid)); + MOCK_METHOD(LocationErrCode, RegisterGnssStatusCallback, (const sptr& callback, + AppIdentity &identity)); MOCK_METHOD(LocationErrCode, UnregisterGnssStatusCallback, (const sptr& callback)); - MOCK_METHOD(LocationErrCode, RegisterNmeaMessageCallback, (const sptr& callback, pid_t uid)); + MOCK_METHOD(LocationErrCode, RegisterNmeaMessageCallback, (const sptr& callback, + AppIdentity &identity)); MOCK_METHOD(LocationErrCode, UnregisterNmeaMessageCallback, (const sptr& callback)); MOCK_METHOD(LocationErrCode, RegisterCachedCallback, (const std::unique_ptr& request, const sptr& callback)); diff --git a/test/location_gnss/source/gnss_ability_test.cpp b/test/location_gnss/source/gnss_ability_test.cpp index 98cf3166..4ad3fb11 100644 --- a/test/location_gnss/source/gnss_ability_test.cpp +++ b/test/location_gnss/source/gnss_ability_test.cpp @@ -220,12 +220,14 @@ HWTEST_F(GnssAbilityTest, RegisterGnssStatusCallback001, TestSize.Level1) */ pid_t lastCallingUid = 1; sptr client = nullptr; - + AppIdentity identity; + identity.SetPid(lastCallingUid); + identity.SetUid(23); /* * @tc.steps: step2. test register gnss status callback * @tc.expected: log info : "SendRegisterMsgToRemote callback is nullptr". */ - EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterGnssStatusCallback(client, lastCallingUid)); + EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterGnssStatusCallback(client, identity)); LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterGnssStatusCallback001 end"); } @@ -243,12 +245,14 @@ HWTEST_F(GnssAbilityTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.L * @tc.steps: step1. give the last calling uid */ pid_t lastCallingUid = 1; - + AppIdentity identity; + identity.SetPid(lastCallingUid); + identity.SetUid(23); /* * @tc.steps: step2. test register gnss status callback * @tc.expected: no exception happens. */ - EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), lastCallingUid)); + EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), identity)); /* * @tc.steps: step3. test unregister gnss status callback @@ -296,12 +300,14 @@ HWTEST_F(GnssAbilityTest, RegisterNmeaMessageCallback001, TestSize.Level1) */ pid_t uid = 1; sptr client = nullptr; - + AppIdentity identity; + identity.SetPid(uid); + identity.SetUid(23); /* * @tc.steps: step2. test register nmea message callback * @tc.expected: log info : "register an invalid nmea callback". */ - EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterNmeaMessageCallback(client, uid)); + EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterNmeaMessageCallback(client, identity)); LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterNmeaMessageCallback001 end"); } @@ -319,12 +325,14 @@ HWTEST_F(GnssAbilityTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize. * @tc.steps: step1.the client is not null. */ pid_t uid = 1; - + AppIdentity identity; + identity.SetPid(uid); + identity.SetUid(23); /* * @tc.steps: step2. test register nmea message callback * @tc.expected: no exception happens */ - EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterNmeaMessageCallback(nemaCallbackStub_->AsObject(), uid)); + EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterNmeaMessageCallback(nemaCallbackStub_->AsObject(), identity)); /* * @tc.steps: step3. test unregister nmea message callback diff --git a/test/location_locator/source/country_code_manager_test.cpp b/test/location_locator/source/country_code_manager_test.cpp index 201b871e..76fc7a3d 100644 --- a/test/location_locator/source/country_code_manager_test.cpp +++ b/test/location_locator/source/country_code_manager_test.cpp @@ -53,7 +53,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback001, TestSize.Leve auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); ASSERT_TRUE(countryCodeManager != nullptr); countryCodeManager->UnregisterCountryCodeCallback(callback); - EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback001 end"); } @@ -65,7 +65,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback002, TestSize.Leve auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); countryCodeManager->UnregisterCountryCodeCallback(nullptr); - EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback002 end"); } @@ -78,7 +78,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback003, TestSize.Leve ASSERT_TRUE(countryCodeManager != nullptr); auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); countryCodeManager->UnregisterCountryCodeCallback(wrongCallback->AsObject()); - EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback003 end"); } @@ -90,14 +90,18 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback004, TestSize.Leve auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); auto callback1 = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(callback1, 0); + AppIdentity identity; + int pid = 2; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(callback1, identity); auto callback2 = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(callback2, 1); + countryCodeManager->RegisterCountryCodeCallback(callback2, identity); countryCodeManager->UnregisterCountryCodeCallback(callback1); // size != 0, func will return - EXPECT_EQ(1, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(1, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback004 end"); } @@ -108,8 +112,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback001, TestSize.Level1 LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); + AppIdentity identity; + int pid = 10; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(callback, identity); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 end"); } @@ -120,8 +128,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback002, TestSize.Level1 LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback002 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); - countryCodeManager->RegisterCountryCodeCallback(nullptr, 0); - EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); + AppIdentity identity; + int pid = 3; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(nullptr, identity); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback002 end"); } @@ -133,8 +145,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback003, TestSize.Level1 auto countryCodeManager = CountryCodeManager::GetInstance(); ASSERT_TRUE(countryCodeManager != nullptr); auto wrongCallback = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(wrongCallback->AsObject(), 0); - EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); + AppIdentity identity; + int pid = 4; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(wrongCallback->AsObject(), identity); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size()); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback003 end"); } @@ -144,7 +160,7 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1) << "CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size()); countryCodeManager->ReSubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 end"); } @@ -156,8 +172,12 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent002, TestSize.Level1) LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); + AppIdentity identity; + int pid = 3; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(callback, identity); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size()); countryCodeManager->ReSubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 end"); } @@ -168,7 +188,7 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1) << "CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1"; LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); - EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size()); + EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size()); countryCodeManager->ReUnsubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 end"); } @@ -180,28 +200,16 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent002, TestSize.Level1) LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 begin"); auto countryCodeManager = CountryCodeManager::GetInstance(); auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - countryCodeManager->RegisterCountryCodeCallback(callback, 0); - EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size()); + AppIdentity identity; + int pid = 3; + identity.SetPid(pid); + identity.SetUid(pid); + countryCodeManager->RegisterCountryCodeCallback(callback, identity); + EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size()); countryCodeManager->ReUnsubscribeEvent(); LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 end"); } -HWTEST_F(CountryCodeManagerTest, NotifyAllListener001, TestSize.Level1) -{ - GTEST_LOG_(INFO) - << "CountryCodeManagerTest, NotifyAllListener001, TestSize.Level1"; - LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 begin"); - auto countryCodeManager = CountryCodeManager::GetInstance(); - ASSERT_TRUE(countryCodeManager != nullptr); - auto callback = sptr(new (std::nothrow) CountryCodeCallbackNapi()); - sptr countryCodeCallback1 = iface_cast(callback); - countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback1); - sptr countryCodeCallback2 = nullptr; - countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback2); - countryCodeManager->NotifyAllListener(); - LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 end"); -} - HWTEST_F(CountryCodeManagerTest, GetCountryCodeByLastLocation001, TestSize.Level1) { GTEST_LOG_(INFO) diff --git a/test/location_locator/source/locator_required_data_manager_test.cpp b/test/location_locator/source/locator_required_data_manager_test.cpp index da5c8504..6b0dd097 100644 --- a/test/location_locator/source/locator_required_data_manager_test.cpp +++ b/test/location_locator/source/locator_required_data_manager_test.cpp @@ -63,7 +63,9 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback001, TestSize.Level1) dataConfig->SetNeedStartScan(true); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); - LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, nullptr); + AppIdentity identity; + identity.SetPid(1); + LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, nullptr); EXPECT_EQ(ERRCODE_INVALID_PARAM, errorCode); errorCode = locatorDataManager->UnregisterCallback(nullptr); EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, errorCode); @@ -82,9 +84,11 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback002, TestSize.Level1) dataConfig->SetNeedStartScan(false); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); + AppIdentity identity; + identity.SetPid(1); auto callback = sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); - LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject()); + LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, callback->AsObject()); EXPECT_EQ(ERRCODE_NOT_SUPPORTED, errorCode); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback002 end"); } @@ -101,9 +105,11 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback003, TestSize.Level1) dataConfig->SetNeedStartScan(false); dataConfig->SetScanIntervalMs(1); dataConfig->SetScanTimeoutMs(1); + AppIdentity identity; + identity.SetPid(1); auto callback = sptr(new (std::nothrow) LocatingRequiredDataCallbackNapi()); - LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject()); + LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, callback->AsObject()); EXPECT_EQ(ERRCODE_SUCCESS, errorCode); LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback003 end"); } diff --git a/test/location_locator/source/locator_service_test.cpp b/test/location_locator/source/locator_service_test.cpp index b333cad0..724c2770 100644 --- a/test/location_locator/source/locator_service_test.cpp +++ b/test/location_locator/source/locator_service_test.cpp @@ -1616,10 +1616,12 @@ HWTEST_F(LocatorServiceTest, locatorServiceGnssStatusCallback001, TestSize.Level auto gnssCallbackHost = sptr(new (std::nothrow) GnssStatusCallbackNapi()); + AppIdentity identity; + identity.SetPid(1); // uid pid not match locationhub process EXPECT_EQ(ERRCODE_PERMISSION_DENIED, - locatorAbility->RegisterGnssStatusCallback(nullptr, SYSTEM_UID)); // invalid callback - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(gnssCallbackHost, SYSTEM_UID)); + locatorAbility->RegisterGnssStatusCallback(nullptr, identity)); // invalid callback + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(gnssCallbackHost, identity)); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(nullptr)); // invalid callback EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(gnssCallbackHost)); LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGnssStatusCallback001 end"); @@ -1636,9 +1638,11 @@ HWTEST_F(LocatorServiceTest, locatorServiceNmeaMessageCallback001, TestSize.Leve sptr(new (std::nothrow) LocatorAbility()); auto nmeaCallbackHost = sptr(new (std::nothrow) NmeaMessageCallbackNapi()); + AppIdentity identity; + identity.SetPid(1); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, - locatorAbility->RegisterNmeaMessageCallback(nullptr, SYSTEM_UID)); // invalid callback - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, SYSTEM_UID)); + locatorAbility->RegisterNmeaMessageCallback(nullptr, identity)); // invalid callback + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, identity)); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nullptr)); // invalid callback EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nmeaCallbackHost)); LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceNmeaMessageCallback001 end");