1 /* 2 * Copyright (c) 2021 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_data_mgr.h" 25 #include "bundle_installer_host.h" 26 #include "bundle_mgr_host_impl.h" 27 #include "bundle_mgr_service_event_handler.h" 28 #include "bundle_permissions_changed_monitor.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 33 class BundleMgrService : public SystemAbility { 34 DECLARE_DELAYED_SINGLETON(BundleMgrService); 35 DECLEAR_SYSTEM_ABILITY(BundleMgrService); 36 37 public: 38 /** 39 * @brief Start the bundle manager service. 40 * @return 41 */ 42 virtual void OnStart() override; 43 /** 44 * @brief Stop the bundle manager service. 45 * @return 46 */ 47 virtual void OnStop() override; 48 /** 49 * @brief Check whether if the bundle manager service is ready. 50 * @return Returns true if the bundle manager service is ready; returns false otherwise. 51 */ 52 bool IsServiceReady() const; 53 /** 54 * @brief Get a shared pointer to the BundleDataMgr object. 55 * @return Returns the pointer of BundleDataMgr object. 56 */ 57 const std::shared_ptr<BundleDataMgr> GetDataMgr() const; 58 /** 59 * @brief Get a IBundleInstaller object for IPC 60 * @return Returns the pointer of IBundleInstaller object. 61 */ 62 sptr<IBundleInstaller> GetBundleInstaller() const; 63 64 private: 65 /** 66 * @brief Initialize the bundle manager service context. 67 * @return Returns true if initialized successfully; returns false otherwise. 68 */ 69 bool Init(); 70 /** 71 * @brief Clean the context of this bundle manager service. 72 * @return 73 */ 74 void SelfClean(); 75 76 private: 77 bool ready_ = false; 78 bool registerToService_ = false; 79 bool needToScan_ = false; 80 std::shared_ptr<EventRunner> runner_; 81 std::shared_ptr<BMSEventHandler> handler_; 82 std::shared_ptr<BundleDataMgr> dataMgr_; 83 sptr<BundleMgrHostImpl> host_; 84 sptr<BundleInstallerHost> installer_; 85 std::shared_ptr<BundlePermissionsChangedMonitor> perChangeSub_; 86 87 DISALLOW_COPY_AND_MOVE(BundleMgrService); 88 }; 89 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_H 93