IssueNo:#I3XCB5

Description:add get file folder size interface
Sig:appexecfwk
Feature or Bugfix:Feature
Binary Source:No

Signed-off-by: wangdengjia <wangdengjia@huawei.com>
This commit is contained in:
wangdengjia
2021-08-10 21:40:14 +08:00
parent 58f34e83d1
commit f1f61ae0af
9 changed files with 123 additions and 1 deletions
@@ -67,4 +67,9 @@ struct BundleCallbackInfo {
BundleStateCallback bundleStateCallback;
void *data;
};
struct ResultOfGetBundleSize {
uint8_t resultCode;
uint32_t bundleSize;
};
#endif // OHOS_BUNDLE_CALLBACK_UTILS_H
@@ -224,6 +224,22 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply)
return resultCode;
}
static uint8_t DeserializeBundleSize(IOwner owner, IpcIo *reply)
{
if ((reply == nullptr) || (owner == nullptr)) {
return OHOS_FAILURE;
}
uint8_t resultCode = IpcIoPopUint8(reply);
ResultOfGetBundleSize *info = reinterpret_cast<ResultOfGetBundleSize *>(owner);
if (resultCode != ERR_OK) {
info->resultCode = resultCode;
return resultCode;
}
info->bundleSize = IpcIoPopUint32(reply);
info->resultCode = resultCode;
return resultCode;
}
static uint8_t DeserializeSystemCapabilities(IOwner owner, IpcIo *reply)
{
if ((reply == nullptr) || (owner == nullptr)) {
@@ -300,6 +316,9 @@ static int Notify(IOwner owner, int code, IpcIo *reply)
HILOG_INFO(HILOG_MODULE_APP, "BundleManager HasSystemCapability invoke return: %{public}d", *ret);
break;
}
case GET_BUNDLE_SIZE: {
return DeserializeBundleSize(owner, reply);
}
case GET_SYS_CAP: {
return DeserializeSystemCapabilities(owner, reply);
}
@@ -605,6 +624,43 @@ 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<const char *>(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);
if (!IpcIoAvailable(&ipcIo)) {
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize ipc failed");
return 0;
}
ResultOfGetBundleSize resultOfGetBundleSize;
int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_SIZE, &ipcIo, &resultOfGetBundleSize, Notify);
if (ret != OHOS_SUCCESS) {
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize invoke failed: %{public}d", ret);
return 0;
}
uint32_t bundleSize = resultOfGetBundleSize.bundleSize;
return bundleSize;
}
uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len)
{
if ((bundleInfos == nullptr) || (len == nullptr)) {
@@ -40,6 +40,7 @@ enum BmsCmd {
QUERY_KEEPALIVE_BUNDLE_INFOS,
GET_BUNDLE_INFOS_BY_METADATA,
CHECK_SYS_CAP,
GET_BUNDLE_SIZE,
GET_SYS_CAP,
BMS_INNER_BEGIN,
INSTALL = BMS_INNER_BEGIN, // bms install application
@@ -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 {
@@ -246,6 +246,17 @@ SystemCapability *GetSystemAvailableCapabilities();
* @version 4
*/
void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap);
/**
* @brief Get bundle size
*
* @param bundleName Indicates the bundle name.
* @return Returns the bundle size if this function is successfully called; returns 0 otherwise.
*
* @since 7
* @version 7
*/
uint32_t GetBundleSize(const char *bundleName);
#ifdef __cplusplus
#if __cplusplus
}
@@ -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<SvcIdentity> GetServiceId() const;
int32_t GenerateUid(const char *bundleName, int8_t bundleStyle);
void RecycleUid(const char *bundleName);
@@ -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];
@@ -625,6 +625,25 @@ uint8_t ManagerService::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos,
return bundleMap_->GetBundleInfos(flags, bundleInfos, len);
}
uint32_t ManagerService::GetBundleSize(const char *bundleName)
{
if (bundleName == nullptr) {
return 0;
}
BundleInfo *installedInfo = bundleMap_->Get(bundleName);
if (installedInfo == nullptr) {
return 0;
}
char *codePath = installedInfo->codePath;
uint32_t codeBundleSize = BundleUtil::GetFileFolderSize(codePath);
if (codeBundleSize == 0) {
return 0;
}
char *dataPath = installedInfo->dataPath;
uint32_t dataBundleSize = BundleUtil::GetFileFolderSize(dataPath);
HILOG_INFO(HILOG_MODULE_APP, "bundle size is %{public}d\n", codeBundleSize + dataBundleSize);
return codeBundleSize + dataBundleSize;
}
std::string ManagerService::GetCodeDirPath() const
{
@@ -42,6 +42,7 @@ static BmsImpl g_bmsImpl = {
.GetBundleInfos = BundleMsFeature::GetBundleInfos,
.QueryKeepAliveBundleInfos = BundleMsFeature::QueryKeepAliveBundleInfos,
.GetBundleNameForUid = BundleMsFeature::GetBundleNameForUid,
.GetBundleSize = BundleMsFeature::GetBundleSize,
IPROXY_END
};
@@ -54,6 +55,7 @@ BundleInvokeType BundleMsFeature::BundleMsInvokeFuc[BMS_INNER_BEGIN] {
HandleGetBundleInfos,
HandleGetBundleInfos,
HasSystemCapability,
GetInnerBundleSize,
GetSystemAvailableCapabilities,
};
@@ -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<char *>(IpcIoPopString(req, &size));
if (bundleName == nullptr) {
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
}
uint32_t bundleSize = GetBundleSize(bundleName);
if (bundleSize == 0) {
return ERR_APPEXECFWK_OBJECT_NULL;
}
IpcIoPushUint8(reply, static_cast<uint8_t>(OHOS_SUCCESS));
IpcIoPushUint32(reply, bundleSize);
return OHOS_SUCCESS;
}
uint8_t BundleMsFeature::HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, IpcIo *reply)
{
if ((req == nullptr) || (reply == nullptr)) {
@@ -427,6 +448,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)) {
+1 -1
View File
@@ -242,7 +242,7 @@ uint32_t BundleUtil::GetCurrentFolderSize(const char *dirPath, List<char *>* lis
continue;
}
if (IsFile(filePath)) {
if (!IsDir(filePath)) {
if (stat(filePath, &buf) != 0 || buf.st_size <= 0) {
fileSize = 0;
break;