1 /* 2 * Copyright (c) 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_APP_SERVICE_FWK_INSTALLER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_APP_SERVICE_FWK_INSTALLER_H 18 19 #include <memory> 20 #include <string> 21 #include <unordered_map> 22 23 #include "bundle_data_mgr.h" 24 #include "bundle_install_checker.h" 25 #include "event_report.h" 26 #include "inner_bundle_info.h" 27 #include "install_param.h" 28 #include "nocopyable.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class AppServiceFwkInstaller { 33 public: 34 AppServiceFwkInstaller(); 35 virtual ~AppServiceFwkInstaller(); 36 37 ErrCode Install( 38 const std::vector<std::string> &hspPaths, InstallParam &installParam); 39 ErrCode UnInstall(const std::string &bundleName, bool isKeepData = false); 40 private: 41 void ResetProperties(); 42 ErrCode BeforeInstall( 43 const std::vector<std::string> &hspPaths, InstallParam &installParam); 44 ErrCode BeforeUninstall(const std::string &bundleName); 45 ErrCode ProcessInstall( 46 const std::vector<std::string> &hspPaths, InstallParam &installParam); 47 ErrCode CheckAndParseFiles( 48 const std::vector<std::string> &hspPaths, InstallParam &installParam, 49 std::unordered_map<std::string, InnerBundleInfo> &newInfos); 50 ErrCode InnerProcessInstall( 51 std::unordered_map<std::string, InnerBundleInfo> &newInfos, 52 InstallParam &installParam); 53 ErrCode CheckAppLabelInfo( 54 const std::unordered_map<std::string, InnerBundleInfo> &infos); 55 ErrCode CheckFileType(const std::vector<std::string> &bundlePaths); 56 void SendBundleSystemEvent( 57 const std::vector<std::string> &hspPaths, BundleEventType bundleEventType, 58 const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode); 59 ErrCode ExtractModule( 60 InnerBundleInfo &newInfo, const std::string &bundlePath, bool copyHapToInstallPath = false); 61 ErrCode ExtractModule(InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo, const std::string &bundlePath); 62 ErrCode MkdirIfNotExist(const std::string &dir); 63 ErrCode ProcessNativeLibrary( 64 const std::string &bundlePath, 65 const std::string &moduleDir, 66 const std::string &moduleName, 67 const std::string &versionDir, 68 InnerBundleInfo &newInfo, 69 bool copyHapToInstallPath = false); 70 ErrCode MoveSoToRealPath( 71 const std::string &moduleName, const std::string &versionDir, 72 const std::string &nativeLibraryPath); 73 void MergeBundleInfos(InnerBundleInfo &info); 74 ErrCode SaveBundleInfoToStorage(); 75 void AddAppProvisionInfo( 76 const std::string &bundleName, 77 const Security::Verify::ProvisionInfo &provisionInfo, 78 const InstallParam &installParam) const; 79 80 void RollBack(); 81 void RemoveInfo(const std::string &bundleName); 82 void SavePreInstallBundleInfo(ErrCode installResult, 83 const std::unordered_map<std::string, InnerBundleInfo> &newInfos, const InstallParam &installParam); 84 ErrCode UpdateAppService(InnerBundleInfo &oldInfo, 85 std::unordered_map<std::string, InnerBundleInfo> &newInfos, 86 InstallParam &installParam); 87 ErrCode UninstallLowerVersion(const std::vector<std::string> &moduleNameList); 88 bool GetInnerBundleInfo(InnerBundleInfo &info, bool &isAppExist); 89 bool CheckNeedInstall(const std::unordered_map<std::string, InnerBundleInfo> &infos, InnerBundleInfo &oldInfo); 90 bool CheckNeedUpdate(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo); 91 ErrCode ProcessBundleUpdateStatus(InnerBundleInfo &oldInfo, InnerBundleInfo &newInfo, 92 const std::string &hspPath, const InstallParam &installParam); 93 ErrCode ProcessNewModuleInstall(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo, 94 const std::string &hspPath, const InstallParam &installParam); 95 ErrCode ProcessModuleUpdate(InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo, 96 const std::string &hspPath, const InstallParam &installParam); 97 ErrCode RemoveLowerVersionSoDir(uint32_t versionCode); 98 ErrCode VerifyCodeSignatureForNativeFiles(const std::string &bundlePath, const std::string &cpuAbi, 99 const std::string &targetSoPath) const; 100 ErrCode DeliveryProfileToCodeSign(std::vector<Security::Verify::HapVerifyResult> &hapVerifyResults) const; 101 void GenerateOdid(std::unordered_map<std::string, InnerBundleInfo> &infos, 102 const std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes) const; 103 ErrCode VerifyCodeSignatureForHsp(const std::string &realHspPath, const std::string &realSoPath) const; 104 ErrCode MarkInstallFinish(); 105 106 std::unique_ptr<BundleInstallChecker> bundleInstallChecker_ = nullptr; 107 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; 108 std::string bundleName_; 109 std::string bundleMsg_; 110 std::vector<std::string> uninstallModuleVec_; 111 bool versionUpgrade_ = false; 112 bool moduleUpdate_ = false; 113 std::vector<std::string> deleteBundlePath_; 114 uint32_t versionCode_ = 0; 115 InnerBundleInfo newInnerBundleInfo_; 116 bool isEnterpriseBundle_ = false; 117 std::string appIdentifier_; 118 std::string compileSdkType_; 119 std::string cpuAbi_; 120 std::string nativeLibraryPath_; 121 DISALLOW_COPY_AND_MOVE(AppServiceFwkInstaller); 122 123 #define CHECK_RESULT(errcode, errmsg) \ 124 do { \ 125 if ((errcode) != ERR_OK) { \ 126 APP_LOGE(errmsg, errcode); \ 127 return errcode; \ 128 } \ 129 } while (0) 130 }; 131 } // namespace AppExecFwk 132 } // namespace OHOS 133 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_APP_SERVICE_FWK_INSTALLER_H