• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_INNER_SHARED_BUNDLE_INSTALLER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_SHARED_BUNDLE_INSTALLER_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "bundle_install_checker.h"
24 #include "event_report.h"
25 #include "inner_bundle_info.h"
26 #include "install_param.h"
27 #include "nocopyable.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 class InnerSharedBundleInstaller {
32 public:
33     /**
34      * @brief Cross-app shared bundle installer for hsp files of same bundle.
35      * @param path Indicates the real path or the parent directory of hsp files to be installed.
36      */
37     explicit InnerSharedBundleInstaller(const std::string &path);
38     virtual ~InnerSharedBundleInstaller();
39 
40     /**
41      * @brief Parse cross-app hsp files of same bundle.
42      * @param checkParam Indicates the install check param.
43      * @return Returns ERR_OK if the files are parsed successfully; returns error code otherwise.
44      */
45     ErrCode ParseFiles(const InstallCheckParam &checkParam);
46 
47     /**
48      * @brief Get the bundle name of current shared bundle to be installed.
49      * @return Returns the bundle name of current shared bundle to be installed.
50      */
GetBundleName()51     inline std::string GetBundleName() const
52     {
53         return bundleName_;
54     }
55 
56     /**
57      * @brief Install cross-app shared bundles of same bundle.
58      * @param installParam Indicates the install param.
59      * @return Returns ERR_OK if the files are installed successfully; returns error code otherwise.
60      */
61     ErrCode Install(const InstallParam &installParam);
62 
63     /**
64      * @brief Roll back the install action.
65     */
66     void RollBack();
67 
68     /**
69      * @brief Checks whether the dependency is satisfied by current installing shared bundle.
70      * @param dependency Indicates the dependency to be checked.
71      * @return Returns true if the dependency is satisfied; returns false otherwise.
72      */
73     bool CheckDependency(const Dependency &dependency) const;
74 
75     /**
76      * @brief Send bundle system event.
77      * @param eventTemplate Indicates the template of EventInfo to send after installation.
78      */
79     void SendBundleSystemEvent(const EventInfo &eventTemplate) const;
80 
81 private:
82     ErrCode CheckAppLabelInfo();
83     ErrCode CheckBundleTypeWithInstalledVersion();
84     ErrCode ExtractSharedBundles(const std::string &bundlePath, InnerBundleInfo &newInfo);
85     ErrCode MkdirIfNotExist(const std::string &dir);
86     void MergeBundleInfos();
87     ErrCode SavePreInstallInfo(const InstallParam &installParam);
88     ErrCode SaveBundleInfoToStorage();
89     void GetInstallEventInfo(EventInfo &eventInfo) const;
90     void AddAppProvisionInfo(const std::string &bundleName,
91         const Security::Verify::ProvisionInfo &provisionInfo) const;
92     void SaveInstallParamInfo(const std::string &bundleName, const InstallParam &installParam) const;
93     ErrCode CopyHspToSecurityDir(std::vector<std::string> &bundlePaths);
94     ErrCode ObtainHspFileAndSignatureFilePath(const std::vector<std::string> &inBundlePaths,
95         std::vector<std::string> &bundlePaths, std::string &signatureFilePath);
96     ErrCode SaveHspToRealInstallationDir(const std::string &bundlePath, const std::string &moduleDir,
97         const std::string &moduleName, const std::string &realHspPath);
98     std::string ObtainTempSoPath(const std::string &moduleName, const std::string &nativeLibPath);
99     ErrCode MoveSoToRealPath(const std::string &moduleName, const std::string &versionDir);
100     ErrCode ProcessNativeLibrary(const std::string &bundlePath,
101         const std::string &moduleDir, const std::string &moduleName, const std::string &versionDir,
102         InnerBundleInfo &newInfo);
103 
104     // the real path or the parent directory of hsp files to be installed.
105     std::string sharedBundlePath_;
106     std::string bundleName_;
107     std::string signatureFileDir_;
108     std::vector<std::string> toDeleteTempHspPath_;
109     // the key is the real path of each hsp file
110     std::unordered_map<std::string, InnerBundleInfo> parsedBundles_;
111     // created directories during installation, will be deleted when rollback.
112     std::vector<std::string> createdDirs_;
113     bool isBundleExist_ = false;
114     InnerBundleInfo oldBundleInfo_;
115     InnerBundleInfo newBundleInfo_;
116     std::unique_ptr<BundleInstallChecker> bundleInstallChecker_ = nullptr;
117     std::string nativeLibraryPath_;
118 
119     DISALLOW_COPY_AND_MOVE(InnerSharedBundleInstaller);
120 
121 #define CHECK_RESULT(errcode, errmsg)                                              \
122     do {                                                                           \
123         if (errcode != ERR_OK) {                                                   \
124             APP_LOGE(errmsg, errcode);                                             \
125             return errcode;                                                        \
126         }                                                                          \
127     } while (0)
128 };
129 }  // namespace AppExecFwk
130 }  // namespace OHOS
131 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_SHARED_BUNDLE_INSTALLER_H