diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 72e183cc7ccbc006b13eaf3aff7a6885958ae45e..8b56e5343414bac38333f5d210914008447c7b93 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -133,7 +133,7 @@ public class Compressor { private static final String APP = "app"; private static final String TYPE_APP_PLUGIN = "appPlugin"; private static final String REQUEST_PERMISSIONS = "requestPermissions"; - private static final String PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernal.SUPPORT_PLUGIN"; + private static final String PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernel.SUPPORT_PLUGIN"; private static final String EXTENSION_ABILITIES = "extensionAbilities"; private static final String MODULE = "module"; private static final String GENERATE_BUILD_HASH = "generateBuildHash"; @@ -511,13 +511,14 @@ public class Compressor { if (!TYPE_APP_PLUGIN.equals(bundleType)) { if (!isPluginHost(utility)) { if (!checkPkgContext(utility)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("plugin package packaging failed.")); - throw new BundleException("Compress hsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString( + "plugin package packing failed, the pkgContextInfo.json not exist.")); + throw new BundleException("Compress hap failed."); } } } else { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("hap can not plugin.")); - throw new BundleException("Compress hsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString("hap can not plugin.")); + throw new BundleException("Compress hap failed."); } compressHapModeForModule(utility); buildHash(utility); @@ -531,13 +532,13 @@ public class Compressor { File file = new File(utility.getJsonPath()); if (!file.exists()) { String errMsg = "The --json-path file does not exist."; - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Verify has generate build hash failed for --json-path file does not exist."); } try (InputStream json = new FileInputStream(file)) { JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(MODULE)) { - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("The --json-path file is invalid.")); + LOG.error(PackingToolErrMsg.IS_PLUGIN_HOST_FAILED.toString("The --json-path file is invalid.")); throw new BundleException("Parse --json-path file is invalid."); } JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -546,26 +547,23 @@ public class Compressor { for (int i = 0; i < requestPermissions.size(); ++i) { JSONObject requestPermission = requestPermissions.getJSONObject(i); if (isPermissionSupportPlugin(requestPermission)) { - LOG.error("have permission support plugin."); return false; } } } return true; } catch (IOException e) { - LOG.error(e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "check is plugin host exist IOException: " + e.getMessage())); } return true; } private static boolean isPermissionSupportPlugin(JSONObject requestPermission) throws BundleException { - if (requestPermission.containsKey(NAME)) { - String reqPermissionName = getJsonString(requestPermission, NAME); - if (reqPermissionName == PERMISSION_SUPPORT_PLUGIN) { - return true; - } + String reqPermissionName = getJsonString(requestPermission, NAME); + if (reqPermissionName.equals(PERMISSION_SUPPORT_PLUGIN)) { + return true; } - LOG.error("no have permission support plugin."); return false; } @@ -574,12 +572,12 @@ public class Compressor { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { String errMsg = "--pkg-context-path file must be the pkgContextInfo.json file."; - LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); + LOG.error(PackingToolErrMsg.CHECK_PKG_CONTEXT_FAILED.toString(errMsg)); return false; } return true; } - LOG.error("no have pkgContextInfo.json file."); + LOG.error(PackingToolErrMsg.CHECK_PKG_CONTEXT_FAILED.toString("no have pkgContextInfo.json file.")); return false; } @@ -587,49 +585,51 @@ public class Compressor { File file = new File(utility.getJsonPath()); if (!file.exists()) { String errMsg = "The --json-path file does not exist."; - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString(errMsg)); throw new BundleException("Verify has generate build hash failed for --json-path file does not exist."); } try (InputStream json = new FileInputStream(file)) { JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(MODULE)) { - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("The --json-path file is invalid.")); + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString("The --json-path file is invalid.")); throw new BundleException("Parse --json-path file is invalid."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); String bundleType = ModuleJsonUtil.parseStageBundleType(jsonString); if (!TYPE_APP_PLUGIN.equals(bundleType)) { - LOG.warning("bundleType not appPlugin"); if (isPluginHost(utility)) { return true; } if (!checkPkgContext(utility)) { - LOG.error("checkPkgContext failed."); + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString("checkPkgContext failed.")); return false; } return true; } JSONObject moduleJson = jsonObject.getJSONObject(MODULE); JSONArray extensionAbilityJsonList = moduleJson.getJSONArray(EXTENSION_ABILITIES); - for (int j = 0; j < extensionAbilityJsonList.size(); j++) { - JSONObject extensionAbilityJson = extensionAbilityJsonList.getJSONObject(j); - if (extensionAbilityJson != null) { - LOG.error("extensionAbilities is not null."); - return false; + if (extensionAbilityJsonList != null) { + for (int j = 0; j < extensionAbilityJsonList.size(); j++) { + JSONObject extensionAbilityJson = extensionAbilityJsonList.getJSONObject(j); + if (extensionAbilityJson != null) { + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString("extensionAbilities is not null.")); + return false; + } } } if (!checkPkgContext(utility)) { - LOG.error("checkPkgContext failed."); + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString("checkPkgContext failed.")); return false; } if (!isPluginHost(utility)) { - LOG.error("plugin package cannot be the host."); + LOG.error(PackingToolErrMsg.CHECK_APP_PLUGIN_FAILED.toString("plugin package cannot be the host.")); return false; } return true; } catch (IOException e) { - LOG.error(e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "check app plugin exist IOException: " + e.getMessage())); } return true; } diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 18c40da2fb65716e63c33c4ff32a9834a4809c83..159a7fad68522e3999cf433eac635c5edbd56f8f 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -774,6 +774,46 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * IS_PLUGIN_HOST_FAILED + */ + public static final ErrorMsg IS_PLUGIN_HOST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("050") + .setDescription("Check is plugin host failed.") + .setCause("%s") + .build(); + + /** + * IS_PERMISSION_SUPPORT_PLUGIN_FAILED + */ + public static final ErrorMsg IS_PERMISSION_SUPPORT_PLUGIN_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("051") + .setDescription("Check is permission support plugin failed.") + .setCause("%s") + .build(); + + /** + * CHECK_PKG_CONTEXT_FAILED + */ + public static final ErrorMsg CHECK_PKG_CONTEXT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("052") + .setDescription("Check pkg context failed.") + .setCause("%s") + .build(); + + /** + * CHECK_APP_PLUGIN_FAILED + */ + public static final ErrorMsg CHECK_APP_PLUGIN_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("053") + .setDescription("Check app plugin failed.") + .setCause("%s") + .build(); + // module json check error /** * PARSE_JSON_OBJECT_EXCEPTION diff --git a/packing_tool/frameworks/include/hsp_packager.h b/packing_tool/frameworks/include/hsp_packager.h index e54103981739d620ac7d702ac0acf102f39efe2b..3400085f2ca27be4724b83e3d0a8340582dff874 100644 --- a/packing_tool/frameworks/include/hsp_packager.h +++ b/packing_tool/frameworks/include/hsp_packager.h @@ -47,6 +47,7 @@ public: bool IsPluginHost(); bool IsPermissionSupportPlugin(std::unique_ptr& requestPermissionsObj); bool CheckPkgContext(); + bool IsExtensionAbility(std::unique_ptr& extensionAbilitiesObj); protected: int32_t InitAllowedParam() override; diff --git a/packing_tool/frameworks/src/hap_packager.cpp b/packing_tool/frameworks/src/hap_packager.cpp index 6f5d50f89f9d891413308496c7f0740733ed1177..323f9f2c251ee0ea00fe2411e3786ed94ad581cd 100644 --- a/packing_tool/frameworks/src/hap_packager.cpp +++ b/packing_tool/frameworks/src/hap_packager.cpp @@ -26,7 +26,7 @@ namespace AppPackingTool { namespace { const std::string NAME = "name"; const std::string REQUEST_PERMISSIONS = "requestPermissions"; -const std::string PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernal.SUPPORT_PLUGIN"; +const std::string PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernel.SUPPORT_PLUGIN"; } HapPackager::HapPackager(const std::map ¶meterMap, std::string &resultReceiver) : Packager(parameterMap, resultReceiver) @@ -392,7 +392,6 @@ bool HapPackager::IsPermissionSupportPlugin(std::unique_ptr& requestPerm } } } - LOGE("no have permission support plugin."); return false; } diff --git a/packing_tool/frameworks/src/hsp_packager.cpp b/packing_tool/frameworks/src/hsp_packager.cpp index 4ff627be3b82b97bac84b0948d3bd4f046185ab8..652857d436f228aa057b59ab7a44eb8c0efeb18b 100644 --- a/packing_tool/frameworks/src/hsp_packager.cpp +++ b/packing_tool/frameworks/src/hsp_packager.cpp @@ -27,7 +27,7 @@ namespace { const std::string NAME = "name"; const std::string EXTENSION_ABILITIES = "extensionAbilities"; const std::string REQUEST_PERMISSIONS = "requestPermissions"; -const std::string PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernal.SUPPORT_PLUGIN"; +const std::string PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernel.SUPPORT_PLUGIN"; } HspPackager::HspPackager(const std::map ¶meterMap, std::string &resultReceiver) : Packager(parameterMap, resultReceiver) @@ -302,7 +302,6 @@ bool HspPackager::CheckAppPlugin() return true; } if (Constants::TYPE_APP_PLUGIN != bundleType) { - LOGW("bundleType not appPlugin"); if (IsPluginHost()) { return true; } @@ -310,6 +309,7 @@ bool HspPackager::CheckAppPlugin() LOGE("CheckPkgContext failed."); return false; } + return true; } std::unique_ptr moduleObj; if (!moduleJson_.GetModuleObject(moduleObj)) { @@ -322,8 +322,10 @@ bool HspPackager::CheckAppPlugin() LOGW("Module node get %s array node failed!", EXTENSION_ABILITIES.c_str()); } if (extensionAbilitiesObj) { - LOGE("extendAbilities of plugin package must empty"); - return false; + if (!IsExtensionAbility(extensionAbilitiesObj)) { + LOGE("IsExtensionAbility failed."); + return false; + } } } if (!CheckPkgContext()) { @@ -341,8 +343,7 @@ bool HspPackager::CheckAppPlugin() return false; } } - LOGE("plugin package packaging failed."); - return false; + return true; } bool HspPackager::IsPluginHost() @@ -366,8 +367,27 @@ bool HspPackager::IsPluginHost() return true; } +bool HspPackager::IsExtensionAbility(std::unique_ptr& extensionAbilitiesObj) +{ + for (int32_t i = 0; i < extensionAbilitiesObj->GetSize(); i++) { + std::unique_ptr extensionAbilityObj = extensionAbilitiesObj->Get(i); + if (extensionAbilityObj->Contains(NAME.c_str())) { + std::string extensionAbilityName; + if (extensionAbilityObj->GetString(NAME.c_str(), &extensionAbilityName) == Result::SUCCESS) { + LOGE("extendAbilities of plugin package must empty"); + return false; + } + } + } + return true; +} + bool HspPackager::IsPermissionSupportPlugin(std::unique_ptr& requestPermissionsObj) { + if (requestPermissionsObj == nullptr) { + LOGE("requestPermissionsObj nullptr!"); + return false; + } for (int32_t i = 0; i < requestPermissionsObj->GetSize(); i++) { std::unique_ptr requestPermissionObj = requestPermissionsObj->Get(i); if (requestPermissionObj->Contains(NAME.c_str())) {