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_BUNDLE_INSTALLER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "nocopyable.h" 24 25 #include "base_bundle_installer.h" 26 #include "status_receiver_interface.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 class BundleInstaller : public BaseBundleInstaller { 31 public: 32 BundleInstaller(const int64_t installerId, const sptr<IStatusReceiver> &statusReceiver); 33 virtual ~BundleInstaller() override; 34 /** 35 * @brief Get the installer ID of an installer object. 36 * @return Returns the installer ID of this object. 37 */ GetInstallerId()38 int64_t GetInstallerId() const 39 { 40 return installerId_; 41 } 42 /** 43 * @brief Install a bundle using this installer object. 44 * @param bundleFilePath Indicates the path for storing the HAP of the bundle to install or update. 45 * @param installParam Indicates the install parameters. 46 * @return 47 */ 48 void Install(const std::string &bundleFilePath, const InstallParam &installParam); 49 /** 50 * @brief Install a bundle by bundleName. 51 * @param bundleName Indicates the bundleName of the bundle to install. 52 * @param installParam Indicates the install parameters. 53 * @return 54 */ 55 void Recover(const std::string &bundleName, const InstallParam &installParam); 56 /** 57 * @brief Install a bundle using this installer object. 58 * @param bundleFilePaths Indicates the paths for storing the HAP of the bundle to install or update. 59 * @param installParam Indicates the install parameters. 60 * @return 61 */ 62 void Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam); 63 /** 64 * @brief Install a bundle by bundleName. 65 * @param bundleName Indicates the bundleName of the bundle to install. 66 * @param installParam Indicates the install parameters. 67 * @return 68 */ 69 void InstallByBundleName(const std::string &bundleName, const InstallParam &installParam); 70 /** 71 * @brief Uninstall a bundle using this installer object. 72 * @param bundleName Indicates the bundle name of the application to uninstall. 73 * @param installParam Indicates the uninstall parameters. 74 * @return 75 */ 76 void Uninstall(const std::string &bundleName, const InstallParam &installParam); 77 /** 78 * @brief Uninstall a module using this installer object. 79 * @param bundleName Indicates the bundle name of the module to uninstall. 80 * @param modulePackage Indicates the module package of the module to uninstall. 81 * @param installParam Indicates the uninstall parameters. 82 * @return 83 */ 84 void Uninstall(const std::string &bundleName, const std::string &modulePackage, const InstallParam &installParam); 85 /** 86 * @brief Uninstall a bundle by uninstallParam. 87 * @param uninstallParam Indicates the input uninstallParam. 88 * @return 89 */ 90 void Uninstall(const UninstallParam &uninstallParam); 91 /** 92 * @brief Update the installer state and send status from the StatusReceiver object. 93 * @attention This function will send the install status to StatusReceiver. 94 * @param state Indicates the state to be updated to. 95 * @return 96 */ 97 virtual void UpdateInstallerState(const InstallerState state) override; 98 void UpdateBundleForSelf(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam); 99 100 void UninstallAndRecover(const std::string &bundleName, const InstallParam &installParam); 101 102 private: 103 /** 104 * @brief Get all exist common userId. 105 * @attention This function will get all exist common userId. 106 * @return Returns all exist common userId 107 */ 108 std::set<int32_t> GetExistsCommonUserIds(); 109 110 private: 111 const int64_t installerId_ = 0; 112 const sptr<IStatusReceiver> statusReceiver_; 113 114 DISALLOW_COPY_AND_MOVE(BundleInstaller); 115 }; 116 } // namespace AppExecFwk 117 } // namespace OHOS 118 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_H