• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_IPC_INSTALLD_INTERFACE_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "iremote_broker.h"
23 
24 #include "appexecfwk_errors.h"
25 #include "ipc/extract_param.h"
26 #include "ipc/file_stat.h"
27 #include "installd/installd_constants.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 class IInstalld : public IRemoteBroker {
32 public:
33     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.Installd");
34     /**
35      * @brief Create a bundle code directory.
36      * @param bundleDir Indicates the bundle code directory path that to be created.
37      * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise.
38      */
39     virtual ErrCode CreateBundleDir(const std::string &bundleDir) = 0;
40     /**
41      * @brief Extract the files of a HAP module to the code directory.
42      * @param srcModulePath Indicates the HAP file path.
43      * @param targetPath normal files decompression path.
44      * @param targetSoPath so files decompression path.
45      * @param cpuAbi cpuAbi.
46      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
47      */
48     virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
49         const std::string &targetSoPath, const std::string &cpuAbi) = 0;
50     /**
51      * @brief Extract the files.
52      * @param extractParam Indicates the extractParam.
53      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
54      */
55     virtual ErrCode ExtractFiles(const ExtractParam &extractParam) = 0;
56     /**
57      * @brief Rename the module directory from temporaily path to the real path.
58      * @param oldPath Indicates the old path name.
59      * @param newPath Indicates the new path name.
60      * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise.
61      */
62     virtual ErrCode RenameModuleDir(const std::string &oldDir, const std::string &newDir) = 0;
63     /**
64      * @brief Create a bundle data directory.
65      * @param bundleName Indicates bundleName to be set to the directory.
66      * @param userid Indicates userid to be set to the directory.
67      * @param uid Indicates uid to be set to the directory.
68      * @param gid Indicates gid to be set to the directory.
69      * @param apl Indicates apl to be set to the directory.
70      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
71      */
72     virtual ErrCode CreateBundleDataDir(const std::string &bundleName,
73         const int userid, const int uid, const int gid, const std::string &apl) = 0;
74     /**
75      * @brief Remove a bundle data directory.
76      * @param bundleDir Indicates the bundle data directory path that to be created.
77      * @param userid Indicates userid to be set to the directory.
78      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
79      */
80     virtual ErrCode RemoveBundleDataDir(const std::string &bundleDir, const int userid) = 0;
81     /**
82      * @brief Remove a module and it's abilities data directory.
83      * @param ModuleDir Indicates the module data directory path that to be created.
84      * @param userid Indicates userid to be set to the directory.
85      * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise.
86      */
87     virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid)= 0;
88     /**
89      * @brief Remove a directory.
90      * @param dir Indicates the directory path that to be removed.
91      * @return Returns ERR_OK if the  directory removed successfully; returns error code otherwise.
92      */
93     virtual ErrCode RemoveDir(const std::string &dir) = 0;
94     /**
95      * @brief Clean all files in a bundle data directory.
96      * @param bundleDir Indicates the data directory path that to be cleaned.
97      * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise.
98      */
99     virtual ErrCode CleanBundleDataDir(const std::string &bundleDir) = 0;
100     /**
101      * @brief Get bundle Stats.
102      * @param bundleName Indicates the bundle name.
103      * @param userId Indicates the user Id.
104      * @param bundleStats Indicates the bundle Stats.
105      * @return Returns ERR_OK if get stats successfully; returns error code otherwise.
106      */
107     virtual ErrCode GetBundleStats(
108         const std::string &bundleName, const int32_t userId, std::vector<int64_t> &bundleStats) = 0;
109     /**
110      * @brief Set dir apl.
111      * @param dir Indicates the data dir.
112      * @param bundleName Indicates the bundle name.
113      * @param apl Indicates the apl type.
114      * @return Returns ERR_OK if set apl successfully; returns error code otherwise.
115      */
116     virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl) = 0;
117     /**
118      * @brief Get all cache file path.
119      * @param dir Indicates the data dir.
120      * @param cachesPath Indicates the cache file path.
121      * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise.
122      */
123     virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) = 0;
124     /**
125      * @brief Scan dir by scanMode and resultMode. this interface has higher permissions to scan.
126      * @param dir Indicates the directory to be scanned.
127      * @param scanMode Indicates the scan mode.
128      *                 Scan all subfiles and subfolders in the directory in SUB_FILE_ALL mode
129      *                 Scan all subfolders in the directory in SUB_FILE_DIR mode
130      *                 Scan all subfiles in the directory in SUB_FILE_FILE mode
131      * @param resultMode Indicates the result mode.
132      *                 Get absolute path in ABSOLUTE_PATH mode
133      *                 Get relative path in RELATIVE_PATH mode
134      * @return Returns ERR_OK if scan dir successfully; returns error code otherwise.
135      */
136     virtual ErrCode ScanDir(
137         const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) = 0;
138 
139     /**
140      * @brief Move file from oldPath to newPath.
141      * @param oldPath Indicates oldPath.
142      * @param newPath Indicates newPath.
143      * @return Returns ERR_OK if move file successfully; returns error code otherwise.
144      */
145     virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath) = 0;
146 
147     /**
148      * @brief Copy file from oldPath to newPath.
149      * @param oldPath Indicates oldPath.
150      * @param newPath Indicates newPath.
151      * @return Returns ERR_OK if copy file successfully; returns error code otherwise.
152      */
153     virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath) = 0;
154 
155     /**
156      * @brief Create directory recursively.
157      * @param dir Indicates dir which will be created.
158      * @param mode Indicates dir mode.
159      * @param uid Indicates dir uid.
160      * @param gid Indicates dir gid.
161      * @return Returns ERR_OK if create directory successfully; returns error code otherwise.
162      */
163     virtual ErrCode Mkdir(
164         const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) = 0;
165 
166     /**
167      * @brief Get file stat.
168      * @param file Indicates file.
169      * @param fileStat Indicates fileStat.
170      * @return Returns ERR_OK if get file stat successfully; returns error code otherwise.
171      */
172     virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat) = 0;
173 
174     virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
175         const std::string &cpuAbi) = 0;
176 
177     virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
178     const std::string &newSoPath) = 0;
179 
180     virtual ErrCode IsExistDir(const std::string &dir, bool &isExist) = 0;
181 
182     virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty) = 0;
183 
184     virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) = 0;
185 
186     virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) = 0;
187 
188 protected:
189     enum Message : uint32_t {
190         CREATE_BUNDLE_DIR = 1,
191         EXTRACT_MODULE_FILES,
192         RENAME_MODULE_DIR,
193         CREATE_BUNDLE_DATA_DIR,
194         CLEAN_BUNDLE_DATA_DIR,
195         REMOVE_BUNDLE_DATA_DIR,
196         REMOVE_MODULE_DATA_DIR,
197         REMOVE_DIR,
198         GET_BUNDLE_STATS,
199         SET_DIR_APL,
200         GET_BUNDLE_CACHE_PATH,
201         SCAN_DIR,
202         MOVE_FILE,
203         COPY_FILE,
204         MKDIR,
205         GET_FILE_STAT,
206         EXTRACT_DIFF_FILES,
207         APPLY_DIFF_PATCH,
208         IS_EXIST_DIR,
209         IS_DIR_EMPTY,
210         OBTAIN_QUICK_FIX_DIR,
211         COPY_FILES,
212         EXTRACT_FILES
213     };
214 };
215 
216 #define INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(parcel, token)                        \
217     do {                                                                            \
218         bool ret = parcel.WriteInterfaceToken((token));                             \
219         if (!ret) {                                                                 \
220             APP_LOGE("fail to write interface token into the parcel!");             \
221             return ERR_APPEXECFWK_PARCEL_ERROR;                                     \
222         }                                                                           \
223     } while (0)
224 
225 #define INSTALLD_PARCEL_WRITE(parcel, type, value)                                  \
226     do {                                                                            \
227         bool ret = parcel.Write##type((value));                                     \
228         if (!ret) {                                                                 \
229             APP_LOGE("fail to write parameter into the parcel!");                   \
230             return ERR_APPEXECFWK_PARCEL_ERROR;                                     \
231         }                                                                           \
232     } while (0)
233 }  // namespace AppExecFwk
234 }  // namespace OHOS
235 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H