diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 35bc7950151b24e1a93777ddb85f15f27e47a4a6..fa2a05e4108626658e549f8f9acc91ecde05767c 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -107,6 +107,9 @@ class HapVerify { if (!checkContinueTypeIsValid(hapVerifyInfos)) { return false; } + if (!checkContinueBundleNameIsValid(hapVerifyInfos)) { + return false; + } return true; } @@ -174,6 +177,33 @@ class HapVerify { return true; } + private static boolean checkContinueBundleNameIsValid(List hapVerifyInfos) { + for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { + if (!checkContinueBundleNameIsValid(hapVerifyInfo)) { + return false; + } + } + return true; + } + + private static boolean checkContinueBundleNameIsValid(HapVerifyInfo hapVerifyInfo) { + List abilityNames = hapVerifyInfo.getAbilityNames(); + String bundleName = hapVerifyInfo.getBundleName(); + for (int i = 0; i < abilityNames.size(); i++) { + List bundleNameList = hapVerifyInfo.getContinueBundleNameMap().get(abilityNames.get(i)); + if (bundleNameList == null) { + continue; + } + for (int j = 0; j < bundleNameList.size(); j++) { + if (bundleName.equals(bundleNameList.get(j))) { + LOG.error("HapVerify::checkContinueBundleNameIsValid continue bundle name include self."); + return false; + } + } + } + return true; + } + /** * check inter-app hsp is valid. * diff --git a/adapter/ohos/HapVerifyInfo.java b/adapter/ohos/HapVerifyInfo.java index 2be4ff24fbf954b9dd6b4c74b07e14e21b2f3df2..2d733bd35ba45a72ebf1c7a7ece727e280bf6aa2 100644 --- a/adapter/ohos/HapVerifyInfo.java +++ b/adapter/ohos/HapVerifyInfo.java @@ -139,6 +139,8 @@ class HapVerifyInfo { private Map> continueTypeMap = new HashMap<>(); + private Map> continueBundleNameMap = new HashMap<>(); + private MultiAppMode multiAppMode = new MultiAppMode(); /** @@ -515,6 +517,20 @@ class HapVerifyInfo { this.continueTypeMap = continueTypeMap; } + /** + * get continueBundleName map for HapVerifyInfo. + */ + public Map> getContinueBundleNameMap() { + return continueBundleNameMap; + } + + /** + * set continueBundleName map for HapVerifyInfo. + */ + public void setContinueBundleNameMap(Map> continueBundleNameMap) { + this.continueBundleNameMap = continueBundleNameMap; + } + public MultiAppMode getMultiAppMode() { return multiAppMode; } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 6086337ffb7fee19608a64278dfd00bc217b3d9a..c4ff424917b0bcc46808307e70b48871cef7401d 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -99,6 +99,7 @@ class ModuleJsonUtil { private static final String PROXY_DATA = "proxyData"; private static final String PROXY_URI = "uri"; private static final String CONTINUE_TYPE = "continueType"; + private static final String CONTINUE_BUNDLE_NAME = "continueBundleName"; private static final String MULTI_APP_MODE = "multiAppMode"; private static final String MULTI_APP_MODE_TYPE = "multiAppModeType"; private static final String MULTI_APP_MODE_NUMBER = "maxCount"; @@ -904,6 +905,7 @@ class ModuleJsonUtil { hapVerifyInfo.setCompileSdkVersion(getCompileSdkVersion(hapVerifyInfo.getProfileStr())); hapVerifyInfo.setProxyDataUris(parseProxyDataUri(hapVerifyInfo.getProfileStr())); hapVerifyInfo.setContinueTypeMap(parseAbilityContinueTypeMap(hapVerifyInfo.getProfileStr())); + hapVerifyInfo.setContinueBundleNameMap(parseAbilityContinueBundleNameMap(hapVerifyInfo.getProfileStr())); hapVerifyInfo.setMultiAppMode(parseMultiAppMode(hapVerifyInfo.getProfileStr())); } @@ -1115,6 +1117,32 @@ class ModuleJsonUtil { return continueTypeMap; } + /** + * get ability continueBundleName map from json file. + * + * @param jsonString is the json String of module.json + * @return continueBundleName map + */ + public static Map> parseAbilityContinueBundleNameMap(String jsonString) + throws BundleException { + Map> continueBundleName = new HashMap<>(); + JSONObject moduleObj = getModuleObj(jsonString); + if (moduleObj.containsKey(ABILITIES)) { + JSONArray abilityObjs = moduleObj.getJSONArray(ABILITIES); + for (int i = 0; i < abilityObjs.size(); ++i) { + JSONObject abilityObj = abilityObjs.getJSONObject(i); + String abilityName = getJsonString(abilityObj, NAME); + if (abilityObj.containsKey(CONTINUE_BUNDLE_NAME)) { + JSONArray typeArray = abilityObj.getJSONArray(CONTINUE_BUNDLE_NAME); + continueBundleName.put(abilityName, typeArray.toJavaList(String.class)); + } else { + continueBundleName.put(abilityName, new ArrayList<>()); + } + } + } + return continueBundleName; + } + /** * parse stage ExtensionAbility names * diff --git a/modulecheck/module.json b/modulecheck/module.json index 20f2d700028578a72338a22f2caa67f2b80f919e..ddfd8beca850d5c3dbaa76368ccf451d2c1c71a7 100644 --- a/modulecheck/module.json +++ b/modulecheck/module.json @@ -367,7 +367,8 @@ "excludeFromDock", "preferMultiWindowOrientation", "isolationProcess", - "continueType" + "continueType", + "continueBundleName" ] }, "properties": { @@ -768,6 +769,17 @@ "pattern": "^[a-zA-Z][0-9a-zA-Z_.]*$", "maxLength": 127 } + }, + "continueBundleName": { + "description": "Configure the package names of other applications to be connected.", + "type": "array", + "uniqueItems": true, + "items": { + "type": "string", + "pattern": "^[a-zA-Z][0-9a-zA-Z_.]+$", + "maxLength": 128, + "minLength": 7 + } } } }