From 0b4d65b98525b6b86da4758cd44dd354e0230324 Mon Sep 17 00:00:00 2001 From: yuanneng Date: Sat, 27 Nov 2021 17:18:33 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:#I4K3GJ=20Description:parsehap=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BB=8Epack.info=E8=8E=B7=E5=8F=96deviceType=20Sig:a?= =?UTF-8?q?afwk=20Feature=20or=20Bugfix:=20Bugfig=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fenghao --- adapter/ohos/JsonUtil.java | 42 ++++++++++++++++++++++++++++++++++-- adapter/ohos/Uncompress.java | 2 +- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/adapter/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java index 35de49de..0a2fedbb 100644 --- a/adapter/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -132,17 +132,54 @@ public class JsonUtil { return true; } + private static void parseDeviceTypeToHapInfo(String packInfoJsonStr, HapInfo hapInfo, String hapName) { + LOG.info("Uncompress::parseDeviceTypeToHapInfo: begin"); + JSONObject jsonObject = JSONObject.parseObject(packInfoJsonStr); + if (jsonObject == null || !jsonObject.containsKey("packages")) { + LOG.error("Uncompress::parseDeviceTypeToHapInfo error: no packages"); + return; + } + JSONArray jsonList = JSONArray.parseArray(getJsonString(jsonObject, "packages")); + if (jsonList == null) { + LOG.error("Uncompress::parseDeviceTypeToHapInfo error: packages is null"); + return; + } + + for (int i = 0; i < jsonList.size(); i++) { + JSONObject tmpObj = jsonList.getJSONObject(i); + if (tmpObj == null) { + LOG.error("Uncompress::parseDeviceTypeToHapInfo error: obj is null"); + continue; + } + String name = getJsonString(tmpObj, NAME); + if (name != null && name.equals(hapName)) { + String deviceTypes = getJsonString(tmpObj, DEVICE_TYPE_NEW); + if (deviceTypes == null || deviceTypes.isEmpty()) { + deviceTypes = getJsonString(tmpObj, DEVICE_TYPE); + } + if (deviceTypes != null && !deviceTypes.isEmpty()) { + hapInfo.deviceType = JSONArray.parseArray(deviceTypes + .replace(UncompressEntrance.DEVICE_TYPE_DEFAULT, UncompressEntrance.DEVICE_TYPE_PHONE), + String.class); + } + break; + } + } + return; + } + /** * parse hap profile info * * @param harmonyProfileJsonString uncompress json String * @param data resource index data * @param paclInfoJsonString pack.info json String + * @param hapName hap file name * @return the parseProfileInfo result * @throws BundleException Throws this exception if the json is not standard. */ - static ProfileInfo parseProfileInfo(String harmonyProfileJsonString, byte[] data, String paclInfoJsonString) - throws BundleException { + static ProfileInfo parseProfileInfo(String harmonyProfileJsonString, byte[] data, String paclInfoJsonString, + String hapName) throws BundleException { ProfileInfo profileInfo = new ProfileInfo(); JSONObject jsonObject = JSONObject.parseObject(harmonyProfileJsonString); if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey("deviceConfig") @@ -158,6 +195,7 @@ public class JsonUtil { JSONObject hapJson = jsonObject.getJSONObject("module"); profileInfo.hapInfo = parseHapInfo(hapJson, data); } + parseDeviceTypeToHapInfo(paclInfoJsonString, profileInfo.hapInfo, hapName); if (jsonObject.containsKey("deviceConfig")) { JSONObject deviceConfigJson = jsonObject.getJSONObject("deviceConfig"); profileInfo.deviceConfig = parseDeviceConfigInfo(deviceConfigJson, profileInfo.hapInfo.deviceType); diff --git a/adapter/ohos/Uncompress.java b/adapter/ohos/Uncompress.java index bd3d5d3e..1634114e 100644 --- a/adapter/ohos/Uncompress.java +++ b/adapter/ohos/Uncompress.java @@ -666,7 +666,7 @@ public class Uncompress { private static void uncompressProfileInfo(HapZipInfo hapZipInfo, UncomperssResult uncomperssResult) throws BundleException { ProfileInfo profileInfo = JsonUtil.parseProfileInfo(hapZipInfo.getHarmonyProfileJsonStr(), - hapZipInfo.getResDataBytes(), hapZipInfo.getPackInfoJsonStr()); + hapZipInfo.getResDataBytes(), hapZipInfo.getPackInfoJsonStr(), hapZipInfo.getHapFileName()); profileInfo.hapName = hapZipInfo.getHapFileName(); uncomperssResult.addProfileInfoStr(hapZipInfo.getHarmonyProfileJsonStr()); uncomperssResult.addProfileInfo(profileInfo); -- Gitee