diff --git a/services/bundlemgr/include/aging/aging_handler.h b/services/bundlemgr/include/aging/aging_handler.h index 0a7cc738d9f1838dea0cf19dad4be33af2313321..9a20b5fe2f4dbebe4e98135dfa8874dba14a54a9 100644 --- a/services/bundlemgr/include/aging/aging_handler.h +++ b/services/bundlemgr/include/aging/aging_handler.h @@ -41,7 +41,7 @@ public: virtual bool Process(AgingRequest &request) const override; virtual bool CheckBundle(const AgingBundleInfo &bundle) const = 0; virtual bool NeedContinue(const AgingRequest &requese) const; - virtual bool isRunning(const std::string bundleName, const int bundleuid) const; + virtual bool IsRunning(const std::string bundleName, const int bundleuid) const; private: bool UnInstallBundle(const std::string &bundlename) const; diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index c566476614f7b2ae1577082e646131932bdf5f02..9ecda97e6fff6c27d702cbfb5ef5c7f56ae42a8b 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -609,13 +609,6 @@ public: * @return Returns all userId. */ std::set GetAllUser() const; -#ifdef BUNDLE_FRAMEWORK_FREE_INSTALL - /** - * @brief Get active user. - * @return Returns active userId. - */ - int32_t GetActiveUserId() const; -#endif /** * @brief Obtains the DistributedBundleInfo based on a given bundle name and networkId. * @param networkId Indicates the networkId of remote device. diff --git a/services/bundlemgr/src/aging/bundle_aging_mgr.cpp b/services/bundlemgr/src/aging/bundle_aging_mgr.cpp index 1ea32ca56bcea328323c2d27abd81778724b9261..d4f4084f3ad111dd6b61cbca8e1e39a79392b156 100644 --- a/services/bundlemgr/src/aging/bundle_aging_mgr.cpp +++ b/services/bundlemgr/src/aging/bundle_aging_mgr.cpp @@ -14,6 +14,7 @@ */ #include "aging/bundle_aging_mgr.h" +#include "account_helper.h" #include "battery_srv_client.h" #include "bundle_active_period_stats.h" #include "bundle_mgr_service.h" @@ -87,8 +88,8 @@ int BundleAgingMgr::AgingQueryFormStatistics(std::vectorQueryFormStatistics(AgingConstants::COUNT_MODULE_RECODES_GET, results, - dataMgr->GetActiveUserId()); + int32_t userId = AccountHelper::GetCurrentActiveUserId(); + int ret = bundleActiveClient->QueryFormStatistics(AgingConstants::COUNT_MODULE_RECODES_GET, results, userId); APP_LOGD("activeModuleRecord size %{public}zu, ret:%{public}d", results.size(), ret); return ret; } diff --git a/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp b/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp index feb95a969043e0c42d14ddb167b59e47b9139605..16983286cffd39fa49120c26c898500e7b80403b 100644 --- a/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp +++ b/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp @@ -16,6 +16,7 @@ #include #include "ability_manager.h" +#include "account_helper.h" #include "aging/aging_handler.h" #include "app_log_wrapper.h" #include "bundle_data_mgr.h" @@ -39,7 +40,7 @@ bool RecentlyUnuseBundleAgingHandler::Process(AgingRequest &request) const break; } APP_LOGD("found matching bundle: %{public}s.", iter->GetBundleName().c_str()); - bool isBundlerunning = isRunning(iter->GetBundleName(), iter->GetBundleUid()); + bool isBundlerunning = IsRunning(iter->GetBundleName(), iter->GetBundleUid()); if (!isBundlerunning) { bool isBundleUnistalled = UnInstallBundle(iter->GetBundleName()); if (isBundleUnistalled) { @@ -81,12 +82,12 @@ bool RecentlyUnuseBundleAgingHandler::UnInstallBundle(const std::string &bundlen sptr userReceiverImpl(new (std::nothrow) AgingUninstallReceiveImpl()); InstallParam installParam; - installParam.userId = bundleDataMgr->GetActiveUserId(); + installParam.userId = AccountHelper::GetCurrentActiveUserId(); bundleInstaller->Uninstall(bundlename, installParam, userReceiverImpl); return true; } -bool RecentlyUnuseBundleAgingHandler::isRunning(const std::string bundleName, const int bundleuid) const +bool RecentlyUnuseBundleAgingHandler::IsRunning(const std::string bundleName, const int bundleuid) const { if (bundleuid < 0) { APP_LOGE("bundleuid is error."); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 513986d7a822b1078154a53a1dd7e893c43a4662..f119139934e1a1a3af4e1c4e5968e5e542944951 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -21,8 +21,8 @@ #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL #include "installd/installd_operator.h" #include "os_account_info.h" -#include "os_account_manager.h" #endif +#include "account_helper.h" #include "app_log_wrapper.h" #include "bundle_constants.h" #include "bundle_data_storage_database.h" @@ -1031,15 +1031,16 @@ bool BundleDataMgr::GetInnerBundleInfoByUid(const int uid, InnerBundleInfo &inne APP_LOGD("the uid(%{public}d) is not exists.", uid); return false; } + #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL int64_t BundleDataMgr::GetBundleSpaceSize(const std::string &bundleName) const { - int32_t userId; + int32_t userId = AccountHelper::GetCurrentActiveUserId(); int64_t curSize = 0; int64_t spaceSize = 0; BundleInfo bundleInfo; - if ((userId = GetActiveUserId()) != Constants::INVALID_USERID + if (userId != Constants::INVALID_USERID && GetBundleInfo(bundleName, GET_ALL_APPLICATION_INFO, bundleInfo, userId) == true) { if (!bundleInfo.applicationInfo.codePath.empty()) { curSize = InstalldOperator::GetDiskUsage(bundleInfo.applicationInfo.codePath); @@ -1059,12 +1060,12 @@ int64_t BundleDataMgr::GetBundleSpaceSize(const std::string &bundleName) const int64_t BundleDataMgr::GetAllFreeInstallBundleSpaceSize() const { - int32_t userId; + int32_t userId = AccountHelper::GetCurrentActiveUserId(); int64_t allSize = 0; int64_t curSize = 0; std::vector bundleInfos; - if ((userId = GetActiveUserId()) != Constants::INVALID_USERID + if (userId != Constants::INVALID_USERID && GetBundleInfos(GET_ALL_APPLICATION_INFO, bundleInfos, userId) == true) { for (const auto &item : bundleInfos) { APP_LOGI("%{public}s freeInstall:%{public}d", item.name.c_str(), item.applicationInfo.isFreeInstallApp); @@ -2474,20 +2475,6 @@ int32_t BundleDataMgr::GetUserIdByCallingUid() const return BundleUtil::GetUserIdByCallingUid(); } -#ifdef BUNDLE_FRAMEWORK_FREE_INSTALL -int32_t BundleDataMgr::GetActiveUserId() const -{ - std::vector activeIds; - int32_t ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); - if (ret != 0 || activeIds.empty()) { - APP_LOGE("QueryActiveOsAccountIds ret = %{public}d. activeIds empty:%{public}d", - ret, activeIds.empty()); - return Constants::INVALID_USERID; - } - return activeIds[0]; -} -#endif - std::set BundleDataMgr::GetAllUser() const { std::lock_guard lock(multiUserIdSetMutex_); @@ -2850,7 +2837,7 @@ bool BundleDataMgr::GetRemovableBundleNameVec(std::map& bundle } for (auto &it : bundleInfos_) { APP_LOGD("bundleName: %{public}s", it.first.c_str()); - int32_t userId = GetActiveUserId(); + int32_t userId = AccountHelper::GetCurrentActiveUserId(); APP_LOGD("bundle userId is %{public}d, userId= %{public}d", it.second.GetUserId(), userId); if (!it.second.HasInnerBundleUserInfo(userId)) { continue;