diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 9d553405e4262eaefb0a2063d88ddba222fd373b..631fb4a6750dc48f15456190e0351d70bfbb2715 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -18,11 +18,15 @@ #include +#include "bundle_info.h" +#include "bundlemgr/bundle_mgr_proxy.h" #include "dds_trace.h" #include "udmf_radar_reporter.h" #include "accesstoken_kit.h" #include "device_manager_adapter.h" +#include "iservice_registry.h" #include "log_print.h" +#include "system_ability_definition.h" #include "udmf_radar_reporter.h" #include "udmf_utils.h" #include "remote_file_share.h" @@ -57,7 +61,10 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption & return E_ERROR; } std::string bundleName; - GetHapBundleNameByToken(option.tokenId, bundleName); + if (GetAlterableBundleNameByTokenId(option.tokenId, bundleName)) { + ZLOGE("GetAlterableBundleNameByTokenId failed."); + return E_ERROR; + } std::string intention = it->second; UnifiedKey key(intention, bundleName, GenerateId()); Privilege privilege; @@ -486,5 +493,49 @@ std::string PreProcessUtils::GetSdkVersionByToken(uint32_t tokenId) } return std::to_string(hapTokenInfo.apiVersion); } + +bool PreProcessUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) +{ + Security::AccessToken::HapTokenInfo hapInfo; + if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) + == Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { + return GetDirByBundleNameAndAppIndex(hapInfo.bundleName, hapInfo.instIndex, bundleName); + } + if (UTILS::IsTokenNative()) { + ZLOGD("TypeATokenTypeEnum is TOKEN_HAP"); + std::string processName; + if (GetNativeProcessNameByToken(tokenId, processName)) { + bundleName = processName; + return true; + } + } + ZLOGE("Get bundle name faild."); + return false; +} + +bool PreProcessUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) +{ + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + ZLOGE("Failed to get system ability mgr."); + return false; + } + auto bundleMgrProxy = samgrProxy->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundleMgrProxy == nullptr) { + ZLOGE("Failed to Get BMS SA."); + return false; + } + auto bundleManager = iface_cast(bundleMgrProxy); + if (bundleManager == nullptr) { + ZLOGE("Failed to get bundle manager"); + return false; + } + auto ret = bundleManager->GetDirByBundleNameAndAppIndex(bundleName, appIndex, dirName); + if (ret != ERR_OK) { + ZLOGE("GetDirByBundleNameAndAppIndex failed, ret:%{public}d", ret); + return false; + } + return true; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 1532f4c49136116310619fbb39865319e80e42e6..36bc7a0ee1de97959e012f71c9797dc119f36c25 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -42,11 +42,13 @@ public: static void SetRecordUid(UnifiedData &data); static bool GetDetailsFromUData(const UnifiedData &data, UDDetails &details); static Status GetSummaryFromDetails(const UDDetails &details, Summary &summary); + static bool GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName); private: static bool CheckUriAuthorization(const std::vector& uris, uint32_t tokenId); static int32_t GetDfsUrisFromLocal(const std::vector &uris, int32_t userId, UnifiedData &data); static bool IsFileType(std::shared_ptr record); static std::string GetSdkVersionByToken(uint32_t tokenId); + static bool GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName); }; } // namespace UDMF } // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index f48bb49536f39e21227c499ed6d3114101af1a9e..0e69d1f843843c57b7e34c222bf47f7e6b33b4e4 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -401,7 +401,10 @@ int32_t UdmfServiceImpl::UpdateData(const QueryOption &query, UnifiedData &unifi return E_INVALID_PARAMETERS; } std::string bundleName; - PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName); + if (PreProcessUtils::GetAlterableBundleNameByTokenId(query.tokenId, bundleName)) { + ZLOGE("GetAlterableBundleNameByTokenId failed."); + return E_ERROR; + } if (key.bundleName != bundleName && !HasDatahubPriviledge(bundleName)) { ZLOGE("update data failed by %{public}s, key: %{public}s.", bundleName.c_str(), query.key.c_str()); return E_INVALID_PARAMETERS; @@ -1041,7 +1044,10 @@ int32_t UdmfServiceImpl::SetDelayInfo(const DataLoadInfo &dataLoadInfo, sptr(IPCSkeleton::GetCallingTokenID()); - PreProcessUtils::GetHapBundleNameByToken(tokenId, bundleName); + if (PreProcessUtils::GetAlterableBundleNameByTokenId(tokenId, bundleName)) { + ZLOGE("GetAlterableBundleNameByTokenId failed."); + return E_ERROR; + } UnifiedKey udkey(UD_INTENTION_MAP.at(UD_INTENTION_DRAG), bundleName, dataLoadInfo.sequenceKey); key = udkey.GetUnifiedKey(); dataLoadCallback_.Insert(key, iface_cast(iUdmfNotifier));