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_MANAGER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_MANAGER_H 18 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 #include <unordered_map> 23 24 #include "nocopyable.h" 25 26 #include "bundle_installer.h" 27 #include "event_handler.h" 28 #include "status_receiver_interface.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class BundleInstallerManager : public EventHandler { 33 public: 34 using ThreadPoolTask = std::function<void()>; 35 36 explicit BundleInstallerManager(const std::shared_ptr<EventRunner> &runner); 37 virtual ~BundleInstallerManager() override; 38 /** 39 * @brief Process the event of destroy bundle installer object. 40 * @param event Indicates the event to be processed. 41 * @return 42 */ 43 virtual void ProcessEvent(const InnerEvent::Pointer &event) override; 44 /** 45 * @brief Create a bundle installer object for installing a bundle. 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 * @param statusReceiver Indicates the callback object that using for notifing the install result. 49 * @return 50 */ 51 void CreateInstallTask(const std::string &bundleFilePath, const InstallParam &installParam, 52 const sptr<IStatusReceiver> &statusReceiver); 53 /** 54 * @brief Create a bundle installer object for installing a bundle by bundleName. 55 * @param bundleName Indicates the bundleName. 56 * @param installParam Indicates the install parameters. 57 * @param statusReceiver Indicates the callback object that using for notifing the install result. 58 * @return 59 */ 60 void CreateInstallByBundleNameTask(const std::string &bundleName, const InstallParam &installParam, 61 const sptr<IStatusReceiver> &statusReceiver); 62 /** 63 * @brief Create a bundle installer object for installing a bundle by bundleName. 64 * @param bundleFilePath Indicates the path for storing the HAP of the bundle to install or update. 65 * @param installParam Indicates the install parameters. 66 * @param statusReceiver Indicates the callback object that using for notifing the install result. 67 * @return 68 */ 69 void CreateRecoverTask(const std::string &bundleName, const InstallParam &installParam, 70 const sptr<IStatusReceiver> &statusReceiver); 71 /** 72 * @brief Create a bundle installer object for installing multiple haps of a bundle. 73 * @param bundleFilePaths Indicates the paths for storing the HAPs of the bundle to install or update. 74 * @param installParam Indicates the install parameters. 75 * @param statusReceiver Indicates the callback object that using for notifing the install result. 76 * @return 77 */ 78 void CreateInstallTask(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 79 const sptr<IStatusReceiver> &statusReceiver); 80 /** 81 * @brief Create a bundle installer object for uninstalling an bundle. 82 * @param bundleName Indicates the bundle name of the application to uninstall. 83 * @param installParam Indicates the uninstall parameters. 84 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 85 * @return 86 */ 87 void CreateUninstallTask( 88 const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver); 89 /** 90 * @brief Create a bundle installer object for uninstalling a module. 91 * @param bundleName Indicates the bundle name of the module to uninstall. 92 * @param modulePackage Indicates the module package of the module to uninstall. 93 * @param installParam Indicates the uninstall parameters. 94 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 95 * @return 96 */ 97 void CreateUninstallTask(const std::string &bundleName, const std::string &modulePackage, 98 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver); 99 enum { 100 REMOVE_BUNDLE_INSTALLER = 1, 101 }; 102 103 private: 104 /** 105 * @brief Create a bundle installer object internal. 106 * @param statusReceiver Indicates the callback object for this installer. 107 * @return Returns a pointers to BundleInstaller object. 108 */ 109 std::shared_ptr<BundleInstaller> CreateInstaller(const sptr<IStatusReceiver> &statusReceiver); 110 /** 111 * @brief Remove an installer object with the installer ID. 112 * @param installerId Indicates the installer ID. 113 * @return 114 */ 115 void RemoveInstaller(const int64_t installerId); 116 117 void AddTask(const ThreadPoolTask &task); 118 119 private: 120 std::mutex mutex_; 121 // map key will use timestamp. 122 std::unordered_map<int64_t, std::shared_ptr<BundleInstaller>> installers_; 123 124 DISALLOW_COPY_AND_MOVE(BundleInstallerManager); 125 }; 126 } // namespace AppExecFwk 127 } // namespace OHOS 128 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_MANAGER_H 129