1 /* 2 * Copyright (c) 2021-2023 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_BASE_BUNDLE_INSTALLER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_BUNDLE_INSTALLER_H 18 19 #include <map> 20 #include <unordered_map> 21 #include <string> 22 23 #include "nocopyable.h" 24 25 #include "access_token.h" 26 #include "bundle_common_event_mgr.h" 27 #include "bundle_data_mgr.h" 28 #include "bundle_install_checker.h" 29 #include "event_report.h" 30 #include "install_param.h" 31 #include "quick_fix/appqf_info.h" 32 #include "shared_bundle_installer.h" 33 34 namespace OHOS { 35 namespace AppExecFwk { 36 class BaseBundleInstaller { 37 public: 38 BaseBundleInstaller(); 39 virtual ~BaseBundleInstaller(); 40 void SetCallingUid(int32_t callingUid); 41 42 protected: 43 bool otaInstall_ = false; 44 enum class InstallerState { 45 INSTALL_START, 46 INSTALL_BUNDLE_CHECKED = 5, 47 INSTALL_SYSCAP_CHECKED = 10, 48 INSTALL_SIGNATURE_CHECKED = 15, 49 INSTALL_PARSED = 20, 50 INSTALL_HAP_HASH_PARAM_CHECKED = 25, 51 INSTALL_OVERLAY_CHECKED = 30, 52 INSTALL_VERSION_AND_BUNDLENAME_CHECKED = 35, 53 INSTALL_NATIVE_SO_CHECKED = 40, 54 INSTALL_PROXY_DATA_CHECKED = 45, 55 INSTALL_REMOVE_SANDBOX_APP = 50, 56 INSTALL_EXTRACTED = 60, 57 INSTALL_INFO_SAVED = 80, 58 INSTALL_RENAMED = 90, 59 INSTALL_SUCCESS = 100, 60 INSTALL_FAILED, 61 }; 62 63 enum SingletonState { 64 DEFAULT, 65 SINGLETON_TO_NON = 1, 66 NON_TO_SINGLETON = 2, 67 }; 68 69 struct SharedBundleRollBackInfo { 70 std::vector<std::string> newDirs; // record newly created directories, delete when rollback 71 std::vector<std::string> newBundles; // record newly installed bundle, uninstall when rollback 72 std::unordered_map<std::string, InnerBundleInfo> backupBundles; // record initial InnerBundleInfo 73 }; 74 75 /** 76 * @brief The main function for system and normal bundle install. 77 * @param bundlePath Indicates the path for storing the HAP file of the application 78 * to install or update. 79 * @param installParam Indicates the install parameters. 80 * @param appType Indicates the application type. 81 * @return Returns ERR_OK if the application install successfully; returns error code otherwise. 82 */ 83 ErrCode InstallBundle( 84 const std::string &bundlePath, const InstallParam &installParam, const Constants::AppType appType); 85 /** 86 * @brief The main function for system and normal bundle install. 87 * @param bundlePaths Indicates the paths for storing the HAP file sof the application 88 * to install or update. 89 * @param installParam Indicates the install parameters. 90 * @param appType Indicates the application type. 91 * @return Returns ERR_OK if the application install successfully; returns error code otherwise. 92 */ 93 ErrCode InstallBundle(const std::vector<std::string> &bundlePaths, const InstallParam &installParam, 94 const Constants::AppType appType); 95 /** 96 * @brief The main function for uninstall a bundle. 97 * @param bundleName Indicates the bundle name of the application to uninstall. 98 * @param installParam Indicates the uninstall parameters. 99 * @return Returns ERR_OK if the application uninstall successfully; returns error code otherwise. 100 */ 101 ErrCode UninstallBundle(const std::string &bundleName, const InstallParam &installParam); 102 /** 103 * @brief The main function for uninstall a module in a specific bundle. 104 * @param bundleName Indicates the bundle name of the application to uninstall. 105 * @param modulePackage Indicates the module package of the module to uninstall. 106 * @param installParam Indicates the uninstall parameters. 107 * @return Returns ERR_OK if the application uninstall successfully; returns error code otherwise. 108 */ 109 ErrCode UninstallBundle( 110 const std::string &bundleName, const std::string &modulePackage, const InstallParam &installParam); 111 /** 112 * @brief The main function for uninstall a bundle by uninstallParam. 113 * @param uninstallParam Indicates the input of uninstallParam. 114 * @return Returns ERR_OK if the application uninstall successfully; returns error code otherwise. 115 */ 116 ErrCode UninstallBundleByUninstallParam(const UninstallParam &uninstallParam); 117 /** 118 * @brief Update the installer state. 119 * @attention This function changes the base class state only. 120 * @param state Indicates the state to be updated to. 121 * @return 122 */ 123 virtual void UpdateInstallerState(const InstallerState state); 124 /** 125 * @brief Get the installer state. 126 * @return The current state of the installer object. 127 */ GetInstallerState()128 inline InstallerState GetInstallerState() 129 { 130 return state_; 131 } 132 /** 133 * @brief Get the installer state. 134 * @param state Indicates the state to be updated to. 135 * @return 136 */ SetInstallerState(InstallerState state)137 inline void SetInstallerState(InstallerState state) 138 { 139 state_ = state; 140 } 141 /** 142 * @brief The main function for bundle install by bundleName. 143 * @param bundleName Indicates the bundleName of the application to install. 144 * @param installParam Indicates the install parameters. 145 * @return Returns ERR_OK if the application install successfully; returns error code otherwise. 146 */ 147 ErrCode Recover(const std::string &bundleName, const InstallParam &installParam); 148 /** 149 * @brief The main function for bundle install by bundleName. 150 * @param bundleName Indicates the bundleName of the application to install. 151 * @param installParam Indicates the install parameters. 152 * @return Returns ERR_OK if the application install successfully; returns error code otherwise. 153 */ 154 ErrCode InstallBundleByBundleName(const std::string &bundleName, const InstallParam &installParam); 155 /** 156 * @brief Reset install properties. 157 */ 158 void ResetInstallProperties(); 159 /** 160 * @brief Reset install properties. 161 * @param isBootScene Indicates the event occurs in the boot phase. 162 */ MarkPreBundleSyeEventBootTag(bool isBootScene)163 void MarkPreBundleSyeEventBootTag(bool isBootScene) 164 { 165 sysEventInfo_.preBundleScene = 166 isBootScene ? InstallScene::BOOT : InstallScene::REBOOT; 167 } 168 169 private: 170 /** 171 * @brief The real procedure for system and normal bundle install. 172 * @param bundlePath Indicates the path for storing the HAP file of the application 173 * to install or update. 174 * @param installParam Indicates the install parameters. 175 * @param appType Indicates the application type. 176 * @param uid Indicates the uid of the application. 177 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 178 */ 179 ErrCode ProcessBundleInstall(const std::vector<std::string> &bundlePaths, const InstallParam &installParam, 180 const Constants::AppType appType, int32_t &uid); 181 182 ErrCode InnerProcessBundleInstall(std::unordered_map<std::string, InnerBundleInfo> &newInfos, 183 InnerBundleInfo &oldInfo, const InstallParam &installParam, int32_t &uid); 184 185 /** 186 * @brief The real procedure function for uninstall a bundle. 187 * @param bundleName Indicates the bundle name of the application to uninstall. 188 * @param installParam Indicates the uninstall parameters. 189 * @param uid Indicates the uid of the application. 190 * @return Returns ERR_OK if the bundle uninstall successfully; returns error code otherwise. 191 */ 192 ErrCode ProcessBundleUninstall(const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 193 /** 194 * @brief The real procedure for uninstall a module in a specific bundle. 195 * @param bundleName Indicates the bundle name of the application to uninstall. 196 * @param modulePackage Indicates the module package of the module to uninstall. 197 * @param installParam Indicates the uninstall parameters. 198 * @param uid Indicates the uid of the application. 199 * @return Returns ERR_OK if the module uninstall successfully; returns error code otherwise. 200 */ 201 ErrCode ProcessBundleUninstall(const std::string &bundleName, const std::string &modulePackage, 202 const InstallParam &installParam, int32_t &uid); 203 /** 204 * @brief The process of installing a new bundle. 205 * @param info Indicates the InnerBundleInfo parsed from the config.json in the HAP package. 206 * @param uid Indicates the uid of the application. 207 * @return Returns ERR_OK if the new bundle install successfully; returns error code otherwise. 208 */ 209 ErrCode ProcessBundleInstallStatus(InnerBundleInfo &info, int32_t &uid); 210 /** 211 * @brief The process of updating an exist bundle. 212 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 213 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 214 * @param isReplace Indicates whether there is the replace flag in the install flag. 215 * @return Returns ERR_OK if the bundle updating successfully; returns error code otherwise. 216 */ 217 ErrCode ProcessBundleUpdateStatus(InnerBundleInfo &oldInfo, 218 InnerBundleInfo &newInfo, bool isReplace, bool noSkipsKill = true); 219 /** 220 * @brief Remove a whole bundle. 221 * @param info Indicates the InnerBundleInfo object of a bundle. 222 * @param isKeepData Indicates that whether to save data. 223 * @return Returns ERR_OK if the bundle removed successfully; returns error code otherwise. 224 */ 225 ErrCode RemoveBundle(InnerBundleInfo &info, bool isKeepData); 226 /** 227 * @brief Create the code and data directories of a bundle. 228 * @param info Indicates the InnerBundleInfo object of a bundle. 229 * @return Returns ERR_OK if the bundle directories created successfully; returns error code otherwise. 230 */ 231 ErrCode CreateBundleAndDataDir(InnerBundleInfo &info) const; 232 /** 233 * @brief Extract the code to temporilay directory and rename it. 234 * @param info Indicates the InnerBundleInfo object of a bundle. 235 * @param modulePath normal files decompression path. 236 * @return Returns ERR_OK if the bundle extract and renamed successfully; returns error code otherwise. 237 */ 238 ErrCode ExtractModule(InnerBundleInfo &info, const std::string &modulePath); 239 /** 240 * @brief Remove the code and data directories of a bundle. 241 * @param info Indicates the InnerBundleInfo object of a bundle. 242 * @param isKeepData Indicates that whether to save data. 243 * @return Returns ERR_OK if the bundle directories removed successfully; returns error code otherwise. 244 */ 245 ErrCode RemoveBundleAndDataDir(const InnerBundleInfo &info, bool isKeepData) const; 246 /** 247 * @brief Remove the code and data directories of a module in a bundle. 248 * @param info Indicates the InnerBundleInfo object of a bundle. 249 * @param modulePackage Indicates the module to be removed. 250 * @param userId Indicates the userId. 251 * @param isKeepData Indicates that whether to save data. 252 * @return Returns ERR_OK if the bundle directories removed successfully; returns error code otherwise. 253 */ 254 ErrCode RemoveModuleAndDataDir(const InnerBundleInfo &info, 255 const std::string &modulePackage, int32_t userId, bool isKeepData) const; 256 /** 257 * @brief Remove the current installing module directory. 258 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 259 * @return Returns ERR_OK if the module directory removed successfully; returns error code otherwise. 260 */ 261 ErrCode RemoveModuleDir(const std::string &modulePath) const; 262 /** 263 * @brief Extract files of the current installing module package. 264 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 265 * @param modulePath normal files decompression path. 266 * @param targetSoPath so files decompression path. 267 * @param cpuAbi cpuAbi. 268 * @return Returns ERR_OK if the module files extraced successfully; returns error code otherwise. 269 */ 270 ErrCode ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath, 271 const std::string &targetSoPath, const std::string &cpuAbi); 272 /** 273 * @brief Rename the directory of current installing module package. 274 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 275 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 276 */ 277 ErrCode RenameModuleDir(const InnerBundleInfo &info) const; 278 /** 279 * @brief The process of install a new module package. 280 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 281 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 282 * @return Returns ERR_OK if the new module install successfully; returns error code otherwise. 283 */ 284 ErrCode ProcessNewModuleInstall(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 285 /** 286 * @brief The process of updating an exist module package. 287 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 288 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 289 * @return Returns ERR_OK if the module updating successfully; returns error code otherwise. 290 */ 291 ErrCode ProcessModuleUpdate(InnerBundleInfo &newInfo, 292 InnerBundleInfo &oldInfo, bool isReplace, bool noSkipsKill = true); 293 /** 294 * @brief try to get the bundle info to decide use install or update. 295 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 296 * @param uid Indicates the uid of the application. 297 * @param installFlag Indicates install Flag. 298 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 299 */ 300 ErrCode ProcessBundleStatus(InnerBundleInfo &newInfo, int32_t &uid, const InstallFlag &installFlag); 301 /** 302 * @brief The real procedure for bundle install by bundleName. 303 * @param bundleName Indicates the bundleName the application to install. 304 * @param installParam Indicates the install parameters. 305 * @param uid Indicates the uid of the application. 306 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 307 */ 308 ErrCode ProcessRecover( 309 const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 310 /** 311 * @brief The real procedure for bundle install by bundleName. 312 * @param bundleName Indicates the bundleName the application to install. 313 * @param installParam Indicates the install parameters. 314 * @param uid Indicates the uid of the application. 315 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 316 */ 317 ErrCode ProcessInstallBundleByBundleName( 318 const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 319 /** 320 * @brief The real procedure for bundle install by bundleName. 321 * @param bundleName Indicates the bundleName the application to install. 322 * @param installParam Indicates the install parameters. 323 * @param uid Indicates the uid of the application. 324 * @param recoverMode Indicates the recoverMode or not. 325 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 326 */ 327 ErrCode InnerProcessInstallByPreInstallInfo( 328 const std::string &bundleName, const InstallParam &installParam, int32_t &uid, bool recoverMode); 329 /** 330 * @brief Check syscap. 331 * @param bundlePaths Indicates the file paths of all HAP packages. 332 * @return Returns ERR_OK if the syscap satisfy; returns error code otherwise. 333 */ 334 ErrCode CheckSysCap(const std::vector<std::string> &bundlePaths); 335 /** 336 * @brief Check signature info of multiple haps. 337 * @param bundlePaths Indicates the file paths of all HAP packages. 338 * @param installParam Indicates the install parameters. 339 * @param hapVerifyRes Indicates the signature info. 340 * @return Returns ERR_OK if the every hap has signature info and all haps have same signature info. 341 */ 342 ErrCode CheckMultipleHapsSignInfo( 343 const std::vector<std::string> &bundlePaths, 344 const InstallParam &installParam, 345 std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes); 346 /** 347 * @brief To parse hap files and to obtain innerBundleInfo of each hap. 348 * @param bundlePaths Indicates the file paths of all HAP packages. 349 * @param installParam Indicates the install parameters. 350 * @param appType Indicates the app type of the hap. 351 * @param hapVerifyRes Indicates all signature info of all haps. 352 * @param infos Indicates the innerBundleinfo of each hap. 353 * @return Returns ERR_OK if each hap is parsed successfully; returns error code otherwise. 354 */ 355 ErrCode ParseHapFiles( 356 const std::vector<std::string> &bundlePaths, 357 const InstallParam &installParam, 358 const Constants::AppType appType, 359 std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes, 360 std::unordered_map<std::string, InnerBundleInfo> &infos); 361 /** 362 * @brief To check dependency whether or not exists. 363 * @param infos Indicates all innerBundleInfo for all haps need to be installed. 364 * @param sharedBundleInstaller Cross-app shared bundle installer 365 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 366 */ 367 ErrCode CheckDependency(std::unordered_map<std::string, InnerBundleInfo> &infos, 368 const SharedBundleInstaller &sharedBundleInstaller); 369 370 /** 371 * @brief To check the hap hash param. 372 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 373 * @param hashParams .Indicates all hashParams in installParam. 374 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 375 */ 376 ErrCode CheckHapHashParams( 377 std::unordered_map<std::string, InnerBundleInfo> &infos, 378 std::map<std::string, std::string> hashParams); 379 /** 380 * @brief To check the version code and bundleName in all haps. 381 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 382 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 383 */ 384 ErrCode CheckAppLabelInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos); 385 386 ErrCode CheckSharedBundleLabelInfo(std::unordered_map<std::string, InnerBundleInfo> &infos); 387 /** 388 * @brief To check native file in all haps. 389 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 390 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 391 */ 392 ErrCode CheckMultiNativeFile( 393 std::unordered_map<std::string, InnerBundleInfo> &infos); 394 /** 395 * @brief To roll back when the installation is failed. 396 * @param infos .Indicates the innerBundleInfo needs to be roll back. 397 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 398 * @return Returns ERR_OK if roll back successfully; returns error code otherwise. 399 */ 400 void RollBack(const InnerBundleInfo &info, InnerBundleInfo &oldInfo); 401 /** 402 * @brief To check the version code and bundleName in all haps. 403 * @param newInfos .Indicates all innerBundleInfo for all haps need to be rolled back. 404 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 405 * @return Returns ERR_OK if roll back successfully; returns error code otherwise. 406 */ 407 void RollBack(const std::unordered_map<std::string, InnerBundleInfo> &newInfos, InnerBundleInfo &oldInfo); 408 /** 409 * @brief To remove innerBundleInfo or moduleInfo of the corresponding haps. 410 * @param bundleName Indicates the bundle name of the bundle which needs to be removed innerBundleInfo or 411 * moudleInfo. 412 * @param packageName Indicates the package name of the hap which needs to be removed the moduleInfo. 413 * @return Returns ERR_OK if the removing is successful; returns error code otherwise. 414 */ 415 void RemoveInfo(const std::string &bundleName, const std::string &packageName); 416 /** 417 * @brief To roll back the moduleInfo of the corresponding haps. 418 * @param bundleName Indicates the bundle name of the bundle which needs to be rolled back the moudleInfo. 419 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 420 * @return Returns ERR_OK if the rollback is successful; returns error code otherwise. 421 */ 422 void RollBackMoudleInfo(const std::string &bundleName, InnerBundleInfo &oldInfo); 423 /** 424 * @brief To obtain the innerBundleInfo of the corresponding hap. 425 * @param info Indicates the innerBundleInfo obtained. 426 * @param isAppExist Indicates if the innerBundleInfo is existed or not. 427 * @return Returns ERR_OK if the innerBundleInfo is obtained successfully; returns error code otherwise. 428 */ 429 bool GetInnerBundleInfo(InnerBundleInfo &info, bool &isAppExist); 430 /** 431 * @brief To check whether the version code is compatible for application or not. 432 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 433 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 434 */ 435 ErrCode CheckVersionCompatibility(const InnerBundleInfo &oldInfo); 436 /** 437 * @brief To check whether the version code is compatible for application or not. 438 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 439 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 440 */ 441 ErrCode CheckVersionCompatibilityForApplication(const InnerBundleInfo &oldInfo); 442 /** 443 * @brief To check whether the version code is compatible for openharmony service or not. 444 * @param info Indicates the original innerBundleInfo of the bundle. 445 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 446 */ 447 ErrCode CheckVersionCompatibilityForHmService(const InnerBundleInfo &oldInfo); 448 /** 449 * @brief To uninstall lower version feature haps. 450 * @param info Indicates the innerBundleInfo of the bundle. 451 * @param packageVec Indicates the array of package names of the high version entry or feature hap. 452 * @return Returns ERR_OK if uninstall successfully; returns error code otherwise. 453 */ 454 ErrCode UninstallLowerVersionFeature(const std::vector<std::string> &packageVec, bool noSkipsKill = false); 455 /** 456 * @brief To get userId. 457 * @param installParam Indicates the installParam of the bundle. 458 * @return Returns userId. 459 */ 460 int32_t GetUserId(const int32_t &userId) const; 461 /** 462 * @brief Remove bundle user data. 463 * @param innerBundleInfo Indicates the innerBundleInfo of the bundle. 464 * @param needRemoveData Indicates need remove data or not. 465 * @return Returns BundleUserMgr. 466 */ 467 ErrCode RemoveBundleUserData(InnerBundleInfo &innerBundleInfo, bool needRemoveData = true); 468 /** 469 * @brief Create bundle user data. 470 * @param innerBundleInfo Indicates the bundle type of the application. 471 * @return Returns ERR_OK if result is ok; returns error code otherwise. 472 */ 473 ErrCode CreateBundleUserData(InnerBundleInfo &innerBundleInfo); 474 475 bool VerifyUriPrefix(const InnerBundleInfo &info, int32_t userId, bool isUpdate = false, 476 bool isModifyEntryName = false, std::string oldEntryName = "") const; 477 478 ErrCode CheckInstallationFree(const InnerBundleInfo &innerBundleInfo, 479 const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 480 481 bool UninstallAppControl(const std::string &appId, int32_t userId); 482 483 ErrCode InstallNormalAppControl(const std::string &installAppId, int32_t userId, bool isPreInstallApp = false); 484 485 ErrCode CreateBundleCodeDir(InnerBundleInfo &info) const; 486 ErrCode CreateBundleDataDir(InnerBundleInfo &info) const; 487 ErrCode RemoveModuleDataDir(const InnerBundleInfo &info, const std::string &modulePackage, 488 int32_t userId) const; 489 ErrCode RemoveBundleCodeDir(const InnerBundleInfo &info) const; 490 ErrCode RemoveBundleDataDir(const InnerBundleInfo &info) const; 491 void RemoveEmptyDirs(const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 492 std::string GetModuleNames(const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 493 Security::AccessToken::AccessTokenIDEx CreateAccessTokenIdEx(const InnerBundleInfo &info); 494 ErrCode GrantRequestPermissions(const InnerBundleInfo &info, const uint32_t tokenId); 495 ErrCode UpdateDefineAndRequestPermissions(const InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo); 496 ErrCode SetDirApl(const InnerBundleInfo &info); 497 /** 498 * @brief Check to set isRemovable true when install. 499 * @param newInfos Indicates all innerBundleInfo for all haps need to be installed. 500 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 501 * @param userId Indicates the userId. 502 * @param isFreeInstallFlag Indicates whether is FREE_INSTALL flag. 503 * @param isAppExist Indicates whether app is exist. 504 * @return 505 */ 506 void CheckEnableRemovable(std::unordered_map<std::string, InnerBundleInfo> &newInfos, 507 InnerBundleInfo &oldInfo, int32_t &userId, bool isFreeInstallFlag, bool isAppExist); 508 /** 509 * @brief Save oldInfo isRemovable to newInfo isRemovable. 510 * @param newModuleInfo Indicates the old innerModuleInfo of the bundle.. 511 * @param oldInfo Indicates the old innerBundleInfo of the bundle. 512 * @param existModule Indicates whether module is exist. 513 * @return 514 */ 515 void SaveOldRemovableInfo(InnerModuleInfo &newModuleInfo, InnerBundleInfo &oldInfo, bool existModule); 516 /** 517 * @brief Save hap path to records. 518 * @param isPreInstallApp Indicates isPreInstallApp or not. 519 * @param infos Indicates all innerBundleInfo for all haps need to be installed. 520 * @return 521 */ 522 void SaveHapPathToRecords( 523 bool isPreInstallApp, const std::unordered_map<std::string, InnerBundleInfo> &infos); 524 void OnSingletonChange(bool noSkipsKill); 525 ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID); 526 ErrCode CheckAppLabel(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 527 ErrCode CheckDebugType(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 528 void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType, 529 const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode); 530 ErrCode CheckNativeFileWithOldInfo( 531 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 532 bool HasAllOldModuleUpdate( 533 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 534 ErrCode CheckArkNativeFileWithOldInfo( 535 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 536 ErrCode CheckNativeSoWithOldInfo( 537 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 538 ErrCode NotifyBundleStatus(const NotifyBundleEvents &installRes); 539 void ProcessHqfInfo(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 540 ErrCode ProcessDiffFiles(const AppqfInfo &appQfInfo, const std::string &nativeLibraryPath, 541 const std::string &cpuAbi) const; 542 ErrCode ProcessDeployedHqfInfo(const std::string &nativeLibraryPath, 543 const std::string &cpuAbi, const InnerBundleInfo &newInfo, const AppQuickFix &appQuickFix) const; 544 ErrCode ProcessDeployingHqfInfo( 545 const std::string &nativeLibraryPath, const std::string &cpuAbi, const InnerBundleInfo &newInfo) const; 546 ErrCode UpdateLibAttrs(const InnerBundleInfo &newInfo, 547 const std::string &cpuAbi, const std::string &nativeLibraryPath, AppqfInfo &appQfInfo) const; 548 bool CheckHapLibsWithPatchLibs( 549 const std::string &nativeLibraryPath, const std::string &hqfLibraryPath) const; 550 ErrCode ExtractArkNativeFile(InnerBundleInfo &info, const std::string &modulePath); 551 ErrCode DeleteOldArkNativeFile(const InnerBundleInfo &oldInfo); 552 int32_t GetConfirmUserId( 553 const int32_t &userId, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 554 ErrCode CheckUserId(const int32_t &userId) const; 555 ErrCode CreateArkProfile( 556 const std::string &bundleName, int32_t userId, int32_t uid, int32_t gid) const; 557 ErrCode DeleteArkProfile(const std::string &bundleName, int32_t userId) const; 558 ErrCode ExtractArkProfileFile(const std::string &modulePath, const std::string &bundleName, 559 int32_t userId) const; 560 ErrCode ExtractAllArkProfileFile(const InnerBundleInfo &oldInfo) const; 561 ErrCode CheckOverlayInstallation(std::unordered_map<std::string, InnerBundleInfo> &newInfos, int32_t userId); 562 ErrCode CheckOverlayUpdate(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo, int32_t userId) const; 563 NotifyType GetNotifyType(); 564 void GetCallingEventInfo(EventInfo &eventInfo); 565 void GetInstallEventInfo(EventInfo &eventInfo); 566 void GetInstallEventInfo(const InnerBundleInfo &bundleInfo, EventInfo &eventInfo); 567 ErrCode CheckArkProfileDir(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo) const; 568 ErrCode ProcessAsanDirectory(InnerBundleInfo &info) const; 569 ErrCode CleanAsanDirectory(InnerBundleInfo &info) const; 570 void AddAppProvisionInfo(const std::string &bundleName, 571 const Security::Verify::ProvisionInfo &provisionInfo, const InstallParam &installParam) const; 572 ErrCode UninstallHspBundle(std::string &uninstallDir, const std::string &bundleName); 573 ErrCode UninstallHspVersion(std::string &uninstallDir, int32_t versionCode, InnerBundleInfo &info); 574 ErrCode CheckProxyDatas(const std::unordered_map<std::string, InnerBundleInfo> &newInfos); 575 bool CheckDuplicateProxyData(const std::unordered_map<std::string, InnerBundleInfo> &newInfos); 576 bool CheckDuplicateProxyData(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo); 577 bool CheckDuplicateProxyData(const std::vector<ProxyData> &proxyDatas); 578 bool CheckApiInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos); 579 ErrCode InnerProcessNativeLibs(InnerBundleInfo &info, const std::string &modulePath); 580 bool ExtractSoFiles(const std::string &soPath, const std::string &cpuAbi) const; 581 void ProcessOldNativeLibraryPath(const std::unordered_map<std::string, InnerBundleInfo> &newInfos, 582 uint32_t oldVersionCode, const std::string &oldNativeLibraryPath) const; 583 void ProcessAOT(bool isOTA, const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 584 ErrCode CopyHapsToSecurityDir(const InstallParam &installParam, std::vector<std::string> &bundlePaths); 585 ErrCode RenameAllTempDir(const std::unordered_map<std::string, InnerBundleInfo> &newInfos) const; 586 ErrCode FindSignatureFileDir(const std::string &moduleName, std::string &signatureFileDir); 587 ErrCode MoveFileToRealInstallationDir(const std::unordered_map<std::string, InnerBundleInfo> &infos); 588 std::string GetTempHapPath(const InnerBundleInfo &info); 589 ErrCode SaveHapToInstallPath(const std::unordered_map<std::string, InnerBundleInfo> &infos); 590 void UpdateAppInstallControlled(int32_t userId); 591 ErrCode MoveSoFileToRealInstallationDir(const std::unordered_map<std::string, InnerBundleInfo> &infos); 592 void ProcessDataGroupInfo(const std::vector<std::string> &bundlePaths, 593 std::unordered_map<std::string, InnerBundleInfo> &infos, 594 int32_t userId, const std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes); 595 ErrCode GetGroupDirsChange(const InnerBundleInfo &info, const InnerBundleInfo &oldInfo, bool oldInfoExisted); 596 ErrCode GetRemoveDataGroupDirs(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo); 597 ErrCode RemoveOldGroupDirs() const; 598 ErrCode CreateGroupDirs() const; 599 ErrCode GetDataGroupCreateInfos(const InnerBundleInfo &newInfo); 600 ErrCode RemoveDataGroupDirs(const std::string &bundleName, int32_t userId) const; 601 void DeleteGroupDirsForException() const; 602 ErrCode CreateDataGroupDirs( 603 const std::unordered_map<std::string, InnerBundleInfo> &newInfos, const InnerBundleInfo &oldInfo); 604 ErrCode UninstallBundleFromBmsExtension(const std::string &bundleName); 605 ErrCode CheckBundleInBmsExtension(const std::string &bundleName, int32_t userId); 606 ErrCode CheckMDMUpdateBundleForSelf(const InstallParam &installParam, InnerBundleInfo &oldInfo, 607 const std::unordered_map<std::string, InnerBundleInfo> &newInfos, bool isAppExist); 608 void ExtractResourceFiles(const InnerBundleInfo &info, const std::string &targetPath) const; 609 void RemoveTempSoDir(const std::string &tempSoDir); 610 611 InstallerState state_ = InstallerState::INSTALL_START; 612 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; // this pointer will get when public functions called 613 std::string bundleName_; 614 std::string moduleTmpDir_; 615 std::string modulePath_; 616 std::string baseDataPath_; 617 std::string modulePackage_; 618 std::string mainAbility_; 619 // key is package name, value is boolean 620 std::unordered_map<std::string, bool> installedModules_; 621 bool isAppExist_ = false; 622 bool isContainEntry_ = false; 623 uint32_t versionCode_ = 0; 624 uint32_t accessTokenId_ = 0; 625 // value is packageName for uninstalling 626 bool isFeatureNeedUninstall_ = false; 627 std::vector<std::string> uninstallModuleVec_; 628 // for quick fix 629 bool needDeleteQuickFixInfo_ = false; 630 631 int32_t userId_ = Constants::INVALID_USERID; 632 bool hasInstalledInUser_ = false; 633 SingletonState singletonState_ = SingletonState::DEFAULT; 634 std::map<std::string, std::string> hapPathRecords_; 635 // used to record system event infos 636 EventInfo sysEventInfo_; 637 std::unique_ptr<BundleInstallChecker> bundleInstallChecker_ = nullptr; 638 int32_t overlayType_ = NON_OVERLAY_TYPE; 639 std::string moduleName_; 640 // utilizing for code-signature 641 std::map<std::string, std::string> verifyCodeParams_; 642 std::vector<std::string> toDeleteTempHapPath_; 643 // key is the temp path of hap or hsp 644 // value is the signature file path 645 std::map<std::string, std::string> signatureFileMap_; 646 std::vector<DataGroupInfo> createGroupDirs_; 647 std::vector<std::string> removeGroupDirs_; 648 std::vector<std::string> bundlePaths_; 649 std::unordered_map<std::string, std::string> signatureFileTmpMap_; 650 651 DISALLOW_COPY_AND_MOVE(BaseBundleInstaller); 652 653 #define CHECK_RESULT(errcode, errmsg) \ 654 do { \ 655 if (errcode != ERR_OK) { \ 656 APP_LOGE(errmsg, errcode); \ 657 return errcode; \ 658 } \ 659 } while (0) 660 661 #define CHECK_RESULT_WITH_ROLLBACK(errcode, errmsg, newInfos, oldInfo) \ 662 do { \ 663 if ((errcode) == ERR_APPEXECFWK_INSTALL_SINGLETON_NOT_SAME || \ 664 (errcode) == ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON) { \ 665 APP_LOGE(errmsg, errcode); \ 666 return errcode; \ 667 } \ 668 \ 669 if (errcode != ERR_OK) { \ 670 APP_LOGE(errmsg, errcode); \ 671 RollBack(newInfos, oldInfo); \ 672 return errcode; \ 673 } \ 674 } while (0) 675 }; 676 } // namespace AppExecFwk 677 } // namespace OHOS 678 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_BUNDLE_INSTALLER_H