diff --git a/interfaces/kits/bundle_lite/appexecfwk_errors.h b/interfaces/kits/bundle_lite/appexecfwk_errors.h index 78c3d95bb0a08222d526db8b0690b21e9b6bf22d..9110f9687f05c396294c1ecc3e92457b694d8f9e 100755 --- a/interfaces/kits/bundle_lite/appexecfwk_errors.h +++ b/interfaces/kits/bundle_lite/appexecfwk_errors.h @@ -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 /** @} */ \ No newline at end of file diff --git a/services/bundlemgr_lite/include/bundle_common.h b/services/bundlemgr_lite/include/bundle_common.h index f3b4b0d520ab8288c588c7003100e82bb9a1baa0..161dca9947121c99cc4f3560aa1c8aebe0fa48bc 100644 --- a/services/bundlemgr_lite/include/bundle_common.h +++ b/services/bundlemgr_lite/include/bundle_common.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; diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index c83c377cad73c967c31a8c55af23ffd6bbd1ee3b..70899cf5cfbbe25075228d4bdf1496a2f46ccb53 100644 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -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(TMP_RESOURCE_DIR), const_cast(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) { diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index b0ad7e276cd46952d869226b1f934be5f28df778..db8770772daa2ffadd8a369308e611edd8d04ea9 100644 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -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(codePath), const_cast(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) { diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index fd9f5da80f8a974a713526742c7dbdd016111bcc..beaea77459effae5c9d46b9c9d8f1851ed21df22 100644 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -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(codePath), const_cast(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) { diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index 6787af8122cfa6b939ac1336366a621b5c4a3da2..5c82938f975b8c2b3c7c16ed629f80851d4a3bda 100644 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -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(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(ASSET_JS_PATH)}; + jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *)); + } else { + char *jsPathComp[] = {bundleInfo->codePath, const_cast(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(ASSETS), relativeIconPath, const_cast(ICON_PNG_NAME) + }; + char *smallIconPngPathComp[] = { + bundleInfo->codePath, const_cast(ASSETS), relativeIconPath, const_cast(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(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(ASSET_JS_PATH)}; + jsPath = BundleUtil::Strscat(jsPathComp, sizeof(jsPathComp) / sizeof(char *)); + } else { + char *jsPathComp[] = {(*bundleInfo)->codePath, const_cast(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)) {