• 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 #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 UnsubscribeEvent();
39     // only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING
40     int32_t PublishPanelStatusChangeEvent(int32_t userId, const InputWindowStatus &status, const ImeWindowInfo &info);
41     class EventSubscriber : public EventFwk::CommonEventSubscriber {
42     public:
43         EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
44         void OnReceiveEvent(const EventFwk::CommonEventData &data);
45         void RemovePackage(const EventFwk::CommonEventData &data);
46         void StartUser(const EventFwk::CommonEventData &data);
47         void RemoveUser(const EventFwk::CommonEventData &data);
48         void StopUser(const EventFwk::CommonEventData &data);
49         void OnBundleScanFinished(const EventFwk::CommonEventData &data);
50         void OnDataShareReady(const EventFwk::CommonEventData &data);
51         void AddPackage(const EventFwk::CommonEventData &data);
52         void ChangePackage(const EventFwk::CommonEventData &data);
53         void HandleBootCompleted(const EventFwk::CommonEventData &data);
54         void OnUserUnlocked(const EventFwk::CommonEventData &data);
55 
56     private:
57         using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>;
58         std::map<std::string, EventListenerFunc> EventManagerFunc_;
59         void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data);
60         void HandleUserEvent(int32_t messageId, const EventFwk::CommonEventData &data);
61     };
62 
63 private:
64     bool SubscribeManagerServiceCommon(const Handler &handler, int32_t saId);
65     class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub {
66     public:
67         explicit SystemAbilityStatusChangeListener(std::function<void()>);
68         ~SystemAbilityStatusChangeListener() = default;
69         virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
70         virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
71 
72     private:
73         std::function<void()> func_ = nullptr;
74     };
75 
76 private:
77     static std::mutex instanceLock_;
78     static sptr<ImCommonEventManager> instance_;
79 };
80 } // namespace MiscServices
81 } // namespace OHOS
82 #endif // SERVICES_INCLUDE_IM_COMMON_EVENT_MANAGER_H
83