122736c2fSopenharmony_ci/* 222736c2fSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 422736c2fSopenharmony_ci * you may not use this file except in compliance with the License. 522736c2fSopenharmony_ci * You may obtain a copy of the License at 622736c2fSopenharmony_ci * 722736c2fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 822736c2fSopenharmony_ci * 922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and 1322736c2fSopenharmony_ci * limitations under the License. 1422736c2fSopenharmony_ci */ 1522736c2fSopenharmony_ci 1622736c2fSopenharmony_ci#ifndef SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 1722736c2fSopenharmony_ci#define SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 1822736c2fSopenharmony_ci 1922736c2fSopenharmony_ci#include <functional> 2022736c2fSopenharmony_ci#include <mutex> 2122736c2fSopenharmony_ci#include <vector> 2222736c2fSopenharmony_ci 2322736c2fSopenharmony_ci#include "common_event_data.h" 2422736c2fSopenharmony_ci#include "common_event_manager.h" 2522736c2fSopenharmony_ci#include "common_event_subscribe_info.h" 2622736c2fSopenharmony_ci#include "common_event_subscriber.h" 2722736c2fSopenharmony_ci#include "common_event_support.h" 2822736c2fSopenharmony_ci#include "focus_monitor_manager.h" 2922736c2fSopenharmony_ci#include "input_window_info.h" 3022736c2fSopenharmony_ci#include "keyboard_event.h" 3122736c2fSopenharmony_ci#include "matching_skills.h" 3222736c2fSopenharmony_ci#include "system_ability_status_change_stub.h" 3322736c2fSopenharmony_ci 3422736c2fSopenharmony_cinamespace OHOS { 3522736c2fSopenharmony_cinamespace MiscServices { 3622736c2fSopenharmony_ciusing Handler = std::function<void()>; 3722736c2fSopenharmony_ciclass ImCommonEventManager : public RefBase { 3822736c2fSopenharmony_cipublic: 3922736c2fSopenharmony_ci ImCommonEventManager(); 4022736c2fSopenharmony_ci ~ImCommonEventManager(); 4122736c2fSopenharmony_ci static sptr<ImCommonEventManager> GetInstance(); 4222736c2fSopenharmony_ci bool SubscribeEvent(); 4322736c2fSopenharmony_ci bool SubscribeKeyboardEvent(KeyHandle handle); 4422736c2fSopenharmony_ci bool SubscribeWindowManagerService(const Handler &handler); 4522736c2fSopenharmony_ci bool SubscribeMemMgrService(const Handler &handler); 4622736c2fSopenharmony_ci bool SubscribeAccountManagerService(Handler handle); 4722736c2fSopenharmony_ci bool UnsubscribeEvent(); 4822736c2fSopenharmony_ci // only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING 4922736c2fSopenharmony_ci int32_t PublishPanelStatusChangeEvent(int32_t userId, const InputWindowStatus &status, const ImeWindowInfo &info); 5022736c2fSopenharmony_ci class EventSubscriber : public EventFwk::CommonEventSubscriber { 5122736c2fSopenharmony_ci public: 5222736c2fSopenharmony_ci EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo); 5322736c2fSopenharmony_ci void OnReceiveEvent(const EventFwk::CommonEventData &data); 5422736c2fSopenharmony_ci void RemovePackage(const EventFwk::CommonEventData &data); 5522736c2fSopenharmony_ci void StartUser(const EventFwk::CommonEventData &data); 5622736c2fSopenharmony_ci void RemoveUser(const EventFwk::CommonEventData &data); 5722736c2fSopenharmony_ci void StopUser(const EventFwk::CommonEventData &data); 5822736c2fSopenharmony_ci void OnBundleScanFinished(const EventFwk::CommonEventData &data); 5922736c2fSopenharmony_ci void AddPackage(const EventFwk::CommonEventData &data); 6022736c2fSopenharmony_ci void ChangePackage(const EventFwk::CommonEventData &data); 6122736c2fSopenharmony_ci void HandleBootCompleted(const EventFwk::CommonEventData &data); 6222736c2fSopenharmony_ci 6322736c2fSopenharmony_ci private: 6422736c2fSopenharmony_ci using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>; 6522736c2fSopenharmony_ci std::map<std::string, EventListenerFunc> EventManagerFunc_; 6622736c2fSopenharmony_ci void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data); 6722736c2fSopenharmony_ci void HandleUserEvent(int32_t messageId, const EventFwk::CommonEventData &data); 6822736c2fSopenharmony_ci }; 6922736c2fSopenharmony_ci 7022736c2fSopenharmony_ciprivate: 7122736c2fSopenharmony_ci class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 7222736c2fSopenharmony_ci public: 7322736c2fSopenharmony_ci explicit SystemAbilityStatusChangeListener(std::function<void()>); 7422736c2fSopenharmony_ci ~SystemAbilityStatusChangeListener() = default; 7522736c2fSopenharmony_ci virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 7622736c2fSopenharmony_ci virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 7722736c2fSopenharmony_ci 7822736c2fSopenharmony_ci private: 7922736c2fSopenharmony_ci std::function<void()> func_ = nullptr; 8022736c2fSopenharmony_ci }; 8122736c2fSopenharmony_ci 8222736c2fSopenharmony_ciprivate: 8322736c2fSopenharmony_ci static std::mutex instanceLock_; 8422736c2fSopenharmony_ci static sptr<ImCommonEventManager> instance_; 8522736c2fSopenharmony_ci}; 8622736c2fSopenharmony_ci} // namespace MiscServices 8722736c2fSopenharmony_ci} // namespace OHOS 8822736c2fSopenharmony_ci#endif // SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 89