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