• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 <atomic>
20 #include <memory>
21 
22 #include "singleton.h"
23 #include "system_ability.h"
24 
25 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
26 #include "app_control_manager_host_impl.h"
27 #endif
28 #include "bms_param.h"
29 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
30 #include "aging/bundle_aging_mgr.h"
31 #include "bundle_connect_ability_mgr.h"
32 #include "bundle_distributed_manager.h"
33 #endif
34 #include "bundle_constants.h"
35 #include "bundle_data_mgr.h"
36 #include "bundle_installer_host.h"
37 #include "bundle_mgr_ext_host_impl.h"
38 #include "bundle_mgr_host_impl.h"
39 #include "bundle_mgr_service_event_handler.h"
40 #include "bundle_user_mgr_host_impl.h"
41 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
42 #include "default_app_host_impl.h"
43 #endif
44 #include "extend_resource_manager_host_impl.h"
45 #include "ffrt.h"
46 #include "hidump_helper.h"
47 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
48 #include "quick_fix_manager_host_impl.h"
49 #endif
50 #include "pre_install_exception_mgr.h"
51 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
52 #include "bundle_overlay_manager_host_impl.h"
53 #endif
54 #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE
55 #include "bundle_resource_host_impl.h"
56 #endif
57 #include "verify_manager_host_impl.h"
58 namespace OHOS {
59 namespace AppExecFwk {
60 class BundleMgrService : public SystemAbility {
61     DECLARE_DELAYED_SINGLETON(BundleMgrService);
62     DECLEAR_SYSTEM_ABILITY(BundleMgrService);
63 
64 public:
65     /**
66      * @brief Start the bundle manager service.
67      * @return
68      */
69     virtual void OnStart() override;
70     /**
71      * @brief Stop the bundle manager service.
72      * @return
73      */
74     virtual void OnStop() override;
75     /**
76      * @brief Implement action when device level changed.
77      * @return
78      */
79     virtual void OnDeviceLevelChanged(int32_t type, int32_t level, std::string& action) override;
80     /**
81      * @brief Check whether if the bundle manager service is ready.
82      * @return Returns true if the bundle manager service is ready; returns false otherwise.
83      */
84     bool IsServiceReady() const;
85 
86     const std::shared_ptr<BundleDataMgr> GetDataMgr() const;
87 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
88     const std::shared_ptr<BundleAgingMgr> GetAgingMgr() const;
89     /**
90      * @brief Get a util object for FA  Distribution center
91      * @return Returns the pointer of BundleConnectAbility object.
92      */
93     const std::shared_ptr<BundleConnectAbilityMgr> GetConnectAbility(int32_t userId = Constants::UNSPECIFIED_USERID);
94 
95     const std::shared_ptr<BundleDistributedManager> GetBundleDistributedManager() const;
96 #endif
97     /**
98      * @brief Get a IBundleInstaller object for IPC
99      * @return Returns the pointer of IBundleInstaller object.
100      */
101     sptr<BundleInstallerHost> GetBundleInstaller() const;
102     /**
103      * @brief Get a IBundleUserMgr object for IPC
104      * @return Returns the pointer of IBundleUserMgr object.
105      */
106     sptr<BundleUserMgrHostImpl> GetBundleUserMgr() const;
107     /**
108      * @brief Get a IVerifyManager object for IPC
109      * @return Returns the pointer of IVerifyManager object.
110      */
111     sptr<IVerifyManager> GetVerifyManager() const;
112 
113     sptr<IExtendResourceManager> GetExtendResourceManager() const;
114 
115 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
116     sptr<IDefaultApp> GetDefaultAppProxy() const;
117 #endif
118 
119 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
120     sptr<IAppControlMgr> GetAppControlProxy() const;
121 #endif
122 
123     sptr<IBundleMgrExt> GetBundleMgrExtProxy() const;
124 
125 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
126     sptr<QuickFixManagerHostImpl> GetQuickFixManagerProxy() const;
127 #endif
128 #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE
129     sptr<IBundleResource> GetBundleResourceProxy() const;
130 #endif
131     /**
132      * @brief Check all user.
133      */
134     void CheckAllUser();
135     /**
136      * @brief register bms sa to samgr
137      */
138     void RegisterService();
139     /**
140      * @brief send bundle scan finished common event
141      */
142     void NotifyBundleScanStatus();
143     /**
144      * @brief Process hidump.
145      * @param args Indicates the args.
146      * @param result Indicates the result.
147      * @return Returns whether the interface is called successfully.
148      */
149     bool Hidump(const std::vector<std::string> &args, std::string& result) const;
150 
151     void RegisterDataMgr(std::shared_ptr<BundleDataMgr> dataMgrImpl);
152 
153     const std::shared_ptr<BmsParam> GetBmsParam() const;
154 
155     const std::shared_ptr<PreInstallExceptionMgr> GetPreInstallExceptionMgr() const;
156 
157 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
158     sptr<IOverlayManager> GetOverlayManagerProxy() const;
159 #endif
160 
161     bool IsBrokerServiceStarted() const;
162 
163     int32_t OnExtension(const std::string& extension, MessageParcel& data, MessageParcel& reply) override;
164 
165 protected:
166     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
167 
168 private:
169     bool Init();
170     void SelfClean();
171 
172     void InitBmsParam();
173     void InitPreInstallExceptionMgr();
174     bool InitBundleMgrHost();
175     bool InitBundleInstaller();
176     void InitBundleDataMgr();
177     bool InitBundleUserMgr();
178     bool InitVerifyManager();
179     bool InitExtendResourceManager();
180     bool InitBundleEventHandler();
181     void InitHidumpHelper();
182     void InitFreeInstall();
183     bool InitDefaultApp();
184     bool InitAppControl();
185     bool InitBundleMgrExt();
186     bool InitQuickFixManager();
187     bool InitOverlayManager();
188     void CreateBmsServiceDir();
189     bool InitBundleResourceMgr();
190 
191 private:
192     bool ready_ = false;
193     bool registerToService_ = false;
194     bool notifyBundleScanStatus = false;
195     std::atomic<bool> isBrokerServiceStarted_ = false;
196     std::shared_ptr<BMSEventHandler> handler_;
197     std::shared_ptr<BundleDataMgr> dataMgr_;
198     std::shared_ptr<HidumpHelper> hidumpHelper_;
199 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
200     mutable ffrt::mutex bundleConnectMutex_;
201     std::shared_ptr<BundleAgingMgr> agingMgr_;
202     std::shared_ptr<BundleDistributedManager> bundleDistributedManager_;
203     // key is userId
204     std::map<int32_t, std::shared_ptr<BundleConnectAbilityMgr>> connectAbilityMgr_;
205 #endif
206     sptr<BundleMgrHostImpl> host_;
207     sptr<BundleInstallerHost> installer_;
208     sptr<BundleUserMgrHostImpl> userMgrHost_;
209     sptr<IVerifyManager> verifyManager_;
210     sptr<IExtendResourceManager> extendResourceManager_;
211     std::shared_ptr<BmsParam> bmsParam_;
212     std::shared_ptr<PreInstallExceptionMgr> preInstallExceptionMgr_;
213 
214 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
215     sptr<DefaultAppHostImpl> defaultAppHostImpl_;
216 #endif
217 
218 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
219     sptr<AppControlManagerHostImpl> appControlManagerHostImpl_;
220 #endif
221 
222     sptr<BundleMgrExtHostImpl> bundleMgrExtHostImpl_;
223 
224 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
225     sptr<QuickFixManagerHostImpl> quickFixManagerHostImpl_;
226 #endif
227 
228 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
229     sptr<OverlayManagerHostImpl>  overlayManagerHostImpl_;
230 #endif
231 
232 #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE
233     sptr<BundleResourceHostImpl> bundleResourceHostImpl_;
234 #endif
235 
236 #define CHECK_INIT_RESULT(result, errmsg)                                         \
237     do {                                                                          \
238         if (!(result)) {                                                          \
239             APP_LOGE(errmsg);                                                     \
240             return result;                                                        \
241         }                                                                         \
242     } while (0)
243 
244     DISALLOW_COPY_AND_MOVE(BundleMgrService);
245 };
246 }  // namespace AppExecFwk
247 }  // namespace OHOS
248 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_H
249