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 bool NotifyAllBundleStatus(); 170 171 private: 172 /** 173 * @brief The real procedure for system and normal bundle install. 174 * @param bundlePath Indicates the path for storing the HAP file of the application 175 * to install or update. 176 * @param installParam Indicates the install parameters. 177 * @param appType Indicates the application type. 178 * @param uid Indicates the uid of the application. 179 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 180 */ 181 ErrCode ProcessBundleInstall(const std::vector<std::string> &bundlePaths, const InstallParam &installParam, 182 const Constants::AppType appType, int32_t &uid); 183 184 ErrCode InnerProcessBundleInstall(std::unordered_map<std::string, InnerBundleInfo> &newInfos, 185 InnerBundleInfo &oldInfo, const InstallParam &installParam, int32_t &uid); 186 187 /** 188 * @brief The real procedure function for uninstall a bundle. 189 * @param bundleName Indicates the bundle name of the application to uninstall. 190 * @param installParam Indicates the uninstall parameters. 191 * @param uid Indicates the uid of the application. 192 * @return Returns ERR_OK if the bundle uninstall successfully; returns error code otherwise. 193 */ 194 ErrCode ProcessBundleUninstall(const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 195 /** 196 * @brief The real procedure for uninstall a module in a specific bundle. 197 * @param bundleName Indicates the bundle name of the application to uninstall. 198 * @param modulePackage Indicates the module package of the module to uninstall. 199 * @param installParam Indicates the uninstall parameters. 200 * @param uid Indicates the uid of the application. 201 * @return Returns ERR_OK if the module uninstall successfully; returns error code otherwise. 202 */ 203 ErrCode ProcessBundleUninstall(const std::string &bundleName, const std::string &modulePackage, 204 const InstallParam &installParam, int32_t &uid); 205 /** 206 * @brief The process of installing a new bundle. 207 * @param info Indicates the InnerBundleInfo parsed from the config.json in the HAP package. 208 * @param uid Indicates the uid of the application. 209 * @return Returns ERR_OK if the new bundle install successfully; returns error code otherwise. 210 */ 211 ErrCode ProcessBundleInstallStatus(InnerBundleInfo &info, int32_t &uid); 212 /** 213 * @brief The process of updating an exist bundle. 214 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 215 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 216 * @param isReplace Indicates whether there is the replace flag in the install flag. 217 * @return Returns ERR_OK if the bundle updating successfully; returns error code otherwise. 218 */ 219 ErrCode ProcessBundleUpdateStatus(InnerBundleInfo &oldInfo, 220 InnerBundleInfo &newInfo, bool isReplace, bool noSkipsKill = true); 221 /** 222 * @brief Remove a whole bundle. 223 * @param info Indicates the InnerBundleInfo object of a bundle. 224 * @param isKeepData Indicates that whether to save data. 225 * @return Returns ERR_OK if the bundle removed successfully; returns error code otherwise. 226 */ 227 ErrCode RemoveBundle(InnerBundleInfo &info, bool isKeepData); 228 /** 229 * @brief Create the code and data directories of a bundle. 230 * @param info Indicates the InnerBundleInfo object of a bundle. 231 * @return Returns ERR_OK if the bundle directories created successfully; returns error code otherwise. 232 */ 233 ErrCode CreateBundleAndDataDir(InnerBundleInfo &info) const; 234 /** 235 * @brief Extract the code to temporilay directory and rename it. 236 * @param info Indicates the InnerBundleInfo object of a bundle. 237 * @param modulePath normal files decompression path. 238 * @return Returns ERR_OK if the bundle extract and renamed successfully; returns error code otherwise. 239 */ 240 ErrCode ExtractModule(InnerBundleInfo &info, const std::string &modulePath); 241 /** 242 * @brief Remove the code and data directories of a bundle. 243 * @param info Indicates the InnerBundleInfo object of a bundle. 244 * @param isKeepData Indicates that whether to save data. 245 * @return Returns ERR_OK if the bundle directories removed successfully; returns error code otherwise. 246 */ 247 ErrCode RemoveBundleAndDataDir(const InnerBundleInfo &info, bool isKeepData) const; 248 /** 249 * @brief Remove the code and data directories of a module in a bundle. 250 * @param info Indicates the InnerBundleInfo object of a bundle. 251 * @param modulePackage Indicates the module to be removed. 252 * @param userId Indicates the userId. 253 * @param isKeepData Indicates that whether to save data. 254 * @return Returns ERR_OK if the bundle directories removed successfully; returns error code otherwise. 255 */ 256 ErrCode RemoveModuleAndDataDir(const InnerBundleInfo &info, 257 const std::string &modulePackage, int32_t userId, bool isKeepData) const; 258 /** 259 * @brief Remove the current installing module directory. 260 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 261 * @return Returns ERR_OK if the module directory removed successfully; returns error code otherwise. 262 */ 263 ErrCode RemoveModuleDir(const std::string &modulePath) const; 264 /** 265 * @brief Extract files of the current installing module package. 266 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 267 * @param modulePath normal files decompression path. 268 * @param targetSoPath so files decompression path. 269 * @param cpuAbi cpuAbi. 270 * @return Returns ERR_OK if the module files extraced successfully; returns error code otherwise. 271 */ 272 ErrCode ExtractModuleFiles(const InnerBundleInfo &info, const std::string &modulePath, 273 const std::string &targetSoPath, const std::string &cpuAbi); 274 /** 275 * @brief Rename the directory of current installing module package. 276 * @param info Indicates the InnerBundleInfo object of a bundle under installing. 277 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 278 */ 279 ErrCode RenameModuleDir(const InnerBundleInfo &info) const; 280 /** 281 * @brief The process of install a new module package. 282 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 283 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 284 * @return Returns ERR_OK if the new module install successfully; returns error code otherwise. 285 */ 286 ErrCode ProcessNewModuleInstall(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 287 /** 288 * @brief The process of updating an exist module package. 289 * @param newInfo Indicates the InnerBundleInfo object parsed from the config.json in the HAP package. 290 * @param oldInfo Indicates the exist InnerBundleInfo object get from the database. 291 * @return Returns ERR_OK if the module updating successfully; returns error code otherwise. 292 */ 293 ErrCode ProcessModuleUpdate(InnerBundleInfo &newInfo, 294 InnerBundleInfo &oldInfo, bool isReplace, bool noSkipsKill = true); 295 /** 296 * @brief The real procedure for bundle install by bundleName. 297 * @param bundleName Indicates the bundleName the application to install. 298 * @param installParam Indicates the install parameters. 299 * @param uid Indicates the uid of the application. 300 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 301 */ 302 ErrCode ProcessRecover( 303 const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 304 /** 305 * @brief The real procedure for bundle install by bundleName. 306 * @param bundleName Indicates the bundleName the application to install. 307 * @param installParam Indicates the install parameters. 308 * @param uid Indicates the uid of the application. 309 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 310 */ 311 ErrCode ProcessInstallBundleByBundleName( 312 const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 313 /** 314 * @brief The real procedure for bundle install by bundleName. 315 * @param bundleName Indicates the bundleName the application to install. 316 * @param installParam Indicates the install parameters. 317 * @param uid Indicates the uid of the application. 318 * @return Returns ERR_OK if the bundle install successfully; returns error code otherwise. 319 */ 320 ErrCode InnerProcessInstallByPreInstallInfo( 321 const std::string &bundleName, const InstallParam &installParam, int32_t &uid); 322 /** 323 * @brief Check syscap. 324 * @param bundlePaths Indicates the file paths of all HAP packages. 325 * @return Returns ERR_OK if the syscap satisfy; returns error code otherwise. 326 */ 327 ErrCode CheckSysCap(const std::vector<std::string> &bundlePaths); 328 /** 329 * @brief Check signature info of multiple haps. 330 * @param bundlePaths Indicates the file paths of all HAP packages. 331 * @param installParam Indicates the install parameters. 332 * @param hapVerifyRes Indicates the signature info. 333 * @return Returns ERR_OK if the every hap has signature info and all haps have same signature info. 334 */ 335 ErrCode CheckMultipleHapsSignInfo( 336 const std::vector<std::string> &bundlePaths, 337 const InstallParam &installParam, 338 std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes); 339 /** 340 * @brief To parse hap files and to obtain innerBundleInfo of each hap. 341 * @param bundlePaths Indicates the file paths of all HAP packages. 342 * @param installParam Indicates the install parameters. 343 * @param appType Indicates the app type of the hap. 344 * @param hapVerifyRes Indicates all signature info of all haps. 345 * @param infos Indicates the innerBundleinfo of each hap. 346 * @return Returns ERR_OK if each hap is parsed successfully; returns error code otherwise. 347 */ 348 ErrCode ParseHapFiles( 349 const std::vector<std::string> &bundlePaths, 350 const InstallParam &installParam, 351 const Constants::AppType appType, 352 std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes, 353 std::unordered_map<std::string, InnerBundleInfo> &infos); 354 355 ErrCode CheckInstallCondition(std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes, 356 std::unordered_map<std::string, InnerBundleInfo> &infos); 357 358 ErrCode CheckInstallPermission(const InstallParam &installParam, 359 std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes); 360 /** 361 * @brief To check dependency whether or not exists. 362 * @param infos Indicates all innerBundleInfo for all haps need to be installed. 363 * @param sharedBundleInstaller Cross-app shared bundle installer 364 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 365 */ 366 ErrCode CheckDependency(std::unordered_map<std::string, InnerBundleInfo> &infos, 367 const SharedBundleInstaller &sharedBundleInstaller); 368 369 /** 370 * @brief To check the hap hash param. 371 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 372 * @param hashParams .Indicates all hashParams in installParam. 373 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 374 */ 375 ErrCode CheckHapHashParams( 376 std::unordered_map<std::string, InnerBundleInfo> &infos, 377 std::map<std::string, std::string> hashParams); 378 /** 379 * @brief To check the version code and bundleName in all haps. 380 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 381 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 382 */ 383 ErrCode CheckAppLabelInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos); 384 385 ErrCode CheckSharedBundleLabelInfo(std::unordered_map<std::string, InnerBundleInfo> &infos); 386 /** 387 * @brief To check native file in all haps. 388 * @param infos .Indicates all innerBundleInfo for all haps need to be installed. 389 * @return Returns ERR_OK if haps checking successfully; returns error code otherwise. 390 */ 391 ErrCode CheckMultiNativeFile( 392 std::unordered_map<std::string, InnerBundleInfo> &infos); 393 /** 394 * @brief To roll back when the installation is failed. 395 * @param infos .Indicates the innerBundleInfo needs to be roll back. 396 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 397 * @return Returns ERR_OK if roll back successfully; returns error code otherwise. 398 */ 399 void RollBack(const InnerBundleInfo &info, InnerBundleInfo &oldInfo); 400 /** 401 * @brief To check the version code and bundleName in all haps. 402 * @param newInfos .Indicates all innerBundleInfo for all haps need to be rolled back. 403 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 404 * @return Returns ERR_OK if roll back successfully; returns error code otherwise. 405 */ 406 void RollBack(const std::unordered_map<std::string, InnerBundleInfo> &newInfos, InnerBundleInfo &oldInfo); 407 /** 408 * @brief To remove innerBundleInfo or moduleInfo of the corresponding haps. 409 * @param bundleName Indicates the bundle name of the bundle which needs to be removed innerBundleInfo or 410 * moudleInfo. 411 * @param packageName Indicates the package name of the hap which needs to be removed the moduleInfo. 412 * @return Returns ERR_OK if the removing is successful; returns error code otherwise. 413 */ 414 void RemoveInfo(const std::string &bundleName, const std::string &packageName); 415 /** 416 * @brief To roll back the moduleInfo of the corresponding haps. 417 * @param bundleName Indicates the bundle name of the bundle which needs to be rolled back the moudleInfo. 418 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 419 * @return Returns ERR_OK if the rollback is successful; returns error code otherwise. 420 */ 421 void RollBackModuleInfo(const std::string &bundleName, InnerBundleInfo &oldInfo); 422 /** 423 * @brief To obtain the innerBundleInfo of the corresponding hap. 424 * @param info Indicates the innerBundleInfo obtained. 425 * @param isAppExist Indicates if the innerBundleInfo is existed or not. 426 * @return Returns ERR_OK if the innerBundleInfo is obtained successfully; returns error code otherwise. 427 */ 428 bool GetInnerBundleInfo(InnerBundleInfo &info, bool &isAppExist); 429 /** 430 * @brief To check whether the version code is compatible for application or not. 431 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 432 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 433 */ 434 ErrCode CheckVersionCompatibility(const InnerBundleInfo &oldInfo); 435 /** 436 * @brief To check whether the version code is compatible for application or not. 437 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 438 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 439 */ 440 ErrCode CheckVersionCompatibilityForApplication(const InnerBundleInfo &oldInfo); 441 /** 442 * @brief To check whether the version code is compatible for openharmony service or not. 443 * @param info Indicates the original innerBundleInfo of the bundle. 444 * @return Returns ERR_OK if version code is checked successfully; returns error code otherwise. 445 */ 446 ErrCode CheckVersionCompatibilityForHmService(const InnerBundleInfo &oldInfo); 447 /** 448 * @brief To uninstall lower version feature haps. 449 * @param info Indicates the innerBundleInfo of the bundle. 450 * @param packageVec Indicates the array of package names of the high version entry or feature hap. 451 * @return Returns ERR_OK if uninstall successfully; returns error code otherwise. 452 */ 453 ErrCode UninstallLowerVersionFeature(const std::vector<std::string> &packageVec, bool noSkipsKill = false); 454 /** 455 * @brief To get userId. 456 * @param installParam Indicates the installParam of the bundle. 457 * @return Returns userId. 458 */ 459 int32_t GetUserId(const int32_t &userId) const; 460 /** 461 * @brief Remove bundle user data. 462 * @param innerBundleInfo Indicates the innerBundleInfo of the bundle. 463 * @param needRemoveData Indicates need remove data or not. 464 * @return Returns BundleUserMgr. 465 */ 466 ErrCode RemoveBundleUserData(InnerBundleInfo &innerBundleInfo, bool needRemoveData = true); 467 /** 468 * @brief Create bundle user data. 469 * @param innerBundleInfo Indicates the bundle type of the application. 470 * @return Returns ERR_OK if result is ok; returns error code otherwise. 471 */ 472 ErrCode CreateBundleUserData(InnerBundleInfo &innerBundleInfo); 473 void AddBundleStatus(const NotifyBundleEvents &installRes); 474 ErrCode CheckInstallationFree(const InnerBundleInfo &innerBundleInfo, 475 const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 476 477 bool UninstallAppControl(const std::string &appId, int32_t userId); 478 479 ErrCode InstallNormalAppControl(const std::string &installAppId, int32_t userId, bool isPreInstallApp = false); 480 481 ErrCode CreateBundleCodeDir(InnerBundleInfo &info) const; 482 ErrCode CreateBundleDataDir(InnerBundleInfo &info) const; 483 ErrCode RemoveModuleDataDir(const InnerBundleInfo &info, const std::string &modulePackage, 484 int32_t userId) const; 485 ErrCode RemoveBundleCodeDir(const InnerBundleInfo &info) const; 486 ErrCode RemoveBundleDataDir(const InnerBundleInfo &info) const; 487 void RemoveEmptyDirs(const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 488 std::string GetModuleNames(const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 489 Security::AccessToken::AccessTokenIDEx CreateAccessTokenIdEx(const InnerBundleInfo &info); 490 ErrCode GrantRequestPermissions(const InnerBundleInfo &info, const uint32_t tokenId); 491 ErrCode UpdateDefineAndRequestPermissions(const InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo); 492 ErrCode SetDirApl(const InnerBundleInfo &info); 493 /** 494 * @brief Check to set isRemovable true when install. 495 * @param newInfos Indicates all innerBundleInfo for all haps need to be installed. 496 * @param oldInfo Indicates the original innerBundleInfo of the bundle. 497 * @param userId Indicates the userId. 498 * @param isFreeInstallFlag Indicates whether is FREE_INSTALL flag. 499 * @param isAppExist Indicates whether app is exist. 500 * @return 501 */ 502 void CheckEnableRemovable(std::unordered_map<std::string, InnerBundleInfo> &newInfos, 503 InnerBundleInfo &oldInfo, int32_t &userId, bool isFreeInstallFlag, bool isAppExist); 504 /** 505 * @brief Save oldInfo isRemovable to newInfo isRemovable. 506 * @param newModuleInfo Indicates the old innerModuleInfo of the bundle.. 507 * @param oldInfo Indicates the old innerBundleInfo of the bundle. 508 * @param existModule Indicates whether module is exist. 509 * @return 510 */ 511 void SaveOldRemovableInfo(InnerModuleInfo &newModuleInfo, InnerBundleInfo &oldInfo, bool existModule); 512 /** 513 * @brief Save hap path to records. 514 * @param isPreInstallApp Indicates isPreInstallApp or not. 515 * @param infos Indicates all innerBundleInfo for all haps need to be installed. 516 * @return 517 */ 518 void SaveHapPathToRecords( 519 bool isPreInstallApp, const std::unordered_map<std::string, InnerBundleInfo> &infos); 520 void OnSingletonChange(bool noSkipsKill); 521 bool AllowSingletonChange(const std::string &bundleName); 522 void MarkPreInstallState(const std::string &bundleName, bool isUninstalled); 523 ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID); 524 ErrCode CheckAppLabel(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 525 ErrCode CheckDebugType(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 526 void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType, 527 const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode); 528 ErrCode CheckNativeFileWithOldInfo( 529 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 530 bool HasAllOldModuleUpdate( 531 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 532 ErrCode CheckArkNativeFileWithOldInfo( 533 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 534 ErrCode CheckNativeSoWithOldInfo( 535 const InnerBundleInfo &oldInfo, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 536 ErrCode NotifyBundleStatus(const NotifyBundleEvents &installRes); 537 void AddNotifyBundleEvents(const NotifyBundleEvents ¬ifyBundleEvents); 538 void ProcessHqfInfo(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const; 539 ErrCode ProcessDiffFiles(const AppqfInfo &appQfInfo, const std::string &nativeLibraryPath, 540 const std::string &cpuAbi) const; 541 ErrCode ProcessDeployedHqfInfo(const std::string &nativeLibraryPath, 542 const std::string &cpuAbi, const InnerBundleInfo &newInfo, const AppQuickFix &appQuickFix) const; 543 ErrCode ProcessDeployingHqfInfo( 544 const std::string &nativeLibraryPath, const std::string &cpuAbi, const InnerBundleInfo &newInfo) const; 545 ErrCode UpdateLibAttrs(const InnerBundleInfo &newInfo, 546 const std::string &cpuAbi, const std::string &nativeLibraryPath, AppqfInfo &appQfInfo) const; 547 bool CheckHapLibsWithPatchLibs( 548 const std::string &nativeLibraryPath, const std::string &hqfLibraryPath) const; 549 ErrCode ExtractArkNativeFile(InnerBundleInfo &info, const std::string &modulePath); 550 ErrCode DeleteOldArkNativeFile(const InnerBundleInfo &oldInfo); 551 int32_t GetConfirmUserId( 552 const int32_t &userId, std::unordered_map<std::string, InnerBundleInfo> &newInfos); 553 ErrCode CheckUserId(const int32_t &userId) const; 554 ErrCode CreateArkProfile( 555 const std::string &bundleName, int32_t userId, int32_t uid, int32_t gid) const; 556 ErrCode DeleteArkProfile(const std::string &bundleName, int32_t userId) const; 557 ErrCode ExtractArkProfileFile(const std::string &modulePath, const std::string &bundleName, 558 int32_t userId) const; 559 ErrCode ExtractAllArkProfileFile(const InnerBundleInfo &oldInfo, bool checkRepeat = false) const; 560 ErrCode CopyPgoFileToArkProfileDir(const std::string &moduleName, const std::string &modulePath, 561 const std::string &bundleName, int32_t userId) const; 562 ErrCode CopyPgoFile(const std::string &moduleName, const std::string &pgoPath, 563 const std::string &bundleName, int32_t userId) const; 564 ErrCode CheckOverlayInstallation(std::unordered_map<std::string, InnerBundleInfo> &newInfos, int32_t userId); 565 ErrCode CheckOverlayUpdate(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo, int32_t userId) const; 566 NotifyType GetNotifyType(); 567 ErrCode CheckAppService( 568 const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo, bool isAppExist); 569 ErrCode CheckSingleton(const InnerBundleInfo &newInfo, const int32_t userId); 570 void GetCallingEventInfo(EventInfo &eventInfo); 571 void GetInstallEventInfo(EventInfo &eventInfo); 572 void GetInstallEventInfo(const InnerBundleInfo &bundleInfo, EventInfo &eventInfo); 573 ErrCode CheckArkProfileDir(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo) const; 574 ErrCode ProcessAsanDirectory(InnerBundleInfo &info) const; 575 ErrCode CleanAsanDirectory(InnerBundleInfo &info) const; 576 void AddAppProvisionInfo(const std::string &bundleName, 577 const Security::Verify::ProvisionInfo &provisionInfo, const InstallParam &installParam) const; 578 ErrCode UninstallHspBundle(std::string &uninstallDir, const std::string &bundleName); 579 ErrCode UninstallHspVersion(std::string &uninstallDir, int32_t versionCode, InnerBundleInfo &info); 580 ErrCode CheckProxyDatas(const std::unordered_map<std::string, InnerBundleInfo> &newInfos); 581 bool CheckDuplicateProxyData(const std::unordered_map<std::string, InnerBundleInfo> &newInfos); 582 bool CheckDuplicateProxyData(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo); 583 bool CheckDuplicateProxyData(const std::vector<ProxyData> &proxyDatas); 584 bool CheckApiInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos); 585 ErrCode InnerProcessNativeLibs(InnerBundleInfo &info, const std::string &modulePath); 586 ErrCode CheckSoEncryption(InnerBundleInfo &info, const std::string &cpuAbi, const std::string &targetSoPath); 587 bool ExtractSoFiles(const std::string &soPath, const std::string &cpuAbi) const; 588 void ProcessOldNativeLibraryPath(const std::unordered_map<std::string, InnerBundleInfo> &newInfos, 589 uint32_t oldVersionCode, const std::string &oldNativeLibraryPath) const; 590 void ProcessAOT(bool isOTA, const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 591 ErrCode CopyHapsToSecurityDir(const InstallParam &installParam, std::vector<std::string> &bundlePaths); 592 ErrCode RenameAllTempDir(const std::unordered_map<std::string, InnerBundleInfo> &newInfos) const; 593 ErrCode FindSignatureFileDir(const std::string &moduleName, std::string &signatureFileDir); 594 ErrCode MoveFileToRealInstallationDir(const std::unordered_map<std::string, InnerBundleInfo> &infos); 595 std::string GetTempHapPath(const InnerBundleInfo &info); 596 ErrCode SaveHapToInstallPath(const std::unordered_map<std::string, InnerBundleInfo> &infos); 597 ErrCode CheckHapEncryption(const std::unordered_map<std::string, InnerBundleInfo> &infos); 598 void UpdateAppInstallControlled(int32_t userId); 599 ErrCode MoveSoFileToRealInstallationDir(const std::unordered_map<std::string, InnerBundleInfo> &infos); 600 void ProcessDataGroupInfo(const std::vector<std::string> &bundlePaths, 601 std::unordered_map<std::string, InnerBundleInfo> &infos, 602 int32_t userId, const std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes); 603 ErrCode GetGroupDirsChange(const InnerBundleInfo &info, const InnerBundleInfo &oldInfo, bool oldInfoExisted); 604 ErrCode GetRemoveDataGroupDirs(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo); 605 ErrCode RemoveOldGroupDirs() const; 606 ErrCode CreateGroupDirs() const; 607 ErrCode GetDataGroupCreateInfos(const InnerBundleInfo &newInfo); 608 ErrCode RemoveDataGroupDirs(const std::string &bundleName, int32_t userId) const; 609 void DeleteGroupDirsForException() const; 610 ErrCode CreateDataGroupDirs( 611 const std::unordered_map<std::string, InnerBundleInfo> &newInfos, const InnerBundleInfo &oldInfo); 612 bool NeedDeleteOldNativeLib( 613 std::unordered_map<std::string, InnerBundleInfo> &newInfos, 614 const InnerBundleInfo &oldInfo); 615 ErrCode UninstallBundleFromBmsExtension(const std::string &bundleName); 616 ErrCode CheckBundleInBmsExtension(const std::string &bundleName, int32_t userId); 617 ErrCode CheckMDMUpdateBundleForSelf(const InstallParam &installParam, InnerBundleInfo &oldInfo, 618 const std::unordered_map<std::string, InnerBundleInfo> &newInfos, bool isAppExist); 619 void ExtractResourceFiles(const InnerBundleInfo &info, const std::string &targetPath) const; 620 void RemoveTempSoDir(const std::string &tempSoDir); 621 bool CheckAppIdentifier(InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo); 622 ErrCode InstallEntryMoudleFirst(std::unordered_map<std::string, InnerBundleInfo> &newInfos, 623 InnerBundleInfo &bundleInfo, const InnerBundleUserInfo &innerBundleUserInfo, const InstallParam &installParam); 624 void ProcessQuickFixWhenInstallNewModule(const InstallParam &installParam, 625 const std::unordered_map<std::string, InnerBundleInfo> &newInfos); 626 bool ExtractEncryptedSoFiles(const InnerBundleInfo &info, const std::string &tmpSoPath, int32_t uid) const; 627 ErrCode VerifyCodeSignatureForNativeFiles(InnerBundleInfo &info, const std::string &cpuAbi, 628 const std::string &targetSoPath, const std::string &signatureFileDir) const; 629 ErrCode VerifyCodeSignatureForHap(const std::unordered_map<std::string, InnerBundleInfo> &infos, 630 const std::string &srcHapPath, const std::string &realHapPath); 631 ErrCode DeliveryProfileToCodeSign() const; 632 ErrCode RemoveProfileFromCodeSign(const std::string &bundleName) const; 633 ErrCode ExtractResFileDir(const std::string &modulePath) const; 634 void DeleteOldNativeLibraryPath() const; 635 void RemoveTempPathOnlyUsedForSo(const InnerBundleInfo &innerBundleInfo) const; 636 637 InstallerState state_ = InstallerState::INSTALL_START; 638 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; // this pointer will get when public functions called 639 std::string bundleName_; 640 std::string moduleTmpDir_; 641 std::string modulePath_; 642 std::string baseDataPath_; 643 std::string modulePackage_; 644 std::string mainAbility_; 645 // key is package name, value is boolean 646 std::unordered_map<std::string, bool> installedModules_; 647 bool isAppExist_ = false; 648 bool isContainEntry_ = false; 649 uint32_t versionCode_ = 0; 650 uint32_t accessTokenId_ = 0; 651 bool isAppService_ = false; 652 // value is packageName for uninstalling 653 bool isFeatureNeedUninstall_ = false; 654 std::vector<std::string> uninstallModuleVec_; 655 // for quick fix 656 bool needDeleteQuickFixInfo_ = false; 657 658 int32_t userId_ = Constants::INVALID_USERID; 659 bool hasInstalledInUser_ = false; 660 SingletonState singletonState_ = SingletonState::DEFAULT; 661 std::map<std::string, std::string> hapPathRecords_; 662 // used to record system event infos 663 EventInfo sysEventInfo_; 664 std::unique_ptr<BundleInstallChecker> bundleInstallChecker_ = nullptr; 665 int32_t overlayType_ = NON_OVERLAY_TYPE; 666 std::string moduleName_; 667 // utilizing for code-signature 668 std::map<std::string, std::string> verifyCodeParams_; 669 std::vector<std::string> toDeleteTempHapPath_; 670 std::vector<NotifyBundleEvents> bundleEvents_; 671 // key is the temp path of hap or hsp 672 // value is the signature file path 673 std::map<std::string, std::string> signatureFileMap_; 674 std::vector<DataGroupInfo> createGroupDirs_; 675 std::vector<std::string> removeGroupDirs_; 676 std::vector<std::string> bundlePaths_; 677 std::unordered_map<std::string, std::string> signatureFileTmpMap_; 678 std::string uninstallBundleAppId_; 679 bool isModuleUpdate_ = false; 680 // utilize for install entry firstly from multi-installation 681 bool isEntryInstalled_ = false; 682 std::string entryModuleName_ = ""; 683 std::map<std::string, std::string> pgoParams_; 684 bool isEnterpriseBundle_ = false; 685 std::string appIdentifier_ = ""; 686 Security::Verify::HapVerifyResult verifyRes_; 687 std::map<std::string, std::string> targetSoPathMap_; 688 bool copyHapToInstallPath_ = false; 689 690 DISALLOW_COPY_AND_MOVE(BaseBundleInstaller); 691 692 #define CHECK_RESULT(errcode, errmsg) \ 693 do { \ 694 if ((errcode) != ERR_OK) { \ 695 APP_LOGE(errmsg, errcode); \ 696 return errcode; \ 697 } \ 698 } while (0) 699 700 #define CHECK_RESULT_WITH_ROLLBACK(errcode, errmsg, newInfos, oldInfo) \ 701 do { \ 702 if ((errcode) == ERR_APPEXECFWK_INSTALL_SINGLETON_NOT_SAME || \ 703 (errcode) == ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON) { \ 704 APP_LOGE(errmsg, errcode); \ 705 return errcode; \ 706 } \ 707 \ 708 if ((errcode) != ERR_OK) { \ 709 APP_LOGE(errmsg, errcode); \ 710 RollBack(newInfos, oldInfo); \ 711 return errcode; \ 712 } \ 713 } while (0) 714 }; 715 } // namespace AppExecFwk 716 } // namespace OHOS 717 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_BUNDLE_INSTALLER_H