• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MGR_SERVICE_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_H
18 
19 #include <memory>
20 
21 #include "singleton.h"
22 #include "system_ability.h"
23 #include "thread_pool.h"
24 
25 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
26 #include "app_control_manager_host_impl.h"
27 #endif
28 #ifdef DEVICE_MANAGER_ENABLE
29 #include "bms_device_manager.h"
30 #endif
31 #include "bms_param.h"
32 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
33 #include "aging/bundle_aging_mgr.h"
34 #include "bundle_connect_ability_mgr.h"
35 #include "bundle_distributed_manager.h"
36 #endif
37 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
38 #include "default_app_host_impl.h"
39 #endif
40 #include "bundle_constants.h"
41 #include "bundle_data_mgr.h"
42 #include "bundle_installer_host.h"
43 #include "bundle_mgr_host_impl.h"
44 #include "bundle_mgr_service_event_handler.h"
45 #include "bundle_user_mgr_host_impl.h"
46 #include "hidump_helper.h"
47 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
48 #include "quick_fix_manager_host_impl.h"
49 #endif
50 
51 namespace OHOS {
52 namespace AppExecFwk {
53 class BundleMgrService : public SystemAbility {
54     DECLARE_DELAYED_SINGLETON(BundleMgrService);
55     DECLEAR_SYSTEM_ABILITY(BundleMgrService);
56 
57 public:
58     /**
59      * @brief Start the bundle manager service.
60      * @return
61      */
62     virtual void OnStart() override;
63     /**
64      * @brief Stop the bundle manager service.
65      * @return
66      */
67     virtual void OnStop() override;
68     /**
69      * @brief Check whether if the bundle manager service is ready.
70      * @return Returns true if the bundle manager service is ready; returns false otherwise.
71      */
72     bool IsServiceReady() const;
73 
74     const std::shared_ptr<BundleDataMgr> GetDataMgr() const;
75 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
76     const std::shared_ptr<BundleAgingMgr> GetAgingMgr() const;
77     /**
78      * @brief Get a util object for FA  Distribution center
79      * @return Returns the pointer of BundleConnectAbility object.
80      */
81     const std::shared_ptr<BundleConnectAbilityMgr> GetConnectAbility() const;
82 
83     const std::shared_ptr<BundleDistributedManager> GetBundleDistributedManager() const;
84 #endif
85     /**
86      * @brief Get a IBundleInstaller object for IPC
87      * @return Returns the pointer of IBundleInstaller object.
88      */
89     sptr<IBundleInstaller> GetBundleInstaller() const;
90     /**
91      * @brief Get a IBundleUserMgr object for IPC
92      * @return Returns the pointer of IBundleUserMgr object.
93      */
94     sptr<BundleUserMgrHostImpl> GetBundleUserMgr() const;
95 
96 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
97     sptr<IDefaultApp> GetDefaultAppProxy() const;
98 #endif
99 
100 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
101     sptr<IAppControlMgr> GetAppControlProxy() const;
102 #endif
103 
104 #ifdef DEVICE_MANAGER_ENABLE
105     const std::shared_ptr<BmsDeviceManager> GetDeviceManager() const;
106 #endif
107 
108 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
109     sptr<QuickFixManagerHostImpl> GetQuickFixManagerProxy() const;
110 #endif
111     /**
112      * @brief Check all user.
113      */
114     void CheckAllUser();
115     /**
116      * @brief register bms sa to samgr
117      */
118     void RegisterService();
119     /**
120      * @brief send bundle scan finished common event
121      */
122     void NotifyBundleScanStatus();
123     /**
124      * @brief Process hidump.
125      * @param args Indicates the args.
126      * @param result Indicates the result.
127      * @return Returns whether the interface is called successfully.
128      */
129     bool Hidump(const std::vector<std::string> &args, std::string& result) const;
130 
131     void RegisterDataMgr(std::shared_ptr<BundleDataMgr> dataMgrImpl);
132 
133     ThreadPool &GetThreadPool();
134 
135     const std::shared_ptr<BmsParam> GetBmsParam() const;
136 
137 protected:
138     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
139     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
140 
141 private:
142     bool Init();
143     void SelfClean();
144 
145     void InitThreadPool();
146     void InitBmsParam();
147     bool InitBundleMgrHost();
148     bool InitBundleInstaller();
149     void InitBundleDataMgr();
150     bool InitBundleUserMgr();
151     bool InitBundleEventHandler();
152     void InitDeviceManager();
153     void InitHidumpHelper();
154     void InitFreeInstall();
155     bool InitDefaultApp();
156     bool InitAppControl();
157     bool InitQuickFixManager();
158 
159 private:
160     bool ready_ = false;
161     bool registerToService_ = false;
162     bool notifyBundleScanStatus = false;
163     std::shared_ptr<EventRunner> runner_;
164     std::shared_ptr<BMSEventHandler> handler_;
165     std::shared_ptr<BundleDataMgr> dataMgr_;
166 #ifdef DEVICE_MANAGER_ENABLE
167     std::shared_ptr<BmsDeviceManager> deviceManager_;
168 #endif
169     std::shared_ptr<HidumpHelper> hidumpHelper_;
170 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
171     std::shared_ptr<BundleAgingMgr> agingMgr_;
172     std::shared_ptr<BundleConnectAbilityMgr> connectAbilityMgr_;
173     std::shared_ptr<BundleDistributedManager> bundleDistributedManager_;
174 #endif
175     sptr<BundleMgrHostImpl> host_;
176     sptr<BundleInstallerHost> installer_;
177     sptr<BundleUserMgrHostImpl> userMgrHost_;
178     std::shared_ptr<BmsParam> bmsParam_;
179     // Thread pool used to start installation or quick fix in parallel.
180     ThreadPool bmsThreadPool_ = ThreadPool(Constants::BMS_SERVICE_NAME);
181     const int THREAD_NUMBER = std::thread::hardware_concurrency();
182 
183 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
184     sptr<DefaultAppHostImpl> defaultAppHostImpl_;
185 #endif
186 
187 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
188     sptr<AppControlManagerHostImpl> appControlManagerHostImpl_;
189 #endif
190 
191 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
192     sptr<QuickFixManagerHostImpl> quickFixManagerHostImpl_;
193 #endif
194 
195 #define CHECK_INIT_RESULT(result, errmsg)                                         \
196     do {                                                                          \
197         if (!(result)) {                                                          \
198             APP_LOGE(errmsg);                                                     \
199             return result;                                                        \
200         }                                                                         \
201     } while (0)
202 
203     DISALLOW_COPY_AND_MOVE(BundleMgrService);
204 };
205 }  // namespace AppExecFwk
206 }  // namespace OHOS
207 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_H
208