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 24 #include "bundle_clone_mgr.h" 25 #include "bundle_constants.h" 26 #include "bundle_data_mgr.h" 27 #include "bundle_installer_host.h" 28 #include "bundle_mgr_host_impl.h" 29 #include "bundle_mgr_service_event_handler.h" 30 #include "bundle_permissions_changed_monitor.h" 31 #include "bundle_user_mgr_host_impl.h" 32 #include "bms_device_manager.h" 33 34 namespace OHOS { 35 namespace AppExecFwk { 36 class BundleMgrService : public SystemAbility { 37 DECLARE_DELAYED_SINGLETON(BundleMgrService); 38 DECLEAR_SYSTEM_ABILITY(BundleMgrService); 39 40 public: 41 /** 42 * @brief Start the bundle manager service. 43 * @return 44 */ 45 virtual void OnStart() override; 46 /** 47 * @brief Stop the bundle manager service. 48 * @return 49 */ 50 virtual void OnStop() override; 51 /** 52 * @brief Check whether if the bundle manager service is ready. 53 * @return Returns true if the bundle manager service is ready; returns false otherwise. 54 */ 55 bool IsServiceReady() const; 56 /** 57 * @brief Get a shared pointer to the BundleDataMgr object. 58 * @return Returns the pointer of BundleDataMgr object. 59 */ 60 const std::shared_ptr<BundleCloneMgr> GetCloneMgr() const; 61 62 const std::shared_ptr<BundleDataMgr> GetDataMgr() const; 63 /** 64 * @brief Get a IBundleInstaller object for IPC 65 * @return Returns the pointer of IBundleInstaller object. 66 */ 67 sptr<IBundleInstaller> GetBundleInstaller() const; 68 /** 69 * @brief Get a IBundleUserMgr object for IPC 70 * @return Returns the pointer of IBundleUserMgr object. 71 */ 72 sptr<BundleUserMgrHostImpl> GetBundleUserMgr() const; 73 /** 74 * @brief Check all user. 75 */ 76 void CheckAllUser(); 77 /** 78 * @brief register bms sa to samgr 79 */ 80 void RegisterService(); 81 protected: 82 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 83 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 84 private: 85 /** 86 * @brief Initialize the bundle manager service context. 87 * @return Returns true if initialized successfully; returns false otherwise. 88 */ 89 bool Init(); 90 /** 91 * @brief Clean the context of this bundle manager service. 92 * @return 93 */ 94 void SelfClean(); 95 /** 96 * @brief Do some work after register to service. 97 * @return 98 */ 99 void AfterRegisterToService(); 100 101 private: 102 bool ready_ = false; 103 bool registerToService_ = false; 104 bool needToScan_ = false; 105 std::shared_ptr<EventRunner> runner_; 106 std::shared_ptr<BMSEventHandler> handler_; 107 std::shared_ptr<BundleDataMgr> dataMgr_; 108 std::shared_ptr<BundleCloneMgr> cloneMgr_; 109 std::shared_ptr<BmsDeviceManager> deviceManager_; 110 sptr<BundleMgrHostImpl> host_; 111 sptr<BundleInstallerHost> installer_; 112 sptr<BundleUserMgrHostImpl> userMgrHost_; 113 std::shared_ptr<BundlePermissionsChangedMonitor> perChangeSub_; 114 115 DISALLOW_COPY_AND_MOVE(BundleMgrService); 116 }; 117 } // namespace AppExecFwk 118 } // namespace OHOS 119 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_H 120