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