From 609cd9bdd394c553f828d9b01e61a2d8eeef0aee Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Wed, 10 Jul 2024 14:34:31 +0800 Subject: [PATCH] =?UTF-8?q?OTA=E6=97=B6=E9=87=8D=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=89=80=E6=9C=89uid=E9=85=8D=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- .../bundle_mgr_service_event_handler.h | 4 + .../src/bundle_mgr_service_event_handler.cpp | 102 ++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index 7ba8c3ea66..b6108e3443 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -495,6 +495,10 @@ private: void InnerProcessCheckCloudShaderDir(); void ProcessNewBackupDir(); + void PrepareBundleDirQuota(const std::string &bundleName, const int32_t uid, + const std::string &bundleDataDirPath, const int32_t limitSize) const; + void RefreshQuotaForAllUid(); + bool InnerProcessUninstallModule(const BundleInfo &bundleInfo, const std::unordered_map &infos); diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index fe864adc84..59ae2a18f3 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -63,6 +63,10 @@ #include "want.h" #include "user_unlocked_event_subscriber.h" #include "json_util.h" +#ifdef STORAGE_SERVICE_ENABLE +#include "storage_manager_proxy.h" +#include "iservice_registry.h" +#endif namespace OHOS { namespace AppExecFwk { @@ -113,6 +117,16 @@ std::set extensiontype_; bool hasLoadPreInstallProFile_ = false; std::vector bundleNameList_; +#ifdef STORAGE_SERVICE_ENABLE +#ifdef QUOTA_PARAM_SET_ENABLE +const std::string SYSTEM_PARAM_ATOMICSERVICE_DATASIZE_THRESHOLD = + "persist.sys.bms.aging.policy.atomicservice.datasize.threshold"; +const int32_t THRESHOLD_VAL_LEN = 20; +#endif // QUOTA_PARAM_SET_ENABLE +const int32_t STORAGE_MANAGER_MANAGER_ID = 5003; +#endif // STORAGE_SERVICE_ENABLE +const int32_t ATOMIC_SERVICE_DATASIZE_THRESHOLD_MB_PRESET = 200; + void MoveTempPath(const std::vector &fromPaths, const std::string &bundleName, std::vector &toPaths) { @@ -1089,6 +1103,7 @@ void BMSEventHandler::ProcessRebootBundle() ProcessCheckShaderCacheDir(); ProcessCheckCloudShaderDir(); ProcessNewBackupDir(); + RefreshQuotaForAllUid(); } void BMSEventHandler::ProcessRebootDeleteArkAp() @@ -1451,6 +1466,93 @@ void BMSEventHandler::InnerProcessCheckCloudShaderDir() LOG_I(BMS_TAG_DEFAULT, "Create cloud shader cache result: %{public}d", result); } +static void SendToStorageQuota(const std::string &bundleName, const int32_t uid, + const std::string &bundleDataDirPath, const int32_t limitSizeMb) +{ +#ifdef STORAGE_SERVICE_ENABLE + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + LOG_W(BMS_TAG_DEFAULT, "SendToStorageQuota, systemAbilityManager error"); + return; + } + + auto remote = systemAbilityManager->CheckSystemAbility(STORAGE_MANAGER_MANAGER_ID); + if (!remote) { + LOG_W(BMS_TAG_DEFAULT, "SendToStorageQuota, CheckSystemAbility error"); + return; + } + + auto proxy = iface_cast(remote); + if (!proxy) { + LOG_W(BMS_TAG_DEFAULT, "SendToStorageQuotactl, proxy get error"); + return; + } + + LOG_I(BMS_TAG_DEFAULT, "SendToStorageQuota bundleName=%{public}s, uid=%{public}d, bundleDataDirPath=%{public}s," + "limitSizeMb=%{public}d", bundleName.c_str(), uid, bundleDataDirPath.c_str(), limitSizeMb); + int err = proxy->SetBundleQuota(bundleName, uid, bundleDataDirPath, limitSizeMb); + if (err != ERR_OK) { + LOG_W(BMS_TAG_DEFAULT, "SendToStorageQuota, SetBundleQuota error, err=%{public}d, uid=%{public}d", err, uid); + } +#endif // STORAGE_SERVICE_ENABLE +} + +void BMSEventHandler::PrepareBundleDirQuota(const std::string &bundleName, const int32_t uid, + const std::string &bundleDataDirPath, const int32_t limitSize) const +{ + if (limitSize == 0) { + LOG_I(BMS_TAG_DEFAULT, "cancel bundleName:%{public}s uid:%{public}d quota", bundleName.c_str(), uid); + SendToStorageQuota(bundleName, uid, bundleDataDirPath, 0); + return; + } + int32_t atomicserviceDatasizeThreshold = limitSize; +#ifdef STORAGE_SERVICE_ENABLE +#ifdef QUOTA_PARAM_SET_ENABLE + char szAtomicDatasizeThresholdMb[THRESHOLD_VAL_LEN] = {0}; + int32_t ret = GetParameter(SYSTEM_PARAM_ATOMICSERVICE_DATASIZE_THRESHOLD.c_str(), "", + szAtomicDatasizeThresholdMb, THRESHOLD_VAL_LEN); + if (ret <= 0) { + LOG_I(BMS_TAG_DEFAULT, "GetParameter failed"); + } else if (strcmp(szAtomicDatasizeThresholdMb, "") != 0) { + atomicserviceDatasizeThreshold = atoi(szAtomicDatasizeThresholdMb); + LOG_I(BMS_TAG_DEFAULT, "InstalldQuotaUtils init atomicserviceDataThreshold mb success"); + } + if (atomicserviceDatasizeThreshold <= 0) { + LOG_W(BMS_TAG_DEFAULT, "no need to prepare quota"); + return; + } +#endif // QUOTA_PARAM_SET_ENABLE +#endif // STORAGE_SERVICE_ENABLE + SendToStorageQuota(bundleName, uid, bundleDataDirPath, atomicserviceDatasizeThreshold); +} + +void BMSEventHandler::RefreshQuotaForAllUid() +{ + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return; + } + std::map infos = dataMgr->GetAllInnerBundleInfos(); + for (auto &infoPair : infos) { + auto &info = infoPair.second; + std::map userInfos = info.GetInnerBundleUserInfos(); + for (auto &userInfoPair : userInfos) { + auto &userInfo = userInfoPair.second; + std::string bundleDataDir = ServiceConstants::BUNDLE_APP_DATA_BASE_DIR + ServiceConstants::BUNDLE_EL[0] + + ServiceConstants::PATH_SEPARATOR + std::to_string(userInfo.bundleUserInfo.userId) + + ServiceConstants::BASE + info.GetBundleName(); + if (info.GetApplicationBundleType() != BundleType::ATOMIC_SERVICE) { + PrepareBundleDirQuota(info.GetBundleName(), info.GetUid(userInfo.bundleUserInfo.userId), + bundleDataDir, 0); + } else { + PrepareBundleDirQuota(info.GetBundleName(), info.GetUid(userInfo.bundleUserInfo.userId), + bundleDataDir, ATOMIC_SERVICE_DATASIZE_THRESHOLD_MB_PRESET); + } + } + } +} + bool BMSEventHandler::LoadAllPreInstallBundleInfos() { if (hasLoadAllPreInstallBundleInfosFromDb_) { -- Gitee