diff --git a/adapter/ohos/Distro.java b/adapter/ohos/Distro.java index 67c08baa49b879e8f3215f3f5764d02a7de80321..6f3b4849f90ad14698ec0c0a446a43e4b2d57d3f 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 4824b15944c45afc6486b0f5ba6ce341140d4ec1..34841750ea3d99f1562475a95a0fd63d4b05e506 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 4224d66a5cc21a2d0a420737d2e88cf83c196e62..baa9317ba4d0589876ac3f2c4e355348d87a4992 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; @@ -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); @@ -518,6 +523,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;