1600cc4afSopenharmony_ci/*
2600cc4afSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3600cc4afSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4600cc4afSopenharmony_ci * you may not use this file except in compliance with the License.
5600cc4afSopenharmony_ci * You may obtain a copy of the License at
6600cc4afSopenharmony_ci *
7600cc4afSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8600cc4afSopenharmony_ci *
9600cc4afSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10600cc4afSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11600cc4afSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12600cc4afSopenharmony_ci * See the License for the specific language governing permissions and
13600cc4afSopenharmony_ci * limitations under the License.
14600cc4afSopenharmony_ci */
15600cc4afSopenharmony_ci
16600cc4afSopenharmony_ci#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H
17600cc4afSopenharmony_ci#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H
18600cc4afSopenharmony_ci
19600cc4afSopenharmony_ci#include <set>
20600cc4afSopenharmony_ci#include <string>
21600cc4afSopenharmony_ci
22600cc4afSopenharmony_ci#include "app_privilege_capability.h"
23600cc4afSopenharmony_ci#include "appexecfwk_errors.h"
24600cc4afSopenharmony_ci#include "default_permission.h"
25600cc4afSopenharmony_ci#include "inner_bundle_info.h"
26600cc4afSopenharmony_ci#include "pre_scan_info.h"
27600cc4afSopenharmony_ci
28600cc4afSopenharmony_cinamespace OHOS {
29600cc4afSopenharmony_cinamespace AppExecFwk {
30600cc4afSopenharmony_ciclass BundleParser {
31600cc4afSopenharmony_ciprivate:
32600cc4afSopenharmony_ci    bool CheckRouterData(nlohmann::json data) const;
33600cc4afSopenharmony_cipublic:
34600cc4afSopenharmony_ci    static bool ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf);
35600cc4afSopenharmony_ci    /**
36600cc4afSopenharmony_ci     * @brief Parse bundle by the path name, then save in innerBundleInfo info.
37600cc4afSopenharmony_ci     * @param pathName Indicates the path of Bundle.
38600cc4afSopenharmony_ci     * @param innerBundleInfo Indicates the obtained InnerBundleInfo object.
39600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
40600cc4afSopenharmony_ci     */
41600cc4afSopenharmony_ci    ErrCode Parse(
42600cc4afSopenharmony_ci        const std::string &pathName,
43600cc4afSopenharmony_ci        InnerBundleInfo &innerBundleInfo) const;
44600cc4afSopenharmony_ci
45600cc4afSopenharmony_ci    ErrCode ParsePackInfo(const std::string &pathName, BundlePackInfo &bundlePackInfo) const;
46600cc4afSopenharmony_ci    /**
47600cc4afSopenharmony_ci     * @brief Parse bundle by the path name, then save in innerBundleInfo info.
48600cc4afSopenharmony_ci     * @param pathName Indicates the path of Bundle.
49600cc4afSopenharmony_ci     * @param sysCaps Indicates the sysCap.
50600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
51600cc4afSopenharmony_ci     */
52600cc4afSopenharmony_ci    ErrCode ParseSysCap(const std::string &pathName, std::vector<std::string> &sysCaps) const;
53600cc4afSopenharmony_ci    /**
54600cc4afSopenharmony_ci     * @brief Parse scanInfos by the configFile.
55600cc4afSopenharmony_ci     * @param configFile Indicates the path of configFile.
56600cc4afSopenharmony_ci     * @param scanInfos Indicates the obtained InnerBundleInfo object.
57600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
58600cc4afSopenharmony_ci     */
59600cc4afSopenharmony_ci    ErrCode ParsePreInstallConfig(
60600cc4afSopenharmony_ci        const std::string &configFile, std::set<PreScanInfo> &scanInfos) const;
61600cc4afSopenharmony_ci    /**
62600cc4afSopenharmony_ci     * @brief Parse bundleNames by the configFile.
63600cc4afSopenharmony_ci     * @param configFile Indicates the path of configFile.
64600cc4afSopenharmony_ci     * @param uninstallList Indicates the uninstallList.
65600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
66600cc4afSopenharmony_ci     */
67600cc4afSopenharmony_ci    ErrCode ParsePreUnInstallConfig(
68600cc4afSopenharmony_ci        const std::string &configFile,
69600cc4afSopenharmony_ci        std::set<std::string> &uninstallList) const;
70600cc4afSopenharmony_ci    /**
71600cc4afSopenharmony_ci     * @brief Parse PreBundleConfigInfo by the configFile.
72600cc4afSopenharmony_ci     * @param configFile Indicates the path of configFile.
73600cc4afSopenharmony_ci     * @param preBundleConfigInfos Indicates the obtained preBundleConfigInfo object.
74600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
75600cc4afSopenharmony_ci     */
76600cc4afSopenharmony_ci    ErrCode ParsePreInstallAbilityConfig(
77600cc4afSopenharmony_ci        const std::string &configFile, std::set<PreBundleConfigInfo> &preBundleConfigInfos) const;
78600cc4afSopenharmony_ci
79600cc4afSopenharmony_ci    /**
80600cc4afSopenharmony_ci     * @brief Parse default permission file, then save in DefaultPermission info.
81600cc4afSopenharmony_ci     * @param permissionFile Indicates the permissionFile.
82600cc4afSopenharmony_ci     * @param defaultPermissions Indicates the obtained DefaultPermission object.
83600cc4afSopenharmony_ci     * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
84600cc4afSopenharmony_ci     */
85600cc4afSopenharmony_ci    ErrCode ParseDefaultPermission(
86600cc4afSopenharmony_ci        const std::string &permissionFile, std::set<DefaultPermission> &defaultPermissions) const;
87600cc4afSopenharmony_ci
88600cc4afSopenharmony_ci    /**
89600cc4afSopenharmony_ci     * @brief Parse default extension type name file, then save in ParseExtensionTypeConfig info.
90600cc4afSopenharmony_ci     * @param configFile Indicates the path of configFile.
91600cc4afSopenharmony_ci     * @param extensionTypeList Indicates the obtained extension type name list.
92600cc4afSopenharmony_ci     * @return Returns ERR_OK if the extensionType successfully parsed; returns ErrCode otherwise.
93600cc4afSopenharmony_ci     */
94600cc4afSopenharmony_ci    ErrCode ParseExtTypeConfig(
95600cc4afSopenharmony_ci        const std::string &configFile, std::set<std::string> &extensionTypeList) const;
96600cc4afSopenharmony_ci
97600cc4afSopenharmony_ci    /**
98600cc4afSopenharmony_ci     * @brief Parse router map json file, then return router map info if necessary.
99600cc4afSopenharmony_ci     * @param configFile Indicates the path of configFile.
100600cc4afSopenharmony_ci     * @param routerArray Indicates the obtained router item list.
101600cc4afSopenharmony_ci     * @return Returns ERR_OK if the router info successfully parsed; returns ErrCode otherwise.
102600cc4afSopenharmony_ci     */
103600cc4afSopenharmony_ci    ErrCode ParseRouterArray(
104600cc4afSopenharmony_ci        const std::string &configFile, std::vector<RouterItem> &routerArray) const;
105600cc4afSopenharmony_ci
106600cc4afSopenharmony_ci    static ErrCode ParseNoDisablingList(const std::string &configPath, std::vector<std::string> &noDisablingList);
107600cc4afSopenharmony_ci};
108600cc4afSopenharmony_ci}  // namespace AppExecFwk
109600cc4afSopenharmony_ci}  // namespace OHOS
110600cc4afSopenharmony_ci#endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_PARSER_H
111