From cc03bceb8e7513c49e4c7df7efdc40c36ceb8324 Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Fri, 20 Aug 2021 17:40:27 +0800 Subject: [PATCH 1/2] IssueNo:#I46KJV Description:add packtools code to master Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia Change-Id: I9b7c864347c2fdc3d4f949043c0932446d681235 --- adapter/ohos/Distro.java | 5 +++++ adapter/ohos/JsonUtil.java | 5 +++++ adapter/ohos/Uncompress.java | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/adapter/ohos/Distro.java b/adapter/ohos/Distro.java index 67c08baa..6f3b4849 100644 --- a/adapter/ohos/Distro.java +++ b/adapter/ohos/Distro.java @@ -39,4 +39,9 @@ public class Distro { * Indicates the installationFree of Distro. */ public int installationFree = 2; + + /** + * Indicates the virtualMachine of Distro. + */ + public String virtualMachine = "default"; } \ No newline at end of file diff --git a/adapter/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java index 4824b159..34841750 100644 --- a/adapter/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -428,6 +428,11 @@ public class JsonUtil { } else { distro.installationFree = 2; } + if (distroObj.containsKey("virtualMachine")) { + distro.virtualMachine = getJsonString(distroObj, "virtualMachine"); + } else { + distro.virtualMachine = "default"; + } hapInfo.distro = distro; } diff --git a/adapter/ohos/Uncompress.java b/adapter/ohos/Uncompress.java index 4224d66a..ffbef2d1 100644 --- a/adapter/ohos/Uncompress.java +++ b/adapter/ohos/Uncompress.java @@ -103,7 +103,7 @@ public class Uncompress { } else if (Utility.MODE_HAR.equals(utility.getMode())) { dataTransferAllFiles(utility.getHarPath(), utility.getOutPath()); } else { - dataTransferAllFiles(utility.getAppPath(), utility.getOutPath()); + dataTransferFilesByApp(utility, utility.getAppPath(), utility.getOutPath()); } } catch (BundleException ignored) { unpackageResult = false; @@ -518,6 +518,45 @@ public class Uncompress { } } + private static void dataTransferFilesByApp(Utility utility, String srcPath, String destDirPath) + throws BundleException { + ZipFile zipFile = null; + try { + zipFile = new ZipFile(new File(srcPath)); + int entriesNum = 0; + for (Enumeration entries = zipFile.entries(); entries.hasMoreElements(); ) { + entriesNum++; + ZipEntry entry = entries.nextElement(); + if (entry == null) { + continue; + } + String filePath = destDirPath + LINUX_FILE_SEPARATOR + entry.getName(); + File destFile = new File(filePath); + if (destFile != null && destFile.getParentFile() != null && !destFile.getParentFile().exists()) { + destFile.getParentFile().mkdirs(); + } + boolean isUnpackApk = "true".equals(utility.getUnpackApk()); + if (isUnpackApk && filePath.toLowerCase().endsWith(HAP_SUFFIX)) { + dataTransfer(zipFile, entry, destFile); + unzip(utility, filePath, destDirPath, APK_SUFFIX); + String[] temp = filePath.replace("\\", "/").split("/"); + String hapName = temp[temp.length - 1]; + repackHap(filePath, destDirPath, hapName, utility.getUnpackApk()); + } else { + dataTransfer(zipFile, entry, destFile); + } + } + } catch (FileNotFoundException ignored) { + LOG.error("Uncompress::unzipApk file not found exception"); + throw new BundleException("Unzip Apk failed"); + } catch (IOException exception) { + LOG.error("Uncompress::unzipApk io exception: " + exception.getMessage()); + throw new BundleException("Unzip Apk failed"); + } finally { + Utility.closeStream(zipFile); + } + } + private static byte[] getResourceDataFromHap(ZipFile zipFile) throws BundleException, IOException { int entriesNum = 0; InputStream indexInputStream = null; -- Gitee From 1a40c82d7908274ed02e07b753dfad182b58f100 Mon Sep 17 00:00:00 2001 From: "fenghao (P)" Date: Sat, 21 Aug 2021 15:37:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?IssueNo:#I46N5X=20Description:=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E7=9B=AE=E5=BD=95=E4=B8=8B=E5=8C=85=E5=90=ABapk?= =?UTF-8?q?=E7=9A=84hap=E5=8C=85=E6=8B=86=E5=8C=85=E5=A4=B1=E8=B4=A5=20Sig?= =?UTF-8?q?:aafwk=20Feature=20or=20Bugfix:=20Bugfig=20Binary=20Source:=20N?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fenghao (P) --- adapter/ohos/Uncompress.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/adapter/ohos/Uncompress.java b/adapter/ohos/Uncompress.java index ffbef2d1..baa9317b 100644 --- a/adapter/ohos/Uncompress.java +++ b/adapter/ohos/Uncompress.java @@ -313,12 +313,12 @@ public class Uncompress { entriesNum++; ZipEntry entry = entries.nextElement(); String entryName = ""; - if (entry == null || entry.getName().isEmpty()) { - continue; - } + if (entry == null || entry.getName().isEmpty()) { + continue; + } if (entry.getName().toLowerCase().endsWith(CUT_ENTRY_FILENAME) && - "false".equals(utility.getUnpackCutEntryApk())) { - continue; + "false".equals(utility.getUnpackCutEntryApk())) { + continue; } entryName = entry.getName(); if (!entryName.toLowerCase(Locale.ENGLISH).endsWith(suffix) || @@ -333,6 +333,11 @@ public class Uncompress { destFileDir.mkdir(); } } + if (APK_SUFFIX.equals(suffix) && "true".equals(utility.getUnpackApk()) + && entryName.contains(LINUX_FILE_SEPARATOR)) { + // only unpack shell apk which in the root directory + continue; + } String tempPath = tempDir + LINUX_FILE_SEPARATOR + entryName; File destFile = new File(tempPath); dataTransfer(zipFile, entry, destFile); -- Gitee