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 "key_subscriber_handler.h"
17
18 #include "bytrace_adapter.h"
19 #include "define_multimodal.h"
20 #include "dfx_hisysevent.h"
21 #include "error_multimodal.h"
22 #include "input_event_data_transformation.h"
23 #include "input_event_handler.h"
24 #include "net_packet.h"
25 #include "proto.h"
26 #include "timer_manager.h"
27 #include "util_ex.h"
28
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeySubscriberHandler" };
33 constexpr uint32_t MAX_PRE_KEY_COUNT = 4;
34 } // namespace
35
36 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)37 void KeySubscriberHandler::HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)
38 {
39 CHKPV(keyEvent);
40 if (OnSubscribeKeyEvent(keyEvent)) {
41 MMI_HILOGD("Subscribe keyEvent filter success. keyCode:%{public}d", keyEvent->GetKeyCode());
42 BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_SUBSCRIBE_EVENT);
43 return;
44 }
45 CHKPV(nextHandler_);
46 nextHandler_->HandleKeyEvent(keyEvent);
47 }
48 #endif // OHOS_BUILD_ENABLE_KEYBOARD
49
50 #ifdef OHOS_BUILD_ENABLE_POINTER
HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)51 void KeySubscriberHandler::HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)
52 {
53 CHKPV(pointerEvent);
54 CHKPV(nextHandler_);
55 nextHandler_->HandlePointerEvent(pointerEvent);
56 }
57 #endif // OHOS_BUILD_ENABLE_POINTER
58
59 #ifdef OHOS_BUILD_ENABLE_TOUCH
HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent)60 void KeySubscriberHandler::HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent)
61 {
62 CHKPV(pointerEvent);
63 CHKPV(nextHandler_);
64 nextHandler_->HandleTouchEvent(pointerEvent);
65 }
66 #endif // OHOS_BUILD_ENABLE_TOUCH
67
SubscribeKeyEvent(SessionPtr sess,int32_t subscribeId,std::shared_ptr<KeyOption> keyOption)68 int32_t KeySubscriberHandler::SubscribeKeyEvent(
69 SessionPtr sess, int32_t subscribeId, std::shared_ptr<KeyOption> keyOption)
70 {
71 CALL_DEBUG_ENTER;
72 if (subscribeId < 0) {
73 MMI_HILOGE("Invalid subscribe");
74 return RET_ERR;
75 }
76 CHKPR(sess, ERROR_NULL_POINTER);
77 CHKPR(keyOption, ERROR_NULL_POINTER);
78 uint32_t preKeySize = keyOption->GetPreKeys().size();
79 if (preKeySize > MAX_PRE_KEY_COUNT) {
80 MMI_HILOGE("Leave, preKeySize:%{public}u", preKeySize);
81 return RET_ERR;
82 }
83
84 for (const auto &keyCode : keyOption->GetPreKeys()) {
85 MMI_HILOGD("keyOption->prekey:%{public}d", keyCode);
86 }
87 MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d,"
88 "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d",
89 subscribeId, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false",
90 keyOption->GetFinalKeyDownDuration());
91 auto subscriber = std::make_shared<Subscriber>(subscribeId, sess, keyOption);
92 InsertSubScriber(subscriber);
93 InitSessionDeleteCallback();
94 return RET_OK;
95 }
96
UnsubscribeKeyEvent(SessionPtr sess,int32_t subscribeId)97 int32_t KeySubscriberHandler::UnsubscribeKeyEvent(SessionPtr sess, int32_t subscribeId)
98 {
99 CALL_INFO_TRACE;
100 MMI_HILOGD("subscribeId:%{public}d", subscribeId);
101 for (auto it = subscribers_.begin(); it != subscribers_.end(); ++it) {
102 if ((*it)->id_ == subscribeId && (*it)->sess_ == sess) {
103 ClearTimer(*it);
104 subscribers_.erase(it);
105 return RET_OK;
106 }
107 }
108 return RET_ERR;
109 }
110
OnSubscribeKeyEvent(std::shared_ptr<KeyEvent> keyEvent)111 bool KeySubscriberHandler::OnSubscribeKeyEvent(std::shared_ptr<KeyEvent> keyEvent)
112 {
113 CHKPF(keyEvent);
114 if (IsRepeatedKeyEvent(keyEvent)) {
115 MMI_HILOGD("Repeat KeyEvent, skip");
116 return true;
117 }
118 keyEvent_ = KeyEvent::Clone(keyEvent);
119 int32_t keyAction = keyEvent->GetKeyAction();
120 MMI_HILOGD("keyCode:%{public}d, keyAction:%{public}s", keyEvent->GetKeyCode(),
121 KeyEvent::ActionToString(keyAction));
122 for (const auto &keyCode : keyEvent->GetPressedKeys()) {
123 MMI_HILOGD("Pressed KeyCode:%{public}d", keyCode);
124 }
125 bool handled = false;
126 if (keyAction == KeyEvent::KEY_ACTION_DOWN) {
127 handled = HandleKeyDown(keyEvent);
128 } else if (keyAction == KeyEvent::KEY_ACTION_UP) {
129 hasEventExecuting_ = false;
130 handled = HandleKeyUp(keyEvent);
131 } else if (keyAction == KeyEvent::KEY_ACTION_CANCEL) {
132 hasEventExecuting_ = false;
133 handled = HandleKeyCancel(keyEvent);
134 } else {
135 MMI_HILOGW("keyAction exception");
136 }
137 return handled;
138 }
139
InsertSubScriber(std::shared_ptr<Subscriber> subs)140 void KeySubscriberHandler::InsertSubScriber(std::shared_ptr<Subscriber> subs)
141 {
142 CALL_DEBUG_ENTER;
143 CHKPV(subs);
144 for (auto it = subscribers_.begin(); it != subscribers_.end(); ++it) {
145 if (subs->sess_ != nullptr && (*it)->id_ == subs->id_ && (*it)->sess_ == subs->sess_) {
146 MMI_HILOGW("Repeat registration id:%{public}d desc:%{public}s",
147 subs->id_, subs->sess_->GetDescript().c_str());
148 return;
149 }
150 }
151 subscribers_.push_back(subs);
152 }
153
OnSessionDelete(SessionPtr sess)154 void KeySubscriberHandler::OnSessionDelete(SessionPtr sess)
155 {
156 CALL_DEBUG_ENTER;
157 CHKPV(sess);
158 for (auto it = subscribers_.begin(); it != subscribers_.end();) {
159 if ((*it)->sess_ == sess) {
160 ClearTimer(*it);
161 subscribers_.erase(it++);
162 continue;
163 }
164 ++it;
165 }
166 }
167
IsPreKeysMatch(const std::set<int32_t> & preKeys,const std::vector<int32_t> & pressedKeys) const168 bool KeySubscriberHandler::IsPreKeysMatch(const std::set<int32_t> &preKeys,
169 const std::vector<int32_t> &pressedKeys) const
170 {
171 if (preKeys.size() == 0) {
172 return true;
173 }
174
175 if (preKeys.size() != pressedKeys.size()) {
176 return false;
177 }
178
179 for (const auto &pressedKey : pressedKeys) {
180 auto it = std::find(preKeys.begin(), preKeys.end(), pressedKey);
181 if (it == preKeys.end()) {
182 return false;
183 }
184 }
185
186 return true;
187 }
188
NotifySubscriber(std::shared_ptr<KeyEvent> keyEvent,const std::shared_ptr<Subscriber> & subscriber)189 void KeySubscriberHandler::NotifySubscriber(std::shared_ptr<KeyEvent> keyEvent,
190 const std::shared_ptr<Subscriber> &subscriber)
191 {
192 CALL_DEBUG_ENTER;
193 CHKPV(keyEvent);
194 CHKPV(subscriber);
195 auto udsServerPtr = InputHandler->GetUDSServer();
196 CHKPV(udsServerPtr);
197 if (keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER) {
198 DfxHisysevent::ReportPowerInfo(keyEvent, OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC);
199 }
200 NetPacket pkt(MmiMessageId::ON_SUBSCRIBE_KEY);
201 InputEventDataTransformation::KeyEventToNetPacket(keyEvent, pkt);
202 int32_t fd = subscriber->sess_->GetFd();
203 pkt << fd << subscriber->id_;
204 if (pkt.ChkRWError()) {
205 MMI_HILOGE("Packet write dispatch subscriber failed");
206 return;
207 }
208 if (!udsServerPtr->SendMsg(fd, pkt)) {
209 MMI_HILOGE("Leave, server dispatch subscriber failed");
210 return;
211 }
212 }
213
AddTimer(const std::shared_ptr<Subscriber> & subscriber,const std::shared_ptr<KeyEvent> & keyEvent)214 bool KeySubscriberHandler::AddTimer(const std::shared_ptr<Subscriber> &subscriber,
215 const std::shared_ptr<KeyEvent> &keyEvent)
216 {
217 CALL_DEBUG_ENTER;
218 CHKPF(keyEvent);
219 CHKPF(subscriber);
220
221 if (subscriber->timerId_ >= 0) {
222 MMI_HILOGW("Leave, timer already added, it may have been added by injection");
223 return true;
224 }
225
226 auto &keyOption = subscriber->keyOption_;
227 bool isKeyDown = keyOption->IsFinalKeyDown();
228 int32_t duration = isKeyDown ? keyOption->GetFinalKeyDownDuration() : keyOption->GetFinalKeyUpDelay();
229 if (duration <= 0) {
230 MMI_HILOGE("Leave, duration <= 0");
231 return true;
232 }
233
234 if (!CloneKeyEvent(keyEvent)) {
235 MMI_HILOGE("Leave, cloneKeyEvent failed");
236 return false;
237 }
238
239 std::weak_ptr<Subscriber> weakSubscriber = subscriber;
240 subscriber->timerId_ = TimerMgr->AddTimer(duration, 1, [this, weakSubscriber] () {
241 MMI_HILOGD("Timer callback");
242 auto subscriber = weakSubscriber.lock();
243 CHKPV(subscriber);
244 OnTimer(subscriber);
245 });
246
247 if (subscriber->timerId_ < 0) {
248 MMI_HILOGE("Leave, addTimer failed");
249 return false;
250 }
251 subscriber->keyEvent_ = keyEvent_;
252 hasEventExecuting_ = true;
253 MMI_HILOGD("Leave, add timer success, subscribeId:%{public}d,"
254 "duration:%{public}d, timerId:%{public}d",
255 subscriber->id_, duration, subscriber->timerId_);
256 return true;
257 }
258
ClearTimer(const std::shared_ptr<Subscriber> & subscriber)259 void KeySubscriberHandler::ClearTimer(const std::shared_ptr<Subscriber> &subscriber)
260 {
261 CALL_DEBUG_ENTER;
262 CHKPV(subscriber);
263
264 if (subscriber->timerId_ < 0) {
265 MMI_HILOGD("Leave, subscribeId:%{public}d, null timerId < 0", subscriber->id_);
266 return;
267 }
268
269 TimerMgr->RemoveTimer(subscriber->timerId_);
270 auto timerId = subscriber->timerId_;
271 subscriber->keyEvent_.reset();
272 subscriber->timerId_ = -1;
273 hasEventExecuting_ = false;
274 MMI_HILOGD("subscribeId:%{public}d, timerId:%{public}d", subscriber->id_, timerId);
275 }
276
OnTimer(const std::shared_ptr<Subscriber> subscriber)277 void KeySubscriberHandler::OnTimer(const std::shared_ptr<Subscriber> subscriber)
278 {
279 CALL_DEBUG_ENTER;
280 CHKPV(subscriber);
281 subscriber->timerId_ = -1;
282 if (subscriber->keyEvent_ == nullptr) {
283 MMI_HILOGE("Leave, subscriber->keyEvent is nullptr, subscribeId:%{public}d", subscriber->id_);
284 return;
285 }
286
287 NotifySubscriber(subscriber->keyEvent_, subscriber);
288 subscriber->keyEvent_.reset();
289 MMI_HILOGD("subscribeId:%{public}d", subscriber->id_);
290 }
291
InitSessionDeleteCallback()292 bool KeySubscriberHandler::InitSessionDeleteCallback()
293 {
294 CALL_DEBUG_ENTER;
295 if (callbackInitialized_) {
296 MMI_HILOGD("Session delete callback has already been initialized");
297 return true;
298 }
299 auto udsServerPtr = InputHandler->GetUDSServer();
300 CHKPF(udsServerPtr);
301 std::function<void(SessionPtr)> callback =
302 std::bind(&KeySubscriberHandler::OnSessionDelete, this, std::placeholders::_1);
303 udsServerPtr->AddSessionDeletedCallback(callback);
304 callbackInitialized_ = true;
305 return true;
306 }
307
HandleKeyDown(const std::shared_ptr<KeyEvent> & keyEvent)308 bool KeySubscriberHandler::HandleKeyDown(const std::shared_ptr<KeyEvent> &keyEvent)
309 {
310 CALL_DEBUG_ENTER;
311 CHKPF(keyEvent);
312 bool handled = false;
313 auto keyCode = keyEvent->GetKeyCode();
314 std::vector<int32_t> pressedKeys = keyEvent->GetPressedKeys();
315 RemoveKeyCode(keyCode, pressedKeys);
316 for (const auto &subscriber : subscribers_) {
317 auto &keyOption = subscriber->keyOption_;
318 MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d,"
319 "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d",
320 subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false",
321 keyOption->GetFinalKeyDownDuration());
322 for (const auto &keyCode : keyOption->GetPreKeys()) {
323 MMI_HILOGD("keyOption->prekey:%{public}d", keyCode);
324 }
325
326 if (!keyOption->IsFinalKeyDown()) {
327 MMI_HILOGD("!keyOption->IsFinalKeyDown()");
328 continue;
329 }
330
331 if (keyCode != keyOption->GetFinalKey()) {
332 ClearTimer(subscriber);
333 MMI_HILOGD("keyCode != keyOption->GetFinalKey()");
334 continue;
335 }
336
337 if (!IsPreKeysMatch(keyOption->GetPreKeys(), pressedKeys)) {
338 ClearTimer(subscriber);
339 MMI_HILOGD("preKeysMatch failed");
340 continue;
341 }
342
343 if (keyOption->GetFinalKeyDownDuration() <= 0) {
344 MMI_HILOGD("keyOption->GetFinalKeyDownDuration() <= 0");
345 NotifySubscriber(keyEvent, subscriber);
346 handled = true;
347 continue;
348 }
349
350 if (!AddTimer(subscriber, keyEvent)) {
351 MMI_HILOGE("Leave, add timer failed");
352 }
353 }
354 MMI_HILOGD("%{public}s", handled ? "true" : "false");
355 return handled;
356 }
357
HandleKeyUp(const std::shared_ptr<KeyEvent> & keyEvent)358 bool KeySubscriberHandler::HandleKeyUp(const std::shared_ptr<KeyEvent> &keyEvent)
359 {
360 CALL_DEBUG_ENTER;
361 CHKPF(keyEvent);
362 bool handled = false;
363 auto keyCode = keyEvent->GetKeyCode();
364 std::vector<int32_t> pressedKeys = keyEvent->GetPressedKeys();
365 RemoveKeyCode(keyCode, pressedKeys);
366 for (const auto &subscriber : subscribers_) {
367 PrintKeyUpLog(subscriber);
368 auto &keyOption = subscriber->keyOption_;
369 if (keyOption->IsFinalKeyDown()) {
370 ClearTimer(subscriber);
371 MMI_HILOGD("keyOption->IsFinalKeyDown()");
372 continue;
373 }
374 if (keyCode != keyOption->GetFinalKey()) {
375 MMI_HILOGD("keyCode != keyOption->GetFinalKey()");
376 continue;
377 }
378 if (!IsPreKeysMatch(keyOption->GetPreKeys(), pressedKeys)) {
379 MMI_HILOGD("PreKeysMatch failed");
380 continue;
381 }
382 if (!IsNotifyPowerKeySubsciber(keyOption->GetFinalKey(), pressedKeys)) {
383 MMI_HILOGD("In special case, subscriber are not notified");
384 continue;
385 }
386 auto duration = keyOption->GetFinalKeyDownDuration();
387 if (duration <= 0) {
388 MMI_HILOGD("duration <= 0");
389 HandleKeyUpWithDelay(keyEvent, subscriber);
390 handled = true;
391 continue;
392 }
393 std::optional<KeyEvent::KeyItem> keyItem = keyEvent->GetKeyItem();
394 if (!keyItem) {
395 MMI_HILOGE("The keyItem is nullopt");
396 return false;
397 }
398 auto upTime = keyEvent->GetActionTime();
399 auto downTime = keyItem->GetDownTime();
400 if (upTime - downTime >= (static_cast<int64_t>(duration) * 1000)) {
401 MMI_HILOGE("upTime - downTime >= duration");
402 continue;
403 }
404 MMI_HILOGD("upTime - downTime < duration");
405 HandleKeyUpWithDelay(keyEvent, subscriber);
406 handled = true;
407 }
408 MMI_HILOGD("%{public}s", handled ? "true" : "false");
409 return handled;
410 }
411
HandleKeyCancel(const std::shared_ptr<KeyEvent> & keyEvent)412 bool KeySubscriberHandler::HandleKeyCancel(const std::shared_ptr<KeyEvent> &keyEvent)
413 {
414 CALL_DEBUG_ENTER;
415 CHKPF(keyEvent);
416 for (const auto &subscriber : subscribers_) {
417 ClearTimer(subscriber);
418 }
419 return false;
420 }
421
IsKeyEventSubscribed(int32_t keyCode,int32_t trrigerType)422 bool KeySubscriberHandler::IsKeyEventSubscribed(int32_t keyCode, int32_t trrigerType)
423 {
424 CALL_DEBUG_ENTER;
425 for (const auto &subscriber : subscribers_) {
426 auto &keyOption = subscriber->keyOption_;
427 MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d,"
428 "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d",
429 subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false",
430 keyOption->GetFinalKeyDownDuration());
431 int32_t keyAction = KeyEvent::KEY_ACTION_UP;
432 if (keyOption->IsFinalKeyDown()) {
433 MMI_HILOGD("keyOption is final key down");
434 keyAction = KeyEvent::KEY_ACTION_DOWN;
435 }
436 if (keyCode == keyOption->GetFinalKey() && trrigerType == keyAction) {
437 MMI_HILOGD("current key event is subscribed.");
438 return true;
439 }
440 }
441 return false;
442 }
443
CloneKeyEvent(std::shared_ptr<KeyEvent> keyEvent)444 bool KeySubscriberHandler::CloneKeyEvent(std::shared_ptr<KeyEvent> keyEvent)
445 {
446 CHKPF(keyEvent);
447 if (keyEvent_ == nullptr) {
448 MMI_HILOGW("keyEvent_ is nullptr");
449 keyEvent_ = KeyEvent::Clone(keyEvent);
450 }
451 CHKPF(keyEvent_);
452 return true;
453 }
454
RemoveKeyCode(int32_t keyCode,std::vector<int32_t> & keyCodes)455 void KeySubscriberHandler::RemoveKeyCode(int32_t keyCode, std::vector<int32_t> &keyCodes)
456 {
457 for (auto it = keyCodes.begin(); it != keyCodes.end(); ++it) {
458 if (*it == keyCode) {
459 keyCodes.erase(it);
460 return;
461 }
462 }
463 }
464
IsRepeatedKeyEvent(std::shared_ptr<KeyEvent> keyEvent)465 bool KeySubscriberHandler::IsRepeatedKeyEvent(std::shared_ptr<KeyEvent> keyEvent)
466 {
467 CHKPF(keyEvent);
468 if (!hasEventExecuting_) {
469 return false;
470 }
471
472 if (keyEvent->GetKeyCode() != keyEvent_->GetKeyCode()) {
473 return false;
474 }
475
476 if (keyEvent->GetKeyAction() != keyEvent_->GetKeyAction()) {
477 return false;
478 }
479
480 if (keyEvent->GetKeyItems().size() != keyEvent_->GetKeyItems().size()) {
481 return false;
482 }
483
484 for (const auto &item : keyEvent->GetKeyItems()) {
485 int32_t keyCode = item.GetKeyCode();
486 bool findResult = false;
487 for (const auto &item1 : keyEvent_->GetKeyItems()) {
488 if (keyCode == item1.GetKeyCode()) {
489 findResult = true;
490 break;
491 }
492 }
493 if (!findResult) {
494 return false;
495 }
496 }
497 return true;
498 }
499
RemoveSubscriberKeyUpTimer(int32_t keyCode)500 void KeySubscriberHandler::RemoveSubscriberKeyUpTimer(int32_t keyCode)
501 {
502 for (const auto& item : subscribers_) {
503 if ((item->timerId_ >= 0) && (item->keyOption_->GetFinalKey() == keyCode)) {
504 ClearTimer(item);
505 }
506 }
507 }
508
IsNotifyPowerKeySubsciber(int32_t keyCode,const std::vector<int32_t> & keyCodes)509 bool KeySubscriberHandler::IsNotifyPowerKeySubsciber(int32_t keyCode, const std::vector<int32_t> &keyCodes)
510 {
511 if (keyCode != KeyEvent::KEYCODE_POWER) {
512 return true;
513 }
514
515 for (const auto& pressedKey: keyCodes) {
516 if (pressedKey == KeyEvent::KEYCODE_VOLUME_DOWN || pressedKey == KeyEvent::KEYCODE_VOLUME_UP) {
517 return false;
518 }
519 }
520 return true;
521 }
522
HandleKeyUpWithDelay(std::shared_ptr<KeyEvent> keyEvent,const std::shared_ptr<Subscriber> & subscriber)523 void KeySubscriberHandler::HandleKeyUpWithDelay(std::shared_ptr<KeyEvent> keyEvent,
524 const std::shared_ptr<Subscriber> &subscriber)
525 {
526 auto keyUpDelay = subscriber->keyOption_->GetFinalKeyUpDelay();
527 if (keyUpDelay <= 0) {
528 NotifySubscriber(keyEvent, subscriber);
529 } else {
530 if (!AddTimer(subscriber, keyEvent)) {
531 MMI_HILOGE("Leave, add timer failed");
532 }
533 }
534 }
535
PrintKeyUpLog(const std::shared_ptr<Subscriber> & subscriber)536 void KeySubscriberHandler::PrintKeyUpLog(const std::shared_ptr<Subscriber> &subscriber)
537 {
538 CHKPV(subscriber);
539 auto &keyOption = subscriber->keyOption_;
540 MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d,"
541 "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d,"
542 "keyOption->finalKeyUpDelay:%{public}d",
543 subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false",
544 keyOption->GetFinalKeyDownDuration(), keyOption->GetFinalKeyUpDelay());
545 for (const auto &keyCode : keyOption->GetPreKeys()) {
546 MMI_HILOGD("keyOption->prekey:%{public}d", keyCode);
547 }
548 }
549
Dump(int32_t fd,const std::vector<std::string> & args)550 void KeySubscriberHandler::Dump(int32_t fd, const std::vector<std::string> &args)
551 {
552 CALL_DEBUG_ENTER;
553 mprintf(fd, "Subscriber information:\t");
554 mprintf(fd, "subscribers: count=%d", subscribers_.size());
555 for (const auto &item : subscribers_) {
556 std::shared_ptr<Subscriber> subscriber = item;
557 CHKPV(subscriber);
558 SessionPtr session = item->sess_;
559 CHKPV(session);
560 std::shared_ptr<KeyOption> keyOption = item->keyOption_;
561 CHKPV(keyOption);
562 mprintf(fd,
563 "subscriber id:%d | timer id:%d | Pid:%d | Uid:%d | Fd:%d "
564 "| FinalKey:%d | finalKeyDownDuration:%d | IsFinalKeyDown:%s\t",
565 subscriber->id_, subscriber->timerId_, session->GetPid(),
566 session->GetUid(), session->GetFd(), keyOption->GetFinalKey(),
567 keyOption->GetFinalKeyDownDuration(), keyOption->IsFinalKeyDown() ? "true" : "false");
568 std::set<int32_t> preKeys = keyOption->GetPreKeys();
569 for (const auto &preKey : preKeys) {
570 mprintf(fd, "preKeys:%d\t", preKey);
571 }
572 }
573 }
574 } // namespace MMI
575 } // namespace OHOS
576