1 /*
2  * Copyright (c) 2021-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_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 "aot/aot_args.h"
25 #include "appexecfwk_errors.h"
26 #include "ipc/check_encryption_param.h"
27 #include "ipc/code_signature_param.h"
28 #include "ipc/create_dir_param.h"
29 #include "ipc/extract_param.h"
30 #include "ipc/file_stat.h"
31 #include "installd/installd_constants.h"
32 
33 namespace OHOS {
34 namespace AppExecFwk {
35 class IInstalld : public IRemoteBroker {
36 public:
37     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.Installd");
38     /**
39      * @brief Create a bundle code directory.
40      * @param bundleDir Indicates the bundle code directory path that to be created.
41      * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise.
42      */
CreateBundleDir(const std::string & bundleDir)43     virtual ErrCode CreateBundleDir(const std::string &bundleDir)
44     {
45         return ERR_OK;
46     }
47     /**
48      * @brief Extract the files of a HAP module to the code directory.
49      * @param srcModulePath Indicates the HAP file path.
50      * @param targetPath normal files decompression path.
51      * @param targetSoPath so files decompression path.
52      * @param cpuAbi cpuAbi.
53      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
54      */
ExtractModuleFiles(const std::string & srcModulePath,const std::string & targetPath,const std::string & targetSoPath,const std::string & cpuAbi)55     virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath,
56         const std::string &targetSoPath, const std::string &cpuAbi)
57     {
58         return ERR_OK;
59     }
60     /**
61      * @brief Extract the files.
62      * @param extractParam Indicates the extractParam.
63      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
64      */
ExtractFiles(const ExtractParam & extractParam)65     virtual ErrCode ExtractFiles(const ExtractParam &extractParam)
66     {
67         return ERR_OK;
68     }
69 
70     /**
71      * @brief Extract the hnpFiles.
72      * @param hnpPackageInfo Indicates the hnpPackageInfo.
73      * @param extractParam Indicates the extractParam.
74      * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise.
75      */
ExtractHnpFiles(const std::string & hnpPackageInfo,const ExtractParam & extractParam)76     virtual ErrCode ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam)
77     {
78         return ERR_OK;
79     }
80 
ProcessBundleInstallNative(const std::string & userId,const std::string & hnpRootPath,const std::string & hapPath,const std::string & cpuAbi,const std::string & packageName)81     virtual ErrCode ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath,
82         const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName)
83     {
84         return ERR_OK;
85     }
86 
ProcessBundleUnInstallNative(const std::string & userId,const std::string & bundleName)87     virtual ErrCode ProcessBundleUnInstallNative(const std::string &userId, const std::string &bundleName)
88     {
89         return ERR_OK;
90     }
91 
ExecuteAOT(const AOTArgs & aotArgs,std::vector<uint8_t> & pendSignData)92     virtual ErrCode ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData)
93     {
94         return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED;
95     }
96 
PendSignAOT(const std::string & anFileName,const std::vector<uint8_t> & signData)97     virtual ErrCode PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData)
98     {
99         return ERR_APPEXECFWK_INSTALLD_SIGN_AOT_FAILED;
100     }
101 
StopAOT()102     virtual ErrCode StopAOT()
103     {
104         return ERR_APPEXECFWK_INSTALLD_STOP_AOT_FAILED;
105     }
106 
DeleteUninstallTmpDirs(const std::vector<std::string> & dirs)107     virtual ErrCode DeleteUninstallTmpDirs(const std::vector<std::string> &dirs)
108     {
109         return ERR_APPEXECFWK_INSTALLD_REMOVE_DIR_FAILED;
110     }
111     /**
112      * @brief Rename the module directory from temporaily path to the real path.
113      * @param oldPath Indicates the old path name.
114      * @param newPath Indicates the new path name.
115      * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise.
116      */
RenameModuleDir(const std::string & oldDir,const std::string & newDir)117     virtual ErrCode RenameModuleDir(const std::string &oldDir, const std::string &newDir)
118     {
119         return ERR_OK;
120     }
121     /**
122      * @brief Create a bundle data directory.
123      * @param createDirParam Indicates param to be set to the directory.
124      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
125      */
CreateBundleDataDir(const CreateDirParam & createDirParam)126     virtual ErrCode CreateBundleDataDir(const CreateDirParam &createDirParam)
127     {
128         return ERR_OK;
129     }
130 
CreateBundleDataDirWithVector(const std::vector<CreateDirParam> & createDirParams)131     virtual ErrCode CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams)
132     {
133         return ERR_OK;
134     }
135     /**
136      * @brief Remove a bundle data directory.
137      * @param bundleDir Indicates the bundle data directory path that to be created.
138      * @param userid Indicates userid to be set to the directory.
139      * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise.
140      */
141     virtual ErrCode RemoveBundleDataDir(const std::string &bundleDir, const int32_t userId,
142         bool isAtomicService = false, const bool async = false)
143     {
144         return ERR_OK;
145     }
146     /**
147      * @brief Remove a module and it's abilities data directory.
148      * @param ModuleDir Indicates the module data directory path that to be created.
149      * @param userid Indicates userid to be set to the directory.
150      * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise.
151      */
RemoveModuleDataDir(const std::string & ModuleDir,const int userid)152     virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid)
153     {
154         return ERR_OK;
155     }
156     /**
157      * @brief Remove a directory.
158      * @param dir Indicates the directory path that to be removed.
159      * @return Returns ERR_OK if the  directory removed successfully; returns error code otherwise.
160      */
RemoveDir(const std::string & dir)161     virtual ErrCode RemoveDir(const std::string &dir)
162     {
163         return ERR_OK;
164     }
165     /**
166      * @brief Get disk usage for dir.
167      * @param dir Indicates the directory.
168      * @param isRealPath Indicates isRealPath.
169      * @return Returns true if successfully; returns false otherwise.
170      */
171     virtual int64_t GetDiskUsage(const std::string &dir, bool isRealPath = false)
172     {
173         return 0;
174     }
175     /**
176      * @brief Clean all files in a bundle data directory.
177      * @param bundleDir Indicates the data directory path that to be cleaned.
178      * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise.
179      */
CleanBundleDataDir(const std::string & bundleDir)180     virtual ErrCode CleanBundleDataDir(const std::string &bundleDir)
181     {
182         return ERR_OK;
183     }
184     /**
185      * @brief Clean a bundle data directory.
186      * @param bundleName Indicates the bundleName data directory path that to be cleaned.
187      * @param userid Indicates userid to be set to the directory.
188      * @param appIndex Indicates userid to be set to the directory.
189      * @return Returns ERR_OK if the bundle data directory cleaned successfully; returns error code otherwise.
190      */
191     virtual ErrCode CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex = 0)
192     {
193         return ERR_OK;
194     }
195     /**
196      * @brief Get bundle Stats.
197      * @param bundleName Indicates the bundle name.
198      * @param userId Indicates the user Id.
199      * @param bundleStats Indicates the bundle Stats.
200      * @return Returns ERR_OK if get stats successfully; returns error code otherwise.
201      */
202     virtual ErrCode GetBundleStats(const std::string &bundleName, const int32_t userId,
203         std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex = 0,
204         const uint32_t statFlag = 0, const std::vector<std::string> &moduleNameList = {})
205     {
206         return ERR_OK;
207     }
208 
GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)209     virtual ErrCode GetAllBundleStats(const int32_t userId,
210         std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids)
211     {
212         return ERR_OK;
213     }
214     /**
215      * @brief Set dir apl.
216      * @param dir Indicates the data dir.
217      * @param bundleName Indicates the bundle name.
218      * @param apl Indicates the apl type.
219      * @param isPreInstallApp Indicates the bundle install type.
220      * @param debug Indicates the bundle debug mode.
221      * @return Returns ERR_OK if set apl successfully; returns error code otherwise.
222      */
SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)223     virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl,
224         bool isPreInstallApp, bool debug)
225     {
226         return ERR_OK;
227     }
228     /**
229      * @brief Get all cache file path.
230      * @param dir Indicates the data dir.
231      * @param cachesPath Indicates the cache file path.
232      * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise.
233      */
GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)234     virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath)
235     {
236         return ERR_OK;
237     }
238     /**
239      * @brief Scan dir by scanMode and resultMode. this interface has higher permissions to scan.
240      * @param dir Indicates the directory to be scanned.
241      * @param scanMode Indicates the scan mode.
242      *                 Scan all subfiles and subfolders in the directory in SUB_FILE_ALL mode
243      *                 Scan all subfolders in the directory in SUB_FILE_DIR mode
244      *                 Scan all subfiles in the directory in SUB_FILE_FILE mode
245      * @param resultMode Indicates the result mode.
246      *                 Get absolute path in ABSOLUTE_PATH mode
247      *                 Get relative path in RELATIVE_PATH mode
248      * @return Returns ERR_OK if scan dir successfully; returns error code otherwise.
249      */
ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)250     virtual ErrCode ScanDir(
251         const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths)
252     {
253         return ERR_OK;
254     }
255 
256     /**
257      * @brief Move file from oldPath to newPath.
258      * @param oldPath Indicates oldPath.
259      * @param newPath Indicates newPath.
260      * @return Returns ERR_OK if move file successfully; returns error code otherwise.
261      */
MoveFile(const std::string & oldPath,const std::string & newPath)262     virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath)
263     {
264         return ERR_OK;
265     }
266 
267     /**
268      * @brief Copy file from oldPath to newPath.
269      * @param oldPath Indicates oldPath.
270      * @param newPath Indicates newPath.
271      * @return Returns ERR_OK if copy file successfully; returns error code otherwise.
272      */
CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)273     virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath,
274         const std::string &signatureFilePath)
275     {
276         return ERR_OK;
277     }
278 
279     /**
280      * @brief Create directory recursively.
281      * @param dir Indicates dir which will be created.
282      * @param mode Indicates dir mode.
283      * @param uid Indicates dir uid.
284      * @param gid Indicates dir gid.
285      * @return Returns ERR_OK if create directory successfully; returns error code otherwise.
286      */
Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)287     virtual ErrCode Mkdir(
288         const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid)
289     {
290         return ERR_OK;
291     }
292 
293     /**
294      * @brief Get file stat.
295      * @param file Indicates file.
296      * @param fileStat Indicates fileStat.
297      * @return Returns ERR_OK if get file stat successfully; returns error code otherwise.
298      */
GetFileStat(const std::string & file,FileStat & fileStat)299     virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat)
300     {
301         return ERR_OK;
302     }
303 
ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)304     virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath,
305         const std::string &cpuAbi)
306     {
307         return ERR_OK;
308     }
309 
ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)310     virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath,
311     const std::string &newSoPath, int32_t uid)
312     {
313         return ERR_OK;
314     }
315 
IsExistDir(const std::string & dir,bool & isExist)316     virtual ErrCode IsExistDir(const std::string &dir, bool &isExist)
317     {
318         return ERR_OK;
319     }
320 
IsExistFile(const std::string & path,bool & isExist)321     virtual ErrCode IsExistFile(const std::string &path, bool &isExist)
322     {
323         return ERR_OK;
324     }
325 
IsExistApFile(const std::string & path,bool & isExist)326     virtual ErrCode IsExistApFile(const std::string &path, bool &isExist)
327     {
328         return ERR_OK;
329     }
330 
IsDirEmpty(const std::string & dir,bool & isDirEmpty)331     virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty)
332     {
333         return ERR_OK;
334     }
335 
ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)336     virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec)
337     {
338         return ERR_OK;
339     }
340 
CopyFiles(const std::string & sourceDir,const std::string & destinationDir)341     virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir)
342     {
343         return ERR_OK;
344     }
345 
GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)346     virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi,
347         std::vector<std::string> &fileNames)
348     {
349         return ERR_OK;
350     }
351 
VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)352     virtual ErrCode VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam)
353     {
354         return ERR_OK;
355     }
356 
CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)357     virtual ErrCode CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption)
358     {
359         return ERR_OK;
360     }
361 
MoveFiles(const std::string & srcDir,const std::string & desDir)362     virtual ErrCode MoveFiles(const std::string &srcDir, const std::string &desDir)
363     {
364         return ERR_OK;
365     }
366 
ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)367     virtual ErrCode ExtractDriverSoFiles(const std::string &srcPath,
368         const std::unordered_multimap<std::string, std::string> &dirMap)
369     {
370         return ERR_OK;
371     }
372 
ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)373     virtual ErrCode ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath,
374         const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid)
375     {
376         return ERR_OK;
377     }
378 
VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)379     virtual ErrCode VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam)
380     {
381         return ERR_OK;
382     }
383 
DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)384     virtual ErrCode DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength,
385         const unsigned char *profileBlock)
386     {
387         return ERR_OK;
388     }
389 
RemoveSignProfile(const std::string & bundleName)390     virtual ErrCode RemoveSignProfile(const std::string &bundleName)
391     {
392         return ERR_OK;
393     }
394 
SetEncryptionPolicy(int32_t uid,const std::string & bundleName,const int32_t userId,std::string & keyId)395     virtual ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName,
396         const int32_t userId, std::string &keyId)
397     {
398         return ERR_OK;
399     }
400 
DeleteEncryptionKeyId(const std::string & bundleName,const int32_t userId)401     virtual ErrCode DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId)
402     {
403         return ERR_OK;
404     }
405 
RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)406     virtual ErrCode RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs)
407     {
408         return ERR_OK;
409     }
410 
IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)411     virtual ErrCode IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist)
412     {
413         return ERR_OK;
414     }
415 
CreateExtensionDataDir(const CreateDirParam & createDirParam)416     virtual ErrCode CreateExtensionDataDir(const CreateDirParam &createDirParam)
417     {
418         return ERR_OK;
419     }
420 
GetExtensionSandboxTypeList(std::vector<std::string> & typeList)421     virtual ErrCode GetExtensionSandboxTypeList(std::vector<std::string> &typeList)
422     {
423         return ERR_OK;
424     }
425 
MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)426     virtual ErrCode MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath)
427     {
428         return ERR_OK;
429     }
430 };
431 
432 #define INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(parcel, token)                        \
433     do {                                                                            \
434         bool ret = parcel.WriteInterfaceToken((token));                             \
435         if (!ret) {                                                                 \
436             APP_LOGE("write interface token failed");             \
437             return ERR_APPEXECFWK_PARCEL_ERROR;                                     \
438         }                                                                           \
439     } while (0)
440 
441 #define INSTALLD_PARCEL_WRITE(parcel, type, value)                                  \
442     do {                                                                            \
443         bool ret = parcel.Write##type((value));                                     \
444         if (!ret) {                                                                 \
445             APP_LOGE("write parameter failed");                   \
446             return ERR_APPEXECFWK_PARCEL_ERROR;                                     \
447         }                                                                           \
448     } while (0)
449 }  // namespace AppExecFwk
450 }  // namespace OHOS
451 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H