diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp old mode 100755 new mode 100644 index 9654f279e157c315f2fac8ce295636949faca9ff..b3d253f3870c187d23e3148342aa65986ce86625 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp @@ -75,8 +75,8 @@ std::string ContextImpl::GetDatabaseDir() { std::string dir; if (IsCreateBySystemApp()) { - dir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + CONTEXT_FILE_SEPARATOR + - CONTEXT_DATABASE + GetBundleName(); + dir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + std::to_string(GetCurrentAccountId()) + + CONTEXT_FILE_SEPARATOR + CONTEXT_DATABASE + GetBundleName(); } else { dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DATABASE; } @@ -111,7 +111,7 @@ std::string ContextImpl::GetDistributedFilesDir() HILOG_DEBUG("ContextImpl::GetDistributedFilesDir"); std::string dir; if (IsCreateBySystemApp()) { - dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + GetCurrentAccountId() + + dir = CONTEXT_DISTRIBUTEDFILES_BASE_BEFORE + std::to_string(GetCurrentAccountId()) + CONTEXT_DISTRIBUTEDFILES_BASE_MIDDLE + GetBundleName(); } else { dir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_DISTRIBUTEDFILES + @@ -136,7 +136,7 @@ std::string ContextImpl::GetBaseDir() const { std::string baseDir; if (IsCreateBySystemApp()) { - baseDir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + GetCurrentAccountId() + + baseDir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + std::to_string(GetCurrentAccountId()) + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE + CONTEXT_FILE_SEPARATOR + GetBundleName(); } else { baseDir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE; @@ -150,11 +150,33 @@ std::string ContextImpl::GetBaseDir() const return baseDir; } -std::string ContextImpl::GetCurrentAccountId() const +int ContextImpl::GetCurrentAccountId() const { int userId = 0; AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId); - return std::to_string(userId); + return userId; +} + +int ContextImpl::GetCurrentActiveAccountId() const +{ + std::vector osAccountInfos; + ErrCode ret = AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(osAccountInfos); + if (ret != ERR_OK) { + HILOG_ERROR("ContextImpl::GetCurrentActiveAccountId error."); + return 0; + } + + if (osAccountInfos.size() == 0) { + HILOG_ERROR("ContextImpl::GetCurrentActiveAccountId error, no accounts."); + return 0; + } + + if (osAccountInfos.size() > 1) { + HILOG_ERROR("ContextImpl::GetCurrentActiveAccountId error, no current now."); + return 0; + } + + return osAccountInfos[0].GetLocalId(); } std::shared_ptr ContextImpl::CreateBundleContext(const std::string &bundleName) @@ -175,10 +197,13 @@ std::shared_ptr ContextImpl::CreateBundleContext(const std::string &bun } AppExecFwk::BundleInfo bundleInfo; - HILOG_DEBUG("ContextImpl::CreateBundleContext length: %{public}zu, bundleName: %{public}s", - (size_t)bundleName.length(), - bundleName.c_str()); - bundleMgr->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo); + int accountId = GetCurrentAccountId(); + if (accountId == 0) { + accountId = GetCurrentActiveAccountId(); + } + HILOG_DEBUG("ContextImpl::CreateBundleContext length: %{public}zu, bundleName: %{public}s, accountId: %{public}d", + (size_t)bundleName.length(), bundleName.c_str(), accountId); + bundleMgr->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, accountId); if (bundleInfo.name.empty() || bundleInfo.applicationInfo.name.empty()) { HILOG_ERROR("ContextImpl::CreateBundleContext GetBundleInfo is error"); diff --git a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h old mode 100755 new mode 100644 index 4658e7fb5a2c5eb181b09623f6771e9ca3eb9217..a6de5ba025b26f6606de409160b1c1e8cb7100c4 --- a/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h +++ b/frameworks/kits/appkit/native/ability_runtime/context/context_impl.h @@ -207,8 +207,9 @@ private: const AppExecFwk::BundleInfo &bundleInfo, const std::shared_ptr &appContext) const; bool IsCreateBySystemApp() const; std::string GetBaseDir() const; - std::string GetCurrentAccountId() const; + int GetCurrentAccountId() const; void SetFlags(int64_t flags); + int GetCurrentActiveAccountId() const; std::shared_ptr applicationInfo_ = nullptr; std::shared_ptr parentContext_ = nullptr; diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index ca0e113c1b6cd3516cdabc5ec8c9d4bfc2e69bf1..d7f0bfe0720953235b2a8f4db7ddf255ddd311df 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -1009,11 +1009,7 @@ int MissionListManager::ClearMission(int missionId) } std::lock_guard guard(managerLock_); auto mission = GetMissionById(missionId); - if (mission == nullptr) { - HILOG_ERROR("mission is nullptr for missionId:%{public}d", missionId); - return ERR_INVALID_VALUE; - } - if (mission->GetMissionList() && mission->GetMissionList()->GetType() == MissionListType::LAUNCHER) { + if (mission && mission->GetMissionList() && mission->GetMissionList()->GetType() == MissionListType::LAUNCHER) { HILOG_ERROR("Mission id is launcher, can not clear."); return ERR_INVALID_VALUE; }