• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "multimodal_event_handler.h"
17 #include "input_manager_impl.h"
18 #include "immi_token.h"
19 #include "input_event.h"
20 #include "input_handler_manager.h"
21 #include "mmi_client.h"
22 #include "proto.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MultimodalEventHandler"};
28 }
OnConnected(const OHOS::MMI::IfMMIClient & client)29 void OnConnected(const OHOS::MMI::IfMMIClient& client)
30 {
31     InputManagerImpl::GetInstance()->OnConnected();
32     KeyEventInputSubscribeMgr.OnConnected();
33     InputHandlerManager::GetInstance().OnConnected();
34 }
35 
InjectEvent(const std::shared_ptr<OHOS::MMI::KeyEvent> keyEventPtr)36 int32_t MultimodalEventHandler::InjectEvent(const std::shared_ptr<OHOS::MMI::KeyEvent> keyEventPtr)
37 {
38     CHKPR(keyEventPtr, ERROR_NULL_POINTER);
39     if (!InitClient()) {
40         return MMI_SERVICE_INVALID;
41     }
42     return EventManager.InjectEvent(keyEventPtr);
43 }
44 
GetMultimodeInputInfo()45 int32_t MultimodalEventHandler::GetMultimodeInputInfo()
46 {
47     if (!InitClient()) {
48         return MMI_SERVICE_INVALID;
49     }
50     return MMI_SERVICE_RUNNING;
51 }
52 
InitClient()53 bool MultimodalEventHandler::InitClient()
54 {
55     MMI_LOGD("enter");
56     if (client_ != nullptr) {
57         return true;
58     }
59     client_ = std::make_shared<MMIClient>();
60     CHKPF(client_);
61     cMsgHandler_ = std::make_shared<ClientMsgHandler>();
62     CHKPF(cMsgHandler_);
63     EventManager.SetClientHandle(client_);
64     client_->RegisterConnectedFunction(&OnConnected);
65     if (!(client_->Start(cMsgHandler_, true))) {
66         MMI_LOGE("The client fails to start");
67         return false;
68     }
69     MMI_LOGD("leave");
70     return true;
71 }
72 
GetMMIClient()73 MMIClientPtr MultimodalEventHandler::GetMMIClient()
74 {
75     if (InitClient()) {
76         return client_;
77     }
78     return nullptr;
79 }
80 
GetDeviceIds(int32_t taskId)81 int32_t MultimodalEventHandler::GetDeviceIds(int32_t taskId)
82 {
83     if (!InitClient()) {
84         return MMI_SERVICE_INVALID;
85     }
86     return EventManager.GetDeviceIds(taskId);
87 }
88 
GetDevice(int32_t taskId,int32_t deviceId)89 int32_t MultimodalEventHandler::GetDevice(int32_t taskId, int32_t deviceId)
90 {
91     if (!InitClient()) {
92         return MMI_SERVICE_INVALID;
93     }
94     return EventManager.GetDevice(taskId, deviceId);
95 }
96 
InjectPointerEvent(std::shared_ptr<PointerEvent> pointerEvent)97 int32_t MultimodalEventHandler::InjectPointerEvent(std::shared_ptr<PointerEvent> pointerEvent)
98 {
99     CHKPR(pointerEvent, ERROR_NULL_POINTER);
100     if (!InitClient()) {
101         return MMI_SERVICE_INVALID;
102     }
103     return EventManager.InjectPointerEvent(pointerEvent);
104 }
105 
AddInterceptor(int32_t sourceType,int32_t id)106 int32_t MultimodalEventHandler::AddInterceptor(int32_t sourceType, int32_t id)
107 {
108     if (!InitClient()) {
109         return MMI_SERVICE_INVALID;
110     }
111 
112     OHOS::MMI::NetPacket pkt(MmiMessageId::ADD_EVENT_INTERCEPTOR);
113     pkt << sourceType << id;
114     client_->SendMessage(pkt);
115     MMI_LOGD("client add a touchpad event interceptor");
116     return RET_OK;
117 }
118 
119 
RemoveInterceptor(int32_t id)120 int32_t MultimodalEventHandler::RemoveInterceptor(int32_t id)
121 {
122     if (!InitClient()) {
123         return MMI_SERVICE_INVALID;
124     }
125 
126     OHOS::MMI::NetPacket pkt(MmiMessageId::REMOVE_EVENT_INTERCEPTOR);
127     pkt << id;
128     client_->SendMessage(pkt);
129     MMI_LOGD("client remove a touchpad event interceptor");
130     return RET_OK;
131 }
132 
AddInputEventMontior(int32_t keyEventType)133 int32_t MultimodalEventHandler::AddInputEventMontior(int32_t keyEventType)
134 {
135     MMI_LOGD("enter");
136     if (!InitClient()) {
137         return MMI_SERVICE_INVALID;
138     }
139     NetPacket pkt(MmiMessageId::ADD_INPUT_EVENT_MONITOR);
140     pkt << keyEventType;
141     client_->SendMessage(pkt);
142     return RET_OK;
143 }
144 
RemoveInputEventMontior(int32_t keyEventType)145 void MultimodalEventHandler::RemoveInputEventMontior(int32_t keyEventType)
146 {
147     MMI_LOGD("enter");
148     if (!InitClient()) {
149         return;
150     }
151     NetPacket pkt(MmiMessageId::REMOVE_INPUT_EVENT_MONITOR);
152     pkt << keyEventType;
153     client_->SendMessage(pkt);
154 }
155 
RemoveInputEventTouchpadMontior(int32_t pointerEventType)156 void MultimodalEventHandler::RemoveInputEventTouchpadMontior(int32_t pointerEventType)
157 {
158     MMI_LOGD("enter");
159     if (!InitClient()) {
160         return;
161     }
162     NetPacket pkt(MmiMessageId::REMOVE_INPUT_EVENT_TOUCHPAD_MONITOR);
163     pkt << OHOS::MMI::InputEvent::EVENT_TYPE_POINTER;
164     client_->SendMessage(pkt);
165 }
166 
AddInputEventTouchpadMontior(int32_t pointerEventType)167 int32_t MultimodalEventHandler::AddInputEventTouchpadMontior(int32_t pointerEventType)
168 {
169     MMI_LOGD("enter");
170     if (!InitClient()) {
171         return MMI_SERVICE_INVALID;
172     }
173     NetPacket pkt(MmiMessageId::ADD_INPUT_EVENT_TOUCHPAD_MONITOR);
174     pkt << OHOS::MMI::InputEvent::EVENT_TYPE_POINTER;
175     MMI_LOGE("send msg before");
176     bool isSuc = client_->SendMessage(pkt);
177     if (isSuc)
178         MMI_LOGD("sendAdd msg Success");
179     return RET_OK;
180 }
181 } // namespace MMI
182 } // namespace OHOS
183