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 Get disk usage for dir. 177 * @param path Indicates the directory vector. 178 * @return Returns true if successfully; returns false otherwise. 179 */ GetDiskUsageFromPath(const std::vector<std::string> & path,int64_t & statSize)180 virtual ErrCode GetDiskUsageFromPath(const std::vector<std::string> &path, int64_t &statSize) 181 { 182 return ERR_OK; 183 } 184 /** 185 * @brief Clean all files in a bundle data directory. 186 * @param bundleDir Indicates the data directory path that to be cleaned. 187 * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise. 188 */ CleanBundleDataDir(const std::string & bundleDir)189 virtual ErrCode CleanBundleDataDir(const std::string &bundleDir) 190 { 191 return ERR_OK; 192 } 193 /** 194 * @brief Clean a bundle data directory. 195 * @param bundleName Indicates the bundleName data directory path that to be cleaned. 196 * @param userid Indicates userid to be set to the directory. 197 * @param appIndex Indicates userid to be set to the directory. 198 * @return Returns ERR_OK if the bundle data directory cleaned successfully; returns error code otherwise. 199 */ 200 virtual ErrCode CleanBundleDataDirByName(const std::string &bundleName, const int userid, const int appIndex = 0) 201 { 202 return ERR_OK; 203 } 204 /** 205 * @brief Get bundle Stats. 206 * @param bundleName Indicates the bundle name. 207 * @param userId Indicates the user Id. 208 * @param bundleStats Indicates the bundle Stats. 209 * @return Returns ERR_OK if get stats successfully; returns error code otherwise. 210 */ 211 virtual ErrCode GetBundleStats(const std::string &bundleName, const int32_t userId, 212 std::vector<int64_t> &bundleStats, const int32_t uid, const int32_t appIndex = 0, 213 const uint32_t statFlag = 0, const std::vector<std::string> &moduleNameList = {}) 214 { 215 return ERR_OK; 216 } 217 GetAllBundleStats(const int32_t userId,std::vector<int64_t> & bundleStats,const std::vector<int32_t> & uids)218 virtual ErrCode GetAllBundleStats(const int32_t userId, 219 std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids) 220 { 221 return ERR_OK; 222 } 223 /** 224 * @brief Set dir apl. 225 * @param dir Indicates the data dir. 226 * @param bundleName Indicates the bundle name. 227 * @param apl Indicates the apl type. 228 * @param isPreInstallApp Indicates the bundle install type. 229 * @param debug Indicates the bundle debug mode. 230 * @return Returns ERR_OK if set apl successfully; returns error code otherwise. 231 */ SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)232 virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl, 233 bool isPreInstallApp, bool debug) 234 { 235 return ERR_OK; 236 } 237 /** 238 * @brief Get all cache file path. 239 * @param dir Indicates the data dir. 240 * @param cachesPath Indicates the cache file path. 241 * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise. 242 */ GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)243 virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) 244 { 245 return ERR_OK; 246 } 247 /** 248 * @brief Scan dir by scanMode and resultMode. this interface has higher permissions to scan. 249 * @param dir Indicates the directory to be scanned. 250 * @param scanMode Indicates the scan mode. 251 * Scan all subfiles and subfolders in the directory in SUB_FILE_ALL mode 252 * Scan all subfolders in the directory in SUB_FILE_DIR mode 253 * Scan all subfiles in the directory in SUB_FILE_FILE mode 254 * @param resultMode Indicates the result mode. 255 * Get absolute path in ABSOLUTE_PATH mode 256 * Get relative path in RELATIVE_PATH mode 257 * @return Returns ERR_OK if scan dir successfully; returns error code otherwise. 258 */ ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)259 virtual ErrCode ScanDir( 260 const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) 261 { 262 return ERR_OK; 263 } 264 265 /** 266 * @brief Move file from oldPath to newPath. 267 * @param oldPath Indicates oldPath. 268 * @param newPath Indicates newPath. 269 * @return Returns ERR_OK if move file successfully; returns error code otherwise. 270 */ MoveFile(const std::string & oldPath,const std::string & newPath)271 virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath) 272 { 273 return ERR_OK; 274 } 275 276 /** 277 * @brief Copy file from oldPath to newPath. 278 * @param oldPath Indicates oldPath. 279 * @param newPath Indicates newPath. 280 * @return Returns ERR_OK if copy file successfully; returns error code otherwise. 281 */ CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)282 virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath, 283 const std::string &signatureFilePath) 284 { 285 return ERR_OK; 286 } 287 288 /** 289 * @brief Create directory recursively. 290 * @param dir Indicates dir which will be created. 291 * @param mode Indicates dir mode. 292 * @param uid Indicates dir uid. 293 * @param gid Indicates dir gid. 294 * @return Returns ERR_OK if create directory successfully; returns error code otherwise. 295 */ Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)296 virtual ErrCode Mkdir( 297 const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) 298 { 299 return ERR_OK; 300 } 301 302 /** 303 * @brief Get file stat. 304 * @param file Indicates file. 305 * @param fileStat Indicates fileStat. 306 * @return Returns ERR_OK if get file stat successfully; returns error code otherwise. 307 */ GetFileStat(const std::string & file,FileStat & fileStat)308 virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat) 309 { 310 return ERR_OK; 311 } 312 ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)313 virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath, 314 const std::string &cpuAbi) 315 { 316 return ERR_OK; 317 } 318 ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath,int32_t uid)319 virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath, 320 const std::string &newSoPath, int32_t uid) 321 { 322 return ERR_OK; 323 } 324 IsExistDir(const std::string & dir,bool & isExist)325 virtual ErrCode IsExistDir(const std::string &dir, bool &isExist) 326 { 327 return ERR_OK; 328 } 329 IsExistFile(const std::string & path,bool & isExist)330 virtual ErrCode IsExistFile(const std::string &path, bool &isExist) 331 { 332 return ERR_OK; 333 } 334 IsExistApFile(const std::string & path,bool & isExist)335 virtual ErrCode IsExistApFile(const std::string &path, bool &isExist) 336 { 337 return ERR_OK; 338 } 339 IsDirEmpty(const std::string & dir,bool & isDirEmpty)340 virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty) 341 { 342 return ERR_OK; 343 } 344 ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)345 virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) 346 { 347 return ERR_OK; 348 } 349 CopyFiles(const std::string & sourceDir,const std::string & destinationDir)350 virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) 351 { 352 return ERR_OK; 353 } 354 GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)355 virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, 356 std::vector<std::string> &fileNames) 357 { 358 return ERR_OK; 359 } 360 VerifyCodeSignature(const CodeSignatureParam & codeSignatureParam)361 virtual ErrCode VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam) 362 { 363 return ERR_OK; 364 } 365 CheckEncryption(const CheckEncryptionParam & checkEncryptionParam,bool & isEncryption)366 virtual ErrCode CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, bool &isEncryption) 367 { 368 return ERR_OK; 369 } 370 MoveFiles(const std::string & srcDir,const std::string & desDir)371 virtual ErrCode MoveFiles(const std::string &srcDir, const std::string &desDir) 372 { 373 return ERR_OK; 374 } 375 ExtractDriverSoFiles(const std::string & srcPath,const std::unordered_multimap<std::string,std::string> & dirMap)376 virtual ErrCode ExtractDriverSoFiles(const std::string &srcPath, 377 const std::unordered_multimap<std::string, std::string> &dirMap) 378 { 379 return ERR_OK; 380 } 381 ExtractEncryptedSoFiles(const std::string & hapPath,const std::string & realSoFilesPath,const std::string & cpuAbi,const std::string & tmpSoPath,int32_t uid)382 virtual ErrCode ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath, 383 const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid) 384 { 385 return ERR_OK; 386 } 387 VerifyCodeSignatureForHap(const CodeSignatureParam & codeSignatureParam)388 virtual ErrCode VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam) 389 { 390 return ERR_OK; 391 } 392 DeliverySignProfile(const std::string & bundleName,int32_t profileBlockLength,const unsigned char * profileBlock)393 virtual ErrCode DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength, 394 const unsigned char *profileBlock) 395 { 396 return ERR_OK; 397 } 398 RemoveSignProfile(const std::string & bundleName)399 virtual ErrCode RemoveSignProfile(const std::string &bundleName) 400 { 401 return ERR_OK; 402 } 403 SetEncryptionPolicy(int32_t uid,const std::string & bundleName,const int32_t userId,std::string & keyId)404 virtual ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName, 405 const int32_t userId, std::string &keyId) 406 { 407 return ERR_OK; 408 } 409 DeleteEncryptionKeyId(const std::string & bundleName,const int32_t userId)410 virtual ErrCode DeleteEncryptionKeyId(const std::string &bundleName, const int32_t userId) 411 { 412 return ERR_OK; 413 } 414 RemoveExtensionDir(int32_t userId,const std::vector<std::string> & extensionBundleDirs)415 virtual ErrCode RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs) 416 { 417 return ERR_OK; 418 } 419 IsExistExtensionDir(int32_t userId,const std::string & extensionBundleDir,bool & isExist)420 virtual ErrCode IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist) 421 { 422 return ERR_OK; 423 } 424 CreateExtensionDataDir(const CreateDirParam & createDirParam)425 virtual ErrCode CreateExtensionDataDir(const CreateDirParam &createDirParam) 426 { 427 return ERR_OK; 428 } 429 GetExtensionSandboxTypeList(std::vector<std::string> & typeList)430 virtual ErrCode GetExtensionSandboxTypeList(std::vector<std::string> &typeList) 431 { 432 return ERR_OK; 433 } 434 MoveHapToCodeDir(const std::string & originPath,const std::string & targetPath)435 virtual ErrCode MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath) 436 { 437 return ERR_OK; 438 } 439 }; 440 441 #define INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(parcel, token) \ 442 do { \ 443 bool ret = parcel.WriteInterfaceToken((token)); \ 444 if (!ret) { \ 445 APP_LOGE("write interface token failed"); \ 446 return ERR_APPEXECFWK_PARCEL_ERROR; \ 447 } \ 448 } while (0) 449 450 #define INSTALLD_PARCEL_WRITE(parcel, type, value) \ 451 do { \ 452 bool ret = parcel.Write##type((value)); \ 453 if (!ret) { \ 454 APP_LOGE("write parameter failed"); \ 455 return ERR_APPEXECFWK_PARCEL_ERROR; \ 456 } \ 457 } while (0) 458 } // namespace AppExecFwk 459 } // namespace OHOS 460 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H