1 /* 2 * Copyright (c) 2021 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 22 #include "nocopyable.h" 23 24 #include "base_bundle_installer.h" 25 #include "event_handler.h" 26 #include "status_receiver_interface.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 31 class BundleInstaller : public BaseBundleInstaller { 32 public: 33 BundleInstaller(const int64_t installerId, const std::shared_ptr<EventHandler> &handler, 34 const sptr<IStatusReceiver> &statusReceiver); 35 virtual ~BundleInstaller() override; 36 /** 37 * @brief Get the installer ID of an installer object. 38 * @return Returns the installer ID of this object. 39 */ GetInstallerId()40 int64_t GetInstallerId() const 41 { 42 return installerId_; 43 } 44 /** 45 * @brief Install a bundle using this installer object. 46 * @param bundleFilePath Indicates the path for storing the HAP of the bundle to install or update. 47 * @param installParam Indicates the install parameters. 48 * @return 49 */ 50 void Install(const std::string &bundleFilePath, const InstallParam &installParam); 51 /** 52 * @brief Uninstall a bundle using this installer object. 53 * @param bundleName Indicates the bundle name of the application to uninstall. 54 * @param installParam Indicates the uninstall parameters. 55 * @return 56 */ 57 void Uninstall(const std::string &bundleName, const InstallParam &installParam); 58 /** 59 * @brief Uninstall a module using this installer object. 60 * @param bundleName Indicates the bundle name of the module to uninstall. 61 * @param modulePackage Indicates the module package of the module to uninstall. 62 * @param installParam Indicates the uninstall parameters. 63 * @return 64 */ 65 void Uninstall(const std::string &bundleName, const std::string &modulePackage, const InstallParam &installParam); 66 /** 67 * @brief Update the installer state and send status from the StatusReceiver object. 68 * @attention This function will send the install status to StatusReceiver. 69 * @param state Indicates the state to be updated to. 70 * @return 71 */ 72 virtual void UpdateInstallerState(const InstallerState state) override; 73 74 private: 75 /** 76 * @brief Send an event for requesting to remove this bundle installer object. 77 * @return 78 */ 79 void SendRemoveEvent() const; 80 81 private: 82 const int64_t installerId_ = 0; 83 const std::weak_ptr<EventHandler> handler_; 84 const sptr<IStatusReceiver> statusReceiver_; 85 86 DISALLOW_COPY_AND_MOVE(BundleInstaller); 87 }; 88 89 } // namespace AppExecFwk 90 } // namespace OHOS 91 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_H