From 2a0d5fb490e1f9453f4cf4b3d638cc8a9849f326 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Mon, 25 Dec 2023 16:44:00 +0800 Subject: [PATCH] fah Signed-off-by: Anonymous --- .../file_access/src/file_access_helper.cpp | 90 +++++-------------- 1 file changed, 20 insertions(+), 70 deletions(-) diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index cfd22d1d..50678c72 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -187,6 +187,7 @@ std::pair, int> FileAccessHelper::Creator( HILOG_ERROR("FileAccessHelper::Creator check IsSystemAppByFullTokenID failed"); return {nullptr, E_PERMISSION_SYS}; } + sptr bm = FileAccessHelper::GetBundleMgrProxy(); FileAccessHelper::wants_.clear(); std::unordered_map> cMap; @@ -197,6 +198,7 @@ std::pair, int> FileAccessHelper::Creator( HILOG_ERROR("FileAccessHelper::Creator QueryExtensionAbilityInfos failed"); return {nullptr, E_GETINFO}; } + for (size_t i = 0; i < extensionInfos.size(); i++) { AAFwk::Want wantTem; wantTem.SetElementName(extensionInfos[i].bundleName, extensionInfos[i].name); @@ -219,16 +221,8 @@ std::pair, int> FileAccessHelper::Creator( return {nullptr, E_GETRESULT}; } FileAccessHelper::wants_.push_back(wantTem); - connectInfo->want = wantTem; - connectInfo->fileAccessExtConnection = fileAccessExtConnection; - cMap.emplace(extensionInfos[i].bundleName, connectInfo); - } - FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(context, cMap); - if (ptrFileAccessHelper == nullptr) { - HILOG_ERROR("FileAccessHelper::Creator failed, create FileAccessHelper failed"); - return {nullptr, E_GETRESULT}; } - return {std::shared_ptr(ptrFileAccessHelper), ERR_OK}; + return FileAccessHelper::Creator(context, wants_); } std::pair, int> FileAccessHelper::Creator( @@ -250,52 +244,25 @@ std::pair, int> FileAccessHelper::Creator( HILOG_ERROR("FileAccessHelper::Creator check IsSystemAppByFullTokenID failed"); return {nullptr, E_PERMISSION_SYS}; } + + return FileAccessHelper::Creator(context -> GetToken(), wants); +} - if (GetRegisteredFileAccessExtAbilityInfo(FileAccessHelper::wants_) != ERR_OK) { - HILOG_ERROR("GetRegisteredFileAccessExtAbilityInfo failed"); - return {nullptr, E_GETINFO}; +int CheckCreatorConditionsForToken(const sptr& token, const std::vector& wants) +{ + if (token == nullptr) { + HILOG_ERROR("FileAccessHelper::Creator failed, token is nullptr"); + return EINVAL; } - - std::unordered_map> cMap; - for (size_t i = 0; i < wants.size(); i++) { - sptr fileAccessExtConnection(new(std::nothrow) FileAccessExtConnection()); - if (fileAccessExtConnection == nullptr) { - HILOG_ERROR("new fileAccessExtConnection fail"); - return {nullptr, E_GETRESULT}; - } - - if (!fileAccessExtConnection->IsExtAbilityConnected()) { - fileAccessExtConnection->ConnectFileExtAbility(wants[i], context->GetToken()); - } - - sptr fileExtProxy = fileAccessExtConnection->GetFileExtProxy(); - if (fileExtProxy == nullptr) { - HILOG_ERROR("Creator get invalid fileExtProxy"); - return {nullptr, E_CONNECT}; - } - - std::shared_ptr connectInfo = std::make_shared(); - if (connectInfo == nullptr) { - HILOG_ERROR("Creator, connectInfo == nullptr"); - return {nullptr, E_GETRESULT}; - } - - connectInfo->want = wants[i]; - connectInfo->fileAccessExtConnection = fileAccessExtConnection; - string bundleName = FileAccessHelper::GetKeyOfWants(wants[i]); - if (bundleName.length() == 0) { - HILOG_ERROR("Creator GetKeyOfWants bundleName not found"); - return {nullptr, E_GETRESULT}; - } - cMap.insert(std::pair>(bundleName, connectInfo)); + if (wants.empty()) { + HILOG_ERROR("FileAccessHelper::Creator failed, wants is empty"); + return EINVAL; } - FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(context, cMap); - if (ptrFileAccessHelper == nullptr) { - HILOG_ERROR("Creator failed, create FileAccessHelper failed"); - return {nullptr, E_GETRESULT}; + if (!IsSystemApp()) { + HILOG_ERROR("FileAccessHelper::Creator check IsSystemAppByFullTokenID failed"); + return E_PERMISSION_SYS; } - - return {std::shared_ptr(ptrFileAccessHelper), ERR_OK}; + return ERR_OK; } std::shared_ptr FileAccessHelper::Creator(const sptr &token, @@ -303,26 +270,14 @@ std::shared_ptr FileAccessHelper::Creator(const sptr> cMap; for (size_t i = 0; i < wants.size(); i++) { sptr fileAccessExtConnection(new(std::nothrow) FileAccessExtConnection()); @@ -330,23 +285,19 @@ std::shared_ptr FileAccessHelper::Creator(const sptrIsExtAbilityConnected()) { fileAccessExtConnection->ConnectFileExtAbility(wants[i], token); } - sptr fileExtProxy = fileAccessExtConnection->GetFileExtProxy(); if (fileExtProxy == nullptr) { HILOG_ERROR("Creator get invalid fileExtProxy"); return nullptr; } - std::shared_ptr connectInfo = std::make_shared(); if (!connectInfo) { HILOG_ERROR("Creator, connectInfo == nullptr"); return nullptr; } - connectInfo->want = wants[i]; connectInfo->fileAccessExtConnection = fileAccessExtConnection; string bundleName = FileAccessHelper::GetKeyOfWants(wants[i]); @@ -361,7 +312,6 @@ std::shared_ptr FileAccessHelper::Creator(const sptr(ptrFileAccessHelper); } -- Gitee