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