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 SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 17#define SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 18 19#include <functional> 20#include <mutex> 21#include <vector> 22 23#include "common_event_data.h" 24#include "common_event_manager.h" 25#include "common_event_subscribe_info.h" 26#include "common_event_subscriber.h" 27#include "common_event_support.h" 28#include "focus_monitor_manager.h" 29#include "input_window_info.h" 30#include "keyboard_event.h" 31#include "matching_skills.h" 32#include "system_ability_status_change_stub.h" 33 34namespace OHOS { 35namespace MiscServices { 36using Handler = std::function<void()>; 37class ImCommonEventManager : public RefBase { 38public: 39 ImCommonEventManager(); 40 ~ImCommonEventManager(); 41 static sptr<ImCommonEventManager> GetInstance(); 42 bool SubscribeEvent(); 43 bool SubscribeKeyboardEvent(KeyHandle handle); 44 bool SubscribeWindowManagerService(const Handler &handler); 45 bool SubscribeMemMgrService(const Handler &handler); 46 bool SubscribeAccountManagerService(Handler handle); 47 bool UnsubscribeEvent(); 48 // only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING 49 int32_t PublishPanelStatusChangeEvent(int32_t userId, const InputWindowStatus &status, const ImeWindowInfo &info); 50 class EventSubscriber : public EventFwk::CommonEventSubscriber { 51 public: 52 EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo); 53 void OnReceiveEvent(const EventFwk::CommonEventData &data); 54 void RemovePackage(const EventFwk::CommonEventData &data); 55 void StartUser(const EventFwk::CommonEventData &data); 56 void RemoveUser(const EventFwk::CommonEventData &data); 57 void StopUser(const EventFwk::CommonEventData &data); 58 void OnBundleScanFinished(const EventFwk::CommonEventData &data); 59 void AddPackage(const EventFwk::CommonEventData &data); 60 void ChangePackage(const EventFwk::CommonEventData &data); 61 void HandleBootCompleted(const EventFwk::CommonEventData &data); 62 63 private: 64 using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>; 65 std::map<std::string, EventListenerFunc> EventManagerFunc_; 66 void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data); 67 void HandleUserEvent(int32_t messageId, const EventFwk::CommonEventData &data); 68 }; 69 70private: 71 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 72 public: 73 explicit SystemAbilityStatusChangeListener(std::function<void()>); 74 ~SystemAbilityStatusChangeListener() = default; 75 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 76 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 77 78 private: 79 std::function<void()> func_ = nullptr; 80 }; 81 82private: 83 static std::mutex instanceLock_; 84 static sptr<ImCommonEventManager> instance_; 85}; 86} // namespace MiscServices 87} // namespace OHOS 88#endif // SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 89