diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp index 6386271224749bb42ffcfbd6b75b62f162082c95..6a0be539857e3d9b8face1fd3d4ee7f4504228a1 100755 --- a/frameworks/bundle_lite/src/bundle_manager.cpp +++ b/frameworks/bundle_lite/src/bundle_manager.cpp @@ -605,6 +605,42 @@ uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len) return ObtainInnerBundleInfos(flags, bundleInfos, len, GET_BUNDLE_INFOS, &ipcIo); } +uint32_t GetBundleSize(const char *bundleName) +{ + if (bundleName == nullptr) { + return 0; + } + if (strlen(bundleName) >= MAX_BUNDLE_NAME) { + return 0; + } + // if (CheckSelfPermission(static_cast(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) { + // HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get bundle size failed due to permission denied"); + // return 0; + // } + auto bmsClient = GetBmsClient(); + if (bmsClient == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get bundle size failed due to nullptr bms client"); + return 0; + } + + IpcIo ipcIo; + char data[IPC_IO_DATA_MAX]; + IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); + IpcIoPushString(&ipcIo, bundleName); + // IpcIoPushInt32(&ipcIo, flags); + if (!IpcIoAvailable(&ipcIo)) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize ipc failed"); + return 0; + } + uint32_t bundleSize = 0; + int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_SIZE, &ipcIo, &bundleSize, Notify); + if (ret != OHOS_SUCCESS) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfo invoke failed: %{public}d", ret); + return 0; + } + return bundleSize; +} + uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) { if ((bundleInfos == nullptr) || (len == nullptr)) { diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h index a79850d197da0b7c2528bdfdc4b03b3d666f0008..c67140e22e423d8c9ea065870825a8145af96348 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_inner_interface.h @@ -41,6 +41,7 @@ enum BmsCmd { GET_BUNDLE_INFOS_BY_METADATA, CHECK_SYS_CAP, GET_SYS_CAP, + GET_BUNDLE_SIZE, BMS_INNER_BEGIN, INSTALL = BMS_INNER_BEGIN, // bms install application UNINSTALL, @@ -59,6 +60,7 @@ struct BmsServerProxy { uint8_t (*GetBundleInfos)(int flags, BundleInfo **bundleInfos, int32_t *len); uint8_t (*QueryKeepAliveBundleInfos)(BundleInfo **bundleInfos, int32_t *len); uint8_t (*GetBundleNameForUid)(int32_t uid, char **bundleName); + uint32_t (*GetBundleSize)(const char *bundleName); }; struct BmsInnerServerProxy { diff --git a/interfaces/kits/bundle_lite/bundle_manager.h b/interfaces/kits/bundle_lite/bundle_manager.h index c55791cab45ca3d7b5fed84e54d7cfe129c35235..4d02ac0f37480373adc90ab3b83d9b09b017a2e8 100755 --- a/interfaces/kits/bundle_lite/bundle_manager.h +++ b/interfaces/kits/bundle_lite/bundle_manager.h @@ -246,6 +246,8 @@ SystemCapability *GetSystemAvailableCapabilities(); * @version 4 */ void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap); + +uint32_t GetBundleSize(const char *bundleName); #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_manager_service.h b/services/bundlemgr_lite/include/bundle_manager_service.h index 472762fd8b8047c69a5a39d99968cb59ce403a8f..ec6bb6f52a3cfe2c0311852670d8f2b2f40796a6 100755 --- a/services/bundlemgr_lite/include/bundle_manager_service.h +++ b/services/bundlemgr_lite/include/bundle_manager_service.h @@ -44,6 +44,7 @@ public: bool UpdateBundleInfo(BundleInfo *info); uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len); + uint32_t GetBundleSize(const char *bundleName); std::vector GetServiceId() const; int32_t GenerateUid(const char *bundleName, int8_t bundleStyle); void RecycleUid(const char *bundleName); diff --git a/services/bundlemgr_lite/include/bundle_ms_feature.h b/services/bundlemgr_lite/include/bundle_ms_feature.h index 8a872f3eb79d880e2d22488681467b72ee3261c0..f33cfdbb3b887ca7323b696d9f5661495a50d288 100755 --- a/services/bundlemgr_lite/include/bundle_ms_feature.h +++ b/services/bundlemgr_lite/include/bundle_ms_feature.h @@ -44,6 +44,7 @@ public: static uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len); static uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len); static uint8_t GetBundleNameForUid(int32_t uid, char **bundleName); + static uint32_t GetBundleSize(const char *bundleName); private: BundleMsFeature(); @@ -60,6 +61,7 @@ private: static uint8_t ChangeInnerCallbackServiceId(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t GetSystemAvailableCapabilities(const uint8_t funcId, IpcIo *req, IpcIo *reply); + static uint8_t GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply); Identity identity_; static BundleInvokeType BundleMsInvokeFuc[BMS_INNER_BEGIN]; diff --git a/services/bundlemgr_lite/src/bundle_installer.cpp b/services/bundlemgr_lite/src/bundle_installer.cpp index cf8b6be0d68c3504c27148fb4de7b5ddadb4a025..4fd681423fc7e0cb939ed60848af38df0ed1fcfd 100755 --- a/services/bundlemgr_lite/src/bundle_installer.cpp +++ b/services/bundlemgr_lite/src/bundle_installer.cpp @@ -105,6 +105,7 @@ uint8_t BundleInstaller::GetHapType(const char *path) uint8_t BundleInstaller::Install(const char *path, const InstallParam &installParam) { + HILOG_ERROR("wdj", "BUNDLE_INSTALLED3"); if (path == nullptr || installParam.installLocation < INSTALL_LOCATION_INTERNAL_ONLY || installParam.installLocation > INSTALL_LOCATION_PREFER_EXTERNAL) { return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR; diff --git a/services/bundlemgr_lite/src/bundle_manager_service.cpp b/services/bundlemgr_lite/src/bundle_manager_service.cpp index 169fb03d230b396f3a64edc4fe66d5fcc0fbc6b1..48dd5a399a4fd841eda0999577283adc21b17718 100755 --- a/services/bundlemgr_lite/src/bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/bundle_manager_service.cpp @@ -203,6 +203,7 @@ void ManagerService::ServiceMsgProcess(Request* request) case BUNDLE_UPDATED: /* Process update request by Install() */ case BUNDLE_INSTALLED: { + HILOG_ERROR("wdj", "BUNDLE_INSTALLED1"); auto info = reinterpret_cast(request->data); if (info == nullptr) { return; @@ -213,6 +214,7 @@ void ManagerService::ServiceMsgProcess(Request* request) return; } + HILOG_ERROR("wdj", "BUNDLE_INSTALLED2"); InstallThirdBundle(info->path, *(info->svc), info->installLocation); AdapterFree(info->path); AdapterFree(info->svc); @@ -302,6 +304,9 @@ void ManagerService::InstallThirdBundle(const char *path, const SvcIdentity &svc InstallParam installParam = {.installLocation = installLocation, .keepData = false}; uint8_t bResult = installer_->Install(path, installParam); HILOG_DEBUG(HILOG_MODULE_APP, "BundleMS InstallThirdBundle Install : %{public}d\n", bResult); + uint32_t bundleSize = GetBundleSize(bundleName); + HILOG_ERROR("wdj", "bundle name is %{public}s\n", bundleName); + HILOG_ERROR("wdj", "bundle size is %{public}d\n", bundleSize); InnerSelfTransact(INSTALL_CALLBACK, bResult, svc); InnerTransact(INSTALL_CALLBACK, bResult, bundleName); } @@ -625,6 +630,31 @@ uint8_t ManagerService::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, return bundleMap_->GetBundleInfos(flags, bundleInfos, len); } +uint32_t ManagerService::GetBundleSize(const char *bundleName) +{ + HILOG_ERROR("wdj", "get bundle size1\n"); + if (bundleName == nullptr) { + return 0; + } + HILOG_ERROR("wdj", "get bundle size2\n"); + BundleInfo *installedInfo = bundleMap_->Get(bundleName); + if (installedInfo == nullptr) { + return 0; + } + HILOG_ERROR("wdj", "get bundle size3\n"); + char *codePath = installedInfo->codePath; + uint32_t codeBundleSize = BundleUtil::GetFileFolderSize(codePath); + if (codeBundleSize == 0) { + return 0; + } + HILOG_ERROR("wdj", "get bundle size4 codePath is %{public}s\n", codePath); + HILOG_ERROR("wdj", "get bundle size4 codeBundleSize is %{public}d\n", codeBundleSize); + char *dataPath = installedInfo->dataPath; + uint32_t dataBundleSize = BundleUtil::GetFileFolderSize(dataPath); + HILOG_ERROR("wdj", "get bundle size5 dataPath is %{public}s\n", dataPath); + HILOG_ERROR("wdj", "get bundle size5 dataBundleSize is %{public}d\n", dataBundleSize); + return codeBundleSize + dataBundleSize; +} std::string ManagerService::GetCodeDirPath() const { diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp index 6edbe6cfcd9db52ea606524292a518bc1e4cc8b1..4c9cfbde152385579dc3b720c1bf1f2a6c25a9f3 100755 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -42,6 +42,7 @@ static BmsImpl g_bmsImpl = { .GetBundleInfos = BundleMsFeature::GetBundleInfos, .QueryKeepAliveBundleInfos = BundleMsFeature::QueryKeepAliveBundleInfos, .GetBundleNameForUid = BundleMsFeature::GetBundleNameForUid, + .GetBundleSize = BundleMsFeature::GetBundleSize, IPROXY_END }; @@ -55,6 +56,7 @@ BundleInvokeType BundleMsFeature::BundleMsInvokeFuc[BMS_INNER_BEGIN] { HandleGetBundleInfos, HasSystemCapability, GetSystemAvailableCapabilities, + GetInnerBundleSize, }; IUnknown *GetBmsFeatureApi(Feature *feature) @@ -248,6 +250,25 @@ uint8_t BundleMsFeature::GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, Ip return OHOS_SUCCESS; } +uint8_t BundleMsFeature::GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply) +{ + if ((req == nullptr) || (reply == nullptr)) { + return ERR_APPEXECFWK_OBJECT_NULL; + } + size_t size = 0; + char *bundleName = reinterpret_cast(IpcIoPopString(req, &size)); + if (bundleName == nullptr) { + return ERR_APPEXECFWK_DESERIALIZATION_FAILED; + } + uint32_t bundleSize = GetBundleSize(bundleName); + if (bundleSize == 0) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleMS GET_BUNDLE_SIZE error!\n"); + return ERR_APPEXECFWK_OBJECT_NULL; + } + IpcIoPushUint32(reply, bundleSize); + return OHOS_SUCCESS; +} + uint8_t BundleMsFeature::HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, IpcIo *reply) { if ((req == nullptr) || (reply == nullptr)) { @@ -367,6 +388,8 @@ int32 BundleMsFeature::Invoke(IServerProxy *iProxy, int funcId, void *origin, Ip ret = BundleMsInvokeFuc[funcId](funcId, req, reply); } else if (funcId >= CHECK_SYS_CAP && funcId <= GET_SYS_CAP) { ret = BundleMsInvokeFuc[funcId](funcId, req, reply); + } else if (funcId == GET_BUNDLE_SIZE) { + ret = BundleMsInvokeFuc[funcId](funcId, req, reply); } else { ret = ERR_APPEXECFWK_COMMAND_ERROR; } @@ -427,6 +450,11 @@ uint8_t BundleMsFeature::GetBundleInfos(const int flags, BundleInfo **bundleInfo return OHOS::ManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len); } +uint32_t BundleMsFeature::GetBundleSize(const char *bundleName) +{ + return OHOS::ManagerService::GetInstance().GetBundleSize(bundleName); +} + uint8_t BundleMsFeature::QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) { if ((bundleInfos == nullptr) || (len == nullptr)) { diff --git a/services/bundlemgr_lite/src/bundle_util.cpp b/services/bundlemgr_lite/src/bundle_util.cpp index 27813a68fca4df3ec6e03f7999689f39d8e8762d..4375fd9b431270e7603a00ae1004016e6a1e044f 100755 --- a/services/bundlemgr_lite/src/bundle_util.cpp +++ b/services/bundlemgr_lite/src/bundle_util.cpp @@ -26,6 +26,9 @@ #include #include #include "bundle_daemon_client.h" + +#include "log.h" + #else #include "adapter.h" #include "bundlems_log.h" @@ -202,7 +205,9 @@ uint32_t BundleUtil::GetFileFolderSize(const char *filePath) if (curPath == nullptr) { break; } + HILOG_ERROR("wdj", "get curPath is %{public}s\n", curPath); fileFolderSize += GetCurrentFolderSize(curPath, list); + HILOG_ERROR("wdj", "get fileFolderSize is %{public}d\n", fileFolderSize); list->PopFront(); AdapterFree(curPath); }