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