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