1 /* 2 * Copyright (c) 2021-2023 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 bundleNames by the configFile. 63 * @param configFile Indicates the path of configFile. 64 * @param uninstallList Indicates the uninstallList. 65 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 66 */ 67 ErrCode ParsePreUnInstallConfig( 68 const std::string &configFile, 69 std::set<std::string> &uninstallList) const; 70 /** 71 * @brief Parse PreBundleConfigInfo by the configFile. 72 * @param configFile Indicates the path of configFile. 73 * @param preBundleConfigInfos Indicates the obtained preBundleConfigInfo object. 74 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 75 */ 76 ErrCode ParsePreInstallAbilityConfig( 77 const std::string &configFile, std::set<PreBundleConfigInfo> &preBundleConfigInfos) const; 78 79 /** 80 * @brief Parse default permission file, then save in DefaultPermission info. 81 * @param permissionFile Indicates the permissionFile. 82 * @param defaultPermissions Indicates the obtained DefaultPermission object. 83 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 84 */ 85 ErrCode ParseDefaultPermission( 86 const std::string &permissionFile, std::set<DefaultPermission> &defaultPermissions) const; 87 88 /** 89 * @brief Parse default extension type name file, then save in ParseExtensionTypeConfig info. 90 * @param configFile Indicates the path of configFile. 91 * @param extensionTypeList Indicates the obtained extension type name list. 92 * @return Returns ERR_OK if the extensionType successfully parsed; returns ErrCode otherwise. 93 */ 94 ErrCode ParseExtTypeConfig( 95 const std::string &configFile, std::set<std::string> &extensionTypeList) const; 96 97 /** 98 * @brief Parse router map json file, then return router map info if necessary. 99 * @param configFile Indicates the path of configFile. 100 * @param routerArray Indicates the obtained router item list. 101 * @return Returns ERR_OK if the router info successfully parsed; returns ErrCode otherwise. 102 */ 103 ErrCode ParseRouterArray( 104 const std::string &configFile, std::vector<RouterItem> &routerArray) const; 105 106 static ErrCode ParseNoDisablingList(const std::string &configPath, std::vector<std::string> &noDisablingList); 107 }; 108 } // namespace AppExecFwk 109 } // namespace OHOS 110 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H 111