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 #include "thread_pool.h" 26 27 #include "bundle_installer.h" 28 #include "event_handler.h" 29 #include "status_receiver_interface.h" 30 31 namespace OHOS { 32 namespace AppExecFwk { 33 34 class BundleInstallerManager : public EventHandler { 35 public: 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 uninstalling an bundle. 55 * @param bundleName Indicates the bundle name of the application to uninstall. 56 * @param installParam Indicates the uninstall parameters. 57 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 58 * @return 59 */ 60 void CreateUninstallTask( 61 const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver); 62 /** 63 * @brief Create a bundle installer object for uninstalling a module. 64 * @param bundleName Indicates the bundle name of the module to uninstall. 65 * @param modulePackage Indicates the module package of the module to uninstall. 66 * @param installParam Indicates the uninstall parameters. 67 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 68 * @return 69 */ 70 void CreateUninstallTask(const std::string &bundleName, const std::string &modulePackage, 71 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver); 72 enum { 73 REMOVE_BUNDLE_INSTALLER = 1, 74 }; 75 76 private: 77 /** 78 * @brief Create a bundle installer object internal. 79 * @param statusReceiver Indicates the callback object for this installer. 80 * @return Returns a pointers to BundleInstaller object. 81 */ 82 std::shared_ptr<BundleInstaller> CreateInstaller(const sptr<IStatusReceiver> &statusReceiver); 83 /** 84 * @brief Remove an installer object with the installer ID. 85 * @param installerId Indicates the installer ID. 86 * @return 87 */ 88 void RemoveInstaller(const int64_t installerId); 89 90 private: 91 const int MAX_TASK_NUMBER = 10; 92 const int THREAD_NUMBER = std::thread::hardware_concurrency(); 93 // Thread pool used to start multipule installer in parallel. 94 ThreadPool installersPool_; 95 std::mutex mutex_; 96 // map key will use timestamp. 97 std::unordered_map<int64_t, std::shared_ptr<BundleInstaller>> installers_; 98 99 DISALLOW_COPY_AND_MOVE(BundleInstallerManager); 100 }; 101 102 } // namespace AppExecFwk 103 } // namespace OHOS 104 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_MANAGER_H 105