• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "keyboard_event.h"
30 #include "matching_skills.h"
31 #include "system_ability_status_change_stub.h"
32 
33 namespace OHOS {
34 namespace MiscServices {
35 using Handler = std::function<void()>;
36 class ImCommonEventManager : public RefBase {
37 public:
38     ImCommonEventManager();
39     ~ImCommonEventManager();
40     static sptr<ImCommonEventManager> GetInstance();
41     bool SubscribeEvent(const std::string &event);
42     bool SubscribeKeyboardEvent(KeyHandle handle);
43     bool SubscribeWindowManagerService(FocusHandle handle, Handler inputHandler);
44     bool SubscribeAccountManagerService(Handler handle);
45 
46     bool UnsubscribeEvent();
47     class EventSubscriber : public EventFwk::CommonEventSubscriber {
48     public:
49         EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
50         void OnReceiveEvent(const EventFwk::CommonEventData &data);
51         void RemovePackage(const EventFwk::CommonEventData &data);
52         void StartUser(const EventFwk::CommonEventData &data);
53         void RemoveUser(const EventFwk::CommonEventData &data);
54 
55     private:
56         using EventListenerFunc = void (EventSubscriber::*)(const EventFwk::CommonEventData &data);
57         std::map<std::string, EventListenerFunc> EventManagerFunc_;
58     };
59 
60 private:
61     class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub {
62     public:
63         explicit SystemAbilityStatusChangeListener(std::function<void()>);
64         ~SystemAbilityStatusChangeListener() = default;
65         virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
66         virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
67 
68     private:
69         std::function<void()> func_ = nullptr;
70     };
71 
72 private:
73     static std::mutex instanceLock_;
74     static sptr<ImCommonEventManager> instance_;
75     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
76     sptr<ISystemAbilityStatusChange> keyboardEventListener_ = nullptr;
77     sptr<ISystemAbilityStatusChange> focusChangeEventListener_ = nullptr;
78 };
79 } // namespace MiscServices
80 } // namespace OHOS
81 #endif // SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H
82