1 /* 2 * Copyright (c) 2021-2022 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 public: 32 static bool ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf); 33 /** 34 * @brief Parse bundle by the path name, then save in innerBundleInfo info. 35 * @param pathName Indicates the path of Bundle. 36 * @param innerBundleInfo Indicates the obtained InnerBundleInfo object. 37 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 38 */ 39 ErrCode Parse( 40 const std::string &pathName, 41 InnerBundleInfo &innerBundleInfo) const; 42 43 ErrCode ParsePackInfo(const std::string &pathName, BundlePackInfo &bundlePackInfo) const; 44 /** 45 * @brief Parse bundle by the path name, then save in innerBundleInfo info. 46 * @param pathName Indicates the path of Bundle. 47 * @param sysCaps Indicates the sysCap. 48 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 49 */ 50 ErrCode ParseSysCap(const std::string &pathName, std::vector<std::string> &sysCaps) const; 51 /** 52 * @brief Parse scanInfos by the configFile. 53 * @param configFile Indicates the path of configFile. 54 * @param scanInfos Indicates the obtained InnerBundleInfo object. 55 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 56 */ 57 ErrCode ParsePreInstallConfig( 58 const std::string &configFile, std::set<PreScanInfo> &scanInfos) const; 59 /** 60 * @brief Parse bundleNames by the configFile. 61 * @param configFile Indicates the path of configFile. 62 * @param uninstallList Indicates the uninstallList. 63 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 64 */ 65 ErrCode ParsePreUnInstallConfig( 66 const std::string &configFile, 67 std::set<std::string> &uninstallList) const; 68 /** 69 * @brief Parse PreBundleConfigInfo by the configFile. 70 * @param configFile Indicates the path of configFile. 71 * @param preBundleConfigInfos Indicates the obtained preBundleConfigInfo object. 72 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 73 */ 74 ErrCode ParsePreInstallAbilityConfig( 75 const std::string &configFile, std::set<PreBundleConfigInfo> &preBundleConfigInfos) const; 76 77 /** 78 * @brief Parse default permission file, then save in DefaultPermission info. 79 * @param permissionFile Indicates the permissionFile. 80 * @param defaultPermissions Indicates the obtained DefaultPermission object. 81 * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. 82 */ 83 ErrCode ParseDefaultPermission( 84 const std::string &permissionFile, std::set<DefaultPermission> &defaultPermissions) const; 85 }; 86 } // namespace AppExecFwk 87 } // namespace OHOS 88 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H 89