diff --git a/BUILD.gn b/BUILD.gn index 42c162213bdb2cde7f7fa1a463f0fa75ea7249d0..0e82b411fef7df8a86e48b986094f11741c553e4 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,15 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved. +# 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. import("//build/config/ohos/rules.gni") import("//build/ohos.gni") @@ -6,101 +17,101 @@ import("//developtools/developtools.gni") java_library("hmos_app_packing_tool_java") { java_files = [ - "com/huawei/ohos/BundleException.java", - "com/huawei/ohos/CommandParser.java", - "com/huawei/ohos/CompressEntrance.java", - "com/huawei/ohos/Compressor.java", - "com/huawei/ohos/CompressVerify.java", - "com/huawei/ohos/Log.java", - "com/huawei/ohos/ShowHelp.java", - "com/huawei/ohos/Utility.java", + "adapter/ohos/BundleException.java", + "adapter/ohos/CommandParser.java", + "adapter/ohos/CompressEntrance.java", + "adapter/ohos/Compressor.java", + "adapter/ohos/CompressVerify.java", + "adapter/ohos/Log.java", + "adapter/ohos/ShowHelp.java", + "adapter/ohos/Utility.java", ] - main_class = "com.huawei.ohos.CompressEntrance" + main_class = "ohos.CompressEntrance" final_jar_path = "$root_build_dir/developtools/hmos_app_packing_tool.jar" } java_library("hmos_app_unpacking_tool_java") { java_files = [ - "com/huawei/ohos/BundleException.java", - "com/huawei/ohos/CommandParser.java", - "com/huawei/ohos/Log.java", - "com/huawei/ohos/ShowHelp.java", - "com/huawei/ohos/UncompressEntrance.java", - "com/huawei/ohos/Uncompress.java", - "com/huawei/ohos/UncompressVerify.java", - "com/huawei/ohos/Utility.java", - "com/huawei/ohos/HapInfo.java", - "com/huawei/ohos/ReqPermission.java", - "com/huawei/ohos/Distro.java", - "com/huawei/ohos/AbilityInfo.java", - "com/huawei/ohos/MetaData.java", - "com/huawei/ohos/MetaDataInfo.java", - "com/huawei/ohos/SkillInfo.java", - "com/huawei/ohos/UsedScene.java", - "com/huawei/ohos/PackInfo.java", - "com/huawei/ohos/FormInfo.java", - "com/huawei/ohos/ProfileInfo.java", - "com/huawei/ohos/AppInfo.java", - "com/huawei/ohos/DefPermission.java", - "com/huawei/ohos/DefPermissionGroup.java", - "com/huawei/ohos/CustomizeData.java", - "com/huawei/ohos/UncomperssResult.java", - "com/huawei/ohos/JsonUtil.java", - "com/huawei/ohos/JsInfo.java", - "com/huawei/ohos/DeviceConfig.java", - "com/huawei/ohos/CommonEvent.java", - "com/huawei/ohos/Shortcut.java", - "com/huawei/ohos/IntentInfo.java", - "com/huawei/ohos/ResourcesParser.java", - "com/huawei/ohos/DistroFilter.java", - "com/huawei/ohos/ApiVersion.java", - "com/huawei/ohos/ScreenShape.java", - "com/huawei/ohos/ScreenDensity.java", - "com/huawei/ohos/ScreenWindow.java", - "com/huawei/ohos/CountryCode.java", - "com/huawei/ohos/HapZipInfo.java", + "adapter/ohos/BundleException.java", + "adapter/ohos/CommandParser.java", + "adapter/ohos/Log.java", + "adapter/ohos/ShowHelp.java", + "adapter/ohos/UncompressEntrance.java", + "adapter/ohos/Uncompress.java", + "adapter/ohos/UncompressVerify.java", + "adapter/ohos/Utility.java", + "adapter/ohos/HapInfo.java", + "adapter/ohos/ReqPermission.java", + "adapter/ohos/Distro.java", + "adapter/ohos/AbilityInfo.java", + "adapter/ohos/MetaData.java", + "adapter/ohos/MetaDataInfo.java", + "adapter/ohos/SkillInfo.java", + "adapter/ohos/UsedScene.java", + "adapter/ohos/PackInfo.java", + "adapter/ohos/FormInfo.java", + "adapter/ohos/ProfileInfo.java", + "adapter/ohos/AppInfo.java", + "adapter/ohos/DefPermission.java", + "adapter/ohos/DefPermissionGroup.java", + "adapter/ohos/CustomizeData.java", + "adapter/ohos/UncomperssResult.java", + "adapter/ohos/JsonUtil.java", + "adapter/ohos/JsInfo.java", + "adapter/ohos/DeviceConfig.java", + "adapter/ohos/CommonEvent.java", + "adapter/ohos/Shortcut.java", + "adapter/ohos/IntentInfo.java", + "adapter/ohos/ResourcesParser.java", + "adapter/ohos/DistroFilter.java", + "adapter/ohos/ApiVersion.java", + "adapter/ohos/ScreenShape.java", + "adapter/ohos/ScreenDensity.java", + "adapter/ohos/ScreenWindow.java", + "adapter/ohos/CountryCode.java", + "adapter/ohos/HapZipInfo.java", ] deps = [ "//third_party/fastjson/repackaged:fastjson_utils_java" ] java_manifest_file = "META-INF/unpacking_tool/MANIFEST.MF" - main_class = "com.huawei.ohos.UncompressEntrance" + main_class = "ohos.UncompressEntrance" final_jar_path = "$root_build_dir/developtools/hmos_app_unpacking_tool.jar" } java_library("hmos_haptobin_tool_java") { java_files = [ - "com/huawei/ohos/Log.java", - "com/huawei/ohos/BinaryTool.java", - "com/huawei/ohos/FileUtils.java", - "com/huawei/ohos/ConvertHapToBin.java", + "adapter/ohos/Log.java", + "adapter/ohos/BinaryTool.java", + "adapter/ohos/FileUtils.java", + "adapter/ohos/ConvertHapToBin.java", ] deps = [ "//third_party/fastjson/repackaged:fastjson_utils_java" ] java_manifest_file = "META-INF/packingbin_tool/MANIFEST.MF" - main_class = "com.huawei.ohos.ConvertHapToBin" + main_class = "ohos.ConvertHapToBin" final_jar_path = "$root_build_dir/developtools/hmos_haptobin_tool.jar" } java_library("hmos_bininfo_collecting_tool_java") { java_files = [ - "com/huawei/ohos/Log.java", - "com/huawei/ohos/FileUtils.java", - "com/huawei/ohos/CollectBinInfo.java", + "adapter/ohos/Log.java", + "adapter/ohos/FileUtils.java", + "adapter/ohos/CollectBinInfo.java", ] deps = [ "//third_party/fastjson/repackaged:fastjson_utils_java" ] java_manifest_file = "META-INF/collectingbininfo_tool/MANIFEST.MF" - main_class = "com.huawei.ohos.CollectBinInfo" + main_class = "ohos.CollectBinInfo" final_jar_path = "$root_build_dir/developtools/hmos_bininfo_collecting_tool.jar" diff --git a/META-INF/collectingbininfo_tool/MANIFEST.MF b/META-INF/collectingbininfo_tool/MANIFEST.MF index d1bcbf7af34a7dd1ef597b51106e75c99e48663e..ddac4c8b9f0bba529dfb1ba82ca5b6537792d4e8 100755 --- a/META-INF/collectingbininfo_tool/MANIFEST.MF +++ b/META-INF/collectingbininfo_tool/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 Created-By: javac.py Class-Path: fastjson_utils_java.jar -Main-Class: com.huawei.ohos.CollectBinInfo +Main-Class: ohos.CollectBinInfo diff --git a/META-INF/packingbin_tool/MANIFEST.MF b/META-INF/packingbin_tool/MANIFEST.MF index 982fa546abf6988c3523c7c20ed8292c4950f81d..0ad86f5f14b003cfcad29d7ea2049fc543b21fb5 100755 --- a/META-INF/packingbin_tool/MANIFEST.MF +++ b/META-INF/packingbin_tool/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 Created-By: javac.py Class-Path: fastjson_utils_java.jar -Main-Class: com.huawei.ohos.ConvertHapToBin +Main-Class: ohos.ConvertHapToBin diff --git a/META-INF/unpacking_tool/MANIFEST.MF b/META-INF/unpacking_tool/MANIFEST.MF index 79aada39298f18668ad6ec48e9238ec319552847..49c41f2b48a044c6091244c4f241838dd2836520 100644 --- a/META-INF/unpacking_tool/MANIFEST.MF +++ b/META-INF/unpacking_tool/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 Created-By: javac.py Class-Path: fastjson_utils_java.jar -Main-Class: com.huawei.ohos.UncompressEntrance +Main-Class: ohos.UncompressEntrance diff --git a/adapter/LICENSE b/adapter/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f8fd74b9598ab0d5b130c50f7cf1bf51abb70c40 --- /dev/null +++ b/adapter/LICENSE @@ -0,0 +1,12 @@ +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. \ No newline at end of file diff --git a/bundles/packing_tool/bundle.json b/adapter/bundles/packing_tool/bundle.json similarity index 100% rename from bundles/packing_tool/bundle.json rename to adapter/bundles/packing_tool/bundle.json diff --git a/bundles/packing_tool/readme.md b/adapter/bundles/packing_tool/readme.md old mode 100755 new mode 100644 similarity index 94% rename from bundles/packing_tool/readme.md rename to adapter/bundles/packing_tool/readme.md index 8011c0260013133fe1b78127f169e5e1cfccb8b5..e5a27079ce42e53a7b64b60d024b37a55cddafd9 --- a/bundles/packing_tool/readme.md +++ b/adapter/bundles/packing_tool/readme.md @@ -1,5 +1,16 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. + * Copyright (c) 2019-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. */ use commands for package hap or app. diff --git a/com/huawei/ohos/AbilityInfo.java b/adapter/ohos/AbilityInfo.java old mode 100755 new mode 100644 similarity index 93% rename from com/huawei/ohos/AbilityInfo.java rename to adapter/ohos/AbilityInfo.java index a8afc7fbfc83ee52d828da76c5114511ba810782..8f6a4c4bbc2ac1bef77241dcf05ed4e720b72047 --- a/com/huawei/ohos/AbilityInfo.java +++ b/adapter/ohos/AbilityInfo.java @@ -1,172 +1,170 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * Ability info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class AbilityInfo { - /** - * Indicates the name of ability. - */ - public String name = ""; - - /** - * Indicates the description of ability. - */ - public String description = ""; - - /** - * Indicates the description resource of ability. - */ - public String descriptionRes = ""; - - /** - * Indicates the icon of ability. - */ - public String icon = ""; - - /** - * Indicates the icon path of ability. - */ - public String iconPath = ""; - - /** - * Indicates the label of ability. - */ - public String label = ""; - - /** - * Indicates the label resource of ability. - */ - public String labelRes = ""; - - /** - * Indicates the type of ability. - */ - public String type = ""; - - /** - * Indicates the formEnabled of ability. - */ - public boolean formEnabled = false; - - /** - * Indicates the formInfo of ability. - */ - public FormInfo formInfo = null; - - /** - * Indicates the uri of ability. - */ - public String uri = ""; - - /** - * Indicates the launchType of ability. - */ - public String launchType = ""; - - /** - * Indicates the metaData of ability. - */ - public MetaData metaData = new MetaData(); - - /** - * Indicates the orientation of ability. - */ - public String orientation = ""; - - /** - * Indicates the permissions of ability. - */ - public List permissions = new ArrayList(); - - /** - * Indicates the skills of ability. - */ - public List skills = new ArrayList(); - - /** - * Indicates the backgroundModes of ability. - */ - public List backgroundModes = new ArrayList(); - - /** - * Indicates the visible of ability. - */ - public boolean visible = false; - - /** - * Indicates the grantPermission of ability. - */ - public boolean grantPermission = false; - - /** - * Indicates the readPermission of ability. - */ - public String readPermission = ""; - - /** - * Indicates the writePermission of ability. - */ - public String writePermission = ""; - - /** - * Indicates the uriPermission mode of ability. - */ - public String uriPermissionMode = ""; - - /** - * Indicates the uriPermission path of ability. - */ - public String uriPermissionPath = ""; - - /** - * Indicates the configChanges of ability. - */ - public List configChanges = new ArrayList(); - - /** - * Indicates the directLaunch of ability. - */ - public boolean directLaunch = false; - - /** - * Indicates the mission of ability. - */ - public String mission = ""; - - /** - * Indicates the targetAbility of ability. - */ - public String targetAbility = ""; - - /** - * Indicates the multiUserShared of ability. - */ - public boolean multiUserShared = false; - - /** - * Indicates the supportPipMode of ability. - */ - public boolean supportPipMode = false; +/* + * 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 info. + * + */ +public class AbilityInfo { + /** + * Indicates the name of ability. + */ + public String name = ""; + + /** + * Indicates the description of ability. + */ + public String description = ""; + + /** + * Indicates the description resource of ability. + */ + public String descriptionRes = ""; + + /** + * Indicates the icon of ability. + */ + public String icon = ""; + + /** + * Indicates the icon path of ability. + */ + public String iconPath = ""; + + /** + * Indicates the label of ability. + */ + public String label = ""; + + /** + * Indicates the label resource of ability. + */ + public String labelRes = ""; + + /** + * Indicates the type of ability. + */ + public String type = ""; + + /** + * Indicates the formEnabled of ability. + */ + public boolean formEnabled = false; + + /** + * Indicates the formInfo of ability. + */ + public FormInfo formInfo = null; + + /** + * Indicates the uri of ability. + */ + public String uri = ""; + + /** + * Indicates the launchType of ability. + */ + public String launchType = ""; + + /** + * Indicates the metaData of ability. + */ + public MetaData metaData = new MetaData(); + + /** + * Indicates the orientation of ability. + */ + public String orientation = ""; + + /** + * Indicates the permissions of ability. + */ + public List permissions = new ArrayList(); + + /** + * Indicates the skills of ability. + */ + public List skills = new ArrayList(); + + /** + * Indicates the backgroundModes of ability. + */ + public List backgroundModes = new ArrayList(); + + /** + * Indicates the visible of ability. + */ + public boolean visible = false; + + /** + * Indicates the grantPermission of ability. + */ + public boolean grantPermission = false; + + /** + * Indicates the readPermission of ability. + */ + public String readPermission = ""; + + /** + * Indicates the writePermission of ability. + */ + public String writePermission = ""; + + /** + * Indicates the uriPermission mode of ability. + */ + public String uriPermissionMode = ""; + + /** + * Indicates the uriPermission path of ability. + */ + public String uriPermissionPath = ""; + + /** + * Indicates the configChanges of ability. + */ + public List configChanges = new ArrayList(); + + /** + * Indicates the directLaunch of ability. + */ + public boolean directLaunch = false; + + /** + * Indicates the mission of ability. + */ + public String mission = ""; + + /** + * Indicates the targetAbility of ability. + */ + public String targetAbility = ""; + + /** + * Indicates the multiUserShared of ability. + */ + public boolean multiUserShared = false; + + /** + * Indicates the supportPipMode of ability. + */ + public boolean supportPipMode = false; } \ No newline at end of file diff --git a/com/huawei/ohos/ApiVersion.java b/adapter/ohos/ApiVersion.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/ApiVersion.java rename to adapter/ohos/ApiVersion.java index 023fe618ef870babb3994168ddc0be39a28dbc89..a1e9a8ca60266068c42b27bdb0249503864c252f --- a/com/huawei/ohos/ApiVersion.java +++ b/adapter/ohos/ApiVersion.java @@ -1,38 +1,36 @@ -/* - * 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 com.huawei.ohos; - -import java.util.List; -import java.util.ArrayList; - -/** - * - * ApiVersion info - * - * @author weiguang - * @since 2021-02-02 - */ -public class ApiVersion { - /** - * ApiVersion policy - */ - public String policy; - - /** - * ApiVersion value list - */ - public List value = null; -} +/* + * 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.List; +import java.util.ArrayList; + +/** + * + * ApiVersion info + * + */ +public class ApiVersion { + /** + * ApiVersion policy + */ + public String policy; + + /** + * ApiVersion value list + */ + public List value = null; +} diff --git a/com/huawei/ohos/AppInfo.java b/adapter/ohos/AppInfo.java old mode 100755 new mode 100644 similarity index 94% rename from com/huawei/ohos/AppInfo.java rename to adapter/ohos/AppInfo.java index 278877abc26852ae2eed3a299496efbff49a14c3..44ef1fc40786c1c39493265d50111f1e63541b31 --- a/com/huawei/ohos/AppInfo.java +++ b/adapter/ohos/AppInfo.java @@ -1,144 +1,142 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * App AppInfo info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class AppInfo { - /** - * Indicates the bundleName of app AppInfo. - */ - public String bundleName = ""; - - /** - * Indicates the vendor of app AppInfo. - */ - public String vendor = ""; - - /** - * Indicates the relatedBundleName of app AppInfo. - */ - public String relatedBundleName = ""; - - /** - * Indicates the versionName of app AppInfo. - */ - public String versionName = ""; - - /** - * Indicates the versionCode of app AppInfo. - */ - public String versionCode = ""; - - /** - * Indicates the target Api Version of app AppInfo. - */ - public int targetApiVersion = 1; - - /** - * Indicates the compatible Api Version of app AppInfo. - */ - public int compatibleApiVersion = 1; - - /** - * Indicates the appName of app AppInfo. - */ - public String appName = ""; - - /** - * Indicates the appNameEN of app AppInfo. - */ - public String appNameEN = ""; - - /** - * Indicates the releaseType of app AppInfo. - */ - public String releaseType = ""; - - - private String shellVersionCode = ""; - private String shellVersionName = ""; - private boolean multiFrameworkBundle; - - /** - * Get shell version code. - * - * @return shell version code - */ - public String getShellVersionCode() { - return shellVersionCode; - } - - /** - * Set shell version code. - * - * @param shellVersionCode Indicates the shell version name - */ - public void setShellVersionCode(String shellVersionCode) { - this.shellVersionCode = shellVersionCode; - } - - /** - * Get shell version name. - * - * @return shell version name - */ - public String getShellVersionName() { - return shellVersionName; - } - - /** - * Set shell version name. - * - * @param shellVersionName Indicates the shell version name - */ - public void setShellVersionName(String shellVersionName) { - this.shellVersionName = shellVersionName; - } - - /** - * Whether the app is multi framework bundle. - * - * @return true if the app is a multi framework bundle. - */ - public boolean isMultiFrameworkBundle() { - return multiFrameworkBundle; - } - - /** - * Set multi framework bundle. - * - * @param multiFrameworkBundle Indicates the app type - */ - public void setMultiFrameworkBundle(boolean multiFrameworkBundle) { - this.multiFrameworkBundle = multiFrameworkBundle; - } - - /** - * Set default shell version - */ - public void setDefaultShellVersion() { - this.shellVersionCode = versionCode; - this.shellVersionName = versionName; - } -} +/* + * 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; + +/** + * App AppInfo info. + * + */ +public class AppInfo { + /** + * Indicates the bundleName of app AppInfo. + */ + public String bundleName = ""; + + /** + * Indicates the vendor of app AppInfo. + */ + public String vendor = ""; + + /** + * Indicates the relatedBundleName of app AppInfo. + */ + public String relatedBundleName = ""; + + /** + * Indicates the versionName of app AppInfo. + */ + public String versionName = ""; + + /** + * Indicates the versionCode of app AppInfo. + */ + public String versionCode = ""; + + /** + * Indicates the target Api Version of app AppInfo. + */ + public int targetApiVersion = 1; + + /** + * Indicates the compatible Api Version of app AppInfo. + */ + public int compatibleApiVersion = 1; + + /** + * Indicates the appName of app AppInfo. + */ + public String appName = ""; + + /** + * Indicates the appNameEN of app AppInfo. + */ + public String appNameEN = ""; + + /** + * Indicates the releaseType of app AppInfo. + */ + public String releaseType = ""; + + + private String shellVersionCode = ""; + private String shellVersionName = ""; + private boolean multiFrameworkBundle; + + /** + * Get shell version code. + * + * @return shell version code + */ + public String getShellVersionCode() { + return shellVersionCode; + } + + /** + * Set shell version code. + * + * @param shellVersionCode Indicates the shell version name + */ + public void setShellVersionCode(String shellVersionCode) { + this.shellVersionCode = shellVersionCode; + } + + /** + * Get shell version name. + * + * @return shell version name + */ + public String getShellVersionName() { + return shellVersionName; + } + + /** + * Set shell version name. + * + * @param shellVersionName Indicates the shell version name + */ + public void setShellVersionName(String shellVersionName) { + this.shellVersionName = shellVersionName; + } + + /** + * Whether the app is multi framework bundle. + * + * @return true if the app is a multi framework bundle. + */ + public boolean isMultiFrameworkBundle() { + return multiFrameworkBundle; + } + + /** + * Set multi framework bundle. + * + * @param multiFrameworkBundle Indicates the app type + */ + public void setMultiFrameworkBundle(boolean multiFrameworkBundle) { + this.multiFrameworkBundle = multiFrameworkBundle; + } + + /** + * Set default shell version + */ + public void setDefaultShellVersion() { + this.shellVersionCode = versionCode; + this.shellVersionName = versionName; + } +} diff --git a/com/huawei/ohos/BinaryTool.java b/adapter/ohos/BinaryTool.java old mode 100755 new mode 100644 similarity index 98% rename from com/huawei/ohos/BinaryTool.java rename to adapter/ohos/BinaryTool.java index d5fa48a4951f31322d12ff9431c8fc9cd61ee2ab..c301278773eca8524926bf94784f5188a59166d5 --- a/com/huawei/ohos/BinaryTool.java +++ b/adapter/ohos/BinaryTool.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import java.io.File; import java.io.IOException; @@ -26,8 +26,6 @@ import java.util.Queue; /** * generate binary file * - * @author panxurong - * @since 2020-02-14 */ public class BinaryTool { private static final String JSON_FILE_NAME = "config.json"; diff --git a/com/huawei/ohos/BundleException.java b/adapter/ohos/BundleException.java old mode 100755 new mode 100644 similarity index 93% rename from com/huawei/ohos/BundleException.java rename to adapter/ohos/BundleException.java index 01da00e8963a02fce44eb9bec0c68255b63ddd68..ea3911857c1de5e20c0e61c027c66cf9a64c70d2 --- a/com/huawei/ohos/BundleException.java +++ b/adapter/ohos/BundleException.java @@ -13,13 +13,11 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; /** * bundle tool exception class. * - * @author huzeqi - * @since 2019-10-25 */ class BundleException extends Exception { private static final long serialVersionUID = 1813070042705457755L; diff --git a/com/huawei/ohos/CollectBinInfo.java b/adapter/ohos/CollectBinInfo.java old mode 100755 new mode 100644 similarity index 98% rename from com/huawei/ohos/CollectBinInfo.java rename to adapter/ohos/CollectBinInfo.java index 56722c22d4c9d1fcbef3383ed00fce9bfdcc0438..ed14304e8385ec6e23eeac73eae68187bc3f7f99 --- a/com/huawei/ohos/CollectBinInfo.java +++ b/adapter/ohos/CollectBinInfo.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import ohos.utils.fastjson.JSONObject; @@ -25,8 +25,6 @@ import java.util.Optional; /** * bin file to hap tool main class. * - * @author panxurong - * @since 2020-07-31 */ public class CollectBinInfo { private static final String JSON_FILE_NAME = "config.json"; diff --git a/com/huawei/ohos/CommandParser.java b/adapter/ohos/CommandParser.java old mode 100755 new mode 100644 similarity index 96% rename from com/huawei/ohos/CommandParser.java rename to adapter/ohos/CommandParser.java index 9e263be3c15e3c08d9853a3c29d59f5d357efda5..6b67ea5332d5c22b0b75d04d49e48820f431650f --- a/com/huawei/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -1,308 +1,306 @@ -/* - * 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 com.huawei.ohos; - -/** - * command parser. - * - * @author huzeqi - * @since 2019-10-25 - */ -public class CommandParser { - /** - * Parses and returns the hap list that supports the device type. - */ - public static final String PARSE_MODE_HAPLIST = "hap-list"; - - /** - * Parses and returns the information about the hap. - */ - public static final String PARSE_MODE_HAPINFO = "hap-info"; - - private static final String CMD_MODE = "--mode"; - private static final String CMD_JSON_PATH = "--json-path"; - private static final String CMD_PROFILE_PATH = "--profile-path"; - private static final String CMD_INDEX_PATH = "--index-path"; - private static final String CMD_SO_PATH = "--maple-so-path"; - private static final String CMD_SO_DIR = "--maple-so-dir"; - private static final String CMD_ABILITY_SO_PATH = "--ability-so-path"; - private static final String CMD_DEX_PATH = "--dex-path"; - private static final String CMD_ABC_PATH = "--abc-path"; - private static final String CMD_LIB_PATH = "--lib-path"; - private static final String CMD_RES_PATH = "--res-path"; - private static final String CMD_RESOURCES_PATH = "--resources-path"; - private static final String CMD_ASSETS_PATH = "--assets-path"; - private static final String CMD_APK_PATH = "--shell-apk-path"; - private static final String CMD_HAP_PATH = "--hap-path"; - private static final String CMD_APP_PATH = "--app-path"; - private static final String CMD_SIGNATURE_PATH = "--signature-path"; - private static final String CMD_CERTIFICATE_PATH = "--certificate-path"; - private static final String CMD_FORCE = "--force"; - private static final String CMD_OUT_PATH = "--out-path"; - private static final String CMD_PACK_INFO_PATH = "--pack-info-path"; - private static final String CMD_BIN_PATH = "--bin-path"; - private static final String CMD_JAR_PATH = "--jar-path"; - private static final String CMD_TXT_PATH = "--txt-path"; - private static final String CMD_HAR_PATH = "--har-path"; - private static final String CMD_PARSE_MODE = "--p"; - private static final String CMD_PACK_RES_PATH = "--pack-res-path"; - private static final String CMD_UNPACKAPK = "--unpackapk"; - private static final String CMD_UNPACK_CUT_ENTRY_APK = "--unpack-cut_entry"; - private static final String CMD_SHAREDLIBS_PATH = "--shared-libs-path"; - private static final String CMD_ENTRYCARD_PATH = "--entrycard-path"; - private static final Log LOG = new Log(CommandParser.class.toString()); - - /** - * judge args is null and enter parser. - * - * @param utility common data - * @param args command line - * @return commandParser if input valid - */ - public static boolean commandParser(Utility utility, String[] args) { - if (args == null) { - LOG.error("CommandParser::commandParser args is null!"); - return false; - } - - parser(utility, args); - return true; - } - - /** - * parse args. - * - * @param utility common data - * @param args command line - */ - private static void parser(Utility utility, String[] args) { - for (int i = 0; i < args.length - 1; i++) { - if (parseAppCmd(utility, args[i], args[i + 1]) || parseHapCmd(utility, args[i], args[i + 1])) { - i++; - continue; - } - switch (args[i]) { - case CMD_MODE: { - utility.setMode(args[i + 1]); - i++; - break; - } - case CMD_FORCE: { - utility.setForceRewrite(args[i + 1]); - i++; - break; - } - case CMD_OUT_PATH: { - utility.setOutPath(args[i + 1]); - i++; - break; - } - case CMD_BIN_PATH: { - utility.setBinPath(args[i + 1]); - i++; - break; - } - case CMD_JAR_PATH: { - utility.setJarPath(args[i + 1]); - i++; - break; - } - case CMD_TXT_PATH: { - utility.setTxtPath(args[i + 1]); - i++; - break; - } - case CMD_HAR_PATH: { - utility.setHarPath(args[i + 1]); - i++; - break; - } - case CMD_PARSE_MODE: { - utility.setParseMode(args[i + 1]); - if (PARSE_MODE_HAPLIST.equals(utility.getParseMode())) { - utility.setDeviceType(args[i + 2]); - } else if (PARSE_MODE_HAPINFO.equals(utility.getParseMode())) { - utility.setHapName(args[i + 2]); - } - i = i + 2; - break; - } - case CMD_UNPACKAPK: { - utility.setUnpackApk(args[i + 1]); - i++; - break; - } - case CMD_UNPACK_CUT_ENTRY_APK: { - utility.setUnpackCutEntryApk(args[i + 1]); - i++; - break; - } - case CMD_PACK_INFO_PATH: { - utility.setPackInfoPath(args[i + 1]); - i++; - break; - } - - case CMD_ENTRYCARD_PATH: { - utility.setEntryCardPath(args[i + 1]); - i++; - break; - } - - case CMD_PACK_RES_PATH: { - utility.setPackResPath(args[i + 1]); - i++; - break; - } - default: { - break; - } - } - } - } - - /** - * parse app args. - * - * @param utility common data - * @param cmd command line - * @param value the value to be set - * @return parse result - */ - private static boolean parseAppCmd(Utility utility, String cmd, String value) { - switch (cmd) { - case CMD_HAP_PATH: { - utility.setHapPath(value); - return true; - } - case CMD_APP_PATH: { - utility.setAppPath(value); - return true; - } - case CMD_CERTIFICATE_PATH: { - utility.setCertificatePath(value); - return true; - } - case CMD_SIGNATURE_PATH: { - utility.setSignaturePath(value); - return true; - } - case CMD_JSON_PATH: { - utility.setJsonPath(value); - return true; - } - case CMD_PACK_INFO_PATH: { - utility.setPackInfoPath(value); - return true; - } - case CMD_RES_PATH: { - utility.setResPath(value); - return true; - } - case CMD_PACK_RES_PATH: { - utility.setPackResPath(value); - return true; - } - default : { - return false; - } - } - } - - /** - * parse hap args. - * - * @param utility common data - * @param cmd command line - * @param value the value to be set - * @return parse result - */ - private static boolean parseHapCmd(Utility utility, String cmd, String value) { - switch (cmd) { - case CMD_JSON_PATH: { - utility.setJsonPath(value); - return true; - } - case CMD_PROFILE_PATH: { - utility.setProfilePath(value); - return true; - } - case CMD_INDEX_PATH: { - utility.setIndexPath(value); - return true; - } - case CMD_SO_PATH: { - utility.setSoPath(value); - return true; - } - case CMD_ABILITY_SO_PATH: { - utility.setAbilitySoPath(value); - return true; - } - case CMD_SO_DIR: { - utility.setSoDir(value); - return true; - } - case CMD_DEX_PATH: { - utility.setDexPath(value); - return true; - } - case CMD_ABC_PATH: { - utility.setAbcPath(value); - return true; - } - case CMD_LIB_PATH: { - utility.setLibPath(value); - return true; - } - case CMD_ASSETS_PATH: { - utility.setAssetsPath(value); - return true; - } - case CMD_RES_PATH: { - utility.setResPath(value); - return true; - } - case CMD_RESOURCES_PATH: { - utility.setResourcesPath(value); - return true; - } - case CMD_SHAREDLIBS_PATH: { - utility.setSharedLibsPath(value); - return true; - } - case CMD_APK_PATH: { - utility.setApkPath(value); - return true; - } - case CMD_JAR_PATH: { - utility.setJarPath(value); - return true; - } - case CMD_TXT_PATH: { - utility.setTxtPath(value); - return true; - } - case CMD_PACK_INFO_PATH: { - utility.setPackInfoPath(value); - return true; - } - default : { - return false; - } - } - } -} +/* + * 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; + +/** + * command parser. + * + */ +public class CommandParser { + /** + * Parses and returns the hap list that supports the device type. + */ + public static final String PARSE_MODE_HAPLIST = "hap-list"; + + /** + * Parses and returns the information about the hap. + */ + public static final String PARSE_MODE_HAPINFO = "hap-info"; + + private static final String CMD_MODE = "--mode"; + private static final String CMD_JSON_PATH = "--json-path"; + private static final String CMD_PROFILE_PATH = "--profile-path"; + private static final String CMD_INDEX_PATH = "--index-path"; + private static final String CMD_SO_PATH = "--maple-so-path"; + private static final String CMD_SO_DIR = "--maple-so-dir"; + private static final String CMD_ABILITY_SO_PATH = "--ability-so-path"; + private static final String CMD_DEX_PATH = "--dex-path"; + private static final String CMD_ABC_PATH = "--abc-path"; + private static final String CMD_LIB_PATH = "--lib-path"; + private static final String CMD_RES_PATH = "--res-path"; + private static final String CMD_RESOURCES_PATH = "--resources-path"; + private static final String CMD_ASSETS_PATH = "--assets-path"; + private static final String CMD_APK_PATH = "--shell-apk-path"; + private static final String CMD_HAP_PATH = "--hap-path"; + private static final String CMD_APP_PATH = "--app-path"; + private static final String CMD_SIGNATURE_PATH = "--signature-path"; + private static final String CMD_CERTIFICATE_PATH = "--certificate-path"; + private static final String CMD_FORCE = "--force"; + private static final String CMD_OUT_PATH = "--out-path"; + private static final String CMD_PACK_INFO_PATH = "--pack-info-path"; + private static final String CMD_BIN_PATH = "--bin-path"; + private static final String CMD_JAR_PATH = "--jar-path"; + private static final String CMD_TXT_PATH = "--txt-path"; + private static final String CMD_HAR_PATH = "--har-path"; + private static final String CMD_PARSE_MODE = "--p"; + private static final String CMD_PACK_RES_PATH = "--pack-res-path"; + private static final String CMD_UNPACKAPK = "--unpackapk"; + private static final String CMD_UNPACK_CUT_ENTRY_APK = "--unpack-cut_entry"; + private static final String CMD_SHAREDLIBS_PATH = "--shared-libs-path"; + private static final String CMD_ENTRYCARD_PATH = "--entrycard-path"; + private static final Log LOG = new Log(CommandParser.class.toString()); + + /** + * judge args is null and enter parser. + * + * @param utility common data + * @param args command line + * @return commandParser if input valid + */ + public static boolean commandParser(Utility utility, String[] args) { + if (args == null) { + LOG.error("CommandParser::commandParser args is null!"); + return false; + } + + parser(utility, args); + return true; + } + + /** + * parse args. + * + * @param utility common data + * @param args command line + */ + private static void parser(Utility utility, String[] args) { + for (int i = 0; i < args.length - 1; i++) { + if (parseAppCmd(utility, args[i], args[i + 1]) || parseHapCmd(utility, args[i], args[i + 1])) { + i++; + continue; + } + switch (args[i]) { + case CMD_MODE: { + utility.setMode(args[i + 1]); + i++; + break; + } + case CMD_FORCE: { + utility.setForceRewrite(args[i + 1]); + i++; + break; + } + case CMD_OUT_PATH: { + utility.setOutPath(args[i + 1]); + i++; + break; + } + case CMD_BIN_PATH: { + utility.setBinPath(args[i + 1]); + i++; + break; + } + case CMD_JAR_PATH: { + utility.setJarPath(args[i + 1]); + i++; + break; + } + case CMD_TXT_PATH: { + utility.setTxtPath(args[i + 1]); + i++; + break; + } + case CMD_HAR_PATH: { + utility.setHarPath(args[i + 1]); + i++; + break; + } + case CMD_PARSE_MODE: { + utility.setParseMode(args[i + 1]); + if (PARSE_MODE_HAPLIST.equals(utility.getParseMode())) { + utility.setDeviceType(args[i + 2]); + } else if (PARSE_MODE_HAPINFO.equals(utility.getParseMode())) { + utility.setHapName(args[i + 2]); + } + i = i + 2; + break; + } + case CMD_UNPACKAPK: { + utility.setUnpackApk(args[i + 1]); + i++; + break; + } + case CMD_UNPACK_CUT_ENTRY_APK: { + utility.setUnpackCutEntryApk(args[i + 1]); + i++; + break; + } + case CMD_PACK_INFO_PATH: { + utility.setPackInfoPath(args[i + 1]); + i++; + break; + } + + case CMD_ENTRYCARD_PATH: { + utility.setEntryCardPath(args[i + 1]); + i++; + break; + } + + case CMD_PACK_RES_PATH: { + utility.setPackResPath(args[i + 1]); + i++; + break; + } + default: { + break; + } + } + } + } + + /** + * parse app args. + * + * @param utility common data + * @param cmd command line + * @param value the value to be set + * @return parse result + */ + private static boolean parseAppCmd(Utility utility, String cmd, String value) { + switch (cmd) { + case CMD_HAP_PATH: { + utility.setHapPath(value); + return true; + } + case CMD_APP_PATH: { + utility.setAppPath(value); + return true; + } + case CMD_CERTIFICATE_PATH: { + utility.setCertificatePath(value); + return true; + } + case CMD_SIGNATURE_PATH: { + utility.setSignaturePath(value); + return true; + } + case CMD_JSON_PATH: { + utility.setJsonPath(value); + return true; + } + case CMD_PACK_INFO_PATH: { + utility.setPackInfoPath(value); + return true; + } + case CMD_RES_PATH: { + utility.setResPath(value); + return true; + } + case CMD_PACK_RES_PATH: { + utility.setPackResPath(value); + return true; + } + default : { + return false; + } + } + } + + /** + * parse hap args. + * + * @param utility common data + * @param cmd command line + * @param value the value to be set + * @return parse result + */ + private static boolean parseHapCmd(Utility utility, String cmd, String value) { + switch (cmd) { + case CMD_JSON_PATH: { + utility.setJsonPath(value); + return true; + } + case CMD_PROFILE_PATH: { + utility.setProfilePath(value); + return true; + } + case CMD_INDEX_PATH: { + utility.setIndexPath(value); + return true; + } + case CMD_SO_PATH: { + utility.setSoPath(value); + return true; + } + case CMD_ABILITY_SO_PATH: { + utility.setAbilitySoPath(value); + return true; + } + case CMD_SO_DIR: { + utility.setSoDir(value); + return true; + } + case CMD_DEX_PATH: { + utility.setDexPath(value); + return true; + } + case CMD_ABC_PATH: { + utility.setAbcPath(value); + return true; + } + case CMD_LIB_PATH: { + utility.setLibPath(value); + return true; + } + case CMD_ASSETS_PATH: { + utility.setAssetsPath(value); + return true; + } + case CMD_RES_PATH: { + utility.setResPath(value); + return true; + } + case CMD_RESOURCES_PATH: { + utility.setResourcesPath(value); + return true; + } + case CMD_SHAREDLIBS_PATH: { + utility.setSharedLibsPath(value); + return true; + } + case CMD_APK_PATH: { + utility.setApkPath(value); + return true; + } + case CMD_JAR_PATH: { + utility.setJarPath(value); + return true; + } + case CMD_TXT_PATH: { + utility.setTxtPath(value); + return true; + } + case CMD_PACK_INFO_PATH: { + utility.setPackInfoPath(value); + return true; + } + default : { + return false; + } + } + } +} diff --git a/com/huawei/ohos/CommonEvent.java b/adapter/ohos/CommonEvent.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/CommonEvent.java rename to adapter/ohos/CommonEvent.java index 72004634b5bb01916e8dae1887f873bbbd3fcdc3..d1bc2d6611d546ef6ef0d717de5bb6bafe34db99 --- a/com/huawei/ohos/CommonEvent.java +++ b/adapter/ohos/CommonEvent.java @@ -1,52 +1,50 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * App CommonEvent info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class CommonEvent { - /** - * Indicates the name of app CommonEvent. - */ - public String name = ""; - - /** - * Indicates the permission of app CommonEvent. - */ - public String permission = ""; - - /** - * Indicates the data of app CommonEvent. - */ - public List data = new ArrayList(); - - /** - * Indicates the type of app CommonEvent. - */ - public List type = new ArrayList(); - - /** - * Indicates the events of app CommonEvent. - */ - public List events = new ArrayList(); -} +/* + * 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; + +/** + * App CommonEvent info. + * + */ +public class CommonEvent { + /** + * Indicates the name of app CommonEvent. + */ + public String name = ""; + + /** + * Indicates the permission of app CommonEvent. + */ + public String permission = ""; + + /** + * Indicates the data of app CommonEvent. + */ + public List data = new ArrayList(); + + /** + * Indicates the type of app CommonEvent. + */ + public List type = new ArrayList(); + + /** + * Indicates the events of app CommonEvent. + */ + public List events = new ArrayList(); +} diff --git a/com/huawei/ohos/CompressEntrance.java b/adapter/ohos/CompressEntrance.java old mode 100755 new mode 100644 similarity index 98% rename from com/huawei/ohos/CompressEntrance.java rename to adapter/ohos/CompressEntrance.java index be9267ca1ceb53068aa23845ef33a821077dd10d..2615cb4ed4b5f2e8a8525b8296f2944bc84c2d43 --- a/com/huawei/ohos/CompressEntrance.java +++ b/adapter/ohos/CompressEntrance.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import java.util.logging.Level; import java.util.logging.Logger; @@ -24,8 +24,6 @@ import java.util.logging.Logger; * step2: verity arguments * step3: compress arguments * - * @author huzeqi - * @since 2019-10-25 */ public class CompressEntrance { private static final int EXIT_STATUS_NORMAL = 0; diff --git a/com/huawei/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java old mode 100755 new mode 100644 similarity index 97% rename from com/huawei/ohos/CompressVerify.java rename to adapter/ohos/CompressVerify.java index 94715aa4b2b5ba4e83534a84ba4f35be9a4a429a..46b00ac6c207f0f7847da3179724769a8cff842e --- a/com/huawei/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -1,477 +1,475 @@ -/* - * 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 com.huawei.ohos; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * compress commend parser. - * - * @author huzeqi - * @since 2019-10-25 - */ -public class CompressVerify { - private static final String COMMA_SPLIT = ","; - private static final String JSON_PROFILE = "config.json"; - private static final String PROFILE_NAME = "CAPABILITY.profile"; - private static final String INDEX_PROFILE = "resources.index"; - private static final String PACK_INFO = "pack.info"; - private static final String PACK_RES = "pack.res"; - private static final String HAP_SUFFIX = ".hap"; - private static final String HAR_SUFFIX = ".har"; - private static final String APP_SUFFIX = ".app"; - private static final String APK_SUFFIX = ".apk"; - private static final String DEX_SUFFIX = ".dex"; - private static final String ABC_SUFFIX = ".abc"; - private static final String SO_SUFFIX = ".so"; - private static final String JAR_SUFFIX = ".jar"; - private static final String TXT_SUFFIX = ".txt"; - private static final String PNG_SUFFIX = ".png"; - private static final String RES_SUFFIX = ".res"; - private static final String ENTRY_CARD_DIRECTORY_NAME = "EntryCard"; - - private static final Log LOG = new Log(CompressVerify.class.toString()); - - private static final boolean TYPE_FILE = true; - private static final boolean TYPE_DIR = false; - - /** - * if args valid. - * - * @param utility common data - * @return commandVerify if command valid. - */ - public static boolean commandVerify(Utility utility) { - if (utility == null) { - LOG.error("CompressVerify::commandVerify utility is null!"); - return false; - } - - if (!utility.getForceRewrite().isEmpty() && !"true".equals(utility.getForceRewrite()) - && !"false".equals(utility.getForceRewrite())) { - LOG.error("CompressVerify::commandVerify forceRewrite is invalid!"); - return false; - } - return commandPathVerify(utility); - } - - /** - * verify path. - * - * @param utility common data - * @return commandPathVerify if command valid. - */ - private static boolean commandPathVerify(Utility utility) { - if (Utility.MODE_HAP.equals(utility.getMode())) { - if (!utility.getJsonPath().isEmpty()) { - File file = new File(utility.getJsonPath()); - if (!file.isFile() || !file.getName().equals(JSON_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHapMode json-path must be config.json file!"); - return false; - } - } - - if (!utility.getApkPath().isEmpty() && !compatibleProcess(utility, utility.getApkPath(), - utility.getFormattedApkPathList(), APK_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode shell-apk-path is invalid!"); - return false; - } - - if (!utility.getProfilePath().isEmpty()) { - File file = new File(utility.getProfilePath()); - if (!file.isFile() || !file.getName().equals(PROFILE_NAME)) { - LOG.error("CompressVerify::isArgsValidInHapMode profile-path must be CAPABILITY.profile file!"); - return false; - } - } - - if (!utility.getDexPath().isEmpty() && !compatibleProcess(utility, utility.getDexPath(), - utility.getFormattedDexPathList(), DEX_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode dex-path is invalid!"); - return false; - } - - if (!utility.getAbcPath().isEmpty() && !compatibleProcess(utility, utility.getAbcPath(), - utility.getFormattedAbcPathList(), ABC_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode abc-path is invalid!"); - return false; - } - - return isVerifyValidInHapMode(utility); - } else if (Utility.MODE_HAR.equals(utility.getMode())) { - return isVerifyValidInHarMode(utility); - } else if (Utility.MODE_APP.equals(utility.getMode())) { - return isVerifyValidInAppMode(utility); - } else if (Utility.MODE_RES.equals(utility.getMode())) { - return isVerifyValidInResMode(utility); - } else { - LOG.error("CompressVerify::commandVerify mode is invalid!"); - return false; - } - } - - /** - * parse and check args if valid in hap mode. - * - * @param utility common data - * @return isVerifyValidInHapMode if verify valid in hap mode. - */ - private static boolean isVerifyValidInHapMode(Utility utility) { - File file = new File(utility.getIndexPath()); - if (!utility.getIndexPath().isEmpty() && !file.isFile() && file.getName().equals(INDEX_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHapMode index-path must be resources.index file!"); - return false; - } - - if (!utility.getSoPath().isEmpty() && - !compatibleProcess(utility, utility.getSoPath(), utility.getFormattedSoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-path is invalid!"); - return false; - } - - if (!utility.getAbilitySoPath().isEmpty() && !compatibleProcess(utility, utility.getAbilitySoPath(), - utility.getFormattedAbilitySoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode ability-so-path is invalid!"); - return false; - } - - if (isHapPathValid(utility.getSoDir())) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-dir is invalid!"); - return false; - } - - if (isHapPathValid(utility.getLibPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode lib-path is invalid!"); - return false; - } - - if (isHapPathValid(utility.getResPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode res-path is invalid!"); - return false; - } - - if (isHapPathValid(utility.getResourcesPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode resources-path is invalid!"); - return false; - } - - if (isHapPathValid(utility.getAssetsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode assets-path is invalid!"); - return false; - } - - if (isHapPathValid(utility.getSharedLibsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode shared-libs-path is invalid!"); - return false; - } - - if (!utility.getJarPath().isEmpty() - && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode jar-path is invalid!"); - return false; - } - - if (!utility.getTxtPath().isEmpty() - && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode txt-path is invalid!"); - return false; - } - - if (!utility.getPackInfoPath().isEmpty() && !isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInHapMode pack-info-path is invalid!"); - return false; - } - - return isOutPathValid(utility, HAP_SUFFIX); - } - - /** - * check hap path if valid - * - * @param path path input - * @return isPathValid if path verify - */ - private static boolean isHapPathValid(String path) { - return (!path.isEmpty() && !isPathValid(path, TYPE_DIR, null)); - } - - /** - * parse and check args if valid in har mode. - * - * @param utility common data - * @return isVerifyValidInHarMode if verify valid in har mode. - */ - private static boolean isVerifyValidInHarMode(Utility utility) { - if (utility.getJsonPath().isEmpty() || !isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file!"); - return false; - } - - if (!utility.getJarPath().isEmpty() - && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid!"); - return false; - } - - if (!utility.getTxtPath().isEmpty() - && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid!"); - return false; - } - - if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid!"); - return false; - } - - if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid!"); - return false; - } - - if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid!"); - return false; - } - - if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid!"); - return false; - } - - return isOutPathValid(utility, HAR_SUFFIX); - } - - /** - * parse and check args if valid in app mode. - * - * @param utility common data - * @return isVerifyValidInAppMode if verify valid in app mode. - */ - private static boolean isVerifyValidInAppMode(Utility utility) { - if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode hap-path is empty!"); - return false; - } - - if (!compatibleProcess(utility, utility.getHapPath(), utility.getFormattedHapPathList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode hap-path is invalid!"); - return false; - } - - if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty!"); - return false; - } - - File file = new File(utility.getPackInfoPath()); - if (!file.isFile() || !file.getName().equals(PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is invalid!"); - return false; - } - - if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode signature-path is invalid!"); - return false; - } - - if (!utility.getCertificatePath().isEmpty() && !(new File(utility.getCertificatePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode certificate-path is invalid!"); - return false; - } - - if (!utility.getEntryCardPath().isEmpty() && - !compatibleProcess(utility, utility.getEntryCardPath(), - utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode entrycard-path is invalid!"); - return false; - } - if (!utility.getPackResPath().isEmpty() && !isPathValid(utility.getPackResPath(), TYPE_FILE, PACK_RES)) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-res-path is invalid!:" ); - return false; - } - - return isOutPathValid(utility, APP_SUFFIX); - } - - - /** - * parse and check args if valid in res mode. - * - * @param utility common data - * @return isVerifyValidInAppMode if verify valid in app mode. - */ - private static boolean isVerifyValidInResMode(Utility utility) { - if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid!"); - return false; - } - - if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); - return false; - } - if (!compatibleProcess(utility, utility.getEntryCardPath(), - utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid!"); - return false; - } - return isOutPathValid(utility, RES_SUFFIX); - } - - - /** - * Compatible file input and directory input - * - * @param utility common data - * @param inputPath input path - * @param fileList save files' path with list - * @param suffix process type - * @return Returns {@code true} if the compatible is successful; returns {@code false} otherwise. - */ - private static boolean compatibleProcess(Utility utility, String inputPath, - List fileList, String suffix) { - if (isPathValid(inputPath, TYPE_DIR, null)) { - File inputFile = new File(inputPath); - File[] files = inputFile.listFiles(); - if (files == null) { - return true; - } - for (File fileItem : files) { - if (fileItem.getName().toLowerCase(Locale.ENGLISH).endsWith(suffix)) { - fileList.add(fileItem.toString()); - } - } - return true; - } else { - String formattedPathItem = ""; - List pathList = removeDuplicatePath(inputPath); - for (String pathItem : pathList) { - formattedPathItem = utility.getFormattedPath(pathItem); - if (!isPathValid(formattedPathItem, TYPE_FILE, suffix)) { - return false; - } - fileList.add(formattedPathItem); - } - return true; - } - } - - /** - * turn input path block to formatted path list - * - * @param utility common data - * @param suffix used to determine type - * @return isVerifyValidInAppMode if verify valid in app mode. - */ - private static boolean isOutPathValid(Utility utility, String suffix) { - File outFile = new File(utility.getOutPath()); - - if (("false".equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error("CompressVerify::isOutPathValid out file already existed!"); - return false; - } - - if (HAP_SUFFIX.equals(suffix)) { - if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hap!"); - return false; - } else { - return true; - } - } - - if (HAR_SUFFIX.equals(suffix)) { - if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAR_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .har!"); - return false; - } else { - return true; - } - } - - if (APP_SUFFIX.equals(suffix)) { - if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .app!"); - return false; - } else { - return true; - } - } - - if (RES_SUFFIX.equals(suffix)) { - if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(RES_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .res!"); - return false; - } else { - return true; - } - } - - return false; - } - - /** - * check path if valid - * - * @param path path input - * @param isFile type input - * @param flag flag input - * @return isPathValid if path verify - */ - private static boolean isPathValid(String path, boolean isFile, String flag) { - File file = new File(path); - if (isFile && (file.isFile()) && file.getName().toLowerCase(Locale.ENGLISH).endsWith(flag)) { - return true; - } - return (!isFile) && file.isDirectory(); - } - - private static boolean isDirectoryValidStrictCase(String path, String directoryName) { - File file = new File(path); - if (!file.exists()) { - LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " - + path); - return false; - } - if (file.isDirectory()) { - return directoryName.equals(file.getName()); - } - return false; - } - - /** - * remove duplicate in path. - * - * @param path input path, use comma separate. - * @return result list - */ - private static List removeDuplicatePath(String path) { - String[] array = path.split(COMMA_SPLIT); - List list = new ArrayList<>(); - - for (String item : array) { - if (!list.contains(item)) { - list.add(item); - } - } - return list; - } -} +/* + * 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.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +/** + * compress commend parser. + * + */ +public class CompressVerify { + private static final String COMMA_SPLIT = ","; + private static final String JSON_PROFILE = "config.json"; + private static final String PROFILE_NAME = "CAPABILITY.profile"; + private static final String INDEX_PROFILE = "resources.index"; + private static final String PACK_INFO = "pack.info"; + private static final String PACK_RES = "pack.res"; + private static final String HAP_SUFFIX = ".hap"; + private static final String HAR_SUFFIX = ".har"; + private static final String APP_SUFFIX = ".app"; + private static final String APK_SUFFIX = ".apk"; + private static final String DEX_SUFFIX = ".dex"; + private static final String ABC_SUFFIX = ".abc"; + private static final String SO_SUFFIX = ".so"; + private static final String JAR_SUFFIX = ".jar"; + private static final String TXT_SUFFIX = ".txt"; + private static final String PNG_SUFFIX = ".png"; + private static final String RES_SUFFIX = ".res"; + private static final String ENTRY_CARD_DIRECTORY_NAME = "EntryCard"; + + private static final Log LOG = new Log(CompressVerify.class.toString()); + + private static final boolean TYPE_FILE = true; + private static final boolean TYPE_DIR = false; + + /** + * if args valid. + * + * @param utility common data + * @return commandVerify if command valid. + */ + public static boolean commandVerify(Utility utility) { + if (utility == null) { + LOG.error("CompressVerify::commandVerify utility is null!"); + return false; + } + + if (!utility.getForceRewrite().isEmpty() && !"true".equals(utility.getForceRewrite()) + && !"false".equals(utility.getForceRewrite())) { + LOG.error("CompressVerify::commandVerify forceRewrite is invalid!"); + return false; + } + return commandPathVerify(utility); + } + + /** + * verify path. + * + * @param utility common data + * @return commandPathVerify if command valid. + */ + private static boolean commandPathVerify(Utility utility) { + if (Utility.MODE_HAP.equals(utility.getMode())) { + if (!utility.getJsonPath().isEmpty()) { + File file = new File(utility.getJsonPath()); + if (!file.isFile() || !file.getName().equals(JSON_PROFILE)) { + LOG.error("CompressVerify::isArgsValidInHapMode json-path must be config.json file!"); + return false; + } + } + + if (!utility.getApkPath().isEmpty() && !compatibleProcess(utility, utility.getApkPath(), + utility.getFormattedApkPathList(), APK_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode shell-apk-path is invalid!"); + return false; + } + + if (!utility.getProfilePath().isEmpty()) { + File file = new File(utility.getProfilePath()); + if (!file.isFile() || !file.getName().equals(PROFILE_NAME)) { + LOG.error("CompressVerify::isArgsValidInHapMode profile-path must be CAPABILITY.profile file!"); + return false; + } + } + + if (!utility.getDexPath().isEmpty() && !compatibleProcess(utility, utility.getDexPath(), + utility.getFormattedDexPathList(), DEX_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode dex-path is invalid!"); + return false; + } + + if (!utility.getAbcPath().isEmpty() && !compatibleProcess(utility, utility.getAbcPath(), + utility.getFormattedAbcPathList(), ABC_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode abc-path is invalid!"); + return false; + } + + return isVerifyValidInHapMode(utility); + } else if (Utility.MODE_HAR.equals(utility.getMode())) { + return isVerifyValidInHarMode(utility); + } else if (Utility.MODE_APP.equals(utility.getMode())) { + return isVerifyValidInAppMode(utility); + } else if (Utility.MODE_RES.equals(utility.getMode())) { + return isVerifyValidInResMode(utility); + } else { + LOG.error("CompressVerify::commandVerify mode is invalid!"); + return false; + } + } + + /** + * parse and check args if valid in hap mode. + * + * @param utility common data + * @return isVerifyValidInHapMode if verify valid in hap mode. + */ + private static boolean isVerifyValidInHapMode(Utility utility) { + File file = new File(utility.getIndexPath()); + if (!utility.getIndexPath().isEmpty() && !file.isFile() && file.getName().equals(INDEX_PROFILE)) { + LOG.error("CompressVerify::isArgsValidInHapMode index-path must be resources.index file!"); + return false; + } + + if (!utility.getSoPath().isEmpty() && + !compatibleProcess(utility, utility.getSoPath(), utility.getFormattedSoPathList(), SO_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode maple-so-path is invalid!"); + return false; + } + + if (!utility.getAbilitySoPath().isEmpty() && !compatibleProcess(utility, utility.getAbilitySoPath(), + utility.getFormattedAbilitySoPathList(), SO_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode ability-so-path is invalid!"); + return false; + } + + if (isHapPathValid(utility.getSoDir())) { + LOG.error("CompressVerify::isArgsValidInHapMode maple-so-dir is invalid!"); + return false; + } + + if (isHapPathValid(utility.getLibPath())) { + LOG.error("CompressVerify::isArgsValidInHapMode lib-path is invalid!"); + return false; + } + + if (isHapPathValid(utility.getResPath())) { + LOG.error("CompressVerify::isArgsValidInHapMode res-path is invalid!"); + return false; + } + + if (isHapPathValid(utility.getResourcesPath())) { + LOG.error("CompressVerify::isArgsValidInHapMode resources-path is invalid!"); + return false; + } + + if (isHapPathValid(utility.getAssetsPath())) { + LOG.error("CompressVerify::isArgsValidInHapMode assets-path is invalid!"); + return false; + } + + if (isHapPathValid(utility.getSharedLibsPath())) { + LOG.error("CompressVerify::isArgsValidInHapMode shared-libs-path is invalid!"); + return false; + } + + if (!utility.getJarPath().isEmpty() + && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode jar-path is invalid!"); + return false; + } + + if (!utility.getTxtPath().isEmpty() + && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHapMode txt-path is invalid!"); + return false; + } + + if (!utility.getPackInfoPath().isEmpty() && !isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { + LOG.error("CompressVerify::isArgsValidInHapMode pack-info-path is invalid!"); + return false; + } + + return isOutPathValid(utility, HAP_SUFFIX); + } + + /** + * check hap path if valid + * + * @param path path input + * @return isPathValid if path verify + */ + private static boolean isHapPathValid(String path) { + return (!path.isEmpty() && !isPathValid(path, TYPE_DIR, null)); + } + + /** + * parse and check args if valid in har mode. + * + * @param utility common data + * @return isVerifyValidInHarMode if verify valid in har mode. + */ + private static boolean isVerifyValidInHarMode(Utility utility) { + if (utility.getJsonPath().isEmpty() || !isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE)) { + LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file!"); + return false; + } + + if (!utility.getJarPath().isEmpty() + && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid!"); + return false; + } + + if (!utility.getTxtPath().isEmpty() + && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid!"); + return false; + } + + if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid!"); + return false; + } + + if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid!"); + return false; + } + + if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid!"); + return false; + } + + if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid!"); + return false; + } + + return isOutPathValid(utility, HAR_SUFFIX); + } + + /** + * parse and check args if valid in app mode. + * + * @param utility common data + * @return isVerifyValidInAppMode if verify valid in app mode. + */ + private static boolean isVerifyValidInAppMode(Utility utility) { + if (utility.getHapPath().isEmpty()) { + LOG.error("CompressVerify::isArgsValidInAppMode hap-path is empty!"); + return false; + } + + if (!compatibleProcess(utility, utility.getHapPath(), utility.getFormattedHapPathList(), HAP_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInAppMode hap-path is invalid!"); + return false; + } + + if (utility.getPackInfoPath().isEmpty()) { + LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty!"); + return false; + } + + File file = new File(utility.getPackInfoPath()); + if (!file.isFile() || !file.getName().equals(PACK_INFO)) { + LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is invalid!"); + return false; + } + + if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { + LOG.error("CompressVerify::isArgsValidInAppMode signature-path is invalid!"); + return false; + } + + if (!utility.getCertificatePath().isEmpty() && !(new File(utility.getCertificatePath())).isFile()) { + LOG.error("CompressVerify::isArgsValidInAppMode certificate-path is invalid!"); + return false; + } + + if (!utility.getEntryCardPath().isEmpty() && + !compatibleProcess(utility, utility.getEntryCardPath(), + utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInAppMode entrycard-path is invalid!"); + return false; + } + if (!utility.getPackResPath().isEmpty() && !isPathValid(utility.getPackResPath(), TYPE_FILE, PACK_RES)) { + LOG.error("CompressVerify::isArgsValidInAppMode pack-res-path is invalid!:" ); + return false; + } + + return isOutPathValid(utility, APP_SUFFIX); + } + + + /** + * parse and check args if valid in res mode. + * + * @param utility common data + * @return isVerifyValidInAppMode if verify valid in app mode. + */ + private static boolean isVerifyValidInResMode(Utility utility) { + if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { + LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid!"); + return false; + } + + if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { + LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + + ", current is " + utility.getEntryCardPath()); + return false; + } + if (!compatibleProcess(utility, utility.getEntryCardPath(), + utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { + LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid!"); + return false; + } + return isOutPathValid(utility, RES_SUFFIX); + } + + + /** + * Compatible file input and directory input + * + * @param utility common data + * @param inputPath input path + * @param fileList save files' path with list + * @param suffix process type + * @return Returns {@code true} if the compatible is successful; returns {@code false} otherwise. + */ + private static boolean compatibleProcess(Utility utility, String inputPath, + List fileList, String suffix) { + if (isPathValid(inputPath, TYPE_DIR, null)) { + File inputFile = new File(inputPath); + File[] files = inputFile.listFiles(); + if (files == null) { + return true; + } + for (File fileItem : files) { + if (fileItem.getName().toLowerCase(Locale.ENGLISH).endsWith(suffix)) { + fileList.add(fileItem.toString()); + } + } + return true; + } else { + String formattedPathItem = ""; + List pathList = removeDuplicatePath(inputPath); + for (String pathItem : pathList) { + formattedPathItem = utility.getFormattedPath(pathItem); + if (!isPathValid(formattedPathItem, TYPE_FILE, suffix)) { + return false; + } + fileList.add(formattedPathItem); + } + return true; + } + } + + /** + * turn input path block to formatted path list + * + * @param utility common data + * @param suffix used to determine type + * @return isVerifyValidInAppMode if verify valid in app mode. + */ + private static boolean isOutPathValid(Utility utility, String suffix) { + File outFile = new File(utility.getOutPath()); + + if (("false".equals(utility.getForceRewrite())) && (outFile.exists())) { + LOG.error("CompressVerify::isOutPathValid out file already existed!"); + return false; + } + + if (HAP_SUFFIX.equals(suffix)) { + if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { + LOG.error("CompressVerify::isOutPathValid out-path must end with .hap!"); + return false; + } else { + return true; + } + } + + if (HAR_SUFFIX.equals(suffix)) { + if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAR_SUFFIX)) { + LOG.error("CompressVerify::isOutPathValid out-path must end with .har!"); + return false; + } else { + return true; + } + } + + if (APP_SUFFIX.equals(suffix)) { + if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { + LOG.error("CompressVerify::isOutPathValid out-path must end with .app!"); + return false; + } else { + return true; + } + } + + if (RES_SUFFIX.equals(suffix)) { + if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(RES_SUFFIX)) { + LOG.error("CompressVerify::isOutPathValid out-path must end with .res!"); + return false; + } else { + return true; + } + } + + return false; + } + + /** + * check path if valid + * + * @param path path input + * @param isFile type input + * @param flag flag input + * @return isPathValid if path verify + */ + private static boolean isPathValid(String path, boolean isFile, String flag) { + File file = new File(path); + if (isFile && (file.isFile()) && file.getName().toLowerCase(Locale.ENGLISH).endsWith(flag)) { + return true; + } + return (!isFile) && file.isDirectory(); + } + + private static boolean isDirectoryValidStrictCase(String path, String directoryName) { + File file = new File(path); + if (!file.exists()) { + LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " + + path); + return false; + } + if (file.isDirectory()) { + return directoryName.equals(file.getName()); + } + return false; + } + + /** + * remove duplicate in path. + * + * @param path input path, use comma separate. + * @return result list + */ + private static List removeDuplicatePath(String path) { + String[] array = path.split(COMMA_SPLIT); + List list = new ArrayList<>(); + + for (String item : array) { + if (!list.contains(item)) { + list.add(item); + } + } + return list; + } +} diff --git a/com/huawei/ohos/Compressor.java b/adapter/ohos/Compressor.java old mode 100755 new mode 100644 similarity index 99% rename from com/huawei/ohos/Compressor.java rename to adapter/ohos/Compressor.java index 1020310c5d0b7115f5062e26a07e46b77b74641f..1e3a5d2bd23fe6e80802c7bf7ab8d7e285369f30 --- a/com/huawei/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import java.io.BufferedOutputStream; import java.io.BufferedInputStream; @@ -44,8 +44,6 @@ import java.util.Arrays; /** * bundle compressor class, compress file and directory. * - * @author huzeqi - * @since 2019-10-25 */ public class Compressor { private static final String JSON_SUFFIX = ".json"; diff --git a/com/huawei/ohos/ConvertHapToBin.java b/adapter/ohos/ConvertHapToBin.java old mode 100755 new mode 100644 similarity index 98% rename from com/huawei/ohos/ConvertHapToBin.java rename to adapter/ohos/ConvertHapToBin.java index dbf07583178861dd0c2414e793ac6d4dd24f27c8..9a87eb57b79edfac51a6379bd7f87c99c744922c --- a/com/huawei/ohos/ConvertHapToBin.java +++ b/adapter/ohos/ConvertHapToBin.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import java.io.File; import java.io.IOException; @@ -22,8 +22,6 @@ import java.util.Optional; /** * hap package to bin package tool main class. * - * @author panxurong - * @since 2020-05-06 */ public class ConvertHapToBin { private static final String HAP_PATH = "--hap-path"; diff --git a/com/huawei/ohos/CountryCode.java b/adapter/ohos/CountryCode.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/CountryCode.java rename to adapter/ohos/CountryCode.java index 3adc6c73ea07fe0ac3c24c4a7882eab8f7ab9b38..c5415f5d77f7e9bad85c3a3a93b7dcf41a6b6f61 --- a/com/huawei/ohos/CountryCode.java +++ b/adapter/ohos/CountryCode.java @@ -1,38 +1,36 @@ -/* - * 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 com.huawei.ohos; - -import java.util.List; -import java.util.ArrayList; - -/** - * - * CountryCode info - * - * @author weiguang - * @since 2021-02-02 - */ -public class CountryCode { - /** - * CountryCode policy - */ - public String policy ; - - /** - * CountryCode value list - */ - public List value = null; -} +/* + * 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.List; +import java.util.ArrayList; + +/** + * + * CountryCode info + * + */ +public class CountryCode { + /** + * CountryCode policy + */ + public String policy ; + + /** + * CountryCode value list + */ + public List value = null; +} diff --git a/com/huawei/ohos/CustomizeData.java b/adapter/ohos/CustomizeData.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/CustomizeData.java rename to adapter/ohos/CustomizeData.java index 68eccf0339dfca6b3359d94b87bf1477ac38063d..968eb436cf616503c0f69b8341e02dbb0116553f --- a/com/huawei/ohos/CustomizeData.java +++ b/adapter/ohos/CustomizeData.java @@ -1,39 +1,37 @@ -/* - * 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 com.huawei.ohos; - -/** - * Customize data info. - * - * @author dingyao - * @since 2020-05-20 - */ -public class CustomizeData { - /** - * Indicates the name of MetaDataInfo. - */ - public String name = ""; - - /** - * Indicates the value of MetaDataInfo. - */ - public String value = ""; - - /** - * Indicates the extra of MetaDataInfo. - */ - public String extra = ""; +/* + * 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; + +/** + * Customize data info. + * + */ +public class CustomizeData { + /** + * Indicates the name of MetaDataInfo. + */ + public String name = ""; + + /** + * Indicates the value of MetaDataInfo. + */ + public String value = ""; + + /** + * Indicates the extra of MetaDataInfo. + */ + public String extra = ""; } \ No newline at end of file diff --git a/com/huawei/ohos/DefPermission.java b/adapter/ohos/DefPermission.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/DefPermission.java rename to adapter/ohos/DefPermission.java index 39f8548a4f0c527de560317c636c9271b881e507..7e066491edfc8a305508d7b6fb38151c3173a491 --- a/com/huawei/ohos/DefPermission.java +++ b/adapter/ohos/DefPermission.java @@ -1,54 +1,52 @@ -/* - * 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 com.huawei.ohos; - -/** - * DefPermission info. - * - * @author dingyao - * @since 2020-05-20 - */ -public class DefPermission { - /** - * Indicates the name of DefPermission. - */ - public String name = ""; - - /** - * Indicates the grantMode of DefPermission. - */ - public String grantMode = ""; - - /** - * Indicates the availableScope of DefPermission. - */ - public String availableScope = ""; - - /** - * Indicates the group of DefPermission. - */ - public String group = ""; - - /** - * Indicates the label of DefPermission. - */ - public String label = ""; - - /** - * Indicates the description of DefPermission. - */ - public String description = ""; +/* + * 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; + +/** + * DefPermission info. + * + */ +public class DefPermission { + /** + * Indicates the name of DefPermission. + */ + public String name = ""; + + /** + * Indicates the grantMode of DefPermission. + */ + public String grantMode = ""; + + /** + * Indicates the availableScope of DefPermission. + */ + public String availableScope = ""; + + /** + * Indicates the group of DefPermission. + */ + public String group = ""; + + /** + * Indicates the label of DefPermission. + */ + public String label = ""; + + /** + * Indicates the description of DefPermission. + */ + public String description = ""; } \ No newline at end of file diff --git a/com/huawei/ohos/DefPermissionGroup.java b/adapter/ohos/DefPermissionGroup.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/DefPermissionGroup.java rename to adapter/ohos/DefPermissionGroup.java index 853a9a57ab8978ef8b4d4d9ce8640ea0a7ef666a..1078ecae8591bee5840ed308be833a7d7f1633c6 --- a/com/huawei/ohos/DefPermissionGroup.java +++ b/adapter/ohos/DefPermissionGroup.java @@ -1,54 +1,52 @@ -/* - * 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 com.huawei.ohos; - -/** - * DefPermissionGroup info. - * - * @author dingyao - * @since 2020-05-20 - */ -public class DefPermissionGroup { - /** - * Indicates the name of DefPermissionGroup. - */ - public String name = ""; - - /** - * Indicates the order of DefPermissionGroup. - */ - public String order = ""; - - /** - * Indicates the icon of DefPermissionGroup. - */ - public String icon = ""; - - /** - * Indicates the label of DefPermissionGroup. - */ - public String label = ""; - - /** - * Indicates the description of DefPermissionGroup. - */ - public String description = ""; - - /** - * Indicates the request of DefPermissionGroup. - */ - public String request = ""; +/* + * 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; + +/** + * DefPermissionGroup info. + * + */ +public class DefPermissionGroup { + /** + * Indicates the name of DefPermissionGroup. + */ + public String name = ""; + + /** + * Indicates the order of DefPermissionGroup. + */ + public String order = ""; + + /** + * Indicates the icon of DefPermissionGroup. + */ + public String icon = ""; + + /** + * Indicates the label of DefPermissionGroup. + */ + public String label = ""; + + /** + * Indicates the description of DefPermissionGroup. + */ + public String description = ""; + + /** + * Indicates the request of DefPermissionGroup. + */ + public String request = ""; } \ No newline at end of file diff --git a/com/huawei/ohos/DeviceConfig.java b/adapter/ohos/DeviceConfig.java old mode 100755 new mode 100644 similarity index 92% rename from com/huawei/ohos/DeviceConfig.java rename to adapter/ohos/DeviceConfig.java index c8de6ce885db0cdeff09712a735e8d9a2f3689ad..2c2180543080ed1661328a6c5f80650aae4b6c8e --- a/com/huawei/ohos/DeviceConfig.java +++ b/adapter/ohos/DeviceConfig.java @@ -1,64 +1,62 @@ -/* - * 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 com.huawei.ohos; - -/** - * App DeviceConfig info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class DeviceConfig { - /** - * Indicates the target request Sdk Version of app DeviceConfig. - */ - public String targetReqSdk = ""; - - /** - * Indicates the compatible request Sdk Version of app DeviceConfig. - */ - public String compatibleReqSdk = ""; - - /** - * Indicates the jointUserid of app DeviceConfig. - */ - public String jointUserid = ""; - - /** - * Indicates the process of app DeviceConfig. - */ - public String process = ""; - - /** - * Indicates the arkFlag of app DeviceConfig. - */ - public String arkFlag = ""; - - /** - * Indicates the targetArkVersion of app DeviceConfig. - */ - public String targetArkVersion = ""; - - /** - * Indicates the compatibleArkVersion of app DeviceConfig. - */ - public String compatibleArkVersion = ""; - - /** - * Indicates the directLaunch of app DeviceConfig. - */ - public boolean directLaunch = false; -} +/* + * 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; + +/** + * App DeviceConfig info. + * + */ +public class DeviceConfig { + /** + * Indicates the target request Sdk Version of app DeviceConfig. + */ + public String targetReqSdk = ""; + + /** + * Indicates the compatible request Sdk Version of app DeviceConfig. + */ + public String compatibleReqSdk = ""; + + /** + * Indicates the jointUserid of app DeviceConfig. + */ + public String jointUserid = ""; + + /** + * Indicates the process of app DeviceConfig. + */ + public String process = ""; + + /** + * Indicates the arkFlag of app DeviceConfig. + */ + public String arkFlag = ""; + + /** + * Indicates the targetArkVersion of app DeviceConfig. + */ + public String targetArkVersion = ""; + + /** + * Indicates the compatibleArkVersion of app DeviceConfig. + */ + public String compatibleArkVersion = ""; + + /** + * Indicates the directLaunch of app DeviceConfig. + */ + public boolean directLaunch = false; +} diff --git a/com/huawei/ohos/Distro.java b/adapter/ohos/Distro.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/Distro.java rename to adapter/ohos/Distro.java index c7851f176c1e85f869aa065bdc71fbd4005d72dd..67c08baa49b879e8f3215f3f5764d02a7de80321 --- a/com/huawei/ohos/Distro.java +++ b/adapter/ohos/Distro.java @@ -1,44 +1,42 @@ -/* - * 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 com.huawei.ohos; - -/** - * Distro info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class Distro { - /** - * Indicates the moduleName of Distro. - */ - public String moduleName = ""; - - /** - * Indicates the moduleType of Distro. - */ - public String moduleType = ""; - - /** - * Indicates the deliveryWithInstall of Distro. - */ - public boolean deliveryWithInstall = false; - - /** - * Indicates the installationFree of Distro. - */ - public int installationFree = 2; +/* + * 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; + +/** + * Distro info. + * + */ +public class Distro { + /** + * Indicates the moduleName of Distro. + */ + public String moduleName = ""; + + /** + * Indicates the moduleType of Distro. + */ + public String moduleType = ""; + + /** + * Indicates the deliveryWithInstall of Distro. + */ + public boolean deliveryWithInstall = false; + + /** + * Indicates the installationFree of Distro. + */ + public int installationFree = 2; } \ No newline at end of file diff --git a/com/huawei/ohos/DistroFilter.java b/adapter/ohos/DistroFilter.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/DistroFilter.java rename to adapter/ohos/DistroFilter.java index d8b4b02ae7b50d4840931f128e95f272b0574552..7e857c535bc1bf0663f88f28a8272673d40fe551 --- a/com/huawei/ohos/DistroFilter.java +++ b/adapter/ohos/DistroFilter.java @@ -1,50 +1,48 @@ -/* - * 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 com.huawei.ohos; - -/** - * DistroFilter info - * - * @author weiguang - * @since 2021-02-02 - */ -public class DistroFilter { - /** - * Indicates the DistroFilter info ApiVersion - */ - public ApiVersion apiVersion = null; - - /** - * Indicates the DistroFilter info ScreenShape - */ - public ScreenShape screenShape = null; - - /** - * Indicates the DistroFilter info ScreenDensity - */ - public ScreenDensity screenDensity = null; - - /** - * Indicates the DistroFilter info ScreenWindow - */ - public ScreenWindow screenWindow = null; - - /** - * Indicates the DistroFilter info CountryCode - */ - public CountryCode countryCode = null; - +/* + * 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; + +/** + * DistroFilter info + * + */ +public class DistroFilter { + /** + * Indicates the DistroFilter info ApiVersion + */ + public ApiVersion apiVersion = null; + + /** + * Indicates the DistroFilter info ScreenShape + */ + public ScreenShape screenShape = null; + + /** + * Indicates the DistroFilter info ScreenDensity + */ + public ScreenDensity screenDensity = null; + + /** + * Indicates the DistroFilter info ScreenWindow + */ + public ScreenWindow screenWindow = null; + + /** + * Indicates the DistroFilter info CountryCode + */ + public CountryCode countryCode = null; + } \ No newline at end of file diff --git a/com/huawei/ohos/FileUtils.java b/adapter/ohos/FileUtils.java old mode 100755 new mode 100644 similarity index 99% rename from com/huawei/ohos/FileUtils.java rename to adapter/ohos/FileUtils.java index c4758cb49babd87962cb47a606af813559ac2de4..21c42fb450feaeb841aabdc44c5d774037790657 --- a/com/huawei/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import ohos.utils.fastjson.JSONObject; @@ -36,8 +36,6 @@ import java.util.zip.ZipFile; /** * file tools * - * @author panxurong - * @since 2020-02-14 */ public class FileUtils { private static final int BUFFER_SIZE = 1024; diff --git a/com/huawei/ohos/FormInfo.java b/adapter/ohos/FormInfo.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/FormInfo.java rename to adapter/ohos/FormInfo.java index 52c560aef71b73e4102e461af9e13c316ef954a7..052e41770982de0482f5066bf28a5fbcbe5a6a1c --- a/com/huawei/ohos/FormInfo.java +++ b/adapter/ohos/FormInfo.java @@ -1,52 +1,50 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * Form info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class FormInfo { - /** - * Indicates the formEntity of formInfo. - */ - public List formEntity = new ArrayList(); - - /** - * Indicates the minHeight of formInfo. - */ - public String minHeight = ""; - - /** - * Indicates the defaultHeight of formInfo. - */ - public String defaultHeight = ""; - - /** - * Indicates the minWidth of formInfo. - */ - public String minWidth = ""; - - /** - * Indicates the defaultWidth of formInfo. - */ - public String defaultWidth = ""; +/* + * 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; + +/** + * Form info. + * + */ +public class FormInfo { + /** + * Indicates the formEntity of formInfo. + */ + public List formEntity = new ArrayList(); + + /** + * Indicates the minHeight of formInfo. + */ + public String minHeight = ""; + + /** + * Indicates the defaultHeight of formInfo. + */ + public String defaultHeight = ""; + + /** + * Indicates the minWidth of formInfo. + */ + public String minWidth = ""; + + /** + * Indicates the defaultWidth of formInfo. + */ + public String defaultWidth = ""; } \ No newline at end of file diff --git a/com/huawei/ohos/HapInfo.java b/adapter/ohos/HapInfo.java old mode 100755 new mode 100644 similarity index 93% rename from com/huawei/ohos/HapInfo.java rename to adapter/ohos/HapInfo.java index 1b3be205dd33714737e735db1ece5c03c676c1c5..98444b8abfd57b5baab78ce415ef0047eab63388 --- a/com/huawei/ohos/HapInfo.java +++ b/adapter/ohos/HapInfo.java @@ -1,108 +1,106 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * Hap info. - * - * @author dingyao - * @since 2020-04-22 - */ -public class HapInfo { - /** - * Indicates the package of HapInfo. - */ - public String packageStr = ""; - - /** - * Indicates the name of HapInfo. - */ - public String name = ""; - - /** - * Indicates the description of HapInfo. - */ - public String description = ""; - - /** - * Indicates the supportedModes of HapInfo. - */ - public List supportedModes = new ArrayList(); - - /** - * Indicates the abilities of HapInfo. - */ - public List abilities = new ArrayList(); - - /** - * Indicates the defPermissions of HapInfo. - */ - public List defPermissions = new ArrayList(); - - /** - * Indicates the defPermissionsGroups of HapInfo. - */ - public List defPermissionsGroups = new ArrayList(); - - /** - * Indicates the distro of HapInfo. - */ - public Distro distro = null; - - /** - * Indicates the reqCapabilities of HapInfo. - */ - public List reqCapabilities = new ArrayList(); - - /** - * Indicates the deviceType of HapInfo. - */ - public List deviceType = new ArrayList(); - - /** - * Indicates the metaData of HapInfo. - */ - public MetaData metaData = new MetaData(); - - /** - * Indicates the HapInfo is Js app. - */ - public boolean isJs = false; - - /** - * Indicates the reqPermissions of HapInfo. - */ - public List reqPermissions = new ArrayList(); - - /** - * Indicates the commonEvents of HapInfo. - */ - public List commonEvents = new ArrayList(); - - /** - * Indicates the shortcuts of HapInfo. - */ - public List shortcuts = new ArrayList(); - - /** - * Indicates the DistroFilter of HapInfo - */ - public DistroFilter distroFilter = new DistroFilter(); - -} +/* + * 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; + +/** + * Hap info. + * + */ +public class HapInfo { + /** + * Indicates the package of HapInfo. + */ + public String packageStr = ""; + + /** + * Indicates the name of HapInfo. + */ + public String name = ""; + + /** + * Indicates the description of HapInfo. + */ + public String description = ""; + + /** + * Indicates the supportedModes of HapInfo. + */ + public List supportedModes = new ArrayList(); + + /** + * Indicates the abilities of HapInfo. + */ + public List abilities = new ArrayList(); + + /** + * Indicates the defPermissions of HapInfo. + */ + public List defPermissions = new ArrayList(); + + /** + * Indicates the defPermissionsGroups of HapInfo. + */ + public List defPermissionsGroups = new ArrayList(); + + /** + * Indicates the distro of HapInfo. + */ + public Distro distro = null; + + /** + * Indicates the reqCapabilities of HapInfo. + */ + public List reqCapabilities = new ArrayList(); + + /** + * Indicates the deviceType of HapInfo. + */ + public List deviceType = new ArrayList(); + + /** + * Indicates the metaData of HapInfo. + */ + public MetaData metaData = new MetaData(); + + /** + * Indicates the HapInfo is Js app. + */ + public boolean isJs = false; + + /** + * Indicates the reqPermissions of HapInfo. + */ + public List reqPermissions = new ArrayList(); + + /** + * Indicates the commonEvents of HapInfo. + */ + public List commonEvents = new ArrayList(); + + /** + * Indicates the shortcuts of HapInfo. + */ + public List shortcuts = new ArrayList(); + + /** + * Indicates the DistroFilter of HapInfo + */ + public DistroFilter distroFilter = new DistroFilter(); + +} diff --git a/com/huawei/ohos/HapZipInfo.java b/adapter/ohos/HapZipInfo.java old mode 100755 new mode 100644 similarity index 93% rename from com/huawei/ohos/HapZipInfo.java rename to adapter/ohos/HapZipInfo.java index 5e26f5c003dadaab855d38a3fce04d6440ec580d..432a845264285584c9ed6995c00cd85bc56e4afc --- a/com/huawei/ohos/HapZipInfo.java +++ b/adapter/ohos/HapZipInfo.java @@ -1,101 +1,99 @@ -/* - * 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 com.huawei.ohos; - -/** - * Hap zip info - * - * @author yaoyanbing - * @since 2021-03-16 - */ -class HapZipInfo { - private byte[] resDataBytes; - private String harmonyProfileJsonStr = ""; - private String packInfoJsonStr = ""; - private String hapFileName = ""; - - /** - * Get resource data bytes. - * - * @return resource data bytes. - */ - public byte[] getResDataBytes() { - return resDataBytes; - } - - /** - * Set resource data bytes. - * - * @param resDataBytes Indicates the resource data bytes. - */ - public void setResDataBytes(byte[] resDataBytes) { - this.resDataBytes = resDataBytes; - } - - /** - * Get harmony profile json string. - * - * @return harmony profile json string. - */ - public String getHarmonyProfileJsonStr() { - return harmonyProfileJsonStr; - } - - /** - * Set harmony profile json string. - * - * @param harmonyProfileJsonStr Indicates harmony profile json string. - */ - public void setHarmonyProfileJsonStr(String harmonyProfileJsonStr) { - this.harmonyProfileJsonStr = harmonyProfileJsonStr; - } - - /** - * Get pack.info json string. - * - * @return pack.info json string. - */ - public String getPackInfoJsonStr() { - return packInfoJsonStr; - } - - /** - * Set pack.info json string. - * - * @param packInfoJsonStr Indicates the pack.info json string. - */ - public void setPackInfoJsonStr(String packInfoJsonStr) { - this.packInfoJsonStr = packInfoJsonStr; - } - - /** - * Get hap file name. - * - * @return hap file name. - */ - public String getHapFileName() { - return hapFileName; - } - - /** - * Set hap file name. - * - * @param hapFileName Indicates the hap file name. - */ - public void setHapFileName(String hapFileName) { - this.hapFileName = hapFileName; - } -} +/* + * 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; + +/** + * Hap zip info + * + */ +class HapZipInfo { + private byte[] resDataBytes; + private String harmonyProfileJsonStr = ""; + private String packInfoJsonStr = ""; + private String hapFileName = ""; + + /** + * Get resource data bytes. + * + * @return resource data bytes. + */ + public byte[] getResDataBytes() { + return resDataBytes; + } + + /** + * Set resource data bytes. + * + * @param resDataBytes Indicates the resource data bytes. + */ + public void setResDataBytes(byte[] resDataBytes) { + this.resDataBytes = resDataBytes; + } + + /** + * Get harmony profile json string. + * + * @return harmony profile json string. + */ + public String getHarmonyProfileJsonStr() { + return harmonyProfileJsonStr; + } + + /** + * Set harmony profile json string. + * + * @param harmonyProfileJsonStr Indicates harmony profile json string. + */ + public void setHarmonyProfileJsonStr(String harmonyProfileJsonStr) { + this.harmonyProfileJsonStr = harmonyProfileJsonStr; + } + + /** + * Get pack.info json string. + * + * @return pack.info json string. + */ + public String getPackInfoJsonStr() { + return packInfoJsonStr; + } + + /** + * Set pack.info json string. + * + * @param packInfoJsonStr Indicates the pack.info json string. + */ + public void setPackInfoJsonStr(String packInfoJsonStr) { + this.packInfoJsonStr = packInfoJsonStr; + } + + /** + * Get hap file name. + * + * @return hap file name. + */ + public String getHapFileName() { + return hapFileName; + } + + /** + * Set hap file name. + * + * @param hapFileName Indicates the hap file name. + */ + public void setHapFileName(String hapFileName) { + this.hapFileName = hapFileName; + } +} diff --git a/com/huawei/ohos/IntentInfo.java b/adapter/ohos/IntentInfo.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/IntentInfo.java rename to adapter/ohos/IntentInfo.java index 5a1410945d9d1255b76a2e4d320252b31c67a05a..3c00109daaac58538d3fd0f21c7f8dd82db93746 --- a/com/huawei/ohos/IntentInfo.java +++ b/adapter/ohos/IntentInfo.java @@ -1,34 +1,32 @@ -/* - * 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 com.huawei.ohos; - -/** - * App IntentInfo info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class IntentInfo { - /** - * Indicates the targetClass of app IntentInfo. - */ - public String targetClass = ""; - - /** - * Indicates the targetBundle of app IntentInfo. - */ - public String targetBundle = ""; -} +/* + * 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; + +/** + * App IntentInfo info. + * + */ +public class IntentInfo { + /** + * Indicates the targetClass of app IntentInfo. + */ + public String targetClass = ""; + + /** + * Indicates the targetBundle of app IntentInfo. + */ + public String targetBundle = ""; +} diff --git a/com/huawei/ohos/JsInfo.java b/adapter/ohos/JsInfo.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/JsInfo.java rename to adapter/ohos/JsInfo.java index e8f2e2652f8ee3400f43eb342f9ad66d059b8507..876884404ad373a7edc142ed2240a20418f03c53 --- a/com/huawei/ohos/JsInfo.java +++ b/adapter/ohos/JsInfo.java @@ -1,42 +1,40 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * JS Module info. - * - * @author dingyao - * @since 2020-06-04 - */ -public class JsInfo { - /** - * Indicates the name of JS Module. - */ - public String name = ""; - - /** - * Indicates the window style of JS Module. - */ - public String window = ""; - - /** - * Indicates the pages of JS Module. - */ - public List pages = new ArrayList(); +/* + * 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; + +/** + * JS Module info. + * + */ +public class JsInfo { + /** + * Indicates the name of JS Module. + */ + public String name = ""; + + /** + * Indicates the window style of JS Module. + */ + public String window = ""; + + /** + * Indicates the pages of JS Module. + */ + public List pages = new ArrayList(); } \ No newline at end of file diff --git a/com/huawei/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java old mode 100755 new mode 100644 similarity index 97% rename from com/huawei/ohos/JsonUtil.java rename to adapter/ohos/JsonUtil.java index 40ced5982e000c2fad2285de6d2bfdf6d439159f..4824b15944c45afc6486b0f5ba6ce341140d4ec1 --- a/com/huawei/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -1,602 +1,600 @@ -/* - * 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 com.huawei.ohos; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.HashMap; -import java.util.Map; -import java.util.Locale; - -import ohos.utils.fastjson.JSONObject; -import ohos.utils.fastjson.JSONArray; - -/** - * Json Util. - * - * @author dingyao - * @since 2020-05-20 - */ -public class JsonUtil { - private static final String DEVICE_TYPE = "device-type"; - private static final String NAME = "name"; - private static final String MODULE_TYPE = "module-type"; - private static final String INSTALL_FLAG = "delivery-with-install"; - private static final String DEVICE_TYPE_NEW = "deviceType"; - private static final String MODULE_TYPE_NEW = "moduleType"; - private static final String INSTALL_FLAG_NEW = "deliveryWithInstall"; - private static final String ASSETS_DIR_NAME = "assets/"; - private static final Log LOG = new Log(JsonUtil.class.toString()); - - private static final String SUMMARY = "summary"; - private static final String APP = "app"; - private static final String VERSION = "version"; - private static final String LEGACY_VERSION_CODE = "legacyVersionCode"; - private static final String LEGACY_VERSION_NAME = "legacyVersionName"; - private static final String MULTI_FRAMEWORK_BUNDLE = "multiFrameworkBundle"; - - /** - * parse hap list by device type - * - * @param deviceType target deviceType - * @param jsonString uncompress json String - * @return the parseHapList result - * @throws BundleException Throws this exception if the json is not standard. - */ - static List parseHapList(String deviceType, String jsonString) throws BundleException { - List packInfos = new ArrayList(); - JSONObject jsonObject = JSONObject.parseObject(jsonString); - if (jsonObject == null || !jsonObject.containsKey("packages")) { - LOG.error("Uncompress::parseHapList exception: packages is null"); - throw new BundleException("Parse hap list failed, packages is null"); - } - JSONArray jsonList = JSONArray.parseArray(getJsonString(jsonObject, "packages")); - if (jsonList == null) { - LOG.error("Uncompress::parseHapList exception: packages is null"); - throw new BundleException("Parse hap list failed, packages is null"); - } - int jsonListSize = jsonList.size(); - for (int i = 0; i < jsonListSize; i++) { - JSONObject tmpObj = jsonList.getJSONObject(i); - String deviceTypes = getJsonString(tmpObj, DEVICE_TYPE); - if (deviceTypes == null || "".equals(deviceTypes)) { - deviceTypes = getJsonString(tmpObj, DEVICE_TYPE_NEW); - } - if (deviceTypes != null && deviceTypes.toLowerCase(Locale.ENGLISH).contains( - deviceType.toLowerCase(Locale.ENGLISH))) { - PackInfo packInfo = new PackInfo(); - packInfo.name = getJsonString(tmpObj, NAME); - packInfo.moduleType = getJsonString(tmpObj, MODULE_TYPE); - if (packInfo.moduleType == null || "".equals(packInfo.moduleType)) { - packInfo.moduleType = getJsonString(tmpObj, MODULE_TYPE_NEW); - } - packInfo.deviceType = JSONArray.parseArray(deviceTypes, String.class); - String deliveryWithInstall = getJsonString(tmpObj, INSTALL_FLAG); - if (deliveryWithInstall == null || "".equals(deliveryWithInstall)) { - deliveryWithInstall = getJsonString(tmpObj, INSTALL_FLAG_NEW); - } - packInfo.deliveryWithInstall = Boolean.parseBoolean(deliveryWithInstall); - packInfos.add(packInfo); - } - } - return packInfos; - } - - private static boolean parseShellVersionInfoToAppInfo(String packInfoJsonStr, AppInfo appInfo) { - LOG.info("Uncompress::parseShellVersionInfoToAppInfo: begin"); - if (!appInfo.isMultiFrameworkBundle()) { - LOG.info("Uncompress::parseShellVersionInfoToAppInfo: is not a multi framewok bundle."); - return false; - } - - JSONObject jsonObject = JSONObject.parseObject(packInfoJsonStr); - if (jsonObject == null) { - LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: summary is null"); - return false; - } - - JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); - if (summaryJson == null) { - LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: summary is null"); - return false; - } - JSONObject appJson = summaryJson.getJSONObject(APP); - if (appJson == null) { - LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: app is null"); - return false; - } - JSONObject versionJson = appJson.getJSONObject(VERSION); - if (versionJson == null) { - LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: version is null"); - return false; - } - - if (!versionJson.containsKey(LEGACY_VERSION_CODE) || !versionJson.containsKey(LEGACY_VERSION_NAME)) { - LOG.error("Uncompress::parseShellVersionInfoToAppInfo no legacy version info."); - return false; - } - appInfo.setShellVersionCode(versionJson.getString(LEGACY_VERSION_CODE)); - appInfo.setShellVersionName(versionJson.getString(LEGACY_VERSION_NAME)); - return true; - } - - /** - * parse hap profile info - * - * @param harmonyProfileJsonString uncompress json String - * @param data resource index data - * @param paclInfoJsonString pack.info json String - * @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 { - ProfileInfo profileInfo = new ProfileInfo(); - JSONObject jsonObject = JSONObject.parseObject(harmonyProfileJsonString); - if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey("deviceConfig") - || !jsonObject.containsKey("module")) { - LOG.error("Uncompress::parseProfileInfo exception: app, deviceConfig or module is null"); - throw new BundleException("Parse profile info failed, app, deviceConfig or module is null"); - } - if (jsonObject.containsKey(APP)) { - JSONObject appJson = jsonObject.getJSONObject(APP); - profileInfo.appInfo = parseAppInfo(appJson); - } - if (jsonObject.containsKey("module")) { - JSONObject hapJson = jsonObject.getJSONObject("module"); - profileInfo.hapInfo = parseHapInfo(hapJson, data); - } - if (jsonObject.containsKey("deviceConfig")) { - JSONObject deviceConfigJson = jsonObject.getJSONObject("deviceConfig"); - profileInfo.deviceConfig = parseDeviceConfigInfo(deviceConfigJson, profileInfo.hapInfo.deviceType); - } - - if (profileInfo.hapInfo.abilities.size() == 1) { - profileInfo.appInfo.appName = profileInfo.hapInfo.abilities.get(0).label; - profileInfo.appInfo.appNameEN = profileInfo.hapInfo.abilities.get(0).label; - } else { - for (AbilityInfo abilityInfo : profileInfo.hapInfo.abilities) { - boolean isLabel = false; - for (SkillInfo skill : abilityInfo.skills) { - if (skill.actions.contains("action.system.home") && skill.entities.contains("entity.system.home")) { - isLabel = true; - break; - } - } - if (isLabel) { - profileInfo.appInfo.appName = abilityInfo.label; - profileInfo.appInfo.appNameEN = abilityInfo.label; - break; - } - } - } - - if (!parseShellVersionInfoToAppInfo(paclInfoJsonString, profileInfo.appInfo)) { - profileInfo.appInfo.setDefaultShellVersion(); - } - return profileInfo; - } - - /** - * parse app info - * - * @param appJson global json Object - * @return the parseAppInfo result - * @throws BundleException Throws this exception if the json is not standard. - */ - static AppInfo parseAppInfo(JSONObject appJson) throws BundleException { - AppInfo appInfo = new AppInfo(); - if (appJson == null) { - LOG.error("Uncompress::parseAppInfo exception: appJson is null"); - throw new BundleException("Parse app info failed, appJson is null"); - } - appInfo.bundleName = getJsonString(appJson, "bundleName"); - appInfo.vendor = getJsonString(appJson, "vendor"); - appInfo.relatedBundleName = getJsonString(appJson, "relatedBundleName"); - if (appJson.containsKey(VERSION)) { - JSONObject version = appJson.getJSONObject(VERSION); - appInfo.versionName = getJsonString(version, "name"); - appInfo.versionCode = getJsonString(version, "code"); - } - if (appJson.containsKey("apiVersion")) { - JSONObject apiVersion = appJson.getJSONObject("apiVersion"); - appInfo.compatibleApiVersion = apiVersion.getIntValue("compatible"); - appInfo.targetApiVersion = apiVersion.getIntValue("target"); - appInfo.releaseType = getJsonString(apiVersion, "releaseType"); - } - appInfo.setMultiFrameworkBundle(appJson.getBooleanValue(MULTI_FRAMEWORK_BUNDLE)); - return appInfo; - } - - /** - * parse deviceConfig infos - * - * @param deviceConfigInfoJson deviceConfig json Object - * @param deviceTypes the deviceTypes of the hap - * @return the parseDeviceConfigInfo result - * @throws BundleException Throws this exception if the json is not standard. - */ - static Map parseDeviceConfigInfo(JSONObject deviceConfigInfoJson, - List deviceTypes) throws BundleException { - Map deviceConfigs = new HashMap<>(); - if (deviceConfigInfoJson == null) { - return deviceConfigs; - } - - DeviceConfig defaultConfig = new DeviceConfig(); - if (deviceConfigInfoJson.containsKey("default")) { - defaultConfig = parseDeviceConfig(deviceConfigInfoJson.getJSONObject("default"), - new DeviceConfig()); - } - - for (String deviceType : deviceTypes) { - getTargetDeviceConfig(deviceConfigs, deviceConfigInfoJson, defaultConfig, deviceType); - } - - if (deviceConfigs.isEmpty()) { - deviceConfigs.put(UncompressEntrance.DEVICE_TYPE_PHONE, defaultConfig); - } - - return deviceConfigs; - } - - /** - * parse deviceConfig infos - * - * @param deviceConfigs the parseDeviceConfigInfo result - * @param deviceConfigInfoJson deviceConfig json Object - * @param defaultConfig the default deviceConfig - * @param targetDeviceType the target deviceType - * @throws BundleException Throws this exception if the json is not standard. - */ - static void getTargetDeviceConfig(Map deviceConfigs, JSONObject deviceConfigInfoJson, - DeviceConfig defaultConfig, String targetDeviceType) throws BundleException { - if (deviceConfigInfoJson.containsKey(targetDeviceType)) { - DeviceConfig deviceConfig = parseDeviceConfig( - deviceConfigInfoJson.getJSONObject(targetDeviceType), defaultConfig); - deviceConfigs.put(targetDeviceType, deviceConfig); - } else { - deviceConfigs.put(targetDeviceType, defaultConfig); - } - } - - /** - * parse deviceConfig info - * - * @param deviceConfigJson deviceConfig json Object - * @param defaultConfig default deviceConfig - * @return the parseDeviceConfigInfo result - * @throws BundleException Throws this exception if the json is not standard. - */ - static DeviceConfig parseDeviceConfig(JSONObject deviceConfigJson, DeviceConfig defaultConfig) - throws BundleException { - DeviceConfig deviceConfig = new DeviceConfig(); - if (deviceConfigJson == null || defaultConfig == null) { - LOG.error("Uncompress::parseDeviceConfigInfo exception: deviceConfigJson or defaultConfig is null"); - throw new BundleException("Parse device config info failed, deviceConfigJson or defaultConfig is null"); - } - - deviceConfig.jointUserid = getJsonString(deviceConfigJson, "jointUserid", defaultConfig.jointUserid); - deviceConfig.process = getJsonString(deviceConfigJson, "process", defaultConfig.process); - - if (deviceConfigJson.containsKey("reqSdk")) { - JSONObject reqSdk = deviceConfigJson.getJSONObject("reqSdk"); - deviceConfig.compatibleReqSdk = getJsonString(reqSdk, "compatible", defaultConfig.compatibleReqSdk); - deviceConfig.targetReqSdk = getJsonString(reqSdk, "target", defaultConfig.targetReqSdk); - } - - if (deviceConfigJson.containsKey("ark")) { - JSONObject ark = deviceConfigJson.getJSONObject("ark"); - deviceConfig.arkFlag = getJsonString(ark, "flag", defaultConfig.arkFlag); - if (ark.containsKey("reqVersion")) { - JSONObject arkVersion = ark.getJSONObject("reqVersion"); - deviceConfig.targetArkVersion = getJsonString(arkVersion, "target", defaultConfig.targetArkVersion); - deviceConfig.compatibleArkVersion = getJsonString(arkVersion, "compatible", - defaultConfig.compatibleArkVersion); - } - } - - if (deviceConfigJson.containsKey("directLaunch")) { - deviceConfig.directLaunch = deviceConfigJson.getBoolean("directLaunch"); - } else { - deviceConfig.directLaunch = defaultConfig.directLaunch; - } - - return deviceConfig; - } - - /** - * parse hap info - * - * @param hapJson hap json Object - * @param data resource index data - * @return the parseHapInfo result - * @throws BundleException Throws this exception if the json is not standard. - */ - static HapInfo parseHapInfo(JSONObject hapJson, byte[] data) throws BundleException { - HapInfo hapInfo = new HapInfo(); - if (hapJson == null) { - LOG.error("Uncompress::parseHapInfo exception: hapJson is null"); - throw new BundleException("Parse hap info failed, hapJson is null"); - } - hapInfo.packageStr = getJsonString(hapJson, "package"); - hapInfo.name = getJsonString(hapJson, "name"); - hapInfo.description = getJsonString(hapJson, "description"); - - if (hapJson.containsKey("supportedModes")) { - hapInfo.supportedModes = JSONObject.parseArray(getJsonString(hapJson, "supportedModes"), - String.class); - } - - if (hapJson.containsKey("defPermissions")) { - hapInfo.defPermissions = JSONArray.parseArray(getJsonString(hapJson, "defPermissions"), - DefPermission.class); - } - - if (hapJson.containsKey("defPermissiongroups")) { - hapInfo.defPermissionsGroups = JSONArray.parseArray(getJsonString(hapJson, "defPermissiongroups"), - DefPermissionGroup.class); - } - - if (hapJson.containsKey("distro")) { - getDistro(hapJson, hapInfo); - } - - if (hapJson.containsKey("reqCapabilities")) { - hapInfo.reqCapabilities = JSONArray.parseArray(getJsonString(hapJson, "reqCapabilities"), - String.class); - } - - if (hapJson.containsKey("deviceType")) { - hapInfo.deviceType = JSONArray.parseArray(getJsonString(hapJson, "deviceType") - .replace(UncompressEntrance.DEVICE_TYPE_DEFAULT, UncompressEntrance.DEVICE_TYPE_PHONE), - String.class); - } - - if (hapJson.containsKey("metaData")) { - hapInfo.metaData = JSONObject.parseObject(getJsonString(hapJson, "metaData"), MetaData.class); - } - - if (hapJson.containsKey("js")) { - List jsInfos = JSONObject.parseArray(getJsonString(hapJson, "js"), JsInfo.class); - if (jsInfos != null && jsInfos.size() > 0) { - hapInfo.isJs = true; - } - } - - if (hapJson.containsKey("reqPermissions")) { - hapInfo.reqPermissions = JSONObject.parseArray(getJsonString(hapJson, "reqPermissions"), - ReqPermission.class); - } - - if (hapJson.containsKey("commonEvents")) { - hapInfo.commonEvents = JSONObject.parseArray(getJsonString(hapJson, "commonEvents"), - CommonEvent.class); - } - - if (hapJson.containsKey("shortcuts")) { - hapInfo.shortcuts = JSONObject.parseArray(getJsonString(hapJson, "shortcuts"), Shortcut.class); - } - - if (hapJson.containsKey("abilities")) { - JSONArray abilities = hapJson.getJSONArray("abilities"); - List abilitieList = new ArrayList(); - int abilitiesSize = abilities.size(); - for (int i = 0; i < abilitiesSize; i++) { - JSONObject tmpObj = abilities.getJSONObject(i); - abilitieList.add(parseAbility(tmpObj, data)); - } - hapInfo.abilities = abilitieList; - } - if (hapJson.containsKey("distroFilter")) { - hapInfo.distroFilter = JSONObject.parseObject(getJsonString(hapJson, "distroFilter"), DistroFilter.class); - } - return hapInfo; - } - - /** - * get distro - * - * @param hapJson hapJson json - * @param hapInfo hapInfo json object - */ - private static void getDistro(JSONObject hapJson, HapInfo hapInfo) { - JSONObject distroObj = hapJson.getJSONObject("distro"); - Distro distro = new Distro(); - distro.moduleName = getJsonString(distroObj, "moduleName"); - distro.moduleType = getJsonString(distroObj, "moduleType"); - distro.deliveryWithInstall = distroObj.getBoolean("deliveryWithInstall"); - if (distroObj.containsKey("installationFree")) { - boolean isFreeInstall = distroObj.getBoolean("installationFree"); - if (isFreeInstall) { - distro.installationFree = 1; - }else { - distro.installationFree = 0; - } - } else { - distro.installationFree = 2; - } - hapInfo.distro = distro; - } - - /** - * parse ability object. - * - * @param abilityJson ability json object - * @param data resource index data - * @return the parseAbility result - * @throws BundleException Throws this exception if the json is not standard. - */ - static AbilityInfo parseAbility(JSONObject abilityJson, byte[] data) throws BundleException { - if (abilityJson == null) { - LOG.error("Uncompress::parseAbility exception: abilityJson is null"); - throw new BundleException("Parse ability failed, abilityJson is null"); - } - AbilityInfo ability = new AbilityInfo(); - ability.name = getJsonString(abilityJson, "name"); - if (abilityJson.containsKey("iconId")) { - int iconId = abilityJson.getIntValue("iconId"); - String iconPath = ResourcesParser.getResourceById(iconId, data); - if (iconPath != null && !iconPath.isEmpty()) { - ability.iconPath = ASSETS_DIR_NAME + iconPath; - } - } - ability.icon = ability.iconPath != null && !ability.iconPath.isEmpty() ? ability.iconPath : - getJsonString(abilityJson, "icon"); - - if (abilityJson.containsKey("descriptionId")) { - int descriptionId = abilityJson.getIntValue("descriptionId"); - ability.descriptionRes = ResourcesParser.getBaseResourceById(descriptionId, data); - } - ability.description = ability.descriptionRes != null && !ability.descriptionRes.isEmpty() ? - ability.descriptionRes : getJsonString(abilityJson, "description"); - - if (abilityJson.containsKey("labelId")) { - int labelId = abilityJson.getIntValue("labelId"); - ability.labelRes = ResourcesParser.getBaseResourceById(labelId, data); - } - if (ability.labelRes != null && !ability.labelRes.isEmpty()) { - ability.label = ability.labelRes; - } else if (!getJsonString(abilityJson, "label").isEmpty()) { - ability.label = getJsonString(abilityJson, "label"); - } else { - ability.label = ability.name; - } - - ability.type = getJsonString(abilityJson, "type"); - ability.launchType = getJsonString(abilityJson, "launchType"); - ability.orientation = getJsonString(abilityJson, "orientation"); - ability.uri = getJsonString(abilityJson, "uri"); - if (abilityJson.containsKey("formEnabled")) { - ability.formEnabled = abilityJson.getBoolean("formEnabled"); - } - - if (abilityJson.containsKey("metaData")) { - ability.metaData = JSONObject.parseObject(getJsonString(abilityJson, "metaData"), MetaData.class); - } - - if (abilityJson.containsKey("skills")) { - ability.skills = JSONObject.parseArray(getJsonString(abilityJson, "skills"), SkillInfo.class); - } - - if (abilityJson.containsKey("backgroundModes")) { - ability.backgroundModes = JSONObject.parseArray(getJsonString(abilityJson, "backgroundModes"), - String.class); - } - - if (abilityJson.containsKey("visible")) { - ability.visible = abilityJson.getBoolean("visible"); - } - - if (abilityJson.containsKey("configChanges")) { - ability.configChanges = JSONObject.parseArray(getJsonString(abilityJson, "configChanges"), String.class); - } - - parseAbilityPermissions(abilityJson, ability); - - return ability; - } - - /** - * parse ability object. - * - * @param abilityJson ability json object - * @param ability the parseAbility result - * @return the parseAbility Permissions result - * @throws BundleException Throws this exception if the json is not standard. - */ - static void parseAbilityPermissions(JSONObject abilityJson, AbilityInfo ability) throws BundleException { - if (abilityJson == null || ability == null) { - LOG.error("Uncompress::parseAbilityPermissions exception: abilityJson or ability is null"); - throw new BundleException("Parse ability permissions failed, abilityJson or ability is null"); - } - if (abilityJson.containsKey("permissions")) { - ability.permissions = JSONObject.parseArray(getJsonString(abilityJson, "permissions"), String.class); - } - - if (abilityJson.containsKey("grantPermission")) { - ability.grantPermission = abilityJson.getBoolean("grantPermission"); - } - ability.readPermission = getJsonString(abilityJson, "readPermission"); - ability.writePermission = getJsonString(abilityJson, "writePermission"); - - if (abilityJson.containsKey("uriPermission")) { - JSONObject uriPermission = abilityJson.getJSONObject("uriPermission"); - ability.uriPermissionMode = getJsonString(uriPermission, "mode"); - ability.uriPermissionPath = getJsonString(uriPermission, "path"); - } - - ability.mission = getJsonString(abilityJson, "mission"); - ability.targetAbility = getJsonString(abilityJson, "targetAbility"); - - if (abilityJson.containsKey("directLaunch")) { - ability.directLaunch = abilityJson.getBoolean("directLaunch"); - } - - if (abilityJson.containsKey("multiUserShared")) { - ability.multiUserShared = abilityJson.getBoolean("multiUserShared"); - } - - if (abilityJson.containsKey("supportPipMode")) { - ability.supportPipMode = abilityJson.getBoolean("supportPipMode"); - } - - if (abilityJson.containsKey("form")) { - JSONObject form = abilityJson.getJSONObject("form"); - FormInfo formInfo = new FormInfo(); - if (form.containsKey("formEntity")) { - formInfo.formEntity = JSONObject.parseArray(getJsonString(form, "formEntity"), String.class); - } - formInfo.minWidth = getJsonString(form, "minWidth"); - formInfo.defaultWidth = getJsonString(form, "defaultWidth"); - formInfo.minHeight = getJsonString(form, "minHeight"); - formInfo.defaultHeight = getJsonString(form, "defaultHeight"); - ability.formInfo = formInfo; - } - } - - /** - * get the String from JSONObject by the key. - * - * @param jsonObject uncompress json object - * @param key value key - * @return the result - */ - private static String getJsonString(JSONObject jsonObject, String key) { - String value = ""; - if (jsonObject != null && jsonObject.containsKey(key)) { - value = jsonObject.get(key).toString(); - } - return value; - } - - /** - * get the String from JSONObject by the key. - * - * @param jsonObject uncompress json object - * @param key value key - * @param defaultValue the default value - * @return the result - */ - private static String getJsonString(JSONObject jsonObject, String key, String defaultValue) { - String value = defaultValue; - if (jsonObject != null && jsonObject.containsKey(key)) { - value = jsonObject.get(key).toString(); - } - return value; - } -} +/* + * 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.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.Locale; + +import ohos.utils.fastjson.JSONObject; +import ohos.utils.fastjson.JSONArray; + +/** + * Json Util. + * + */ +public class JsonUtil { + private static final String DEVICE_TYPE = "device-type"; + private static final String NAME = "name"; + private static final String MODULE_TYPE = "module-type"; + private static final String INSTALL_FLAG = "delivery-with-install"; + private static final String DEVICE_TYPE_NEW = "deviceType"; + private static final String MODULE_TYPE_NEW = "moduleType"; + private static final String INSTALL_FLAG_NEW = "deliveryWithInstall"; + private static final String ASSETS_DIR_NAME = "assets/"; + private static final Log LOG = new Log(JsonUtil.class.toString()); + + private static final String SUMMARY = "summary"; + private static final String APP = "app"; + private static final String VERSION = "version"; + private static final String LEGACY_VERSION_CODE = "legacyVersionCode"; + private static final String LEGACY_VERSION_NAME = "legacyVersionName"; + private static final String MULTI_FRAMEWORK_BUNDLE = "multiFrameworkBundle"; + + /** + * parse hap list by device type + * + * @param deviceType target deviceType + * @param jsonString uncompress json String + * @return the parseHapList result + * @throws BundleException Throws this exception if the json is not standard. + */ + static List parseHapList(String deviceType, String jsonString) throws BundleException { + List packInfos = new ArrayList(); + JSONObject jsonObject = JSONObject.parseObject(jsonString); + if (jsonObject == null || !jsonObject.containsKey("packages")) { + LOG.error("Uncompress::parseHapList exception: packages is null"); + throw new BundleException("Parse hap list failed, packages is null"); + } + JSONArray jsonList = JSONArray.parseArray(getJsonString(jsonObject, "packages")); + if (jsonList == null) { + LOG.error("Uncompress::parseHapList exception: packages is null"); + throw new BundleException("Parse hap list failed, packages is null"); + } + int jsonListSize = jsonList.size(); + for (int i = 0; i < jsonListSize; i++) { + JSONObject tmpObj = jsonList.getJSONObject(i); + String deviceTypes = getJsonString(tmpObj, DEVICE_TYPE); + if (deviceTypes == null || "".equals(deviceTypes)) { + deviceTypes = getJsonString(tmpObj, DEVICE_TYPE_NEW); + } + if (deviceTypes != null && deviceTypes.toLowerCase(Locale.ENGLISH).contains( + deviceType.toLowerCase(Locale.ENGLISH))) { + PackInfo packInfo = new PackInfo(); + packInfo.name = getJsonString(tmpObj, NAME); + packInfo.moduleType = getJsonString(tmpObj, MODULE_TYPE); + if (packInfo.moduleType == null || "".equals(packInfo.moduleType)) { + packInfo.moduleType = getJsonString(tmpObj, MODULE_TYPE_NEW); + } + packInfo.deviceType = JSONArray.parseArray(deviceTypes, String.class); + String deliveryWithInstall = getJsonString(tmpObj, INSTALL_FLAG); + if (deliveryWithInstall == null || "".equals(deliveryWithInstall)) { + deliveryWithInstall = getJsonString(tmpObj, INSTALL_FLAG_NEW); + } + packInfo.deliveryWithInstall = Boolean.parseBoolean(deliveryWithInstall); + packInfos.add(packInfo); + } + } + return packInfos; + } + + private static boolean parseShellVersionInfoToAppInfo(String packInfoJsonStr, AppInfo appInfo) { + LOG.info("Uncompress::parseShellVersionInfoToAppInfo: begin"); + if (!appInfo.isMultiFrameworkBundle()) { + LOG.info("Uncompress::parseShellVersionInfoToAppInfo: is not a multi framewok bundle."); + return false; + } + + JSONObject jsonObject = JSONObject.parseObject(packInfoJsonStr); + if (jsonObject == null) { + LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: summary is null"); + return false; + } + + JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); + if (summaryJson == null) { + LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: summary is null"); + return false; + } + JSONObject appJson = summaryJson.getJSONObject(APP); + if (appJson == null) { + LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: app is null"); + return false; + } + JSONObject versionJson = appJson.getJSONObject(VERSION); + if (versionJson == null) { + LOG.error("Uncompress::parseShellVersionInfoToAppInfo error: version is null"); + return false; + } + + if (!versionJson.containsKey(LEGACY_VERSION_CODE) || !versionJson.containsKey(LEGACY_VERSION_NAME)) { + LOG.error("Uncompress::parseShellVersionInfoToAppInfo no legacy version info."); + return false; + } + appInfo.setShellVersionCode(versionJson.getString(LEGACY_VERSION_CODE)); + appInfo.setShellVersionName(versionJson.getString(LEGACY_VERSION_NAME)); + return true; + } + + /** + * parse hap profile info + * + * @param harmonyProfileJsonString uncompress json String + * @param data resource index data + * @param paclInfoJsonString pack.info json String + * @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 { + ProfileInfo profileInfo = new ProfileInfo(); + JSONObject jsonObject = JSONObject.parseObject(harmonyProfileJsonString); + if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey("deviceConfig") + || !jsonObject.containsKey("module")) { + LOG.error("Uncompress::parseProfileInfo exception: app, deviceConfig or module is null"); + throw new BundleException("Parse profile info failed, app, deviceConfig or module is null"); + } + if (jsonObject.containsKey(APP)) { + JSONObject appJson = jsonObject.getJSONObject(APP); + profileInfo.appInfo = parseAppInfo(appJson); + } + if (jsonObject.containsKey("module")) { + JSONObject hapJson = jsonObject.getJSONObject("module"); + profileInfo.hapInfo = parseHapInfo(hapJson, data); + } + if (jsonObject.containsKey("deviceConfig")) { + JSONObject deviceConfigJson = jsonObject.getJSONObject("deviceConfig"); + profileInfo.deviceConfig = parseDeviceConfigInfo(deviceConfigJson, profileInfo.hapInfo.deviceType); + } + + if (profileInfo.hapInfo.abilities.size() == 1) { + profileInfo.appInfo.appName = profileInfo.hapInfo.abilities.get(0).label; + profileInfo.appInfo.appNameEN = profileInfo.hapInfo.abilities.get(0).label; + } else { + for (AbilityInfo abilityInfo : profileInfo.hapInfo.abilities) { + boolean isLabel = false; + for (SkillInfo skill : abilityInfo.skills) { + if (skill.actions.contains("action.system.home") && skill.entities.contains("entity.system.home")) { + isLabel = true; + break; + } + } + if (isLabel) { + profileInfo.appInfo.appName = abilityInfo.label; + profileInfo.appInfo.appNameEN = abilityInfo.label; + break; + } + } + } + + if (!parseShellVersionInfoToAppInfo(paclInfoJsonString, profileInfo.appInfo)) { + profileInfo.appInfo.setDefaultShellVersion(); + } + return profileInfo; + } + + /** + * parse app info + * + * @param appJson global json Object + * @return the parseAppInfo result + * @throws BundleException Throws this exception if the json is not standard. + */ + static AppInfo parseAppInfo(JSONObject appJson) throws BundleException { + AppInfo appInfo = new AppInfo(); + if (appJson == null) { + LOG.error("Uncompress::parseAppInfo exception: appJson is null"); + throw new BundleException("Parse app info failed, appJson is null"); + } + appInfo.bundleName = getJsonString(appJson, "bundleName"); + appInfo.vendor = getJsonString(appJson, "vendor"); + appInfo.relatedBundleName = getJsonString(appJson, "relatedBundleName"); + if (appJson.containsKey(VERSION)) { + JSONObject version = appJson.getJSONObject(VERSION); + appInfo.versionName = getJsonString(version, "name"); + appInfo.versionCode = getJsonString(version, "code"); + } + if (appJson.containsKey("apiVersion")) { + JSONObject apiVersion = appJson.getJSONObject("apiVersion"); + appInfo.compatibleApiVersion = apiVersion.getIntValue("compatible"); + appInfo.targetApiVersion = apiVersion.getIntValue("target"); + appInfo.releaseType = getJsonString(apiVersion, "releaseType"); + } + appInfo.setMultiFrameworkBundle(appJson.getBooleanValue(MULTI_FRAMEWORK_BUNDLE)); + return appInfo; + } + + /** + * parse deviceConfig infos + * + * @param deviceConfigInfoJson deviceConfig json Object + * @param deviceTypes the deviceTypes of the hap + * @return the parseDeviceConfigInfo result + * @throws BundleException Throws this exception if the json is not standard. + */ + static Map parseDeviceConfigInfo(JSONObject deviceConfigInfoJson, + List deviceTypes) throws BundleException { + Map deviceConfigs = new HashMap<>(); + if (deviceConfigInfoJson == null) { + return deviceConfigs; + } + + DeviceConfig defaultConfig = new DeviceConfig(); + if (deviceConfigInfoJson.containsKey("default")) { + defaultConfig = parseDeviceConfig(deviceConfigInfoJson.getJSONObject("default"), + new DeviceConfig()); + } + + for (String deviceType : deviceTypes) { + getTargetDeviceConfig(deviceConfigs, deviceConfigInfoJson, defaultConfig, deviceType); + } + + if (deviceConfigs.isEmpty()) { + deviceConfigs.put(UncompressEntrance.DEVICE_TYPE_PHONE, defaultConfig); + } + + return deviceConfigs; + } + + /** + * parse deviceConfig infos + * + * @param deviceConfigs the parseDeviceConfigInfo result + * @param deviceConfigInfoJson deviceConfig json Object + * @param defaultConfig the default deviceConfig + * @param targetDeviceType the target deviceType + * @throws BundleException Throws this exception if the json is not standard. + */ + static void getTargetDeviceConfig(Map deviceConfigs, JSONObject deviceConfigInfoJson, + DeviceConfig defaultConfig, String targetDeviceType) throws BundleException { + if (deviceConfigInfoJson.containsKey(targetDeviceType)) { + DeviceConfig deviceConfig = parseDeviceConfig( + deviceConfigInfoJson.getJSONObject(targetDeviceType), defaultConfig); + deviceConfigs.put(targetDeviceType, deviceConfig); + } else { + deviceConfigs.put(targetDeviceType, defaultConfig); + } + } + + /** + * parse deviceConfig info + * + * @param deviceConfigJson deviceConfig json Object + * @param defaultConfig default deviceConfig + * @return the parseDeviceConfigInfo result + * @throws BundleException Throws this exception if the json is not standard. + */ + static DeviceConfig parseDeviceConfig(JSONObject deviceConfigJson, DeviceConfig defaultConfig) + throws BundleException { + DeviceConfig deviceConfig = new DeviceConfig(); + if (deviceConfigJson == null || defaultConfig == null) { + LOG.error("Uncompress::parseDeviceConfigInfo exception: deviceConfigJson or defaultConfig is null"); + throw new BundleException("Parse device config info failed, deviceConfigJson or defaultConfig is null"); + } + + deviceConfig.jointUserid = getJsonString(deviceConfigJson, "jointUserid", defaultConfig.jointUserid); + deviceConfig.process = getJsonString(deviceConfigJson, "process", defaultConfig.process); + + if (deviceConfigJson.containsKey("reqSdk")) { + JSONObject reqSdk = deviceConfigJson.getJSONObject("reqSdk"); + deviceConfig.compatibleReqSdk = getJsonString(reqSdk, "compatible", defaultConfig.compatibleReqSdk); + deviceConfig.targetReqSdk = getJsonString(reqSdk, "target", defaultConfig.targetReqSdk); + } + + if (deviceConfigJson.containsKey("ark")) { + JSONObject ark = deviceConfigJson.getJSONObject("ark"); + deviceConfig.arkFlag = getJsonString(ark, "flag", defaultConfig.arkFlag); + if (ark.containsKey("reqVersion")) { + JSONObject arkVersion = ark.getJSONObject("reqVersion"); + deviceConfig.targetArkVersion = getJsonString(arkVersion, "target", defaultConfig.targetArkVersion); + deviceConfig.compatibleArkVersion = getJsonString(arkVersion, "compatible", + defaultConfig.compatibleArkVersion); + } + } + + if (deviceConfigJson.containsKey("directLaunch")) { + deviceConfig.directLaunch = deviceConfigJson.getBoolean("directLaunch"); + } else { + deviceConfig.directLaunch = defaultConfig.directLaunch; + } + + return deviceConfig; + } + + /** + * parse hap info + * + * @param hapJson hap json Object + * @param data resource index data + * @return the parseHapInfo result + * @throws BundleException Throws this exception if the json is not standard. + */ + static HapInfo parseHapInfo(JSONObject hapJson, byte[] data) throws BundleException { + HapInfo hapInfo = new HapInfo(); + if (hapJson == null) { + LOG.error("Uncompress::parseHapInfo exception: hapJson is null"); + throw new BundleException("Parse hap info failed, hapJson is null"); + } + hapInfo.packageStr = getJsonString(hapJson, "package"); + hapInfo.name = getJsonString(hapJson, "name"); + hapInfo.description = getJsonString(hapJson, "description"); + + if (hapJson.containsKey("supportedModes")) { + hapInfo.supportedModes = JSONObject.parseArray(getJsonString(hapJson, "supportedModes"), + String.class); + } + + if (hapJson.containsKey("defPermissions")) { + hapInfo.defPermissions = JSONArray.parseArray(getJsonString(hapJson, "defPermissions"), + DefPermission.class); + } + + if (hapJson.containsKey("defPermissiongroups")) { + hapInfo.defPermissionsGroups = JSONArray.parseArray(getJsonString(hapJson, "defPermissiongroups"), + DefPermissionGroup.class); + } + + if (hapJson.containsKey("distro")) { + getDistro(hapJson, hapInfo); + } + + if (hapJson.containsKey("reqCapabilities")) { + hapInfo.reqCapabilities = JSONArray.parseArray(getJsonString(hapJson, "reqCapabilities"), + String.class); + } + + if (hapJson.containsKey("deviceType")) { + hapInfo.deviceType = JSONArray.parseArray(getJsonString(hapJson, "deviceType") + .replace(UncompressEntrance.DEVICE_TYPE_DEFAULT, UncompressEntrance.DEVICE_TYPE_PHONE), + String.class); + } + + if (hapJson.containsKey("metaData")) { + hapInfo.metaData = JSONObject.parseObject(getJsonString(hapJson, "metaData"), MetaData.class); + } + + if (hapJson.containsKey("js")) { + List jsInfos = JSONObject.parseArray(getJsonString(hapJson, "js"), JsInfo.class); + if (jsInfos != null && jsInfos.size() > 0) { + hapInfo.isJs = true; + } + } + + if (hapJson.containsKey("reqPermissions")) { + hapInfo.reqPermissions = JSONObject.parseArray(getJsonString(hapJson, "reqPermissions"), + ReqPermission.class); + } + + if (hapJson.containsKey("commonEvents")) { + hapInfo.commonEvents = JSONObject.parseArray(getJsonString(hapJson, "commonEvents"), + CommonEvent.class); + } + + if (hapJson.containsKey("shortcuts")) { + hapInfo.shortcuts = JSONObject.parseArray(getJsonString(hapJson, "shortcuts"), Shortcut.class); + } + + if (hapJson.containsKey("abilities")) { + JSONArray abilities = hapJson.getJSONArray("abilities"); + List abilitieList = new ArrayList(); + int abilitiesSize = abilities.size(); + for (int i = 0; i < abilitiesSize; i++) { + JSONObject tmpObj = abilities.getJSONObject(i); + abilitieList.add(parseAbility(tmpObj, data)); + } + hapInfo.abilities = abilitieList; + } + if (hapJson.containsKey("distroFilter")) { + hapInfo.distroFilter = JSONObject.parseObject(getJsonString(hapJson, "distroFilter"), DistroFilter.class); + } + return hapInfo; + } + + /** + * get distro + * + * @param hapJson hapJson json + * @param hapInfo hapInfo json object + */ + private static void getDistro(JSONObject hapJson, HapInfo hapInfo) { + JSONObject distroObj = hapJson.getJSONObject("distro"); + Distro distro = new Distro(); + distro.moduleName = getJsonString(distroObj, "moduleName"); + distro.moduleType = getJsonString(distroObj, "moduleType"); + distro.deliveryWithInstall = distroObj.getBoolean("deliveryWithInstall"); + if (distroObj.containsKey("installationFree")) { + boolean isFreeInstall = distroObj.getBoolean("installationFree"); + if (isFreeInstall) { + distro.installationFree = 1; + }else { + distro.installationFree = 0; + } + } else { + distro.installationFree = 2; + } + hapInfo.distro = distro; + } + + /** + * parse ability object. + * + * @param abilityJson ability json object + * @param data resource index data + * @return the parseAbility result + * @throws BundleException Throws this exception if the json is not standard. + */ + static AbilityInfo parseAbility(JSONObject abilityJson, byte[] data) throws BundleException { + if (abilityJson == null) { + LOG.error("Uncompress::parseAbility exception: abilityJson is null"); + throw new BundleException("Parse ability failed, abilityJson is null"); + } + AbilityInfo ability = new AbilityInfo(); + ability.name = getJsonString(abilityJson, "name"); + if (abilityJson.containsKey("iconId")) { + int iconId = abilityJson.getIntValue("iconId"); + String iconPath = ResourcesParser.getResourceById(iconId, data); + if (iconPath != null && !iconPath.isEmpty()) { + ability.iconPath = ASSETS_DIR_NAME + iconPath; + } + } + ability.icon = ability.iconPath != null && !ability.iconPath.isEmpty() ? ability.iconPath : + getJsonString(abilityJson, "icon"); + + if (abilityJson.containsKey("descriptionId")) { + int descriptionId = abilityJson.getIntValue("descriptionId"); + ability.descriptionRes = ResourcesParser.getBaseResourceById(descriptionId, data); + } + ability.description = ability.descriptionRes != null && !ability.descriptionRes.isEmpty() ? + ability.descriptionRes : getJsonString(abilityJson, "description"); + + if (abilityJson.containsKey("labelId")) { + int labelId = abilityJson.getIntValue("labelId"); + ability.labelRes = ResourcesParser.getBaseResourceById(labelId, data); + } + if (ability.labelRes != null && !ability.labelRes.isEmpty()) { + ability.label = ability.labelRes; + } else if (!getJsonString(abilityJson, "label").isEmpty()) { + ability.label = getJsonString(abilityJson, "label"); + } else { + ability.label = ability.name; + } + + ability.type = getJsonString(abilityJson, "type"); + ability.launchType = getJsonString(abilityJson, "launchType"); + ability.orientation = getJsonString(abilityJson, "orientation"); + ability.uri = getJsonString(abilityJson, "uri"); + if (abilityJson.containsKey("formEnabled")) { + ability.formEnabled = abilityJson.getBoolean("formEnabled"); + } + + if (abilityJson.containsKey("metaData")) { + ability.metaData = JSONObject.parseObject(getJsonString(abilityJson, "metaData"), MetaData.class); + } + + if (abilityJson.containsKey("skills")) { + ability.skills = JSONObject.parseArray(getJsonString(abilityJson, "skills"), SkillInfo.class); + } + + if (abilityJson.containsKey("backgroundModes")) { + ability.backgroundModes = JSONObject.parseArray(getJsonString(abilityJson, "backgroundModes"), + String.class); + } + + if (abilityJson.containsKey("visible")) { + ability.visible = abilityJson.getBoolean("visible"); + } + + if (abilityJson.containsKey("configChanges")) { + ability.configChanges = JSONObject.parseArray(getJsonString(abilityJson, "configChanges"), String.class); + } + + parseAbilityPermissions(abilityJson, ability); + + return ability; + } + + /** + * parse ability object. + * + * @param abilityJson ability json object + * @param ability the parseAbility result + * @return the parseAbility Permissions result + * @throws BundleException Throws this exception if the json is not standard. + */ + static void parseAbilityPermissions(JSONObject abilityJson, AbilityInfo ability) throws BundleException { + if (abilityJson == null || ability == null) { + LOG.error("Uncompress::parseAbilityPermissions exception: abilityJson or ability is null"); + throw new BundleException("Parse ability permissions failed, abilityJson or ability is null"); + } + if (abilityJson.containsKey("permissions")) { + ability.permissions = JSONObject.parseArray(getJsonString(abilityJson, "permissions"), String.class); + } + + if (abilityJson.containsKey("grantPermission")) { + ability.grantPermission = abilityJson.getBoolean("grantPermission"); + } + ability.readPermission = getJsonString(abilityJson, "readPermission"); + ability.writePermission = getJsonString(abilityJson, "writePermission"); + + if (abilityJson.containsKey("uriPermission")) { + JSONObject uriPermission = abilityJson.getJSONObject("uriPermission"); + ability.uriPermissionMode = getJsonString(uriPermission, "mode"); + ability.uriPermissionPath = getJsonString(uriPermission, "path"); + } + + ability.mission = getJsonString(abilityJson, "mission"); + ability.targetAbility = getJsonString(abilityJson, "targetAbility"); + + if (abilityJson.containsKey("directLaunch")) { + ability.directLaunch = abilityJson.getBoolean("directLaunch"); + } + + if (abilityJson.containsKey("multiUserShared")) { + ability.multiUserShared = abilityJson.getBoolean("multiUserShared"); + } + + if (abilityJson.containsKey("supportPipMode")) { + ability.supportPipMode = abilityJson.getBoolean("supportPipMode"); + } + + if (abilityJson.containsKey("form")) { + JSONObject form = abilityJson.getJSONObject("form"); + FormInfo formInfo = new FormInfo(); + if (form.containsKey("formEntity")) { + formInfo.formEntity = JSONObject.parseArray(getJsonString(form, "formEntity"), String.class); + } + formInfo.minWidth = getJsonString(form, "minWidth"); + formInfo.defaultWidth = getJsonString(form, "defaultWidth"); + formInfo.minHeight = getJsonString(form, "minHeight"); + formInfo.defaultHeight = getJsonString(form, "defaultHeight"); + ability.formInfo = formInfo; + } + } + + /** + * get the String from JSONObject by the key. + * + * @param jsonObject uncompress json object + * @param key value key + * @return the result + */ + private static String getJsonString(JSONObject jsonObject, String key) { + String value = ""; + if (jsonObject != null && jsonObject.containsKey(key)) { + value = jsonObject.get(key).toString(); + } + return value; + } + + /** + * get the String from JSONObject by the key. + * + * @param jsonObject uncompress json object + * @param key value key + * @param defaultValue the default value + * @return the result + */ + private static String getJsonString(JSONObject jsonObject, String key, String defaultValue) { + String value = defaultValue; + if (jsonObject != null && jsonObject.containsKey(key)) { + value = jsonObject.get(key).toString(); + } + return value; + } +} diff --git a/com/huawei/ohos/Log.java b/adapter/ohos/Log.java old mode 100755 new mode 100644 similarity index 93% rename from com/huawei/ohos/Log.java rename to adapter/ohos/Log.java index 995dff12b4e5e7bbf4089aeec513dd50f17d838d..e3a666e86f217be18d4f5824952688757f050dd8 --- a/com/huawei/ohos/Log.java +++ b/adapter/ohos/Log.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.huawei.ohos; +package ohos; import java.util.logging.Level; import java.util.logging.Logger; @@ -21,8 +21,6 @@ import java.util.logging.Logger; /** * Class used to print logs and will remove if the official log module is ready. * - * @author huzeqi - * @since 2019-10-25 */ public class Log { private static Logger log; @@ -83,7 +81,7 @@ enum LogType { * @return format log tag */ public static String buildTag(LogType logType) { - return "HarmonyOS BundleTool [" + logType.value + "]: "; + return "Ohos BundleTool [" + logType.value + "]: "; } } diff --git a/com/huawei/ohos/MetaData.java b/adapter/ohos/MetaData.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/MetaData.java rename to adapter/ohos/MetaData.java index ad6fa329cac801748806e525e2a1f934e95ceb94..696cb3e937f4ba44d85c52a32ffdf05a7e37507b --- a/com/huawei/ohos/MetaData.java +++ b/adapter/ohos/MetaData.java @@ -1,42 +1,40 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * MetaData info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class MetaData { - /** - * Indicates the parameters of MetaData. - */ - public List parameters = new ArrayList(); - - /** - * Indicates the results of MetaData. - */ - public List results = new ArrayList(); - - /** - * Indicates the CustomizeDatas of MetaData. - */ - public List customizeDatas = new ArrayList(); +/* + * 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; + +/** + * MetaData info. + * + */ +public class MetaData { + /** + * Indicates the parameters of MetaData. + */ + public List parameters = new ArrayList(); + + /** + * Indicates the results of MetaData. + */ + public List results = new ArrayList(); + + /** + * Indicates the CustomizeDatas of MetaData. + */ + public List customizeDatas = new ArrayList(); } \ No newline at end of file diff --git a/com/huawei/ohos/MetaDataInfo.java b/adapter/ohos/MetaDataInfo.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/MetaDataInfo.java rename to adapter/ohos/MetaDataInfo.java index 5399600b315f6f1839e1ee4b99a058611322588e..a78627195bae705a600a8eb573751a46a9d8e88f --- a/com/huawei/ohos/MetaDataInfo.java +++ b/adapter/ohos/MetaDataInfo.java @@ -1,39 +1,37 @@ -/* - * 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 com.huawei.ohos; - -/** - * Meta data info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class MetaDataInfo { - /** - * Indicates the name of MetaDataInfo. - */ - public String name = ""; - - /** - * Indicates the description of MetaDataInfo. - */ - public String description = ""; - - /** - * Indicates the type of MetaDataInfo. - */ - public String type = ""; +/* + * 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; + +/** + * Meta data info. + * + */ +public class MetaDataInfo { + /** + * Indicates the name of MetaDataInfo. + */ + public String name = ""; + + /** + * Indicates the description of MetaDataInfo. + */ + public String description = ""; + + /** + * Indicates the type of MetaDataInfo. + */ + public String type = ""; } \ No newline at end of file diff --git a/com/huawei/ohos/PackInfo.java b/adapter/ohos/PackInfo.java old mode 100755 new mode 100644 similarity index 91% rename from com/huawei/ohos/PackInfo.java rename to adapter/ohos/PackInfo.java index c146a69723fcc1a9d9bce922616479c70f817b1d..f72feb9266401447c39fe6c7d3627c578f3e7065 --- a/com/huawei/ohos/PackInfo.java +++ b/adapter/ohos/PackInfo.java @@ -1,52 +1,50 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * Package info. - * - * @author dingyao - * @since 2020-04-22 - */ -public class PackInfo { - /** - * Indicates the name of PackInfo. - */ - public String name = ""; - - /** - * Indicates the moduleName of PackInfo. - */ - public String moduleName = ""; - - /** - * Indicates the moduleType of PackInfo. - */ - public String moduleType = ""; - - /** - * Indicates the deviceType of PackInfo. - */ - public List deviceType = new ArrayList(); - - /** - * Indicates the deliveryWithInstall of PackInfo. - */ - public boolean deliveryWithInstall = false; -} +/* + * 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; + +/** + * Package info. + * + */ +public class PackInfo { + /** + * Indicates the name of PackInfo. + */ + public String name = ""; + + /** + * Indicates the moduleName of PackInfo. + */ + public String moduleName = ""; + + /** + * Indicates the moduleType of PackInfo. + */ + public String moduleType = ""; + + /** + * Indicates the deviceType of PackInfo. + */ + public List deviceType = new ArrayList(); + + /** + * Indicates the deliveryWithInstall of PackInfo. + */ + public boolean deliveryWithInstall = false; +} diff --git a/com/huawei/ohos/ProfileInfo.java b/adapter/ohos/ProfileInfo.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/ProfileInfo.java rename to adapter/ohos/ProfileInfo.java index 94716f9d9aa5ebe2c144f26103e0ddca893a778a..4060e8ae87650bf3149fa2f018aecae4e17a1846 --- a/com/huawei/ohos/ProfileInfo.java +++ b/adapter/ohos/ProfileInfo.java @@ -1,47 +1,45 @@ -/* - * 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 com.huawei.ohos; - -import java.util.HashMap; -import java.util.Map; - -/** - * App Profile info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class ProfileInfo { - /** - * Indicates the file name of the hap. - */ - public String hapName = ""; - - /** - * Indicates the appInfo of app. - */ - public AppInfo appInfo = null; - - /** - * Indicates the deviceConfig of app. - */ - public Map deviceConfig = new HashMap<>(); - - /** - * Indicates the hapInfo of app. - */ - public HapInfo hapInfo = null; -} +/* + * 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.HashMap; +import java.util.Map; + +/** + * App Profile info. + * + */ +public class ProfileInfo { + /** + * Indicates the file name of the hap. + */ + public String hapName = ""; + + /** + * Indicates the appInfo of app. + */ + public AppInfo appInfo = null; + + /** + * Indicates the deviceConfig of app. + */ + public Map deviceConfig = new HashMap<>(); + + /** + * Indicates the hapInfo of app. + */ + public HapInfo hapInfo = null; +} diff --git a/com/huawei/ohos/README b/adapter/ohos/README old mode 100755 new mode 100644 similarity index 94% rename from com/huawei/ohos/README rename to adapter/ohos/README index 12ca00b9573958834f5833e9b01442e87d803cba..951e25e97c885574fbef7564b190520b0c521b2d --- a/com/huawei/ohos/README +++ b/adapter/ohos/README @@ -1,5 +1,16 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. + * Copyright (c) 2019-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. */ use commands for package hap or app. diff --git a/com/huawei/ohos/ReqPermission.java b/adapter/ohos/ReqPermission.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/ReqPermission.java rename to adapter/ohos/ReqPermission.java index 8238d5e484380725c8a77a9301b498bae283399c..b62067d9182d0955c41db3c454553ad94f946287 --- a/com/huawei/ohos/ReqPermission.java +++ b/adapter/ohos/ReqPermission.java @@ -1,42 +1,40 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * ReqPermission info. - * - * @author dingyao - * @since 2020-05-09 - */ -public class ReqPermission { - /** - * Indicates the name of ReqPermission. - */ - public String name = ""; - - /** - * Indicates the reason of ReqPermission. - */ - public String reason = ""; - - /** - * Indicates the usedScene of ReqPermission. - */ - public UsedScene usedScene = null; +/* + * 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; + +/** + * ReqPermission info. + * + */ +public class ReqPermission { + /** + * Indicates the name of ReqPermission. + */ + public String name = ""; + + /** + * Indicates the reason of ReqPermission. + */ + public String reason = ""; + + /** + * Indicates the usedScene of ReqPermission. + */ + public UsedScene usedScene = null; } \ No newline at end of file diff --git a/com/huawei/ohos/ResourcesParser.java b/adapter/ohos/ResourcesParser.java old mode 100755 new mode 100644 similarity index 96% rename from com/huawei/ohos/ResourcesParser.java rename to adapter/ohos/ResourcesParser.java index e6f43eef4d7ece77fc9ab77bcecf5e64afdfbf71..c6bc332a0811009ad7bf2d5d09aa97adbafe7443 --- a/com/huawei/ohos/ResourcesParser.java +++ b/adapter/ohos/ResourcesParser.java @@ -1,299 +1,297 @@ -/* - * 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 com.huawei.ohos; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * Resources Parser. - * - * @author dingyao - * @since 2020-07-22 - */ -public class ResourcesParser { - /** - * Parses resources default id. - */ - public static final int RESOURCE_DEFAULT_ID = -1; - - private static final int VERSION_BYTE_LENGTH = 128; - private static final int TAG_BYTE_LENGTH = 4; - private static final int BUF_MOVE_LENGTH = 8; - private static final Log LOG = new Log(ResourcesParser.class.toString()); - - /** - * Key Param. - */ - static class KeyParam { - int keyType; - int value; - } - - /** - * Config Index. - */ - static class ConfigIndex { - String tag; - int offset; - int keyCount; - KeyParam[] params; - } - - /** - * Data Item. - */ - static class DataItem { - int size; - int type; - int id; - String value; - String name; - } - - /** - * Get resource value by resource id. - * - * @param resourceId resource id - * @param data resource index data - * @return the resourceId value - * @throws BundleException IOException. - */ - static String getResourceById(int resourceId, byte[] data) throws BundleException { - String resourceIdValue = ""; - if (data == null || data.length <= 0 || resourceId == RESOURCE_DEFAULT_ID) { - LOG.error("ResourcesParser::getIconPath data byte or ResourceId is null"); - return resourceIdValue; - } - - List result = getResource(resourceId, data); - if (result != null && result.size() > 0 && result.get(0) != null && !"".equals(result.get(0))) { - resourceIdValue = result.get(0).substring(0, result.get(0).length() - 1); - } - return resourceIdValue; - } - - /** - * Get base resource value by resource id. - * - * @param resourceId resource id - * @param data resource index data - * @return the resource value - * @throws BundleException IOException. - */ - static String getBaseResourceById(int resourceId, byte[] data) throws BundleException { - String resourceIdValue = ""; - if (data == null || data.length <= 0 || resourceId == RESOURCE_DEFAULT_ID) { - LOG.error("ResourcesParser::getBaseResourceById data byte or ResourceId is null"); - return resourceIdValue; - } - resourceIdValue = getBaseResource(resourceId, data); - if (resourceIdValue != null && !"".equals(resourceIdValue)) { - resourceIdValue = resourceIdValue.substring(0, resourceIdValue.length() - 1); - } - return resourceIdValue; - } - - /** - * Get base resource. - * - * @param resId resource id - * @param data resource index data array - * @return the resource value - * @throws BundleException IOException. - */ - static String getBaseResource(int resId, byte[] data) { - ByteBuffer byteBuf = ByteBuffer.wrap(data); - byteBuf.order(ByteOrder.LITTLE_ENDIAN); - byte[] version = new byte[VERSION_BYTE_LENGTH]; - byteBuf.get(version); - byteBuf.getInt(); - int configCount = byteBuf.getInt(); - Optional optionalConfigIndex = loadBaseConfig(byteBuf, configCount); - if (!optionalConfigIndex.isPresent()) { - LOG.error("ResourcesParser::getBaseResource configIndex is null"); - return ""; - } - return readBaseItem(resId, optionalConfigIndex.get(), byteBuf); - } - - /** - * Load index config. - * - * @param bufBuf config byte buffer - * @param count config count - * @return the base config index - * @throws BundleException IOException. - */ - static Optional loadBaseConfig(ByteBuffer bufBuf, int count) { - for (int i = 0; i < count; i++) { - ConfigIndex cfg = new ConfigIndex(); - byte[] tag = new byte[TAG_BYTE_LENGTH]; - bufBuf.get(tag); - cfg.tag = new String(tag, StandardCharsets.UTF_8); - cfg.offset = bufBuf.getInt(); - cfg.keyCount = bufBuf.getInt(); - cfg.params = new KeyParam[cfg.keyCount]; - for (int j = 0; j < cfg.keyCount; j++) { - cfg.params[j] = new KeyParam(); - cfg.params[j].keyType = bufBuf.getInt(); - cfg.params[j].value = bufBuf.getInt(); - } - if (cfg.keyCount == 0) { - return Optional.of(cfg); - } - } - return Optional.empty(); - } - - /** - * Read base config item. - * - * @param resId resource id - * @param configIndex the config index - * @param buf config byte buffer - * @return the base item - * @throws BundleException IOException. - */ - static String readBaseItem(int resId, ConfigIndex configIndex, ByteBuffer buf) { - buf.rewind(); - buf.position(configIndex.offset); - byte[] tag = new byte[TAG_BYTE_LENGTH]; - buf.get(tag); - int count = buf.getInt(); - for (int i = 0; i < count; i++) { - int id = buf.getInt(); - int offset = buf.getInt(); - if (id == resId) { - buf.rewind(); - buf.position(offset); - DataItem item = readItem(buf); - return item.value; - } - } - return ""; - } - - /** - * Get Icon resource. - * - * @param resId resource id - * @param data resource index data array - * @return the result - * @throws BundleException IOException. - */ - static List getResource(int resId, byte[] data) { - ByteBuffer byteBuf = ByteBuffer.wrap(data); - byteBuf.order(ByteOrder.LITTLE_ENDIAN); - byte[] version = new byte[VERSION_BYTE_LENGTH]; - byteBuf.get(version); - byteBuf.getInt(); - int configCount = byteBuf.getInt(); - List cfg = loadConfig(byteBuf, configCount); - return readAllItem(resId, cfg, byteBuf); - } - - /** - * Load index config. - * - * @param bufBuf config byte buffer - * @param count config count - * @return the config list - * @throws BundleException IOException. - */ - static List loadConfig(ByteBuffer bufBuf, int count) { - List configList = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - ConfigIndex cfg = new ConfigIndex(); - byte[] tag = new byte[TAG_BYTE_LENGTH]; - bufBuf.get(tag); - cfg.tag = new String(tag, StandardCharsets.UTF_8); - cfg.offset = bufBuf.getInt(); - cfg.keyCount = bufBuf.getInt(); - cfg.params = new KeyParam[cfg.keyCount]; - for (int j = 0; j < cfg.keyCount; j++) { - cfg.params[j] = new KeyParam(); - cfg.params[j].keyType = bufBuf.getInt(); - cfg.params[j].value = bufBuf.getInt(); - } - - configList.add(cfg); - } - return configList; - } - - /** - * Read all config item. - * - * @param resId resource id - * @param configs the config list - * @param buf config byte buffer - * @return the item list - * @throws BundleException IOException. - */ - static List readAllItem(int resId, List configs, ByteBuffer buf) { - List result = new ArrayList<>(); - for (ConfigIndex index : configs) { - buf.rewind(); - buf.position(index.offset); - byte[] tag = new byte[TAG_BYTE_LENGTH]; - buf.get(tag); - int count = buf.getInt(); - for (int i = 0; i < count; i++) { - int id = buf.getInt(); - int offset = buf.getInt(); - if (id == resId) { - buf.rewind(); - buf.position(offset); - DataItem item = readItem(buf); - result.add(item.value); - break; - } - } - } - return result; - } - - /** - * Read the config item. - * - * @param buf config byte buffer - * @return the item info - * @throws BundleException IOException. - */ - static DataItem readItem(ByteBuffer buf) { - DataItem item = new DataItem(); - item.size = buf.getInt(); - item.type = buf.getInt(); - item.id = buf.getInt(); - int len = buf.get() | (buf.get() << BUF_MOVE_LENGTH); - byte[] value = new byte[len]; - buf.get(value); - item.value = new String(value, StandardCharsets.UTF_8); - len = buf.get() | (buf.get() << BUF_MOVE_LENGTH); - byte[] name = new byte[len]; - buf.get(name); - item.name = new String(name, StandardCharsets.UTF_8); - return item; - } -} - +/* + * 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.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * Resources Parser. + * + */ +public class ResourcesParser { + /** + * Parses resources default id. + */ + public static final int RESOURCE_DEFAULT_ID = -1; + + private static final int VERSION_BYTE_LENGTH = 128; + private static final int TAG_BYTE_LENGTH = 4; + private static final int BUF_MOVE_LENGTH = 8; + private static final Log LOG = new Log(ResourcesParser.class.toString()); + + /** + * Key Param. + */ + static class KeyParam { + int keyType; + int value; + } + + /** + * Config Index. + */ + static class ConfigIndex { + String tag; + int offset; + int keyCount; + KeyParam[] params; + } + + /** + * Data Item. + */ + static class DataItem { + int size; + int type; + int id; + String value; + String name; + } + + /** + * Get resource value by resource id. + * + * @param resourceId resource id + * @param data resource index data + * @return the resourceId value + * @throws BundleException IOException. + */ + static String getResourceById(int resourceId, byte[] data) throws BundleException { + String resourceIdValue = ""; + if (data == null || data.length <= 0 || resourceId == RESOURCE_DEFAULT_ID) { + LOG.error("ResourcesParser::getIconPath data byte or ResourceId is null"); + return resourceIdValue; + } + + List result = getResource(resourceId, data); + if (result != null && result.size() > 0 && result.get(0) != null && !"".equals(result.get(0))) { + resourceIdValue = result.get(0).substring(0, result.get(0).length() - 1); + } + return resourceIdValue; + } + + /** + * Get base resource value by resource id. + * + * @param resourceId resource id + * @param data resource index data + * @return the resource value + * @throws BundleException IOException. + */ + static String getBaseResourceById(int resourceId, byte[] data) throws BundleException { + String resourceIdValue = ""; + if (data == null || data.length <= 0 || resourceId == RESOURCE_DEFAULT_ID) { + LOG.error("ResourcesParser::getBaseResourceById data byte or ResourceId is null"); + return resourceIdValue; + } + resourceIdValue = getBaseResource(resourceId, data); + if (resourceIdValue != null && !"".equals(resourceIdValue)) { + resourceIdValue = resourceIdValue.substring(0, resourceIdValue.length() - 1); + } + return resourceIdValue; + } + + /** + * Get base resource. + * + * @param resId resource id + * @param data resource index data array + * @return the resource value + * @throws BundleException IOException. + */ + static String getBaseResource(int resId, byte[] data) { + ByteBuffer byteBuf = ByteBuffer.wrap(data); + byteBuf.order(ByteOrder.LITTLE_ENDIAN); + byte[] version = new byte[VERSION_BYTE_LENGTH]; + byteBuf.get(version); + byteBuf.getInt(); + int configCount = byteBuf.getInt(); + Optional optionalConfigIndex = loadBaseConfig(byteBuf, configCount); + if (!optionalConfigIndex.isPresent()) { + LOG.error("ResourcesParser::getBaseResource configIndex is null"); + return ""; + } + return readBaseItem(resId, optionalConfigIndex.get(), byteBuf); + } + + /** + * Load index config. + * + * @param bufBuf config byte buffer + * @param count config count + * @return the base config index + * @throws BundleException IOException. + */ + static Optional loadBaseConfig(ByteBuffer bufBuf, int count) { + for (int i = 0; i < count; i++) { + ConfigIndex cfg = new ConfigIndex(); + byte[] tag = new byte[TAG_BYTE_LENGTH]; + bufBuf.get(tag); + cfg.tag = new String(tag, StandardCharsets.UTF_8); + cfg.offset = bufBuf.getInt(); + cfg.keyCount = bufBuf.getInt(); + cfg.params = new KeyParam[cfg.keyCount]; + for (int j = 0; j < cfg.keyCount; j++) { + cfg.params[j] = new KeyParam(); + cfg.params[j].keyType = bufBuf.getInt(); + cfg.params[j].value = bufBuf.getInt(); + } + if (cfg.keyCount == 0) { + return Optional.of(cfg); + } + } + return Optional.empty(); + } + + /** + * Read base config item. + * + * @param resId resource id + * @param configIndex the config index + * @param buf config byte buffer + * @return the base item + * @throws BundleException IOException. + */ + static String readBaseItem(int resId, ConfigIndex configIndex, ByteBuffer buf) { + buf.rewind(); + buf.position(configIndex.offset); + byte[] tag = new byte[TAG_BYTE_LENGTH]; + buf.get(tag); + int count = buf.getInt(); + for (int i = 0; i < count; i++) { + int id = buf.getInt(); + int offset = buf.getInt(); + if (id == resId) { + buf.rewind(); + buf.position(offset); + DataItem item = readItem(buf); + return item.value; + } + } + return ""; + } + + /** + * Get Icon resource. + * + * @param resId resource id + * @param data resource index data array + * @return the result + * @throws BundleException IOException. + */ + static List getResource(int resId, byte[] data) { + ByteBuffer byteBuf = ByteBuffer.wrap(data); + byteBuf.order(ByteOrder.LITTLE_ENDIAN); + byte[] version = new byte[VERSION_BYTE_LENGTH]; + byteBuf.get(version); + byteBuf.getInt(); + int configCount = byteBuf.getInt(); + List cfg = loadConfig(byteBuf, configCount); + return readAllItem(resId, cfg, byteBuf); + } + + /** + * Load index config. + * + * @param bufBuf config byte buffer + * @param count config count + * @return the config list + * @throws BundleException IOException. + */ + static List loadConfig(ByteBuffer bufBuf, int count) { + List configList = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + ConfigIndex cfg = new ConfigIndex(); + byte[] tag = new byte[TAG_BYTE_LENGTH]; + bufBuf.get(tag); + cfg.tag = new String(tag, StandardCharsets.UTF_8); + cfg.offset = bufBuf.getInt(); + cfg.keyCount = bufBuf.getInt(); + cfg.params = new KeyParam[cfg.keyCount]; + for (int j = 0; j < cfg.keyCount; j++) { + cfg.params[j] = new KeyParam(); + cfg.params[j].keyType = bufBuf.getInt(); + cfg.params[j].value = bufBuf.getInt(); + } + + configList.add(cfg); + } + return configList; + } + + /** + * Read all config item. + * + * @param resId resource id + * @param configs the config list + * @param buf config byte buffer + * @return the item list + * @throws BundleException IOException. + */ + static List readAllItem(int resId, List configs, ByteBuffer buf) { + List result = new ArrayList<>(); + for (ConfigIndex index : configs) { + buf.rewind(); + buf.position(index.offset); + byte[] tag = new byte[TAG_BYTE_LENGTH]; + buf.get(tag); + int count = buf.getInt(); + for (int i = 0; i < count; i++) { + int id = buf.getInt(); + int offset = buf.getInt(); + if (id == resId) { + buf.rewind(); + buf.position(offset); + DataItem item = readItem(buf); + result.add(item.value); + break; + } + } + } + return result; + } + + /** + * Read the config item. + * + * @param buf config byte buffer + * @return the item info + * @throws BundleException IOException. + */ + static DataItem readItem(ByteBuffer buf) { + DataItem item = new DataItem(); + item.size = buf.getInt(); + item.type = buf.getInt(); + item.id = buf.getInt(); + int len = buf.get() | (buf.get() << BUF_MOVE_LENGTH); + byte[] value = new byte[len]; + buf.get(value); + item.value = new String(value, StandardCharsets.UTF_8); + len = buf.get() | (buf.get() << BUF_MOVE_LENGTH); + byte[] name = new byte[len]; + buf.get(name); + item.name = new String(name, StandardCharsets.UTF_8); + return item; + } +} + diff --git a/com/huawei/ohos/ScreenDensity.java b/adapter/ohos/ScreenDensity.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/ScreenDensity.java rename to adapter/ohos/ScreenDensity.java index 46c2ae3f3ee5f8c019bc06c4284a9d1e601581b6..62fd307ada114a4c8f2227f04aa739cb6c7b7d92 --- a/com/huawei/ohos/ScreenDensity.java +++ b/adapter/ohos/ScreenDensity.java @@ -1,38 +1,36 @@ -/* - * 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 com.huawei.ohos; - -import java.util.List; -import java.util.ArrayList; - -/** - * - * ScreenDensity info - * - * @author weiguang - * @since 2021-02-02 - */ -public class ScreenDensity { - /** - * ScreenDensity policy - */ - public String policy ; - - /** - * ScreenDensity value list - */ - public List value = null; -} +/* + * 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.List; +import java.util.ArrayList; + +/** + * + * ScreenDensity info + * + */ +public class ScreenDensity { + /** + * ScreenDensity policy + */ + public String policy ; + + /** + * ScreenDensity value list + */ + public List value = null; +} diff --git a/com/huawei/ohos/ScreenShape.java b/adapter/ohos/ScreenShape.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/ScreenShape.java rename to adapter/ohos/ScreenShape.java index aa2153866fa057c5ec77da70db0c2a87b1a0681e..f27541a92a549a9d24470be1f222bb5367b03343 --- a/com/huawei/ohos/ScreenShape.java +++ b/adapter/ohos/ScreenShape.java @@ -1,39 +1,37 @@ -/* - * 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 com.huawei.ohos; - -import java.util.List; -import java.util.ArrayList; - -/** - * - * ScreenShape info - * - * @author weiguang - * @since 2021-02-02 - */ -public class ScreenShape { - /** - * ScreenShape policy - */ - public String policy ; - - /** - * ScreenShape value list - */ - public List value = null; - -} +/* + * 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.List; +import java.util.ArrayList; + +/** + * + * ScreenShape info + * + */ +public class ScreenShape { + /** + * ScreenShape policy + */ + public String policy ; + + /** + * ScreenShape value list + */ + public List value = null; + +} diff --git a/com/huawei/ohos/ScreenWindow.java b/adapter/ohos/ScreenWindow.java old mode 100755 new mode 100644 similarity index 89% rename from com/huawei/ohos/ScreenWindow.java rename to adapter/ohos/ScreenWindow.java index 643ad8b196467a97a255cf3b9d01d106d1942621..e762ac93a8bedc4cc77ef08a78b48ab42adcc2b1 --- a/com/huawei/ohos/ScreenWindow.java +++ b/adapter/ohos/ScreenWindow.java @@ -1,39 +1,37 @@ -/* - * 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 com.huawei.ohos; - -import java.util.List; -import java.util.ArrayList; - -/** - * - * ScreenWindow info - * - * @author weiguang - * @since 2021-02-02 - */ -public class ScreenWindow { - /** - * ScreenWindow policy - */ - public String policy ; - - /** - * ScreenWindow value list - */ - public List value = null; - -} +/* + * 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.List; +import java.util.ArrayList; + +/** + * + * ScreenWindow info + * + */ +public class ScreenWindow { + /** + * ScreenWindow policy + */ + public String policy ; + + /** + * ScreenWindow value list + */ + public List value = null; + +} diff --git a/com/huawei/ohos/Shortcut.java b/adapter/ohos/Shortcut.java old mode 100755 new mode 100644 similarity index 90% rename from com/huawei/ohos/Shortcut.java rename to adapter/ohos/Shortcut.java index 78f3d484d486b1c88130138805de7468ea4e4364..f1a683bf2751328f4678784540e632214690afda --- a/com/huawei/ohos/Shortcut.java +++ b/adapter/ohos/Shortcut.java @@ -1,47 +1,45 @@ -/* - * 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 com.huawei.ohos; - -import java.util.ArrayList; -import java.util.List; - -/** - * App Shortcut info. - * - * @author dingyao - * @since 2020-05-19 - */ -public class Shortcut { - /** - * Indicates the shortcutId of app Shortcut. - */ - public String shortcutId = ""; - - /** - * Indicates the label of app Shortcut. - */ - public String label = ""; - - /** - * Indicates the icon of app Shortcut. - */ - public String icon = ""; - - /** - * Indicates the intents of app Shortcut. - */ - public List intents = new ArrayList(); -} +/* + * 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; + +/** + * App Shortcut info. + * + */ +public class Shortcut { + /** + * Indicates the shortcutId of app Shortcut. + */ + public String shortcutId = ""; + + /** + * Indicates the label of app Shortcut. + */ + public String label = ""; + + /** + * Indicates the icon of app Shortcut. + */ + public String icon = ""; + + /** + * Indicates the intents of app Shortcut. + */ + public List intents = new ArrayList(); +} diff --git a/com/huawei/ohos/ShowHelp.java b/adapter/ohos/ShowHelp.java old mode 100755 new mode 100644 similarity index 97% rename from com/huawei/ohos/ShowHelp.java rename to adapter/ohos/ShowHelp.java index 57aeb1c91a3cef1f847bbe518d3dad72e9e3d860..5c31cd7b93cd2701d807e4fcb7fc9f3f4620e926 --- a/com/huawei/ohos/ShowHelp.java +++ b/adapter/ohos/ShowHelp.java @@ -1,132 +1,130 @@ -/* - * 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 com.huawei.ohos; - -/** - * showhelp class of compress tool. - * - * @author huzeqi - * @since 2019-10-25 - */ -public interface ShowHelp { - Log log = new Log(ShowHelp.class.toString()); - /** - * content of compress command help menu. - */ - static void compressHelp() { - log.info("\nHAP USAGE:\n" + - "java -jar hmos_app_packing_tool.jar --mode --json-path