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