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 34 namespace OHOS { 35 namespace MiscServices { 36 using Handler = std::function<void()>; 37 class ImCommonEventManager : public RefBase { 38 public: 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 OnDataShareReady(const EventFwk::CommonEventData &data); 60 void AddPackage(const EventFwk::CommonEventData &data); 61 void ChangePackage(const EventFwk::CommonEventData &data); 62 void HandleBootCompleted(const EventFwk::CommonEventData &data); 63 void OnUserUnlocked(const EventFwk::CommonEventData &data); 64 65 private: 66 using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>; 67 std::map<std::string, EventListenerFunc> EventManagerFunc_; 68 void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data); 69 void HandleUserEvent(int32_t messageId, const EventFwk::CommonEventData &data); 70 }; 71 72 private: 73 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 74 public: 75 explicit SystemAbilityStatusChangeListener(std::function<void()>); 76 ~SystemAbilityStatusChangeListener() = default; 77 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 78 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 79 80 private: 81 std::function<void()> func_ = nullptr; 82 }; 83 84 private: 85 static std::mutex instanceLock_; 86 static sptr<ImCommonEventManager> instance_; 87 }; 88 } // namespace MiscServices 89 } // namespace OHOS 90 #endif // SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H 91