From fa1606b7034f876b037f662c4dcb636eafe4b287 Mon Sep 17 00:00:00 2001 From: tantingting Date: Tue, 20 Aug 2024 20:02:36 +0800 Subject: [PATCH] support continueBundleName Signed-off-by: tantingting --- adapter/ohos/HapVerify.java | 30 ++++++++++++++++++++++++++++++ adapter/ohos/HapVerifyInfo.java | 16 ++++++++++++++++ adapter/ohos/ModuleJsonUtil.java | 28 ++++++++++++++++++++++++++++ modulecheck/module.json | 14 +++++++++++++- 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 35bc7950..fa2a05e4 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 2be4ff24..2d733bd3 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 6086337f..c4ff4249 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 20f2d700..ddfd8bec 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 + } } } } -- Gitee