From b68b8ec4a7cb3b214a5112bf1f779c92489a81c0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Aug 2021 11:45:14 +0800 Subject: [PATCH] IssueNo:#I3XCB5 Description:add get file folder size interface Sig:appexecfwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: root --- frameworks/bundle_lite/src/bundle_manager.cpp | 36 +++++++++++++++++++ .../bundlemgr_lite/bundle_inner_interface.h | 2 ++ interfaces/kits/bundle_lite/bundle_manager.h | 2 ++ .../include/bundle_manager_service.h | 1 + .../include/bundle_ms_feature.h | 2 ++ .../bundlemgr_lite/src/bundle_installer.cpp | 1 + .../src/bundle_manager_service.cpp | 30 ++++++++++++++++ .../bundlemgr_lite/src/bundle_ms_feature.cpp | 28 +++++++++++++++ services/bundlemgr_lite/src/bundle_util.cpp | 5 +++ 9 files changed, 107 insertions(+) diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp index 6386271..6a0be53 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 a79850d..c67140e 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 c55791c..4d02ac0 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 472762f..ec6bb6f 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 8a872f3..f33cfdb 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 cf8b6be..4fd6814 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 169fb03..48dd5a3 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 6edbe6c..4c9cfbd 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 27813a6..4375fd9 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); } -- Gitee