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