diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index ecf0e3efc7..d13217d115 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -30,10 +30,10 @@ config("upms_config") { libupms_sources = [ "src/batch_uri.cpp", "src/file_permission_manager.cpp", + "src/file_uri_distribution_utils.cpp", "src/tokenid_permission.cpp", "src/uri_permission_manager_service.cpp", "src/uri_permission_manager_stub_impl.cpp", - "src/uri_permission_utils.cpp", ] #build so diff --git a/services/uripermmgr/include/uri_permission_utils.h b/services/uripermmgr/include/file_uri_distribution_utils.h similarity index 88% rename from services/uripermmgr/include/uri_permission_utils.h rename to services/uripermmgr/include/file_uri_distribution_utils.h index 5aa124c0ee..f37d9f716a 100644 --- a/services/uripermmgr/include/uri_permission_utils.h +++ b/services/uripermmgr/include/file_uri_distribution_utils.h @@ -13,10 +13,9 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H -#define OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H +#ifndef OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H +#define OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H -#include "bundle_mgr_helper.h" #include "event_report.h" #include "uri.h" @@ -28,7 +27,7 @@ struct FUDAppInfo { std::string alterBundleName; int32_t userId = 0; }; -class UPMSUtils { +class FUDUtils { public: static bool SendShareUnPrivilegeUriEvent(uint32_t callTokenId, uint32_t targetTokenId); static bool SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, @@ -51,10 +50,7 @@ public: private: static bool CheckAndCreateEventInfo(uint32_t callerTokenId, uint32_t targetTokenId, EventInfo &eventInfo); static bool CheckIsSystemAppByBundleName(std::string &bundleName); - -private: - static std::shared_ptr bundleMgrHelper_; }; } // OHOS } // AAFwk -#endif // OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H \ No newline at end of file +#endif // OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H \ No newline at end of file diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 3f9365e9f9..c950219c48 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -23,12 +23,12 @@ #include #include "app_mgr_interface.h" #include "batch_uri.h" +#include "file_uri_distribution_utils.h" #include "istorage_manager.h" #include "tokenid_permission.h" #include "uri.h" #include "uri_permission_manager_stub.h" #include "uri_permission_raw_data.h" -#include "uri_permission_utils.h" #include "access_token.h" #ifdef ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER diff --git a/services/uripermmgr/src/batch_uri.cpp b/services/uripermmgr/src/batch_uri.cpp index a645df7cef..f84563da22 100644 --- a/services/uripermmgr/src/batch_uri.cpp +++ b/services/uripermmgr/src/batch_uri.cpp @@ -16,8 +16,8 @@ #include "batch_uri.h" #include "file_permission_manager.h" +#include "file_uri_distribution_utils.h" #include "hilog_tag_wrapper.h" -#include "uri_permission_utils.h" #include "fud_constants.h" namespace OHOS { namespace AAFwk { diff --git a/services/uripermmgr/src/uri_permission_utils.cpp b/services/uripermmgr/src/file_uri_distribution_utils.cpp similarity index 88% rename from services/uripermmgr/src/uri_permission_utils.cpp rename to services/uripermmgr/src/file_uri_distribution_utils.cpp index 7d6238544b..c2bc283b25 100644 --- a/services/uripermmgr/src/uri_permission_utils.cpp +++ b/services/uripermmgr/src/file_uri_distribution_utils.cpp @@ -13,11 +13,12 @@ * limitations under the License. */ -#include "uri_permission_utils.h" +#include "file_uri_distribution_utils.h" #include "ability_manager_errors.h" #include "accesstoken_kit.h" #include "bundle_mgr_client.h" +#include "bundle_mgr_helper.h" #include "global_constant.h" #include "hilog_tag_wrapper.h" #include "in_process_call_wrapper.h" @@ -36,7 +37,7 @@ constexpr int32_t FOUNDATION_UID = 5523; constexpr const char* NET_WORK_ID_MARK = "?networkid="; } -bool UPMSUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t targetTokenId) +bool FUDUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t targetTokenId) { std::string callerBundleName; if (!GetBundleNameByTokenId(callerTokenId, callerBundleName)) { @@ -54,7 +55,7 @@ bool UPMSUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t ta return true; } -bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, +bool FUDUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, const std::vector &uriVec, const std::vector &resVec) { TAG_LOGD(AAFwkTag::URIPERMMGR, "send grant uri permission event start."); @@ -74,7 +75,7 @@ bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uin return false; } -bool UPMSUtils::CheckAndCreateEventInfo(uint32_t callerTokenId, uint32_t targetTokenId, +bool FUDUtils::CheckAndCreateEventInfo(uint32_t callerTokenId, uint32_t targetTokenId, EventInfo &eventInfo) { std::string callerBundleName; @@ -100,7 +101,7 @@ bool UPMSUtils::CheckAndCreateEventInfo(uint32_t callerTokenId, uint32_t targetT return true; } -int32_t UPMSUtils::GetCurrentAccountId() +int32_t FUDUtils::GetCurrentAccountId() { std::vector osActiveAccountIds; auto ret = DelayedSingleton::GetInstance()-> @@ -117,23 +118,23 @@ int32_t UPMSUtils::GetCurrentAccountId() return osActiveAccountIds.front(); } -bool UPMSUtils::IsFoundationCall() +bool FUDUtils::IsFoundationCall() { return IPCSkeleton::GetCallingUid() == FOUNDATION_UID; } -bool UPMSUtils::IsSAOrSystemAppCall() +bool FUDUtils::IsSAOrSystemAppCall() { return PermissionVerification::GetInstance()->IsSystemAppCall() || PermissionVerification::GetInstance()->IsSACall(); } -bool UPMSUtils::IsSystemAppCall() +bool FUDUtils::IsSystemAppCall() { return PermissionVerification::GetInstance()->IsSystemAppCall(); } -bool UPMSUtils::CheckIsSystemAppByBundleName(std::string &bundleName) +bool FUDUtils::CheckIsSystemAppByBundleName(std::string &bundleName) { auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { @@ -152,7 +153,7 @@ bool UPMSUtils::CheckIsSystemAppByBundleName(std::string &bundleName) return isSystemApp; } -bool UPMSUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t &targetApiVersion) +bool FUDUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t &targetApiVersion) { auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { @@ -169,7 +170,7 @@ bool UPMSUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t return true; } -bool UPMSUtils::CheckIsSystemAppByTokenId(uint32_t tokenId) +bool FUDUtils::CheckIsSystemAppByTokenId(uint32_t tokenId) { std::string bundleName; if (GetBundleNameByTokenId(tokenId, bundleName)) { @@ -178,7 +179,7 @@ bool UPMSUtils::CheckIsSystemAppByTokenId(uint32_t tokenId) return false; } -bool UPMSUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) +bool FUDUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) { // if get dir name failed, set dirName as bundleName dirName = bundleName; @@ -195,7 +196,7 @@ bool UPMSUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int return true; } -bool UPMSUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) +bool FUDUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) { auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { @@ -210,7 +211,7 @@ bool UPMSUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &b return false; } -bool UPMSUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) +bool FUDUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) { auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { @@ -226,7 +227,7 @@ bool UPMSUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName return false; } -int32_t UPMSUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId) +int32_t FUDUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId) { TAG_LOGD(AAFwkTag::URIPERMMGR, "BundleName is %{public}s.", bundleName.c_str()); auto bms = DelayedSingleton::GetInstance(); @@ -243,7 +244,7 @@ int32_t UPMSUtils::GetAppIdByBundleName(const std::string &bundleName, std::stri return ERR_OK; } -int32_t UPMSUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId) +int32_t FUDUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId) { TAG_LOGD(AAFwkTag::URIPERMMGR, "BundleName:%{public}s, appIndex:%{public}d", bundleName.c_str(), appIndex); auto bms = DelayedSingleton::GetInstance(); @@ -279,7 +280,7 @@ int32_t UPMSUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t return ERR_OK; } -bool UPMSUtils::GenerateFUDAppInfo(FUDAppInfo &info) +bool FUDUtils::GenerateFUDAppInfo(FUDAppInfo &info) { auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(info.tokenId); if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { @@ -296,7 +297,7 @@ bool UPMSUtils::GenerateFUDAppInfo(FUDAppInfo &info) return false; } -bool UPMSUtils::CheckUriTypeIsValid(Uri &uri) +bool FUDUtils::CheckUriTypeIsValid(Uri &uri) { auto &&scheme = uri.GetScheme(); if (scheme != FUDConstants::FILE_SCHEME && scheme != FUDConstants::CONTENT_SCHEME) { @@ -306,12 +307,10 @@ bool UPMSUtils::CheckUriTypeIsValid(Uri &uri) return true; } -bool UPMSUtils::IsDocsCloudUri(Uri &uri) +bool FUDUtils::IsDocsCloudUri(Uri &uri) { return (uri.GetAuthority() == FUDConstants::DOCS_AUTHORITY && uri.ToString().find(NET_WORK_ID_MARK) != std::string::npos); } - -std::shared_ptr UPMSUtils::bundleMgrHelper_ = nullptr; } // namespace AAFwk } // namespace OHOS diff --git a/services/uripermmgr/src/media_permission_manager.cpp b/services/uripermmgr/src/media_permission_manager.cpp index 6e99682f41..0513f1b05a 100644 --- a/services/uripermmgr/src/media_permission_manager.cpp +++ b/services/uripermmgr/src/media_permission_manager.cpp @@ -20,12 +20,12 @@ #include #include "ability_manager_errors.h" +#include "file_uri_distribution_utils.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "iservice_registry.h" #include "system_ability_definition.h" -#include "uri_permission_utils.h" #include "want.h" namespace OHOS { diff --git a/services/uripermmgr/src/upms_udmf_utils.cpp b/services/uripermmgr/src/upms_udmf_utils.cpp index 3664052b27..fc51e8c038 100644 --- a/services/uripermmgr/src/upms_udmf_utils.cpp +++ b/services/uripermmgr/src/upms_udmf_utils.cpp @@ -16,11 +16,11 @@ #include "upms_udmf_utils.h" #include "ability_manager_errors.h" +#include "file_uri_distribution_utils.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "udmf_client.h" -#include "uri_permission_utils.h" #include "uri.h" namespace OHOS { @@ -91,7 +91,7 @@ bool UDMFUtils::IsUdKeyCreateByCaller(uint32_t callerTokenId, const std::string HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto keyAuthority = IN_PROCESS_CALL(UDMF::UdmfClient::GetInstance().GetBundleNameByUdKey(key)); std::string callerAuthority; - UPMSUtils::GetAlterableBundleNameByTokenId(callerTokenId, callerAuthority); + FUDUtils::GetAlterableBundleNameByTokenId(callerTokenId, callerAuthority); if (callerAuthority != keyAuthority) { TAG_LOGE(AAFwkTag::URIPERMMGR, "Authority: %{public}s-%{public}s", keyAuthority.c_str(), callerAuthority.c_str()); diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index b552be729f..79d85cf115 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -19,6 +19,7 @@ #include "ability_manager_client.h" #include "accesstoken_kit.h" #include "app_utils.h" +#include "file_uri_distribution_utils.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "if_system_ability_manager.h" @@ -36,7 +37,6 @@ #endif // ABILITY_RUNTIME_FEATURE_SANDBOXMANAGER #include "system_ability_definition.h" #include "tokenid_kit.h" -#include "uri_permission_utils.h" #include "fud_constants.h" #ifdef ABILITY_RUNTIME_UDMF_ENABLE #include "upms_udmf_utils.h" @@ -72,7 +72,7 @@ ErrCode UriPermissionManagerStubImpl::VerifyUriPermission(const Uri& uri, uint32 // verify if tokenId have uri permission record TAG_LOGI(AAFwkTag::URIPERMMGR, "uri:%{private}s, flag:%{public}u, tokenId:%{public}u", uri.ToString().c_str(), flag, tokenId); - if (!UPMSUtils::IsSAOrSystemAppCall()) { + if (!FUDUtils::IsSAOrSystemAppCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "not SA/SystemApp"); funcResult = false; return ERR_OK; @@ -183,7 +183,7 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const Uri& uri, uint32_ { TAG_LOGI(AAFwkTag::URIPERMMGR, "Uri:%{private}s", uri.ToString().c_str()); Uri tempUri = uri; - if (UPMSUtils::IsSystemAppCall() && tempUri.GetScheme() != FUDConstants::FILE_SCHEME) { + if (FUDUtils::IsSystemAppCall() && tempUri.GetScheme() != FUDConstants::FILE_SCHEME) { TAG_LOGE(AAFwkTag::URIPERMMGR, "Only support file uri"); return WrapErrorCode(ERR_CODE_INVALID_URI_TYPE, funcResult); } @@ -198,7 +198,7 @@ ErrCode UriPermissionManagerStubImpl::GrantUriPermission(const std::vector uriVecInner; for (auto& uri : uriVec) { uriVecInner.emplace_back(uri); @@ -561,7 +561,7 @@ int32_t UriPermissionManagerStubImpl::GrantUriPermissionPrivilegedInner(const st int32_t grantRet = INNER_ERR; for (auto &uri : uriVec) { auto uriInner = uri; - if (!UPMSUtils::CheckUriTypeIsValid(uriInner)) { + if (!FUDUtils::CheckUriTypeIsValid(uriInner)) { continue; } validUriCount++; @@ -570,7 +570,7 @@ int32_t UriPermissionManagerStubImpl::GrantUriPermissionPrivilegedInner(const st batchUris.contentUris.emplace_back(uriInner.ToString()); continue; } - if (UPMSUtils::IsDocsCloudUri(uriInner)) { + if (FUDUtils::IsDocsCloudUri(uriInner)) { batchUris.uriStrVec.emplace_back(uriInner.ToString()); continue; } @@ -704,7 +704,7 @@ int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKeyAsCaller() TAG_LOGE(AAFwkTag::URIPERMMGR, "not support grant uri permission"); return ERR_CAPABILITY_NOT_SUPPORT; } - if (!UPMSUtils::IsSystemAppCall()) { + if (!FUDUtils::IsSystemAppCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "caller not system"); return ERR_NOT_SYSTEM_APP; } @@ -728,7 +728,7 @@ int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKey() TAG_LOGE(AAFwkTag::URIPERMMGR, "not support grant uri permission"); return ERR_CAPABILITY_NOT_SUPPORT; } - if (!UPMSUtils::IsSystemAppCall()) { + if (!FUDUtils::IsSystemAppCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "caller not system"); return ERR_NOT_SYSTEM_APP; } @@ -751,11 +751,11 @@ int32_t UriPermissionManagerStubImpl::CheckGrantUriPermissionByKeyParams(const s TAG_LOGE(AAFwkTag::URIPERMMGR, "caller equal to target"); return ERR_UPMS_INVALID_TARGET_TOKENID; } - if (!UPMSUtils::GenerateFUDAppInfo(callerAppInfo)) { + if (!FUDUtils::GenerateFUDAppInfo(callerAppInfo)) { TAG_LOGE(AAFwkTag::URIPERMMGR, "callerTokenId invalid"); return ERR_UPMS_INVALID_CALLER_TOKENID; } - if (!UPMSUtils::GenerateFUDAppInfo(targetAppInfo)) { + if (!FUDUtils::GenerateFUDAppInfo(targetAppInfo)) { TAG_LOGE(AAFwkTag::URIPERMMGR, "targetTokenId invalid"); return ERR_UPMS_INVALID_TARGET_TOKENID; } @@ -784,7 +784,7 @@ ErrCode UriPermissionManagerStubImpl::CheckUriAuthorization(const std::vector UriPermissionManagerStubImpl::CheckUriPermission(TokenIdPermis std::vector mediaUris; std::vector mediaUriIndexs; std::string callerAlterableBundleName; - UPMSUtils::GetAlterableBundleNameByTokenId(tokenId, callerAlterableBundleName); + FUDUtils::GetAlterableBundleNameByTokenId(tokenId, callerAlterableBundleName); for (size_t i = 0; i < uriVec.size(); i++) { auto uri = Uri(uriVec[i]); auto &&scheme = uri.GetScheme(); @@ -935,7 +935,7 @@ void UriPermissionManagerStubImpl::RevokeMapUriPermission(uint32_t tokenId) ErrCode UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId, int32_t& funcResult) { TAG_LOGI(AAFwkTag::URIPERMMGR, "RevokeAllUriPermissions, tokenId:%{public}u", tokenId); - if (!UPMSUtils::IsFoundationCall()) { + if (!FUDUtils::IsFoundationCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "No permission to revoke all uri permission"); funcResult = CHECK_PERMISSION_FAILED; return ERR_OK; @@ -949,7 +949,7 @@ ErrCode UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId, int32_t UriPermissionManagerStubImpl::RevokeAllMapUriPermissions(uint32_t tokenId) { std::string callerAuthority = ""; - UPMSUtils::GetAlterableBundleNameByTokenId(tokenId, callerAuthority); + FUDUtils::GetAlterableBundleNameByTokenId(tokenId, callerAuthority); std::map> uriLists; { std::lock_guard guard(mutex_); @@ -995,19 +995,19 @@ ErrCode UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri& uri HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::URIPERMMGR, "uri:%{private}s, bundleName:%{public}s, appIndex:%{public}d", uri.ToString().c_str(), bundleName.c_str(), appIndex); - if (!UPMSUtils::IsSAOrSystemAppCall()) { + if (!FUDUtils::IsSAOrSystemAppCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "not SA/SystemApp"); funcResult = CHECK_PERMISSION_FAILED; return ERR_OK; } auto uriInner = uri; - if (!UPMSUtils::CheckUriTypeIsValid(uriInner)) { + if (!FUDUtils::CheckUriTypeIsValid(uriInner)) { TAG_LOGE(AAFwkTag::URIPERMMGR, "CheckUriType failed, uri:%{private}s", uri.ToString().c_str()); funcResult = ERR_CODE_INVALID_URI_TYPE; return ERR_OK; } uint32_t targetTokenId = 0; - auto ret = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, targetTokenId); + auto ret = FUDUtils::GetTokenIdByBundleName(bundleName, appIndex, targetTokenId); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::URIPERMMGR, "get tokenId by bundleName fail"); funcResult = ret; @@ -1024,7 +1024,7 @@ int32_t UriPermissionManagerStubImpl::RevokeUriPermissionManuallyInner(Uri &uri, TAG_LOGI(AAFwkTag::URIPERMMGR, "callerTokenId: %{public}u, targetTokenId:%{public}u", callerTokenId, targetTokenId); - if (UPMSUtils::IsDocsCloudUri(uri)) { + if (FUDUtils::IsDocsCloudUri(uri)) { return RevokeMapUriPermissionManually(callerTokenId, targetTokenId, uri); } if (uri.GetAuthority() == FUDConstants::MEDIA_AUTHORITY) { @@ -1041,7 +1041,7 @@ int32_t UriPermissionManagerStubImpl::RevokeMapUriPermissionManually(uint32_t ca auto uriAuthority = uri.GetAuthority(); // uri belong to caller or caller is target. std::string callerAuthority = ""; - UPMSUtils::GetAlterableBundleNameByTokenId(callerTokenId, callerAuthority); + FUDUtils::GetAlterableBundleNameByTokenId(callerTokenId, callerAuthority); bool isRevokeSelfUri = (callerTokenId == targetTokenId || callerAuthority == uriAuthority); std::vector uriList; { @@ -1170,7 +1170,7 @@ ErrCode UriPermissionManagerStubImpl::ClearPermissionTokenByMap(uint32_t tokenId { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::URIPERMMGR, "call"); - if (!UPMSUtils::IsFoundationCall()) { + if (!FUDUtils::IsFoundationCall()) { TAG_LOGE(AAFwkTag::URIPERMMGR, "not foundation call"); return WrapErrorCode(ERR_PERMISSION_DENIED, funcResult); } diff --git a/test/unittest/file_permission_manager_test/file_permission_manager_test.cpp b/test/unittest/file_permission_manager_test/file_permission_manager_test.cpp index 4f320e47bd..844fbd6510 100644 --- a/test/unittest/file_permission_manager_test/file_permission_manager_test.cpp +++ b/test/unittest/file_permission_manager_test/file_permission_manager_test.cpp @@ -41,7 +41,7 @@ void FilePermissionManagerTest::TearDown() * Feature: CheckUriPersistentPermission * Function: CheckUriPersistentPermission * SubFunction: NA - * FunctionPoints: UPMSUtils CheckUriPersistentPermission + * FunctionPoints: CheckUriPersistentPermission */ HWTEST_F(FilePermissionManagerTest, CheckUriPersistentPermission_001, TestSize.Level1) { @@ -61,7 +61,7 @@ HWTEST_F(FilePermissionManagerTest, CheckUriPersistentPermission_001, TestSize.L * Feature: GetPathPolicyInfoFromUri * Function: GetPathPolicyInfoFromUri * SubFunction: NA - * FunctionPoints: UPMSUtils GetPathPolicyInfoFromUri + * FunctionPoints: GetPathPolicyInfoFromUri */ HWTEST_F(FilePermissionManagerTest, GetPathPolicyInfoFromUri_001, TestSize.Level1) { diff --git a/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_new_test.cpp b/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_new_test.cpp index a0526e9299..7c67be500d 100644 --- a/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_new_test.cpp +++ b/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_new_test.cpp @@ -17,11 +17,11 @@ #include "ability_manager_errors.h" #include "event_report.h" +#define private public +#include "file_uri_distribution_utils.h" +#undef private #include "system_ability_definition.h" #include "tokenid_kit.h" -#define private public -#include "uri_permission_utils.h" -#undef private #include "mock_my_flag.h" #include "accesstoken_kit.h" #include "uri.h" @@ -48,10 +48,10 @@ void FileUriDistributionUtilsNewTest::SetUp() {} void FileUriDistributionUtilsNewTest::TearDown() {} /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils SendShareUnPrivilegeUriEvent + * FunctionPoints: FUDUtils SendShareUnPrivilegeUriEvent */ HWTEST_F(FileUriDistributionUtilsNewTest, SendShareUnPrivilegeUriEvent_001, TestSize.Level1) { @@ -62,15 +62,15 @@ HWTEST_F(FileUriDistributionUtilsNewTest, SendShareUnPrivilegeUriEvent_001, Test "com.test.test", "com.test.test"); MyFlag::tokenInfos_[targetTokenId] = TokenInfo(targetTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, "com.test.test", "com.test.test"); - auto result = UPMSUtils::SendShareUnPrivilegeUriEvent(callerTokenId, targetTokenId); + auto result = FUDUtils::SendShareUnPrivilegeUriEvent(callerTokenId, targetTokenId); EXPECT_TRUE(result); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils CheckAndCreateEventInfo + * FunctionPoints: FUDUtils CheckAndCreateEventInfo */ HWTEST_F(FileUriDistributionUtilsNewTest, CheckAndCreateEventInfo_001, TestSize.Level1) { @@ -82,15 +82,15 @@ HWTEST_F(FileUriDistributionUtilsNewTest, CheckAndCreateEventInfo_001, TestSize. "com.test.ohos", "com.test.ohos"); MyFlag::tokenInfos_[targetTokenId] = TokenInfo(targetTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, "com.test.ohos", "com.test.ohos"); - auto result = UPMSUtils::CheckAndCreateEventInfo(callerTokenId, targetTokenId, eventInfo); + auto result = FUDUtils::CheckAndCreateEventInfo(callerTokenId, targetTokenId, eventInfo); EXPECT_FALSE(result); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GenerateFUDAppInfo * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo + * FunctionPoints: FUDUtils GenerateFUDAppInfo */ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_001, TestSize.Level1) { @@ -98,15 +98,15 @@ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_001, TestSize.Level FUDAppInfo info = { .tokenId = tokenId }; MyFlag::tokenInfos_.clear(); MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); - auto result = UPMSUtils::GenerateFUDAppInfo(info); + auto result = FUDUtils::GenerateFUDAppInfo(info); EXPECT_FALSE(result); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GenerateFUDAppInfo * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo + * FunctionPoints: FUDUtils GenerateFUDAppInfo */ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_002, TestSize.Level1) { @@ -115,15 +115,15 @@ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_002, TestSize.Level MyFlag::tokenInfos_.clear(); MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_FAILED; - auto result = UPMSUtils::GenerateFUDAppInfo(info); + auto result = FUDUtils::GenerateFUDAppInfo(info); EXPECT_FALSE(result); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GenerateFUDAppInfo * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo + * FunctionPoints: FUDUtils GenerateFUDAppInfo */ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_003, TestSize.Level1) { @@ -135,16 +135,16 @@ HWTEST_F(FileUriDistributionUtilsNewTest, GenerateFUDAppInfo_003, TestSize.Level MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, processName, bundleName); MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_SUCCESS; - auto result = UPMSUtils::GenerateFUDAppInfo(info); + auto result = FUDUtils::GenerateFUDAppInfo(info); EXPECT_TRUE(result); EXPECT_EQ(info.bundleName, bundleName); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils GetAlterableBundleNameByTokenId + * FunctionPoints: FUDUtils GetAlterableBundleNameByTokenId */ HWTEST_F(FileUriDistributionUtilsNewTest, GetAlterableBundleNameByTokenId_001, TestSize.Level1) { @@ -153,99 +153,99 @@ HWTEST_F(FileUriDistributionUtilsNewTest, GetAlterableBundleNameByTokenId_001, T MyFlag::tokenInfos_.clear(); MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_FAILED; - auto result = UPMSUtils::GetAlterableBundleNameByTokenId(tokenId, bundleName); + auto result = FUDUtils::GetAlterableBundleNameByTokenId(tokenId, bundleName); EXPECT_FALSE(result); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils GetAppIdByBundleName + * FunctionPoints: FUDUtils GetAppIdByBundleName */ HWTEST_F(FileUriDistributionUtilsNewTest, GetAppIdByBundleName_001, TestSize.Level1) { std::string bundleName = ""; std::string appId = ""; - auto result = UPMSUtils::GetAppIdByBundleName(bundleName, appId); + auto result = FUDUtils::GetAppIdByBundleName(bundleName, appId); EXPECT_EQ(result, INNER_ERR); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils GetTokenIdByBundleName + * FunctionPoints: FUDUtils GetTokenIdByBundleName */ HWTEST_F(FileUriDistributionUtilsNewTest, GetTokenIdByBundleName_001, TestSize.Level1) { std::string bundleName = ""; int32_t appIndex = 1001; uint32_t tokenId = 1; - auto result = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); + auto result = FUDUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); EXPECT_EQ(result, ERR_GET_TARGET_BUNDLE_INFO_FAILED); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: IsDocsCloudUri * SubFunction: NA - * FunctionPoints: UPMSUtils IsDocsCloudUri + * FunctionPoints: FUDUtils IsDocsCloudUri */ HWTEST_F(FileUriDistributionUtilsNewTest, IsDocsCloudUri_001, TestSize.Level1) { Uri uri("ccc"); - EXPECT_FALSE(UPMSUtils::IsDocsCloudUri(uri)); + EXPECT_FALSE(FUDUtils::IsDocsCloudUri(uri)); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: CheckUriTypeIsValid * SubFunction: NA - * FunctionPoints: UPMSUtils CheckUriTypeIsValid + * FunctionPoints: FUDUtils CheckUriTypeIsValid */ HWTEST_F(FileUriDistributionUtilsNewTest, CheckUriTypeIsValid_001, TestSize.Level1) { Uri uri("ccc"); - EXPECT_FALSE(UPMSUtils::CheckUriTypeIsValid(uri)); + EXPECT_FALSE(FUDUtils::CheckUriTypeIsValid(uri)); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: CheckUriTypeIsValid * SubFunction: NA - * FunctionPoints: UPMSUtils CheckUriTypeIsValid + * FunctionPoints: FUDUtils CheckUriTypeIsValid */ HWTEST_F(FileUriDistributionUtilsNewTest, CheckUriTypeIsValid_002, TestSize.Level1) { Uri uri("file:///path/to/file"); - EXPECT_TRUE(UPMSUtils::CheckUriTypeIsValid(uri)); + EXPECT_TRUE(FUDUtils::CheckUriTypeIsValid(uri)); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GetBundleApiTargetVersion * SubFunction: NA - * FunctionPoints: UPMSUtils GetBundleApiTargetVersion + * FunctionPoints: FUDUtils GetBundleApiTargetVersion */ HWTEST_F(FileUriDistributionUtilsNewTest, GetBundleApiTargetVersion_001, TestSize.Level1) { std::string bundleName = "ohos.bundle.test"; int32_t targetApiVersion = 0; - EXPECT_FALSE(UPMSUtils::GetBundleApiTargetVersion(bundleName, targetApiVersion)); + EXPECT_FALSE(FUDUtils::GetBundleApiTargetVersion(bundleName, targetApiVersion)); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GetDirByBundleNameAndAppIndex * SubFunction: NA - * FunctionPoints: UPMSUtils GetDirByBundleNameAndAppIndex + * FunctionPoints: FUDUtils GetDirByBundleNameAndAppIndex */ HWTEST_F(FileUriDistributionUtilsNewTest, GetDirByBundleNameAndAppIndex_001, TestSize.Level1) { std::string bundleName = "ohos.bundle.test"; std::string dirName = "/Data"; - EXPECT_TRUE(UPMSUtils::GetDirByBundleNameAndAppIndex(bundleName, 0, dirName)); + EXPECT_TRUE(FUDUtils::GetDirByBundleNameAndAppIndex(bundleName, 0, dirName)); } } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_test.cpp b/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_test.cpp index 688adf1413..44a14f8efd 100644 --- a/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_test.cpp +++ b/test/unittest/file_uri_distribution_utils_test/file_uri_distribution_utils_test.cpp @@ -17,11 +17,11 @@ #include "ability_manager_errors.h" #include "event_report.h" +#define private public +#include "file_uri_distribution_utils.h" +#undef private #include "system_ability_definition.h" #include "tokenid_kit.h" -#define private public -#include "uri_permission_utils.h" -#undef private using namespace testing; using namespace testing::ext; @@ -45,131 +45,131 @@ void FileUriDistributionUtilsTest::SetUp() {} void FileUriDistributionUtilsTest::TearDown() {} /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: ConnectManager * SubFunction: NA - * FunctionPoints: UPMSUtils SendSystemAppGrantUriPermissionEvent + * FunctionPoints: FUDUtils SendSystemAppGrantUriPermissionEvent */ HWTEST_F(FileUriDistributionUtilsTest, SendSystemAppGrantUriPermissionEvent_001, TestSize.Level1) { std::vector uriVec = { "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt" }; const std::vector resVec = { true }; - auto ret = UPMSUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec); + auto ret = FUDUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec); ASSERT_EQ(ret, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: SendShareUnPrivilegeUriEvent * SubFunction: NA * FunctionPoints: URIPermissionManagerService SendShareUnPrivilegeUriEvent */ HWTEST_F(FileUriDistributionUtilsTest, SendShareUnPrivilegeUriEvent_001, TestSize.Level1) { - auto ret = UPMSUtils::SendShareUnPrivilegeUriEvent(1001, 1002); + auto ret = FUDUtils::SendShareUnPrivilegeUriEvent(1001, 1002); EXPECT_EQ(ret, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GetCurrentAccountId * SubFunction: NA - * FunctionPoints: UPMSUtils GetCurrentAccountId + * FunctionPoints: FUDUtils GetCurrentAccountId */ HWTEST_F(FileUriDistributionUtilsTest, GetCurrentAccountId_001, TestSize.Level1) { - auto testCurrentAccountId = UPMSUtils::GetCurrentAccountId(); + auto testCurrentAccountId = FUDUtils::GetCurrentAccountId(); EXPECT_EQ(testCurrentAccountId, 100); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: IsFoundationCall * SubFunction: NA - * FunctionPoints: UPMSUtils IsFoundationCall + * FunctionPoints: FUDUtils IsFoundationCall */ HWTEST_F(FileUriDistributionUtilsTest, IsFoundationCall_001, TestSize.Level1) { - auto testIsFoundationCall = UPMSUtils::IsFoundationCall(); + auto testIsFoundationCall = FUDUtils::IsFoundationCall(); EXPECT_EQ(testIsFoundationCall, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: IsSAOrSystemAppCall * SubFunction: NA - * FunctionPoints: UPMSUtils IsSAOrSystemAppCall + * FunctionPoints: FUDUtils IsSAOrSystemAppCall */ HWTEST_F(FileUriDistributionUtilsTest, IsSAOrSystemAppCall_001, TestSize.Level1) { - auto testIsSAOrSystemAppCall = UPMSUtils::IsSAOrSystemAppCall(); + auto testIsSAOrSystemAppCall = FUDUtils::IsSAOrSystemAppCall(); EXPECT_EQ(testIsSAOrSystemAppCall, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: IsSystemAppCall * SubFunction: NA - * FunctionPoints: UPMSUtils IsSystemAppCall + * FunctionPoints: FUDUtils IsSystemAppCall */ HWTEST_F(FileUriDistributionUtilsTest, IsSystemAppCall_001, TestSize.Level1) { - auto testIsSystemAppCall = UPMSUtils::IsSystemAppCall(); + auto testIsSystemAppCall = FUDUtils::IsSystemAppCall(); EXPECT_EQ(testIsSystemAppCall, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: CheckIsSystemAppByBundleName * SubFunction: NA - * FunctionPoints: UPMSUtils CheckIsSystemAppByBundleName + * FunctionPoints: FUDUtils CheckIsSystemAppByBundleName */ HWTEST_F(FileUriDistributionUtilsTest, CheckIsSystemAppByBundleName_001, TestSize.Level1) { std::string bundleName = ""; - auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByBundleName(bundleName); + auto testIsSystemApp = FUDUtils::CheckIsSystemAppByBundleName(bundleName); EXPECT_EQ(testIsSystemApp, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: CheckIsSystemAppByTokenId * SubFunction: NA - * FunctionPoints: UPMSUtils CheckIsSystemAppByTokenId + * FunctionPoints: FUDUtils CheckIsSystemAppByTokenId */ HWTEST_F(FileUriDistributionUtilsTest, CheckIsSystemAppByTokenId_001, TestSize.Level1) { uint32_t tokenId = 1001; - auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByTokenId(tokenId); + auto testIsSystemApp = FUDUtils::CheckIsSystemAppByTokenId(tokenId); EXPECT_EQ(testIsSystemApp, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GetBundleNameByTokenId * SubFunction: NA - * FunctionPoints: UPMSUtils GetBundleNameByTokenId + * FunctionPoints: FUDUtils GetBundleNameByTokenId */ HWTEST_F(FileUriDistributionUtilsTest, GetBundleNameByTokenId_001, TestSize.Level1) { uint32_t tokenId = 1001; std::string bundleName = ""; - auto testGetBundleNameByTokenIdFlag = UPMSUtils::GetBundleNameByTokenId(tokenId, bundleName); + auto testGetBundleNameByTokenIdFlag = FUDUtils::GetBundleNameByTokenId(tokenId, bundleName); EXPECT_EQ (testGetBundleNameByTokenIdFlag, false); } /* - * Feature: UPMSUtils + * Feature: FUDUtils * Function: GetTokenIdByBundleName * SubFunction: NA - * FunctionPoints: UPMSUtils GetTokenIdByBundleName + * FunctionPoints: FUDUtils GetTokenIdByBundleName */ HWTEST_F(FileUriDistributionUtilsTest, GetTokenIdByBundleName_001, TestSize.Level1) { std::string bundleName = "com.example.test"; int32_t appIndex = 10; uint32_t tokenId; - auto testTokenId = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); + auto testTokenId = FUDUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); EXPECT_EQ(testTokenId, ERR_GET_TARGET_BUNDLE_INFO_FAILED); } } // namespace AAFwk diff --git a/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_new_test.cpp b/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_new_test.cpp deleted file mode 100644 index a186b928c7..0000000000 --- a/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_new_test.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ability_manager_errors.h" -#include "event_report.h" -#include "system_ability_definition.h" -#include "tokenid_kit.h" -#define private public -#include "uri_permission_utils.h" -#undef private -#include "mock_my_flag.h" -#include "accesstoken_kit.h" -#include "uri.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UriPermissionUtilsNewTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void UriPermissionUtilsNewTest::SetUpTestCase() {} - -void UriPermissionUtilsNewTest::TearDownTestCase() {} - -void UriPermissionUtilsNewTest::SetUp() {} - -void UriPermissionUtilsNewTest::TearDown() {} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils SendShareUnPrivilegeUriEvent - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_SendShareUnPrivilegeUriEvent_001, TestSize.Level1) -{ - uint32_t callerTokenId = 1; - uint32_t targetTokenId = 2; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[callerTokenId] = TokenInfo(callerTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, - "com.test.test", "com.test.test"); - MyFlag::tokenInfos_[targetTokenId] = TokenInfo(targetTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, - "com.test.test", "com.test.test"); - auto result = UPMSUtils::SendShareUnPrivilegeUriEvent(callerTokenId, targetTokenId); - EXPECT_TRUE(result); -} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils CheckAndCreateEventInfo - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_CheckAndCreateEventInfo_001, TestSize.Level1) -{ - uint32_t callerTokenId = 1; - uint32_t targetTokenId = 2; - EventInfo eventInfo; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[callerTokenId] = TokenInfo(callerTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, - "com.test.ohos", "com.test.ohos"); - MyFlag::tokenInfos_[targetTokenId] = TokenInfo(targetTokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, - "com.test.ohos", "com.test.ohos"); - auto result = UPMSUtils::CheckAndCreateEventInfo(callerTokenId, targetTokenId, eventInfo); - EXPECT_FALSE(result); -} - -/* - * Feature: UPMSUtils - * Function: GenerateFUDAppInfo - * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GenerateFUDAppInfo_001, TestSize.Level1) -{ - uint32_t tokenId = 1001; - FUDAppInfo info = { .tokenId = tokenId }; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); - auto result = UPMSUtils::GenerateFUDAppInfo(info); - EXPECT_FALSE(result); -} - -/* - * Feature: UPMSUtils - * Function: GenerateFUDAppInfo - * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GenerateFUDAppInfo_002, TestSize.Level1) -{ - uint32_t tokenId = 1001; - FUDAppInfo info = { .tokenId = tokenId }; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); - MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_FAILED; - auto result = UPMSUtils::GenerateFUDAppInfo(info); - EXPECT_FALSE(result); -} - -/* - * Feature: UPMSUtils - * Function: GenerateFUDAppInfo - * SubFunction: NA - * FunctionPoints: UPMSUtils GenerateFUDAppInfo - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GenerateFUDAppInfo_003, TestSize.Level1) -{ - uint32_t tokenId = 1001; - FUDAppInfo info = { .tokenId = tokenId }; - std::string bundleName = "testApp"; - std::string processName = "testApp"; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP, - processName, bundleName); - MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_SUCCESS; - auto result = UPMSUtils::GenerateFUDAppInfo(info); - EXPECT_TRUE(result); - EXPECT_EQ(info.bundleName, bundleName); -} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils GetAlterableBundleNameByTokenId - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GetAlterableBundleNameByTokenId_001, TestSize.Level1) -{ - uint32_t tokenId = 1; - std::string bundleName = ""; - MyFlag::tokenInfos_.clear(); - MyFlag::tokenInfos_[tokenId] = TokenInfo(tokenId, Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); - MyFlag::retHapSuccValue_ = Security::AccessToken::AccessTokenKitRet::RET_FAILED; - auto result = UPMSUtils::GetAlterableBundleNameByTokenId(tokenId, bundleName); - EXPECT_FALSE(result); -} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils GetAppIdByBundleName - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GetAppIdByBundleName_001, TestSize.Level1) -{ - std::string bundleName = ""; - std::string appId = ""; - auto result = UPMSUtils::GetAppIdByBundleName(bundleName, appId); - EXPECT_EQ(result, INNER_ERR); -} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils GetTokenIdByBundleName - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GetTokenIdByBundleName_001, TestSize.Level1) -{ - std::string bundleName = ""; - int32_t appIndex = 1001; - uint32_t tokenId = 1; - auto result = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); - EXPECT_EQ(result, ERR_GET_TARGET_BUNDLE_INFO_FAILED); -} - -/* - * Feature: UPMSUtils - * Function: IsDocsCloudUri - * SubFunction: NA - * FunctionPoints: UPMSUtils IsDocsCloudUri - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_IsDocsCloudUri_001, TestSize.Level1) -{ - Uri uri("ccc"); - EXPECT_FALSE(UPMSUtils::IsDocsCloudUri(uri)); -} - -/* - * Feature: UPMSUtils - * Function: CheckUriTypeIsValid - * SubFunction: NA - * FunctionPoints: UPMSUtils CheckUriTypeIsValid - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_CheckUriTypeIsValid_001, TestSize.Level1) -{ - Uri uri("ccc"); - EXPECT_FALSE(UPMSUtils::CheckUriTypeIsValid(uri)); -} - -/* - * Feature: UPMSUtils - * Function: CheckUriTypeIsValid - * SubFunction: NA - * FunctionPoints: UPMSUtils CheckUriTypeIsValid - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_CheckUriTypeIsValid_002, TestSize.Level1) -{ - Uri uri("file:///path/to/file"); - EXPECT_TRUE(UPMSUtils::CheckUriTypeIsValid(uri)); -} - -/* - * Feature: UPMSUtils - * Function: GetBundleApiTargetVersion - * SubFunction: NA - * FunctionPoints: UPMSUtils GetBundleApiTargetVersion - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GetBundleApiTargetVersion_001, TestSize.Level1) -{ - std::string bundleName = "ohos.bundle.test"; - int32_t targetApiVersion = 0; - EXPECT_FALSE(UPMSUtils::GetBundleApiTargetVersion(bundleName, targetApiVersion)); -} - -/* - * Feature: UPMSUtils - * Function: GetDirByBundleNameAndAppIndex - * SubFunction: NA - * FunctionPoints: UPMSUtils GetDirByBundleNameAndAppIndex - */ -HWTEST_F(UriPermissionUtilsNewTest, Upms_GetDirByBundleNameAndAppIndex_001, TestSize.Level1) -{ - std::string bundleName = "ohos.bundle.test"; - std::string dirName = "/Data"; - EXPECT_TRUE(UPMSUtils::GetDirByBundleNameAndAppIndex(bundleName, 0, dirName)); -} -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_test.cpp b/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_test.cpp deleted file mode 100644 index 49de2d8988..0000000000 --- a/test/unittest/file_uri_distribution_utils_test/uri_permission_utils_test.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ability_manager_errors.h" -#include "event_report.h" -#include "system_ability_definition.h" -#include "tokenid_kit.h" -#define private public -#include "uri_permission_utils.h" -#undef private - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace AAFwk { -class UriPermissionUtilsTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -}; - -void UriPermissionUtilsTest::SetUpTestCase() {} - -void UriPermissionUtilsTest::TearDownTestCase() {} - -void UriPermissionUtilsTest::SetUp() {} - -void UriPermissionUtilsTest::TearDown() {} - -/* - * Feature: UPMSUtils - * Function: ConnectManager - * SubFunction: NA - * FunctionPoints: UPMSUtils SendSystemAppGrantUriPermissionEvent - */ -HWTEST_F(UriPermissionUtilsTest, Upms_SendSystemAppGrantUriPermissionEvent_001, TestSize.Level1) -{ - std::vector uriVec = { "file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt" }; - const std::vector resVec = { true }; - auto ret = UPMSUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec); - ASSERT_EQ(ret, false); -} - -/* - * Feature: UPMSUtils - * Function: SendShareUnPrivilegeUriEvent - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService SendShareUnPrivilegeUriEvent - */ -HWTEST_F(UriPermissionUtilsTest, Upms_SendShareUnPrivilegeUriEvent_001, TestSize.Level1) -{ - auto ret = UPMSUtils::SendShareUnPrivilegeUriEvent(1001, 1002); - EXPECT_EQ(ret, false); -} - -/* - * Feature: UPMSUtils - * Function: GetCurrentAccountId - * SubFunction: NA - * FunctionPoints: UPMSUtils GetCurrentAccountId - */ -HWTEST_F(UriPermissionUtilsTest, Upms_GetCurrentAccountId_001, TestSize.Level1) -{ - auto testCurrentAccountId = UPMSUtils::GetCurrentAccountId(); - EXPECT_EQ(testCurrentAccountId, 100); -} - -/* - * Feature: UPMSUtils - * Function: IsFoundationCall - * SubFunction: NA - * FunctionPoints: UPMSUtils IsFoundationCall - */ -HWTEST_F(UriPermissionUtilsTest, Upms_IsFoundationCall_001, TestSize.Level1) -{ - auto testIsFoundationCall = UPMSUtils::IsFoundationCall(); - EXPECT_EQ(testIsFoundationCall, false); -} - -/* - * Feature: UPMSUtils - * Function: IsSAOrSystemAppCall - * SubFunction: NA - * FunctionPoints: UPMSUtils IsSAOrSystemAppCall - */ -HWTEST_F(UriPermissionUtilsTest, Upms_IsSAOrSystemAppCall_001, TestSize.Level1) -{ - auto testIsSAOrSystemAppCall = UPMSUtils::IsSAOrSystemAppCall(); - EXPECT_EQ(testIsSAOrSystemAppCall, false); -} - -/* - * Feature: UPMSUtils - * Function: IsSystemAppCall - * SubFunction: NA - * FunctionPoints: UPMSUtils IsSystemAppCall - */ -HWTEST_F(UriPermissionUtilsTest, Upms_IsSystemAppCall_001, TestSize.Level1) -{ - auto testIsSystemAppCall = UPMSUtils::IsSystemAppCall(); - EXPECT_EQ(testIsSystemAppCall, false); -} - -/* - * Feature: UPMSUtils - * Function: CheckIsSystemAppByBundleName - * SubFunction: NA - * FunctionPoints: UPMSUtils CheckIsSystemAppByBundleName - */ -HWTEST_F(UriPermissionUtilsTest, Upms_CheckIsSystemAppByBundleName_001, TestSize.Level1) -{ - std::string bundleName = ""; - auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByBundleName(bundleName); - EXPECT_EQ(testIsSystemApp, false); -} - -/* - * Feature: UPMSUtils - * Function: CheckIsSystemAppByTokenId - * SubFunction: NA - * FunctionPoints: UPMSUtils CheckIsSystemAppByTokenId - */ -HWTEST_F(UriPermissionUtilsTest, Upms_CheckIsSystemAppByTokenId_001, TestSize.Level1) -{ - uint32_t tokenId = 1001; - auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByTokenId(tokenId); - EXPECT_EQ(testIsSystemApp, false); -} - -/* - * Feature: UPMSUtils - * Function: GetBundleNameByTokenId - * SubFunction: NA - * FunctionPoints: UPMSUtils GetBundleNameByTokenId - */ -HWTEST_F(UriPermissionUtilsTest, Upms_GetBundleNameByTokenId_001, TestSize.Level1) -{ - uint32_t tokenId = 1001; - std::string bundleName = ""; - auto testGetBundleNameByTokenIdFlag = UPMSUtils::GetBundleNameByTokenId(tokenId, bundleName); - EXPECT_EQ (testGetBundleNameByTokenIdFlag, false); -} - -/* - * Feature: UPMSUtils - * Function: GetTokenIdByBundleName - * SubFunction: NA - * FunctionPoints: UPMSUtils GetTokenIdByBundleName - */ -HWTEST_F(UriPermissionUtilsTest, Upms_GetTokenIdByBundleName_001, TestSize.Level1) -{ - std::string bundleName = "com.example.test"; - int32_t appIndex = 10; - uint32_t tokenId; - auto testTokenId = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId); - EXPECT_EQ(testTokenId, ERR_GET_TARGET_BUNDLE_INFO_FAILED); -} - -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/BUILD.gn b/test/unittest/uri_permission_impl_test/BUILD.gn index 645649529e..5f23260f4a 100755 --- a/test/unittest/uri_permission_impl_test/BUILD.gn +++ b/test/unittest/uri_permission_impl_test/BUILD.gn @@ -43,13 +43,13 @@ ohos_unittest("uri_permission_impl_test") { "mock/src/mock_accesstoken_kit.cpp", "mock/src/mock_app_utils.cpp", "mock/src/mock_bundle_mgr_helper.cpp", + "mock/src/mock_file_uri_distribution_utils.cpp", "mock/src/mock_iability_manager_collaborator.cpp", "mock/src/mock_ipc_skeleton.cpp", "mock/src/mock_my_flag.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_sandbox_manager.cpp", "mock/src/mock_udmf_utils.cpp", - "mock/src/mock_uri_permission_utils.cpp", "batch_uri_test.cpp", "uri_permission_impl_test.cpp", ] @@ -121,8 +121,8 @@ ohos_unittest("uri_permission_manager_stub_impl_test") { sources = [ "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", "mock/src/mock_ability_manager_client.cpp", + "mock/src/mock_file_uri_distribution_utils.cpp", "mock/src/mock_my_flag.cpp", - "mock/src/mock_uri_permission_utils.cpp", "mock/src/mock_iability_manager_collaborator.cpp", "uri_permission_manager_stub_impl_test.cpp", ] @@ -205,8 +205,8 @@ ohos_unittest("upms_udmf_utils_test") { sources = [ "${ability_runtime_services_path}/uripermmgr/src/upms_udmf_utils.cpp", + "mock/src/mock_file_uri_distribution_utils.cpp", "mock/src/mock_my_flag.cpp", - "mock/src/mock_uri_permission_utils.cpp", "mock/src/udmf_client.cpp", "udmf_utils_test.cpp", ] diff --git a/test/unittest/uri_permission_impl_test/mock/include/uri_permission_utils.h b/test/unittest/uri_permission_impl_test/mock/include/file_uri_distribution_utils.h similarity index 91% rename from test/unittest/uri_permission_impl_test/mock/include/uri_permission_utils.h rename to test/unittest/uri_permission_impl_test/mock/include/file_uri_distribution_utils.h index a54a1fe1f9..aa442d34d3 100644 --- a/test/unittest/uri_permission_impl_test/mock/include/uri_permission_utils.h +++ b/test/unittest/uri_permission_impl_test/mock/include/file_uri_distribution_utils.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H -#define OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H +#ifndef OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H +#define OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H #include "uri.h" @@ -26,7 +26,7 @@ struct FUDAppInfo { std::string alterBundleName; int32_t userId = 0; }; -class UPMSUtils { +class FUDUtils { public: static bool SendShareUnPrivilegeUriEvent(uint32_t callTokenId, uint32_t targetTokenId); static bool SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, @@ -48,4 +48,4 @@ public: }; } // OHOS } // AAFwk -#endif // OHOS_ABILITY_RUNTIME_URI_PERMISSION_UTILS_H \ No newline at end of file +#endif // OHOS_ABILITY_RUNTIME_FILE_URI_DISTRIBUTION_UTILS_H \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/mock_uri_permission_utils.cpp b/test/unittest/uri_permission_impl_test/mock/src/mock_file_uri_distribution_utils.cpp similarity index 63% rename from test/unittest/uri_permission_impl_test/mock/src/mock_uri_permission_utils.cpp rename to test/unittest/uri_permission_impl_test/mock/src/mock_file_uri_distribution_utils.cpp index 7923b68b5f..a8fbc6dfb0 100644 --- a/test/unittest/uri_permission_impl_test/mock/src/mock_uri_permission_utils.cpp +++ b/test/unittest/uri_permission_impl_test/mock/src/mock_file_uri_distribution_utils.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "uri_permission_utils.h" +#include "file_uri_distribution_utils.h" #include "ability_manager_errors.h" #include "mock_my_flag.h" @@ -22,88 +22,88 @@ namespace OHOS { namespace AAFwk { using MyFlag = OHOS::AAFwk::MyFlag; -bool UPMSUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t targetTokenId) +bool FUDUtils::SendShareUnPrivilegeUriEvent(uint32_t callerTokenId, uint32_t targetTokenId) { return true; } -bool UPMSUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, +bool FUDUtils::SendSystemAppGrantUriPermissionEvent(uint32_t callerTokenId, uint32_t targetTokenId, const std::vector &uriVec, const std::vector &resVec) { return true; } -int32_t UPMSUtils::GetCurrentAccountId() +int32_t FUDUtils::GetCurrentAccountId() { return 1; } -bool UPMSUtils::IsFoundationCall() +bool FUDUtils::IsFoundationCall() { return MyFlag::upmsUtilsIsFoundationCallRet_; } -bool UPMSUtils::IsSAOrSystemAppCall() +bool FUDUtils::IsSAOrSystemAppCall() { return MyFlag::isSAOrSystemAppCall_ || (MyFlag::IS_SA_CALL & MyFlag::flag_) != 0; } -bool UPMSUtils::IsSystemAppCall() +bool FUDUtils::IsSystemAppCall() { return MyFlag::isSystemAppCall_; } -bool UPMSUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t &targetApiVersion) +bool FUDUtils::GetBundleApiTargetVersion(const std::string &bundleName, int32_t &targetApiVersion) { return true; } -bool UPMSUtils::CheckIsSystemAppByTokenId(uint32_t tokenId) +bool FUDUtils::CheckIsSystemAppByTokenId(uint32_t tokenId) { return MyFlag::upmsUtilsCheckIsSystemAppByTokenIdRet_; } -bool UPMSUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) +bool FUDUtils::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) { dirName = MyFlag::upmsUtilsAlterBundleName_; return MyFlag::upmsUtilsGetDirByBundleNameAndAppIndexRet_; } -bool UPMSUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) +bool FUDUtils::GetAlterableBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) { bundleName = MyFlag::upmsUtilsAlterBundleName_; return MyFlag::upmsUtilsGetAlterBundleNameByTokenIdRet_; } -bool UPMSUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) +bool FUDUtils::GetBundleNameByTokenId(uint32_t tokenId, std::string &bundleName) { bundleName = MyFlag::upmsUtilsBundleName_; return MyFlag::upmsUtilsGetBundleNameByTokenIdRet_; } -int32_t UPMSUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId) +int32_t FUDUtils::GetAppIdByBundleName(const std::string &bundleName, std::string &appId) { appId = MyFlag::upmsUtilsAppId_; return MyFlag::upmsUtilsGetAppIdByBundleNameRet_; } -int32_t UPMSUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId) +int32_t FUDUtils::GetTokenIdByBundleName(const std::string &bundleName, int32_t appIndex, uint32_t &tokenId) { tokenId = MyFlag::upmsUtilsTokenId_; return MyFlag::getTokenIdByBundleNameStatus_; } -bool UPMSUtils::CheckUriTypeIsValid(Uri &uri) +bool FUDUtils::CheckUriTypeIsValid(Uri &uri) { return MyFlag::isUriTypeValid_; } -bool UPMSUtils::IsDocsCloudUri(Uri &uri) +bool FUDUtils::IsDocsCloudUri(Uri &uri) { return MyFlag::isDocsCloudUri_; } -bool UPMSUtils::GenerateFUDAppInfo(FUDAppInfo &info) +bool FUDUtils::GenerateFUDAppInfo(FUDAppInfo &info) { info.alterBundleName = MyFlag::upmsUtilsAlterBundleName_; info.bundleName = MyFlag::upmsUtilsBundleName_; diff --git a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp index 2fcaef5cba..8e4977f34f 100755 --- a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp +++ b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp @@ -32,9 +32,9 @@ #include "system_ability_definition.h" #include "tokenid_kit.h" #define private public +#include "file_uri_distribution_utils.h" #include "uri_permission_manager_client.h" #include "uri_permission_manager_stub_impl.h" -#include "uri_permission_utils.h" #undef private using namespace testing;