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