fix problem

Signed-off-by: shilei <shilei91@huawei.com>
Change-Id: I7ecc63a389fe838a5200b94e724d718db3539896
This commit is contained in:
shilei
2023-07-20 12:55:46 +00:00
parent 28c911ee95
commit 4f8072c2e8
6 changed files with 86 additions and 29 deletions
@@ -202,7 +202,7 @@ enum AppexecfwkErrors {
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR,
/** Failed to parse the {@link AbilityInfo}. */
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR,
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR = 60,
/** Failed to parse the class name of the ability. */
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_NAME_ERROR,
@@ -232,7 +232,7 @@ enum AppexecfwkErrors {
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_LABEL_LENGTH_ERROR,
/** The parsed application version name exceeds the maximum length (127 bytes). */
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VERSIONNAME_LENGTH_ERROR,
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VERSIONNAME_LENGTH_ERROR = 70,
/** The parsed application metadata name exceeds the maximum length (255 bytes). */
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_NAME_LENGTH_ERROR,
@@ -262,7 +262,7 @@ enum AppexecfwkErrors {
ERR_APPEXECFWK_INSTALL_FAILED_EXTRACT_HAP_ERROR,
/** Failed to parse the JavaScript path. This error code is available only to basic watches. */
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_JS_DIR_ERROR,
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_JS_DIR_ERROR = 80,
/** The resource index does not exist. */
ERR_APPEXECFWK_INSTALL_FAILED_RESOURCE_INDEX_NOT_EXISTS,
@@ -359,6 +359,9 @@ enum AppexecfwkErrors {
/** The server that invokes the Bundle Manager Service does not have required permission. */
ERR_APPEXECFWK_PERMISSION_DENIED,
/** Failed to parse the source path of the ability. */
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_SRC_PATH_ERROR,
};
#endif // OHOS_APPEXECFWK_ERRORS_H
/** @} */
@@ -103,6 +103,7 @@ const char PROFILE_KEY_MODULE_ABILITY_TYPE[] = "type";
const char PROFILE_KEY_MODULE_ABILITY_LAUNCHTYPE[] = "launchType";
const char PROFILE_KEY_MODULE_ABILITY_VISIBLE[] = "visible";
const char PROFILE_KEY_MODULE_ABILITY_DEVICE_CAP[] = "deviceCapability";
const char PROFILE_KEY_MODULE_ABILITY_SRC_PATH[] = "srcPath";
// js config
const char PROFILE_KEY_JS[] = "js";
@@ -158,8 +159,12 @@ const char JSON_PATH_NO_SLASH_END[] = "user/ace/etc/bundles";
// store bundle permissions for IAM
const char PERMISSIONS_PATH[] = "user/ace/etc/permissions";
const char ASSET_JS_PATH[] = "/assets/js/default";
const char NEW_ASSET_JS_PATH[] = "/assets/js/MainAbility";
const char ASSET_PATH[] = "/assets/js/";
const char ICON_NAME[] = "/icon.bin";
const char SMALL_ICON_NAME[] = "/icon_small.bin";
const char ICON_PNG_NAME[] = "/icon.png.bin";
const char SMALL_ICON_PNG_NAME[] = "/icon_small.png.bin";
const char DEFAULT_ICON_SETTING[] = "$media:icon";
const char INSTALL_FILE_SUFFIX[] = ".bin";
const char TMP_RESOURCE_DIR[] = "user/ace/run/tmpResource";
@@ -231,6 +236,7 @@ struct BundleProfile {
char *vendor;
char *label;
char *iconPath;
char *srcPath = nullptr;
ProfileVersion profileVersion;
ProfileApiVersion profileApiVersion;
ModuleInfo moduleInfo;
@@ -158,7 +158,8 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32
int32_t fileNameLen = strlen(fileName);
if ((strlen(relativeFilePath) == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) ||
!BundleUtil::StartWith(relativeFilePath, ASSET_JS_PATH)) {
(!BundleUtil::StartWith(relativeFilePath, ASSET_JS_PATH) &&
!BundleUtil::StartWith(relativeFilePath, NEW_ASSET_JS_PATH))) {
if (!GtExtractorUtil::HasWrittenFile(path, relativeFilePath, fileName, fp, fileSize)) {
UI_Free(fileName);
UI_Free(relativeFilePath);
@@ -200,17 +201,6 @@ uint8_t GtBundleExtractor::ExtractInstallMsg(const char *path, char **bundleName
#else
int32_t totalFileSize = BundleUtil::GetFileSize(path);
#endif
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 ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
if (!BundleUtil::MkDirs(emptyJsPath)) {
AdapterFree(emptyJsPath);
return ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR;
}
AdapterFree(emptyJsPath);
int32_t fp = open(path, O_RDONLY, S_IREAD);
if (fp < 0) {
@@ -498,6 +498,14 @@ uint8_t GtBundleInstaller::TransformJsToBc(const char *codePath, InstallRecord &
if (jsPath == nullptr) {
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
if (!BundleUtil::IsDir(jsPath)) {
AdapterFree(jsPath);
char *newJsPathComp[] = {const_cast<char *>(codePath), const_cast<char *>(NEW_ASSET_JS_PATH)};
jsPath = BundleUtil::Strscat(newJsPathComp, sizeof(newJsPathComp) / sizeof(char *));
if (jsPath == nullptr) {
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
}
EXECRES result = walk_directory(jsPath);
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] transform js to bc when install, result is %d", result);
if (result != EXCE_ACE_JERRY_EXEC_OK) {
@@ -876,7 +876,14 @@ void GtManagerService::TransformJsToBc(const char *codePath, const char *bundleJ
if (jsPath == nullptr) {
return;
}
if (!BundleUtil::IsDir(jsPath)) {
AdapterFree(jsPath);
char *newJsPathComp[] = {const_cast<char *>(codePath), const_cast<char *>(NEW_ASSET_JS_PATH)};
jsPath = BundleUtil::Strscat(newJsPathComp, sizeof(newJsPathComp) / sizeof(char *));
if (jsPath == nullptr) {
return;
}
}
EXECRES result = walk_directory(jsPath);
HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] transform js to bc, result is %d", result);
if (result != EXCE_ACE_JERRY_EXEC_OK) {
@@ -303,6 +303,11 @@ uint8_t GtBundleParser::ParseAbilityInfo(const cJSON *abilityInfoObjects, Bundle
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_ICONPATH_ERROR;
}
bundleRes.abilityRes->iconId = iconId;
if (cJSON_HasObjectItem(firstAbilityJson, PROFILE_KEY_MODULE_ABILITY_SRC_PATH)) {
bundleProfile.srcPath = ParseValue(firstAbilityJson, PROFILE_KEY_MODULE_ABILITY_SRC_PATH);
CHECK_NULL(bundleProfile.srcPath, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_SRC_PATH_ERROR);
}
return ERR_OK;
}
@@ -409,18 +414,19 @@ BundleInfo *GtBundleParser::CreateBundleInfo(const char *path, const BundleProfi
return nullptr;
}
// get js path
char *jsPathComp[] = {bundleInfo->codePath, const_cast<char *>(ASSET_JS_PATH)};
char *jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
char *jsPath = nullptr;
if (bundleProfile.srcPath == nullptr) {
char *jsPathComp[] = {bundleInfo->codePath, const_cast<char *>(ASSET_JS_PATH)};
jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
} else {
char *jsPathComp[] = {bundleInfo->codePath, const_cast<char *>(ASSET_PATH), bundleProfile.srcPath};
jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
}
if (jsPath == nullptr) {
BundleInfoUtils::FreeBundleInfo(bundleInfo);
return nullptr;
}
if (!BundleUtil::IsDir(jsPath)) {
BundleInfoUtils::FreeBundleInfo(bundleInfo);
AdapterFree(jsPath);
return nullptr;
}
// set abilityInfo
AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = bundleInfo->bundleName};
if (!BundleInfoUtils::SetBundleInfoAbilityInfo(bundleInfo, abilityInfo)) {
@@ -510,17 +516,48 @@ bool GtBundleParser::ConvertIconResToBundleInfo(const char *resPath, uint32_t ic
AdapterFree(bigIconPath);
return false;
}
char *bigIconPngPathComp[] = {
bundleInfo->codePath, const_cast<char *>(ASSETS), relativeIconPath, const_cast<char *>(ICON_PNG_NAME)
};
char *smallIconPngPathComp[] = {
bundleInfo->codePath, const_cast<char *>(ASSETS), relativeIconPath, const_cast<char *>(SMALL_ICON_PNG_NAME)
};
char *bigIconPngPath = BundleUtil::Strscat(bigIconPngPathComp, sizeof(bigIconPngPathComp) / sizeof(char *));
if (bigIconPngPath == nullptr) {
Free(relativeIconPath);
return false;
}
char *smallIconPngPath = BundleUtil::Strscat(smallIconPngPathComp, sizeof(smallIconPngPathComp) / sizeof(char *));
if (smallIconPngPath == nullptr) {
Free(relativeIconPath);
AdapterFree(bigIconPngPath);
return false;
}
Free(relativeIconPath);
if (!BundleUtil::IsFile(bigIconPath) || !BundleUtil::IsFile(smallIconPath)) {
bool isBigIconExisted = BundleUtil::IsFile(bigIconPath);
bool isSmallIconExisted = BundleUtil::IsFile(smallIconPath);
if ((!isBigIconExisted && !BundleUtil::IsFile(bigIconPngPath))||
(!isSmallIconExisted && !BundleUtil::IsFile(smallIconPngPath))) {
AdapterFree(bigIconPath);
AdapterFree(smallIconPath);
AdapterFree(bigIconPngPath);
AdapterFree(smallIconPngPath);
return false;
}
// release bigIconPath and smallIconPath memory in bundleInfo first
AdapterFree(bundleInfo->bigIconPath);
AdapterFree(bundleInfo->smallIconPath);
bundleInfo->bigIconPath = bigIconPath;
bundleInfo->smallIconPath = smallIconPath;
if (isBigIconExisted) {
bundleInfo->bigIconPath = bigIconPath;
} else {
bundleInfo->bigIconPath = bigIconPngPath;
}
if (isSmallIconExisted) {
bundleInfo->smallIconPath = smallIconPath;
} else {
bundleInfo->smallIconPath = smallIconPngPath;
}
return true;
}
@@ -599,14 +636,20 @@ uint8_t GtBundleParser::SaveBundleInfo(const BundleProfile &bundleProfile, const
*bundleInfo = nullptr;
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
char *jsPathComp[] = {(*bundleInfo)->codePath, const_cast<char *>(ASSET_JS_PATH)};
char *jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
char *jsPath = nullptr;
if (bundleProfile.srcPath == nullptr) {
char *jsPathComp[] = {(*bundleInfo)->codePath, const_cast<char *>(ASSET_JS_PATH)};
jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
} else {
char *jsPathComp[] = {(*bundleInfo)->codePath, const_cast<char *>(ASSET_PATH), bundleProfile.srcPath};
jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *));
}
if (jsPath == nullptr) {
BundleInfoUtils::FreeBundleInfo(*bundleInfo);
*bundleInfo = nullptr;
return ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR;
}
AbilityInfo abilityInfo = {.srcPath = jsPath, .bundleName = (*bundleInfo)->bundleName};
// set abilityInfo
if (!BundleInfoUtils::SetBundleInfoAbilityInfo(*bundleInfo, abilityInfo)) {