• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class BundleInstallerManager : public EventHandler {
34 public:
35     explicit BundleInstallerManager(const std::shared_ptr<EventRunner> &runner);
36     virtual ~BundleInstallerManager() override;
37     /**
38      * @brief Process the event of destroy bundle installer object.
39      * @param event Indicates the event to be processed.
40      * @return
41      */
42     virtual void ProcessEvent(const InnerEvent::Pointer &event) override;
43     /**
44      * @brief Create a bundle installer object for installing a bundle.
45      * @param bundleFilePath Indicates the path for storing the HAP of the bundle to install or update.
46      * @param installParam Indicates the install parameters.
47      * @param statusReceiver Indicates the callback object that using for notifing the install result.
48      * @return
49      */
50     void CreateInstallTask(const std::string &bundleFilePath, const InstallParam &installParam,
51         const sptr<IStatusReceiver> &statusReceiver);
52     /**
53      * @brief Create a bundle installer object for installing a bundle by bundleName.
54      * @param bundleFilePath Indicates the path for storing the HAP of the bundle to install or update.
55      * @param installParam Indicates the install parameters.
56      * @param statusReceiver Indicates the callback object that using for notifing the install result.
57      * @return
58      */
59     void CreateRecoverTask(const std::string &bundleName, const InstallParam &installParam,
60         const sptr<IStatusReceiver> &statusReceiver);
61     /**
62      * @brief Create a bundle installer object for installing multiple haps of a bundle.
63      * @param bundleFilePaths Indicates the paths for storing the HAPs of the bundle to install or update.
64      * @param installParam Indicates the install parameters.
65      * @param statusReceiver Indicates the callback object that using for notifing the install result.
66      * @return
67      */
68     void CreateInstallTask(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
69         const sptr<IStatusReceiver> &statusReceiver);
70     /**
71      * @brief Create a bundle installer object for uninstalling an bundle.
72      * @param bundleName Indicates the bundle name of the application to uninstall.
73      * @param installParam Indicates the uninstall parameters.
74      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
75      * @return
76      */
77     void CreateUninstallTask(
78         const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver);
79     /**
80      * @brief Create a bundle installer object for uninstalling a module.
81      * @param bundleName Indicates the bundle name of the module to uninstall.
82      * @param modulePackage Indicates the module package of the module 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(const std::string &bundleName, const std::string &modulePackage,
88         const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver);
89     enum {
90         REMOVE_BUNDLE_INSTALLER = 1,
91     };
92 
93 private:
94     /**
95      * @brief Create a bundle installer object internal.
96      * @param statusReceiver Indicates the callback object for this installer.
97      * @return Returns a pointers to BundleInstaller object.
98      */
99     std::shared_ptr<BundleInstaller> CreateInstaller(const sptr<IStatusReceiver> &statusReceiver);
100     /**
101      * @brief Remove an installer object with the installer ID.
102      * @param installerId Indicates the installer ID.
103      * @return
104      */
105     void RemoveInstaller(const int64_t installerId);
106 
107 private:
108     const int MAX_TASK_NUMBER = 10;
109     const int THREAD_NUMBER = std::thread::hardware_concurrency();
110     // Thread pool used to start multipule installer in parallel.
111     ThreadPool installersPool_;
112     std::mutex mutex_;
113     // map key will use timestamp.
114     std::unordered_map<int64_t, std::shared_ptr<BundleInstaller>> installers_;
115 
116     DISALLOW_COPY_AND_MOVE(BundleInstallerManager);
117 };
118 }  // namespace AppExecFwk
119 }  // namespace OHOS
120 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_MANAGER_H
121