diff --git a/kits/BUILD.gn b/kits/BUILD.gn old mode 100755 new mode 100644 index 7a472b036685ba9f78635abe50daad536df53132..5c51633fe87a9f3ee77baa0bef705b89d81efa65 --- a/kits/BUILD.gn +++ b/kits/BUILD.gn @@ -165,6 +165,10 @@ ohos_shared_library("appkit_native") { # build so ohos_shared_library("app_context") { include_dirs = [ + "//base/account/os_account/frameworks/common/account_error/include", + "//base/account/os_account/frameworks/common/database/include", + "//base/account/os_account/frameworks/common/log/include", + "//base/account/os_account/interfaces/innerkits/osaccount/native/include", "$SUBSYSTEM_DIR/kits/appkit/native/app/include", "$SUBSYSTEM_DIR/kits/appkit/native/ability_runtime/context", "$SUBSYSTEM_DIR/interfaces/innerkits/appexecfwk_core/include/bundlemgr", @@ -205,6 +209,7 @@ ohos_shared_library("app_context") { ] public_deps = [ + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", ] diff --git a/kits/appkit/native/ability_runtime/context/context_impl.cpp b/kits/appkit/native/ability_runtime/context/context_impl.cpp index c9f22bb3fa0e31d700b16ccd09e0bdbdd1e63502..029b4de0fecb43b4913c1fbc0c744f1cde7d67b2 100644 --- a/kits/appkit/native/ability_runtime/context/context_impl.cpp +++ b/kits/appkit/native/ability_runtime/context/context_impl.cpp @@ -18,6 +18,7 @@ #include "hilog_wrapper.h" #include "ipc_singleton.h" #include "locale_config.h" +#include "os_account_manager.h" #include "sys_mgr_client.h" #include "system_ability_definition.h" @@ -101,7 +102,7 @@ std::string ContextImpl::GetDistributedFilesDir() HILOG_DEBUG("ContextImpl::GetDistributedFilesDir"); std::string dir; if (IsCreateBySystemApp()) { - dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + GetCurrentAccount() + + dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + GetCurrentAccountId() + CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE + GetBundleName(); } else { dir = CONTEXT_BASE + CONTEXT_DISTRIBUTEDFILES; @@ -114,7 +115,7 @@ std::string ContextImpl::GetBaseDir() const { std::string baseDir; if (IsCreateBySystemApp()) { - baseDir = CONTEXT_DATA + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccount() + + baseDir = CONTEXT_DATA + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + CONTEXT_BUNDLE + GetBundleName(); } else { baseDir = CONTEXT_BASE + currArea_; @@ -127,9 +128,11 @@ std::string ContextImpl::GetBaseDir() const return baseDir; } -std::string ContextImpl::GetCurrentAccount() const +std::string ContextImpl::GetCurrentAccountId() const { - return "0"; + int userId; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId); + return std::to_string(userId); } std::shared_ptr ContextImpl::CreateBundleContext(const std::string &bundleName) diff --git a/kits/appkit/native/ability_runtime/context/context_impl.h b/kits/appkit/native/ability_runtime/context/context_impl.h index 088fea12975afbdc9f417d51c1be62e37c3dd8cf..1d4a5e485e13c9788fe682c3ec360ea739d38bca 100644 --- a/kits/appkit/native/ability_runtime/context/context_impl.h +++ b/kits/appkit/native/ability_runtime/context/context_impl.h @@ -191,7 +191,7 @@ private: const AppExecFwk::BundleInfo &bundleInfo, const std::shared_ptr &appContext) const; bool IsCreateBySystemApp() const; std::string GetBaseDir() const; - std::string GetCurrentAccount() const; + std::string GetCurrentAccountId() const; void SetFlags(int64_t flags); std::shared_ptr applicationInfo_ = nullptr;