1 /* 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H 17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H 18 19 #include <list> 20 #include <string> 21 22 #include "pt_json.h" 23 24 namespace OHOS { 25 namespace AppPackingTool { 26 struct PackInfoVersion { 27 int32_t code = -1; 28 std::string name = ""; 29 }; 30 31 class PackInfo { 32 public: PackInfo()33 PackInfo() {}; ~PackInfo()34 virtual ~PackInfo() {}; 35 36 bool ParseFromString(const std::string& jsonString); 37 bool ParseFromFile(const std::string& jsonFile); 38 std::string ToString(); 39 void Release(); 40 41 bool IsValid(); 42 43 // object funcs 44 bool GetSummaryObject(std::unique_ptr<PtJson>& summaryObj); 45 bool GetPackagesObject(std::unique_ptr<PtJson>& packagesObj); 46 bool GetAppObject(std::unique_ptr<PtJson>& appObj); 47 bool GetModulesObject(std::unique_ptr<PtJson>& modulesObj); 48 bool GetVersionObject(std::unique_ptr<PtJson>& versionObj); 49 bool GetDistroObject(int32_t moduleIndex, std::unique_ptr<PtJson>& distroObj); 50 bool GetDistroObjectByModulesObj(const std::unique_ptr<PtJson>& modulesObj, 51 int32_t moduleIndex, std::unique_ptr<PtJson>& distroObj); 52 bool GetDistroObjectByModuleObj(const std::unique_ptr<PtJson>& moduleObj, 53 std::unique_ptr<PtJson>& distroObj); 54 bool GetApiVersionObjectByModuleObj(const std::unique_ptr<PtJson>& moduleObj, 55 std::unique_ptr<PtJson>& distroObj); 56 bool GetPackageObject(int32_t packageIndex, std::unique_ptr<PtJson>& packageObj); 57 bool GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr<PtJson>& extensionAbilitiesObj); 58 bool GetExtensionAbilitiesObjByModulesObj(const std::unique_ptr<PtJson>& modulesObj, 59 int32_t moduleIndex, std::unique_ptr<PtJson>& extensionAbilitiesObj); 60 bool GetExtensionAbilitiesObjByModuleObj(const std::unique_ptr<PtJson>& moduleObj, 61 std::unique_ptr<PtJson>& extensionAbilitiesObj); 62 bool GetFormsObjByExtensionAbilityObj(const std::unique_ptr<PtJson>& extensionAbilityObj, 63 std::unique_ptr<PtJson>& formsObj); 64 65 // funcs 66 bool GetBundleName(std::string& bundleName); 67 bool GetBundleNameByAppObj(const std::unique_ptr<PtJson>& appObj, std::string& bundleName); 68 bool SetBundleName(const std::string& bundleName); 69 bool GetBundleType(std::string& bundleType, const std::string& defaultBundleType); 70 bool GetBundleTypeByAppObj(const std::unique_ptr<PtJson>& appObj, std::string& bundleType, 71 const std::string& defaultBundleType); 72 bool GetVersion(PackInfoVersion& version); 73 bool GetVersionByVersionObj(const std::unique_ptr<PtJson>& appObj, PackInfoVersion& version); 74 bool SetVersionCode(const int32_t& versionCode); 75 bool SetVersionName(const std::string& versionName); 76 bool GetModuleNameByDistroObj(const std::unique_ptr<PtJson>& distroObj, std::string& moduleName); 77 bool GetNameByPackageObj(const std::unique_ptr<PtJson>& packageObj, std::string& name); 78 bool GetNameByFormObj(const std::unique_ptr<PtJson>& formObj, std::string& name); 79 bool GetDefaultDimensionByFormObj(const std::unique_ptr<PtJson>& formObj, std::string& defaultDimension); 80 bool GetSupportDimensionsByFormObj(const std::unique_ptr<PtJson>& formObj, 81 std::list<std::string>& supportDimensions); 82 bool GetFormNames(std::list<std::string>& formNames, std::list<std::string>& formFullNames); 83 bool GetFormNamesByExtensionAbilitiesObj(const std::unique_ptr<PtJson>& extensionAbilitiesObj, 84 std::string moduleName, std::list<std::string>& formNames, std::list<std::string>& formFullNames); 85 bool GetFormNamesByFormsObj(const std::unique_ptr<PtJson>& formsObj, 86 std::string moduleName, std::list<std::string>& formNames, std::list<std::string>& formFullNames); 87 bool GetPackageNames(std::list<std::string> &packageNames); 88 bool GetPackageNamesByPackagesObj(const std::unique_ptr<PtJson>& appObj, std::list<std::string> &packageNames); 89 90 bool SetMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode); 91 bool SetMinAPIVersion(const int32_t& minAPIVersion); 92 bool SetTargetAPIVersion(const int32_t& targetAPIVersion); 93 bool SetApiReleaseType(const std::string& apiReleaseType); 94 bool SetBundleType(const std::string& bundleType); 95 bool SetInstallationFree(const bool& installationFree); 96 bool SetDeliveryWithInstall(const bool& deliveryWithInstall); 97 bool SetDeviceTypes(const std::list<std::string>& deviceTypes); 98 99 private: 100 std::unique_ptr<PtJson> root_ = nullptr; 101 }; 102 } // namespace AppPackingTool 103 } // namespace OHOS 104 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H 105