1 /* 2 * Copyright (c) 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 OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_MGR_SERVICE_H 17 #define OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_MGR_SERVICE_H 18 19 #include "event_runner.h" 20 #include "event_handler.h" 21 #include "service_info.h" 22 #include "service_router_mgr_stub.h" 23 #include "singleton.h" 24 #include "sr_common_event_subscriber.h" 25 #include "system_ability.h" 26 #include "want.h" 27 28 namespace OHOS { 29 namespace AbilityRuntime { 30 using namespace OHOS::AppExecFwk; 31 32 /** 33 * @class ServiceRouterMgrService 34 * ServiceRouterMgrService provides a facility for managing ability life cycle. 35 */ 36 class ServiceRouterMgrService : public SystemAbility, public ServiceRouterMgrStub { 37 DECLARE_DELAYED_SINGLETON(ServiceRouterMgrService) 38 DECLEAR_SYSTEM_ABILITY(ServiceRouterMgrService) 39 public: 40 /** 41 * @brief Start the service router manager service. 42 * @return 43 */ 44 virtual void OnStart() override; 45 /** 46 * @brief Stop the service router service. 47 * @return 48 */ 49 virtual void OnStop() override; 50 51 /** 52 * @brief Check whether if the service router service is ready. 53 * @return Returns true if the service router service is ready; returns false otherwise. 54 */ 55 bool IsServiceReady() const; 56 57 /** 58 * @brief Query the business ability info of list by the given filter. 59 * @param filter Indicates the filter containing the business ability info to be queried. 60 * @param businessAbilityInfos Indicates the obtained business ability info objects 61 * @return Returns ERR_OK on success, others on failure. 62 */ 63 virtual int32_t QueryBusinessAbilityInfos(const BusinessAbilityFilter &filter, 64 std::vector<BusinessAbilityInfo> &businessAbilityInfos) override; 65 66 /** 67 * @brief Query the PurposeInfo of list by the given Want. 68 * @param want Indicates the information of the want. 69 * @param purposeName Indicates the purposeName. 70 * @param purposeInfos Indicates the obtained PurposeInfos object. 71 * @return Returns ERR_OK on success, others on failure. 72 */ 73 virtual int32_t QueryPurposeInfos(const Want &want, const std::string purposeName, 74 std::vector<PurposeInfo> &purposeInfos) override; 75 76 /** 77 * Start ui extension ability with extension session info, send extension session info to ability manager service. 78 * 79 * @param sessionInfo the extension session info of the ability to start. 80 * @param userId, Designation User ID. 81 * @return Returns ERR_OK on success, others on failure. 82 */ 83 virtual int32_t StartUIExtensionAbility(const sptr<SessionInfo> &sessionInfo, 84 int32_t userId = DEFAULT_INVAL_VALUE) override; 85 86 /** 87 * Connect ui extension ability with want, connect session with service ability. 88 * 89 * @param want, Special want for service type's ability. 90 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 91 * @param sessionInfo the extension session info of the ability to start. 92 * @param userId, Designation User ID. 93 * @return Returns ERR_OK on success, others on failure. 94 */ 95 virtual int32_t ConnectUIExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect, 96 const sptr<SessionInfo> &sessionInfo, int32_t userId = DEFAULT_INVAL_VALUE) override; 97 98 private: 99 void Init(); 100 bool InitEventRunnerAndHandler(); 101 bool LoadAllBundleInfos(); 102 bool SubscribeCommonEvent(); 103 bool SubscribeBundleEvent(); 104 void DelayUnloadTask(); 105 106 std::shared_ptr<EventRunner> runner_ = nullptr; 107 std::shared_ptr<EventHandler> handler_ = nullptr; 108 std::mutex bundleMgrMutex_; 109 std::mutex mutex_; 110 std::shared_ptr<SrCommonEventSubscriber> eventSubscriber_ = nullptr; 111 std::mutex delayTaskMutex_; 112 }; 113 } // namespace AbilityRuntime 114 } // namespace OHOS 115 #endif // OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_MGR_SERVICE_H 116