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_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 "event_handler.h" 27 #include "status_receiver_interface.h" 28 29 namespace OHOS { 30 namespace AppExecFwk { 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 Install a bundle by bundleName. 53 * @param bundleName Indicates the bundleName of the bundle to install. 54 * @param installParam Indicates the install parameters. 55 * @return 56 */ 57 void Recover(const std::string &bundleName, const InstallParam &installParam); 58 /** 59 * @brief Install a bundle using this installer object. 60 * @param bundleFilePaths Indicates the paths for storing the HAP of the bundle to install or update. 61 * @param installParam Indicates the install parameters. 62 * @return 63 */ 64 void Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam); 65 /** 66 * @brief Uninstall a bundle using this installer object. 67 * @param bundleName Indicates the bundle name of the application to uninstall. 68 * @param installParam Indicates the uninstall parameters. 69 * @return 70 */ 71 void Uninstall(const std::string &bundleName, const InstallParam &installParam); 72 /** 73 * @brief Uninstall a module using this installer object. 74 * @param bundleName Indicates the bundle name of the module to uninstall. 75 * @param modulePackage Indicates the module package of the module to uninstall. 76 * @param installParam Indicates the uninstall parameters. 77 * @return 78 */ 79 void Uninstall(const std::string &bundleName, const std::string &modulePackage, const InstallParam &installParam); 80 /** 81 * @brief Update the installer state and send status from the StatusReceiver object. 82 * @attention This function will send the install status to StatusReceiver. 83 * @param state Indicates the state to be updated to. 84 * @return 85 */ 86 virtual void UpdateInstallerState(const InstallerState state) override; 87 88 private: 89 /** 90 * @brief Send an event for requesting to remove this bundle installer object. 91 * @return 92 */ 93 void SendRemoveEvent() const; 94 /** 95 * @brief Get all exist common userId. 96 * @attention This function will get all exist common userId. 97 * @return Returns all exist common userId 98 */ 99 std::set<int32_t> GetExistsCommonUserIs(); 100 101 private: 102 const int64_t installerId_ = 0; 103 const std::weak_ptr<EventHandler> handler_; 104 const sptr<IStatusReceiver> statusReceiver_; 105 106 DISALLOW_COPY_AND_MOVE(BundleInstaller); 107 }; 108 } // namespace AppExecFwk 109 } // namespace OHOS 110 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_H