From 95ce8e13d911c26d09e6d8643ba20cb5a7012f07 Mon Sep 17 00:00:00 2001 From: jerry Date: Mon, 24 Jan 2022 13:05:48 +0000 Subject: [PATCH 1/2] fix-bugs Signed-off-by: jerry --- services/abilitymgr/src/mission_list_manager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index ca0e113c1b6..d7f0bfe0720 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; } -- Gitee From cc0e0345c81d5ac941c0ec0fa8299ea36a9763e2 Mon Sep 17 00:00:00 2001 From: jerry Date: Tue, 25 Jan 2022 01:31:04 +0000 Subject: [PATCH 2/2] fix bugs Signed-off-by: jerry --- .../ability_runtime/context/context_impl.cpp | 45 ++++++++++++++----- .../ability_runtime/context/context_impl.h | 3 +- 2 files changed, 37 insertions(+), 11 deletions(-) mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/context_impl.cpp mode change 100755 => 100644 frameworks/kits/appkit/native/ability_runtime/context/context_impl.h 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 9654f279e15..b3d253f3870 --- 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 4658e7fb5a2..a6de5ba025b --- 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; -- Gitee