From 035d9366bb8a21b3d080810900ebc1f5830789df Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Thu, 18 Aug 2022 17:09:22 +0800 Subject: [PATCH 1/8] Modify id to get Signed-off-by: wangjianqiang --- .../file_access/src/file_access_helper.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index a85b68bc..89861462 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace FileAccessFwk { -const int32_t DEFAULT_USERID = 100; std::unordered_map FileAccessHelper::wantsMap_; sptr FileAccessHelper::GetBundleMgrProxy() @@ -164,8 +163,17 @@ std::shared_ptr FileAccessHelper::Creator( FileAccessHelper::wantsMap_.clear(); std::unordered_map> cMap; std::vector extensionInfos; + + std::vector activeIds; + int ret1 = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); + if (ret1 != 0) { + HILOG_INFO("Failed to get ID"); + return nullptr; + } + int userId = activeIds[0]; + bool ret = bm->QueryExtensionAbilityInfos( - AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, DEFAULT_USERID, extensionInfos); + AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, userId, extensionInfos); if (!ret) { HILOG_ERROR("FileAccessHelper::Creator QueryExtensionAbilityInfos failed"); return nullptr; @@ -514,8 +522,16 @@ std::vector FileAccessHelper::GetRegisterFileAccessExtAbilityInfo() std::vector wants; std::vector extensionInfos; sptr bm = FileAccessHelper::GetBundleMgrProxy(); + + std::vector activeIds; + int ret1 = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); + if (ret1 != 0) { + HILOG_INFO("Failed to get ID"); + } + int userId = activeIds[0]; + bool ret = bm->QueryExtensionAbilityInfos( - AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, DEFAULT_USERID, extensionInfos); + AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, userId, extensionInfos); if (!ret) { HILOG_ERROR("FileAccessHelper::GetRegisterFileAccessExtAbilityInfo QueryExtensionAbilityInfos error"); return wants; -- Gitee From f2559b48085a53e34527cd96cfc7ff6aa97e6f64 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Thu, 18 Aug 2022 17:16:45 +0800 Subject: [PATCH 2/8] add BUILD Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 78e238b3..3ab8889d 100644 --- a/frameworks/innerkits/file_access/BUILD.gn +++ b/frameworks/innerkits/file_access/BUILD.gn @@ -93,6 +93,7 @@ ohos_shared_library("file_access_extension_ability_kit") { "ipc:ipc_core", "ipc_js:rpc", "samgr:samgr_proxy", + "os_account:os_account_innerkits", ] public_deps = [ -- Gitee From 14a5d0bbdddc4755b7fb2175897515a394b8c9fa Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Thu, 18 Aug 2022 17:47:27 +0800 Subject: [PATCH 3/8] add head Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/src/file_access_helper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 89861462..1ef8adda 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -23,6 +23,7 @@ #include "ifile_access_ext_base.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "os_account_manager.h" namespace OHOS { namespace FileAccessFwk { -- Gitee From 8154ad89bf78582050f5cf0be6d2c6bd48313cca Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Fri, 19 Aug 2022 09:56:33 +0800 Subject: [PATCH 4/8] clean codecheck Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/BUILD.gn | 2 +- .../file_access/include/file_access_helper.h | 1 + .../file_access/src/file_access_helper.cpp | 28 +++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/frameworks/innerkits/file_access/BUILD.gn b/frameworks/innerkits/file_access/BUILD.gn index 3ab8889d..838f2cf7 100644 --- a/frameworks/innerkits/file_access/BUILD.gn +++ b/frameworks/innerkits/file_access/BUILD.gn @@ -92,8 +92,8 @@ ohos_shared_library("file_access_extension_ability_kit") { "hitrace_native:hitrace_meter", "ipc:ipc_core", "ipc_js:rpc", - "samgr:samgr_proxy", "os_account:os_account_innerkits", + "samgr:samgr_proxy", ] public_deps = [ diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index f872fbb8..39a51bba 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -94,6 +94,7 @@ private: static std::unordered_map wantsMap_; static std::string GetKeyOfWantsMap(const AAFwk::Want &want); + static int getUserId(); sptr callerDeathRecipient_ = nullptr; sptr notifyAgent_ = nullptr; diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 1ef8adda..7f163cb6 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -22,8 +22,8 @@ #include "if_system_ability_manager.h" #include "ifile_access_ext_base.h" #include "iservice_registry.h" -#include "system_ability_definition.h" #include "os_account_manager.h" +#include "system_ability_definition.h" namespace OHOS { namespace FileAccessFwk { @@ -130,6 +130,17 @@ std::string FileAccessHelper::GetKeyOfWantsMap(const AAFwk::Want &want) return nullptr; } +int FileAccessHelper::getUserId() +{ + std::vector activeIds; + int ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); + if (ret != ERR_OK) { + HILOG_ERROR("Failed to get ID"); + return ERR_INVALID_PARAM; + } + return activeIds[0]; +} + void FileAccessHelper::InsertConnectInfo(const std::string &key, const AAFwk::Want &want, const sptr &fileAccessExtProxy, @@ -165,13 +176,10 @@ std::shared_ptr FileAccessHelper::Creator( std::unordered_map> cMap; std::vector extensionInfos; - std::vector activeIds; - int ret1 = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); - if (ret1 != 0) { - HILOG_INFO("Failed to get ID"); + int userId = FileAccessHelper::getUserId(); + if (userId < ERR_OK) { return nullptr; } - int userId = activeIds[0]; bool ret = bm->QueryExtensionAbilityInfos( AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, userId, extensionInfos); @@ -524,12 +532,10 @@ std::vector FileAccessHelper::GetRegisterFileAccessExtAbilityInfo() std::vector extensionInfos; sptr bm = FileAccessHelper::GetBundleMgrProxy(); - std::vector activeIds; - int ret1 = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); - if (ret1 != 0) { - HILOG_INFO("Failed to get ID"); + int userId = FileAccessHelper::getUserId(); + if (userId < ERR_OK) { + return wants; } - int userId = activeIds[0]; bool ret = bm->QueryExtensionAbilityInfos( AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, userId, extensionInfos); -- Gitee From 699f85c78bbee0113480064b106a6a789dea9a8e Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 23 Aug 2022 16:09:27 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=91=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../file_access/include/file_access_helper.h | 2 +- .../innerkits/file_access/src/file_access_helper.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index da027896..ddabf4d5 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -93,7 +93,7 @@ private: static std::unordered_map wantsMap_; static std::string GetKeyOfWantsMap(const AAFwk::Want &want); - static int getUserId(); + static int GetUserId(); sptr callerDeathRecipient_ = nullptr; diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index b395aee9..a50185a4 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -153,7 +153,7 @@ std::string FileAccessHelper::GetKeyOfWantsMap(const AAFwk::Want &want) return nullptr; } -int FileAccessHelper::getUserId() +int FileAccessHelper::GetUserId() { std::vector activeIds; int ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); @@ -161,6 +161,11 @@ int FileAccessHelper::getUserId() HILOG_ERROR("Failed to get ID"); return ERR_INVALID_PARAM; } + + if (activeIds.size() == ERR_OK) { + return ERR_INVALID_PARAM; + } + return activeIds[0]; } @@ -198,7 +203,7 @@ std::shared_ptr FileAccessHelper::Creator( std::unordered_map> cMap; std::vector extensionInfos; - int userId = FileAccessHelper::getUserId(); + int userId = FileAccessHelper::GetUserId(); if (userId < ERR_OK) { return nullptr; } @@ -607,7 +612,7 @@ std::vector FileAccessHelper::GetRegisterFileAccessExtAbilityInfo() std::vector extensionInfos; sptr bm = FileAccessHelper::GetBundleMgrProxy(); - int userId = FileAccessHelper::getUserId(); + int userId = FileAccessHelper::GetUserId(); if (userId < ERR_OK) { return wants; } -- Gitee From e27fb15874d622f86448bb4b1179039f5d47a650 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 23 Aug 2022 16:24:52 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=91=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- .../file_access/include/file_access_helper.h | 2 +- .../file_access/src/file_access_helper.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frameworks/innerkits/file_access/include/file_access_helper.h b/frameworks/innerkits/file_access/include/file_access_helper.h index ddabf4d5..c592522b 100644 --- a/frameworks/innerkits/file_access/include/file_access_helper.h +++ b/frameworks/innerkits/file_access/include/file_access_helper.h @@ -93,7 +93,7 @@ private: static std::unordered_map wantsMap_; static std::string GetKeyOfWantsMap(const AAFwk::Want &want); - static int GetUserId(); + static int GetUserId(int &userId); sptr callerDeathRecipient_ = nullptr; diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index a50185a4..904c6ce8 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -153,7 +153,7 @@ std::string FileAccessHelper::GetKeyOfWantsMap(const AAFwk::Want &want) return nullptr; } -int FileAccessHelper::GetUserId() +int FileAccessHelper::GetUserId(int &userId) { std::vector activeIds; int ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); @@ -162,11 +162,12 @@ int FileAccessHelper::GetUserId() return ERR_INVALID_PARAM; } - if (activeIds.size() == ERR_OK) { + if (activeIds.size() == 0) { return ERR_INVALID_PARAM; } - return activeIds[0]; + userId = activeIds[0] + return ERR_OK; } void FileAccessHelper::InsertConnectInfo(const std::string &key, @@ -203,8 +204,8 @@ std::shared_ptr FileAccessHelper::Creator( std::unordered_map> cMap; std::vector extensionInfos; - int userId = FileAccessHelper::GetUserId(); - if (userId < ERR_OK) { + int userId = 0; + if (FileAccessHelper::GetUserId(userId) != ERR_OK) { return nullptr; } @@ -612,8 +613,8 @@ std::vector FileAccessHelper::GetRegisterFileAccessExtAbilityInfo() std::vector extensionInfos; sptr bm = FileAccessHelper::GetBundleMgrProxy(); - int userId = FileAccessHelper::GetUserId(); - if (userId < ERR_OK) { + int userId = 0; + if (FileAccessHelper::GetUserId(userId) != ERR_OK) { return wants; } -- Gitee From 1c17fc7211f291e1d0e6f043d173fa81bb06d670 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 23 Aug 2022 16:59:43 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/src/file_access_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 904c6ce8..314e154e 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -166,7 +166,7 @@ int FileAccessHelper::GetUserId(int &userId) return ERR_INVALID_PARAM; } - userId = activeIds[0] + userId = activeIds[0]; return ERR_OK; } -- Gitee From 6cc143ebbab4a4776f148d241535cd722f9179af Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 23 Aug 2022 09:23:15 +0000 Subject: [PATCH 8/8] =?UTF-8?q?update=20frameworks/innerkits/file=5Faccess?= =?UTF-8?q?/src/file=5Faccess=5Fhelper.cpp.=20=E4=BF=AE=E6=94=B9=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjianqiang --- frameworks/innerkits/file_access/src/file_access_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkits/file_access/src/file_access_helper.cpp b/frameworks/innerkits/file_access/src/file_access_helper.cpp index 314e154e..adf3cc78 100644 --- a/frameworks/innerkits/file_access/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_access/src/file_access_helper.cpp @@ -158,7 +158,7 @@ int FileAccessHelper::GetUserId(int &userId) std::vector activeIds; int ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); if (ret != ERR_OK) { - HILOG_ERROR("Failed to get ID"); + HILOG_ERROR("Failed to get UserID"); return ERR_INVALID_PARAM; } -- Gitee