• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_CLONE_MGR_H
16 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_CLONE_MGR_H
17 
18 #include <string>
19 #include "nocopyable.h"
20 #include "appexecfwk_errors.h"
21 #include "inner_bundle_info.h"
22 #include "install_param.h"
23 #include "bundle_data_mgr.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class BundleCloneMgr {
28 public:
29     BundleCloneMgr();
30     ~BundleCloneMgr();
31     /**
32      * @brief Remove cloned bundle.
33      * @param oldName Indicates the ontology application bundle name.
34      * @param bundleName Indicates the bundle name of remove cloned bundle.
35      * @return Returns true if this function is successfully called; returns false otherwise.
36      */
37     bool RemoveClonedBundle(const std::string &oldName, const std::string &bundleName);
38     /**
39      * @brief create bundle clone.
40      * @param bundleName Indicates the bundle name of create bundle clone.
41      * @return Returns true if this function is successfully called; returns false otherwise.
42      */
43     bool BundleClone(const std::string &bundleName);
44     /**
45      * @brief Set clone name into CloneAppName.json.
46      * @param bundleName Indicates the cloned name to be set.
47      * @return Returns true if this function is successfully called; returns false otherwise.
48      */
49     bool SetCloneAppName(const std::string &bundleName);
50     /**
51      * @brief Delete cloned bundle's name from CloneAppName.json.
52      * @param bundleName Indicates the cloned bundle's name.
53      * @return Returns true if this function is successfully called; returns false otherwise.
54      */
55     bool DeleteCloneAppName(const std::string &bundleName);
56     /**
57      * @brief The real procedure for bundle clone.
58      * @param bundleName Indicates the bundle name of bundle clone.
59      * @return Returns ERR_OK if the bundle clone successfully; returns error code otherwise.
60      */
61     ErrCode ProcessCloneInstall(const std::string &bundleName);
62     /**
63      * @brief Create the code and data directories of a bundle.
64      * @param info Indicates the InnerBundleInfo object of a bundle.
65      * @return Returns ERR_OK if the bundle directories created successfully; returns error code otherwise.
66      */
67     ErrCode CreateBundleAndDataDir(InnerBundleInfo &info) const;
68     /**
69      * @brief Update the bundle paths in the InnerBundleInfo object.
70      * @param info Indicates the InnerBundleInfo object of a bundle under clone.
71      * @param baseDataPath Indicates the data file paths.
72      * @return Returns true if the path set successfully; returns false otherwise.
73      */
74     bool UpdateBundlePaths(InnerBundleInfo &info, const std::string baseDataPath) const;
75     /**
76      * @brief Modify the clone directory path for different clone type.
77      * @param info Indicates the InnerBundleInfo object of a bundle under clone.
78      * @return Returns true if the path set successfully; returns false otherwise.
79      */
80     bool ModifyInstallDirByHapType(InnerBundleInfo &info);
81     /**
82      * @brief Extract the code to temporilay directory and rename it.
83      * @param info Indicates the InnerBundleInfo object of a bundle.
84      * @return Returns ERR_OK if the bundle extract and renamed successfully; returns error code otherwise.
85      */
86     ErrCode ExtractModuleAndRename(InnerBundleInfo &info);
87     /**
88      * @brief Extract files of the current clone module package.
89      * @param info Indicates the InnerBundleInfo object of a bundle under clone.
90      * @return Returns ERR_OK if the module files extraced successfully; returns error code otherwise.
91      */
92     ErrCode ExtractModuleFiles(InnerBundleInfo &info);
93     /**
94      * @brief Create the data directories of current clone module package.
95      * @param info Indicates the InnerBundleInfo object of a bundle under clone.
96      * @return Returns ERR_OK if the module directory created successfully; returns error code otherwise.
97      */
98     ErrCode CreateModuleDataDir(InnerBundleInfo &info) const;
99     /**
100      * @brief Create clone bundle info.
101      * @param bundleName Indicates the bundle Names.
102      * @return Returns true if clone bundle is success; returns false otherwise.
103      */
104     bool CreateCloneBundleInfo(const std::string &bundleName);
105     /**
106      * @brief Save the cloned info to DB.
107      * @return Returns true if save cloned info successfully; returns false otherwise.
108      */
109     bool SaveNewInfoToDB();
110     /**
111      * @brief Determine whether the application is in the allow list.
112      * @param bundleName Indicates the bundle Names.
113      * @return Returns true if bundle name in the allow list successfully; returns false otherwise.
114      */
115     bool CheckBundleNameInAllowList(const std::string &bundleName);
116 
117 private:
118     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;  // this pointer will get when public functions called
119     std::string bundleName_;
120     std::string moduleTmpDir_;
121     std::string modulePath_;
122     std::string baseCodePath_;
123     std::string baseDataPath_;
124     std::string modulePackage_;
125     std::string mainAbility_;
126     InnerBundleInfo cloneInfo_;
127 };
128 }  // namespace AppExecFwk
129 }  // namespace OHOS
130 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_CLONE_MGR_H