• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_INSTALLD_HOST_IMPL_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_HOST_IMPL_H
18 
19 #include "bundle_constants.h"
20 #include "code_sign_helper.h"
21 #include "ipc/installd_host.h"
22 #include "installd/installd_operator.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class InstalldHostImpl : public InstalldHost {
27 public:
28     InstalldHostImpl();
29     virtual ~InstalldHostImpl();
30     /**
31      * @brief Create a bundle code directory.
32      * @param bundleDir Indicates the bundle code directory path that to be created.
33      * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise.
34      */
35     virtual ErrCode CreateBundleDir(const std::string &bundleDir) override;
36     /**
37      * @brief Extract the files of a HAP module to the code directory.
38      * @param srcModulePath Indicates the HAP file path.
39      * @param targetPath normal files decompression path.
40      * @param targetSoPath so files decompression path.
41      * @param cpuAbi cpuAbi.
42      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
43      */
44     virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
45         const std::string &targetSoPath, const std::string &cpuAbi) override;
46     /**
47      * @brief Extract the files.
48      * @param extractParam Indicates the extractParam.
49      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
50      */
51     virtual ErrCode ExtractFiles(const ExtractParam &extractParam) override;
52 
53     virtual ErrCode ExecuteAOT(const AOTArgs &aotArgs) override;
54     /**
55      * @brief Rename the module directory from temporaily path to the real path.
56      * @param oldPath Indicates the old path name.
57      * @param newPath Indicates the new path name.
58      * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise.
59      */
60     virtual ErrCode RenameModuleDir(const std::string &oldPath, const std::string &newPath) override;
61     /**
62      * @brief Create a bundle data directory.
63      * @param createDirParam Indicates param to be set to the directory.
64      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
65      */
66     virtual ErrCode CreateBundleDataDir(const CreateDirParam &createDirParam) override;
67 
68     virtual ErrCode CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams) override;
69     /**
70      * @brief Remove a bundle data directory.
71      * @param bundleName Indicates the bundleName data directory path that to be created.
72      * @param userid Indicates userid to be set to the directory.
73      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
74      */
75     virtual ErrCode RemoveBundleDataDir(
76         const std::string &bundleName, const int userid) override;
77     /**
78      * @brief Remove a module data directory.
79      * @param ModuleDir Indicates the module data directory path that to be created.
80      * @param userid Indicates userid to be set to the directory.
81      * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise.
82      */
83     virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid) override;
84     /**
85      * @brief Remove a directory.
86      * @param dir Indicates the directory path that to be removed.
87      * @return Returns ERR_OK if the  directory removed successfully; returns error code otherwise.
88      */
89     virtual ErrCode RemoveDir(const std::string &dir) override;
90     /**
91      * @brief Clean all files in a bundle data directory.
92      * @param bundleDir Indicates the data directory path that to be cleaned.
93      * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise.
94      */
95     virtual ErrCode CleanBundleDataDir(const std::string &bundleDir) override;
96     /**
97      * @brief Clean a bundle data directory.
98      * @param bundleName Indicates the bundleName data directory path that to be cleaned.
99      * @param userid Indicates userid to be set to the directory.
100      * @return Returns ERR_OK if the bundle data directory cleaned successfully; returns error code otherwise.
101      */
102     virtual ErrCode CleanBundleDataDirByName(const std::string &bundleName, const int userid) override;
103     /**
104      * @brief Get bundle Stats.
105      * @param bundleName Indicates the bundle name.
106      * @param userId Indicates the user Id.
107      * @param bundleStats Indicates the bundle Stats.
108      * @return Returns ERR_OK if get stats successfully; returns error code otherwise.
109      */
110     virtual ErrCode GetBundleStats(const std::string &bundleName, const int32_t userId,
111         std::vector<int64_t> &bundleStats, const int32_t uid = Constants::INVALID_UID) override;
112 
113     virtual ErrCode GetAllBundleStats(const std::vector<std::string> &bundleNames, const int32_t userId,
114         std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids) override;
115     /**
116      * @brief Set dir apl.
117      * @param dir Indicates the data dir.
118      * @param bundleName Indicates the bundle name.
119      * @param apl Indicates the apl type.
120      * @param isPreInstallApp Indicates the bundle install type.
121      * @param debug Indicates the bundle debug mode.
122      * @return Returns ERR_OK if set apl successfully; returns error code otherwise.
123      */
124     virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
125         bool isPreInstallApp, bool debug) override;
126 
127     /**
128      * @brief Get all cache file path.
129      * @param dir Indicates the data dir.
130      * @param cachesPath Indicates the cache file path.
131      * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise.
132      */
133     virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) override;
134 
135     virtual ErrCode ScanDir(
136         const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) override;
137 
138     virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath) override;
139 
140     virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath,
141         const std::string &signatureFilePath = "") override;
142 
143     virtual ErrCode Mkdir(
144         const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) override;
145 
146     virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat) override;
147 
148     virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
149         const std::string &cpuAbi) override;
150 
151     virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
152         const std::string &newSoPath, int32_t uid) override;
153 
154     virtual ErrCode IsExistDir(const std::string &dir, bool &isExist) override;
155 
156     virtual ErrCode IsExistFile(const std::string &path, bool &isExist) override;
157 
158     virtual ErrCode IsExistApFile(const std::string &path, bool &isExist) override;
159 
160     virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty) override;
161 
162     virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) override;
163 
164     virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) override;
165 
166     virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
167         std::vector<std::string> &fileNames) override;
168 
169     virtual ErrCode VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam) override;
170 
171     virtual ErrCode CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption) override;
172 
173     virtual ErrCode MoveFiles(const std::string &srcDir, const std::string &desDir) override;
174 
175     virtual ErrCode ExtractDriverSoFiles(const std::string &srcPath,
176         const std::unordered_multimap<std::string, std::string> &dirMap) override;
177 
178     virtual ErrCode ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
179         const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid) override;
180 
181 #if defined(CODE_SIGNATURE_ENABLE)
182     ErrCode PrepareEntryMap(const CodeSignatureParam &codeSignatureParam, Security::CodeSign::EntryMap &entryMap);
183 #endif
184 
185     virtual ErrCode VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam) override;
186 
187     virtual ErrCode DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
188         const unsigned char *profileBlock) override;
189 
190     virtual ErrCode RemoveSignProfile(const std::string &bundleName) override;
191 
192 private:
193     std::string GetBundleDataDir(const std::string &el, const int userid) const;
194     bool CheckPathValid(const std::string &path, const std::string &prefix);
195 };
196 }  // namespace AppExecFwk
197 }  // namespace OHOS
198 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_HOST_IMPL_H