From ac0e59cb9369b53a3de77b5f3db3f292c8e00a26 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Fri, 22 Nov 2024 09:59:04 +0800 Subject: [PATCH 1/2] fix packingTool Signed-off-by: sunjiakun --- adapter/ohos/Compressor.java | 7 +++++ adapter/ohos/HapVerify.java | 50 ++++++++++++++++++++++++++------- adapter/ohos/HapVerifyInfo.java | 10 +++++++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index c66abb09..82e91512 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -2894,6 +2894,13 @@ public class Compressor { hapVerifyInfo.setStageModule(true); ModuleJsonUtil.parseStageHapVerifyInfo(hapVerifyInfo); hapVerifyInfo.setFileLength(FileUtils.getFileSize(filePath)); + File srcFile = new File(filePath); + String fileStr = srcFile.getName(); + if (fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { + hapVerifyInfo.setFileType(HAP_SUFFIX); + } else if (fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { + hapVerifyInfo.setFileType(HSP_SUFFIX); + } return hapVerifyInfo; } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 35bc7950..c07e2237 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -46,6 +46,8 @@ class HapVerify { private static final long FILE_LENGTH_1M = 1024 * 1024L; private static final double FILE_SIZE_OFFSET_DOUBLE = 0.01d; private static final int FILE_SIZE_DECIMAL_PRECISION = 2; + private static final String HAP_SUFFIX = ".hap"; + private static final String HSP_SUFFIX = ".hsp"; /** * check hap is verify. @@ -231,15 +233,16 @@ class HapVerify { if (optional.isPresent()) { verifyInfo = optional.get(); } + List hapList = new ArrayList<>(); + int hspMinCompatibleVersionCodeMax = -1; + int hspTargetApiVersionMax = -1; VerifyCollection verifyCollection = new VerifyCollection(); verifyCollection.bundleName = verifyInfo.getBundleName(); verifyCollection.setBundleType(verifyInfo.getBundleType()); verifyCollection.vendor = verifyInfo.getVendor(); verifyCollection.versionCode = verifyInfo.getVersion().versionCode; verifyCollection.versionName = verifyInfo.getVersion().versionName; - verifyCollection.minCompatibleVersionCode = verifyInfo.getVersion().minCompatibleVersionCode; verifyCollection.compatibleApiVersion = verifyInfo.getApiVersion().getCompatibleApiVersion(); - verifyCollection.targetApiVersion = verifyInfo.getApiVersion().getTargetApiVersion(); verifyCollection.releaseType = verifyInfo.getApiVersion().getReleaseType(); verifyCollection.targetBundleName = verifyInfo.getTargetBundleName(); verifyCollection.targetPriority = verifyInfo.getTargetPriority(); @@ -253,6 +256,41 @@ class HapVerify { hapVerifyInfo.getModuleName() + ") has different values."); return false; } + if (hapVerifyInfo.getFileType() == HAP_SUFFIX) { + hapList.add(hapVerifyInfo); + } else if (hapVerifyInfo.getFileType() == HSP_SUFFIX) { + if (hapVerifyInfo.getVersion().minCompatibleVersionCode > hspMinCompatibleVersionCodeMax) { + hspMinCompatibleVersionCodeMax = hapVerifyInfo.getVersion().minCompatibleVersionCode; + } + if (hapVerifyInfo.getApiVersion().getTargetApiVersion() > hspTargetApiVersionMax) { + hspTargetApiVersionMax = hapVerifyInfo.getApiVersion().getTargetApiVersion(); + } + } + } + if (!appFieldsIsValid(hapList, hspMinCompatibleVersionCodeMax, hspTargetApiVersionMax)) { + return false; + } + return true; + } + + private static boolean appFieldsIsValid(List hapVerifyInfos, int minCompatibleVersionCode, + int targetApiVersion) { + if (hapVerifyInfos.isEmpty()) { + LOG.warning("hapList empty"); + return true; + } + HapVerifyInfo hap = hapVerifyInfos.get(0); + for (HapVerifyInfo hapInfo : hapVerifyInfos) { + if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || + hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { + LOG.error("hap minCompatibleVersionCode or targetApiVersion different"); + return false; + } + } + if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || + hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { + LOG.error("minCompatibleVersionCode or targetApiVersion property hap less than hsp"); + return false; } return true; } @@ -271,18 +309,10 @@ class HapVerify { LOG.error("input module versionCode is different."); return false; } - if (verifyCollection.minCompatibleVersionCode != hapVerifyInfo.getVersion().minCompatibleVersionCode) { - LOG.error("input module minCompatibleVersionCode is different."); - return false; - } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { LOG.error("input module minApiVersion is different."); return false; } - if (verifyCollection.targetApiVersion != hapVerifyInfo.getApiVersion().getTargetApiVersion()) { - LOG.error("input module targetApiVersion is different."); - return false; - } if (!verifyCollection.releaseType.equals(hapVerifyInfo.getApiVersion().getReleaseType())) { if (verifyCollection.getModuleType().equals(TYPE_SHARED) || hapVerifyInfo.getModuleType().equals(TYPE_SHARED)) { diff --git a/adapter/ohos/HapVerifyInfo.java b/adapter/ohos/HapVerifyInfo.java index 2be4ff24..a962f7da 100644 --- a/adapter/ohos/HapVerifyInfo.java +++ b/adapter/ohos/HapVerifyInfo.java @@ -141,6 +141,8 @@ class HapVerifyInfo { private MultiAppMode multiAppMode = new MultiAppMode(); + private String fileType = ""; + /** * get bundle name form HapVerifyInfo. */ @@ -522,4 +524,12 @@ class HapVerifyInfo { public void setMultiAppMode(MultiAppMode multiAppMode) { this.multiAppMode = multiAppMode; } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } } -- Gitee From f89f0a324d0c79a44e8cc28c1e211ced678570d1 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Thu, 12 Dec 2024 11:23:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20deoc=20=EF=BC=88cherry=20picked=20com?= =?UTF-8?q?mit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjiakun --- README_zh.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README_zh.md b/README_zh.md index 6a1cded1..fda40b72 100644 --- a/README_zh.md +++ b/README_zh.md @@ -98,6 +98,7 @@ java -jar app_packing_tool.jar --mode app --hap-path