1 /* 2 * Copyright (c) 2021-2024 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H 18 19 #include <set> 20 #include <string> 21 #include <unordered_set> 22 23 #include "app_privilege_capability.h" 24 #include "appexecfwk_errors.h" 25 #include "default_permission.h" 26 #include "inner_bundle_info.h" 27 #include "module_test_runner.h" 28 #include "pre_scan_info.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class BundleParser { 33 private: 34 bool CheckRouterData(nlohmann::json data) const; 35 public: 36 static bool ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf); 37 /** 38 * @brief Parse bundle by the path name, then save in innerBundleInfo info. 39 * @param pathName Indicates the path of Bundle. 40 * @param innerBundleInfo Indicates the obtained InnerBundleInfo object. 41 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 42 */ 43 ErrCode Parse( 44 const std::string &pathName, 45 InnerBundleInfo &innerBundleInfo) const; 46 47 ErrCode ParsePackInfo(const std::string &pathName, BundlePackInfo &bundlePackInfo) const; 48 /** 49 * @brief Parse bundle by the path name, then save in innerBundleInfo info. 50 * @param pathName Indicates the path of Bundle. 51 * @param sysCaps Indicates the sysCap. 52 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 53 */ 54 ErrCode ParseSysCap(const std::string &pathName, std::vector<std::string> &sysCaps) const; 55 /** 56 * @brief Parse scanInfos by the configFile. 57 * @param configFile Indicates the path of configFile. 58 * @param scanInfos Indicates the obtained InnerBundleInfo object. 59 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 60 */ 61 ErrCode ParsePreInstallConfig( 62 const std::string &configFile, std::set<PreScanInfo> &scanInfos) const; 63 /** 64 * @brief Parse scanAppInfos by the configFile. 65 * @param configFile Indicates the path of configFile. 66 * @param scanInfos Indicates the obtained InnerBundleInfo object. 67 * @param scanDemandInfos Indicates the obtained onDemandBundleInfo object. 68 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 69 */ 70 ErrCode ParsePreAppListConfig(const std::string &configFile, std::set<PreScanInfo> &scanAppInfos, 71 std::set<PreScanInfo> &scanDemandInfos) const; 72 /** 73 * @brief Parse scanInfos by the configFile. 74 * @param configFile Indicates the path of configFile. 75 * @param scanInfos Indicates the obtained InnerBundleInfo object. 76 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 77 */ 78 ErrCode ParseDemandInstallConfig( 79 const std::string &configFile, std::set<PreScanInfo> &scanInfos) const; 80 /** 81 * @brief Parse bundleNames by the configFile. 82 * @param configFile Indicates the path of configFile. 83 * @param uninstallList Indicates the uninstallList. 84 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 85 */ 86 ErrCode ParsePreUnInstallConfig( 87 const std::string &configFile, 88 std::set<std::string> &uninstallList) const; 89 /** 90 * @brief Parse PreBundleConfigInfo by the configFile. 91 * @param configFile Indicates the path of configFile. 92 * @param preBundleConfigInfos Indicates the obtained preBundleConfigInfo object. 93 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 94 */ 95 ErrCode ParsePreInstallAbilityConfig( 96 const std::string &configFile, std::set<PreBundleConfigInfo> &preBundleConfigInfos) const; 97 98 /** 99 * @brief Parse default permission file, then save in DefaultPermission info. 100 * @param permissionFile Indicates the permissionFile. 101 * @param defaultPermissions Indicates the obtained DefaultPermission object. 102 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 103 */ 104 ErrCode ParseDefaultPermission( 105 const std::string &permissionFile, std::set<DefaultPermission> &defaultPermissions) const; 106 107 static std::map<std::string, std::string> ParseAclExtendedMap(const std::string &appServiceCapabilities); 108 109 /** 110 * @brief Parse default extension type name file, then save in ParseExtensionTypeConfig info. 111 * @param configFile Indicates the path of configFile. 112 * @param extensionTypeList Indicates the obtained extension type name list. 113 * @return Returns ERR_OK if the extensionType successfully parsed; returns ErrCode otherwise. 114 */ 115 ErrCode ParseExtTypeConfig( 116 const std::string &configFile, std::set<std::string> &extensionTypeList) const; 117 118 /** 119 * @brief Parse router map json file, then return router map info if necessary. 120 * @param configFile Indicates the path of configFile. 121 * @param routerArray Indicates the obtained router item list. 122 * @return Returns ERR_OK if the router info successfully parsed; returns ErrCode otherwise. 123 */ 124 ErrCode ParseRouterArray( 125 const std::string &configFile, std::vector<RouterItem> &routerArray) const; 126 127 static ErrCode ParseNoDisablingList(const std::string &configPath, std::vector<std::string> &noDisablingList); 128 /** 129 * @brief Parse bundleNames by the configFile. 130 * @param configFile Indicates the path of configFile. 131 * @param bundleNames Indicates the ark startup cache list. 132 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 133 */ 134 static ErrCode ParseArkStartupCacheConfig(const std::string &configFile, 135 std::unordered_set<std::string> &bundleNames); 136 137 ErrCode ParseTestRunner(const std::string &hapPath, ModuleTestRunner &testRunner) const; 138 }; 139 } // namespace AppExecFwk 140 } // namespace OHOS 141 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H 142