diff --git a/BUILD.gn b/BUILD.gn index 0e82b411fef7df8a86e48b986094f11741c553e4..6b8d92839e17d7af6b72ea22410cabc25aa5ecb1 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -72,6 +72,7 @@ java_library("hmos_app_unpacking_tool_java") { "adapter/ohos/ScreenWindow.java", "adapter/ohos/CountryCode.java", "adapter/ohos/HapZipInfo.java", + "adapter/ohos/AbilityFormInfo.java", ] deps = [ "//third_party/fastjson/repackaged:fastjson_utils_java" ] diff --git a/adapter/ohos/AbilityFormInfo.java b/adapter/ohos/AbilityFormInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..f9c5662d19621ac4e834641a9a4fc2d828ed9c04 --- /dev/null +++ b/adapter/ohos/AbilityFormInfo.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos; + +import java.util.ArrayList; +import java.util.List; + +/** + * Ability form info. + * + */ +public class AbilityFormInfo { + /** + * Indicates the name of ability form. + */ + public String name = ""; + + /** + * Indicates the type of ability form. + */ + public String type = ""; + + /** + * Indicates whether or not this form is allowed to update periodically. + */ + public boolean updateEnabled = false; + + /** + * Indicates the scheduledUpdateTime of ability form. + */ + public String scheduledUpdateTime = ""; + + /** + * Indicates the update duration, unit: 30 mins. + */ + public int updateDuration = 1; + + /** + * Indicates the supportDimensions of ability form. + */ + public List supportDimensions = new ArrayList(); + + /** + * Indicates the defaultDimension of ability form. + */ + public String defaultDimension = ""; + + /** + * Indicates the metaData of ability form. + */ + public MetaData metaData = new MetaData(); + + /** + * get the customize Data value defined in this ability form. + */ + public String getCustomizeDataValue(String customizeDataName) { + for (CustomizeData data : metaData.customizeDatas) { + if (customizeDataName.equals(data.name)) { + return data.value; + } + } + return ""; + } +} \ No newline at end of file diff --git a/adapter/ohos/AbilityInfo.java b/adapter/ohos/AbilityInfo.java index 8f6a4c4bbc2ac1bef77241dcf05ed4e720b72047..b802c53f80a6fe8d9f0c33dd421f9c5a19248c20 100644 --- a/adapter/ohos/AbilityInfo.java +++ b/adapter/ohos/AbilityInfo.java @@ -167,4 +167,21 @@ public class AbilityInfo { * Indicates the supportPipMode of ability. */ public boolean supportPipMode = false; + + /** + * Indicates the forms of ability. + */ + public List formInfos = new ArrayList(); + + /** + * get the customize Data value defined in this ability. + */ + public String getCustomizeDataValue(String customizeDataName) { + for (CustomizeData data : metaData.customizeDatas) { + if (customizeDataName.equals(data.name)) { + return data.value; + } + } + return ""; + } } \ No newline at end of file diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index cd8b30c7013f0f2cf95f8b990901be30841e6d3d..38ccc10d9395cc7141505f5e882df0edc69852ef 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -100,6 +100,7 @@ public class Compressor { private static final String REGEX_DEVICE_TYPE = "^phone|tablet|car|tv|wearable|liteWearable$"; private static final String REGEX_SCREEN_DENSITY = "^sdpi|mdpi|ldpi|xldpi|xxldpi$"; private static final String REGEX_COLOR_MODE = "^light|dark$"; + private static final String REGEX_SHAPE = "^circle$"; // set timestamp to get fixed MD5 @@ -699,8 +700,16 @@ public class Compressor { return false; } } - String colorMode = thirdLevelDirectoryName.substring(sixthDelimiterIndex + 1, thirdLevelDirectoryName.length()); - return checkColorMode(colorMode); + int seventhDelimiterIndex = thirdLevelDirectoryName.indexOf("-", sixthDelimiterIndex + 1); + if (seventhDelimiterIndex < 0) { + String tmp = thirdLevelDirectoryName.substring(sixthDelimiterIndex + 1, thirdLevelDirectoryName.length()); + return checkColorModeOrShape(tmp); + } + if (!checkColorMode(thirdLevelDirectoryName.substring(sixthDelimiterIndex + 1, seventhDelimiterIndex))) { + return false; + } + String shape = thirdLevelDirectoryName.substring(seventhDelimiterIndex + 1, thirdLevelDirectoryName.length()); + return checkShape(shape); } private boolean checkLanguage(String language) { @@ -763,6 +772,24 @@ public class Compressor { return true; } + private boolean checkColorModeOrShape(String tmp) { + if (Pattern.compile(REGEX_COLOR_MODE).matcher(tmp).matches() || + Pattern.compile(REGEX_SHAPE).matcher(tmp).matches()) { + return true; + } + LOG.error("Compressor::compressProcess " + tmp + + " is neither in colorMode list {light, dark} nor in shape list {circle}"); + return false; + } + + private boolean checkShape(String shape) { + if (Pattern.compile(REGEX_SHAPE).matcher(shape).matches()) { + return true; + } + LOG.error("Compressor::compressProcess shape" + shape + " is not in {circle} list"); + return false; + } + /** * Check whether languageCountryName meets specifications. * diff --git a/adapter/ohos/HapInfo.java b/adapter/ohos/HapInfo.java index 98444b8abfd57b5baab78ce415ef0047eab63388..f3aa258f530cd55a95e0eb6136b6a2a6101baf30 100644 --- a/adapter/ohos/HapInfo.java +++ b/adapter/ohos/HapInfo.java @@ -103,4 +103,15 @@ public class HapInfo { */ public DistroFilter distroFilter = new DistroFilter(); + /** + * get the customize Data value defined in this module. + */ + public String getCustomizeDataValue(String customizeDataName) { + for (CustomizeData data : metaData.customizeDatas) { + if (customizeDataName.equals(data.name)) { + return data.value; + } + } + return ""; + } } diff --git a/adapter/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java index 0a2fedbb09b34acbf00d5b7a7bd37741630ec7c0..19d8914c1bc15f8a90e13ac148aedafd900a818e 100644 --- a/adapter/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -419,7 +419,8 @@ public class JsonUtil { } if (hapJson.containsKey("metaData")) { - hapInfo.metaData = JSONObject.parseObject(getJsonString(hapJson, "metaData"), MetaData.class); + JSONObject metaDataJson = hapJson.getJSONObject("metaData"); + hapInfo.metaData = parseMetaData(metaDataJson); } if (hapJson.containsKey("js")) { @@ -489,6 +490,34 @@ public class JsonUtil { hapInfo.distro = distro; } + /** + * parse meta data + * + * @param metaDataJson meta data json + * @return the parseMetaData result + */ + private static MetaData parseMetaData(JSONObject metaDataJson) { + MetaData metaData = new MetaData(); + if (metaDataJson == null) { + LOG.error("Uncompress::parseMetaData : metaDataJson is null"); + return metaData; + } + + if (metaDataJson.containsKey("parameters")) { + metaData.parameters = JSONObject.parseArray(getJsonString(metaDataJson, "parameters"), + MetaDataInfo.class); + } + if (metaDataJson.containsKey("results")) { + metaData.results = JSONObject.parseArray(getJsonString(metaDataJson, "results"), + MetaDataInfo.class); + } + if (metaDataJson.containsKey("customizeData")) { + metaData.customizeDatas = JSONObject.parseArray(getJsonString(metaDataJson, "customizeData"), + CustomizeData.class); + } + return metaData; + } + /** * parse ability object. * @@ -542,7 +571,8 @@ public class JsonUtil { } if (abilityJson.containsKey("metaData")) { - ability.metaData = JSONObject.parseObject(getJsonString(abilityJson, "metaData"), MetaData.class); + JSONObject metaDataJson = abilityJson.getJSONObject("metaData"); + ability.metaData = parseMetaData(metaDataJson); } if (abilityJson.containsKey("skills")) { @@ -564,6 +594,17 @@ public class JsonUtil { parseAbilityPermissions(abilityJson, ability); + if (abilityJson.containsKey("forms")) { + JSONArray forms = abilityJson.getJSONArray("forms"); + List formList = new ArrayList(); + int formSize = forms.size(); + for (int i = 0; i < formSize; i++) { + JSONObject tmpObj = forms.getJSONObject(i); + formList.add(parseAbilityFormInfo(tmpObj)); + } + ability.formInfos = formList; + } + return ability; } @@ -624,6 +665,38 @@ public class JsonUtil { ability.formInfo = formInfo; } } + /** + * parse ability forms object + * + * @param abilityFormJson ability form json object + * @return the ability form info result + */ + static AbilityFormInfo parseAbilityFormInfo(JSONObject abilityFormJson) { + AbilityFormInfo abilityForm = new AbilityFormInfo(); + if (abilityFormJson == null) { + LOG.error("Uncompress::parseAbilityFormInfo : abilityFormJson is null"); + return abilityForm; + } + abilityForm.name = getJsonString(abilityFormJson, "name"); + abilityForm.type = getJsonString(abilityFormJson, "type"); + if (abilityFormJson.containsKey("updateEnabled")) { + abilityForm.updateEnabled = abilityFormJson.getBoolean("updateEnabled"); + } + abilityForm.scheduledUpdateTime = getJsonString(abilityFormJson, "scheduledUpdateTime"); + if (abilityFormJson.containsKey("updateDuration")) { + abilityForm.updateDuration = abilityFormJson.getIntValue("updateDuration"); + } + if (abilityFormJson.containsKey("supportDimensions")) { + abilityForm.supportDimensions = JSONObject.parseArray(getJsonString(abilityFormJson, "supportDimensions"), + String.class); + } + abilityForm.defaultDimension = getJsonString(abilityFormJson, "defaultDimension"); + if (abilityFormJson.containsKey("metaData")) { + JSONObject metaDataJson = abilityFormJson.getJSONObject("metaData"); + abilityForm.metaData = parseMetaData(metaDataJson); + } + return abilityForm; + } /** * get the String from JSONObject by the key.