mirror of
https://github.com/openharmony/bundlemanager_bundle_framework_lite.git
synced 2026-07-20 23:55:24 -04:00
@@ -49,6 +49,8 @@ public:
|
||||
|
||||
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState) const;
|
||||
|
||||
uint32_t GetBundleSize(const char *bundleName) const;
|
||||
|
||||
private:
|
||||
BundleMsClient() = default;
|
||||
|
||||
|
||||
@@ -28,4 +28,9 @@ bool GetUninstallState(const char *bundleName, UninstallState *uninstallState)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetUninstallState(bundleName, uninstallState);
|
||||
}
|
||||
|
||||
uint32_t GetBundleSize(const char *bundleName)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetBundleSize(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,4 +165,12 @@ bool BundleMsClient::GetUninstallState (const char *bundleName, UninstallState *
|
||||
}
|
||||
return bmsProxy_->GetUninstallState(bundleName, uninstallState);
|
||||
}
|
||||
|
||||
uint32_t BundleMsClient::GetBundleSize (const char *bundleName) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
return -1;
|
||||
}
|
||||
return bmsProxy_->GetBundleSize(bundleName);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -51,6 +51,7 @@ struct BmsSliteInterface {
|
||||
uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
bool (*GetInstallState)(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
bool (*GetUninstallState)(const char *bundleName, UninstallState *uninstallState);
|
||||
uint32_t (*GetBundleSize)(const char *bundleName);
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -68,6 +68,15 @@ bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t
|
||||
*/
|
||||
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
|
||||
|
||||
/**
|
||||
* @brief Get the bundle size.
|
||||
*
|
||||
* @param bundleName Indicates the name of the bundle.
|
||||
* @return Returns bundle size or returns 0 if get bundle size failed.
|
||||
*
|
||||
*/
|
||||
uint32_t GetBundleSize(const char *bundleName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
static bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
static bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
|
||||
static uint32_t GetBundleSize (const char *bundleName);
|
||||
|
||||
static BundleMgrSliteFeature *GetInstance()
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ public:
|
||||
static bool StartWith(const char *str, const char *subStr);
|
||||
static cJSON *GetJsonStream(const char *path);
|
||||
static uint32_t GetFileSize(const char *filePath);
|
||||
static uint32_t GetFileFolderSize(const char *filePath);
|
||||
static uint32_t GetCurrentFolderSize(const char *dirPath, List<char *>* list);
|
||||
static cJSON *ConvertInstallRecordToJson(const InstallRecord &installRecord);
|
||||
static char *GetValueFromBundleJson(const char *bundleName, const char *key);
|
||||
static int32_t GetValueFromBundleJson(const char *bundleName, const char *key, int32_t defaultValue);
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
uint8_t bundleStyle);
|
||||
static char *ExtractHapProfile(int32_t fp, uint32_t totalFileSize);
|
||||
static uint8_t ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName);
|
||||
static bool ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath,
|
||||
static uint8_t ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath,
|
||||
char **bigIconPath);
|
||||
private:
|
||||
static uint8_t ExtractFileDataPos(int32_t fp, uint64_t &filePos);
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
uint8_t process, InstallerCallback installerCallback);
|
||||
bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess);
|
||||
bool GetUninstallState(const char *bundleName, UninstallState *uninstallState);
|
||||
uint32_t GetBundleSize(const char *bundleName);
|
||||
|
||||
private:
|
||||
GtManagerService();
|
||||
|
||||
@@ -34,6 +34,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
|
||||
.GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos,
|
||||
.GetInstallState = BundleMgrSliteFeature::GetInstallState,
|
||||
.GetUninstallState = BundleMgrSliteFeature::GetUninstallState,
|
||||
.GetBundleSize = BundleMgrSliteFeature::GetBundleSize,
|
||||
DEFAULT_IUNKNOWN_ENTRY_END
|
||||
};
|
||||
|
||||
@@ -132,4 +133,9 @@ bool BundleMgrSliteFeature::GetUninstallState(const char *bundleName, UninstallS
|
||||
{
|
||||
return OHOS::GtManagerService::GetInstance().GetUninstallState(bundleName, uninstallState);
|
||||
}
|
||||
|
||||
uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName)
|
||||
{
|
||||
return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -182,6 +182,80 @@ uint32_t BundleUtil::GetFileSize(const char *filePath)
|
||||
return fileInfo.st_size;
|
||||
}
|
||||
|
||||
uint32_t BundleUtil::GetFileFolderSize(const char *filePath)
|
||||
{
|
||||
if (!CheckRealPath(filePath)) {
|
||||
return 0;
|
||||
}
|
||||
List<char *>* list = new (std::nothrow)List<char *>();
|
||||
if (list == nullptr) {
|
||||
#ifdef APP_PLATFORM_WATCHGT
|
||||
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] GetFolderSize failed, list is null");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
list->PushFront(Utils::Strdup(filePath));
|
||||
uint32_t fileFolderSize = 0;
|
||||
while(!list->IsEmpty()) {
|
||||
char *curPath = list->Front();
|
||||
if (curPath == nullptr) {
|
||||
break;
|
||||
}
|
||||
fileFolderSize += GetCurrentFolderSize(curPath, list);
|
||||
list->PopFront();
|
||||
AdapterFree(curPath);
|
||||
}
|
||||
|
||||
if (!list->IsEmpty()) {
|
||||
#ifdef APP_PLATFORM_WATCHGT
|
||||
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] After get folder size, list is still not empty");
|
||||
#endif
|
||||
for (auto node = list->Begin(); node != list->End(); node = node->next_) {
|
||||
AdapterFree(node->value_);
|
||||
}
|
||||
}
|
||||
delete list;
|
||||
return fileFolderSize;
|
||||
}
|
||||
|
||||
uint32_t BundleUtil::GetCurrentFolderSize(const char *dirPath, List<char *>* list)
|
||||
{
|
||||
DIR *dir = nullptr;
|
||||
if ((dir = opendir(dirPath)) == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
dirent *dp = nullptr;
|
||||
char filePath[PATH_LENGTH] = { 0 };
|
||||
struct stat buf = { 0 };
|
||||
uint32_t fileSize = 0;
|
||||
while ((dp = readdir(dir)) != nullptr) {
|
||||
if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..")) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (memset_s(filePath, PATH_LENGTH, 0, PATH_LENGTH) != EOK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sprintf_s(filePath, PATH_LENGTH, "%s/%s", dirPath, dp->d_name) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsFile(filePath)) {
|
||||
if (stat(filePath, &buf) != 0 || buf.st_size <= 0) {
|
||||
fileSize = 0;
|
||||
break;
|
||||
}
|
||||
fileSize += buf.st_size;
|
||||
} else {
|
||||
list->PushBack(Utils::Strdup(filePath));
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
void BundleUtil::DeleteJsonFile(const char *bundleName, const char *randStr)
|
||||
{
|
||||
if (bundleName == nullptr || randStr == nullptr) {
|
||||
|
||||
@@ -179,45 +179,45 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath,
|
||||
uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath,
|
||||
char **bigIconPath)
|
||||
{
|
||||
if (!BundleUtil::CheckRealPath(path)) {
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t totalFileSize = APPVERI_GetUnsignedFileLength(path);
|
||||
if (totalFileSize == V_ERR) {
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
char *emptyJsPathComp[] = {const_cast<char *>(TMP_RESOURCE_DIR), const_cast<char *>(ASSET_JS_PATH)};
|
||||
char *emptyJsPath = BundleUtil::Strscat(emptyJsPathComp, sizeof(emptyJsPathComp) / sizeof(char *));
|
||||
if (emptyJsPath == nullptr) {
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
if (!BundleUtil::MkDirs(emptyJsPath)) {
|
||||
AdapterFree(emptyJsPath);
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR;
|
||||
}
|
||||
AdapterFree(emptyJsPath);
|
||||
|
||||
int32_t fp = open(path, O_RDONLY, S_IREAD | S_IWRITE);
|
||||
if (fp < 0) {
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS;
|
||||
}
|
||||
// extractor config.json、 resources dir and resources.index in TMP_RESOURCE_DIR
|
||||
if (!ExtractResourceFile(TMP_RESOURCE_DIR, fp, static_cast<uint32_t>(totalFileSize))) {
|
||||
close(fp);
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR;
|
||||
}
|
||||
close(fp);
|
||||
// get bundleName、 label、 smallIconPath and bigIconPath from bundleInfo
|
||||
BundleRes bundleRes = { 0 };
|
||||
BundleInfo *bundleInfo = GtBundleParser::ParseHapProfile(TMP_RESOURCE_DIR, &bundleRes);
|
||||
if (bundleInfo == nullptr) {
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR;
|
||||
}
|
||||
if (bundleRes.abilityRes != nullptr) {
|
||||
AdapterFree(bundleRes.abilityRes);
|
||||
@@ -228,10 +228,10 @@ bool GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName, c
|
||||
*bigIconPath = Utils::Strdup(bundleInfo->bigIconPath);
|
||||
if (*bundleName == nullptr || *label == nullptr || *smallIconPath == nullptr || *bigIconPath == nullptr) {
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo);
|
||||
return false;
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR;
|
||||
}
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo);
|
||||
return true;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
uint8_t GtBundleExtractor::ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName)
|
||||
|
||||
@@ -95,20 +95,25 @@ bool GtManagerService::Install(const char *hapPath, const InstallParam *installP
|
||||
return false;
|
||||
}
|
||||
// set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_
|
||||
bool isSuccess = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName),
|
||||
uint8_t ret = GtBundleExtractor::ExtractInstallMsg(path, &(bundleInstallMsg_->bundleName),
|
||||
&(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath),
|
||||
&(bundleInstallMsg_->bigIconPath));
|
||||
if (!isSuccess) {
|
||||
|
||||
if (ret != 0) {
|
||||
char *name = strchr(path, '/');
|
||||
bundleInstallMsg_->bundleName = Utils::Strdup(name + 1);
|
||||
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_FAIL, BMS_INSTALLATION_COMPLETED, installerCallback);
|
||||
// delete resource temp dir
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
ClearSystemBundleInstallMsg();
|
||||
AdapterFree(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCurrentBundle(bundleInstallMsg_->bundleName);
|
||||
(void) ReportInstallCallback(OPERATION_DOING, 0, BMS_INSTALLATION_START, installerCallback);
|
||||
DisableServiceWdg();
|
||||
uint8_t ret = installer_->Install(path, installerCallback);
|
||||
ret = installer_->Install(path, installerCallback);
|
||||
EnableServiceWdg();
|
||||
if (ret == 0) {
|
||||
(void) ReportInstallCallback(ret, BUNDLE_INSTALL_OK, BMS_INSTALLATION_COMPLETED, installerCallback);
|
||||
@@ -198,6 +203,27 @@ bool GtManagerService::GetInstallState(const char *bundleName, InstallState *ins
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t GtManagerService::GetBundleSize(const char *bundleName)
|
||||
{
|
||||
if (bundleName == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
BundleInfo *installedInfo = bundleMap_->Get(bundleName);
|
||||
if (installedInfo == nullptr) {
|
||||
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] failed to get bundle size because the bundle does not exist!");
|
||||
return 0;
|
||||
}
|
||||
char *codePath = installedInfo->codePath;
|
||||
uint32_t codeBundleSize = BundleUtil::GetFileFolderSize(codePath);
|
||||
if (codeBundleSize == 0) {
|
||||
HILOG_ERROR(HILOG_MODULE_AAFWK, "[BMS] failed to get code bundle size!");
|
||||
return 0;
|
||||
}
|
||||
char *dataPath = installedInfo->dataPath;
|
||||
uint32_t dataBundleSize = BundleUtil::GetFileFolderSize(dataPath);
|
||||
return codeBundleSize + dataBundleSize;
|
||||
}
|
||||
|
||||
bool GtManagerService::GetUninstallState(const char *bundleName, UninstallState *uninstallState)
|
||||
{
|
||||
BundleInfo *uninstalledInfo = bundleMap_->Get(bundleName);
|
||||
@@ -290,10 +316,10 @@ void GtManagerService::InstallSystemBundle(const char *systemAppPath)
|
||||
return;
|
||||
}
|
||||
// set bundleName、label、smallIconPath、bigIconPath in bundleInstallMsg_
|
||||
bool ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName),
|
||||
uint8_t ret = GtBundleExtractor::ExtractInstallMsg(systemAppPath, &(bundleInstallMsg_->bundleName),
|
||||
&(bundleInstallMsg_->label), &(bundleInstallMsg_->smallIconPath),
|
||||
&(bundleInstallMsg_->bigIconPath));
|
||||
if (!ret) {
|
||||
if (ret != 0) {
|
||||
// delete resource temp dir
|
||||
(void) BundleUtil::RemoveDir(TMP_RESOURCE_DIR);
|
||||
ClearSystemBundleInstallMsg();
|
||||
|
||||
Reference in New Issue
Block a user