• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_APP_SERVICE_FWK_INSTALLER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_APP_SERVICE_FWK_INSTALLER_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "bundle_data_mgr.h"
24 #include "bundle_install_checker.h"
25 #include "event_report.h"
26 #include "inner_bundle_info.h"
27 #include "install_param.h"
28 #include "nocopyable.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 class AppServiceFwkInstaller {
33 public:
34     AppServiceFwkInstaller();
35     virtual ~AppServiceFwkInstaller();
36 
37     ErrCode Install(
38         const std::vector<std::string> &hspPaths, InstallParam &installParam);
39     ErrCode UnInstall(const std::string &bundleName, bool isKeepData = false);
40     ErrCode UnInstall(const std::string &bundleName, const std::string &moduleName);
41 private:
42     void ResetProperties();
43     ErrCode BeforeInstall(
44         const std::vector<std::string> &hspPaths, InstallParam &installParam);
45     ErrCode BeforeUninstall(const std::string &bundleName);
46     bool CheckNeedUninstallBundle(const std::string &moduleName, const InnerBundleInfo &info);
47     ErrCode UnInstall(const std::string &bundleName, const std::string &moduleName, InnerBundleInfo &oldInfo);
48     void RemoveModuleDataDir(
49         const std::string &bundleName, const std::string &moduleName, const InnerBundleInfo &oldInfo);
50     ErrCode ProcessInstall(
51         const std::vector<std::string> &hspPaths, InstallParam &installParam);
52     ErrCode CheckAndParseFiles(
53         const std::vector<std::string> &hspPaths, InstallParam &installParam,
54         std::unordered_map<std::string, InnerBundleInfo> &newInfos);
55     ErrCode InnerProcessInstall(
56         std::unordered_map<std::string, InnerBundleInfo> &newInfos,
57         InstallParam &installParam);
58     ErrCode CheckAppLabelInfo(
59         const std::unordered_map<std::string, InnerBundleInfo> &infos);
60     ErrCode CheckFileType(const std::vector<std::string> &bundlePaths);
61     void SendBundleSystemEvent(
62         const std::vector<std::string> &hspPaths, BundleEventType bundleEventType,
63         const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode);
64     ErrCode ExtractModule(
65         InnerBundleInfo &newInfo, const std::string &bundlePath, bool copyHapToInstallPath = false);
66     ErrCode ExtractModule(InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo, const std::string &bundlePath);
67     ErrCode MkdirIfNotExist(const std::string &dir);
68     ErrCode ProcessNativeLibrary(
69         const std::string &bundlePath,
70         const std::string &moduleDir,
71         const std::string &moduleName,
72         const std::string &versionDir,
73         InnerBundleInfo &newInfo,
74         bool copyHapToInstallPath = false);
75     ErrCode MoveSoToRealPath(
76         const std::string &moduleName, const std::string &versionDir,
77         const std::string &nativeLibraryPath);
78     void MergeBundleInfos(InnerBundleInfo &info);
79     ErrCode SaveBundleInfoToStorage();
80     void AddAppProvisionInfo(
81         const std::string &bundleName,
82         const Security::Verify::ProvisionInfo &provisionInfo,
83         const InstallParam &installParam) const;
84 
85     void RollBack();
86     void RemoveInfo(const std::string &bundleName);
87     void SavePreInstallBundleInfo(ErrCode installResult,
88         const std::unordered_map<std::string, InnerBundleInfo> &newInfos, const InstallParam &installParam);
89     ErrCode UpdateAppService(InnerBundleInfo &oldInfo,
90         std::unordered_map<std::string, InnerBundleInfo> &newInfos,
91         InstallParam &installParam);
92     ErrCode UninstallLowerVersion(const std::vector<std::string> &moduleNameList);
93     bool GetInnerBundleInfoWithDisable(InnerBundleInfo &info, bool &isAppExist);
94     bool CheckNeedInstall(const std::unordered_map<std::string, InnerBundleInfo> &infos, InnerBundleInfo &oldInfo,
95         bool &isDowngrade);
96     ErrCode ProcessBundleUpdateStatus(InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo,
97         const std::string &hspPath, const InstallParam &installParam);
98     ErrCode ProcessNewModuleInstall(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo,
99         const std::string &hspPath, const InstallParam &installParam);
100     ErrCode ProcessModuleUpdate(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo,
101         const std::string &hspPath, const InstallParam &installParam);
102     ErrCode RemoveLowerVersionSoDir(uint32_t versionCode);
103     ErrCode VerifyCodeSignatureForNativeFiles(const std::string &bundlePath, const std::string &cpuAbi,
104         const std::string &targetSoPath) const;
105     ErrCode DeliveryProfileToCodeSign(std::vector<Security::Verify::HapVerifyResult> &hapVerifyResults) const;
106     void GenerateOdid(std::unordered_map<std::string, InnerBundleInfo> &infos,
107         const std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes) const;
108     ErrCode VerifyCodeSignatureForHsp(const std::string &realHspPath, const std::string &realSoPath) const;
109     ErrCode MarkInstallFinish();
110 
111     bool versionUpgrade_ = false;
112     bool moduleUpdate_ = false;
113     bool isEnterpriseBundle_ = false;
114     bool isCompressNativeLibs_ = true;
115     uint32_t versionCode_ = 0;
116     std::string bundleName_;
117     std::string bundleMsg_;
118     std::string appIdentifier_;
119     std::string compileSdkType_;
120     std::string cpuAbi_;
121     std::string nativeLibraryPath_;
122     std::unique_ptr<BundleInstallChecker> bundleInstallChecker_ = nullptr;
123     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;
124     std::vector<std::string> uninstallModuleVec_;
125     std::vector<std::string> deleteBundlePath_;
126     InnerBundleInfo newInnerBundleInfo_;
127     DISALLOW_COPY_AND_MOVE(AppServiceFwkInstaller);
128 
129 #define CHECK_RESULT(errcode, errmsg)                                              \
130     do {                                                                           \
131         if ((errcode) != ERR_OK) {                                                   \
132             APP_LOGE(errmsg, errcode);                                             \
133             return errcode;                                                        \
134         }                                                                          \
135     } while (0)
136 };
137 }  // namespace AppExecFwk
138 }  // namespace OHOS
139 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_APP_SERVICE_FWK_INSTALLER_H