• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 <chrono>
17 #include <gtest/gtest.h>
18 #include <thread>
19 
20 #include "util.h"
21 
22 #include "ability_manager_client.h"
23 #include "bundle_name_parser.h"
24 #include "common_event_support.h"
25 #include "display_event_monitor.h"
26 #include "event_log_helper.h"
27 #include "gesturesense_wrapper.h"
28 #include "input_event_handler.h"
29 #include "input_handler_type.h"
30 #include "input_windows_manager.h"
31 #include "i_preference_manager.h"
32 #include "key_shortcut_manager.h"
33 #include "mmi_log.h"
34 #include "multimodal_event_handler.h"
35 #include "multimodal_input_preferences_manager.h"
36 #include "system_info.h"
37 #include "stylus_key_handler.h"
38 #define private public
39 #include "key_command_handler.h"
40 #undef private
41 
42 #undef MMI_LOG_TAG
43 #define MMI_LOG_TAG "KeyCommandHandlerTest"
44 
45 namespace OHOS {
46 namespace MMI {
47 namespace {
48 using namespace testing::ext;
49 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
50 constexpr int32_t SEC_TO_NANOSEC = 1000000000;
51 constexpr int32_t COMMON_PARAMETER_ERROR = 401;
52 constexpr int32_t INTERVAL_TIME = 100;
53 constexpr int32_t INTERVAL_TIME_OUT = 500000;
54 constexpr int32_t ERROR_DELAY_VALUE = -1000;
55 constexpr int32_t TWO_FINGERS_TIME_LIMIT = 150000;
56 constexpr int32_t TWO_FINGERS_DISTANCE_LIMIT = 16;
57 constexpr int32_t TOUCH_LIFT_LIMIT = 24;
58 constexpr int32_t TOUCH_RIGHT_LIMIT = 24;
59 constexpr int32_t TOUCH_TOP_LIMIT = 80;
60 constexpr int32_t TOUCH_BOTTOM_LIMIT = 41;
61 constexpr int32_t MAX_SHORT_KEY_DOWN_DURATION = 4000;
62 constexpr int32_t MIN_SHORT_KEY_DOWN_DURATION = 0;
63 constexpr float DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG = 64.0;
64 constexpr int32_t WINDOW_INPUT_METHOD_TYPE = 2105;
65 const std::string EXTENSION_ABILITY = "extensionAbility";
66 const std::string EXTENSION_ABILITY_ABNORMAL = "extensionAbilityAbnormal";
67 const std::string SOS_BUNDLE_NAME {"com.hmos.emergencycommunication"};
68 const std::string SCREENRECORDER_BUNDLE_NAME {"com.hmos.screenrecorder"};
69 const std::string CMD_DEVICE_TYPE_TV = OHOS::system::GetParameter("const.product.devicetype", "unknown");
70 const std::string CMD_PRODUCT_TYPE_TV { "tv" };
71 const vector<float> CIRCLE_COORDINATES = {328.0f, 596.0f, 328.0f, 597.0f, 322.0f, 606.0f, 306.0f, 635.0f, 291.0f,
72     665.0f, 283.0f, 691.0f, 291.0f, 739.0f, 300.0f, 751.0f, 312.0f, 759.0f, 327.0f, 765.0f, 343.0f, 768.0f, 361.0f,
73     769.0f, 379.0f, 767.0f, 395.0f, 761.0f, 411.0f, 751.0f, 425.0f, 737.0f, 439.0f, 718.0f, 449.0f, 709.0f, 456.0f,
74     683.0f, 459.0f, 654.0f, 451.0f, 569.0f, 437.0f, 552.0f, 418.0f, 542.0f, 392.0f, 540.0f, 363.0f, 545.0f};
75 const vector<int64_t> CIRCLE_TIMESTAMPS = {71304451, 71377126, 71387783, 71398239, 71409629, 71419392, 71461386,
76     71472044, 71483797, 71493077, 71503426, 71514339, 71524715, 71535126, 71545652, 71556329, 71566506, 71577283,
77     71587745, 71598921, 71630319, 71642155, 71651090, 71662474, 71671657};
78 const vector<float> CURVE_COORDINATES = {374.0f, 489.0f, 373.0f, 489.0f, 365.0f, 491.0f, 341.0f, 503.0f, 316.0f, 519.0f,
79     300.0f, 541.0f, 293.0f, 561.0f, 289.0f, 582.0f, 292.0f, 643.0f, 301.0f, 657.0f, 317.0f, 668.0f, 336.0f, 681.0f,
80     358.0f, 695.0f, 381.0f, 706.0f, 403.0f, 717.0f, 423.0f, 715.0f, 441.0f, 727.0f, 458.0f, 739.0f, 468.0f, 751.0f,
81     474.0f, 764.0f, 467.0f, 812.0f, 455.0f, 828.0f, 435.0f, 844.0f, 412.0f, 860.0f, 387.0f, 876.0f, 362.0f, 894.0f,
82     338.0f, 906.0f, 317.0f, 913.0f, 296.0f, 918.0f};
83 const vector<int64_t> CURVE_TIMESTAMPS = {134900436, 134951403, 134962832, 134973234, 134983492, 134995390, 135003876,
84     135014389, 135045917, 135057774, 135067076, 135077688, 135088139, 135098494, 135109130, 135119679, 135130101,
85     135140670, 135151182, 135161672, 135193739, 135203790, 135214272, 135224868, 135236197, 135245828, 135256481,
86     135267186, 135276939};
87 const vector<float> LINE_COORDINATES = {390.0f, 340.0f, 390.0f, 348.0f, 390.0f, 367.0f, 387.0f, 417.0f, 385.0f, 455.0f,
88     384.0f, 491.0f, 382.0f, 516.0f, 381.0f, 539.0f, 380.0f, 564.0f, 378.0f, 589.0f, 377.0f, 616.0f, 376.0f, 643.0f,
89     375.0f, 669.0f, 375.0f, 694.0f, 374.0f, 718.0f, 374.0f, 727.0f, 374.0f, 750.0f, 374.0f, 771.0f, 374.0f, 791.0f,
90     374.0f, 811.0f, 375.0f, 831.0f, 375.0f, 851.0f, 376.0f, 870.0f, 377.0f, 886.0f, 377.0f, 902.0f, 379.0f, 918.0f,
91     379.0f, 934.0f, 380.0f, 950.0f, 381.0f, 963.0f, 383.0f, 977.0f, 385.0f, 992.0f, 387.0f, 1002.0f, 389.0f, 1016.0f,
92     390.0f, 1030.0f, 390.0f, 1042.0f, 390.0f, 1052.0f, 390.0f, 1061.0f, 391.0f, 1069.0f, 391.0f, 1075.0f, 391.0f,
93     1080.0f, 391.0f, 1085.0f, 391.0f, 1089.0f, 392.0f, 1095.0f, 393.0f, 1099.0f, 394.0f, 1103.0f, 395.0f, 1111.0f,
94     395.0f, 1117.0f, 396.0f, 1124.0f, 397.0f, 1130.0f, 397.0f, 1134.0f, 397.0f, 1138.0f};
95 const vector<int64_t> LINE_TIMESTAMPS = {70809086, 70912930, 70923294, 70933960, 70944571, 70955130, 70965726, 70976076,
96     70986620, 70997190, 71007517, 71017998, 71028551, 71039171, 71049654, 71060120, 71070809, 71082130, 71091709,
97     71102285, 71112746, 71123402, 71133898, 71144469, 71154894, 71165617, 71175944, 71186477, 71197199, 71207737,
98     71218030, 71228652, 71239243, 71249733, 71260291, 71270821, 71281313, 71291919, 71302477, 71313573, 71323426,
99     71333880, 71355034, 71376110, 71418297, 71439219, 71449749, 71460268, 71470874, 71481275, 71744747};
100 } // namespace
101 class KeyCommandHandlerTest : public testing::Test {
102 public:
SetUpTestCase(void)103     static void SetUpTestCase(void) {}
TearDownTestCase(void)104     static void TearDownTestCase(void) {}
SetUp(void)105     void SetUp(void)
106     {
107         touchEvent_ = PointerEvent::Create();
108         keyEvent_ = KeyEvent::Create();
109     }
TearDown(void)110     void TearDown(void)
111     {
112         touchEvent_ = nullptr;
113         keyEvent_ = nullptr;
114     }
115     std::shared_ptr<PointerEvent> touchEvent_;
116     std::shared_ptr<KeyEvent> keyEvent_;
117     std::shared_ptr<KeyEvent> SetupKeyEvent();
118     std::shared_ptr<PointerEvent> SetupThreeFingerTapEvent();
119     std::shared_ptr<PointerEvent> SetupFourFingerTapEvent();
120 #ifdef OHOS_BUILD_ENABLE_TOUCH
121     std::shared_ptr<PointerEvent> SetupDoubleFingerDownEvent();
122     std::shared_ptr<PointerEvent> SetupSingleKnuckleDownEvent();
123     std::shared_ptr<PointerEvent> SetupDoubleKnuckleDownEvent();
124 #endif // OHOS_BUILD_ENABLE_TOUCH
125 };
126 
GetNanoTime()127 int64_t GetNanoTime()
128 {
129     struct timespec time = {0};
130     clock_gettime(CLOCK_MONOTONIC, &time);
131     return static_cast<int64_t>(time.tv_sec) * SEC_TO_NANOSEC + time.tv_nsec;
132 }
133 
SetupKeyEvent()134 std::shared_ptr<KeyEvent> KeyCommandHandlerTest::SetupKeyEvent()
135 {
136     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
137     CHKPP(keyEvent);
138     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
139     KeyEvent::KeyItem kitDown;
140     kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
141     kitDown.SetPressed(true);
142     kitDown.SetDownTime(downTime);
143     keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
144     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
145     keyEvent->AddPressedKeyItems(kitDown);
146 
147     return keyEvent;
148 }
149 
150 #ifdef OHOS_BUILD_ENABLE_TOUCH
SetupDoubleFingerDownEvent()151 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupDoubleFingerDownEvent()
152 {
153     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
154     CHKPP(pointerEvent);
155     PointerEvent::PointerItem item;
156     PointerEvent::PointerItem item2;
157     item.SetPointerId(0);
158     item.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
159     int32_t downX = 100;
160     int32_t downY = 200;
161     item.SetDisplayX(downX);
162     item.SetDisplayY(downY);
163     item.SetPressed(true);
164     pointerEvent->SetPointerId(0);
165     pointerEvent->AddPointerItem(item);
166 
167     item2.SetPointerId(1);
168     item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
169     int32_t secondDownX = 120;
170     int32_t secondDownY = 220;
171     item2.SetDisplayX(secondDownX);
172     item2.SetDisplayY(secondDownY);
173     item2.SetPressed(true);
174     pointerEvent->SetPointerId(1);
175     pointerEvent->AddPointerItem(item2);
176     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
177     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
178     return pointerEvent;
179 }
180 
SetupSingleKnuckleDownEvent()181 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupSingleKnuckleDownEvent()
182 {
183     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
184     CHKPP(pointerEvent);
185     PointerEvent::PointerItem item;
186     item.SetPointerId(0);
187     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
188     int32_t downX = 100;
189     int32_t downY = 200;
190     item.SetDisplayX(downX);
191     item.SetDisplayY(downY);
192     item.SetPressed(true);
193     pointerEvent->SetPointerId(0);
194     pointerEvent->AddPointerItem(item);
195     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
196     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
197     return pointerEvent;
198 }
199 
SetupDoubleKnuckleDownEvent()200 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupDoubleKnuckleDownEvent()
201 {
202     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
203     CHKPP(pointerEvent);
204     PointerEvent::PointerItem item;
205     PointerEvent::PointerItem item2;
206     item.SetPointerId(0);
207     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
208     int32_t downX = 100;
209     int32_t downY = 200;
210     item.SetDisplayX(downX);
211     item.SetDisplayY(downY);
212     item.SetPressed(true);
213     pointerEvent->SetPointerId(0);
214     pointerEvent->AddPointerItem(item);
215 
216     item2.SetPointerId(1);
217     item2.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
218     int32_t secondDownX = 120;
219     int32_t secondDownY = 220;
220     item2.SetDisplayX(secondDownX);
221     item2.SetDisplayY(secondDownY);
222     item2.SetPressed(true);
223     pointerEvent->SetPointerId(1);
224     pointerEvent->AddPointerItem(item2);
225     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
226     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
227     return pointerEvent;
228 }
229 #endif // OHOS_BUILD_ENABLE_TOUCH
230 
SetupThreeFingerTapEvent()231 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupThreeFingerTapEvent()
232 {
233     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
234     CHKPP(pointerEvent);
235     PointerEvent::PointerItem item1;
236     PointerEvent::PointerItem item2;
237     PointerEvent::PointerItem item3;
238 
239     int32_t id0 = 0;
240     item1.SetPointerId(id0);
241     int32_t downX1 = 100;
242     int32_t downY1 = 200;
243     int64_t actionTime1 = 1000000;
244     item1.SetDisplayX(downX1);
245     item1.SetDisplayY(downY1);
246     item1.SetDownTime(actionTime1);
247     pointerEvent->SetPointerId(id0);
248     pointerEvent->AddPointerItem(item1);
249 
250     int32_t id1 = 1;
251     item2.SetPointerId(id1);
252     int32_t downX2 = 200;
253     int32_t downY2 = 300;
254     int64_t actionTime2 = 1000100;
255     item2.SetDisplayX(downX2);
256     item2.SetDisplayY(downY2);
257     item2.SetDownTime(actionTime2);
258     pointerEvent->SetPointerId(id1);
259     pointerEvent->AddPointerItem(item2);
260 
261     int32_t id2 = 2;
262     item3.SetPointerId(id2);
263     int32_t downX3 = 100;
264     int32_t downY3 = 200;
265     int64_t actionTime3 = 1000200;
266     item3.SetDisplayX(downX3);
267     item3.SetDisplayY(downY3);
268     item3.SetDownTime(actionTime3);
269     pointerEvent->SetPointerId(id2);
270     pointerEvent->AddPointerItem(item3);
271 
272     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP);
273     return pointerEvent;
274 }
275 
SetupFourFingerTapEvent()276 std::shared_ptr<PointerEvent> KeyCommandHandlerTest::SetupFourFingerTapEvent()
277 {
278     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
279     CHKPP(pointerEvent);
280     PointerEvent::PointerItem item1;
281     PointerEvent::PointerItem item2;
282     PointerEvent::PointerItem item3;
283     PointerEvent::PointerItem item4;
284 
285     int32_t id0 = 0;
286     item1.SetPointerId(id0);
287     int32_t downX1 = 100;
288     int32_t downY1 = 200;
289     int64_t actionTime1 = 1000000;
290     item1.SetDisplayX(downX1);
291     item1.SetDisplayY(downY1);
292     item1.SetDownTime(actionTime1);
293     pointerEvent->SetPointerId(id0);
294     pointerEvent->AddPointerItem(item1);
295 
296     int32_t id1 = 1;
297     item2.SetPointerId(id1);
298     int32_t downX2 = 200;
299     int32_t downY2 = 300;
300     int64_t actionTime2 = 1000100;
301     item2.SetDisplayX(downX2);
302     item2.SetDisplayY(downY2);
303     item2.SetDownTime(actionTime2);
304     pointerEvent->SetPointerId(id1);
305     pointerEvent->AddPointerItem(item2);
306 
307     int32_t id2 = 2;
308     item3.SetPointerId(id2);
309     int32_t downX3 = 100;
310     int32_t downY3 = 200;
311     int64_t actionTime3 = 1000200;
312     item3.SetDisplayX(downX3);
313     item3.SetDisplayY(downY3);
314     item3.SetDownTime(actionTime3);
315     pointerEvent->SetPointerId(id2);
316     pointerEvent->AddPointerItem(item3);
317 
318     int32_t id3 = 3;
319     item4.SetPointerId(id3);
320     int32_t downX4 = 400;
321     int32_t downY4 = 280;
322     int64_t actionTime4 = 1000300;
323     item4.SetDisplayX(downX4);
324     item4.SetDisplayY(downY4);
325     item4.SetDownTime(actionTime4);
326     pointerEvent->SetPointerId(id3);
327     pointerEvent->AddPointerItem(item4);
328 
329     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
330     return pointerEvent;
331 }
332 
333 /**
334  * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_01
335  * @tc.desc: Test CheckAndUpdateTappingCountAtDown
336  * @tc.type: Function
337  * @tc.require:
338  */
339 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_01, TestSize.Level1)
340 {
341     CALL_TEST_DEBUG;
342     KeyCommandHandler handler;
343     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
344     ASSERT_NE(pointerEvent, nullptr);
345     pointerEvent->actionTime_ = 10000;
346     handler.lastDownTime_ = 15000;
347     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
348 
349     pointerEvent->actionTime_ = 800000;
350     handler.lastDownTime_ = 200000;
351     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
352 }
353 
354 /**
355  * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_02
356  * @tc.desc: Test CheckAndUpdateTappingCountAtDown
357  * @tc.type: Function
358  * @tc.require:
359  */
360 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_02, TestSize.Level1)
361 {
362     CALL_TEST_DEBUG;
363     KeyCommandHandler handler;
364     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
365     ASSERT_NE(pointerEvent, nullptr);
366 
367     pointerEvent->actionTime_ = 800000;
368     handler.lastDownTime_ = 500000;
369     handler.previousUpTime_ = 850000;
370     handler.downToPrevUpTimeConfig_ = 0;
371     handler.tappingCount_ = 2;
372     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
373 
374     handler.tappingCount_ = 5;
375     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(pointerEvent));
376 }
377 
378 /**
379  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_002
380  * @tc.desc: Test the funcation MatchShortcutKey
381  * @tc.type: FUNC
382  * @tc.require:
383  */
384 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_002, TestSize.Level1)
385 {
386     KeyCommandHandler handler;
387     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
388     ASSERT_NE(keyEvent, nullptr);
389     ShortcutKey shortcutKey;
390     std::vector<ShortcutKey> upAbilities;
391     shortcutKey.statusConfigValue = true;
392     shortcutKey.finalKey = -1;
393     shortcutKey.keyDownDuration = 0;
394     EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
395     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
396 
397     shortcutKey.businessId = "V1";
398     int32_t delay = handler.GetKeyDownDurationFromXml(shortcutKey.businessId);
399     delay = 100;
400     EXPECT_TRUE(delay >= MIN_SHORT_KEY_DOWN_DURATION);
401     EXPECT_TRUE(delay <= MAX_SHORT_KEY_DOWN_DURATION);
402     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
403     delay = 5000;
404     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
405     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
406 
407     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
408     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
409     EXPECT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
410     shortcutKey.keyDownDuration = 100;
411     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
412 }
413 
414 /**
415  * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess_01
416  * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickProcess
417  * @tc.type: FUNC
418  * @tc.require:
419  */
420 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess_01, TestSize.Level1)
421 {
422     CALL_TEST_DEBUG;
423     KeyCommandHandler handler;
424     std::string bundleName = "bundleName";
425     std::string abilityName = "abilityName";
426     std::string action = "move";
427 
428     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_OFF;
429     DISPLAY_MONITOR->isScreenLocked_ = true;
430     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
431 
432     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_ON;
433     DISPLAY_MONITOR->isScreenLocked_ = true;
434     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
435 
436     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_OFF;
437     DISPLAY_MONITOR->isScreenLocked_ = false;
438     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
439 
440     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_ON;
441     DISPLAY_MONITOR->isScreenLocked_ = false;
442     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
443 }
444 
445 /**
446  * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle_01
447  * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickHandle
448  * @tc.type: FUNC
449  * @tc.require:
450  */
451 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle_01, TestSize.Level1)
452 {
453     CALL_TEST_DEBUG;
454     KeyCommandHandler handler;
455     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
456     ASSERT_NE(keyEvent, nullptr);
457 
458     keyEvent->keyAction_ = KNUCKLE_1F_DOUBLE_CLICK;
459     EXPECT_TRUE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
460 
461     keyEvent->keyAction_ = KNUCKLE_2F_DOUBLE_CLICK;
462     EXPECT_TRUE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
463 
464     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UNKNOWN;
465     EXPECT_FALSE(handler.TouchPadKnuckleDoubleClickHandle(keyEvent));
466 }
467 
468 /**
469  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_001
470  * @tc.desc: Test the funcation HandleRepeatKeyOwnCount
471  * @tc.type: FUNC
472  * @tc.require:
473  */
474 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_001, TestSize.Level1)
475 {
476     CALL_TEST_DEBUG;
477     KeyCommandHandler handler;
478     RepeatKey repeatKey;
479     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
480 }
481 
482 /**
483  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_002
484  * @tc.desc: Test the funcation HandleRepeatKeyOwnCount
485  * @tc.type: FUNC
486  * @tc.require:
487  */
488 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_002, TestSize.Level1)
489 {
490     CALL_TEST_DEBUG;
491     KeyCommandHandler handler;
492     RepeatKey repeatKey;
493     repeatKey.ability.bundleName = SCREENRECORDER_BUNDLE_NAME;
494     handler.downActionTime_ = 600000;
495     handler.upActionTime_ = 800000;
496     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
497 }
498 
499 /**
500  * @tc.name: KeyCommandHandlerTest_SendKeyEvent_01
501  * @tc.desc: Test the funcation SendKeyEvent
502  * @tc.type: FUNC
503  * @tc.require:
504  */
505 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_01, TestSize.Level1)
506 {
507     CALL_TEST_DEBUG;
508     KeyCommandHandler handler;
509     handler.isHandleSequence_ = false;
510     handler.launchAbilityCount_ = 1;
511     handler.count_ = 10;
512     handler.repeatKey_.keyCode = 18;
513     handler.repeatKeyMaxTimes_[18] = 11;
514     handler.repeatKeyMaxTimes_[2] = 3;
515     ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
516 }
517 
518 /**
519  * @tc.name: KeyCommandHandlerTest_SendKeyEvent_02
520  * @tc.desc: Test the funcation SendKeyEvent
521  * @tc.type: FUNC
522  * @tc.require:
523  */
524 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_02, TestSize.Level1)
525 {
526     CALL_TEST_DEBUG;
527     KeyCommandHandler handler;
528     handler.isHandleSequence_ = false;
529     handler.launchAbilityCount_ = 1;
530     handler.count_ = 10;
531     handler.repeatKey_.keyCode = 16;
532     handler.repeatKeyMaxTimes_[16] = 15;
533     handler.repeatKeyMaxTimes_[2] = 3;
534     ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
535 }
536 
537 /**
538  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_01
539  * @tc.desc: Test the funcation CheckInputMethodArea
540  * @tc.type: FUNC
541  * @tc.require:
542  */
543 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_01, TestSize.Level1)
544 {
545     CALL_TEST_DEBUG;
546     KeyCommandHandler handler;
547     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
548     ASSERT_NE(touchEvent, nullptr);
549 
550     touchEvent->targetDisplayId_ = 10;
551     touchEvent->targetWindowId_ = 5;
552     InputWindowsManager inputWindowsManager;
553     WindowGroupInfo windowGroupInfo;
554     WindowInfo window1;
555     window1.windowType = 2100;
556     window1.id = 1;
557     window1.pid = 2;
558     windowGroupInfo.windowsInfo.push_back(window1);
559     inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
560     ASSERT_FALSE(handler.CheckInputMethodArea(touchEvent));
561 }
562 
563 /**
564  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_02
565  * @tc.desc: Test the funcation CheckInputMethodArea
566  * @tc.type: FUNC
567  * @tc.require:
568  */
569 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_02, TestSize.Level1)
570 {
571     CALL_TEST_DEBUG;
572     KeyCommandHandler handler;
573     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
574     ASSERT_NE(pointerEvent, nullptr);
575     pointerEvent->targetDisplayId_ = 10;
576     pointerEvent->targetWindowId_ = 5;
577     PointerEvent::PointerItem item;
578     item.SetDisplayX(10);
579     item.SetDisplayY(15);
580 
581     InputWindowsManager inputWindowsManager;
582     WindowGroupInfo windowGroupInfo;
583     WindowInfo window1;
584     window1.windowType = 2105;
585     window1.id = 1;
586     window1.pid = 2;
587     window1.area.x = 5;
588     window1.area.y = 8;
589     window1.area.width = 20;
590     windowGroupInfo.windowsInfo.push_back(window1);
591     inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
592     ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
593 
594     pointerEvent->targetWindowId_ = 1;
595     int32_t rightDownX = 30;
596     int32_t rightDownY = 40;
597     EXPECT_TRUE(item.GetDisplayX() <= rightDownX);
598     EXPECT_TRUE(item.GetDisplayY() <= rightDownY);
599     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
600     ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
601 
602     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
603     ASSERT_FALSE(handler.CheckInputMethodArea(pointerEvent));
604 }
605 
606 /**
607  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_01
608  * @tc.desc: Test the funcation ConvertVPToPX
609  * @tc.type: FUNC
610  * @tc.require:
611  */
612 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_01, TestSize.Level1)
613 {
614     CALL_TEST_DEBUG;
615     KeyCommandHandler handler;
616     int32_t vp = -1;
617     ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
618     vp = 1;
619     DisplayInfo displayInfo;
620     displayInfo.dpi = -20;
621     ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
622 
623     displayInfo.dpi = 30;
624     ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
625 }
626 
627 /**
628  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_01
629  * @tc.desc: Test the funcation HandleKnuckleGestureEvent
630  * @tc.type: FUNC
631  * @tc.require:
632  */
633 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_01, TestSize.Level1)
634 {
635     CALL_TEST_DEBUG;
636     KeyCommandHandler handler;
637     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
638     ASSERT_NE(pointerEvent, nullptr);
639     EXPECT_FALSE(handler.CheckKnuckleCondition(pointerEvent));
640     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(pointerEvent));
641 }
642 
643 /**
644  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_01
645  * @tc.desc: Test the funcation HandleKnuckleGestureTouchMove
646  * @tc.type: FUNC
647  * @tc.require:
648  */
649 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_01, TestSize.Level1)
650 {
651     CALL_TEST_DEBUG;
652     KeyCommandHandler handler;
653     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
654     ASSERT_NE(pointerEvent, nullptr);
655     PointerEvent::PointerItem item;
656     pointerEvent->pointerId_ = 5;
657     pointerEvent->targetDisplayId_ = 10;
658     item.rawDisplayX_ = 20.0;
659     item.rawDisplayY_ = 25.0;
660     handler.gestureLastX_ = 1.0f;
661     handler.gestureLastY_ = 2.0f;
662 
663     handler.isStartBase_ = true;
664     handler.isGesturing_ = false;
665     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
666 
667     handler.isGesturing_ = true;
668     handler.isLetterGesturing_ = false;
669     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
670 
671     handler.isLetterGesturing_ = true;
672     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(pointerEvent));
673 }
674 
675 /**
676  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_04
677  * @tc.desc: Test the funcation HandleKnuckleGestureTouchUp
678  * @tc.type: FUNC
679  * @tc.require:
680  */
681 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_04, TestSize.Level1)
682 {
683     CALL_TEST_DEBUG;
684     KeyCommandHandler handler;
685     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
686     ASSERT_NE(touchEvent, nullptr);
687     GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool,
__anonde368b400202(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 688                                          bool) -> int32_t {
689         return 0;
690     };
691     ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
692     handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
693     handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
694     handler.isGesturing_ = true;
695     handler.isLetterGesturing_ = true;
696     NotifyType notifyType;
697     notifyType = NotifyType::REGIONGESTURE;
698     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
699 
700     notifyType = NotifyType::LETTERGESTURE;
701     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
702 
703     notifyType = NotifyType::OTHER;
704     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
705 }
706 
707 /**
708  * @tc.name: KeyCommandHandlerTest_HandleKeyDown_001
709  * @tc.desc: test HandleKeyDown
710  * @tc.type: FUNC
711  * @tc.require:
712  */
713 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_001, TestSize.Level1)
714 {
715     CALL_TEST_DEBUG;
716     KeyCommandHandler handler;
717     ShortcutKey shortcutKey;
718     shortcutKey.keyDownDuration = 10;
719     shortcutKey.timerId = -1;
720     ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
721 
722     shortcutKey.timerId = 2;
723     shortcutKey.finalKey = -1;
724     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
725     ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
726 }
727 
728 /**
729  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_01
730  * @tc.desc: Test the funcation MatchShortcutKey
731  * @tc.type: FUNC
732  * @tc.require:
733  */
734 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_01, TestSize.Level1)
735 {
736     KeyCommandHandler handler;
737     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
738     ASSERT_NE(keyEvent, nullptr);
739     ShortcutKey shortcutKey;
740     std::vector<ShortcutKey> upAbilities;
741     shortcutKey.statusConfigValue = true;
742     shortcutKey.finalKey = -1;
743     shortcutKey.keyDownDuration = 0;
744     EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
745     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
746 
747     shortcutKey.businessId = "V1";
748     int32_t delay = handler.GetKeyDownDurationFromXml(shortcutKey.businessId);
749     delay = 100;
750     EXPECT_TRUE(delay >= MIN_SHORT_KEY_DOWN_DURATION);
751     EXPECT_TRUE(delay <= MAX_SHORT_KEY_DOWN_DURATION);
752     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
753 
754     delay = 5000;
755     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
756     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
757 
758     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
759     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
760     EXPECT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
761     shortcutKey.keyDownDuration = 100;
762     EXPECT_FALSE(handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities));
763 }
764 
765 /**
766  * @tc.name: KeyCommandHandlerTest_MatchShortcutKeys_01
767  * @tc.desc: Test the funcation MatchShortcutKeys
768  * @tc.type: FUNC
769  * @tc.require:
770  */
771 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKeys_01, TestSize.Level1)
772 {
773     CALL_TEST_DEBUG;
774     KeyCommandHandler handler;
775     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
776     ASSERT_NE(keyEvent, nullptr);
777     keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
778     bool ret = KEY_SHORTCUT_MGR->HaveShortcutConsumed(keyEvent);
779     EXPECT_FALSE(ret);
780 
781     std::vector<ShortcutKey> upAbilities;
782     ShortcutKey key1;
783     key1.preKeys = {1, 2, 3};
784     key1.businessId = "business1";
785     key1.statusConfig = "config1";
786     key1.finalKey = -1;
787     upAbilities.push_back(key1);
788     EXPECT_FALSE(upAbilities.empty());
789     EXPECT_TRUE(handler.MatchShortcutKeys(keyEvent));
790 }
791 
792 /**
793  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_001
794  * @tc.desc: HandleRepeatKeyAbility
795  * @tc.type: FUNC
796  * @tc.require:
797  */
798 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_001, TestSize.Level1)
799 {
800     CALL_TEST_DEBUG;
801     KeyCommandHandler handler;
802     RepeatKey repeatKey;
803     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
804     ASSERT_NE(keyEvent, nullptr);
805     handler.count_ = 2;
806     repeatKey.ability.bundleName = "bundleName";
807     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, false));
808 }
809 
810 /**
811  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_002
812  * @tc.desc: HandleRepeatKeyAbility
813  * @tc.type: FUNC
814  * @tc.require:
815  */
816 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_002, TestSize.Level1)
817 {
818     CALL_TEST_DEBUG;
819     KeyCommandHandler handler;
820     RepeatKey repeatKey;
821     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
822     ASSERT_NE(keyEvent, nullptr);
823     handler.count_ = 2;
824     repeatKey.ability.bundleName = "bundleName";
825     handler.repeatKeyTimerIds_.emplace(repeatKey.ability.bundleName, 1);
826     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, false));
827 }
828 
829 /**
830  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_003
831  * @tc.desc: HandleRepeatKeyAbility
832  * @tc.type: FUNC
833  * @tc.require:
834  */
835 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_003, TestSize.Level1)
836 {
837     CALL_TEST_DEBUG;
838     KeyCommandHandler handler;
839     RepeatKey repeatKey;
840     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
841     ASSERT_NE(keyEvent, nullptr);
842     bool isMaxTimes = false;
843 
844     repeatKey.ability.bundleName = "bundleName1";
845     handler.repeatKeyTimerIds_["bundleName1"] = 1;
846     handler.repeatKeyTimerIds_["bundleName2"] = 2;
847     handler.repeatKeyTimerIds_["bundleName3"] = 3;
848     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, isMaxTimes));
849 }
850 
851 /**
852  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_004
853  * @tc.desc: HandleRepeatKeyAbility
854  * @tc.type: FUNC
855  * @tc.require:
856  */
857 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_004, TestSize.Level1)
858 {
859     CALL_TEST_DEBUG;
860     KeyCommandHandler handler;
861     RepeatKey repeatKey;
862     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
863     ASSERT_NE(keyEvent, nullptr);
864     bool isMaxTimes = false;
865 
866     repeatKey.ability.bundleName = "bundleName4";
867     handler.repeatKeyTimerIds_["bundleName1"] = 1;
868     handler.repeatKeyTimerIds_["bundleName2"] = 2;
869     handler.repeatKeyTimerIds_["bundleName3"] = 3;
870 
871     handler.repeatTimerId_ = 2;
872     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, isMaxTimes));
873     handler.repeatTimerId_ = -1;
874     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, isMaxTimes));
875 }
876 
877 /**
878  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyAbility_005
879  * @tc.desc: HandleRepeatKeyAbility
880  * @tc.type: FUNC
881  * @tc.require:
882  */
883 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyAbility_005, TestSize.Level1)
884 {
885     CALL_TEST_DEBUG;
886     KeyCommandHandler handler;
887     RepeatKey repeatKey;
888     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
889     ASSERT_NE(keyEvent, nullptr);
890     bool isMaxTimes = true;
891     ASSERT_TRUE(handler.HandleRepeatKeyAbility(repeatKey, keyEvent, isMaxTimes));
892 }
893 
894 /**
895  * @tc.name: KeyCommandHandlerTest_OnHandleEvent_002
896  * @tc.desc: Test the funcation OnHandleEvent
897  * @tc.type: FUNC
898  * @tc.require:
899  */
900 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_002, TestSize.Level1)
901 {
902     CALL_TEST_DEBUG;
903     KeyCommandHandler handler;
904     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
905     ASSERT_NE(key, nullptr);
906     key->SetKeyCode(18);
907     handler.specialKeys_.insert(std::make_pair(18, 18));
908     bool ret = handler.OnHandleEvent(key);
909     EXPECT_TRUE(ret);
910     key->SetKeyCode(KeyEvent::KEYCODE_POWER);
911     handler.specialTimers_.insert(std::make_pair(KeyEvent::KEYCODE_POWER, 10));
912     ret = handler.OnHandleEvent(key);
913     EXPECT_TRUE(ret);
914     key->SetKeyCode(5);
915     ret = handler.OnHandleEvent(key);
916     EXPECT_FALSE(ret);
917 }
918 
919 /**
920  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_006
921  * @tc.desc: Test the funcation HandleShortKeys
922  * @tc.type: FUNC
923  * @tc.require:
924  */
925 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_006, TestSize.Level1)
926 {
927     KeyCommandHandler handler;
928     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
929     ASSERT_NE(keyEvent, nullptr);
930     ShortcutKey key;
931     key.preKeys = {2, 3, 4};
932     key.businessId = "business";
933     key.statusConfig = "config";
934     key.statusConfigValue = true;
935     key.finalKey = 6;
936     key.keyDownDuration = 7;
937     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
938     key.timerId = 10;
939     handler.shortcutKeys_.insert(std::make_pair("key1", key));
940     bool ret = handler.HandleShortKeys(keyEvent);
941     ASSERT_FALSE(ret);
942     handler.currentLaunchAbilityKey_.businessId = "business1";
943     handler.currentLaunchAbilityKey_.statusConfig = "config1";
944     handler.currentLaunchAbilityKey_.timerId = 6;
945     handler.currentLaunchAbilityKey_.statusConfigValue = true;
946     handler.currentLaunchAbilityKey_.finalKey = 4;
947     handler.currentLaunchAbilityKey_.keyDownDuration = 5;
948     handler.currentLaunchAbilityKey_.triggerType = KeyEvent::KEY_ACTION_DOWN;
949     keyEvent->SetKeyCode(KeyEvent::INTENTION_RIGHT);
950     keyEvent->SetKeyAction(KeyEvent::INTENTION_UP);
951     SequenceKey sequenceKey;
952     sequenceKey.keyCode = 2017;
953     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
954     handler.keys_.push_back(sequenceKey);
955     sequenceKey.keyCode = 2022;
956     sequenceKey.keyAction = KeyEvent::INTENTION_UP;
957     handler.keys_.push_back(sequenceKey);
958     EventLogHelper eventLogHelper;
959     eventLogHelper.userType_ = "beta";
960     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
961     EXPECT_NE(inputEvent, nullptr);
962     inputEvent->bitwise_ = 0x00000040;
963     ret = handler.HandleShortKeys(keyEvent);
964     ASSERT_FALSE(ret);
965     eventLogHelper.userType_ = "abcde";
966     ret = handler.HandleShortKeys(keyEvent);
967     ASSERT_FALSE(ret);
968     inputEvent->bitwise_ = 0x00000000;
969     ret = handler.HandleShortKeys(keyEvent);
970     ASSERT_FALSE(ret);
971     handler.lastMatchedKey_.timerId = -5;
972     ret = handler.HandleShortKeys(keyEvent);
973     ASSERT_FALSE(ret);
974 }
975 
976 /**
977  * @tc.name: KeyCommandHandlerTest_HandlePointerEvent_002
978  * @tc.desc: Test the funcation HandlePointerEvent
979  * @tc.type: FUNC
980  * @tc.require:
981  */
982 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerEvent_002, TestSize.Level1)
983 {
984     CALL_TEST_DEBUG;
985     KeyCommandHandler handler;
986     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
987     ASSERT_TRUE(pointerEvent != nullptr);
988     handler.isParseConfig_ = true;
989     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
990     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
991 
992     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP);
993     EventLogHelper eventLogHelper;
994     eventLogHelper.userType_ = "beta";
995     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
996     EXPECT_NE(inputEvent, nullptr);
997     inputEvent->bitwise_ = 0;
998     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
999     eventLogHelper.userType_ = "default";
1000     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1001     inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
1002     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
1003 }
1004 
1005 /**
1006  * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_003
1007  * @tc.desc: Test the funcation StartTwoFingerGesture
1008  * @tc.type: FUNC
1009  * @tc.require:
1010  */
1011 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_003, TestSize.Level1)
1012 {
1013     CALL_TEST_DEBUG;
1014     KeyCommandHandler handler;
1015     handler.twoFingerGesture_.active = true;
1016     handler.twoFingerGesture_.touches[0].downTime = 150000;
1017     handler.twoFingerGesture_.touches[0].id = 10;
1018     handler.twoFingerGesture_.touches[0].x = 100;
1019     handler.twoFingerGesture_.touches[0].y = 200;
1020     handler.twoFingerGesture_.touches[1].downTime = 100000;
1021     handler.twoFingerGesture_.touches[0].id = 5;
1022     handler.twoFingerGesture_.touches[0].x = 50;
1023     handler.twoFingerGesture_.touches[0].y = 100;
1024     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1025     handler.twoFingerGesture_.touches[0].downTime = 350000;
1026     handler.twoFingerGesture_.touches[1].downTime = 100000;
1027     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1028     handler.twoFingerGesture_.active = false;
1029     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1030 }
1031 
1032 /**
1033  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_006
1034  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1035  * @tc.type: FUNC
1036  * @tc.require:
1037  */
1038 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_006, TestSize.Level1)
1039 {
1040     CALL_TEST_DEBUG;
1041     KeyCommandHandler handler;
1042     handler.twoFingerGesture_.active = true;
1043     handler.twoFingerGesture_.touches[0].id = 1;
1044     handler.twoFingerGesture_.touches[0].x = 30;
1045     handler.twoFingerGesture_.touches[0].y = 20;
1046     handler.twoFingerGesture_.touches[0].downTime = 150000;
1047     handler.twoFingerGesture_.touches[1].id = 2;
1048     handler.twoFingerGesture_.touches[1].x = 20;
1049     handler.twoFingerGesture_.touches[1].y = 10;
1050     handler.twoFingerGesture_.touches[1].downTime = 100000;
1051     InputWindowsManager inputWindowsManager;
1052     OLD::DisplayInfo displayInfo;
1053     displayInfo.dpi = 320;
1054     displayInfo.width = 150;
1055     displayInfo.height = 300;
1056     displayInfo.uniq = "default0";
1057     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
1058     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
1059         it->second.displaysInfo.push_back(displayInfo);
1060     }
1061     bool ret = handler.CheckTwoFingerGestureAction();
1062     EXPECT_FALSE(ret);
1063     handler.twoFingerGesture_.touches[0].x = 30;
1064     handler.twoFingerGesture_.touches[0].y = 200;
1065     handler.twoFingerGesture_.touches[1].x = 60;
1066     handler.twoFingerGesture_.touches[1].y = 170;
1067     ret = handler.CheckTwoFingerGestureAction();
1068     EXPECT_FALSE(ret);
1069     handler.twoFingerGesture_.touches[0].x = 120;
1070     ret = handler.CheckTwoFingerGestureAction();
1071     EXPECT_FALSE(ret);
1072     handler.twoFingerGesture_.touches[0].x = 90;
1073     handler.twoFingerGesture_.touches[0].y = 120;
1074     ret = handler.CheckTwoFingerGestureAction();
1075     EXPECT_FALSE(ret);
1076     handler.twoFingerGesture_.touches[0].y = 250;
1077     ret = handler.CheckTwoFingerGestureAction();
1078     EXPECT_FALSE(ret);
1079 }
1080 
1081 /**
1082  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_007
1083  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1084  * @tc.type: FUNC
1085  * @tc.require:
1086  */
1087 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_007, TestSize.Level1)
1088 {
1089     CALL_TEST_DEBUG;
1090     KeyCommandHandler handler;
1091     handler.twoFingerGesture_.active = true;
1092     handler.twoFingerGesture_.touches[0].x = 90;
1093     handler.twoFingerGesture_.touches[0].y = 200;
1094     handler.twoFingerGesture_.touches[0].downTime = 150000;
1095     handler.twoFingerGesture_.touches[1].x = 30;
1096     handler.twoFingerGesture_.touches[1].y = 170;
1097     handler.twoFingerGesture_.touches[1].downTime = 100000;
1098     InputWindowsManager inputWindowsManager;
1099     OLD::DisplayInfo displayInfo;
1100     displayInfo.dpi = 320;
1101     displayInfo.width = 150;
1102     displayInfo.height = 300;
1103     displayInfo.uniq = "default0";
1104     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
1105     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
1106         it->second.displaysInfo.push_back(displayInfo);
1107     }
1108     handler.twoFingerGesture_.touches[0].y = 200;
1109     handler.twoFingerGesture_.touches[1].x = 30;
1110     bool ret = handler.CheckTwoFingerGestureAction();
1111     EXPECT_FALSE(ret);
1112     handler.twoFingerGesture_.touches[1].x = 130;
1113     ret = handler.CheckTwoFingerGestureAction();
1114     EXPECT_FALSE(ret);
1115     handler.twoFingerGesture_.touches[1].x = 60;
1116     handler.twoFingerGesture_.touches[1].y = 100;
1117     ret = handler.CheckTwoFingerGestureAction();
1118     EXPECT_FALSE(ret);
1119     handler.twoFingerGesture_.touches[1].y = 250;
1120     ret = handler.CheckTwoFingerGestureAction();
1121     EXPECT_FALSE(ret);
1122     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1123     handler.twoFingerGesture_.touches[1].y = 170;
1124     ret = handler.CheckTwoFingerGestureAction();
1125     EXPECT_FALSE(ret);
1126     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1127 }
1128 
1129 /**
1130  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_008
1131  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
1132  * @tc.type: FUNC
1133  * @tc.require:
1134  */
1135 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_008, TestSize.Level1)
1136 {
1137     CALL_TEST_DEBUG;
1138     KeyCommandHandler handler;
1139     handler.twoFingerGesture_.active = true;
1140     auto firstFinger = handler.twoFingerGesture_.touches[0];
1141     auto secondFinger = handler.twoFingerGesture_.touches[1];
1142 
1143     int64_t firstTime = firstFinger.downTime;
1144     firstTime = 150000;
1145     int64_t secondTime = secondFinger.downTime;
1146     secondTime = 200000;
1147     auto pressTimeInterval = fabs(firstTime - secondTime);
1148     EXPECT_FALSE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
1149     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1150 
1151     int32_t firstFingerX = firstFinger.x;
1152     firstFingerX = 90;
1153     int32_t firstFingerY = firstFinger.y;
1154     firstFingerY = 200;
1155     int32_t secondFingerX = secondFinger.x;
1156     secondFingerX = 30;
1157     int32_t secondFingerY = secondFinger.y;
1158     secondFingerY = 170;
1159     int32_t devX = firstFingerX - secondFingerX;
1160     int32_t devY = firstFingerY - secondFingerY;
1161     auto distance = sqrt(pow(devX, 2) + pow(devY, 2));
1162     EXPECT_FALSE(distance < handler.ConvertVPToPX(TWO_FINGERS_DISTANCE_LIMIT));
1163     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1164 
1165     auto leftLimit = handler.ConvertVPToPX(TOUCH_LIFT_LIMIT);
1166     firstFingerX = -10;
1167     EXPECT_TRUE(firstFingerX <= leftLimit);
1168     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1169 
1170     InputWindowsManager inputWindowsManager;
1171     OLD::DisplayInfo displayInfo;
1172     displayInfo.dpi = 320;
1173     displayInfo.width = 10;
1174     displayInfo.height = 30;
1175     inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo);
1176     auto rightLimit = displayInfo.width - handler.ConvertVPToPX(TOUCH_RIGHT_LIMIT);
1177     firstFingerX = 50;
1178     EXPECT_TRUE(firstFingerX >= rightLimit);
1179     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1180 
1181     auto topLimit = handler.ConvertVPToPX(TOUCH_TOP_LIMIT);
1182     firstFingerY = -20;
1183     EXPECT_TRUE(firstFingerY <= topLimit);
1184     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1185 
1186     auto bottomLimit = displayInfo.height - handler.ConvertVPToPX(TOUCH_BOTTOM_LIMIT);
1187     firstFingerY = 60;
1188     EXPECT_TRUE(firstFingerY >= bottomLimit);
1189     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1190 
1191     secondFingerX = -5;
1192     EXPECT_TRUE(secondFingerX <= leftLimit);
1193     secondFingerX = 30;
1194     EXPECT_TRUE(secondFingerX >= rightLimit);
1195     secondFingerY = -1;
1196     EXPECT_TRUE(secondFingerY <= topLimit);
1197     secondFingerY = 50;
1198     EXPECT_TRUE(secondFingerY >= bottomLimit);
1199     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1200 }
1201 
1202 /**
1203  * @tc.name: KeyCommandHandlerTest_IsKeyMatch_01
1204  * @tc.desc: Test the funcation IsKeyMatch
1205  * @tc.type: FUNC
1206  * @tc.require:
1207  */
1208 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsKeyMatch_01, TestSize.Level1)
1209 {
1210     KeyCommandHandler handler;
1211     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1212     ASSERT_NE(keyEvent, nullptr);
1213     ShortcutKey shortcutKey;
1214     std::vector<ShortcutKey> upAbilities;
1215     shortcutKey.statusConfigValue = true;
1216     shortcutKey.finalKey = 2076;
1217     shortcutKey.keyDownDuration = 0;
1218     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
1219     keyEvent->keyCode_ = 2076;
1220     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1221 
1222     shortcutKey.preKeys = {2076, 2077};
1223     KeyEvent::KeyItem item;
1224     item.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1225     item.SetKeyCode(KeyEvent::KEYCODE_META_RIGHT);
1226     item.SetKeyCode(KeyEvent::KEYCODE_FUNCTION);
1227     keyEvent->AddKeyItem(item);
1228     EXPECT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
1229 }
1230 
1231 /**
1232  * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_01
1233  * @tc.desc: Test the funcation StartTwoFingerGesture
1234  * @tc.type: FUNC
1235  * @tc.require:
1236  */
1237 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_01, TestSize.Level1)
1238 {
1239     CALL_TEST_DEBUG;
1240     KeyCommandHandler handler;
1241     handler.twoFingerGesture_.active = false;
1242     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1243     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1244 }
1245 
1246 /**
1247  * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_02
1248  * @tc.desc: Test the funcation StartTwoFingerGesture
1249  * @tc.type: FUNC
1250  * @tc.require:
1251  */
1252 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_02, TestSize.Level1)
1253 {
1254     CALL_TEST_DEBUG;
1255     KeyCommandHandler handler;
1256     handler.twoFingerGesture_.active = true;
1257     EXPECT_FALSE(handler.CheckTwoFingerGestureAction());
1258     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
1259 }
1260 
1261 /**
1262  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_004
1263  * @tc.desc: Test the funcation ConvertVPToPX
1264  * @tc.type: FUNC
1265  * @tc.require:
1266  */
1267 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_004, TestSize.Level1)
1268 {
1269     CALL_TEST_DEBUG;
1270     KeyCommandHandler handler;
1271     int32_t vp = 10;
1272     InputWindowsManager inputWindowsManager;
1273     OLD::DisplayInfo displayInfo;
1274     displayInfo.dpi = -10;
1275     displayInfo.uniq = "default0";
1276     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
1277     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
1278         it->second.displaysInfo.push_back(displayInfo);
1279     }
1280     int32_t ret = handler.ConvertVPToPX(vp);
1281     ASSERT_EQ(ret, 0);
1282     displayInfo.dpi = 160;
1283     it->second.displaysInfo.push_back(displayInfo);
1284     ret = handler.ConvertVPToPX(vp);
1285     ASSERT_EQ(ret, 0);
1286 }
1287 
1288 /**
1289  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_004
1290  * @tc.desc: Test the funcation HandleKnuckleGestureEvent
1291  * @tc.type: FUNC
1292  * @tc.require:
1293  */
1294 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_004, TestSize.Level1)
1295 {
1296     CALL_TEST_DEBUG;
1297     KeyCommandHandler handler;
1298     PointerEvent::PointerItem item;
1299     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1300     ASSERT_NE(touchEvent, nullptr);
1301     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1302     handler.singleKnuckleGesture_.state = false;
1303     handler.gameForbidFingerKnuckle_ = false;
1304     touchEvent->AddPointerItem(item);
1305     touchEvent->SetPointerId(1);
1306     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
1307     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1308     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1309     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1310     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1311     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1312     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1313     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1314     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN);
1315     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1316     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
1317     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1318     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_END);
1319     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1320     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1321     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1322     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP);
1323     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
1324 }
1325 
1326 /**
1327  * @tc.name: KeyCommandHandlerTest_OnHandleTouchEvent
1328  * @tc.desc: Test OnHandleTouchEvent
1329  * @tc.type: FUNC
1330  * @tc.require:
1331  */
1332 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleTouchEvent, TestSize.Level1)
1333 {
1334     CALL_TEST_DEBUG;
1335     KeyCommandHandler handler;
1336     PointerEvent::PointerItem item;
1337     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1338     ASSERT_NE(touchEvent, nullptr);
1339     handler.isParseConfig_ = false;
1340     handler.isDistanceConfig_ = false;
1341     handler.isKnuckleSwitchConfig_ = true;
1342     item.SetPointerId(1);
1343     item.SetToolType(PointerEvent::TOOL_TYPE_PENCIL);
1344     touchEvent->AddPointerItem(item);
1345     touchEvent->SetPointerId(1);
1346     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1347     ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1348 
1349     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1350     ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1351 
1352     touchEvent->RemovePointerItem(1);
1353     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1354     ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1355 
1356     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1357     ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
1358 }
1359 
1360 /**
1361  * @tc.name: KeyCommandHandlerTest_HandlePointerActionMoveEvent
1362  * @tc.desc: Test HandlePointerActionMoveEvent
1363  * @tc.type: FUNC
1364  * @tc.require:
1365  */
1366 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerActionMoveEvent, TestSize.Level1)
1367 {
1368     CALL_TEST_DEBUG;
1369     KeyCommandHandler handler;
1370     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1371     ASSERT_NE(touchEvent, nullptr);
1372     handler.twoFingerGesture_.active = true;
1373     handler.twoFingerGesture_.timerId = -1;
1374     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1375 
1376     touchEvent->SetPointerId(2);
1377     handler.twoFingerGesture_.timerId = 1;
1378     handler.twoFingerGesture_.touches->id = 1;
1379     handler.twoFingerGesture_.touches->x = 25;
1380     handler.twoFingerGesture_.touches->y = 25;
1381     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1382 
1383     touchEvent->SetPointerId(1);
1384     PointerEvent::PointerItem item;
1385     item.SetDisplayX(5);
1386     item.SetDisplayY(5);
1387     touchEvent->AddPointerItem(item);
1388     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerActionMoveEvent(touchEvent));
1389 }
1390 
1391 /**
1392  * @tc.name: KeyCommandHandlerTest_HandleFingerGestureDownEvent
1393  * @tc.desc: Test HandleFingerGestureDownEvent
1394  * @tc.type: FUNC
1395  * @tc.require:
1396  */
1397 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleFingerGestureDownEvent, TestSize.Level1)
1398 {
1399     CALL_TEST_DEBUG;
1400     KeyCommandHandler handler;
1401     PointerEvent::PointerItem item;
1402     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1403     ASSERT_NE(touchEvent, nullptr);
1404     handler.twoFingerGesture_.active = true;
1405     item.SetPointerId(1);
1406     item.SetDisplayX(10);
1407     item.SetDisplayY(10);
1408     touchEvent->AddPointerItem(item);
1409     touchEvent->SetPointerId(1);
1410     ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1411 
1412     item.SetPointerId(2);
1413     item.SetDisplayX(15);
1414     item.SetDisplayY(15);
1415     touchEvent->AddPointerItem(item);
1416     ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1417 
1418     handler.twoFingerGesture_.active = true;
1419     handler.twoFingerGesture_.timerId = 150;
1420     ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureUpEvent(touchEvent));
1421 }
1422 
1423 /**
1424  * @tc.name: KeyCommandHandlerTest_HandleFingerGestureDownEvent_001
1425  * @tc.desc: Test HandleFingerGestureDownEvent
1426  * @tc.type: FUNC
1427  * @tc.require:
1428  */
1429 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleFingerGestureDownEvent_001, TestSize.Level1)
1430 {
1431     CALL_TEST_DEBUG;
1432     KeyCommandHandler handler;
1433     PointerEvent::PointerItem item;
1434     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1435     ASSERT_NE(touchEvent, nullptr);
1436     handler.twoFingerGesture_.active = true;
1437     ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1438 
1439     item.SetPointerId(1);
1440     touchEvent->AddPointerItem(item);
1441     item.SetPointerId(2);
1442     touchEvent->AddPointerItem(item);
1443     item.SetPointerId(3);
1444     touchEvent->AddPointerItem(item);
1445     ASSERT_NO_FATAL_FAILURE(handler.HandleFingerGestureDownEvent(touchEvent));
1446 }
1447 
1448 /**
1449  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_001
1450  * @tc.desc: Test HandleKnuckleGestureDownEvent_001
1451  * @tc.type: FUNC
1452  * @tc.require:
1453  */
1454 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_001, TestSize.Level1)
1455 {
1456     CALL_TEST_DEBUG;
1457     KeyCommandHandler handler;
1458     PointerEvent::PointerItem item;
1459     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1460     ASSERT_NE(touchEvent, nullptr);
1461     handler.twoFingerGesture_.active = true;
1462     item.SetPointerId(1);
1463     item.SetToolType(PointerEvent::TOOL_TYPE_PALM);
1464     touchEvent->AddPointerItem(item);
1465     touchEvent->SetPointerId(1);
1466     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1467 
1468     item.SetPointerId(2);
1469     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1470     touchEvent->AddPointerItem(item);
1471     item.SetPointerId(3);
1472     touchEvent->AddPointerItem(item);
1473     touchEvent->SetPointerId(2);
1474     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1475 
1476     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureUpEvent(touchEvent));
1477 }
1478 
1479 /**
1480  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_002
1481  * @tc.desc: Test HandleKnuckleGestureDownEvent_002
1482  * @tc.type: FUNC
1483  * @tc.require:
1484  */
1485 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_002, TestSize.Level1)
1486 {
1487     CALL_TEST_DEBUG;
1488     KeyCommandHandler handler;
1489     PointerEvent::PointerItem item;
1490     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1491     ASSERT_NE(touchEvent, nullptr);
1492     handler.twoFingerGesture_.active = true;
1493     handler.gameForbidFingerKnuckle_ = true;
1494 
1495     item.SetPointerId(2);
1496     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1497     touchEvent->AddPointerItem(item);
1498     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1499 }
1500 
1501 /**
1502  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_003
1503  * @tc.desc: Test HandleKnuckleGestureDownEvent_003
1504  * @tc.type: FUNC
1505  * @tc.require:
1506  */
1507 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_003, TestSize.Level1)
1508 {
1509     CALL_TEST_DEBUG;
1510     KeyCommandHandler handler;
1511     PointerEvent::PointerItem item;
1512     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1513     ASSERT_NE(touchEvent, nullptr);
1514     handler.twoFingerGesture_.active = true;
1515     handler.gameForbidFingerKnuckle_ = false;
1516 
1517     item.SetPointerId(2);
1518     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
1519     touchEvent->AddPointerItem(item);
1520     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
1521 }
1522 
1523 /**
1524  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureUpEvent
1525  * @tc.desc: Test HandleKnuckleGestureUpEvent
1526  * @tc.type: FUNC
1527  * @tc.require:
1528  */
1529 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureUpEvent, TestSize.Level1)
1530 {
1531     CALL_TEST_DEBUG;
1532     KeyCommandHandler handler;
1533     PointerEvent::PointerItem item;
1534     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1535     ASSERT_NE(touchEvent, nullptr);
1536     item.SetPointerId(1);
1537     touchEvent->AddPointerItem(item);
1538     handler.isDoubleClick_ = true;
1539     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureUpEvent(touchEvent));
1540 }
1541 
1542 /**
1543  * @tc.name: KeyCommandHandlerTest_KnuckleGestureProcessor
1544  * @tc.desc: Test KnuckleGestureProcessor
1545  * @tc.type: FUNC
1546  * @tc.require:
1547  */
1548 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleGestureProcessor, TestSize.Level1)
1549 {
1550     CALL_TEST_DEBUG;
1551     KeyCommandHandler handler;
1552     KnuckleGesture knuckleGesture;
1553     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
1554     ASSERT_NE(touchEvent, nullptr);
1555     knuckleGesture.lastPointerDownEvent = touchEvent;
1556     knuckleGesture.lastPointerUpTime = 10;
1557     touchEvent->SetActionTime(5);
1558     handler.knuckleCount_ = 2;
1559     ASSERT_NO_FATAL_FAILURE(
1560         handler.KnuckleGestureProcessor(touchEvent, knuckleGesture, KnuckleType::KNUCKLE_TYPE_SINGLE));
1561 }
1562 
1563 /**
1564  * @tc.name: KeyCommandHandlerTest_HandleMultiTapTest__001
1565  * @tc.desc: Test three fingers tap event launch ability
1566  * @tc.type: FUNC
1567  * @tc.require:
1568  */
1569 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMultiTapTest__001, TestSize.Level1)
1570 {
1571     CALL_TEST_DEBUG;
1572     auto threeFingerTap = SetupThreeFingerTapEvent();
1573     ASSERT_TRUE(threeFingerTap != nullptr);
1574     KeyCommandHandler keyCommandHandler;
1575     ASSERT_TRUE(keyCommandHandler.OnHandleEvent(threeFingerTap));
1576 }
1577 
1578 /**
1579  * @tc.name: KeyCommandHandlerTest_HandleMultiTapTest__002
1580  * @tc.desc: Test four fingers tap event launch ability
1581  * @tc.type: FUNC
1582  * @tc.require:
1583  */
1584 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMultiTapTest__002, TestSize.Level1)
1585 {
1586     CALL_TEST_DEBUG;
1587     auto fourFingerTap = SetupFourFingerTapEvent();
1588     ASSERT_TRUE(fourFingerTap != nullptr);
1589     KeyCommandHandler keyCommandHandler;
1590     ASSERT_FALSE(keyCommandHandler.OnHandleEvent(fourFingerTap));
1591 }
1592 
1593 /**
1594  * @tc.name: KeyCommandHandlerTest_001
1595  * @tc.desc: Test update key down duration 0, 100, 4000
1596  * @tc.type: FUNC
1597  * @tc.require:
1598  */
1599 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_001, TestSize.Level1)
1600 {
1601     CALL_TEST_DEBUG;
1602     KeyCommandHandler eventKeyCommandHandler;
1603     std::string businessId = "aaa";
1604     int32_t delay = 0;
1605     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1606     delay = 100;
1607     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1608     delay = 4000;
1609     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1610 }
1611 
1612 /**
1613  * @tc.name: KeyCommandHandlerTest_EnableCombineKey_001
1614  * @tc.desc: Test enable combineKey
1615  * @tc.type: FUNC
1616  * @tc.require:
1617  */
1618 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_EnableCombineKey_001, TestSize.Level1)
1619 {
1620     CALL_TEST_DEBUG;
1621     KeyCommandHandler eventKeyCommandHandler;
1622     ASSERT_EQ(eventKeyCommandHandler.EnableCombineKey(true), RET_OK);
1623 }
1624 
1625 /**
1626  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_001
1627  * @tc.desc: Test IsEnableCombineKey
1628  * @tc.type: FUNC
1629  * @tc.require:
1630  */
1631 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_001, TestSize.Level1)
1632 {
1633     CALL_TEST_DEBUG;
1634     KeyCommandHandler eventKeyCommandHandler;
1635     eventKeyCommandHandler.EnableCombineKey(false);
1636     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1637     CHKPV(keyEvent);
1638     KeyEvent::KeyItem item;
1639     item.SetKeyCode(KeyEvent::KEYCODE_POWER);
1640     keyEvent->AddKeyItem(item);
1641     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1642     ASSERT_EQ(eventKeyCommandHandler.OnHandleEvent(keyEvent), false);
1643     eventKeyCommandHandler.EnableCombineKey(true);
1644 }
1645 
1646 /**
1647  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_002
1648  * @tc.desc: Test IsEnableCombineKey
1649  * @tc.type: FUNC
1650  * @tc.require:
1651  */
1652 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_002, TestSize.Level1)
1653 {
1654     CALL_TEST_DEBUG;
1655     KeyCommandHandler eventKeyCommandHandler;
1656     eventKeyCommandHandler.EnableCombineKey(false);
1657     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1658     CHKPV(keyEvent);
1659     KeyEvent::KeyItem item1;
1660     item1.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1661     keyEvent->AddKeyItem(item1);
1662     KeyEvent::KeyItem item2;
1663     item2.SetKeyCode(KeyEvent::KEYCODE_L);
1664     keyEvent->AddKeyItem(item2);
1665     keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1666     ASSERT_EQ(eventKeyCommandHandler.OnHandleEvent(keyEvent), false);
1667     eventKeyCommandHandler.EnableCombineKey(true);
1668 }
1669 
1670 /**
1671  * @tc.name: KeyCommandHandlerTest_002
1672  * @tc.desc: Test update key down duration -1 and 4001
1673  * @tc.type: FUNC
1674  * @tc.require:
1675  */
1676 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_002, TestSize.Level1)
1677 {
1678     CALL_TEST_DEBUG;
1679     KeyCommandHandler eventKeyCommandHandler;
1680     std::string businessId = "com.ohos.camera";
1681     int32_t delay = -1;
1682     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1683     delay = 4001;
1684     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1685 }
1686 
1687 /**
1688  * @tc.name: KeyCommandHandlerTest_003
1689  * @tc.desc: Test businessId is ""
1690  * @tc.type: FUNC
1691  * @tc.require:
1692  */
1693 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_003, TestSize.Level1)
1694 {
1695     CALL_TEST_DEBUG;
1696     KeyCommandHandler eventKeyCommandHandler;
1697     std::string businessId = "";
1698     int32_t delay = 100;
1699     ASSERT_EQ(COMMON_PARAMETER_ERROR, eventKeyCommandHandler.UpdateSettingsXml(businessId, delay));
1700 }
1701 
1702 /**
1703  * @tc.name: KeyCommandHandlerTest_004
1704  * @tc.desc: Test key event
1705  * @tc.type: FUNC
1706  * @tc.require:
1707  */
1708 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_004, TestSize.Level1)
1709 {
1710     CALL_TEST_DEBUG;
1711     auto keyEvent = SetupKeyEvent();
1712     ASSERT_TRUE(keyEvent != nullptr);
1713     KeyCommandHandler eventKeyCommandHandler;
1714     ASSERT_FALSE(eventKeyCommandHandler.OnHandleEvent(keyEvent));
1715 }
1716 
1717 /**
1718  * @tc.name: KeyCommandHandlerTest_HandleEvent_01
1719  * @tc.desc: Test HandleEvent
1720  * @tc.type: FUNC
1721  * @tc.require:
1722  */
1723 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_01, TestSize.Level1)
1724 {
1725     CALL_TEST_DEBUG;
1726     auto keyEvent = SetupKeyEvent();
1727     ASSERT_TRUE(keyEvent != nullptr);
1728     KeyCommandHandler eventKeyCommandHandler;
1729 
1730     bool preHandleEvent = eventKeyCommandHandler.PreHandleEvent(keyEvent);
1731     EXPECT_TRUE(preHandleEvent);
1732     bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1733     EXPECT_FALSE(ret);
1734 }
1735 
1736 /**
1737  * @tc.name: KeyCommandHandlerTest_HandleEvent_02
1738  * @tc.desc: Test HandleEvent
1739  * @tc.type: FUNC
1740  * @tc.require:
1741  */
1742 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_02, TestSize.Level1)
1743 {
1744     CALL_TEST_DEBUG;
1745     auto keyEvent = SetupKeyEvent();
1746     ASSERT_TRUE(keyEvent != nullptr);
1747     KeyCommandHandler eventKeyCommandHandler;
1748 
1749     bool stylusKey = STYLUS_HANDLER->HandleStylusKey(keyEvent);
1750     EXPECT_FALSE(stylusKey);
1751     bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1752     EXPECT_FALSE(ret);
1753 }
1754 
1755 /**
1756  * @tc.name: KeyCommandHandlerTest_HandleEvent_03
1757  * @tc.desc: Test HandleEvent
1758  * @tc.type: FUNC
1759  * @tc.require:
1760  */
1761 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_03, TestSize.Level1)
1762 {
1763     CALL_TEST_DEBUG;
1764     auto keyEvent = SetupKeyEvent();
1765     ASSERT_TRUE(keyEvent != nullptr);
1766     KeyCommandHandler eventKeyCommandHandler;
1767 
1768     bool isHandled = eventKeyCommandHandler.HandleShortKeys(keyEvent);
1769     EXPECT_FALSE(isHandled);
1770     bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1771     EXPECT_FALSE(ret);
1772 }
1773 
1774 /**
1775  * @tc.name: KeyCommandHandlerTest_HandleEvent_04
1776  * @tc.desc: Test HandleEvent
1777  * @tc.type: FUNC
1778  * @tc.require:
1779  */
1780 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_04, TestSize.Level1)
1781 {
1782     CALL_TEST_DEBUG;
1783     auto keyEvent = SetupKeyEvent();
1784     ASSERT_TRUE(keyEvent != nullptr);
1785     KeyCommandHandler eventKeyCommandHandler;
1786 
1787     eventKeyCommandHandler.isDownStart_ = true;
1788     bool isRepeatKeyHandle = eventKeyCommandHandler.HandleRepeatKeys(keyEvent);
1789     EXPECT_FALSE(isRepeatKeyHandle);
1790     bool ret = eventKeyCommandHandler.HandleEvent(keyEvent);
1791     EXPECT_FALSE(ret);
1792 }
1793 
1794 /**
1795  * @tc.name: KeyCommandHandlerTest_HandleEvent_05
1796  * @tc.desc: Test HandleEvent
1797  * @tc.type: FUNC
1798  * @tc.require:
1799  */
1800 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_05, TestSize.Level1)
1801 {
1802     CALL_TEST_DEBUG;
1803     auto keyEvent = KeyEvent::Create();
1804     ASSERT_TRUE(keyEvent != nullptr);
1805     KeyCommandHandler keyCommandHandler;
1806     EXPECT_TRUE(keyCommandHandler.PreHandleEvent(keyEvent));
1807     EXPECT_FALSE(STYLUS_HANDLER->HandleStylusKey(keyEvent));
1808     EXPECT_FALSE(keyCommandHandler.HandleShortKeys(keyEvent));
1809 
1810     bool ret = keyCommandHandler.HandleEvent(keyEvent);
1811     EXPECT_FALSE(ret);
1812 }
1813 
1814 /**
1815  * @tc.name: KeyCommandHandlerTest_HandleEvent_06
1816  * @tc.desc: Test HandleEvent
1817  * @tc.type: FUNC
1818  * @tc.require:
1819  */
1820 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_06, TestSize.Level1)
1821 {
1822     CALL_TEST_DEBUG;
1823     auto keyEvent = KeyEvent::Create();
1824     ASSERT_TRUE(keyEvent != nullptr);
1825     KeyCommandHandler keyCommandHandler;
1826     EXPECT_TRUE(keyCommandHandler.PreHandleEvent(keyEvent));
1827     EXPECT_FALSE(STYLUS_HANDLER->HandleStylusKey(keyEvent));
1828     EXPECT_FALSE(keyCommandHandler.HandleShortKeys(keyEvent));
1829     EXPECT_FALSE(keyCommandHandler.HandleSequences(keyEvent));
1830     keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
1831 
1832     bool ret = keyCommandHandler.HandleEvent(keyEvent);
1833     EXPECT_FALSE(ret);
1834 }
1835 
1836 /**
1837  * @tc.name: KeyCommandHandlerTest_ParseJson_01
1838  * @tc.desc: Test ParseJson
1839  * @tc.type: FUNC
1840  * @tc.require:
1841  */
1842 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_01, TestSize.Level1)
1843 {
1844     CALL_TEST_DEBUG;
1845     std::string configFile = "abc";
1846     std::string jsonStr = ReadJsonFile(configFile);
1847     KeyCommandHandler eventKeyCommandHandler;
1848 
1849     jsonStr = "";
1850     bool ret = eventKeyCommandHandler.ParseJson(configFile);
1851     EXPECT_TRUE(jsonStr.empty());
1852     EXPECT_FALSE(ret);
1853 }
1854 
1855 /**
1856  * @tc.name: KeyCommandHandlerTest_ParseJson_02
1857  * @tc.desc: Test ParseJson
1858  * @tc.type: FUNC
1859  * @tc.require:
1860  */
1861 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_02, TestSize.Level1)
1862 {
1863     CALL_TEST_DEBUG;
1864     std::string configFile = "config";
1865     std::string jsonStr = ReadJsonFile(configFile);
1866     KeyCommandHandler eventKeyCommandHandler;
1867 
1868     jsonStr = "abc";
1869     bool ret = eventKeyCommandHandler.ParseJson(configFile);
1870     EXPECT_FALSE(jsonStr.empty());
1871     EXPECT_FALSE(ret);
1872 }
1873 
1874 /**
1875  * @tc.name: KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_01
1876  * @tc.desc: Test ProcessKnuckleGestureTouchUp
1877  * @tc.type: FUNC
1878  * @tc.require:
1879  */
1880 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_01, TestSize.Level1)
1881 {
1882     CALL_TEST_DEBUG;
1883     NotifyType type;
1884     KeyCommandHandler handler;
1885     type = NotifyType::REGIONGESTURE;
1886     handler.isStartBase_ = false;
1887     ASSERT_NO_FATAL_FAILURE(handler.ProcessKnuckleGestureTouchUp(type));
1888 
1889     handler.isStartBase_ = true;
1890     ASSERT_NO_FATAL_FAILURE(handler.ProcessKnuckleGestureTouchUp(type));
1891 }
1892 
1893 /**
1894  * @tc.name: KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_02
1895  * @tc.desc: Test ProcessKnuckleGestureTouchUp
1896  * @tc.type: FUNC
1897  * @tc.require:
1898  */
1899 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ProcessKnuckleGestureTouchUp_02, TestSize.Level1)
1900 {
1901     CALL_TEST_DEBUG;
1902     NotifyType type;
1903     KeyCommandHandler eventKeyCommandHandler;
1904     type = NotifyType::LETTERGESTURE;
1905     ASSERT_NO_FATAL_FAILURE(eventKeyCommandHandler.ProcessKnuckleGestureTouchUp(type));
1906 }
1907 
1908 /**
1909  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_01
1910  * @tc.desc: Test CheckTwoFingerGestureAction
1911  * @tc.type: FUNC
1912  * @tc.require:
1913  */
1914 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_01, TestSize.Level1)
1915 {
1916     CALL_TEST_DEBUG;
1917     KeyCommandHandler eventKeyCommandHandler;
1918     bool isActive = eventKeyCommandHandler.twoFingerGesture_.active;
1919     EXPECT_FALSE(isActive);
1920     bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
1921     EXPECT_FALSE(ret);
1922 }
1923 
1924 /**
1925  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_02
1926  * @tc.desc: Test CheckTwoFingerGestureAction
1927  * @tc.type: FUNC
1928  * @tc.require:
1929  */
1930 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_02, TestSize.Level1)
1931 {
1932     CALL_TEST_DEBUG;
1933     KeyCommandHandler eventKeyCommandHandler;
1934     auto pressTimeInterval = fabs(200000 - 40000);
1935     EXPECT_TRUE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
1936     bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
1937     EXPECT_FALSE(ret);
1938 }
1939 
1940 /**
1941  * @tc.name: KeyCommandHandlerTest_Dump
1942  * @tc.desc: Test Dump
1943  * @tc.type: FUNC
1944  * @tc.require:
1945  */
1946 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_Dump, TestSize.Level1)
1947 {
1948     CALL_TEST_DEBUG;
1949     KeyCommandHandler eventKeyCommandHandler;
1950     char temp[] = "/tmp/KeyCommandHandlerTest_DUMP";
1951     int fd = mkstemp(temp);
1952     std::vector<std::string> args;
1953     EXPECT_NO_FATAL_FAILURE(eventKeyCommandHandler.Dump(fd, args));
1954     unlink(temp);
1955 }
1956 
1957 /**
1958  * @tc.name: KeyCommandHandlerTest_PrintGestureInfo
1959  * @tc.desc: Test PrintGestureInfo
1960  * @tc.type: FUNC
1961  * @tc.require:
1962  */
1963 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PrintGestureInfo, TestSize.Level1)
1964 {
1965     CALL_TEST_DEBUG;
1966     KeyCommandHandler eventKeyCommandHandler;
1967     EXPECT_NO_FATAL_FAILURE(eventKeyCommandHandler.PrintGestureInfo(1));
1968 }
1969 
1970 /**
1971  * @tc.name: KeyCommandHandlerTest_RegisterKnuckleSwitchByUserId
1972  * @tc.desc: Test RegisterKnuckleSwitchByUserId
1973  * @tc.type: FUNC
1974  * @tc.require:
1975  */
1976 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterKnuckleSwitchByUserId, TestSize.Level1)
1977 {
1978     CALL_TEST_DEBUG;
1979     KeyCommandHandler eventKeyCommandHandler;
1980     EXPECT_EQ(eventKeyCommandHandler.RegisterKnuckleSwitchByUserId(1), RET_OK);
1981 }
1982 
1983 /**
1984  * @tc.name: KeyCommandHandlerTest_SetKnuckleSwitch
1985  * @tc.desc: Test SetKnuckleSwitch
1986  * @tc.type: FUNC
1987  * @tc.require:
1988  */
1989 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetKnuckleSwitch, TestSize.Level1)
1990 {
1991     CALL_TEST_DEBUG;
1992     KeyCommandHandler eventKeyCommandHandler;
1993     EXPECT_EQ(eventKeyCommandHandler.SetKnuckleSwitch(true), RET_OK);
1994 }
1995 
1996 /**
1997  * @tc.name: KeyCommandHandlerTest_SkipKnuckleDetect
1998  * @tc.desc: Test SkipKnuckleDetect
1999  * @tc.type: FUNC
2000  * @tc.require:
2001  */
2002 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SkipKnuckleDetect, TestSize.Level1)
2003 {
2004     CALL_TEST_DEBUG;
2005     KeyCommandHandler eventKeyCommandHandler;
2006     EXPECT_EQ(eventKeyCommandHandler.SkipKnuckleDetect(), true);
2007 }
2008 
2009 /**
2010  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_03
2011  * @tc.desc: Test CheckTwoFingerGestureAction
2012  * @tc.type: FUNC
2013  * @tc.require:
2014  */
2015 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_03, TestSize.Level1)
2016 {
2017     CALL_TEST_DEBUG;
2018     KeyCommandHandler eventKeyCommandHandler;
2019     auto pressTimeInterval = fabs(200000 - 60000);
2020     EXPECT_FALSE(pressTimeInterval > TWO_FINGERS_TIME_LIMIT);
2021     bool ret = eventKeyCommandHandler.CheckTwoFingerGestureAction();
2022     EXPECT_FALSE(ret);
2023 }
2024 
2025 #ifdef OHOS_BUILD_ENABLE_TOUCH
2026 /**
2027  * @tc.name: KeyCommandHandlerTest_TouchTest_001
2028  * @tc.desc: Test double finger down event
2029  * @tc.type: FUNC
2030  * @tc.require:
2031  */
2032 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchTest_001, TestSize.Level1)
2033 {
2034     CALL_TEST_DEBUG;
2035     auto pointerEvent = SetupDoubleFingerDownEvent();
2036     ASSERT_TRUE(pointerEvent != nullptr);
2037     KeyCommandHandler keyCommandHandler;
2038     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2039     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2040     keyCommandHandler.HandlePointerActionMoveEvent(pointerEvent);
2041     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2042     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2043     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2044     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2045 }
2046 
2047 /**
2048  * @tc.name: KeyCommandHandlerTest_KnuckleTest_001
2049  * @tc.desc: Test single knuckle double click
2050  * @tc.type: FUNC
2051  * @tc.require:
2052  */
2053 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_001, TestSize.Level1)
2054 {
2055     CALL_TEST_DEBUG;
2056     auto pointerEvent = SetupSingleKnuckleDownEvent();
2057     ASSERT_TRUE(pointerEvent != nullptr);
2058     KeyCommandHandler keyCommandHandler;
2059     keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2060     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2061     pointerEvent->SetActionTime(actionTime);
2062     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2063     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2064     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2065     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2066     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2067     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2068     actionTime = actionTime + INTERVAL_TIME;
2069     pointerEvent->SetActionTime(actionTime);
2070     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2071     ASSERT_TRUE(keyCommandHandler.GetSingleKnuckleGesture().state);
2072     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2073     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2074     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2075 }
2076 
2077 /**
2078  * @tc.name: KeyCommandHandlerTest_KnuckleTest_002
2079  * @tc.desc: Test double knuckle double click
2080  * @tc.type: FUNC
2081  * @tc.require:
2082  */
2083 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_002, TestSize.Level1)
2084 {
2085     CALL_TEST_DEBUG;
2086     auto pointerEvent = SetupDoubleKnuckleDownEvent();
2087     ASSERT_TRUE(pointerEvent != nullptr);
2088     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2089     pointerEvent->SetActionTime(actionTime);
2090     KeyCommandHandler keyCommandHandler;
2091     keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2092     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2093     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2094     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2095     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2096     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2097     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2098     actionTime = actionTime + INTERVAL_TIME;
2099     pointerEvent->SetActionTime(actionTime);
2100     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2101     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2102     ASSERT_TRUE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2103 }
2104 
2105 /**
2106  * @tc.name: KeyCommandHandlerTest_KnuckleTest_003
2107  * @tc.desc: Test single knuckle event to double knuckle event
2108  * @tc.type: FUNC
2109  * @tc.require:
2110  */
2111 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_003, TestSize.Level1)
2112 {
2113     CALL_TEST_DEBUG;
2114     auto singlePointerEvent = SetupSingleKnuckleDownEvent();
2115     ASSERT_TRUE(singlePointerEvent != nullptr);
2116     auto pointerEvent = SetupDoubleKnuckleDownEvent();
2117     ASSERT_TRUE(pointerEvent != nullptr);
2118     KeyCommandHandler keyCommandHandler;
2119     keyCommandHandler.HandlePointerActionDownEvent(singlePointerEvent);
2120     singlePointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2121     keyCommandHandler.HandlePointerActionUpEvent(singlePointerEvent);
2122     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2123     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2124     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2125 }
2126 
2127 /**
2128  * @tc.name: KeyCommandHandlerTest_KnuckleTest_004
2129  * @tc.desc: Test sing knuckle double click interval time out
2130  * @tc.type: FUNC
2131  * @tc.require:
2132  */
2133 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_004, TestSize.Level1)
2134 {
2135     CALL_DEBUG_ENTER;
2136     auto pointerEvent = SetupSingleKnuckleDownEvent();
2137     ASSERT_TRUE(pointerEvent != nullptr);
2138     KeyCommandHandler keyCommandHandler;
2139     keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2140     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2141     pointerEvent->SetActionTime(actionTime);
2142     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2143     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2144     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2145     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2146     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2147     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2148     actionTime = actionTime + INTERVAL_TIME_OUT;
2149     pointerEvent->SetActionTime(actionTime);
2150     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2151     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2152     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2153     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2154     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2155 }
2156 
2157 /**
2158  * @tc.name: KeyCommandHandlerTest_KnuckleTest_005
2159  * @tc.desc: Test double knuckle double CLICK click interval time out
2160  * @tc.type: FUNC
2161  * @tc.require:
2162  */
2163 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_005, TestSize.Level1)
2164 {
2165     CALL_DEBUG_ENTER;
2166     auto pointerEvent = SetupDoubleKnuckleDownEvent();
2167     ASSERT_TRUE(pointerEvent != nullptr);
2168     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2169     pointerEvent->SetActionTime(actionTime);
2170     KeyCommandHandler keyCommandHandler;
2171     keyCommandHandler.SetKnuckleDoubleTapDistance(DOUBLE_CLICK_DISTANCE_DEFAULT_CONFIG);
2172     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2173     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2174     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2175     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2176     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2177     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2178     actionTime = actionTime + INTERVAL_TIME_OUT;
2179     pointerEvent->SetActionTime(actionTime);
2180     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2181     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2182     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2183 }
2184 
2185 /**
2186  * @tc.name: KeyCommandHandlerTest_KnuckleTest_006
2187  * @tc.desc: Test the tool type is TOOL_TYPE_TOUCHPAD Action down
2188  * @tc.type: FUNC
2189  * @tc.require:
2190  */
2191 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_006, TestSize.Level1)
2192 {
2193     CALL_DEBUG_ENTER;
2194     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2195     ASSERT_TRUE(pointerEvent != nullptr);
2196     PointerEvent::PointerItem item;
2197     item.SetPointerId(0);
2198     item.SetToolType(PointerEvent::TOOL_TYPE_TOUCHPAD);
2199     int32_t downX = 100;
2200     int32_t downY = 200;
2201     item.SetDisplayX(downX);
2202     item.SetDisplayY(downY);
2203     item.SetPressed(true);
2204     pointerEvent->SetPointerId(0);
2205     pointerEvent->AddPointerItem(item);
2206     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2207     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2208     KeyCommandHandler keyCommandHandler;
2209     keyCommandHandler.HandlePointerActionDownEvent(pointerEvent);
2210     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2211     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2212 }
2213 
2214 /**
2215  * @tc.name: KeyCommandHandlerTest_KnuckleTest_007
2216  * @tc.desc: Test the tool type is TOOL_TYPE_TOUCHPAD Action up
2217  * @tc.type: FUNC
2218  * @tc.require:
2219  */
2220 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleTest_007, TestSize.Level1)
2221 {
2222     CALL_DEBUG_ENTER;
2223     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2224     ASSERT_TRUE(pointerEvent != nullptr);
2225     PointerEvent::PointerItem item;
2226     item.SetPointerId(0);
2227     item.SetToolType(PointerEvent::TOOL_TYPE_TOUCHPAD);
2228     int32_t downX = 100;
2229     int32_t downY = 200;
2230     item.SetDisplayX(downX);
2231     item.SetDisplayY(downY);
2232     item.SetPressed(true);
2233     pointerEvent->SetPointerId(0);
2234     pointerEvent->AddPointerItem(item);
2235     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2236     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2237     KeyCommandHandler keyCommandHandler;
2238     keyCommandHandler.HandlePointerActionUpEvent(pointerEvent);
2239     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2240     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2241 }
2242 
2243 /**
2244  * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_001
2245  * @tc.desc: Test signl knuckle CLICK set HandleTouchEvent pointerEvent
2246  * @tc.type: FUNC
2247  * @tc.require:
2248  */
2249 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_001, TestSize.Level1)
2250 {
2251     CALL_DEBUG_ENTER;
2252     auto pointerEvent = SetupSingleKnuckleDownEvent();
2253     ASSERT_TRUE(pointerEvent != nullptr);
2254     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2255     pointerEvent->SetActionTime(actionTime);
2256     KeyCommandHandler keyCommandHandler;
2257     keyCommandHandler.HandleTouchEvent(pointerEvent);
2258     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2259     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2260 }
2261 
2262 /**
2263  * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_002
2264  * @tc.desc: Test double knuckle CLICK set HandleTouchEvent pointerEvent
2265  * @tc.type: FUNC
2266  * @tc.require:
2267  */
2268 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_002, TestSize.Level1)
2269 {
2270     CALL_DEBUG_ENTER;
2271     auto pointerEvent = SetupDoubleKnuckleDownEvent();
2272     ASSERT_TRUE(pointerEvent != nullptr);
2273     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2274     pointerEvent->SetActionTime(actionTime);
2275     KeyCommandHandler keyCommandHandler;
2276     keyCommandHandler.HandleTouchEvent(pointerEvent);
2277     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2278     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2279 }
2280 
2281 /**
2282  * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_003
2283  * @tc.desc: Test signl knuckle double CLICK set HandleTouchEvent pointerEvent
2284  * @tc.type: FUNC
2285  * @tc.require:
2286  */
2287 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_003, TestSize.Level1)
2288 {
2289     CALL_DEBUG_ENTER;
2290     auto pointerEvent = SetupSingleKnuckleDownEvent();
2291     ASSERT_TRUE(pointerEvent != nullptr);
2292     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2293     pointerEvent->SetActionTime(actionTime);
2294     KeyCommandHandler keyCommandHandler;
2295     keyCommandHandler.HandleTouchEvent(pointerEvent);
2296     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2297     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2298     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2299     keyCommandHandler.HandleTouchEvent(pointerEvent);
2300     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2301     actionTime = actionTime + INTERVAL_TIME;
2302     pointerEvent->SetActionTime(actionTime);
2303     keyCommandHandler.HandleTouchEvent(pointerEvent);
2304     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2305     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2306 }
2307 
2308 /**
2309  * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_004
2310  * @tc.desc: Test double knuckle double CLICK set HandleTouchEvent pointerEvent
2311  * @tc.type: FUNC
2312  * @tc.require:
2313  */
2314 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_004, TestSize.Level1)
2315 {
2316     CALL_DEBUG_ENTER;
2317     auto pointerEvent = SetupDoubleKnuckleDownEvent();
2318     ASSERT_TRUE(pointerEvent != nullptr);
2319     int32_t actionTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2320     pointerEvent->SetActionTime(actionTime);
2321     KeyCommandHandler keyCommandHandler;
2322     keyCommandHandler.HandleTouchEvent(pointerEvent);
2323     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2324     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2325     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2326     keyCommandHandler.HandleTouchEvent(pointerEvent);
2327     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2328     actionTime = actionTime + INTERVAL_TIME;
2329     pointerEvent->SetActionTime(actionTime);
2330     keyCommandHandler.HandleTouchEvent(pointerEvent);
2331     ASSERT_FALSE(keyCommandHandler.GetSingleKnuckleGesture().state);
2332     ASSERT_FALSE(keyCommandHandler.GetDoubleKnuckleGesture().state);
2333 }
2334 #endif // OHOS_BUILD_ENABLE_TOUCH
2335 
2336 /**
2337  * @tc.name: KeyCommandHandlerTest_UpdateSettingsXml_001
2338  * @tc.desc: Update settings xml verify
2339  * @tc.type: FUNC
2340  * @tc.require:
2341  */
2342 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UpdateSettingsXml_001, TestSize.Level1)
2343 {
2344     KeyCommandHandler handler;
2345     ASSERT_EQ(handler.UpdateSettingsXml("", 100), COMMON_PARAMETER_ERROR);
2346     ASSERT_EQ(handler.UpdateSettingsXml("businessId", 100), COMMON_PARAMETER_ERROR);
2347     handler.businessIds_ = {"businessId1", "businessId2"};
2348     ASSERT_EQ(handler.UpdateSettingsXml("businessId3", 100), COMMON_PARAMETER_ERROR);
2349     handler.businessIds_ = {"businessId"};
2350     ASSERT_EQ(handler.UpdateSettingsXml("businessId", 1000), 0);
2351     auto result = PREFERENCES_MGR->SetShortKeyDuration("businessId", 100);
2352     ASSERT_EQ(handler.UpdateSettingsXml("businessId", 100), result);
2353 }
2354 
2355 /**
2356  * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_001
2357  * @tc.desc: Adjust distance configIf need verify
2358  * @tc.type: FUNC
2359  * @tc.require:
2360  */
2361 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_001, TestSize.Level1)
2362 {
2363     KeyCommandHandler handler;
2364     handler.downToPrevDownDistanceConfig_ = handler.distanceDefaultConfig_;
2365     handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_);
2366     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2367     handler.AdjustDistanceConfigIfNeed(handler.distanceLongConfig_);
2368     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2369     handler.downToPrevDownDistanceConfig_ = handler.distanceLongConfig_;
2370     handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_);
2371     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2372     handler.AdjustDistanceConfigIfNeed(handler.distanceLongConfig_);
2373     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceLongConfig_);
2374     handler.downToPrevDownDistanceConfig_ = handler.distanceDefaultConfig_;
2375     handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_ - 1);
2376     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceLongConfig_);
2377     handler.downToPrevDownDistanceConfig_ = handler.distanceLongConfig_;
2378     handler.AdjustDistanceConfigIfNeed(handler.distanceDefaultConfig_ - 1);
2379     ASSERT_EQ(handler.downToPrevDownDistanceConfig_, handler.distanceDefaultConfig_);
2380 }
2381 
2382 /**
2383  * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_001
2384  * @tc.desc: Start two finger gesture verify
2385  * @tc.type: FUNC
2386  * @tc.require:
2387  */
2388 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_001, TestSize.Level1)
2389 {
2390     KeyCommandHandler handler;
2391     handler.twoFingerGesture_.abilityStartDelay = 1000;
2392     handler.StartTwoFingerGesture();
2393     ASSERT_NE(-1, handler.twoFingerGesture_.timerId);
2394 }
2395 
2396 /**
2397  * @tc.name: KeyCommandHandlerTest_SkipFinalKey
2398  * @tc.desc: Skip Final Key
2399  * @tc.type: FUNC
2400  * @tc.require:
2401  */
2402 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SkipFinalKey, TestSize.Level1)
2403 {
2404     CALL_TEST_DEBUG;
2405     KeyCommandHandler handler;
2406     int32_t keyCode = 1024;
2407     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2408     ASSERT_NE(keyEvent, nullptr);
2409     ASSERT_FALSE(handler.SkipFinalKey(keyCode, keyEvent));
2410 }
2411 
2412 /**
2413  * @tc.name: KeyCommandHandlerTest_HandleKeyDown_01
2414  * @tc.desc: Handle Key Down
2415  * @tc.type: FUNC
2416  * @tc.require:
2417  */
2418 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_01, TestSize.Level1)
2419 {
2420     CALL_TEST_DEBUG;
2421     KeyCommandHandler handler;
2422     ShortcutKey shortcutKey;
2423     shortcutKey.keyDownDuration = 0;
2424     ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
2425 }
2426 
2427 /**
2428  * @tc.name: KeyCommandHandlerTest_HandleKeyDown_02
2429  * @tc.desc: test HandleKeyDown
2430  * @tc.type: FUNC
2431  * @tc.require:
2432  */
2433 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyDown_02, TestSize.Level1)
2434 {
2435     CALL_TEST_DEBUG;
2436     KeyCommandHandler handler;
2437     ShortcutKey shortcutKey;
2438     shortcutKey.timerId = -1;
2439     ASSERT_TRUE(handler.HandleKeyDown(shortcutKey));
2440 }
2441 
2442 /**
2443  * @tc.name: KeyCommandHandlerTest_GetKeyDownDurationFromXml
2444  * @tc.desc: GetKeyDownDurationFromXml
2445  * @tc.type: FUNC
2446  * @tc.require:
2447  */
2448 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GetKeyDownDurationFromXml, TestSize.Level1)
2449 {
2450     CALL_TEST_DEBUG;
2451     KeyCommandHandler handler;
2452     std::string businessId = "power";
2453     int32_t ret = handler.GetKeyDownDurationFromXml(businessId);
2454     ASSERT_EQ(ret, ERROR_DELAY_VALUE);
2455 }
2456 
2457 /**
2458  * @tc.name: KeyCommandHandlerTest_HandleKeyUp_001
2459  * @tc.desc: HandleKeyUp
2460  * @tc.type: FUNC
2461  * @tc.require:
2462  */
2463 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_001, TestSize.Level1)
2464 {
2465     CALL_TEST_DEBUG;
2466     KeyCommandHandler handler;
2467     ShortcutKey shortcutKey;
2468     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2469     ASSERT_NE(keyEvent, nullptr);
2470     shortcutKey.keyDownDuration = 0;
2471     ASSERT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
2472 }
2473 
2474 /**
2475  * @tc.name: KeyCommandHandlerTest_HandleKeyUp_002
2476  * @tc.desc: HandleKeyUp
2477  * @tc.type: FUNC
2478  * @tc.require:
2479  */
2480 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_002, TestSize.Level1)
2481 {
2482     CALL_TEST_DEBUG;
2483     KeyCommandHandler handler;
2484     ShortcutKey shortcutKey;
2485     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2486     ASSERT_NE(keyEvent, nullptr);
2487     shortcutKey.keyDownDuration = 1;
2488     ASSERT_FALSE(handler.HandleKeyUp(keyEvent, shortcutKey));
2489 }
2490 
2491 /**
2492  * @tc.name: KeyCommandHandlerTest_HandleKeyUp_003
2493  * @tc.desc: HandleKeyUp
2494  * @tc.type: FUNC
2495  * @tc.require:
2496  */
2497 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_003, TestSize.Level1)
2498 {
2499     CALL_TEST_DEBUG;
2500     KeyCommandHandler handler;
2501     ShortcutKey shortcutKey;
2502     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2503     KeyEvent::KeyItem item;
2504     ASSERT_NE(keyEvent, nullptr);
2505     shortcutKey.keyDownDuration = 1;
2506     item.SetKeyCode(KeyEvent::KEYCODE_H);
2507     keyEvent->AddKeyItem(item);
2508     keyEvent->SetKeyCode(KeyEvent::KEYCODE_H);
2509     keyEvent->SetActionTime(10000);
2510     ASSERT_TRUE(handler.HandleKeyUp(keyEvent, shortcutKey));
2511 }
2512 
2513 /**
2514  * @tc.name: KeyCommandHandlerTest_HandleKeyUp_004
2515  * @tc.desc: HandleKeyUp
2516  * @tc.type: FUNC
2517  * @tc.require:
2518  */
2519 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUp_004, TestSize.Level1)
2520 {
2521     CALL_TEST_DEBUG;
2522     KeyCommandHandler handler;
2523     ShortcutKey shortcutKey;
2524     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2525     KeyEvent::KeyItem item;
2526     ASSERT_NE(keyEvent, nullptr);
2527     shortcutKey.keyDownDuration = 10;
2528     item.SetKeyCode(KeyEvent::KEYCODE_H);
2529     keyEvent->AddKeyItem(item);
2530     keyEvent->SetKeyCode(KeyEvent::KEYCODE_H);
2531     keyEvent->SetActionTime(100);
2532     ASSERT_FALSE(handler.HandleKeyUp(keyEvent, shortcutKey));
2533 }
2534 
2535 /**
2536  * @tc.name: KeyCommandHandlerTest_HandleKeyCancel
2537  * @tc.desc: HandleKeyCancel
2538  * @tc.type: FUNC
2539  * @tc.require:
2540  */
2541 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyCancel, TestSize.Level1)
2542 {
2543     CALL_TEST_DEBUG;
2544     KeyCommandHandler handler;
2545     ShortcutKey shortcutKey;
2546     shortcutKey.timerId = -1;
2547     ASSERT_FALSE(handler.HandleKeyCancel(shortcutKey));
2548     shortcutKey.timerId = 10;
2549     ASSERT_FALSE(handler.HandleKeyCancel(shortcutKey));
2550 }
2551 
2552 /**
2553  * @tc.name: KeyCommandHandlerTest_LaunchAbility_001
2554  * @tc.desc: LaunchAbility
2555  * @tc.type: FUNC
2556  * @tc.require:
2557  */
2558 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_001, TestSize.Level1)
2559 {
2560     CALL_TEST_DEBUG;
2561     KeyCommandHandler handler;
2562     Ability ability;
2563     ability.abilityType = EXTENSION_ABILITY;
2564     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability));
2565     ability.abilityType = EXTENSION_ABILITY_ABNORMAL;
2566     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability));
2567 }
2568 
2569 /**
2570  * @tc.name: KeyCommandHandlerTest_LaunchAbility_002
2571  * @tc.desc: LaunchAbility
2572  * @tc.type: FUNC
2573  * @tc.require:
2574  */
2575 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_002, TestSize.Level1)
2576 {
2577     CALL_TEST_DEBUG;
2578     KeyCommandHandler handler;
2579     ShortcutKey shortcutKey;
2580     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(shortcutKey));
2581 }
2582 
2583 /**
2584  * @tc.name: KeyCommandHandlerTest_LaunchAbility_003
2585  * @tc.desc: LaunchAbility
2586  * @tc.type: FUNC
2587  * @tc.require:
2588  */
2589 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_003, TestSize.Level1)
2590 {
2591     CALL_TEST_DEBUG;
2592     KeyCommandHandler handler;
2593     Sequence sequence;
2594     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(sequence));
2595 }
2596 
2597 /**
2598  * @tc.name: KeyCommandHandlerTest_LaunchAbility_004
2599  * @tc.desc: LaunchAbility
2600  * @tc.type: FUNC
2601  * @tc.require:
2602  */
2603 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAbility_004, TestSize.Level1)
2604 {
2605     CALL_TEST_DEBUG;
2606     KeyCommandHandler handler;
2607     Ability ability;
2608     int64_t delay = 100;
2609     ability.deviceId = "deviceId";
2610     ability.bundleName = "bundleName";
2611     ability.abilityName = "abilityName";
2612     ability.uri = "abilityUri";
2613     ability.type = "type";
2614     ability.action = "abilityAction";
2615     ability.entities.push_back("entities");
2616     ability.params.insert(std::make_pair("paramsFirst", "paramsSecond"));
2617     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(ability, delay));
2618 }
2619 
2620 /**
2621  * @tc.name: KeyCommandHandlerTest_KeyCommandHandlerPrint
2622  * @tc.desc: Print
2623  * @tc.type: FUNC
2624  * @tc.require:
2625  */
2626 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KeyCommandHandlerPrint, TestSize.Level1)
2627 {
2628     CALL_TEST_DEBUG;
2629     KeyCommandHandler handler;
2630     ShortcutKey shortcutKey;
2631     Ability ability_temp;
2632     std::string copyShortcutKey = "copyShortcutKey";
2633     shortcutKey.preKeys.insert(2072);
2634     shortcutKey.finalKey = 2019;
2635     shortcutKey.keyDownDuration = 100;
2636     ability_temp.bundleName = "bundleName";
2637     ability_temp.abilityName = "abilityName";
2638     shortcutKey.ability = ability_temp;
2639     handler.shortcutKeys_.insert(std::make_pair(copyShortcutKey, shortcutKey));
2640     ASSERT_NO_FATAL_FAILURE(handler.Print());
2641 }
2642 
2643 /**
2644  * @tc.name: KeyCommandHandlerTest_shortcutKeyPrint
2645  * @tc.desc: Print
2646  * @tc.type: FUNC
2647  * @tc.require:
2648  */
2649 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_shortcutKeyPrint, TestSize.Level1)
2650 {
2651     CALL_TEST_DEBUG;
2652     ShortcutKey shortcutKey;
2653     Ability ability_temp;
2654     shortcutKey.preKeys.insert(2072);
2655     shortcutKey.finalKey = 2019;
2656     ability_temp.bundleName = "bundleName";
2657     shortcutKey.ability = ability_temp;
2658     ASSERT_NO_FATAL_FAILURE(shortcutKey.Print());
2659 }
2660 
2661 /**
2662  * @tc.name: KeyCommandHandlerTest_RemoveSubscribedTimer
2663  * @tc.desc: RemoveSubscribedTimer
2664  * @tc.type: FUNC
2665  * @tc.require:
2666  */
2667 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RemoveSubscribedTimer, TestSize.Level1)
2668 {
2669     CALL_TEST_DEBUG;
2670     KeyCommandHandler handler;
2671     int32_t keyCode = 16;
2672     std::list<int32_t> timerIds;
2673     timerIds.push_back(100);
2674     handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
2675     ASSERT_NO_FATAL_FAILURE(handler.RemoveSubscribedTimer(keyCode));
2676     keyCode = 17;
2677     ASSERT_NO_FATAL_FAILURE(handler.RemoveSubscribedTimer(keyCode));
2678 }
2679 
2680 /**
2681  * @tc.name: KeyCommandHandlerTest_HandleSpecialKeys
2682  * @tc.desc: HandleSpecialKeys
2683  * @tc.type: FUNC
2684  * @tc.require:
2685  */
2686 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSpecialKeys, TestSize.Level1)
2687 {
2688     CALL_TEST_DEBUG;
2689     KeyCommandHandler handler;
2690     int32_t keyCodeVolumeUp = 16;
2691     int32_t keyCodeVolumeDown = 17;
2692     int32_t keyAction = KeyEvent::KEY_ACTION_UP;
2693     handler.specialKeys_.insert(std::make_pair(keyCodeVolumeUp, keyAction));
2694     ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCodeVolumeUp, keyAction));
2695     handler.specialKeys_.clear();
2696 
2697     keyAction = KeyEvent::KEY_ACTION_DOWN;
2698     ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCodeVolumeDown, keyAction));
2699 }
2700 
2701 /**
2702  * @tc.name: KeyCommandHandlerTest_HandleSpecialKeys_001
2703  * @tc.desc: Overrides the HandleSpecialKeys function exception branch
2704  * @tc.type: FUNC
2705  * @tc.require:
2706  */
2707 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSpecialKeys_001, TestSize.Level1)
2708 {
2709     CALL_DEBUG_ENTER;
2710     KeyCommandHandler handler;
2711     int32_t powerKeyCode = 18;
2712     int32_t keyCode = 2017;
2713     int32_t keyAction = KeyEvent::KEY_ACTION_UP;
2714     handler.specialKeys_.insert(std::make_pair(powerKeyCode, keyAction));
2715     ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(keyCode, keyAction));
2716 
2717     keyAction = KeyEvent::KEY_ACTION_DOWN;
2718     ASSERT_NO_FATAL_FAILURE(handler.HandleSpecialKeys(powerKeyCode, keyAction));
2719 }
2720 
2721 /**
2722  * @tc.name: KeyCommandHandlerTest_InterruptTimers
2723  * @tc.desc: InterruptTimers
2724  * @tc.type: FUNC
2725  * @tc.require:
2726  */
2727 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_InterruptTimers, TestSize.Level1)
2728 {
2729     CALL_TEST_DEBUG;
2730     KeyCommandHandler handler;
2731     Sequence sequence;
2732     sequence.timerId = 1;
2733     handler.filterSequences_.push_back(sequence);
2734     ASSERT_NO_FATAL_FAILURE(handler.InterruptTimers());
2735 
2736     handler.filterSequences_.clear();
2737     sequence.timerId = -1;
2738     handler.filterSequences_.push_back(sequence);
2739     ASSERT_NO_FATAL_FAILURE(handler.InterruptTimers());
2740 }
2741 
2742 /**
2743  * @tc.name: KeyCommandHandlerTest_SetKnuckleDoubleTapDistance
2744  * @tc.desc: SetKnuckleDoubleTapDistance
2745  * @tc.type: FUNC
2746  * @tc.require:
2747  */
2748 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetKnuckleDoubleTapDistance, TestSize.Level1)
2749 {
2750     CALL_TEST_DEBUG;
2751     KeyCommandHandler handler;
2752     float distance = -1.0f;
2753     ASSERT_NO_FATAL_FAILURE(handler.SetKnuckleDoubleTapDistance(distance));
2754 }
2755 
2756 /**
2757  * @tc.name: KeyCommandHandlerTest_HandleMulFingersTap
2758  * @tc.desc: Overrides the HandleMulFingersTap function exception branch
2759  * @tc.type: FUNC
2760  * @tc.require:
2761  */
2762 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMulFingersTap, TestSize.Level1)
2763 {
2764     CALL_DEBUG_ENTER;
2765     KeyCommandHandler handler;
2766     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2767     ASSERT_NE(pointerEvent, nullptr);
2768     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP);
2769     ASSERT_FALSE(handler.HandleMulFingersTap(pointerEvent));
2770 }
2771 
2772 /**
2773  * @tc.name: KeyCommandHandlerTest_IsKeyMatch
2774  * @tc.desc: IsKeyMatch
2775  * @tc.type: FUNC
2776  * @tc.require:
2777  */
2778 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsKeyMatch, TestSize.Level1)
2779 {
2780     CALL_TEST_DEBUG;
2781     KeyCommandHandler handler;
2782     ShortcutKey shortcutKey;
2783     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2784     ASSERT_NE(keyEvent, nullptr);
2785     KeyEvent::KeyItem item;
2786     shortcutKey.finalKey = 2019;
2787     shortcutKey.preKeys.insert(2072);
2788     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
2789     item.SetKeyCode(KeyEvent::KEYCODE_C);
2790     keyEvent->AddKeyItem(item);
2791     keyEvent->SetKeyCode(KeyEvent::KEYCODE_C);
2792     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2793     ASSERT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
2794 
2795     shortcutKey.preKeys.insert(2047);
2796     item.SetKeyCode(KeyEvent::KEYCODE_B);
2797     keyEvent->AddKeyItem(item);
2798     item.SetKeyCode(KeyEvent::KEYCODE_E);
2799     keyEvent->AddKeyItem(item);
2800     ASSERT_FALSE(handler.IsKeyMatch(shortcutKey, keyEvent));
2801 }
2802 
2803 /**
2804  * @tc.name: KeyCommandHandlerTest_HandleSequence
2805  * @tc.desc: HandleSequence
2806  * @tc.type: FUNC
2807  * @tc.require:
2808  */
2809 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequence, TestSize.Level1)
2810 {
2811     CALL_TEST_DEBUG;
2812     KeyCommandHandler handler;
2813     Sequence sequence;
2814     SequenceKey sequenceKey;
2815     bool isLaunchAbility = false;
2816     sequence.statusConfigValue = false;
2817     ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2818 
2819     sequence.statusConfigValue = true;
2820     sequenceKey.keyCode = 2017;
2821     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2822     handler.keys_.push_back(sequenceKey);
2823     sequenceKey.keyCode = 2018;
2824     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2825     handler.keys_.push_back(sequenceKey);
2826 
2827     sequenceKey.keyCode = 2019;
2828     sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2829     sequence.sequenceKeys.push_back(sequenceKey);
2830     ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2831 
2832     sequenceKey.keyCode = 2017;
2833     sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2834     sequence.sequenceKeys.push_back(sequenceKey);
2835     ASSERT_FALSE(handler.HandleSequence(sequence, isLaunchAbility));
2836 }
2837 
2838 /**
2839  * @tc.name: KeyCommandHandlerTest_IsRepeatKeyEvent
2840  * @tc.desc: IsRepeatKeyEvent
2841  * @tc.type: FUNC
2842  * @tc.require:
2843  */
2844 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsRepeatKeyEvent, TestSize.Level1)
2845 {
2846     CALL_TEST_DEBUG;
2847     KeyCommandHandler handler;
2848     SequenceKey sequenceKey;
2849     sequenceKey.keyCode = 2018;
2850     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2851     handler.keys_.push_back(sequenceKey);
2852 
2853     sequenceKey.keyCode = 2018;
2854     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
2855     ASSERT_TRUE(handler.IsRepeatKeyEvent(sequenceKey));
2856 
2857     sequenceKey.keyAction = KeyEvent::KEY_ACTION_UP;
2858     ASSERT_FALSE(handler.IsRepeatKeyEvent(sequenceKey));
2859 
2860     handler.keys_.clear();
2861     sequenceKey.keyCode = 2019;
2862     handler.keys_.push_back(sequenceKey);
2863     sequenceKey.keyCode = 2020;
2864     ASSERT_FALSE(handler.IsRepeatKeyEvent(sequenceKey));
2865 }
2866 
2867 /**
2868  * @tc.name: KeyCommandHandlerTest_HandleSequences
2869  * @tc.desc: HandleSequences
2870  * @tc.type: FUNC
2871  * @tc.require:
2872  */
2873 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences, TestSize.Level1)
2874 {
2875     CALL_TEST_DEBUG;
2876     KeyCommandHandler handler;
2877     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2878     ASSERT_NE(keyEvent, nullptr);
2879     handler.matchedSequence_.timerId = 10;
2880     ASSERT_FALSE(handler.HandleSequences(keyEvent));
2881     handler.matchedSequence_.timerId = -1;
2882     ASSERT_FALSE(handler.HandleSequences(keyEvent));
2883 
2884     keyEvent->SetKeyCode(2017);
2885     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2886     keyEvent->SetActionTime(10000);
2887     SequenceKey sequenceKey;
2888     Sequence sequence;
2889     handler.sequences_.push_back(sequence);
2890     sequenceKey.actionTime = 15000;
2891     handler.keys_.push_back(sequenceKey);
2892     ASSERT_FALSE(handler.HandleSequences(keyEvent));
2893 
2894     handler.keys_.clear();
2895     keyEvent->SetActionTime(1500000);
2896     sequenceKey.actionTime = 200000;
2897     sequence.statusConfigValue = false;
2898     handler.filterSequences_.push_back(sequence);
2899     ASSERT_FALSE(handler.HandleSequences(keyEvent));
2900 }
2901 
2902 /**
2903  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyCount
2904  * @tc.desc: HandleRepeatKeyCount
2905  * @tc.type: FUNC
2906  * @tc.require:
2907  */
2908 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyCount, TestSize.Level1)
2909 {
2910     CALL_TEST_DEBUG;
2911     KeyCommandHandler handler;
2912     RepeatKey repeatKey;
2913     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2914     ASSERT_NE(keyEvent, nullptr);
2915     repeatKey.keyCode = 2017;
2916     keyEvent->SetKeyCode(2017);
2917     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2918     keyEvent->SetActionTime(20);
2919     handler.repeatKey_.keyCode = 2018;
2920     ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2921 
2922     handler.repeatKey_.keyCode = 2017;
2923     ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2924 
2925     handler.intervalTime_ = 100;
2926     keyEvent->SetActionTime(50);
2927     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2928     ASSERT_TRUE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2929 
2930     keyEvent->SetKeyCode(2018);
2931     ASSERT_FALSE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
2932 }
2933 
2934 /**
2935  * @tc.name: KeyCommandHandlerTest_HandleKeyUpCancel
2936  * @tc.desc: HandleKeyUpCancel
2937  * @tc.type: FUNC
2938  * @tc.require:
2939  */
2940 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyUpCancel, TestSize.Level1)
2941 {
2942     CALL_TEST_DEBUG;
2943     KeyCommandHandler handler;
2944     RepeatKey repeatKey;
2945     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2946     ASSERT_NE(keyEvent, nullptr);
2947     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
2948     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2949     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
2950     ASSERT_TRUE(handler.HandleKeyUpCancel(repeatKey, keyEvent));
2951 }
2952 
2953 /**
2954  * @tc.name: KeyCommandHandlerTest_HandleRepeatKey
2955  * @tc.desc: HandleRepeatKey
2956  * @tc.type: FUNC
2957  * @tc.require:
2958  */
2959 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey, TestSize.Level1)
2960 {
2961     CALL_TEST_DEBUG;
2962     KeyCommandHandler handler;
2963     RepeatKey repeatKey;
2964     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2965     ASSERT_NE(keyEvent, nullptr);
2966     repeatKey.times = 2;
2967     repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
2968     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
2969     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2970     ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, keyEvent));
2971 }
2972 
2973 /**
2974  * @tc.name: KeyCommandHandlerTest_CreateKeyEvent
2975  * @tc.desc: CreateKeyEvent
2976  * @tc.type: FUNC
2977  * @tc.require:
2978  */
2979 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CreateKeyEvent, TestSize.Level1)
2980 {
2981     CALL_TEST_DEBUG;
2982     KeyCommandHandler handler;
2983     int32_t keyCode = 2017;
2984     int32_t keyAction = KeyEvent::KEY_ACTION_DOWN;
2985     bool isPressed = true;
2986     ASSERT_NE(handler.CreateKeyEvent(keyCode, keyAction, isPressed), nullptr);
2987 }
2988 
2989 /**
2990  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey
2991  * @tc.desc: Test IsEnableCombineKey
2992  * @tc.type: FUNC
2993  * @tc.require:
2994  */
2995 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey, TestSize.Level1)
2996 {
2997     CALL_TEST_DEBUG;
2998     KeyCommandHandler handler;
2999     KeyEvent::KeyItem item;
3000     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
3001     ASSERT_NE(key, nullptr);
3002     handler.enableCombineKey_ = false;
3003     item.SetKeyCode(KeyEvent::KEYCODE_A);
3004     key->SetKeyCode(KeyEvent::KEYCODE_POWER);
3005     key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
3006     key->AddKeyItem(item);
3007     ASSERT_FALSE(handler.IsEnableCombineKey(key));
3008     item.SetKeyCode(KeyEvent::KEYCODE_B);
3009     key->AddKeyItem(item);
3010     ASSERT_FALSE(handler.IsEnableCombineKey(key));
3011     key->SetKeyCode(KeyEvent::KEYCODE_L);
3012     ASSERT_FALSE(handler.IsEnableCombineKey(key));
3013 }
3014 
3015 /**
3016  * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed
3017  * @tc.desc: Test AdjustDistanceConfigIfNeed
3018  * @tc.type: FUNC
3019  * @tc.require:
3020  */
3021 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed, TestSize.Level1)
3022 {
3023     CALL_TEST_DEBUG;
3024     KeyCommandHandler handler;
3025     float distance = 5.0f;
3026     handler.downToPrevDownDistanceConfig_ = 10.0f;
3027     handler.distanceDefaultConfig_ = 10.0f;
3028     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3029 
3030     distance = 20.0f;
3031     handler.distanceLongConfig_ = 15.0f;
3032     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3033 
3034     distance = 12.0f;
3035     handler.checkAdjustDistanceCount_ = 6;
3036     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3037 
3038     handler.downToPrevDownDistanceConfig_ = 15.0f;
3039     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3040 
3041     distance = 5.0f;
3042     handler.checkAdjustDistanceCount_ = 0;
3043     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3044 
3045     handler.downToPrevDownDistanceConfig_ = 11.5f;
3046     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3047 }
3048 
3049 /**
3050  * @tc.name: KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_002
3051  * @tc.desc: Test AdjustDistanceConfigIfNeed
3052  * @tc.type: FUNC
3053  * @tc.require:
3054  */
3055 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AdjustDistanceConfigIfNeed_002, TestSize.Level1)
3056 {
3057     CALL_TEST_DEBUG;
3058     KeyCommandHandler handler;
3059     float distance = 15.0f;
3060     handler.downToPrevDownDistanceConfig_ = 10.0f;
3061     handler.distanceLongConfig_ = 10.0f;
3062     handler.distanceDefaultConfig_ = 5.0f;
3063     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3064     handler.distanceDefaultConfig_ = 20.0f;
3065     handler.checkAdjustDistanceCount_ = 6;
3066     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3067     handler.downToPrevDownDistanceConfig_ = 30.0f;
3068     ASSERT_NO_FATAL_FAILURE(handler.AdjustDistanceConfigIfNeed(distance));
3069 }
3070 
3071 #ifdef OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
3072 /**
3073  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_001
3074  * @tc.desc: Test knuckle gesture touch down event
3075  * @tc.type: FUNC
3076  * @tc.require:
3077  */
3078 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_001, TestSize.Level1)
3079 {
3080     CALL_TEST_DEBUG;
3081     KeyCommandHandler handler;
3082     PointerEvent::PointerItem item;
3083     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3084     ASSERT_NE(touchEvent, nullptr);
3085 
3086     item.SetPointerId(1);
3087     item.SetRawDisplayX(4);
3088     item.SetRawDisplayY(4);
3089     touchEvent->SetPointerId(1);
3090     touchEvent->SetActionTime(1);
3091     touchEvent->AddPointerItem(item);
3092     KeyCommandHandler keyCommandHandler;
3093     keyCommandHandler.HandleKnuckleGestureTouchDown(touchEvent);
3094 
3095     ASSERT_TRUE(handler.gestureTimeStamps_.empty());
3096 }
3097 
3098 /**
3099  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_002
3100  * @tc.desc: Test knuckle gesture touch down event
3101  * @tc.type: FUNC
3102  * @tc.require:
3103  */
3104 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchDown_002, TestSize.Level1)
3105 {
3106     CALL_TEST_DEBUG;
3107     KeyCommandHandler handler;
3108     PointerEvent::PointerItem item;
3109     ASSERT_NE(touchEvent_, nullptr);
3110 
3111     item.SetPointerId(0);
3112     item.SetRawDisplayX(4);
3113     item.SetRawDisplayY(4);
3114     touchEvent_->SetPointerId(0);
3115     touchEvent_->SetActionTime(1);
3116     touchEvent_->AddPointerItem(item);
3117     touchEvent_->SetTargetDisplayId(0);
3118 
3119     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
3120     OLD::DisplayGroupInfo displayGroupInfo;
3121     OLD::DisplayInfo displayInfo;
3122     displayInfo.id = 0;
3123     displayInfo.x = 2;
3124     displayInfo.y = 3;
3125     displayInfo.width = 4;
3126     displayInfo.height = 5;
3127     displayInfo.dpi = -1;
3128     displayGroupInfo.displaysInfo.emplace_back(displayInfo);
3129     displayGroupInfo.groupId = 0;
3130     inputWindowsManager->displayGroupInfoMap_[0] = displayGroupInfo;
3131     inputWindowsManager->displayGroupInfo_ = displayGroupInfo;
3132     IInputWindowsManager::instance_ = inputWindowsManager;
3133 
3134     KeyCommandHandler keyCommandHandler;
3135     keyCommandHandler.HandleKnuckleGestureTouchDown(touchEvent_);
3136     ASSERT_TRUE(handler.gestureTimeStamps_.empty());
3137 }
3138 
3139 /**
3140  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_001
3141  * @tc.desc: Test knuckle gesture touch move event
3142  * @tc.type: FUNC
3143  * @tc.require:
3144  */
3145 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_001, TestSize.Level1)
3146 {
3147     CALL_TEST_DEBUG;
3148     KeyCommandHandler handler;
3149     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3150     ASSERT_NE(touchEvent, nullptr);
3151 
3152     handler.gestureLastX_ = 4.0;
3153     handler.gestureLastY_ = 4.0;
3154 
3155     PointerEvent::PointerItem item1;
3156     item1.SetPointerId(2);
3157     item1.SetRawDisplayX(24);
3158     item1.SetRawDisplayY(24);
3159     touchEvent->AddPointerItem(item1);
3160     touchEvent->SetActionTime(6);
3161     touchEvent->SetPointerId(2);
3162 
3163     handler.HandleKnuckleGestureTouchMove(touchEvent);
3164     ASSERT_FALSE(handler.isLetterGesturing_);
3165 }
3166 
3167 /**
3168  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_001
3169  * @tc.desc: Test knuckle gesture touch up event partial screenshot
3170  * @tc.type: FUNC
3171  * @tc.require:
3172  */
3173 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_001, TestSize.Level1)
3174 {
3175     CALL_TEST_DEBUG;
3176     KeyCommandHandler handler;
3177     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3178     ASSERT_NE(touchEvent, nullptr);
3179 
3180     handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
3181     handler.gestureTimeStamps_.assign(CIRCLE_TIMESTAMPS.begin(), CIRCLE_TIMESTAMPS.end());
3182     handler.isGesturing_ = true;
3183     handler.isLetterGesturing_ = true;
3184 
3185     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3186 }
3187 
3188 /**
3189  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_002
3190  * @tc.desc: Test knuckle gesture touch up event long screenshot
3191  * @tc.type: FUNC
3192  * @tc.require:
3193  */
3194 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_002, TestSize.Level1)
3195 {
3196     CALL_TEST_DEBUG;
3197     KeyCommandHandler handler;
3198     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3199     ASSERT_NE(touchEvent, nullptr);
3200 
3201     handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
3202     handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
3203     handler.isGesturing_ = true;
3204     handler.isLetterGesturing_ = true;
3205 
3206     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3207 }
3208 
3209 /**
3210  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_003
3211  * @tc.desc: Test knuckle gesture touch up event straight line
3212  * @tc.type: FUNC
3213  * @tc.require:
3214  */
3215 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_003, TestSize.Level1)
3216 {
3217     CALL_TEST_DEBUG;
3218     KeyCommandHandler handler;
3219     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3220     ASSERT_NE(touchEvent, nullptr);
3221 
3222     handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
3223     handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
3224     handler.isGesturing_ = true;
3225     handler.isLetterGesturing_ = true;
3226 
3227     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
3228 }
3229 
3230 /**
3231  * @tc.name: KeyCommandHandlerTest_ResetKnuckleGesture_001
3232  * @tc.desc: Test ResetKnuckleGesture function
3233  * @tc.type: FUNC
3234  * @tc.require:
3235  */
3236 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ResetKnuckleGesture_001, TestSize.Level1)
3237 {
3238     CALL_TEST_DEBUG;
3239     KeyCommandHandler handler;
3240     handler.gestureLastX_ = 1.0f;
3241     handler.gestureLastY_ = 1.0f;
3242     handler.isGesturing_ = true;
3243     handler.isDistanceConfig_ = true;
3244     handler.gestureTrackLength_ = 2.0f;
3245     handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
3246     handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
3247 
3248     handler.ResetKnuckleGesture();
3249     ASSERT_EQ(handler.gestureLastX_, 0.0f);
3250     ASSERT_EQ(handler.gestureLastY_, 0.0f);
3251     ASSERT_FALSE(handler.isGesturing_);
3252     ASSERT_TRUE(handler.isDistanceConfig_);
3253     ASSERT_EQ(handler.gestureTrackLength_, 0.0f);
3254     ASSERT_TRUE(handler.gesturePoints_.empty());
3255     ASSERT_TRUE(handler.gestureTimeStamps_.empty());
3256 }
3257 
3258 /**
3259  * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_001
3260  * @tc.desc: Test GesturePointsToStr function
3261  * @tc.type: FUNC
3262  * @tc.require:
3263  */
3264 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_001, TestSize.Level1)
3265 {
3266     CALL_TEST_DEBUG;
3267     KeyCommandHandler handler;
3268     handler.gesturePoints_ = {0.0f, 1.0f, 2.0f, 3.0f};
3269 
3270     auto result = handler.GesturePointsToStr();
3271     ASSERT_EQ(result.length(), 50);
3272     ASSERT_EQ(handler.gesturePoints_.size(), 4);
3273 }
3274 
3275 /**
3276  * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_002
3277  * @tc.desc: Test GesturePointsToStr function
3278  * @tc.type: FUNC
3279  * @tc.require:
3280  */
3281 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_002, TestSize.Level1)
3282 {
3283     CALL_TEST_DEBUG;
3284     KeyCommandHandler handler;
3285 
3286     auto result = handler.GesturePointsToStr();
3287     ASSERT_TRUE(result.empty());
3288     ASSERT_TRUE(handler.gesturePoints_.empty());
3289 }
3290 
3291 /**
3292  * @tc.name: KeyCommandHandlerTest_GesturePointsToStr_003
3293  * @tc.desc: Test GesturePointsToStr function
3294  * @tc.type: FUNC
3295  * @tc.require:
3296  */
3297 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_GesturePointsToStr_003, TestSize.Level1)
3298 {
3299     CALL_TEST_DEBUG;
3300     KeyCommandHandler handler;
3301     handler.gesturePoints_ = {0.0f};
3302 
3303     auto result = handler.GesturePointsToStr();
3304     ASSERT_TRUE(result.empty());
3305     ASSERT_EQ(handler.gesturePoints_.size(), 1);
3306 }
3307 
3308 /**
3309  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_001
3310  * @tc.desc: Test HandleKnuckleGestureEvent function
3311  * @tc.type: FUNC
3312  * @tc.require:
3313  */
3314 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_001, TestSize.Level1)
3315 {
3316     CALL_TEST_DEBUG;
3317     KeyCommandHandler handler;
3318     PointerEvent::PointerItem item;
3319     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3320     ASSERT_NE(touchEvent, nullptr);
3321     item.SetPointerId(1);
3322     item.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
3323     touchEvent->AddPointerItem(item);
3324     touchEvent->SetPointerId(1);
3325     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3326     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3327 
3328     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3329     touchEvent->AddPointerItem(item);
3330     touchEvent->SetPointerId(1);
3331     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3332     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3333 
3334     handler.singleKnuckleGesture_.state = true;
3335     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3336 }
3337 
3338 /**
3339  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_002
3340  * @tc.desc: Test HandleKnuckleGestureEvent function
3341  * @tc.type: FUNC
3342  * @tc.require:
3343  */
3344 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_002, TestSize.Level1)
3345 {
3346     CALL_TEST_DEBUG;
3347     KeyCommandHandler handler;
3348     PointerEvent::PointerItem item;
3349     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3350     ASSERT_NE(touchEvent, nullptr);
3351     item.SetPointerId(1);
3352     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3353     touchEvent->AddPointerItem(item);
3354     touchEvent->SetPointerId(1);
3355     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3356 
3357     handler.singleKnuckleGesture_.state = false;
3358     handler.gameForbidFingerKnuckle_ = false;
3359     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3360 }
3361 
3362 /**
3363  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureEvent_003
3364  * @tc.desc: Test HandleKnuckleGestureEvent function
3365  * @tc.type: FUNC
3366  * @tc.require:
3367  */
3368 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureEvent_003, TestSize.Level1)
3369 {
3370     CALL_TEST_DEBUG;
3371     KeyCommandHandler handler;
3372     PointerEvent::PointerItem item;
3373     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3374     ASSERT_NE(touchEvent, nullptr);
3375     item.SetPointerId(1);
3376     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3377     touchEvent->AddPointerItem(item);
3378     touchEvent->SetPointerId(1);
3379     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3380 
3381     handler.singleKnuckleGesture_.state = false;
3382     handler.gameForbidFingerKnuckle_ = true;
3383     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureEvent(touchEvent));
3384 }
3385 
3386 /**
3387  * @tc.name: KeyCommandHandlerTest_IsValidAction
3388  * @tc.desc: Test IsValidAction
3389  * @tc.type: FUNC
3390  * @tc.require:
3391  */
3392 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsValidAction, TestSize.Level1)
3393 {
3394     CALL_TEST_DEBUG;
3395     KeyCommandHandler handler;
3396     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
3397     ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3398 
3399     action = PointerEvent::POINTER_ACTION_MOVE;
3400     handler.gesturePoints_ = {0.0f};
3401     ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3402 
3403     action = PointerEvent::POINTER_ACTION_UP;
3404     handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
3405     ASSERT_NO_FATAL_FAILURE(handler.IsValidAction(action));
3406 }
3407 
3408 /**
3409  * @tc.name: KeyCommandHandlerTest_SendNotSupportMsg_001
3410  * @tc.desc: Test the funcation SendNotSupportMsg
3411  * @tc.type: FUNC
3412  * @tc.require:
3413  */
3414 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendNotSupportMsg_001, TestSize.Level1)
3415 {
3416     CALL_TEST_DEBUG;
3417     KeyCommandHandler handler;
3418     ASSERT_NO_FATAL_FAILURE(handler.SendNotSupportMsg(nullptr));
3419 }
3420 
3421 /**
3422  * @tc.name: KeyCommandHandlerTest_SendNotSupportMsg_002
3423  * @tc.desc: Test the funcation SendNotSupportMsg
3424  * @tc.type: FUNC
3425  * @tc.require:
3426  */
3427 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendNotSupportMsg_002, TestSize.Level1)
3428 {
3429     CALL_TEST_DEBUG;
3430     KeyCommandHandler handler;
3431     ASSERT_NE(touchEvent_, nullptr);
3432     PointerEvent::PointerItem item;
3433     item.SetPointerId(1);
3434     item.SetToolType(PointerEvent::TOOL_TYPE_PENCIL);
3435     touchEvent_->AddPointerItem(item);
3436     ASSERT_NO_FATAL_FAILURE(handler.SendNotSupportMsg(touchEvent_));
3437 }
3438 
3439 /**
3440  * @tc.name: KeyCommandHandlerTest_ReportRegionGesture
3441  * @tc.desc: Test the funcation ReportRegionGesture
3442  * @tc.type: FUNC
3443  * @tc.require:
3444  */
3445 HWTEST_F(KeyCommandHandlerTest, ReportRegionGesture, TestSize.Level1)
3446 {
3447     CALL_TEST_DEBUG;
3448     KeyCommandHandler handler;
3449     ASSERT_NO_FATAL_FAILURE(handler.ReportRegionGesture());
3450 }
3451 
3452 /**
3453  * @tc.name: KeyCommandHandlerTest_ReportLetterGesture
3454  * @tc.desc: Test the funcation ReportLetterGesture
3455  * @tc.type: FUNC
3456  * @tc.require:
3457  */
3458 HWTEST_F(KeyCommandHandlerTest, ReportLetterGesture, TestSize.Level1)
3459 {
3460     CALL_TEST_DEBUG;
3461     KeyCommandHandler handler;
3462     ASSERT_NO_FATAL_FAILURE(handler.ReportLetterGesture());
3463 }
3464 #endif // OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
3465 
3466 /**
3467  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_001
3468  * @tc.desc: Test the funcation HandleShortKeys
3469  * @tc.type: FUNC
3470  * @tc.require:
3471  */
3472 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_001, TestSize.Level1)
3473 {
3474     CALL_TEST_DEBUG;
3475     KeyCommandHandler handler;
3476     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3477     ASSERT_NE(keyEvent, nullptr);
3478     bool ret = handler.HandleShortKeys(keyEvent);
3479     ASSERT_FALSE(ret);
3480     ShortcutKey key;
3481     key.preKeys = {1, 2, 3};
3482     key.businessId = "business1";
3483     key.statusConfig = "config1";
3484     key.statusConfigValue = true;
3485     key.finalKey = 4;
3486     key.keyDownDuration = 5;
3487     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
3488     key.timerId = 6;
3489     Ability ability_temp;
3490     ability_temp.bundleName = "bundleName1";
3491     ability_temp.abilityName = "abilityName1";
3492     key.ability = ability_temp;
3493     handler.shortcutKeys_.insert(std::make_pair("key1", key));
3494     ret = handler.HandleShortKeys(keyEvent);
3495     ASSERT_FALSE(ret);
3496     handler.lastMatchedKey_.timerId = 1;
3497     ret = handler.HandleShortKeys(keyEvent);
3498     ASSERT_FALSE(ret);
3499     handler.lastMatchedKey_.timerId = -1;
3500     ret = handler.HandleShortKeys(keyEvent);
3501     ASSERT_FALSE(ret);
3502     std::string businessId = "power";
3503     ret = handler.HandleShortKeys(keyEvent);
3504     ASSERT_FALSE(ret);
3505 }
3506 
3507 /**
3508  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_002
3509  * @tc.desc: Test the funcation HandleShortKeys
3510  * @tc.type: FUNC
3511  * @tc.require:
3512  */
3513 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_002, TestSize.Level1)
3514 {
3515     CALL_TEST_DEBUG;
3516     KeyCommandHandler handler;
3517     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3518     ASSERT_NE(keyEvent, nullptr);
3519     ShortcutKey key;
3520     key.preKeys = {1, 2, 3};
3521     key.businessId = "business2";
3522     key.statusConfig = "config2";
3523     key.statusConfigValue = true;
3524     key.finalKey = 5;
3525     key.keyDownDuration = 6;
3526     key.triggerType = KeyEvent::KEY_ACTION_UP;
3527     key.timerId = 6;
3528     Ability ability_temp;
3529     ability_temp.bundleName = "bundleName2";
3530     ability_temp.abilityName = "abilityName2";
3531     key.ability = ability_temp;
3532     handler.shortcutKeys_.insert(std::make_pair("key2", key));
3533     bool ret = handler.HandleShortKeys(keyEvent);
3534     ASSERT_FALSE(ret);
3535     handler.lastMatchedKey_.timerId = -1;
3536     ret = handler.HandleShortKeys(keyEvent);
3537     ASSERT_FALSE(ret);
3538     std::string businessId = "power";
3539     ret = handler.HandleShortKeys(keyEvent);
3540     ASSERT_FALSE(ret);
3541 }
3542 
3543 /**
3544  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_003
3545  * @tc.desc: Test the funcation HandleShortKeys
3546  * @tc.type: FUNC
3547  * @tc.require:
3548  */
3549 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_003, TestSize.Level1)
3550 {
3551     CALL_TEST_DEBUG;
3552     KeyCommandHandler handler;
3553     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3554     ASSERT_NE(keyEvent, nullptr);
3555     ShortcutKey key;
3556     key.preKeys = {1, 2, 3};
3557     key.businessId = "business3";
3558     key.statusConfig = "config3";
3559     key.statusConfigValue = true;
3560     key.finalKey = 7;
3561     key.keyDownDuration = 8;
3562     key.triggerType = KeyEvent::KEY_ACTION_CANCEL;
3563     key.timerId = 6;
3564     Ability ability_temp;
3565     ability_temp.bundleName = "bundleName3";
3566     ability_temp.abilityName = "abilityName3";
3567     key.ability = ability_temp;
3568     handler.shortcutKeys_.insert(std::make_pair("key3", key));
3569     bool ret = handler.HandleShortKeys(keyEvent);
3570     ASSERT_FALSE(ret);
3571     handler.lastMatchedKey_.timerId = -1;
3572     ret = handler.HandleShortKeys(keyEvent);
3573     ASSERT_FALSE(ret);
3574     std::string businessId = "power";
3575     ret = handler.HandleShortKeys(keyEvent);
3576     ASSERT_FALSE(ret);
3577 }
3578 
3579 /**
3580  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_04
3581  * @tc.desc: Test the funcation HandleShortKeys
3582  * @tc.type: FUNC
3583  * @tc.require:
3584  */
3585 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_04, TestSize.Level1)
3586 {
3587     CALL_TEST_DEBUG;
3588     KeyCommandHandler handler;
3589     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3590     ASSERT_NE(keyEvent, nullptr);
3591     ShortcutKey key;
3592     key.preKeys = {1, 2, 3};
3593     key.businessId = "business2";
3594     key.statusConfig = "config2";
3595     key.statusConfigValue = true;
3596     key.finalKey = 5;
3597     key.keyDownDuration = 6;
3598     key.triggerType = KeyEvent::KEY_ACTION_UP;
3599     key.timerId = 6;
3600     Ability ability_temp;
3601     ability_temp.bundleName = "bundleName2";
3602     ability_temp.abilityName = "abilityName2";
3603     key.ability = ability_temp;
3604     handler.shortcutKeys_.insert(std::make_pair("key2", key));
3605     bool ret = handler.HandleShortKeys(keyEvent);
3606     EXPECT_FALSE(ret);
3607     handler.lastMatchedKey_.timerId = -1;
3608     ret = handler.HandleShortKeys(keyEvent);
3609     EXPECT_FALSE(ret);
3610 
3611     key.businessId = "power";
3612     int32_t delay = handler.GetKeyDownDurationFromXml(key.businessId);
3613     EXPECT_TRUE(delay < 0);
3614     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
3615     ret = handler.HandleShortKeys(keyEvent);
3616     EXPECT_FALSE(ret);
3617 
3618     key.triggerType = KeyEvent::KEY_ACTION_UP;
3619     bool handleResult = handler.HandleKeyUp(keyEvent, key);
3620     EXPECT_FALSE(handleResult);
3621     ret = handler.HandleShortKeys(keyEvent);
3622     EXPECT_FALSE(ret);
3623 }
3624 
3625 /**
3626  * @tc.name: KeyCommandHandlerTest_AddSequenceKey_001
3627  * @tc.desc: Test the funcation AddSequenceKey
3628  * @tc.type: FUNC
3629  * @tc.require:
3630  */
3631 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_001, TestSize.Level1)
3632 {
3633     CALL_TEST_DEBUG;
3634     KeyCommandHandler handler;
3635     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3636     ASSERT_NE(keyEvent, nullptr);
3637     SequenceKey sequenceKey;
3638     sequenceKey.keyCode = 1;
3639     sequenceKey.keyAction = 2;
3640     sequenceKey.actionTime = 3;
3641     sequenceKey.delay = 4;
3642     handler.keys_.push_back(sequenceKey);
3643     bool ret = handler.AddSequenceKey(keyEvent);
3644     ASSERT_TRUE(ret);
3645 }
3646 
3647 /**
3648  * @tc.name: KeyCommandHandlerTest_AddSequenceKey_002
3649  * @tc.desc: Test the funcation AddSequenceKey
3650  * @tc.type: FUNC
3651  * @tc.require:
3652  */
3653 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_002, TestSize.Level1)
3654 {
3655     CALL_TEST_DEBUG;
3656     KeyCommandHandler handler;
3657     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3658     ASSERT_NE(keyEvent, nullptr);
3659     SequenceKey sequenceKey;
3660     sequenceKey.keyCode = 1;
3661     sequenceKey.keyAction = 2;
3662     sequenceKey.actionTime = 15;
3663     sequenceKey.delay = 16;
3664     handler.keys_.push_back(sequenceKey);
3665     bool ret = handler.AddSequenceKey(keyEvent);
3666     ASSERT_TRUE(ret);
3667 }
3668 
3669 /**
3670  * @tc.name: KeyCommandHandlerTest_AddSequenceKey_003
3671  * @tc.desc: Test the funcation AddSequenceKey
3672  * @tc.type: FUNC
3673  * @tc.require:
3674  */
3675 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_AddSequenceKey_003, TestSize.Level1)
3676 {
3677     CALL_TEST_DEBUG;
3678     KeyCommandHandler handler;
3679     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3680     ASSERT_NE(keyEvent, nullptr);
3681     SequenceKey sequenceKey;
3682     sequenceKey.keyCode = 1;
3683     sequenceKey.keyAction = 2;
3684     sequenceKey.actionTime = -2;
3685     sequenceKey.delay = -3;
3686     handler.keys_.push_back(sequenceKey);
3687     bool ret = handler.AddSequenceKey(keyEvent);
3688     ASSERT_TRUE(ret);
3689     handler.keys_.clear();
3690     ret = handler.AddSequenceKey(keyEvent);
3691     ASSERT_TRUE(ret);
3692 }
3693 
3694 /**
3695  * @tc.name: KeyCommandHandlerTest_HandleNormalSequence_001
3696  * @tc.desc: Test the funcation HandleNormalSequence
3697  * @tc.type: FUNC
3698  * @tc.require:
3699  */
3700 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleNormalSequence_001, TestSize.Level1)
3701 {
3702     CALL_TEST_DEBUG;
3703     KeyCommandHandler handler;
3704     Sequence sequence;
3705     bool isLaunchAbility = true;
3706     sequence.abilityStartDelay = 0;
3707     bool ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3708     ASSERT_TRUE(ret);
3709     sequence.abilityStartDelay = 1;
3710     sequence.timerId = -1;
3711     ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3712     ASSERT_TRUE(ret);
3713     sequence.timerId = 1;
3714     ret = handler.HandleNormalSequence(sequence, isLaunchAbility);
3715     ASSERT_TRUE(ret);
3716 }
3717 
3718 /**
3719  * @tc.name: KeyCommandHandlerTest_HandleMatchedSequence_001
3720  * @tc.desc: Test the funcation HandleMatchedSequence
3721  * @tc.type: FUNC
3722  * @tc.require:
3723  */
3724 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMatchedSequence_001, TestSize.Level1)
3725 {
3726     CALL_TEST_DEBUG;
3727     KeyCommandHandler handler;
3728     Sequence sequence;
3729     bool isLaunchAbility = true;
3730     sequence.ability.bundleName = ".screenshot";
3731     bool ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3732     ASSERT_TRUE(ret);
3733     sequence.ability.bundleName = "abc";
3734     DisplayEventMonitor displayEventMonitor;
3735     displayEventMonitor.screenStatus_ = "usual.event.SCREEN_OFF";
3736     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3737     ASSERT_TRUE(ret);
3738     displayEventMonitor.screenStatus_ = "usual.event.SCREEN_ON";
3739     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3740     ASSERT_TRUE(ret);
3741     displayEventMonitor.isScreenLocked_ = true;
3742     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3743     ASSERT_TRUE(ret);
3744     displayEventMonitor.isScreenLocked_ = false;
3745     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
3746     ASSERT_TRUE(ret);
3747 }
3748 
3749 /**
3750  * @tc.name: KeyCommandHandlerTest_HandleSequence_001
3751  * @tc.desc: Test the funcation HandleSequence
3752  * @tc.type: FUNC
3753  * @tc.require:
3754  */
3755 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequence_001, TestSize.Level1)
3756 {
3757     CALL_TEST_DEBUG;
3758     KeyCommandHandler handler;
3759     Sequence sequence;
3760     SequenceKey sequenceKey;
3761     bool isLaunchAbility = true;
3762     sequence.statusConfigValue = false;
3763     bool ret = handler.HandleSequence(sequence, isLaunchAbility);
3764     ASSERT_FALSE(ret);
3765     sequence.statusConfigValue = true;
3766     sequenceKey.keyCode = 10;
3767     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
3768     sequenceKey.actionTime = 10;
3769     sequenceKey.delay = 10;
3770     handler.keys_.push_back(sequenceKey);
3771     sequence.sequenceKeys.push_back(sequenceKey);
3772     ret = handler.HandleSequence(sequence, isLaunchAbility);
3773     ASSERT_TRUE(ret);
3774 }
3775 
3776 /**
3777  * @tc.name: KeyCommandHandlerTest_ConvertKeyActionToString_001
3778  * @tc.desc: Test the funcation ConvertKeyActionToString
3779  * @tc.type: FUNC
3780  * @tc.require:
3781  */
3782 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertKeyActionToString_001, TestSize.Level1)
3783 {
3784     CALL_TEST_DEBUG;
3785     KeyCommandHandler handler;
3786     int32_t keyAction = 0;
3787     std::string ret = handler.ConvertKeyActionToString(keyAction);
3788     ASSERT_EQ(ret, "UNKNOWN");
3789     keyAction = 1;
3790     ret = handler.ConvertKeyActionToString(keyAction);
3791     ASSERT_EQ(ret, "CANCEL");
3792     keyAction = 2;
3793     ret = handler.ConvertKeyActionToString(keyAction);
3794     ASSERT_EQ(ret, "DOWN");
3795     keyAction = 3;
3796     ret = handler.ConvertKeyActionToString(keyAction);
3797     ASSERT_EQ(ret, "UP");
3798     keyAction = 4;
3799     ret = handler.ConvertKeyActionToString(keyAction);
3800     ASSERT_EQ(ret, "UNKNOWN_ACTION");
3801 }
3802 
3803 /**
3804  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_001
3805  * @tc.desc: Test the funcation HandleKeyEvent
3806  * @tc.type: FUNC
3807  * @tc.require:
3808  */
3809 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_001, TestSize.Level1)
3810 {
3811     CALL_TEST_DEBUG;
3812     KeyCommandHandler handler;
3813     handler.EnableCombineKey(false);
3814     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3815     ASSERT_NE(keyEvent, nullptr);
3816     KeyEvent::KeyItem item;
3817     item.SetKeyCode(KeyEvent::KEYCODE_POWER);
3818     keyEvent->AddKeyItem(item);
3819     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
3820     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
3821 }
3822 
3823 /**
3824  * @tc.name: KeyCommandHandlerTest_HandlePointerEvent_001
3825  * @tc.desc: Test the funcation HandlePointerEvent
3826  * @tc.type: FUNC
3827  * @tc.require:
3828  */
3829 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerEvent_001, TestSize.Level1)
3830 {
3831     CALL_TEST_DEBUG;
3832     KeyCommandHandler handler;
3833     handler.EnableCombineKey(false);
3834     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
3835     ASSERT_TRUE(pointerEvent != nullptr);
3836     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
3837     ASSERT_NE(keyEvent, nullptr);
3838     KeyEvent::KeyItem item;
3839     item.SetKeyCode(KeyEvent::KEYCODE_POWER);
3840     keyEvent->AddKeyItem(item);
3841     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
3842     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerEvent(pointerEvent));
3843 }
3844 
3845 /**
3846  * @tc.name: KeyCommandHandlerTest_HandleTouchEventTest_005
3847  * @tc.desc: Test the funcation HandleTouchEvent
3848  * @tc.require:
3849  */
3850 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleTouchEventTest_005, TestSize.Level1)
3851 {
3852     CALL_DEBUG_ENTER;
3853     KeyCommandHandler handler;
3854     std::shared_ptr<PointerEvent> pointerEvent = SetupDoubleKnuckleDownEvent();
3855     ASSERT_TRUE(pointerEvent != nullptr);
3856     handler.nextHandler_ = std::make_shared<EventFilterHandler>();
3857     handler.SetNext(handler.nextHandler_);
3858     PointerEvent::PointerItem item;
3859     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3860     ASSERT_NE(touchEvent, nullptr);
3861     item.SetPointerId(1);
3862     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
3863     touchEvent->AddPointerItem(item);
3864     ASSERT_NO_FATAL_FAILURE(handler.HandleTouchEvent(pointerEvent));
3865     item.SetPointerId(2);
3866     item.SetToolType(PointerEvent::TOOL_TYPE_PALM);
3867     touchEvent->AddPointerItem(item);
3868     ASSERT_NO_FATAL_FAILURE(handler.HandleTouchEvent(pointerEvent));
3869 }
3870 
3871 /**
3872  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_001
3873  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
3874  * @tc.type: FUNC
3875  * @tc.require:
3876  */
3877 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_001, TestSize.Level1)
3878 {
3879     CALL_TEST_DEBUG;
3880     KeyCommandHandler handler;
3881     handler.twoFingerGesture_.active = false;
3882     bool ret = handler.CheckTwoFingerGestureAction();
3883     EXPECT_FALSE(ret);
3884     handler.twoFingerGesture_.active = true;
3885     handler.twoFingerGesture_.touches[0].id = 1;
3886     handler.twoFingerGesture_.touches[0].x = 100;
3887     handler.twoFingerGesture_.touches[0].y = 200;
3888     handler.twoFingerGesture_.touches[0].downTime = 250000;
3889     handler.twoFingerGesture_.touches[1].id = 2;
3890     handler.twoFingerGesture_.touches[1].x = 300;
3891     handler.twoFingerGesture_.touches[1].y = 400;
3892     handler.twoFingerGesture_.touches[1].downTime = 50000;
3893     ret = handler.CheckTwoFingerGestureAction();
3894     EXPECT_FALSE(ret);
3895 }
3896 
3897 /**
3898  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_002
3899  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
3900  * @tc.type: FUNC
3901  * @tc.require:
3902  */
3903 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_002, TestSize.Level1)
3904 {
3905     CALL_TEST_DEBUG;
3906     KeyCommandHandler handler;
3907     handler.twoFingerGesture_.active = true;
3908     handler.twoFingerGesture_.touches[0].id = 1;
3909     handler.twoFingerGesture_.touches[0].x = 100;
3910     handler.twoFingerGesture_.touches[0].y = 200;
3911     handler.twoFingerGesture_.touches[0].downTime = 150000;
3912     handler.twoFingerGesture_.touches[1].id = 2;
3913     handler.twoFingerGesture_.touches[1].x = 300;
3914     handler.twoFingerGesture_.touches[1].y = 400;
3915     handler.twoFingerGesture_.touches[1].downTime = 50000;
3916     bool ret = handler.CheckTwoFingerGestureAction();
3917     EXPECT_FALSE(ret);
3918 }
3919 
3920 /**
3921  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_001
3922  * @tc.desc: Test the funcation ConvertVPToPX
3923  * @tc.type: FUNC
3924  * @tc.require:
3925  */
3926 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_001, TestSize.Level1)
3927 {
3928     CALL_TEST_DEBUG;
3929     KeyCommandHandler handler;
3930     int32_t vp = -1;
3931     ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
3932     vp = 1;
3933     ASSERT_NO_FATAL_FAILURE(handler.ConvertVPToPX(vp));
3934 }
3935 
3936 /**
3937  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_002
3938  * @tc.desc: Test the funcation HandleKnuckleGestureTouchMove
3939  * @tc.type: FUNC
3940  * @tc.require:
3941  */
3942 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_002, TestSize.Level1)
3943 {
3944     CALL_TEST_DEBUG;
3945     KeyCommandHandler handler;
3946     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
3947     ASSERT_NE(touchEvent, nullptr);
3948     PointerEvent::PointerItem item;
3949     item.SetDisplayX(8.0);
3950     item.SetDisplayY(8.0);
3951     handler.gestureLastX_ = 4.0;
3952     handler.gestureLastY_ = 4.0;
3953     handler.isGesturing_ = false;
3954     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3955     handler.isGesturing_ = true;
3956     handler.isLetterGesturing_ = false;
3957     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3958     handler.isLetterGesturing_ = true;
3959     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3960     handler.gestureLastX_ = 6.0;
3961     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3962     handler.gestureLastY_ = 6.0;
3963     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
3964 }
3965 
3966 /**
3967  * @tc.name: KeyCommandHandlerTest_ReportIfNeed_001
3968  * @tc.desc: Test the funcation ReportIfNeed
3969  * @tc.type: FUNC
3970  * @tc.require:
3971  */
3972 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportIfNeed_001, TestSize.Level1)
3973 {
3974     CALL_TEST_DEBUG;
3975     KeyCommandHandler handler;
3976     ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3977     handler.isGesturing_ = true;
3978     handler.isLastGestureSucceed_ = true;
3979     ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3980     handler.isLastGestureSucceed_ = false;
3981     ASSERT_NO_FATAL_FAILURE(handler.ReportIfNeed());
3982 }
3983 
3984 /**
3985  * @tc.name: KeyCommandHandlerTest_ReportGestureInfo_001
3986  * @tc.desc: Test the funcation ReportGestureInfo
3987  * @tc.type: FUNC
3988  * @tc.require:
3989  */
3990 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportGestureInfo_001, TestSize.Level1)
3991 {
3992     CALL_TEST_DEBUG;
3993     KeyCommandHandler handler;
3994     handler.isLastGestureSucceed_ = true;
3995     ASSERT_NO_FATAL_FAILURE(handler.ReportGestureInfo());
3996     handler.isLastGestureSucceed_ = false;
3997     ASSERT_NO_FATAL_FAILURE(handler.ReportGestureInfo());
3998 }
3999 
4000 /**
4001  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_004
4002  * @tc.desc: Test knuckle gesture touch up event straight line
4003  * @tc.type: FUNC
4004  * @tc.require:
4005  */
4006 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_004, TestSize.Level1)
4007 {
4008     CALL_TEST_DEBUG;
4009     KeyCommandHandler handler;
4010     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4011     ASSERT_NE(touchEvent, nullptr);
4012     GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool,
__anonde368b400302(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 4013                                          bool) -> int32_t {
4014         return 0;
4015     };
4016     ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
4017     handler.gesturePoints_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
4018     handler.gestureTimeStamps_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
4019     handler.isGesturing_ = true;
4020     handler.isLetterGesturing_ = true;
4021     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4022     handler.gesturePoints_.assign(CIRCLE_COORDINATES.begin(), CIRCLE_COORDINATES.end());
4023     handler.gestureTimeStamps_.assign(CIRCLE_TIMESTAMPS.begin(), CIRCLE_TIMESTAMPS.end());
4024     handler.isGesturing_ = true;
4025     handler.isLetterGesturing_ = true;
4026     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4027     handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
4028     handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
4029     handler.isGesturing_ = true;
4030     handler.isLetterGesturing_ = true;
4031     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4032 }
4033 
4034 /**
4035  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_004
4036  * @tc.desc: Test the funcation HandleShortKeys
4037  * @tc.type: FUNC
4038  * @tc.require:
4039  */
4040 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_004, TestSize.Level1)
4041 {
4042     KeyCommandHandler handler;
4043     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4044     ASSERT_NE(keyEvent, nullptr);
4045     ShortcutKey key;
4046     key.preKeys = {1, 2, 3};
4047     key.businessId = "business1";
4048     key.statusConfig = "config1";
4049     key.statusConfigValue = true;
4050     key.finalKey = 4;
4051     key.keyDownDuration = 5;
4052     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
4053     key.timerId = 6;
4054     handler.lastMatchedKey_.finalKey = 1;
4055     handler.lastMatchedKey_.triggerType = 2;
4056     keyEvent->SetKeyCode(1);
4057     keyEvent->SetKeyAction(2);
4058     bool result = handler.IsKeyMatch(handler.lastMatchedKey_, keyEvent);
4059     ASSERT_FALSE(result);
4060     handler.shortcutKeys_.insert(std::make_pair("key1", key));
4061     bool ret = handler.HandleShortKeys(keyEvent);
4062     ASSERT_FALSE(ret);
4063 }
4064 
4065 /**
4066  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_005
4067  * @tc.desc: Test the funcation HandleShortKeys
4068  * @tc.type: FUNC
4069  * @tc.require:
4070  */
4071 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_005, TestSize.Level1)
4072 {
4073     KeyCommandHandler handler;
4074     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4075     ASSERT_NE(keyEvent, nullptr);
4076     ShortcutKey key;
4077     key.preKeys = {1, 2, 3};
4078     key.businessId = "business1";
4079     key.statusConfig = "config1";
4080     key.statusConfigValue = true;
4081     key.finalKey = 4;
4082     key.keyDownDuration = 5;
4083     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
4084     key.timerId = 6;
4085     handler.currentLaunchAbilityKey_.finalKey = 1;
4086     handler.currentLaunchAbilityKey_.triggerType = 2;
4087     keyEvent->SetKeyCode(1);
4088     keyEvent->SetKeyAction(2);
4089     bool result = handler.IsKeyMatch(handler.currentLaunchAbilityKey_, keyEvent);
4090     ASSERT_FALSE(result);
4091     handler.shortcutKeys_.insert(std::make_pair("key1", key));
4092     handler.currentLaunchAbilityKey_.timerId = 0;
4093     bool ret = handler.HandleShortKeys(keyEvent);
4094     ASSERT_FALSE(ret);
4095     handler.currentLaunchAbilityKey_.timerId = -1;
4096     ret = handler.HandleShortKeys(keyEvent);
4097     ASSERT_FALSE(ret);
4098     handler.currentLaunchAbilityKey_.timerId = 0;
4099     handler.currentLaunchAbilityKey_.finalKey = 1;
4100     handler.currentLaunchAbilityKey_.triggerType = 2;
4101     keyEvent->SetKeyCode(3);
4102     keyEvent->SetKeyAction(4);
4103     ret = handler.HandleShortKeys(keyEvent);
4104     ASSERT_FALSE(ret);
4105     handler.currentLaunchAbilityKey_.timerId = -1;
4106     handler.currentLaunchAbilityKey_.finalKey = 1;
4107     handler.currentLaunchAbilityKey_.triggerType = 2;
4108     keyEvent->SetKeyCode(3);
4109     keyEvent->SetKeyAction(4);
4110     ret = handler.HandleShortKeys(keyEvent);
4111     ASSERT_FALSE(ret);
4112 }
4113 
4114 /**
4115  * @tc.name: KeyCommandHandlerTest_HandleMatchedSequence_002
4116  * @tc.desc: Test the funcation HandleMatchedSequence
4117  * @tc.type: FUNC
4118  * @tc.require:
4119  */
4120 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleMatchedSequence_002, TestSize.Level1)
4121 {
4122     CALL_TEST_DEBUG;
4123     KeyCommandHandler handler;
4124     Sequence sequence;
4125     bool isLaunchAbility = true;
4126     DISPLAY_MONITOR->isScreenLocked_ = false;
4127     sequence.ability.bundleName = ".screenshot";
4128     DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_OFF";
4129     bool ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4130     ASSERT_TRUE(ret);
4131     DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_OFF";
4132     sequence.ability.bundleName = "abc";
4133     DisplayEventMonitor displayEventMonitor;
4134     displayEventMonitor.screenStatus_ = "usual.event.SCREEN_OFF";
4135     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4136     ASSERT_TRUE(ret);
4137     DISPLAY_MONITOR->screenStatus_ = "usual.event.SCREEN_LOCKED";
4138     DISPLAY_MONITOR->isScreenLocked_ = true;
4139     sequence.ability.bundleName = ".screenshot";
4140     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4141     ASSERT_TRUE(ret);
4142     DISPLAY_MONITOR->isScreenLocked_ = false;
4143     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4144     ASSERT_TRUE(ret);
4145     DISPLAY_MONITOR->isScreenLocked_ = true;
4146     sequence.ability.bundleName = "abc";
4147     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4148     ASSERT_TRUE(ret);
4149     DISPLAY_MONITOR->isScreenLocked_ = false;
4150     sequence.ability.bundleName = "abc";
4151     ret = handler.HandleMatchedSequence(sequence, isLaunchAbility);
4152     ASSERT_TRUE(ret);
4153 }
4154 
4155 /**
4156  * @tc.name: KeyCommandHandlerTest_HandlePointerVisibleKeys_001
4157  * @tc.desc: Test HandlePointerVisibleKeys
4158  * @tc.type: FUNC
4159  * @tc.require:
4160  */
4161 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandlePointerVisibleKeys_001, TestSize.Level1)
4162 {
4163     CALL_TEST_DEBUG;
4164     KeyCommandHandler handler;
4165     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4166     ASSERT_NE(keyEvent, nullptr);
4167     keyEvent->keyCode_ = KeyEvent::KEYCODE_F9;
4168     handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CTRL_LEFT;
4169     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4170     keyEvent->keyCode_ = KeyEvent::KEYCODE_F1;
4171     handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CTRL_LEFT;
4172     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4173     keyEvent->keyCode_ = KeyEvent::KEYCODE_F9;
4174     handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CAPS_LOCK;
4175     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4176     keyEvent->keyCode_ = KeyEvent::KEYCODE_F1;
4177     handler.lastKeyEventCode_ = KeyEvent::KEYCODE_CAPS_LOCK;
4178     ASSERT_NO_FATAL_FAILURE(handler.HandlePointerVisibleKeys(keyEvent));
4179 }
4180 
4181 /**
4182  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_002
4183  * @tc.desc: Test the funcation ConvertVPToPX
4184  * @tc.type: FUNC
4185  * @tc.require:
4186  */
4187 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_002, TestSize.Level1)
4188 {
4189     CALL_TEST_DEBUG;
4190     KeyCommandHandler handler;
4191     int32_t vp = -5;
4192     int32_t ret = handler.ConvertVPToPX(vp);
4193     ASSERT_EQ(ret, 0);
4194     vp = 5;
4195     InputWindowsManager inputWindowsManager;
4196     OLD::DisplayInfo displayInfo;
4197     displayInfo.id = 1;
4198     displayInfo.x = 2;
4199     displayInfo.y = 3;
4200     displayInfo.width = 4;
4201     displayInfo.height = 5;
4202     displayInfo.dpi = -1;
4203     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
4204     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
4205         it->second.displaysInfo.push_back(displayInfo);
4206     }
4207     ret = handler.ConvertVPToPX(vp);
4208     ASSERT_EQ(ret, 0);
4209 }
4210 
4211 /**
4212  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_003
4213  * @tc.desc: Test the funcation ConvertVPToPX
4214  * @tc.type: FUNC
4215  * @tc.require:
4216  */
4217 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_003, TestSize.Level1)
4218 {
4219     CALL_TEST_DEBUG;
4220     KeyCommandHandler handler;
4221     int32_t vp = 5;
4222     InputWindowsManager inputWindowsManager;
4223     OLD::DisplayInfo displayInfo;
4224     displayInfo.id = 1;
4225     displayInfo.x = 2;
4226     displayInfo.y = 3;
4227     displayInfo.width = 4;
4228     displayInfo.height = 5;
4229     displayInfo.dpi = 160;
4230     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
4231     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
4232         it->second.displaysInfo.push_back(displayInfo);
4233     }
4234     int32_t ret = handler.ConvertVPToPX(vp);
4235     ASSERT_EQ(ret, 0);
4236 }
4237 
4238 /**
4239  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_003
4240  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4241  * @tc.type: FUNC
4242  * @tc.require:
4243  */
4244 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_003, TestSize.Level1)
4245 {
4246     CALL_TEST_DEBUG;
4247     KeyCommandHandler handler;
4248     handler.twoFingerGesture_.active = true;
4249     handler.twoFingerGesture_.touches[0].id = 1;
4250     handler.twoFingerGesture_.touches[0].x = -100;
4251     handler.twoFingerGesture_.touches[0].y = -200;
4252     handler.twoFingerGesture_.touches[0].downTime = 100000;
4253     handler.twoFingerGesture_.touches[1].id = 2;
4254     handler.twoFingerGesture_.touches[1].x = -300;
4255     handler.twoFingerGesture_.touches[1].y = -400;
4256     handler.twoFingerGesture_.touches[1].downTime = 50000;
4257     InputWindowsManager inputWindowsManager;
4258     OLD::DisplayInfo displayInfo;
4259     displayInfo.id = 1;
4260     displayInfo.x = 2;
4261     displayInfo.y = 3;
4262     displayInfo.width = 4;
4263     displayInfo.height = 5;
4264     displayInfo.dpi = -1;
4265     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
4266     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
4267         it->second.displaysInfo.push_back(displayInfo);
4268     }
4269     bool ret = handler.CheckTwoFingerGestureAction();
4270     EXPECT_FALSE(ret);
4271 }
4272 
4273 /**
4274  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_004
4275  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4276  * @tc.type: FUNC
4277  * @tc.require:
4278  */
4279 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_004, TestSize.Level1)
4280 {
4281     CALL_TEST_DEBUG;
4282     KeyCommandHandler handler;
4283     handler.twoFingerGesture_.active = true;
4284     handler.twoFingerGesture_.touches[0].id = 1;
4285     handler.twoFingerGesture_.touches[0].x = 100;
4286     handler.twoFingerGesture_.touches[0].y = 200;
4287     handler.twoFingerGesture_.touches[0].downTime = 100000;
4288     handler.twoFingerGesture_.touches[1].id = 2;
4289     handler.twoFingerGesture_.touches[1].x = 300;
4290     handler.twoFingerGesture_.touches[1].y = 400;
4291     handler.twoFingerGesture_.touches[1].downTime = 50000;
4292     InputWindowsManager inputWindowsManager;
4293     OLD::DisplayInfo displayInfo;
4294     displayInfo.id = 1;
4295     displayInfo.x = 2;
4296     displayInfo.y = 3;
4297     displayInfo.width = 40;
4298     displayInfo.height = 50;
4299     displayInfo.dpi = -1;
4300     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
4301     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
4302         it->second.displaysInfo.push_back(displayInfo);
4303     }
4304     bool ret = handler.CheckTwoFingerGestureAction();
4305     EXPECT_FALSE(ret);
4306 }
4307 
4308 /**
4309  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_005
4310  * @tc.desc: Test the funcation CheckTwoFingerGestureAction
4311  * @tc.type: FUNC
4312  * @tc.require:
4313  */
4314 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_005, TestSize.Level1)
4315 {
4316     CALL_TEST_DEBUG;
4317     KeyCommandHandler handler;
4318     handler.twoFingerGesture_.active = true;
4319     handler.twoFingerGesture_.touches[0].id = 1;
4320     handler.twoFingerGesture_.touches[0].x = 10;
4321     handler.twoFingerGesture_.touches[0].y = 20;
4322     handler.twoFingerGesture_.touches[0].downTime = 100000;
4323     handler.twoFingerGesture_.touches[1].id = 2;
4324     handler.twoFingerGesture_.touches[1].x = 30;
4325     handler.twoFingerGesture_.touches[1].y = 20;
4326     handler.twoFingerGesture_.touches[1].downTime = 50000;
4327     InputWindowsManager inputWindowsManager;
4328     OLD::DisplayInfo displayInfo;
4329     displayInfo.id = 1;
4330     displayInfo.x = 2;
4331     displayInfo.y = 3;
4332     displayInfo.width = 40;
4333     displayInfo.height = 50;
4334     displayInfo.dpi = -1;
4335     auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
4336     if (it != inputWindowsManager.displayGroupInfoMap_.end()) {
4337         it->second.displaysInfo.push_back(displayInfo);
4338     }
4339     bool ret = handler.CheckTwoFingerGestureAction();
4340     EXPECT_FALSE(ret);
4341 }
4342 
4343 /**
4344  * @tc.name: KeyCommandHandlerTest_StartTwoFingerGesture_002
4345  * @tc.desc: Test the funcation StartTwoFingerGesture
4346  * @tc.type: FUNC
4347  * @tc.require:
4348  */
4349 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_StartTwoFingerGesture_002, TestSize.Level1)
4350 {
4351     KeyCommandHandler handler;
4352     handler.twoFingerGesture_.active = false;
4353     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
4354     handler.twoFingerGesture_.active = true;
4355     handler.twoFingerGesture_.touches[0].id = 5;
4356     handler.twoFingerGesture_.touches[0].x = 50;
4357     handler.twoFingerGesture_.touches[0].y = 60;
4358     handler.twoFingerGesture_.touches[0].downTime = 13000;
4359     handler.twoFingerGesture_.touches[1].id = 9;
4360     handler.twoFingerGesture_.touches[1].x = 100;
4361     handler.twoFingerGesture_.touches[1].y = 400;
4362     handler.twoFingerGesture_.touches[1].downTime = 96000;
4363     ASSERT_NO_FATAL_FAILURE(handler.StartTwoFingerGesture());
4364 }
4365 
4366 /**
4367  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_005
4368  * @tc.desc: Test the funcation HandleKnuckleGestureTouchUp
4369  * @tc.type: FUNC
4370  * @tc.require:
4371  */
4372 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_005, TestSize.Level1)
4373 {
4374     CALL_TEST_DEBUG;
4375     KeyCommandHandler handler;
4376     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4377     ASSERT_NE(touchEvent, nullptr);
4378     GESTURESENSE_WRAPPER->touchUp_ = [](const std::vector<float> &, const std::vector<int64_t> &, bool,
__anonde368b400402(const std::vector<float> &, const std::vector<int64_t> &, bool, bool) 4379                                          bool) -> int32_t {
4380         return 0;
4381     };
4382     ASSERT_NE(GESTURESENSE_WRAPPER->touchUp_, nullptr);
4383     handler.isGesturing_ = false;
4384     handler.isLetterGesturing_ = false;
4385     handler.gesturePoints_.assign(LINE_TIMESTAMPS.begin(), LINE_TIMESTAMPS.end());
4386     handler.gestureTimeStamps_.assign(LINE_COORDINATES.begin(), LINE_COORDINATES.end());
4387     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4388     handler.gesturePoints_.assign(CURVE_COORDINATES.begin(), CURVE_COORDINATES.end());
4389     handler.gestureTimeStamps_.assign(CURVE_TIMESTAMPS.begin(), CURVE_TIMESTAMPS.end());
4390     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4391     handler.isGesturing_ = true;
4392     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4393     handler.isLetterGesturing_ = true;
4394     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(touchEvent));
4395 }
4396 
4397 /**
4398  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_01
4399  * @tc.desc: Test HandleKnuckleGestureTouchUp
4400  * @tc.type: FUNC
4401  * @tc.require:
4402  */
4403 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_01, TestSize.Level1)
4404 {
4405     CALL_TEST_DEBUG;
4406     KeyCommandHandler handler;
4407     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4408     ASSERT_NE(pointerEvent, nullptr);
4409 
4410     NotifyType notifyType;
4411     notifyType = NotifyType::REGIONGESTURE;
4412     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4413 }
4414 
4415 /**
4416  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_02
4417  * @tc.desc: Test HandleKnuckleGestureTouchUp
4418  * @tc.type: FUNC
4419  * @tc.require:
4420  */
4421 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_02, TestSize.Level1)
4422 {
4423     CALL_TEST_DEBUG;
4424     KeyCommandHandler handler;
4425     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4426     ASSERT_NE(pointerEvent, nullptr);
4427 
4428     NotifyType notifyType;
4429     notifyType = NotifyType::LETTERGESTURE;
4430     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4431 }
4432 
4433 /**
4434  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_03
4435  * @tc.desc: Test HandleKnuckleGestureTouchUp
4436  * @tc.type: FUNC
4437  * @tc.require:
4438  */
4439 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchUp_03, TestSize.Level1)
4440 {
4441     CALL_TEST_DEBUG;
4442     KeyCommandHandler handler;
4443     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4444     ASSERT_NE(pointerEvent, nullptr);
4445 
4446     NotifyType notifyType;
4447     notifyType = NotifyType::OTHER;
4448     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchUp(pointerEvent));
4449 }
4450 
4451 /**
4452  * @tc.name: KeyCommandHandlerTest_ParseJson_001
4453  * @tc.desc: Test the funcation ParseJson
4454  * @tc.type: FUNC
4455  * @tc.require:
4456  */
4457 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_001, TestSize.Level1)
4458 {
4459     CALL_TEST_DEBUG;
4460     KeyCommandHandler handler;
4461     std::string configFile;
4462     bool ret = handler.ParseJson(configFile);
4463     EXPECT_FALSE(ret);
4464     configFile = "config";
4465     std::string copyShortcutKey = "copyShortcutKey";
4466     ShortcutKey shortcutKey;
4467     Ability ability_temp;
4468     shortcutKey.preKeys.insert(2072);
4469     shortcutKey.finalKey = 2019;
4470     shortcutKey.keyDownDuration = 100;
4471     ability_temp.bundleName = "bundleName";
4472     ability_temp.abilityName = "abilityName";
4473     shortcutKey.ability = ability_temp;
4474     handler.shortcutKeys_.insert(std::make_pair(copyShortcutKey, shortcutKey));
4475     handler.businessIds_ = {"businessId"};
4476     handler.twoFingerGesture_.active = true;
4477     handler.twoFingerGesture_.timerId = 1;
4478     ret = handler.ParseJson(configFile);
4479     EXPECT_FALSE(ret);
4480 }
4481 
4482 /**
4483  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_003
4484  * @tc.desc: Test the funcation IsEnableCombineKey
4485  * @tc.type: FUNC
4486  * @tc.require:
4487  */
4488 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_003, TestSize.Level1)
4489 {
4490     CALL_TEST_DEBUG;
4491     KeyCommandHandler handler;
4492     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4493     ASSERT_NE(key, nullptr);
4494     handler.enableCombineKey_ = false;
4495     handler.isParseExcludeConfig_ = false;
4496     ASSERT_FALSE(handler.IsEnableCombineKey(key));
4497     handler.isParseExcludeConfig_ = true;
4498     ExcludeKey excludeKey;
4499     excludeKey.keyCode = 1;
4500     excludeKey.keyAction = 2;
4501     excludeKey.delay = 3;
4502     handler.excludeKeys_.push_back(excludeKey);
4503     key->keyCode_ = 1;
4504     key->keyAction_ = 2;
4505     SequenceKey sequenceKey;
4506     sequenceKey.keyCode = 2017;
4507     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4508     handler.keys_.push_back(sequenceKey);
4509     ASSERT_FALSE(handler.IsEnableCombineKey(key));
4510     sequenceKey.keyCode = 2018;
4511     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4512     handler.keys_.push_back(sequenceKey);
4513     ASSERT_FALSE(handler.IsEnableCombineKey(key));
4514 }
4515 
4516 /**
4517  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_004
4518  * @tc.desc: Test the funcation IsEnableCombineKey
4519  * @tc.type: FUNC
4520  * @tc.require:
4521  */
4522 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_004, TestSize.Level1)
4523 {
4524     CALL_TEST_DEBUG;
4525     KeyCommandHandler handler;
4526     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4527     ASSERT_NE(key, nullptr);
4528     handler.enableCombineKey_ = false;
4529     handler.isParseExcludeConfig_ = true;
4530     ExcludeKey excludeKey;
4531     excludeKey.keyCode = 1;
4532     excludeKey.keyAction = 2;
4533     excludeKey.delay = 3;
4534     handler.excludeKeys_.push_back(excludeKey);
4535     key->keyCode_ = KeyEvent::KEYCODE_L;
4536     key->keyAction_ = 200;
4537     SequenceKey sequenceKey;
4538     sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4539     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4540     handler.keys_.push_back(sequenceKey);
4541     ASSERT_TRUE(handler.IsEnableCombineKey(key));
4542     sequenceKey.keyCode = KeyEvent::KEYCODE_L;
4543     handler.keys_.push_back(sequenceKey);
4544     ASSERT_TRUE(handler.IsEnableCombineKey(key));
4545     sequenceKey.keyCode = KeyEvent::KEYCODE_META_LEFT;
4546     handler.keys_.push_back(sequenceKey);
4547     ASSERT_TRUE(handler.IsEnableCombineKey(key));
4548     sequenceKey.keyCode = KeyEvent::KEYCODE_META_RIGHT;
4549     handler.keys_.push_back(sequenceKey);
4550     ASSERT_TRUE(handler.IsEnableCombineKey(key));
4551 }
4552 
4553 /**
4554  * @tc.name: KeyCommandHandlerTest_HandleEvent_001
4555  * @tc.desc: Test the funcation HandleEvent
4556  * @tc.type: FUNC
4557  * @tc.require:
4558  */
4559 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_001, TestSize.Level1)
4560 {
4561     CALL_TEST_DEBUG;
4562     KeyCommandHandler handler;
4563     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4564     ASSERT_NE(key, nullptr);
4565     handler.enableCombineKey_ = false;
4566     handler.isParseExcludeConfig_ = true;
4567     ExcludeKey excludeKey;
4568     excludeKey.keyCode = 3;
4569     excludeKey.keyAction = 5;
4570     excludeKey.delay = 8;
4571     handler.excludeKeys_.push_back(excludeKey);
4572     key->keyCode_ = KeyEvent::KEYCODE_L;
4573     key->keyAction_ = 200;
4574     SequenceKey sequenceKey;
4575     sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4576     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4577     handler.keys_.push_back(sequenceKey);
4578     ShortcutKey shortcutKey;
4579     shortcutKey.preKeys = {1, 2, 3};
4580     shortcutKey.businessId = "business1";
4581     shortcutKey.statusConfig = "config1";
4582     shortcutKey.statusConfigValue = true;
4583     shortcutKey.finalKey = 4;
4584     shortcutKey.keyDownDuration = 5;
4585     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
4586     shortcutKey.timerId = 6;
4587     handler.currentLaunchAbilityKey_.finalKey = 1;
4588     handler.currentLaunchAbilityKey_.triggerType = 2;
4589     key->SetKeyCode(1);
4590     key->SetKeyAction(2);
4591     handler.IsKeyMatch(handler.currentLaunchAbilityKey_, key);
4592     handler.shortcutKeys_.insert(std::make_pair("key1", shortcutKey));
4593     handler.currentLaunchAbilityKey_.timerId = 0;
4594     handler.HandleShortKeys(key);
4595     handler.isKeyCancel_ = true;
4596     bool ret = handler.HandleEvent(key);
4597     EXPECT_FALSE(ret);
4598     handler.isKeyCancel_ = false;
4599     ret = handler.HandleEvent(key);
4600     EXPECT_FALSE(ret);
4601 }
4602 
4603 /**
4604  * @tc.name: KeyCommandHandlerTest_HandleEvent_002
4605  * @tc.desc: Test the funcation HandleEvent
4606  * @tc.type: FUNC
4607  * @tc.require:
4608  */
4609 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_002, TestSize.Level1)
4610 {
4611     CALL_TEST_DEBUG;
4612     KeyCommandHandler handler;
4613     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4614     ASSERT_NE(key, nullptr);
4615     handler.enableCombineKey_ = false;
4616     handler.isParseExcludeConfig_ = true;
4617     ExcludeKey excludeKey;
4618     excludeKey.keyCode = 2;
4619     excludeKey.keyAction = 6;
4620     excludeKey.delay = 9;
4621     handler.excludeKeys_.push_back(excludeKey);
4622     key->keyCode_ = KeyEvent::KEYCODE_L;
4623     key->keyAction_ = 300;
4624     SequenceKey sequenceKey;
4625     sequenceKey.keyCode = KeyEvent::KEYCODE_SPACE;
4626     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
4627     handler.keys_.push_back(sequenceKey);
4628     ShortcutKey shortcutKey;
4629     shortcutKey.preKeys = {1, 2, 3};
4630     shortcutKey.businessId = "business2";
4631     shortcutKey.statusConfig = "config2";
4632     shortcutKey.statusConfigValue = true;
4633     shortcutKey.finalKey = 5;
4634     shortcutKey.keyDownDuration = 6;
4635     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
4636     shortcutKey.timerId = 6;
4637     Ability ability_temp;
4638     ability_temp.bundleName = "bundleName2";
4639     ability_temp.abilityName = "abilityName2";
4640     shortcutKey.ability = ability_temp;
4641     handler.shortcutKeys_.insert(std::make_pair("key2", shortcutKey));
4642     handler.HandleShortKeys(key);
4643     handler.isDownStart_ = false;
4644     bool ret = handler.HandleEvent(key);
4645     EXPECT_FALSE(ret);
4646     handler.isDownStart_ = true;
4647     ret = handler.HandleEvent(key);
4648     EXPECT_FALSE(ret);
4649 }
4650 
4651 /**
4652  * @tc.name: KeyCommandHandlerTest_OnHandleEvent_001
4653  * @tc.desc: Test the funcation OnHandleEvent
4654  * @tc.type: FUNC
4655  * @tc.require:
4656  */
4657 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_001, TestSize.Level1)
4658 {
4659     CALL_TEST_DEBUG;
4660     KeyCommandHandler handler;
4661     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
4662     ASSERT_NE(key, nullptr);
4663     key->SetKeyCode(KeyEvent::KEYCODE_POWER);
4664     int32_t keyAction = KeyEvent::KEYCODE_VOLUME_UP;
4665     handler.specialKeys_.insert(std::make_pair(10, keyAction));
4666     bool ret = handler.OnHandleEvent(key);
4667     EXPECT_FALSE(ret);
4668     key->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
4669     int32_t keyCode = 99;
4670     std::list<int32_t> timerIds;
4671     timerIds.push_back(100);
4672     handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
4673     ret = handler.OnHandleEvent(key);
4674     EXPECT_FALSE(ret);
4675     keyCode = KeyEvent::KEYCODE_VOLUME_UP;
4676     handler.specialTimers_.insert(std::make_pair(keyCode, timerIds));
4677     ret = handler.OnHandleEvent(key);
4678     EXPECT_FALSE(ret);
4679 }
4680 
4681 /**
4682  * @tc.name: KeyCommandHandlerTest_OnHandleEvent_003
4683  * @tc.desc: Test the funcation OnHandleEvent
4684  * @tc.type: FUNC
4685  * @tc.require:
4686  */
4687 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_003, TestSize.Level1)
4688 {
4689     CALL_TEST_DEBUG;
4690     KeyCommandHandler handler;
4691     ASSERT_NE(keyEvent_, nullptr);
4692     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_STYLUS_SCREEN);
4693 
4694     STYLUS_HANDLER->stylusKey_.isLaunchAbility = true;
4695     bool ret = handler.OnHandleEvent(keyEvent_);
4696     EXPECT_TRUE(ret);
4697 }
4698 
4699 /**
4700  * @tc.name: KeyCommandHandlerTest_OnHandleEvent_004
4701  * @tc.desc: Test the funcation OnHandleEvent
4702  * @tc.type: FUNC
4703  * @tc.require:
4704  */
4705 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleEvent_004, TestSize.Level1)
4706 {
4707     CALL_TEST_DEBUG;
4708     KeyCommandHandler handler;
4709     ASSERT_NE(keyEvent_, nullptr);
4710 
4711     bool ret = handler.OnHandleEvent(keyEvent_);
4712     EXPECT_TRUE(ret);
4713 }
4714 
4715 /**
4716  * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_001
4717  * @tc.desc: Test the funcation HandleRepeatKey
4718  * @tc.type: FUNC
4719  * @tc.require:
4720  */
4721 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_001, TestSize.Level1)
4722 {
4723     CALL_TEST_DEBUG;
4724     KeyCommandHandler handler;
4725     RepeatKey item;
4726     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4727     ASSERT_NE(keyEvent, nullptr);
4728     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
4729     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4730     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
4731     item.times = 5;
4732     handler.count_ = 5;
4733     ASSERT_FALSE(handler.HandleRepeatKey(item, keyEvent));
4734     handler.count_ = 10;
4735     ASSERT_FALSE(handler.HandleRepeatKey(item, keyEvent));
4736 }
4737 
4738 /**
4739  * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_002
4740  * @tc.desc: Test the funcation HandleRepeatKey
4741  * @tc.type: FUNC
4742  * @tc.require:
4743  */
4744 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_002, TestSize.Level1)
4745 {
4746     CALL_TEST_DEBUG;
4747     KeyCommandHandler handler;
4748     RepeatKey item;
4749     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4750     ASSERT_NE(keyEvent, nullptr);
4751     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
4752     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4753     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
4754     item.times = 6;
4755     handler.count_ = 5;
4756     ASSERT_FALSE(handler.HandleRepeatKey(item, keyEvent));
4757 }
4758 
4759 /**
4760  * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_003
4761  * @tc.desc: HandleRepeatKey_003
4762  * @tc.type: FUNC
4763  * @tc.require:
4764  */
4765 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_003, TestSize.Level1)
4766 {
4767     CALL_TEST_DEBUG;
4768     KeyCommandHandler handler;
4769     RepeatKey repeatKey;
4770     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4771     ASSERT_NE(keyEvent, nullptr);
4772     repeatKey.times = 2;
4773     repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
4774     repeatKey.ability.bundleName = "bundleName";
4775     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
4776     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4777     handler.repeatKeyCountMap_.emplace(repeatKey.ability.bundleName, 2);
4778     handler.repeatKeyMaxTimes_.emplace(KeyEvent::KEYCODE_POWER, 2);
4779     ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, keyEvent));
4780 }
4781 
4782 /**
4783  * @tc.name: KeyCommandHandlerTest_HandleRepeatKey_004
4784  * @tc.desc: HandleRepeatKey_004
4785  * @tc.type: FUNC
4786  * @tc.require:
4787  */
4788 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKey_004, TestSize.Level1)
4789 {
4790     CALL_TEST_DEBUG;
4791     KeyCommandHandler handler;
4792     RepeatKey repeatKey;
4793     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
4794     ASSERT_NE(keyEvent, nullptr);
4795     handler.count_ = 3;
4796     repeatKey.times = 2;
4797     repeatKey.statusConfig = "statusConfig";
4798     repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
4799     repeatKey.ability.bundleName = "bundleName";
4800     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
4801     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4802     handler.repeatKeyCountMap_.emplace(repeatKey.ability.bundleName, 2);
4803     handler.repeatKeyMaxTimes_.emplace(KeyEvent::KEYCODE_POWER, 5);
4804     ASSERT_FALSE(handler.HandleRepeatKey(repeatKey, keyEvent));
4805 }
4806 
4807 /**
4808  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_001
4809  * @tc.desc: Test the funcation CheckInputMethodArea
4810  * @tc.type: FUNC
4811  * @tc.require:
4812  */
4813 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_001, TestSize.Level1)
4814 {
4815     CALL_TEST_DEBUG;
4816     KeyCommandHandler handler;
4817     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4818     ASSERT_NE(touchEvent, nullptr);
4819     WindowInfo windowInfo;
4820     windowInfo.windowType = 2000;
4821     bool ret = handler.CheckInputMethodArea(touchEvent);
4822     ASSERT_FALSE(ret);
4823     windowInfo.windowType = 2105;
4824     windowInfo.area.x = 10;
4825     windowInfo.area.width = INT32_MAX;
4826     windowInfo.area.y = 100;
4827     windowInfo.area.height = 200;
4828     std::vector<WindowInfo> windows;
4829     windows.push_back(windowInfo);
4830     ret = handler.CheckInputMethodArea(touchEvent);
4831     ASSERT_FALSE(ret);
4832 }
4833 
4834 /**
4835  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_002
4836  * @tc.desc: Test the funcation CheckInputMethodArea
4837  * @tc.type: FUNC
4838  * @tc.require:
4839  */
4840 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_002, TestSize.Level1)
4841 {
4842     CALL_TEST_DEBUG;
4843     KeyCommandHandler handler;
4844     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4845     ASSERT_NE(touchEvent, nullptr);
4846     WindowInfo windowInfo;
4847     windowInfo.windowType = 2105;
4848     windowInfo.area.x = 10;
4849     windowInfo.area.width = 100;
4850     windowInfo.area.y = 20;
4851     windowInfo.area.height = INT32_MAX;
4852     std::vector<WindowInfo> windows;
4853     windows.push_back(windowInfo);
4854     bool ret = handler.CheckInputMethodArea(touchEvent);
4855     ASSERT_FALSE(ret);
4856 }
4857 
4858 /**
4859  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_003
4860  * @tc.desc: Test the funcation CheckInputMethodArea
4861  * @tc.type: FUNC
4862  * @tc.require:
4863  */
4864 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_003, TestSize.Level1)
4865 {
4866     CALL_TEST_DEBUG;
4867     KeyCommandHandler handler;
4868     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4869     ASSERT_NE(touchEvent, nullptr);
4870     WindowInfo windowInfo;
4871     windowInfo.windowType = 2105;
4872     windowInfo.area.x = 30;
4873     windowInfo.area.width = 300;
4874     windowInfo.area.y = 90;
4875     windowInfo.area.height = 1000;
4876     std::vector<WindowInfo> windows;
4877     windows.push_back(windowInfo);
4878     bool ret = handler.CheckInputMethodArea(touchEvent);
4879     ASSERT_FALSE(ret);
4880 }
4881 
4882 /**
4883  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_004
4884  * @tc.desc: Test the funcation CheckInputMethodArea
4885  * @tc.type: FUNC
4886  * @tc.require:
4887  */
4888 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_004, TestSize.Level1)
4889 {
4890     CALL_TEST_DEBUG;
4891     KeyCommandHandler handler;
4892     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4893     ASSERT_NE(pointerEvent, nullptr);
4894 
4895     WindowInfo windowInfo;
4896     windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
4897     bool ret = handler.CheckInputMethodArea(pointerEvent);
4898     EXPECT_FALSE(ret);
4899 
4900     windowInfo.area.x = 10;
4901     windowInfo.area.width = INT32_MAX;
4902     windowInfo.area.y = 100;
4903     windowInfo.area.height = 200;
4904     ret = handler.CheckInputMethodArea(pointerEvent);
4905     EXPECT_FALSE(ret);
4906 }
4907 
4908 /**
4909  * @tc.name: KeyCommandHandlerTest_SendKeyEvent_001
4910  * @tc.desc: Test the funcation SendKeyEvent
4911  * @tc.type: FUNC
4912  * @tc.require:
4913  */
4914 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_001, TestSize.Level1)
4915 {
4916     CALL_TEST_DEBUG;
4917     KeyCommandHandler handler;
4918     handler.isHandleSequence_ = true;
4919     handler.launchAbilityCount_ = 1;
4920     handler.count_ = 5;
4921     ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4922 }
4923 
4924 /**
4925  * @tc.name: KeyCommandHandlerTest_SendKeyEvent_002
4926  * @tc.desc: Test the funcation SendKeyEvent
4927  * @tc.type: FUNC
4928  * @tc.require:
4929  */
4930 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_002, TestSize.Level1)
4931 {
4932     CALL_TEST_DEBUG;
4933     KeyCommandHandler handler;
4934     handler.isHandleSequence_ = false;
4935     handler.launchAbilityCount_ = 1;
4936     handler.repeatKey_.keyCode = 3;
4937     ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4938 }
4939 
4940 /**
4941  * @tc.name: KeyCommandHandlerTest_SendKeyEvent_003
4942  * @tc.desc: Test the funcation SendKeyEvent
4943  * @tc.type: FUNC
4944  * @tc.require:
4945  */
4946 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SendKeyEvent_003, TestSize.Level1)
4947 {
4948     CALL_TEST_DEBUG;
4949     KeyCommandHandler handler;
4950     handler.isHandleSequence_ = false;
4951     handler.launchAbilityCount_ = 0;
4952     handler.repeatKey_.keyCode = 2;
4953     ASSERT_NO_FATAL_FAILURE(handler.SendKeyEvent());
4954 }
4955 
4956 /**
4957  * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_001
4958  * @tc.desc: Test the funcation CheckAndUpdateTappingCountAtDown
4959  * @tc.type: FUNC
4960  * @tc.require:
4961  */
4962 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_001, TestSize.Level1)
4963 {
4964     CALL_TEST_DEBUG;
4965     KeyCommandHandler handler;
4966     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4967     ASSERT_NE(touchEvent, nullptr);
4968     touchEvent->SetActionTime(0);
4969     handler.lastDownTime_ = 0;
4970     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4971     ASSERT_EQ(handler.tappingCount_, 1);
4972 
4973     touchEvent->SetActionTime(600000);
4974     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4975     ASSERT_EQ(handler.tappingCount_, 1);
4976 }
4977 
4978 /**
4979  * @tc.name: KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_002
4980  * @tc.desc: Test the funcation CheckAndUpdateTappingCountAtDown
4981  * @tc.type: FUNC
4982  * @tc.require:
4983  */
4984 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckAndUpdateTappingCountAtDown_002, TestSize.Level1)
4985 {
4986     CALL_TEST_DEBUG;
4987     KeyCommandHandler handler;
4988     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
4989     ASSERT_NE(touchEvent, nullptr);
4990     touchEvent->SetActionTime(10);
4991     handler.lastDownTime_ = 0;
4992     handler.previousUpTime_ = 0;
4993     handler.downToPrevUpTimeConfig_ = 20;
4994     handler.tappingCount_ = 1;
4995     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
4996     ASSERT_EQ(handler.tappingCount_, 2);
4997 
4998     touchEvent->SetActionTime(20);
4999     ASSERT_NO_FATAL_FAILURE(handler.CheckAndUpdateTappingCountAtDown(touchEvent));
5000     ASSERT_EQ(handler.tappingCount_, 3);
5001 }
5002 
5003 /**
5004  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_005
5005  * @tc.desc: Test the funcation CheckInputMethodArea
5006  * @tc.type: FUNC
5007  * @tc.require:
5008  */
5009 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_005, TestSize.Level1)
5010 {
5011     CALL_TEST_DEBUG;
5012     KeyCommandHandler handler;
5013     InputWindowsManager inputWindowsManager;
5014     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5015     ASSERT_NE(touchEvent, nullptr);
5016     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5017     EXPECT_NE(inputEvent, nullptr);
5018     inputEvent->targetDisplayId_ = 1;
5019     WindowGroupInfo windowGroupInfo;
5020     inputWindowsManager.windowsPerDisplay_.insert(std::make_pair(1, windowGroupInfo));
5021     bool ret = handler.CheckInputMethodArea(touchEvent);
5022     ASSERT_FALSE(ret);
5023 }
5024 
5025 /**
5026  * @tc.name: KeyCommandHandlerTest_HandleSequences_001
5027  * @tc.desc: HandleSequences
5028  * @tc.type: FUNC
5029  * @tc.require:
5030  */
5031 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_001, TestSize.Level1)
5032 {
5033     CALL_TEST_DEBUG;
5034     KeyCommandHandler handler;
5035     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5036     ASSERT_NE(keyEvent, nullptr);
5037     handler.matchedSequence_.timerId = 10;
5038     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5039     ASSERT_FALSE(handler.HandleSequences(keyEvent));
5040     handler.matchedSequence_.timerId = -1;
5041     ASSERT_FALSE(handler.HandleSequences(keyEvent));
5042     keyEvent->SetKeyCode(2017);
5043     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5044     keyEvent->SetActionTime(10000);
5045     SequenceKey sequenceKey;
5046     Sequence sequence;
5047     sequence.statusConfigValue = false;
5048     sequence.timerId = 1;
5049     handler.filterSequences_.push_back(sequence);
5050     sequenceKey.actionTime = 15000;
5051     handler.keys_.push_back(sequenceKey);
5052     ASSERT_FALSE(handler.HandleSequences(keyEvent));
5053     handler.keys_.clear();
5054     keyEvent->SetActionTime(1500000);
5055     sequenceKey.actionTime = 200000;
5056     sequence.statusConfigValue = false;
5057     sequence.timerId = 1;
5058     handler.filterSequences_.push_back(sequence);
5059     ASSERT_FALSE(handler.HandleSequences(keyEvent));
5060 }
5061 
5062 /**
5063  * @tc.name: KeyCommandHandlerTest_HandleConsumedKeyEvent_001
5064  * @tc.desc: Test the funcation HandleConsumedKeyEvent
5065  * @tc.type: FUNC
5066  * @tc.require:
5067  */
5068 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleConsumedKeyEvent_001, TestSize.Level1)
5069 {
5070     CALL_TEST_DEBUG;
5071     KeyCommandHandler handler;
5072     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5073     ASSERT_NE(keyEvent, nullptr);
5074     ShortcutKey testKey;
5075     testKey.finalKey = -1;
5076     handler.currentLaunchAbilityKey_ = testKey;
5077     int32_t keyCode = -1;
5078     keyEvent->SetKeyCode(keyCode);
5079     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5080     bool ret = handler.HandleConsumedKeyEvent(keyEvent);
5081     EXPECT_FALSE(ret);
5082 }
5083 
5084 /**
5085  * @tc.name: KeyCommandHandlerTest_HandleSequences_003
5086  * @tc.desc: HandleSequences
5087  * @tc.type: FUNC
5088  * @tc.require:
5089  */
5090 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_003, TestSize.Level1)
5091 {
5092     CALL_TEST_DEBUG;
5093     KeyCommandHandler handler;
5094     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5095     ASSERT_NE(keyEvent, nullptr);
5096     handler.sequenceOccurred_ = false;
5097     handler.matchedSequence_.timerId = 1;
5098     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5099     bool ret = handler.HandleSequences(keyEvent);
5100     ASSERT_FALSE(ret);
5101 }
5102 
5103 /**
5104  * @tc.name: KeyCommandHandlerTest_HandleScreenLocked_001
5105  * @tc.desc: HandleScreenLocked
5106  * @tc.type: FUNC
5107  * @tc.require:
5108  */
5109 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleScreenLocked_001, TestSize.Level1)
5110 {
5111     CALL_TEST_DEBUG;
5112     KeyCommandHandler handler;
5113     Sequence sequence;
5114     sequence.timerId = -1;
5115     bool isLaunchAbility = true;
5116     bool ret = handler.HandleScreenLocked(sequence, isLaunchAbility);
5117     ASSERT_TRUE(ret);
5118     sequence.timerId = 2;
5119     ret = handler.HandleScreenLocked(sequence, isLaunchAbility);
5120     ASSERT_TRUE(ret);
5121 }
5122 
5123 /**
5124  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_001
5125  * @tc.desc: Test the funcation MatchShortcutKey
5126  * @tc.type: FUNC
5127  * @tc.require:
5128  */
5129 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_001, TestSize.Level1)
5130 {
5131     KeyCommandHandler handler;
5132     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5133     ASSERT_NE(keyEvent, nullptr);
5134     ShortcutKey shortcutKey;
5135     std::vector<ShortcutKey> upAbilities;
5136     shortcutKey.statusConfigValue = false;
5137     bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5138     ASSERT_FALSE(ret);
5139     shortcutKey.statusConfigValue = true;
5140     shortcutKey.finalKey = 1;
5141     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5142     keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5143     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5144     shortcutKey.preKeys.insert(2024);
5145     KeyEvent::KeyItem item1;
5146     item1.SetKeyCode(KeyEvent::KEYCODE_R);
5147     item1.SetPressed(true);
5148     item1.SetDownTime(500);
5149     keyEvent->keys_.push_back(item1);
5150     KeyEvent::KeyItem item2;
5151     item2.SetKeyCode(KeyEvent::KEYCODE_R);
5152     item2.SetPressed(false);
5153     item2.SetDownTime(200);
5154     keyEvent->keys_.push_back(item2);
5155     ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5156     ASSERT_FALSE(ret);
5157 }
5158 
5159 /**
5160  * @tc.name: KeyCommandHandlerTest_PreHandleEvent_001
5161  * @tc.desc: Test the funcation PreHandleEvent
5162  * @tc.type: FUNC
5163  * @tc.require:
5164  */
5165 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_001, TestSize.Level1)
5166 {
5167     KeyCommandHandler handler;
5168     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5169     ASSERT_NE(key, nullptr);
5170     EventLogHelper eventLogHelper;
5171     eventLogHelper.userType_ = "beta";
5172     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5173     EXPECT_NE(inputEvent, nullptr);
5174     inputEvent->bitwise_ = 0x00000000;
5175     bool ret = handler.PreHandleEvent(key);
5176     ASSERT_TRUE(ret);
5177     inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
5178     ret = handler.PreHandleEvent(key);
5179     ASSERT_TRUE(ret);
5180     handler.enableCombineKey_ = false;
5181     ret = handler.PreHandleEvent(key);
5182     ASSERT_FALSE(ret);
5183     handler.enableCombineKey_ = true;
5184     handler.isParseConfig_ = false;
5185     ret = handler.PreHandleEvent(key);
5186     ASSERT_TRUE(ret);
5187     handler.isParseConfig_ = true;
5188     handler.isParseMaxCount_ = false;
5189     ret = handler.PreHandleEvent(key);
5190     ASSERT_TRUE(ret);
5191     handler.isParseMaxCount_ = true;
5192     handler.isParseStatusConfig_ = false;
5193     ret = handler.PreHandleEvent(key);
5194     ASSERT_TRUE(ret);
5195     handler.isParseStatusConfig_ = false;
5196     ret = handler.PreHandleEvent(key);
5197     ASSERT_TRUE(ret);
5198 }
5199 
5200 /**
5201  * @tc.name: KeyCommandHandlerTest_PreHandleEvent_002
5202  * @tc.desc: Test the funcation PreHandleEvent
5203  * @tc.type: FUNC
5204  * @tc.require:
5205  */
5206 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_002, TestSize.Level1)
5207 {
5208     KeyCommandHandler handler;
5209     ASSERT_NE(keyEvent_, nullptr);
5210     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_F1);
5211     handler.enableCombineKey_ = true;
5212     bool ret = handler.PreHandleEvent(keyEvent_);
5213     ASSERT_FALSE(ret);
5214 }
5215 
5216 /**
5217  * @tc.name: KeyCommandHandlerTest_CheckInputMethodArea_006
5218  * @tc.desc: Test the funcation CheckInputMethodArea
5219  * @tc.type: FUNC
5220  * @tc.require:
5221  */
5222 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckInputMethodArea_006, TestSize.Level1)
5223 {
5224     CALL_TEST_DEBUG;
5225     KeyCommandHandler handler;
5226     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5227     ASSERT_NE(touchEvent, nullptr);
5228     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5229     EXPECT_NE(inputEvent, nullptr);
5230     inputEvent->SetTargetDisplayId(-1);
5231     inputEvent->SetTargetWindowId(5);
5232     InputWindowsManager inputWindowsManager;
5233     WindowInfo windowInfo;
5234     windowInfo.windowType = 2105;
5235     windowInfo.id = 5;
5236     windowInfo.area.x = 10;
5237     windowInfo.area.y = 20;
5238     windowInfo.area.width = 100;
5239     windowInfo.area.height = 200;
5240     inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5241     PointerEvent::PointerItem item;
5242     item.SetDisplayX(5);
5243     item.SetDisplayY(10);
5244     touchEvent->AddPointerItem(item);
5245     bool ret = handler.CheckInputMethodArea(touchEvent);
5246     ASSERT_FALSE(ret);
5247     item.SetDisplayX(20);
5248     item.SetDisplayY(30);
5249     touchEvent->AddPointerItem(item);
5250     ret = handler.CheckInputMethodArea(touchEvent);
5251     ASSERT_FALSE(ret);
5252     windowInfo.area.height = INT32_MAX;
5253     inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5254     ret = handler.CheckInputMethodArea(touchEvent);
5255     ASSERT_FALSE(ret);
5256     windowInfo.area.width = INT32_MAX;
5257     inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo);
5258     ret = handler.CheckInputMethodArea(touchEvent);
5259     ASSERT_FALSE(ret);
5260     inputEvent->SetTargetWindowId(10);
5261     ret = handler.CheckInputMethodArea(touchEvent);
5262     ASSERT_FALSE(ret);
5263     windowInfo.windowType = 1000;
5264     ret = handler.CheckInputMethodArea(touchEvent);
5265     ASSERT_FALSE(ret);
5266 }
5267 
5268 /**
5269  * @tc.name: KeyCommandHandlerTest_HandleSequences_004
5270  * @tc.desc: Test the funcation HandleSequences
5271  * @tc.type: FUNC
5272  * @tc.require:
5273  */
5274 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleSequences_004, TestSize.Level1)
5275 {
5276     CALL_TEST_DEBUG;
5277     KeyCommandHandler handler;
5278     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5279     ASSERT_NE(keyEvent, nullptr);
5280     handler.sequenceOccurred_ = false;
5281     handler.matchedSequence_.timerId = -10;
5282     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5283     Sequence sequence1;
5284     sequence1.statusConfig = "statusConfig1";
5285     sequence1.statusConfigValue = true;
5286     sequence1.abilityStartDelay = 1;
5287     sequence1.timerId = 5;
5288     handler.sequences_.push_back(sequence1);
5289     Sequence sequence2;
5290     sequence2.statusConfig = "statusConfig2";
5291     sequence2.statusConfigValue = false;
5292     sequence2.abilityStartDelay = 2;
5293     sequence2.timerId = 1;
5294     handler.filterSequences_.push_back(sequence2);
5295     bool ret = handler.HandleSequences(keyEvent);
5296     ASSERT_FALSE(ret);
5297     SequenceKey sequenceKey;
5298     sequenceKey.keyCode = 1;
5299     sequenceKey.keyAction = KeyEvent::KEY_ACTION_DOWN;
5300     sequenceKey.actionTime = 2;
5301     sequenceKey.delay = 5;
5302     handler.keys_.push_back(sequenceKey);
5303     ret = handler.HandleSequences(keyEvent);
5304     ASSERT_FALSE(ret);
5305 }
5306 
5307 /**
5308  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_003
5309  * @tc.desc: Test the funcation MatchShortcutKey
5310  * @tc.type: FUNC
5311  * @tc.require:
5312  */
5313 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_003, TestSize.Level1)
5314 {
5315     KeyCommandHandler handler;
5316     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5317     ASSERT_NE(keyEvent, nullptr);
5318     ShortcutKey shortcutKey;
5319     std::vector<ShortcutKey> upAbilities;
5320     shortcutKey.statusConfigValue = true;
5321     shortcutKey.finalKey = 5;
5322     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5323     shortcutKey.preKeys = {1};
5324     shortcutKey.businessId = "Ctrl+O";
5325     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5326     ASSERT_NE(key, nullptr);
5327     key->SetKeyCode(5);
5328     key->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5329     KeyEvent::KeyItem item1;
5330     item1.SetKeyCode(1);
5331     item1.SetDownTime(10);
5332     item1.SetDeviceId(3);
5333     KeyEvent::KeyItem item2;
5334     item2.SetKeyCode(1);
5335     item2.SetDownTime(20);
5336     item2.SetDeviceId(4);
5337     keyEvent->AddKeyItem(item1);
5338     keyEvent->AddKeyItem(item2);
5339     MultiModalInputPreferencesManager multiModalInputPreferencesManager;
5340     multiModalInputPreferencesManager.shortcutKeyMap_.insert(std::make_pair("Ctrl+O", 5000));
5341     bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5342     EXPECT_FALSE(ret);
5343     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
5344     key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5345     ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5346     EXPECT_FALSE(ret);
5347     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UNKNOWN;
5348     key->SetKeyAction(KeyEvent::KEY_ACTION_UNKNOWN);
5349     ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5350     EXPECT_FALSE(ret);
5351 }
5352 
5353 /**
5354  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_004
5355  * @tc.desc: Test the funcation MatchShortcutKey
5356  * @tc.type: FUNC
5357  * @tc.require:
5358  */
5359 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_004, TestSize.Level1)
5360 {
5361     KeyCommandHandler handler;
5362     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5363     ASSERT_NE(keyEvent, nullptr);
5364     ShortcutKey shortcutKey;
5365     std::vector<ShortcutKey> upAbilities;
5366     shortcutKey.statusConfigValue = true;
5367     shortcutKey.finalKey = 10;
5368     shortcutKey.triggerType = KeyEvent::KEY_ACTION_UP;
5369     shortcutKey.preKeys = {5};
5370     shortcutKey.businessId = "Ctrl+T";
5371     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
5372     ASSERT_NE(key, nullptr);
5373     key->SetKeyCode(10);
5374     key->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5375     KeyEvent::KeyItem item1;
5376     item1.SetKeyCode(5);
5377     item1.SetDownTime(6);
5378     item1.SetDeviceId(7);
5379     KeyEvent::KeyItem item2;
5380     item2.SetKeyCode(5);
5381     item2.SetDownTime(2);
5382     item2.SetDeviceId(1);
5383     keyEvent->AddKeyItem(item1);
5384     keyEvent->AddKeyItem(item2);
5385     MultiModalInputPreferencesManager multiModalInputPreferencesManager;
5386     multiModalInputPreferencesManager.shortcutKeyMap_.insert(std::make_pair("Ctrl+R", 300));
5387     bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5388     EXPECT_FALSE(ret);
5389 }
5390 
5391 /**
5392  * @tc.name: KeyCommandHandlerTest_HandleShortKeys_01
5393  * @tc.desc: Test the funcation HandleShortKeys
5394  * @tc.type: FUNC
5395  * @tc.require:
5396  */
5397 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleShortKeys_01, TestSize.Level1)
5398 {
5399     KeyCommandHandler handler;
5400     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5401     ASSERT_NE(keyEvent, nullptr);
5402     ShortcutKey shortcutKey;
5403     shortcutKey.preKeys = {2};
5404     shortcutKey.statusConfigValue = true;
5405     shortcutKey.finalKey = 6;
5406     shortcutKey.keyDownDuration = 7;
5407     shortcutKey.triggerType = KeyEvent::KEY_ACTION_DOWN;
5408     shortcutKey.timerId = 10;
5409     handler.shortcutKeys_.insert(std::make_pair("key", shortcutKey));
5410     handler.lastMatchedKey_.finalKey = 1;
5411     handler.lastMatchedKey_.triggerType = KeyEvent::KEY_ACTION_UP;
5412     handler.lastMatchedKey_.preKeys = {3};
5413     keyEvent->SetKeyCode(1);
5414     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5415     KeyEvent::KeyItem item1;
5416     item1.SetKeyCode(3);
5417     item1.SetDownTime(5);
5418     item1.SetDeviceId(8);
5419     KeyEvent::KeyItem item2;
5420     item2.SetKeyCode(3);
5421     item2.SetDownTime(6);
5422     item2.SetDeviceId(4);
5423     keyEvent->AddKeyItem(item1);
5424     keyEvent->AddKeyItem(item2);
5425     bool ret = handler.HandleShortKeys(keyEvent);
5426     ASSERT_TRUE(ret);
5427     handler.lastMatchedKey_.preKeys = {4, 5, 6};
5428     handler.currentLaunchAbilityKey_.timerId = 5;
5429     handler.currentLaunchAbilityKey_.finalKey = 1;
5430     handler.currentLaunchAbilityKey_.triggerType = KeyEvent::KEY_ACTION_UP;
5431     handler.currentLaunchAbilityKey_.preKeys = {3};
5432     EventLogHelper eventLogHelper;
5433     eventLogHelper.userType_ = "beta";
5434     std::shared_ptr<InputEvent> inputEvent = InputEvent::Create();
5435     EXPECT_NE(inputEvent, nullptr);
5436     inputEvent->bitwise_ = InputEvent::EVENT_FLAG_PRIVACY_MODE;
5437     ret = handler.HandleShortKeys(keyEvent);
5438     ASSERT_TRUE(ret);
5439     eventLogHelper.userType_ = "aaaaaaa";
5440     ret = handler.HandleShortKeys(keyEvent);
5441     ASSERT_TRUE(ret);
5442     inputEvent->bitwise_ = 0;
5443     ret = handler.HandleShortKeys(keyEvent);
5444     ASSERT_TRUE(ret);
5445 }
5446 
5447 /**
5448  * @tc.name: KeyCommandHandlerTest_IsMatchedAbility
5449  * @tc.desc: Test IsMatchedAbility
5450  * @tc.type: Function
5451  * @tc.require:
5452  */
5453 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMatchedAbility, TestSize.Level1)
5454 {
5455     CALL_TEST_DEBUG;
5456     KeyCommandHandler handler;
5457     std::vector<float> gesturePoints;
5458     float gestureLastX = 100.0f;
5459     float gestureLastY = 100.0f;
5460     gesturePoints.push_back(10.0f);
5461     EXPECT_FALSE(handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY));
5462 
5463     gesturePoints.push_back(15.0f);
5464     gesturePoints.push_back(20.0f);
5465     EXPECT_TRUE(handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY));
5466 }
5467 
5468 /**
5469  * @tc.name: KeyCommandHandlerTest_ParseRepeatKeyMaxCount
5470  * @tc.desc: Test ParseRepeatKeyMaxCount
5471  * @tc.type: Function
5472  * @tc.require:
5473  */
5474 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseRepeatKeyMaxCount, TestSize.Level1)
5475 {
5476     CALL_TEST_DEBUG;
5477     KeyCommandHandler handler;
5478     EXPECT_NO_FATAL_FAILURE(handler.ParseRepeatKeyMaxCount());
5479 }
5480 
5481 /**
5482  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey
5483  * @tc.desc: Test SetIsFreezePowerKey
5484  * @tc.type: Function
5485  * @tc.require:
5486  */
5487 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey, TestSize.Level1)
5488 {
5489     CALL_TEST_DEBUG;
5490     KeyCommandHandler handler;
5491     std::string pageName = "SosCountup";
5492     EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5493     pageName = "SosCountdown";
5494     handler.sosDelayTimerId_ = 100;
5495     EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5496     handler.sosDelayTimerId_ = -1;
5497     EXPECT_EQ(handler.SetIsFreezePowerKey(pageName), RET_OK);
5498 }
5499 
5500 /**
5501  * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess
5502  * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickProcess
5503  * @tc.type: Function
5504  * @tc.require:
5505  */
5506 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickProcess, TestSize.Level1)
5507 {
5508     CALL_TEST_DEBUG;
5509     KeyCommandHandler handler;
5510     std::string bundleName = "bundleName";
5511     std::string abilityName = "abilityName";
5512     std::string action = "action";
5513     DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
5514     DISPLAY_MONITOR->SetScreenLocked(true);
5515     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5516     DISPLAY_MONITOR->SetScreenStatus("abc");
5517     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5518     DISPLAY_MONITOR->SetScreenLocked(false);
5519     ASSERT_NO_FATAL_FAILURE(handler.TouchPadKnuckleDoubleClickProcess(bundleName, abilityName, action));
5520 }
5521 
5522 /**
5523  * @tc.name: KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle
5524  * @tc.desc: Test the funcation TouchPadKnuckleDoubleClickHandle
5525  * @tc.type: Function
5526  * @tc.require:
5527  */
5528 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_TouchPadKnuckleDoubleClickHandle, TestSize.Level1)
5529 {
5530     CALL_TEST_DEBUG;
5531     KeyCommandHandler handler;
5532     std::shared_ptr<KeyEvent> event = KeyEvent::Create();
5533     ASSERT_NE(event, nullptr);
5534     event->SetKeyAction(KNUCKLE_1F_DOUBLE_CLICK);
5535     bool ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5536     ASSERT_TRUE(ret);
5537     event->SetKeyAction(KNUCKLE_2F_DOUBLE_CLICK);
5538     ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5539     ASSERT_TRUE(ret);
5540     event->SetKeyAction(1);
5541     ret = handler.TouchPadKnuckleDoubleClickHandle(event);
5542     ASSERT_FALSE(ret);
5543 }
5544 
5545 /**
5546  * @tc.name: KeyCommandHandlerTest_IsMatchedAbility_001
5547  * @tc.desc: Test the funcation IsMatchedAbility
5548  * @tc.type: Function
5549  * @tc.require:
5550  */
5551 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMatchedAbility_001, TestSize.Level1)
5552 {
5553     CALL_TEST_DEBUG;
5554     KeyCommandHandler handler;
5555     std::vector<float> gesturePoints;
5556     float gestureLastX = 100.0f;
5557     float gestureLastY = 150.0f;
5558     bool ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5559     ASSERT_FALSE(ret);
5560     gesturePoints.push_back(100.0f);
5561     gesturePoints.push_back(150.0f);
5562     ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5563     ASSERT_FALSE(ret);
5564     gesturePoints.push_back(200.0f);
5565     ret = handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY);
5566     ASSERT_FALSE(ret);
5567 }
5568 
5569 /**
5570  * @tc.name: KeyCommandHandlerTest_InitKeyObserver
5571  * @tc.desc: Test the funcation InitKeyObserver
5572  * @tc.type: Function
5573  * @tc.require:
5574  */
5575 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_InitKeyObserver, TestSize.Level1)
5576 {
5577     CALL_TEST_DEBUG;
5578     KeyCommandHandler handler;
5579     handler.isParseStatusConfig_ = false;
5580     handler.isKnuckleSwitchConfig_ = false;
5581     ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5582     handler.isKnuckleSwitchConfig_ = true;
5583     ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5584     handler.isParseStatusConfig_ = true;
5585     handler.isKnuckleSwitchConfig_ = false;
5586     ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5587     handler.isKnuckleSwitchConfig_ = true;
5588     ASSERT_NO_FATAL_FAILURE(handler.InitKeyObserver());
5589 }
5590 
5591 /**
5592  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey_001
5593  * @tc.desc: Test the funcation SetIsFreezePowerKey
5594  * @tc.type: Function
5595  * @tc.require:
5596  */
5597 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey_001, TestSize.Level1)
5598 {
5599     CALL_TEST_DEBUG;
5600     KeyCommandHandler handler;
5601     handler.isFreezePowerKey_ = true;
5602     std::string pageName = "pageName";
5603     int32_t ret = handler.SetIsFreezePowerKey(pageName);
5604     EXPECT_EQ(ret, RET_OK);
5605     handler.isFreezePowerKey_ = false;
5606     handler.sosDelayTimerId_ = 1;
5607     pageName = "SosCountdown";
5608     ret = handler.SetIsFreezePowerKey(pageName);
5609     EXPECT_EQ(ret, RET_OK);
5610     handler.sosDelayTimerId_ = -1;
5611     ret = handler.SetIsFreezePowerKey(pageName);
5612     EXPECT_EQ(ret, RET_OK);
5613 }
5614 
5615 /**
5616  * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_001
5617  * @tc.desc: Test the funcation ParseStatusConfigObserver
5618  * @tc.type: FUNC
5619  * @tc.require:
5620  */
5621 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_001, TestSize.Level1)
5622 {
5623     CALL_TEST_DEBUG;
5624     KeyCommandHandler handler;
5625     Sequence sequence;
5626     sequence.statusConfig = "statusConfig";
5627     sequence.statusConfigValue = false;
5628     sequence.abilityStartDelay = 1;
5629     sequence.timerId = 1;
5630     handler.sequences_.push_back(sequence);
5631     ShortcutKey key;
5632     key.preKeys = {1, 2, 3};
5633     key.businessId = "business1";
5634     key.statusConfig = "";
5635     handler.shortcutKeys_.insert(std::make_pair("key1", key));
5636     ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5637 }
5638 
5639 /**
5640  * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_002
5641  * @tc.desc: Test the funcation ParseStatusConfigObserver
5642  * @tc.type: FUNC
5643  * @tc.require:
5644  */
5645 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_002, TestSize.Level1)
5646 {
5647     CALL_TEST_DEBUG;
5648     KeyCommandHandler handler;
5649     Sequence sequence;
5650     sequence.statusConfig = "abc";
5651     sequence.statusConfigValue = true;
5652     sequence.abilityStartDelay = 1;
5653     sequence.timerId = 5;
5654     handler.sequences_.push_back(sequence);
5655     ShortcutKey key;
5656     key.preKeys = {1, 2, 3};
5657     key.businessId = "business1";
5658     key.statusConfig = "statusConfig";
5659     key.statusConfigValue = true;
5660     key.finalKey = 4;
5661     key.keyDownDuration = 5;
5662     key.triggerType = KeyEvent::KEY_ACTION_DOWN;
5663     key.timerId = 6;
5664     Ability ability_temp;
5665     ability_temp.bundleName = "bundleName";
5666     ability_temp.abilityName = "abilityName";
5667     key.ability = ability_temp;
5668     handler.shortcutKeys_.insert(std::make_pair("key1", key));
5669     ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5670 }
5671 
5672 /**
5673  * @tc.name: KeyCommandHandlerTest_ParseStatusConfigObserver_003
5674  * @tc.desc: Test the funcation ParseStatusConfigObserver
5675  * @tc.type: FUNC
5676  * @tc.require:
5677  */
5678 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseStatusConfigObserver_003, TestSize.Level1)
5679 {
5680     CALL_TEST_DEBUG;
5681     KeyCommandHandler handler;
5682     Sequence sequence;
5683     sequence.statusConfig = "";
5684     sequence.statusConfigValue = false;
5685     sequence.abilityStartDelay = 2;
5686     sequence.timerId = 2;
5687     handler.sequences_.push_back(sequence);
5688     ASSERT_NO_FATAL_FAILURE(handler.ParseStatusConfigObserver());
5689 }
5690 
5691 /**
5692  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_03
5693  * @tc.desc: Test the funcation MatchShortcutKey
5694  * @tc.type: Function
5695  * @tc.require:
5696  */
5697 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_03, TestSize.Level1)
5698 {
5699     CALL_TEST_DEBUG;
5700     KeyCommandHandler handler;
5701     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5702     keyEvent->SetKeyCode(1);
5703     keyEvent->SetKeyAction(5);
5704     ASSERT_NE(keyEvent, nullptr);
5705     ShortcutKey shortcutKey;
5706     shortcutKey.preKeys = {1, 2, 3};
5707     shortcutKey.businessId = "businessId";
5708     shortcutKey.statusConfig = "statusConfig";
5709     shortcutKey.statusConfigValue = true;
5710     shortcutKey.finalKey = 5;
5711     shortcutKey.keyDownDuration = 1;
5712     shortcutKey.triggerType = 10;
5713     shortcutKey.timerId = 1;
5714     std::vector<ShortcutKey> upAbilities;
5715     upAbilities.push_back(shortcutKey);
5716     bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5717     ASSERT_FALSE(ret);
5718 }
5719 
5720 /**
5721  * @tc.name: KeyCommandHandlerTest_MatchShortcutKey_02
5722  * @tc.desc: Test the funcation MatchShortcutKey
5723  * @tc.type: Function
5724  * @tc.require:
5725  */
5726 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MatchShortcutKey_02, TestSize.Level1)
5727 {
5728     CALL_TEST_DEBUG;
5729     KeyCommandHandler handler;
5730     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
5731     keyEvent->SetKeyCode(6);
5732     keyEvent->SetKeyAction(3);
5733     ASSERT_NE(keyEvent, nullptr);
5734     ShortcutKey shortcutKey;
5735     shortcutKey.preKeys = {3, 2, 4};
5736     shortcutKey.businessId = "businessId1";
5737     shortcutKey.statusConfig = "statusConfig1";
5738     shortcutKey.statusConfigValue = false;
5739     shortcutKey.finalKey = 6;
5740     shortcutKey.keyDownDuration = 9;
5741     shortcutKey.triggerType = 1;
5742     shortcutKey.timerId = 3;
5743     std::vector<ShortcutKey> upAbilities;
5744     upAbilities.push_back(shortcutKey);
5745     bool ret = handler.MatchShortcutKey(keyEvent, shortcutKey, upAbilities);
5746     ASSERT_FALSE(ret);
5747 }
5748 
5749 /**
5750  * @tc.name: KeyCommandHandlerTest_PreHandleEvent_02
5751  * @tc.desc: Test the funcation PreHandleEvent
5752  * @tc.type: Function
5753  * @tc.require:
5754  */
5755 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_02, TestSize.Level1)
5756 {
5757     CALL_TEST_DEBUG;
5758     KeyCommandHandler handler;
5759 
5760     handler.isParseConfig_ = false;
5761     handler.isParseLongPressConfig_ = false;
5762     handler.isParseMaxCount_ = false;
5763     bool ret = false;
5764     ret = handler.PreHandleEvent();
5765     ASSERT_TRUE(ret);
5766 }
5767 
5768 /**
5769  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_004
5770  * @tc.desc: Test HandleKnuckleGestureDownEvent
5771  * @tc.type: FUNC
5772  * @tc.require:
5773  */
5774 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_004, TestSize.Level1)
5775 {
5776     CALL_TEST_DEBUG;
5777     PointerEvent::PointerItem item;
5778     item.SetPointerId(0);
5779     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5780     int64_t downTime = 100;
5781     item.SetDownTime(downTime);
5782     item.SetTargetWindowId(0);
5783     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5784     ASSERT_NE(touchEvent, nullptr);
5785     touchEvent->AddPointerItem(item);
5786     touchEvent->SetTargetDisplayId(0);
5787 
5788     KeyCommandHandler handler;
5789     handler.gameForbidFingerKnuckle_ = false;
5790 
5791     OLD::DisplayInfo displayInfo;
5792     displayInfo.id = 0;
5793     WindowInfo windowInfo;
5794     windowInfo.id = 0;
5795     windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
5796     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5797     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
5798     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
5799         it->second.windowsInfo.push_back(windowInfo);
5800         it->second.displaysInfo.push_back(displayInfo);
5801     }
5802     IInputWindowsManager::instance_ = inputWindowsManager;
5803 
5804     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5805 
5806     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5807     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5808 
5809     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
5810     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5811 
5812     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
5813     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent));
5814 }
5815 
5816 /**
5817  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_009
5818  * @tc.desc: Test CheckTwoFingerGestureAction
5819  * @tc.type: FUNC
5820  * @tc.require:
5821  */
5822 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_009, TestSize.Level1)
5823 {
5824     CALL_TEST_DEBUG;
5825     KeyCommandHandler handler;
5826     handler.twoFingerGesture_.active = true;
5827     handler.twoFingerGesture_.touches[0].downTime = 0;
5828     handler.twoFingerGesture_.touches[1].downTime = 1;
5829 
5830     OLD::DisplayInfo displayInfo;
5831     displayInfo.dpi = 320;
5832     displayInfo.width = 1260;
5833     displayInfo.height = 2720;
5834     displayInfo.uniq = "default0";
5835     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5836     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
5837     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
5838         it->second.displaysInfo.push_back(displayInfo);
5839     }
5840     IInputWindowsManager::instance_ = inputWindowsManager;
5841     handler.twoFingerGesture_.touches[0].x = 600;
5842     handler.twoFingerGesture_.touches[0].y = 600;
5843 
5844     handler.twoFingerGesture_.touches[1].x = 800;
5845     handler.twoFingerGesture_.touches[1].y = 600;
5846     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5847 
5848     handler.twoFingerGesture_.touches[1].x = 10;
5849     handler.twoFingerGesture_.touches[1].y = 600;
5850     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5851 
5852     handler.twoFingerGesture_.touches[1].x = 1250;
5853     handler.twoFingerGesture_.touches[1].y = 600;
5854     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5855 
5856     handler.twoFingerGesture_.touches[1].x = 600;
5857     handler.twoFingerGesture_.touches[1].y = 10;
5858     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5859 
5860     handler.twoFingerGesture_.touches[1].x = 600;
5861     handler.twoFingerGesture_.touches[1].y = 2710;
5862     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5863 }
5864 
5865 
5866 /**
5867  * @tc.name: KeyCommandHandlerTest_CheckTwoFingerGestureAction_010
5868  * @tc.desc: Test CheckTwoFingerGestureAction
5869  * @tc.type: FUNC
5870  * @tc.require:
5871  */
5872 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureAction_010, TestSize.Level1)
5873 {
5874     CALL_TEST_DEBUG;
5875     KeyCommandHandler handler;
5876     handler.twoFingerGesture_.active = true;
5877     handler.twoFingerGesture_.touches[0].downTime = 0;
5878     handler.twoFingerGesture_.touches[1].downTime = 1;
5879 
5880     handler.twoFingerGesture_.touches[0].x = 600;
5881     handler.twoFingerGesture_.touches[0].y = 600;
5882 
5883     handler.twoFingerGesture_.touches[1].x = 601;
5884     handler.twoFingerGesture_.touches[1].y = 601;
5885     ASSERT_NO_FATAL_FAILURE(handler.CheckTwoFingerGestureAction());
5886 }
5887 
5888 /**
5889  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_005
5890  * @tc.desc: Verify if (vp <= 0)
5891  * @tc.type: Function
5892  * @tc.require:
5893  */
5894 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_005, TestSize.Level1)
5895 {
5896     CALL_TEST_DEBUG;
5897     int32_t vp = -1;
5898     KeyCommandHandler handler;
5899     int32_t ret = handler.ConvertVPToPX(vp);
5900     ASSERT_EQ(ret, 0);
5901     ret = handler.ConvertVPToPX(vp);
5902 }
5903 
5904 /**
5905  * @tc.name: KeyCommandHandlerTest_ConvertVPToPX_006
5906  * @tc.desc: Verify if (dpi <= 0)
5907  * @tc.type: Function
5908  * @tc.require:
5909  */
5910 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_006, TestSize.Level1)
5911 {
5912     CALL_TEST_DEBUG;
5913     int32_t vp = 5;
5914     OLD::DisplayInfo displayInfo;
5915     displayInfo.id = 1;
5916     displayInfo.x = 2;
5917     displayInfo.y = 3;
5918     displayInfo.width = 4;
5919     displayInfo.height = 5;
5920     displayInfo.dpi = -1;
5921     displayInfo.uniq = "default0";
5922     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5923     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
5924     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
5925         it->second.displaysInfo.push_back(displayInfo);
5926     }
5927     IInputWindowsManager::instance_ = inputWindowsManager;
5928     KeyCommandHandler handler;
5929     int32_t ret = handler.ConvertVPToPX(vp);
5930     ASSERT_EQ(ret, 0);
5931 }
5932 
5933 /**
5934  * @tc.name: KeyCommandHandlerTest_CheckKnuckleCondition_001
5935  * @tc.desc: Test if (physicDisplayInfo != nullptr && physicDisplayInfo->direction != lastDirection_)
5936  * @tc.type: FUNC
5937  * @tc.require:
5938  */
5939 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_001, TestSize.Level1)
5940 {
5941     CALL_TEST_DEBUG;
5942     PointerEvent::PointerItem item;
5943     item.SetPointerId(0);
5944     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
5945     item.SetTargetWindowId(0);
5946     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
5947     ASSERT_NE(touchEvent, nullptr);
5948     touchEvent->AddPointerItem(item);
5949     touchEvent->SetPointerId(0);
5950 
5951     KeyCommandHandler handler;
5952     handler.gameForbidFingerKnuckle_ = false;
5953     handler.singleKnuckleGesture_.state = false;
5954 
5955     OLD::DisplayInfo displayInfo;
5956     displayInfo.id = 0;
5957     displayInfo.direction = DIRECTION0;
5958     WindowInfo windowInfo;
5959     windowInfo.id = 0;
5960     windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
5961     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
5962     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
5963     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
5964         it->second.windowsInfo.push_back(windowInfo);
5965         it->second.displaysInfo.push_back(displayInfo);
5966     }
5967     IInputWindowsManager::instance_ = inputWindowsManager;
5968 
5969     touchEvent->SetTargetDisplayId(1);
5970     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5971 
5972     touchEvent->SetTargetDisplayId(0);
5973     handler.lastDirection_ = DIRECTION0;
5974     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5975 
5976     handler.lastDirection_ = DIRECTION90;
5977     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5978     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5979 
5980     handler.lastDirection_ = DIRECTION90;
5981     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
5982     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5983 
5984     handler.lastDirection_ = DIRECTION90;
5985     float pointer = 1.0;
5986     handler.gesturePoints_.push_back(pointer);
5987     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
5988 }
5989 
5990 /**
5991  * @tc.name: KeyCommandHandlerTest_CheckKnuckleCondition_002
5992  * @tc.desc: Test if (touchEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN ||
5993  * touchEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP)
5994  * @tc.type: FUNC
5995  * @tc.require:
5996  */
5997 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_002, TestSize.Level1)
5998 {
5999     CALL_TEST_DEBUG;
6000     PointerEvent::PointerItem item;
6001     item.SetPointerId(0);
6002     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6003     item.SetTargetWindowId(0);
6004     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6005     ASSERT_NE(touchEvent, nullptr);
6006     touchEvent->AddPointerItem(item);
6007     touchEvent->SetPointerId(0);
6008 
6009     KeyCommandHandler handler;
6010     handler.gameForbidFingerKnuckle_ = false;
6011     handler.singleKnuckleGesture_.state = false;
6012 
6013     OLD::DisplayInfo displayInfo;
6014     displayInfo.id = 0;
6015     displayInfo.direction = DIRECTION0;
6016     WindowInfo windowInfo;
6017     windowInfo.id = 0;
6018     windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE;
6019     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6020     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6021     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6022         it->second.windowsInfo.push_back(windowInfo);
6023         it->second.displaysInfo.push_back(displayInfo);
6024     }
6025     IInputWindowsManager::instance_ = inputWindowsManager;
6026 
6027     touchEvent->SetTargetDisplayId(0);
6028     handler.lastDirection_ = DIRECTION0;
6029 
6030     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
6031     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
6032 
6033     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
6034     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
6035 
6036     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
6037     ASSERT_NO_FATAL_FAILURE(handler.CheckKnuckleCondition(touchEvent));
6038 }
6039 
6040 /**
6041  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_003
6042  * @tc.desc: Test if (dx >= MOVE_TOLERANCE || dy >= MOVE_TOLERANCE)
6043  * @tc.type: FUNC
6044  * @tc.require:
6045  */
6046 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_003, TestSize.Level1)
6047 {
6048     CALL_TEST_DEBUG;
6049     PointerEvent::PointerItem item;
6050     item.SetPointerId(0);
6051     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6052     item.SetTargetWindowId(0);
6053     item.SetRawDisplayX(3.0f);
6054     item.SetRawDisplayY(3.0f);
6055     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6056     ASSERT_NE(touchEvent, nullptr);
6057     touchEvent->AddPointerItem(item);
6058     touchEvent->SetPointerId(0);
6059     touchEvent->SetTargetDisplayId(0);
6060 
6061     OLD::DisplayInfo displayInfo;
6062     displayInfo.id = 0;
6063     displayInfo.direction = DIRECTION0;
6064     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6065     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6066     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6067         it->second.displaysInfo.push_back(displayInfo);
6068     }
6069     IInputWindowsManager::instance_ = inputWindowsManager;
6070 
6071     KeyCommandHandler handler;
6072     handler.gestureLastX_ = 3.0f;
6073     handler.gestureLastY_ = 3.0f;
6074     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6075 
6076     handler.gestureLastX_ = 0.0f;
6077     handler.gestureLastY_ = 3.0f;
6078     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6079 
6080     handler.gestureLastX_ = 3.0f;
6081     handler.gestureLastY_ = 0.0f;
6082     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6083 
6084     handler.gestureLastX_ = 0.0f;
6085     handler.gestureLastY_ = 0.0f;
6086     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6087 }
6088 
6089 /**
6090  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_004
6091  * @tc.desc: Test if (!isStartBase_ && IsMatchedAbility(gesturePoints_, gestureLastX_, gestureLastY_))
6092  * @tc.type: FUNC
6093  * @tc.require:
6094  */
6095 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_004, TestSize.Level1)
6096 {
6097     CALL_TEST_DEBUG;
6098     PointerEvent::PointerItem item;
6099     item.SetPointerId(0);
6100     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6101     item.SetTargetWindowId(0);
6102     item.SetRawDisplayX(3.0f);
6103     item.SetRawDisplayY(3.0f);
6104     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6105     ASSERT_NE(touchEvent, nullptr);
6106     touchEvent->AddPointerItem(item);
6107     touchEvent->SetPointerId(0);
6108     touchEvent->SetTargetDisplayId(0);
6109 
6110     OLD::DisplayInfo displayInfo;
6111     displayInfo.id = 0;
6112     displayInfo.direction = DIRECTION0;
6113     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6114     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6115     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6116         it->second.displaysInfo.push_back(displayInfo);
6117     }
6118     IInputWindowsManager::instance_ = inputWindowsManager;
6119 
6120     KeyCommandHandler handler;
6121     handler.gestureLastX_ = 0.0f;
6122     handler.gestureLastY_ = 0.0f;
6123     handler.isStartBase_ = true;
6124 
6125     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6126 
6127     handler.gesturePoints_.clear();
6128     float pointer = 500.0f;
6129     handler.gesturePoints_.emplace_back(pointer);
6130     pointer = 500.0f;
6131     handler.gesturePoints_.emplace_back(pointer);
6132     handler.isStartBase_ = false;
6133     handler.gestureLastX_ = 0.0f;
6134     handler.gestureLastY_ = 0.0f;
6135     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6136 }
6137 
6138 /**
6139  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_005
6140  * @tc.desc: Test if (!isGesturing_)
6141  * @tc.type: FUNC
6142  * @tc.require:
6143  */
6144 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_005, TestSize.Level1)
6145 {
6146     CALL_TEST_DEBUG;
6147     PointerEvent::PointerItem item;
6148     item.SetPointerId(0);
6149     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6150     item.SetTargetWindowId(0);
6151     item.SetRawDisplayX(3.0f);
6152     item.SetRawDisplayY(3.0f);
6153     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6154     ASSERT_NE(touchEvent, nullptr);
6155     touchEvent->AddPointerItem(item);
6156     touchEvent->SetPointerId(0);
6157     touchEvent->SetTargetDisplayId(0);
6158 
6159     OLD::DisplayInfo displayInfo;
6160     displayInfo.id = 0;
6161     displayInfo.direction = DIRECTION0;
6162     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6163     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6164     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6165         it->second.displaysInfo.push_back(displayInfo);
6166     }
6167     IInputWindowsManager::instance_ = inputWindowsManager;
6168 
6169     KeyCommandHandler handler;
6170     handler.gestureLastX_ = 0.0f;
6171     handler.gestureLastY_ = 0.0f;
6172     handler.isStartBase_ = true;
6173     handler.isGesturing_ = true;
6174 
6175     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6176 
6177     handler.isStartBase_ = true;
6178     handler.isGesturing_ = false;
6179     handler.gestureLastX_ = 0.0f;
6180     handler.gestureLastY_ = 0.0f;
6181     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6182 }
6183 
6184 /**
6185  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_006
6186  * @tc.desc: Test if (gestureTrackLength_ > MIN_GESTURE_STROKE_LENGTH)
6187  * @tc.type: FUNC
6188  * @tc.require:
6189  */
6190 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_006, TestSize.Level1)
6191 {
6192     CALL_TEST_DEBUG;
6193     PointerEvent::PointerItem item;
6194     item.SetPointerId(0);
6195     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6196     item.SetTargetWindowId(0);
6197     item.SetRawDisplayX(3.0f);
6198     item.SetRawDisplayY(3.0f);
6199     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6200     ASSERT_NE(touchEvent, nullptr);
6201     touchEvent->AddPointerItem(item);
6202     touchEvent->SetPointerId(0);
6203     touchEvent->SetTargetDisplayId(0);
6204 
6205     OLD::DisplayInfo displayInfo;
6206     displayInfo.id = 0;
6207     displayInfo.direction = DIRECTION0;
6208     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6209     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6210     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6211         it->second.displaysInfo.push_back(displayInfo);
6212     }
6213     IInputWindowsManager::instance_ = inputWindowsManager;
6214 
6215     KeyCommandHandler handler;
6216     handler.gestureLastX_ = 0.0f;
6217     handler.gestureLastY_ = 0.0f;
6218     handler.gestureTrackLength_ = 0.0f;
6219     handler.isStartBase_ = true;
6220     handler.isGesturing_ = false;
6221 
6222     handler.gestureTrackLength_ = 0.0f;
6223     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6224 
6225     handler.gestureTrackLength_ = 300.0f;
6226     handler.gestureLastX_ = 0.0f;
6227     handler.gestureLastY_ = 0.0f;
6228     handler.isStartBase_ = true;
6229     handler.isGesturing_ = false;
6230     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6231 }
6232 
6233 /**
6234  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_007
6235  * @tc.desc: Test if (isGesturing_ && !isLetterGesturing_)
6236  * @tc.type: FUNC
6237  * @tc.require:
6238  */
6239 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_007, TestSize.Level1)
6240 {
6241     CALL_TEST_DEBUG;
6242     PointerEvent::PointerItem item;
6243     item.SetPointerId(0);
6244     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6245     item.SetTargetWindowId(0);
6246     item.SetRawDisplayX(3.0f);
6247     item.SetRawDisplayY(3.0f);
6248     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6249     ASSERT_NE(touchEvent, nullptr);
6250     touchEvent->AddPointerItem(item);
6251     touchEvent->SetPointerId(0);
6252     touchEvent->SetTargetDisplayId(0);
6253 
6254     OLD::DisplayInfo displayInfo;
6255     displayInfo.id = 0;
6256     displayInfo.direction = DIRECTION0;
6257     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6258     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6259     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6260         it->second.displaysInfo.push_back(displayInfo);
6261     }
6262     IInputWindowsManager::instance_ = inputWindowsManager;
6263 
6264     KeyCommandHandler handler;
6265     handler.gestureLastX_ = 0.0f;
6266     handler.gestureLastY_ = 0.0f;
6267     handler.gestureTrackLength_ = 0.0f;
6268     handler.isStartBase_ = true;
6269     handler.isGesturing_ = true;
6270     handler.isLetterGesturing_ = true;
6271     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6272 
6273     handler.isStartBase_ = true;
6274     handler.isGesturing_ = true;
6275     handler.isLetterGesturing_ = false;
6276     handler.gestureLastX_ = 0.0f;
6277     handler.gestureLastY_ = 0.0f;
6278     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6279 }
6280 
6281 /**
6282  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_008
6283  * @tc.desc: Test if (boundingSquareness > MIN_LETTER_GESTURE_SQUARENESS)
6284  * @tc.type: FUNC
6285  * @tc.require:
6286  */
6287 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchMove_008, TestSize.Level1)
6288 {
6289     CALL_TEST_DEBUG;
6290     PointerEvent::PointerItem item;
6291     item.SetPointerId(0);
6292     item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6293     item.SetTargetWindowId(0);
6294     item.SetRawDisplayX(3.0f);
6295     item.SetRawDisplayY(3.0f);
6296     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6297     ASSERT_NE(touchEvent, nullptr);
6298     touchEvent->AddPointerItem(item);
6299     touchEvent->SetPointerId(0);
6300     touchEvent->SetTargetDisplayId(0);
6301 
6302     OLD::DisplayInfo displayInfo;
6303     displayInfo.id = 0;
6304     displayInfo.direction = DIRECTION0;
6305     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6306     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6307     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6308         it->second.displaysInfo.push_back(displayInfo);
6309     }
6310     IInputWindowsManager::instance_ = inputWindowsManager;
6311 
6312     KeyCommandHandler handler;
6313     handler.gestureLastX_ = 0.0f;
6314     handler.gestureLastY_ = 0.0f;
6315     handler.gestureTrackLength_ = 0.0f;
6316     handler.isStartBase_ = true;
6317     handler.isGesturing_ = true;
6318     handler.isLetterGesturing_ = false;
6319 
6320     ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureTouchMove(touchEvent));
6321 }
6322 
6323 /**
6324  * @tc.name: KeyCommandHandlerTest_ParseJson_002
6325  * @tc.desc: Test the funcation ParseJson
6326  * @tc.type: FUNC
6327  * @tc.require:
6328  */
6329 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_002, TestSize.Level1)
6330 {
6331     CALL_TEST_DEBUG;
6332     KeyCommandHandler handler;
6333     std::string defaultConfig = "/system/etc/multimodalinput/ability_launch_config.json";
6334     ASSERT_NO_FATAL_FAILURE(handler.ParseJson(defaultConfig));
6335 }
6336 
6337 /**
6338  * @tc.name: KeyCommandHandlerTest_ParseExcludeJson
6339  * @tc.desc: Test the funcation ParseExcludeJson
6340  * @tc.type: FUNC
6341  * @tc.require:
6342  */
6343 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseExcludeJson, TestSize.Level1)
6344 {
6345     CALL_TEST_DEBUG;
6346     KeyCommandHandler handler;
6347     std::string defaultConfig = "/system/etc/multimodalinput/ability_launch_config2.json";
6348     EXPECT_FALSE(handler.ParseExcludeJson(defaultConfig));
6349 }
6350 
6351 /**
6352  * @tc.name: KeyCommandHandlerTest_ParseJson_003
6353  * @tc.desc: Test the funcation ParseJson
6354  * @tc.type: FUNC
6355  * @tc.require:
6356  */
6357 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ParseJson_003, TestSize.Level1)
6358 {
6359     CALL_TEST_DEBUG;
6360     KeyCommandHandler handler;
6361     std::string defaultConfig = "/system/etc/multimodalinput/ability_launch_config2.json";
6362     EXPECT_FALSE(handler.ParseJson(defaultConfig));
6363 }
6364 
6365 /**
6366  * @tc.name: KeyCommandHandlerTest_HandleEvent_003
6367  * @tc.desc: Test the funcation HandleEvent
6368  * @tc.type: FUNC
6369  * @tc.require:
6370  */
6371 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_003, TestSize.Level1)
6372 {
6373     CALL_TEST_DEBUG;
6374     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6375     ASSERT_NE(keyEvent, nullptr);
6376     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6377     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6378     int64_t time = 4000000;
6379     keyEvent->SetActionTime(time);
6380     KeyCommandHandler handler;
6381     handler.powerUpTime_ = 0;
6382     handler.sosLaunchTime_ = 0;
6383     handler.isParseConfig_ = true;
6384     handler.isParseLongPressConfig_ = true;
6385     handler.isParseMaxCount_ = true;
6386     ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6387 }
6388 
6389 /**
6390  * @tc.name: KeyCommandHandlerTest_HandleEvent_004
6391  * @tc.desc: Test if ((key->GetActionTime() - powerUpTime_) > POWER_ACTION_INTERVAL * FREQUENCY &&
6392  * (key->GetActionTime() - sosLaunchTime_) > SOS_WAIT_TIME * FREQUENCY)
6393  * @tc.type: FUNC
6394  * @tc.require:
6395  */
6396 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_004, TestSize.Level1)
6397 {
6398     CALL_TEST_DEBUG;
6399     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6400     ASSERT_NE(keyEvent, nullptr);
6401     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6402     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6403     int64_t time = 0;
6404     keyEvent->SetActionTime(time);
6405     KeyCommandHandler handler;
6406     handler.powerUpTime_ = 0;
6407     handler.sosLaunchTime_ = 0;
6408     handler.isParseConfig_ = true;
6409     handler.isParseLongPressConfig_ = true;
6410     handler.isParseMaxCount_ = true;
6411     ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6412 }
6413 
6414 /**
6415  * @tc.name: KeyCommandHandlerTest_HandleEvent_005
6416  * @tc.desc: Test if ((key->GetActionTime() - powerUpTime_) > POWER_ACTION_INTERVAL * FREQUENCY &&
6417  * (key->GetActionTime() - sosLaunchTime_) > SOS_WAIT_TIME * FREQUENCY)
6418  * @tc.type: FUNC
6419  * @tc.require:
6420  */
6421 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleEvent_005, TestSize.Level1)
6422 {
6423     CALL_TEST_DEBUG;
6424     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6425     ASSERT_NE(keyEvent, nullptr);
6426     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6427     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6428     int64_t time = 700000;
6429     keyEvent->SetActionTime(time);
6430     KeyCommandHandler handler;
6431     handler.powerUpTime_ = 0;
6432     handler.sosLaunchTime_ = 0;
6433     handler.isParseConfig_ = true;
6434     handler.isParseLongPressConfig_ = true;
6435     handler.isParseMaxCount_ = true;
6436     ASSERT_NO_FATAL_FAILURE(handler.HandleEvent(keyEvent));
6437 }
6438 
6439 /**
6440  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_003
6441  * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6442  * @tc.type: FUNC
6443  * @tc.require:
6444  */
6445 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_003, TestSize.Level1)
6446 {
6447     CALL_TEST_DEBUG;
6448     KeyCommandHandler handler;
6449     RepeatKey repeatKey;
6450     repeatKey.ability.bundleName = SOS_BUNDLE_NAME;
6451     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6452 
6453     repeatKey.ability.bundleName = "test";
6454     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6455 }
6456 
6457 /**
6458  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_004
6459  * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6460  * @tc.type: FUNC
6461  * @tc.require:
6462  */
6463 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_004, TestSize.Level1)
6464 {
6465     CALL_TEST_DEBUG;
6466     KeyCommandHandler handler;
6467     RepeatKey repeatKey;
6468     repeatKey.ability.bundleName = SOS_BUNDLE_NAME;
6469     repeatKey.delay = 10;
6470     handler.downActionTime_ = 10;
6471     handler.lastDownActionTime_ = 10;
6472     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6473 
6474     handler.downActionTime_ = 100;
6475     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6476 }
6477 
6478 /**
6479  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyOwnCount_005
6480  * @tc.desc: Test if (item.ability.bundleName == SOS_BUNDLE_NAME)
6481  * @tc.type: FUNC
6482  * @tc.require:
6483  */
6484 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyOwnCount_005, TestSize.Level1)
6485 {
6486     CALL_TEST_DEBUG;
6487     KeyCommandHandler handler;
6488     RepeatKey repeatKey;
6489     repeatKey.ability.bundleName = "test";
6490     repeatKey.delay = 10;
6491     handler.upActionTime_ = 10;
6492     handler.lastDownActionTime_ = 10;
6493     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6494 
6495     handler.downActionTime_ = 100;
6496     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyOwnCount(repeatKey));
6497 }
6498 
6499 constexpr int32_t MODULE_TYPE {1};
6500 constexpr int32_t UDS_FD {-1};
6501 constexpr int32_t UDS_UID {100};
6502 constexpr int32_t UDS_PID {100};
6503 
6504 /**
6505  * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_001
6506  * @tc.desc: Test if (bundleName.find(matchName) == std::string::npos)
6507  * @tc.type: FUNC
6508  * @tc.require:
6509  */
6510 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_001, TestSize.Level1)
6511 {
6512     CALL_TEST_DEBUG;
6513     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6514     ASSERT_NE(keyEvent, nullptr);
6515     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6516 
6517     RepeatKey repeatKey;
6518     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6519     repeatKey.ability.bundleName = ".camera";
6520 
6521     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6522     WindowInfo windowInfo;
6523     windowInfo.id = 0;
6524     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6525     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6526         it->second.windowsInfo.push_back(windowInfo);
6527         it->second.focusWindowId = 0;
6528     }
6529     UDSServer udsServer;
6530     udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6531     SessionPtr sessionPtr =
6532         std::make_shared<UDSSession>(repeatKey.ability.bundleName, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
6533     udsServer.sessionsMap_[1] = sessionPtr;
6534     inputWindowsManager->udsServer_ = &udsServer;
6535     EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6536     IInputWindowsManager::instance_ = inputWindowsManager;
6537 
6538     KeyCommandHandler handler;
6539     DISPLAY_MONITOR->SetScreenStatus("test");
6540     DISPLAY_MONITOR->SetScreenLocked(true);
6541     ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6542 }
6543 
6544 /**
6545  * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_002
6546  * @tc.desc: Test if (WIN_MGR->JudgeCameraInFore() &&
6547  * (screenStatus != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF && isScreenLocked))
6548  * @tc.type: FUNC
6549  * @tc.require:
6550  */
6551 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_002, TestSize.Level1)
6552 {
6553     CALL_TEST_DEBUG;
6554     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6555     ASSERT_NE(keyEvent, nullptr);
6556     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6557 
6558     RepeatKey repeatKey;
6559     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6560     repeatKey.ability.bundleName = ".camera";
6561 
6562     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6563     WindowInfo windowInfo;
6564     windowInfo.id = 0;
6565     OLD::DisplayGroupInfo displayGroupInfoRef;
6566     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6567     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6568         displayGroupInfoRef = it->second;
6569     }
6570     displayGroupInfoRef.windowsInfo.push_back(windowInfo);
6571     displayGroupInfoRef.focusWindowId = 0;
6572     UDSServer udsServer;
6573     udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6574     SessionPtr sessionPtr =
6575         std::make_shared<UDSSession>(repeatKey.ability.bundleName, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
6576     udsServer.sessionsMap_[1] = sessionPtr;
6577     inputWindowsManager->udsServer_ = &udsServer;
6578     EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6579     IInputWindowsManager::instance_ = inputWindowsManager;
6580 
6581     KeyCommandHandler handler;
6582     DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
6583     DISPLAY_MONITOR->SetScreenLocked(true);
6584     ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6585 }
6586 
6587 /**
6588  * @tc.name: KeyCommandHandlerTest_CheckSpecialRepeatKey_003
6589  * @tc.desc: Test if (WIN_MGR->JudgeCameraInFore() &&
6590  * (screenStatus != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF && isScreenLocked))
6591  * @tc.type: FUNC
6592  * @tc.require:
6593  */
6594 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_003, TestSize.Level1)
6595 {
6596     CALL_TEST_DEBUG;
6597     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6598     ASSERT_NE(keyEvent, nullptr);
6599     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6600 
6601     RepeatKey repeatKey;
6602     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6603     repeatKey.ability.bundleName = ".camera";
6604 
6605     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6606     WindowInfo windowInfo;
6607     windowInfo.id = 0;
6608     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6609     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
6610         it->second.windowsInfo.push_back(windowInfo);
6611         it->second.focusWindowId = 0;
6612     }
6613     UDSServer udsServer;
6614     udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6615     SessionPtr sessionPtr =
6616         std::make_shared<UDSSession>(repeatKey.ability.bundleName, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
6617     udsServer.sessionsMap_[1] = sessionPtr;
6618     inputWindowsManager->udsServer_ = &udsServer;
6619     EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6620     IInputWindowsManager::instance_ = inputWindowsManager;
6621 
6622     KeyCommandHandler handler;
6623     DISPLAY_MONITOR->SetScreenStatus("test");
6624     DISPLAY_MONITOR->SetScreenLocked(false);
6625     ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6626 }
6627 
6628 /**
6629  * @tc.name: CheckSpecialRepeatKey_Normal_Branch_004
6630  * @tc.desc: Test KEY_ACTION_UP and keyCode equl
6631  * @tc.type: FUNC
6632  * @tc.require:
6633  */
6634 HWTEST_F(KeyCommandHandlerTest, CheckSpecialRepeatKey_Normal_Branch_004, TestSize.Level1)
6635 {
6636     CALL_TEST_DEBUG;
6637     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6638     ASSERT_NE(keyEvent, nullptr);
6639     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
6640     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
6641     RepeatKey repeatKey;
6642     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
6643     repeatKey.ability.bundleName = ".camera";
6644 
6645     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
6646     WindowInfo windowInfo;
6647     windowInfo.id = 0;
6648     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
6649     if (it != inputWindowsManager->displayGroupInfoMap_.end())
6650     {
6651         it->second.windowsInfo.push_back(windowInfo);
6652         it->second.focusWindowId = 0;
6653     }
6654     UDSServer udsServer;
6655     udsServer.idxPidMap_.insert(std::make_pair(0, 1));
6656     SessionPtr sessionPtr =
6657         std::make_shared<UDSSession>(repeatKey.ability.bundleName, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
6658     udsServer.sessionsMap_[1] = sessionPtr;
6659     inputWindowsManager->udsServer_ = &udsServer;
6660     EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
6661     IInputWindowsManager::instance_ = inputWindowsManager;
6662 
6663     KeyCommandHandler handler;
6664     DISPLAY_MONITOR->SetScreenStatus("test");
6665     DISPLAY_MONITOR->SetScreenLocked(false);
6666     ASSERT_NO_FATAL_FAILURE(handler.CheckSpecialRepeatKey(repeatKey, keyEvent));
6667     int32_t ret = keyEvent->GetKeyAction();
6668     EXPECT_EQ(handler.repeatKey_.keyAction, ret);
6669 }
6670 
6671 /**
6672  * @tc.name: KeyCommandHandlerTest_HandleRepeatKeyCount_001
6673  * @tc.desc: Test if (walletLaunchDelayTimes_ != 0)
6674  * @tc.type: FUNC
6675  * @tc.require:
6676  */
6677 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleRepeatKeyCount_001, TestSize.Level1)
6678 {
6679     CALL_TEST_DEBUG;
6680     KeyCommandHandler handler;
6681     RepeatKey repeatKey;
6682     repeatKey.keyCode = KeyEvent::KEYCODE_POWER;
6683     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6684     ASSERT_NE(keyEvent, nullptr);
6685     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6686     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
6687     handler.walletLaunchDelayTimes_ = 0;
6688     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
6689 
6690     handler.walletLaunchDelayTimes_ = 1;
6691     ASSERT_NO_FATAL_FAILURE(handler.HandleRepeatKeyCount(repeatKey, keyEvent));
6692 }
6693 
6694 /**
6695  * @tc.name: KeyCommandHandlerTest_LaunchAiScreenAbility_001
6696  * @tc.desc: Test LaunchAiScreenAbility
6697  * @tc.type: FUNC
6698  * @tc.require:
6699  */
6700 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchAiScreenAbility_001, TestSize.Level1)
6701 {
6702     CALL_TEST_DEBUG;
6703     KeyCommandHandler handler;
6704     int32_t pid = 1;
6705     int32_t ret = handler.LaunchAiScreenAbility(pid);
6706     EXPECT_NE(ret, RET_OK);
6707 
6708     handler.twoFingerGesture_.touchEvent = PointerEvent::Create();
6709     ret = handler.LaunchAiScreenAbility(pid);
6710     EXPECT_NE(ret, RET_OK);
6711 
6712     auto now = std::chrono::high_resolution_clock::now();
6713     auto duration = now.time_since_epoch();
6714     handler.twoFingerGesture_.startTime = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
6715     ret = handler.LaunchAiScreenAbility(pid);
6716     EXPECT_NE(ret, RET_OK);
6717 
6718     handler.twoFingerGesture_.windowId = handler.twoFingerGesture_.touchEvent->GetTargetWindowId();
6719     ret = handler.LaunchAiScreenAbility(pid);
6720     EXPECT_NE(ret, RET_OK);
6721 
6722     handler.twoFingerGesture_.longPressFlag = true;
6723     ret = handler.LaunchAiScreenAbility(pid);
6724     EXPECT_NE(ret, RET_OK);
6725 }
6726 
6727 /**
6728  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_002
6729  * @tc.desc: Test the funcation HandleKeyEvent
6730  * @tc.type: FUNC
6731  * @tc.require:
6732  */
6733 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_002, TestSize.Level1)
6734 {
6735     CALL_TEST_DEBUG;
6736     KeyCommandHandler handler;
6737     std::shared_ptr<KeyEvent> keyEvent = nullptr;
6738     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
6739 }
6740 
6741 /**
6742  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_003
6743  * @tc.desc: Test the funcation HandleKeyEvent
6744  * @tc.type: FUNC
6745  * @tc.require:
6746  */
6747 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_003, TestSize.Level1)
6748 {
6749     CALL_TEST_DEBUG;
6750     KeyCommandHandler handler;
6751     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6752     ASSERT_NE(keyEvent, nullptr);
6753 
6754     // Set up menu key event
6755     KeyEvent::KeyItem item;
6756     item.SetKeyCode(KeyEvent::KEYCODE_MENU);
6757     keyEvent->AddKeyItem(item);
6758     keyEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
6759 
6760     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
6761 }
6762 
6763 /**
6764  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_004
6765  * @tc.desc: Test the funcation HandleKeyEvent
6766  * @tc.type: FUNC
6767  * @tc.require:
6768  */
6769 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_004, TestSize.Level1)
6770 {
6771     CALL_TEST_DEBUG;
6772     KeyCommandHandler handler;
6773     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6774     ASSERT_NE(keyEvent, nullptr);
6775     // Set up key event that would make OnHandleEvent return true
6776     KeyEvent::KeyItem item;
6777     item.SetKeyCode(KeyEvent::KEYCODE_POWER);
6778     keyEvent->AddKeyItem(item);
6779     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
6780     // Set screen status to off
6781     DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
6782     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
6783 }
6784 
6785 /**
6786  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_005
6787  * @tc.desc: Test the funcation HandleKeyEvent
6788  * @tc.type: FUNC
6789  * @tc.require:
6790  */
6791 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_005, TestSize.Level1)
6792 {
6793     CALL_TEST_DEBUG;
6794     KeyCommandHandler handler;
6795     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6796     ASSERT_NE(keyEvent, nullptr);
6797     // Set up key event that would make OnHandleEvent return true
6798     KeyEvent::KeyItem item;
6799     item.SetKeyCode(KeyEvent::KEYCODE_HOME);
6800     keyEvent->AddKeyItem(item);
6801     keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
6802     // Set screen status to on
6803     DISPLAY_MONITOR->SetScreenStatus(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
6804     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
6805 }
6806 
6807 /**
6808  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_006
6809  * @tc.desc: Test the funcation HandleKeyEvent
6810  * @tc.type: FUNC
6811  * @tc.require:
6812  */
6813 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_006, TestSize.Level1)
6814 {
6815     CALL_TEST_DEBUG;
6816     KeyCommandHandler handler;
6817     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
6818     ASSERT_NE(keyEvent, nullptr);
6819 
6820     KeyEvent::KeyItem item;
6821     item.SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6822     keyEvent->AddKeyItem(item);
6823     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6824     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
6825 }
6826 
6827 /**
6828  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_007
6829  * @tc.desc: Test the funcation HandleKeyEvent
6830  * @tc.type: FUNC
6831  * @tc.require:
6832  */
6833 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_007, TestSize.Level1)
6834 {
6835     CALL_TEST_DEBUG;
6836     KeyCommandHandler handler;
6837     ASSERT_NE(keyEvent_, nullptr);
6838 
6839     KeyEvent::KeyItem item;
6840     item.SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6841     keyEvent_->AddKeyItem(item);
6842     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6843     keyEvent_->SetKeyAction(KNUCKLE_1F_DOUBLE_CLICK);
6844     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent_));
6845 }
6846 
6847 /**
6848  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_008
6849  * @tc.desc: Test the funcation HandleKeyEvent
6850  * @tc.type: FUNC
6851  * @tc.require:
6852  */
6853 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_008, TestSize.Level1)
6854 {
6855     CALL_TEST_DEBUG;
6856     KeyCommandHandler handler;
6857     ASSERT_NE(keyEvent_, nullptr);
6858 
6859     KeyEvent::KeyItem item;
6860     item.SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6861     keyEvent_->AddKeyItem(item);
6862     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_MENU);
6863     keyEvent_->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
6864     handler.existMenuDown_ = false;
6865     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent_));
6866 }
6867 
6868 /**
6869  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_009
6870  * @tc.desc: Test the funcation HandleKeyEvent
6871  * @tc.type: FUNC
6872  * @tc.require:
6873  */
6874 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_009, TestSize.Level1)
6875 {
6876     CALL_TEST_DEBUG;
6877     KeyCommandHandler handler;
6878     ASSERT_NE(keyEvent_, nullptr);
6879 
6880     KeyEvent::KeyItem item;
6881     item.SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6882     keyEvent_->AddKeyItem(item);
6883     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_POWER);
6884     handler.isFreezePowerKey_ = true;
6885     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_OFF;
6886     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent_));
6887 
6888     DISPLAY_MONITOR->screenStatus_ = EventFwk::CommonEventSupportTest::COMMON_EVENT_SCREEN_ON;
6889     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent_));
6890 }
6891 
6892 /**
6893  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_010
6894  * @tc.desc: Test the funcation HandleKeyEvent
6895  * @tc.type: FUNC
6896  * @tc.require:
6897  */
6898 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_010, TestSize.Level1)
6899 {
6900     CALL_TEST_DEBUG;
6901     KeyCommandHandler handler;
6902     handler.nextHandler_ = std::make_shared<EventFilterHandler>();
6903     handler.SetNext(handler.nextHandler_);
6904     ASSERT_NE(keyEvent_, nullptr);
6905 
6906     KeyEvent::KeyItem item;
6907     item.SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6908     keyEvent_->AddKeyItem(item);
6909     keyEvent_->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
6910     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent_));
6911 }
6912 
6913 /**
6914  * @tc.name: KeyCommandHandlerTest_OnHandleTouchEvent001
6915  * @tc.desc: Test OnHandleTouchEvent
6916  * @tc.type: FUNC
6917  * @tc.require:
6918  */
6919 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_OnHandleTouchEvent001, TestSize.Level1)
6920 {
6921     CALL_TEST_DEBUG;
6922     KeyCommandHandler handler;
6923     PointerEvent::PointerItem item;
6924     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
6925     ASSERT_NE(touchEvent, nullptr);
6926     handler.isParseConfig_ = false;
6927     handler.isDistanceConfig_ = false;
6928     handler.isKnuckleSwitchConfig_ = true;
6929     item.SetPointerId(1);
6930     item.SetToolType(PointerEvent::TOOL_TYPE_PENCIL);
6931     touchEvent->AddPointerItem(item);
6932     touchEvent->SetPointerId(1);
6933     touchEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_MOVE);
6934     ASSERT_NO_FATAL_FAILURE(handler.OnHandleTouchEvent(touchEvent));
6935 }
6936 
6937 /**
6938  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_005
6939  * @tc.desc: Test HandleKnuckleGestureDownEvent
6940  * @tc.type: FUNC
6941  * @tc.require:
6942  */
6943 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_005, TestSize.Level1)
6944 {
6945     CALL_DEBUG_ENTER;
6946     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
6947     ASSERT_TRUE(pointerEvent != nullptr);
6948 
6949     PointerEvent::PointerItem firstItem;
6950     firstItem.SetPointerId(1);
6951     firstItem.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6952     firstItem.SetDownTime(1000);
6953 
6954     PointerEvent::PointerItem secondItem;
6955     secondItem.SetPointerId(2);
6956     secondItem.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6957     secondItem.SetDownTime(1000 + TWO_FINGERS_TIME_LIMIT);
6958     pointerEvent->SetPointerId(1);
6959     pointerEvent->AddPointerItem(firstItem);
6960     KeyCommandHandler keyCommandHandler;
6961     ASSERT_NO_FATAL_FAILURE(keyCommandHandler.HandleKnuckleGestureDownEvent(pointerEvent));
6962 
6963     pointerEvent->SetPointerId(2);
6964     pointerEvent->RemovePointerItem(1);
6965     pointerEvent->AddPointerItem(secondItem);
6966     ASSERT_NO_FATAL_FAILURE(keyCommandHandler.HandleKnuckleGestureDownEvent(pointerEvent));
6967 }
6968 
6969 /**
6970  * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_006
6971  * @tc.desc: Test HandleKnuckleGestureDownEvent
6972  * @tc.type: FUNC
6973  * @tc.require:
6974  */
6975 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_006, TestSize.Level1)
6976 {
6977     CALL_DEBUG_ENTER;
6978     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
6979     ASSERT_TRUE(pointerEvent != nullptr);
6980     KeyCommandHandler keyCommandHandler;
6981     PointerEvent::PointerItem firstItem;
6982     firstItem.SetPointerId(1);
6983     firstItem.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6984     firstItem.SetDownTime(1000);
6985 
6986     PointerEvent::PointerItem secondItem;
6987     secondItem.SetPointerId(2);
6988     secondItem.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6989     secondItem.SetDownTime(1100);
6990 
6991     PointerEvent::PointerItem thirdItem;
6992     thirdItem.SetPointerId(3);
6993     thirdItem.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE);
6994     thirdItem.SetDownTime(1200);
6995 
6996     pointerEvent->SetPointerId(1);
6997     pointerEvent->AddPointerItem(firstItem);
6998     pointerEvent->SetPointerId(2);
6999     pointerEvent->AddPointerItem(secondItem);
7000     pointerEvent->SetPointerId(3);
7001     pointerEvent->AddPointerItem(thirdItem);
7002     ASSERT_NO_FATAL_FAILURE(keyCommandHandler.HandleKnuckleGestureDownEvent(pointerEvent));
7003 }
7004 
7005 /**
7006  * @tc.name: KeyCommandHandlerTest_KnuckleGestureProcessor_001
7007  * @tc.desc: Test KnuckleGestureProcessor
7008  * @tc.type: FUNC
7009  * @tc.require:
7010  */
7011 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleGestureProcessor_001, TestSize.Level1)
7012 {
7013     CALL_TEST_DEBUG;
7014     KeyCommandHandler handler;
7015     KnuckleGesture knuckleGesture;
7016     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
7017     ASSERT_NE(touchEvent, nullptr);
7018     knuckleGesture.lastPointerDownEvent = touchEvent;
7019     knuckleGesture.lastPointerUpTime = 10;
7020     knuckleGesture.ability.bundleName = SCREENRECORDER_BUNDLE_NAME;
7021     touchEvent->SetActionTime(20);
7022     handler.knuckleCount_ = 1;
7023     ASSERT_NO_FATAL_FAILURE(
7024         handler.KnuckleGestureProcessor(touchEvent, knuckleGesture, KnuckleType::KNUCKLE_TYPE_DOUBLE));
7025 }
7026 
7027 /**
7028  * @tc.name: KeyCommandHandlerTest_ReportKnuckleScreenCapture
7029  * @tc.desc: Test KnuckleGestureProcessor
7030  * @tc.type: FUNC
7031  * @tc.require:
7032  */
7033 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportKnuckleScreenCapture, TestSize.Level1)
7034 {
7035     CALL_TEST_DEBUG;
7036     KeyCommandHandler handler;
7037     KnuckleGesture knuckleGesture;
7038     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
7039     ASSERT_NE(touchEvent, nullptr);
7040     PointerEvent::PointerItem item;
7041     item.SetPointerId(0);
7042     touchEvent->SetPointerId(0);
7043     touchEvent->AddPointerItem(item);
7044     ASSERT_NO_FATAL_FAILURE(handler.ReportKnuckleScreenCapture(touchEvent));
7045 }
7046 
7047 /**
7048  * @tc.name: KeyCommandHandlerTest_ReportKnuckleScreenCapture_001
7049  * @tc.desc: Test KnuckleGestureProcessor
7050  * @tc.type: FUNC
7051  * @tc.require:
7052  */
7053 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportKnuckleScreenCapture_001, TestSize.Level1)
7054 {
7055     CALL_TEST_DEBUG;
7056     KeyCommandHandler handler;
7057     KnuckleGesture knuckleGesture;
7058     std::shared_ptr<PointerEvent> touchEvent = PointerEvent::Create();
7059     ASSERT_NE(touchEvent, nullptr);
7060     PointerEvent::PointerItem item;
7061     PointerEvent::PointerItem item2;
7062     item.SetPointerId(0);
7063     touchEvent->SetPointerId(0);
7064     touchEvent->AddPointerItem(item);
7065     item2.SetPointerId(1);
7066     touchEvent->SetPointerId(1);
7067     touchEvent->AddPointerItem(item2);
7068     ASSERT_NO_FATAL_FAILURE(handler.ReportKnuckleScreenCapture(touchEvent));
7069 }
7070 
7071 /**
7072  * @tc.name: KeyCommandHandlerTest_SwitchScreenCapturePermission
7073  * @tc.desc: Test SwitchScreenCapturePermission
7074  * @tc.type: FUNC
7075  * @tc.require:
7076  */
7077 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SwitchScreenCapturePermission, TestSize.Level1)
7078 {
7079     CALL_TEST_DEBUG;
7080     KeyCommandHandler handler;
7081     std::uint32_t permissions = DEFAULT_PERMISSIONS;
7082     bool enable = false;
7083     ASSERT_NO_FATAL_FAILURE(handler.SwitchScreenCapturePermission(permissions, enable));
7084     EXPECT_EQ(handler.screenCapturePermission_, 0);
7085 
7086     enable = true;
7087     ASSERT_NO_FATAL_FAILURE(handler.SwitchScreenCapturePermission(permissions, enable));
7088     EXPECT_EQ(handler.screenCapturePermission_, DEFAULT_PERMISSIONS);
7089 }
7090 
7091 /**
7092  * @tc.name: KeyCommandHandlerTest_HasScreenCapturePermission
7093  * @tc.desc: Test HasScreenCapturePermission
7094  * @tc.type: FUNC
7095  * @tc.require:
7096  */
7097 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HasScreenCapturePermission, TestSize.Level1)
7098 {
7099     CALL_TEST_DEBUG;
7100     KeyCommandHandler handler;
7101     handler.gameForbidFingerKnuckle_ = false;
7102     handler.screenshotSwitch_.statusConfigValue = true;
7103     handler.recordSwitch_.statusConfigValue = true;
7104     EXPECT_EQ(handler.HasScreenCapturePermission(KNUCKLE_SCREENSHOT), 1);
7105     EXPECT_EQ(handler.HasScreenCapturePermission(KNUCKLE_SCROLL_SCREENSHOT), 1);
7106     EXPECT_EQ(handler.HasScreenCapturePermission(KNUCKLE_ENABLE_AI_BASE), 1);
7107     EXPECT_EQ(handler.HasScreenCapturePermission(KNUCKLE_SCREEN_RECORDING), 1);
7108     EXPECT_EQ(handler.HasScreenCapturePermission(TOUCHPAD_KNUCKLE_SCREENSHOT), 1);
7109     EXPECT_EQ(handler.HasScreenCapturePermission(TOUCHPAD_KNUCKLE_SCREEN_RECORDING), 1);
7110     EXPECT_EQ(handler.HasScreenCapturePermission(SHORTCUT_KEY_SCREENSHOT), 1);
7111     EXPECT_EQ(handler.HasScreenCapturePermission(SHORTCUT_KEY_SCREEN_RECORDING), 1);
7112     EXPECT_EQ(handler.HasScreenCapturePermission(DEFAULT_PERMISSIONS), 1);
7113 }
7114 
7115 /**
7116  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor
7117  * @tc.desc: Test if (bundleName.find(matchName) == std::string::npos)
7118  * @tc.type: FUNC
7119  * @tc.require:
7120  */
7121 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterProximitySensor, TestSize.Level1)
7122 {
7123     CALL_TEST_DEBUG;
7124     KeyCommandHandler handler;
7125     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7126     ASSERT_NE(keyEvent, nullptr);
7127     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
7128 
7129     RepeatKey repeatKey;
7130     repeatKey.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7131     repeatKey.ability.bundleName = ".camera";
7132 
7133     auto inputWindowsManager = std::make_shared<InputWindowsManager>();
7134     WindowInfo windowInfo;
7135     windowInfo.id = 0;
7136     auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID);
7137     if (it != inputWindowsManager->displayGroupInfoMap_.end()) {
7138         it->second.windowsInfo.push_back(windowInfo);
7139         it->second.focusWindowId = 0;
7140     }
7141     UDSServer udsServer;
7142     udsServer.idxPidMap_.insert(std::make_pair(0, 1));
7143     SessionPtr sessionPtr =
7144         std::make_shared<UDSSession>(repeatKey.ability.bundleName, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
7145     udsServer.sessionsMap_[1] = sessionPtr;
7146     inputWindowsManager->udsServer_ = &udsServer;
7147     EXPECT_NE(inputWindowsManager->udsServer_, nullptr);
7148     IInputWindowsManager::instance_ = inputWindowsManager;
7149     ASSERT_NO_FATAL_FAILURE(handler.RegisterProximitySensor());
7150     handler.hasRegisteredSensor_ = true;
7151     ASSERT_NO_FATAL_FAILURE(handler.RegisterProximitySensor());
7152 }
7153 
7154 /**
7155  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_020
7156  * @tc.desc: Test HandleKeyEvent
7157  * @tc.type: FUNC
7158  * @tc.require:
7159  */
7160 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_020, TestSize.Level1)
7161 {
7162     CALL_TEST_DEBUG;
7163     KeyCommandHandler handler;
7164     std::shared_ptr<KeyEvent> keyEvent = nullptr;
7165     ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
7166 }
7167 
7168 /**
7169  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_030
7170  * @tc.desc: Test ParseRepeatKeyMaxCount
7171  * @tc.type: FUNC
7172  * @tc.require:
7173  */
7174 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_030, TestSize.Level1)
7175 {
7176     CALL_TEST_DEBUG;
7177     KeyCommandHandler handler;
7178     ASSERT_NO_FATAL_FAILURE(handler.ParseRepeatKeyMaxCount());
7179 }
7180 
7181 /**
7182  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_031
7183  * @tc.desc: Test UnregisterProximitySensor
7184  * @tc.type: FUNC
7185  * @tc.require:
7186  */
7187 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_031, TestSize.Level1)
7188 {
7189     CALL_TEST_DEBUG;
7190     KeyCommandHandler handler;
7191     handler.hasRegisteredSensor_ = true;
7192     ASSERT_NO_FATAL_FAILURE(handler.UnregisterProximitySensor());
7193     handler.hasRegisteredSensor_ = false;
7194     ASSERT_NO_FATAL_FAILURE(handler.UnregisterProximitySensor());
7195 }
7196 
7197 /**
7198  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_032
7199  * @tc.desc: Test RegisterProximitySensor
7200  * @tc.type: FUNC
7201  * @tc.require:
7202  */
7203 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_032, TestSize.Level1)
7204 {
7205     CALL_TEST_DEBUG;
7206     KeyCommandHandler handler;
7207     handler.hasRegisteredSensor_ = true;
7208     ASSERT_NO_FATAL_FAILURE(handler.RegisterProximitySensor());
7209     handler.hasRegisteredSensor_ = false;
7210     ASSERT_NO_FATAL_FAILURE(handler.RegisterProximitySensor());
7211 }
7212 
7213 /**
7214  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_033
7215  * @tc.desc: Test SendSaveEvent
7216  * @tc.type: FUNC
7217  * @tc.require:
7218  */
7219 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_033, TestSize.Level1)
7220 {
7221     CALL_TEST_DEBUG;
7222     KeyCommandHandler handler;
7223     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7224     ASSERT_NE(keyEvent, nullptr);
7225     handler.isParseConfig_ = false;
7226     ASSERT_NO_FATAL_FAILURE(handler.SendSaveEvent(keyEvent));
7227 }
7228 
7229 /**
7230  * @tc.name: KeyCommandHandlerTest_HandleKeyEvent_034
7231  * @tc.desc: Test MenuClickProcess
7232  * @tc.type: FUNC
7233  * @tc.require:
7234  */
7235 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKeyEvent_034, TestSize.Level1)
7236 {
7237     CALL_TEST_DEBUG;
7238     KeyCommandHandler handler;
7239     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7240     DisplayEventMonitor displayEventMonitor;
7241     std::string bundleName = "";
7242     std::string abilityName = "";
7243     std::string action = "";
7244     displayEventMonitor.screenStatus_ = "usual.event.SCREEN_OFF";
7245     displayEventMonitor.isScreenLocked_ = false;
7246     ASSERT_NO_FATAL_FAILURE(handler.MenuClickProcess(bundleName, abilityName, action));
7247     displayEventMonitor.screenStatus_ = "usual";
7248     displayEventMonitor.isScreenLocked_ = true;
7249     ASSERT_NO_FATAL_FAILURE(handler.MenuClickProcess(bundleName, abilityName, action));
7250 }
7251 
7252 /**
7253  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_001
7254  * @tc.desc: Test MenuClickProcess
7255  * @tc.type: FUNC
7256  * @tc.require:
7257  */
7258 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterProximitySensor_001, TestSize.Level1)
7259 {
7260     CALL_TEST_DEBUG;
7261     KeyCommandHandler handler;
7262     handler.hasRegisteredSensor_ = true;
7263     handler.RegisterProximitySensor();
7264     EXPECT_EQ(handler.hasRegisteredSensor_, true);
7265 }
7266 
7267 /**
7268  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_002
7269  * @tc.desc: Test MenuClickProcess
7270  * @tc.type: FUNC
7271  * @tc.require:
7272  */
7273 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterProximitySensor_002, TestSize.Level1)
7274 {
7275     CALL_TEST_DEBUG;
7276     KeyCommandHandler handler;
7277     handler.hasRegisteredSensor_ = false;
7278     handler.RegisterProximitySensor();
7279     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7280 }
7281 
7282 /**
7283  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_001
7284  * @tc.desc: Test MenuClickProcess
7285  * @tc.type: FUNC
7286  * @tc.require:
7287  */
7288 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterProximitySensor_001, TestSize.Level1)
7289 {
7290     CALL_TEST_DEBUG;
7291     KeyCommandHandler handler;
7292     handler.hasRegisteredSensor_ = true;
7293     handler.UnregisterProximitySensor();
7294     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7295 }
7296 
7297 /**
7298  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_002
7299  * @tc.desc: Test MenuClickProcess
7300  * @tc.type: FUNC
7301  * @tc.require:
7302  */
7303 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterProximitySensor_002, TestSize.Level1)
7304 {
7305     CALL_TEST_DEBUG;
7306     KeyCommandHandler handler;
7307     handler.hasRegisteredSensor_ = false;
7308     handler.UnregisterProximitySensor();
7309     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7310 }
7311 
7312 /**
7313  * @tc.name: KeyCommandHandlerTest_MenuClickHandle_001
7314  * @tc.desc: Test MenuClickProcess
7315  * @tc.type: FUNC
7316  * @tc.require:
7317  */
7318 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MenuClickHandle_001, TestSize.Level1)
7319 {
7320     CALL_TEST_DEBUG;
7321     bool ret = false;
7322     if (CMD_DEVICE_TYPE_TV != CMD_PRODUCT_TYPE_TV) {
7323         EXPECT_EQ(ret, false);
7324     } else {
7325         KeyCommandHandler handler;
7326         std::shared_ptr<KeyEvent> event = KeyEvent::Create();
7327         event->SetKeyCode(KeyEvent::KEYCODE_MENU);
7328         event->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7329         ret = handler.MenuClickHandle(event);
7330         EXPECT_EQ(ret, true);
7331         EXPECT_EQ(handler.existMenuDown_, true);
7332     }
7333 }
7334 
7335 /**
7336  * @tc.name: KeyCommandHandlerTest_MenuClickHandle_002
7337  * @tc.desc: Test MenuClickProcess
7338  * @tc.type: FUNC
7339  * @tc.require:
7340  */
7341 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MenuClickHandle_002, TestSize.Level1)
7342 {
7343     CALL_TEST_DEBUG;
7344     bool ret = false;
7345     if (CMD_DEVICE_TYPE_TV != CMD_PRODUCT_TYPE_TV) {
7346         EXPECT_EQ(ret, false);
7347     } else {
7348         KeyCommandHandler handler;
7349         std::shared_ptr<KeyEvent> event = KeyEvent::Create();
7350         event->SetKeyCode(KeyEvent::KEYCODE_MENU);
7351         event->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7352         ret = handler.MenuClickHandle(event);
7353         EXPECT_EQ(ret, true);
7354         EXPECT_EQ(handler.existMenuDown_, true);
7355 
7356         event->SetKeyAction(KeyEvent::KEY_ACTION_UP);
7357         std::this_thread::sleep_for(std::chrono::seconds(1));
7358         ret = handler.MenuClickHandle(event);
7359         EXPECT_EQ(handler.existMenuDown_, false);
7360         EXPECT_EQ(handler.tmpkeyEvent_, nullptr);
7361         EXPECT_EQ(ret, true);
7362     }
7363 }
7364 
7365 /**
7366  * @tc.name: KeyCommandHandlerTest_MenuClickHandle_003
7367  * @tc.desc: Test MenuClickProcess
7368  * @tc.type: FUNC
7369  * @tc.require:
7370  */
7371 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MenuClickHandle_003, TestSize.Level1)
7372 {
7373     CALL_TEST_DEBUG;
7374     bool ret = false;
7375     if (CMD_DEVICE_TYPE_TV != CMD_PRODUCT_TYPE_TV) {
7376         EXPECT_EQ(ret, false);
7377     } else {
7378         KeyCommandHandler handler;
7379         std::shared_ptr<KeyEvent> event = KeyEvent::Create();
7380         event->SetKeyCode(KeyEvent::KEYCODE_MENU);
7381         event->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7382         ret = handler.MenuClickHandle(event);
7383         EXPECT_EQ(ret, true);
7384         EXPECT_EQ(handler.existMenuDown_, true);
7385 
7386         event->SetKeyAction(KeyEvent::KEY_ACTION_UP);
7387         ret = handler.MenuClickHandle(event);
7388         EXPECT_EQ(ret, false);
7389     }
7390 }
7391 
7392 /**
7393  * @tc.name: KeyCommandHandlerTest_MenuClickHandle_004
7394  * @tc.desc: Test MenuClickProcess
7395  * @tc.type: FUNC
7396  * @tc.require:
7397  */
7398 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MenuClickHandle_004, TestSize.Level1)
7399 {
7400     CALL_TEST_DEBUG;
7401     bool ret = false;
7402     if (CMD_DEVICE_TYPE_TV != CMD_PRODUCT_TYPE_TV) {
7403         EXPECT_EQ(ret, false);
7404     } else {
7405         KeyCommandHandler handler;
7406         std::shared_ptr<KeyEvent> event = KeyEvent::Create();
7407         event->SetKeyCode(KeyEvent::KEYCODE_MENU);
7408         event->SetKeyAction(KeyEvent::KEY_ACTION_UP);
7409         ret = handler.MenuClickHandle(event);
7410         EXPECT_EQ(ret, false);
7411         EXPECT_EQ(handler.existMenuDown_, false);
7412     }
7413 }
7414 
7415 /**
7416  * @tc.name: KeyCommandHandlerTest_MenuClickHandle_005
7417  * @tc.desc: Test MenuClickProcess
7418  * @tc.type: FUNC
7419  * @tc.require:
7420  */
7421 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_MenuClickHandle_005, TestSize.Level1)
7422 {
7423     CALL_TEST_DEBUG;
7424     bool ret = false;
7425     if (CMD_DEVICE_TYPE_TV != CMD_PRODUCT_TYPE_TV) {
7426         EXPECT_EQ(ret, false);
7427     } else {
7428         KeyCommandHandler handler;
7429         std::shared_ptr<KeyEvent> event = KeyEvent::Create();
7430         event->SetKeyCode(KeyEvent::KEYCODE_MENU);
7431         event->SetKeyAction(KeyEvent::KEY_ACTION_UP);
7432         ret = handler.MenuClickHandle(event);
7433         EXPECT_EQ(ret, false);
7434         EXPECT_EQ(handler.existMenuDown_, false);
7435 
7436         ret = handler.MenuClickHandle(event);
7437         EXPECT_EQ(ret, false);
7438 
7439         handler.existMenuDown_ = true;
7440         event->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7441         ret = handler.MenuClickHandle(event);
7442         EXPECT_EQ(ret, true);
7443 
7444         handler.existMenuDown_ = false;
7445         event->SetKeyAction(KeyEvent::KEY_ACTION_UP);
7446         ret = handler.MenuClickHandle(event);
7447         EXPECT_EQ(ret, false);
7448     }
7449 }
7450 
7451 #ifdef OHOS_BUILD_ENABLE_MISTOUCH_PREVENTION
7452  /**
7453   * @tc.name: KeyCommandHandlerTest_CallMistouchPrevention001
7454   * @tc.desc: Test the normal running condition
7455   * @tc.type: FUNC
7456   * @tc.require:
7457   */
7458  HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CallMistouchPrevention001, TestSize.Level1)
7459  {
7460     auto handler = std::make_shared<KeyCommandHandler>();
7461     handler->CallMistouchPrevention();
7462     EXPECT_EQ(handler->mistouchLibHandle_, nullptr);
7463 }
7464 
7465 /**
7466 * @tc.name  : KeyCommandHandlerTest_CallMistouchPrevention002
7467 * @tc.number: CallMistouchPrevention_Test_002
7468 * @tc.desc  : Test CallMistouchPrevention when dlsym fails
7469 */
7470 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CallMistouchPrevention002, TestSize.Level1)
7471 {
7472     auto handler = std::make_shared<KeyCommandHandler>();
7473     handler->mistouchLibHandle_ = nullptr;
7474     ASSERT_NO_FATAL_FAILURE(handler->CallMistouchPrevention());
7475 }
7476 
7477 /**
7478  * @tc.name  : CallMistouchPrevention_ShouldLogError_WhenLoadLibraryFails
7479  * @tc.number: CallMistouchPreventionTest_003
7480  * @tc.desc  : When loading the contactless operation library fails, the function should log an error and return
7481  */
7482 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CallMistouchPrevention003, TestSize.Level1)
7483 {
7484     keyCommandHandler->hasRegisteredSensor_ = false;
7485     keyCommandHandler->mistouchLibHandle_ = nullptr;
7486     keyCommandHandler->CallMistouchPrevention();
7487 
7488     EXPECT_EQ(keyCommandHandler->mistouchLibHandle_, nullptr);
7489 }
7490 
7491 /**
7492  * @tc.name  : CallMistouchPrevention_ShouldLogError_WhenCreateFunctionFails
7493  * @tc.number: CallMistouchPreventionTest_003
7494  * @tc.desc  : When the IMistouchPrevention instance creation function fails,
7495  * the function should log an error and return
7496  */
7497 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CallMistouchPrevention004, TestSize.Level1)
7498 {
7499     keyCommandHandler->hasRegisteredSensor_ = false;
7500     keyCommandHandler->mistouchLibHandle_ = (void*)0x1;
7501     keyCommandHandler->fnCreate_ = nullptr;
7502     keyCommandHandler->CallMistouchPrevention();
7503 
7504     EXPECT_EQ(keyCommandHandler->fnCreate_, nullptr);
7505 }
7506 
7507 /**
7508  * @tc.name  : CallMistouchPrevention_ShouldSucceed_WhenAllConditionsMet
7509  * @tc.number: CallMistouchPreventionTest_004
7510  * @tc.desc  : When all conditions are met, the function should successfully
7511  * execute the touch free operation logic
7512  */
7513 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CallMistouchPrevention005, TestSize.Level1)
7514 {
7515     keyCommandHandler->hasRegisteredSensor_ = false;
7516     keyCommandHandler->mistouchLibHandle_ = (void*)0x1;
7517     keyCommandHandler->fnCreate_ = (void*)0x1;
7518     keyCommandHandler->mistouchPrevention_ = (IMistouchPrevention*)0x1;
7519     keyCommandHandler->ret_ = 0;
7520     keyCommandHandler->timerId_ = 0;
7521     keyCommandHandler->CallMistouchPrevention();
7522     EXPECT_TRUE(keyCommandHandler->hasRegisteredSensor_);
7523     EXPECT_NE(keyCommandHandler->timerId_, -1);
7524 }
7525 
7526 /**
7527  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_001
7528  * @tc.desc: Test MenuClickProcess
7529  * @tc.type: FUNC
7530  * @tc.require:
7531  */
7532 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterProximitySensor_001, TestSize.Level1)
7533 {
7534     CALL_TEST_DEBUG;
7535     KeyCommandHandler handler;
7536     handler.hasRegisteredSensor_ = true;
7537     handler.RegisterProximitySensor();
7538     EXPECT_EQ(handler.hasRegisteredSensor_, true);
7539 }
7540 
7541 /**
7542  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_002
7543  * @tc.desc: Test MenuClickProcess
7544  * @tc.type: FUNC
7545  * @tc.require:
7546  */
7547 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_RegisterProximitySensor_002, TestSize.Level1)
7548 {
7549     CALL_TEST_DEBUG;
7550     KeyCommandHandler handler;
7551     handler.hasRegisteredSensor_ = false;
7552     handler.RegisterProximitySensor();
7553     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7554 }
7555 
7556 /**
7557  * @tc.name  : UnregisterMistouchPrevention_ShouldDoNothing_WhenNotRegistered
7558  * @tc.number: UnregisterMistouchPreventionTest_001
7559  * @tc.desc  : When an unregistered sensor is tested, the UnregisterMistouchPrevention
7560  * function should return immediately.
7561  */
7562 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterMistouchPrevention001, TestSize.Level1) {
7563     KeyCommandHandler handler;
7564     handler.hasRegisteredSensor_ = false;
7565     handler.UnregisterMistouchPrevention();
7566     EXPECT_FALSE(handler.hasRegisteredSensor_);
7567 }
7568 
7569 /**
7570  * @tc.name  : KeyCommandHandlerTest_UnregisterMistouchPrevention002
7571  * @tc.number: UnregisterMistouchPreventionTest_002
7572  * @tc.desc  : When an unregistered sensor is tested, the UnregisterMistouchPrevention
7573  * function should return immediately.
7574  */
7575 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterMistouchPrevention002, TestSize.Level1) {
7576     KeyCommandHandler handler;
7577     handler.hasRegisteredSensor_ = true;
7578     handler.timerId_ = 1;
7579     ASSERT_NO_FATAL_FAILURE(handler.UnregisterMistouchPrevention());
7580 }
7581 
7582 /**
7583  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_003
7584  * @tc.desc: Test MenuClickProcess
7585  * @tc.type: FUNC
7586  * @tc.require:
7587  */
7588 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterProximitySensor_003, TestSize.Level1)
7589 {
7590     CALL_TEST_DEBUG;
7591     KeyCommandHandler handler;
7592     handler.hasRegisteredSensor_ = true;
7593     handler.UnregisterProximitySensor();
7594     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7595 }
7596 
7597 /**
7598  * @tc.name: KeyCommandHandlerTest_RegisterProximitySensor_004
7599  * @tc.desc: Test MenuClickProcess
7600  * @tc.type: FUNC
7601  * @tc.require:
7602  */
7603 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_UnregisterProximitySensor_004, TestSize.Level1)
7604 {
7605     CALL_TEST_DEBUG;
7606     KeyCommandHandler handler;
7607     handler.hasRegisteredSensor_ = false;
7608     handler.UnregisterProximitySensor();
7609     EXPECT_EQ(handler.hasRegisteredSensor_, false);
7610 }
7611 
7612 /**
7613  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey001
7614  * @tc.number: CheckSpecialRepeatKeyTest_001
7615  * @tc.desc  : When the key code does not match, the function should return false
7616  */
7617 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey001, TestSize.Level1) {
7618     RepeatKey item;
7619     item.keyCode = KeyEvent::KEYCODE_POWER;
7620     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7621     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
7622 
7623     EXPECT_FALSE(CheckSpecialRepeatKey(item, keyEvent));
7624 }
7625 
7626 /**
7627  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey002
7628  * @tc.number: CheckSpecialRepeatKeyTest_002
7629  * @tc.desc  : When the key code is not the volume down key, the function should return false
7630  */
7631 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey002, TestSize.Level1) {
7632     RepeatKey item;
7633     item.keyCode = KeyEvent::KEYCODE_POWER;
7634     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7635     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
7636 
7637     EXPECT_FALSE(CheckSpecialRepeatKey(item, keyEvent));
7638 }
7639 
7640 /**
7641  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey003
7642  * @tc.number: CheckSpecialRepeatKeyTest_003
7643  * @tc.desc  : When the application package name does not contain '. camera',
7644  * the function should return false
7645  */
7646 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey003, TestSize.Level1) {
7647     RepeatKey item;
7648     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7649     item.ability.bundleName = "com.example.app";
7650     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7651     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
7652 
7653     EXPECT_FALSE(CheckSpecialRepeatKey(item, keyEvent));
7654 }
7655 
7656 /**
7657  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey004
7658  * @tc.number: CheckSpecialRepeatKeyTest_004
7659  * @tc.desc  : When the screen is locked and the screen status is not off,
7660  * the function should return true
7661  */
7662 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey004, TestSize.Level1) {
7663     RepeatKey item;
7664     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7665     item.ability.bundleName = "com.example.camera";
7666     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7667     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
7668 
7669     EXPECT_TRUE(CheckSpecialRepeatKey(item, keyEvent));
7670 }
7671 
7672 /**
7673  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey005
7674  * @tc.number: CheckSpecialRepeatKeyTest_005
7675  * @tc.desc  : When the call status is active, the function should return true
7676  */
7677 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey005, TestSize.Level1) {
7678     RepeatKey item;
7679     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7680     item.ability.bundleName = "com.example.camera";
7681     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7682     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
7683 
7684     EXPECT_TRUE(CheckSpecialRepeatKey(item, keyEvent));
7685 }
7686 
7687 /**
7688  * @tc.name  : KeyCommandHandlerTest_CheckSpecialRepeatKey006
7689  * @tc.number: CheckSpecialRepeatKeyTest_006
7690  * @tc.desc  : When the screen is locked and the music is not activated,
7691  * the function should return false
7692  */
7693 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey006, TestSize.Level1) {
7694     RepeatKey item;
7695     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7696     item.ability.bundleName = "com.example.camera";
7697     std::shared_ptr<KeyEvent> keyEvent = std::make_shared<KeyEvent>();
7698     keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
7699 
7700     EXPECT_FALSE(CheckSpecialRepeatKey(item, keyEvent));
7701 }
7702 
7703 /**
7704  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility001
7705  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_001
7706  * @tc.desc: Verify VOLUME_DOWN + camera app with valid state launches ability
7707  */
7708 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility001, TestSize.Level1)
7709 {
7710     RepeatKey item;
7711     KeyCommandHandler handler;
7712     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7713     ASSERT_NE(keyEvent, nullptr);
7714     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7715     item.ability.bundleName = "com.ohos.camera";
7716     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7717 
7718     handler.ret_.store(0);
7719 
7720     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7721 
7722     handler.LaunchRepeatKeyAbility(item, keyEvent);
7723     EXPECT_TRUE(handler.repeatKeyCountMap_.empty());
7724 }
7725 
7726 /**
7727  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility002
7728  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_002
7729  * @tc.desc: Verify VOLUME_DOWN + camera app with valid state launches ability
7730  */
7731 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility002, TestSize.Level1)
7732 {
7733     RepeatKey item;
7734     KeyCommandHandler handler;
7735     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7736     ASSERT_NE(keyEvent, nullptr);
7737     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7738     item.ability.bundleName = "com.ohos.camera";
7739     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7740 
7741     handler.ret_.store(5);
7742 
7743     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7744 
7745     handler.LaunchRepeatKeyAbility(item, keyEvent);
7746     EXPECT_TRUE(handler.repeatKeyCountMap_.empty());
7747 }
7748 
7749 /**
7750  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility003
7751  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_003
7752  * @tc.desc: Verify VOLUME_DOWN + camera app with valid state launches ability
7753  */
7754 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility003, TestSize.Level1)
7755 {
7756     RepeatKey item;
7757     KeyCommandHandler handler;
7758     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7759     ASSERT_NE(keyEvent, nullptr);
7760     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7761     item.ability.bundleName = "com.ohos.camera";
7762     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7763 
7764     handler.ret_.store(100);
7765 
7766     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7767 
7768     handler.LaunchRepeatKeyAbility(item, keyEvent);
7769     EXPECT_TRUE(handler.repeatKeyCountMap_.empty());
7770 }
7771 
7772 /**
7773  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility004
7774  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_004
7775  * @tc.desc: Verify non-VOLUME_DOWN key launches ability
7776  */
7777 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility004, TestSize.Level1)
7778 {
7779     RepeatKey item;
7780     KeyCommandHandler handler;
7781     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7782     ASSERT_NE(keyEvent, nullptr);
7783     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7784     item.ability.bundleName = "com.ohos.camera";
7785     keyEvent->SetKeyAction(KeyEvent::KEYCODE_VOLUME_DOWN);
7786 
7787     handler.ret_.store(5);
7788 
7789     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7790 
7791     handler.LaunchRepeatKeyAbility(item, keyEvent);
7792     EXPECT_TRUE(handler.repeatKeyCountMap_.empty());
7793 }
7794 
7795 /**
7796  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility005
7797  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_005
7798  * @tc.desc: Verify cancel event propagation
7799  */
7800 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility005, TestSize.Level1)
7801 {
7802     RepeatKey item;
7803     KeyCommandHandler handler;
7804     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7805     ASSERT_NE(keyEvent, nullptr);
7806     item.keyCode = KeyEvent::KEYCODE_POWER;
7807     item.ability.bundleName = "com.ohos.settings";
7808     keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
7809     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
7810 
7811     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7812 }
7813 
7814 /**
7815  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility006
7816  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_006
7817  * @tc.desc: Verify map clearing
7818  */
7819 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility006, TestSize.Level1)
7820 {
7821     RepeatKey item;
7822     item.keyCode = KeyEvent::KEYCODE_VOLUME_UP;
7823     item.ability.bundleName = "com.ohos.music";
7824     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7825     ASSERT_NE(keyEvent, nullptr);
7826 
7827     KeyCommandHandler handler;
7828 
7829     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7830 }
7831 
7832 /**
7833  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility007
7834  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_007
7835  * @tc.desc: Verify mistouch prevention safety with null pointer
7836  */
7837 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility007, TestSize.Level1)
7838 {
7839     RepeatKey item;
7840     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7841     item.ability.bundleName = "com.ohos.camera";
7842     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7843     ASSERT_NE(keyEvent, nullptr);
7844 
7845     KeyCommandHandler handler;
7846     handler.ret_.store(0);
7847     handler.mistouchPrevention_ = nullptr;  // Null pointer
7848 
7849     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7850 }
7851 
7852 /**
7853  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility008
7854  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_008
7855  * @tc.desc: Verify null subscriber handler safety
7856  */
7857 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility008, TestSize.Level1)
7858 {
7859     RepeatKey item;
7860     item.keyCode = KeyEvent::KEYCODE_VOLUME_UP;
7861     item.ability.bundleName = "com.ohos.music";
7862     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7863     ASSERT_NE(keyEvent, nullptr);
7864 
7865     KeyCommandHandler handler;
7866 
7867     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7868 }
7869 
7870 /**
7871  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility009
7872  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_009
7873  * @tc.desc: Verify bytrace start/stop pairing
7874  */
7875 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility009, TestSize.Level1)
7876 {
7877     RepeatKey item;
7878     item.keyCode = KeyEvent::KEYCODE_POWER;
7879     item.ability.bundleName = "com.ohos.settings";
7880     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7881     ASSERT_NE(keyEvent, nullptr);
7882 
7883     KeyCommandHandler handler;
7884 
7885     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7886 }
7887 
7888 /**
7889  * @tc.name: KeyCommandHandlerTest_LaunchRepeatKeyAbility010
7890  * @tc.number: KeyCommandHandlerTest_LaunchRepeatKeyAbility_010
7891  * @tc.desc: Verify camera substring matching
7892  */
7893 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_LaunchRepeatKeyAbility010, TestSize.Level1)
7894 {
7895     RepeatKey item;
7896     item.keyCode = KeyEvent::KEYCODE_VOLUME_DOWN;
7897     item.ability.bundleName = "com.example.camera.pro";  // Contains ".camera"
7898     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
7899     ASSERT_NE(keyEvent, nullptr);
7900 
7901     KeyCommandHandler handler;
7902     handler.ret_.store(0);
7903 
7904     ASSERT_NO_FATAL_FAILURE(handler.LaunchAbility(item.ability));
7905 }
7906 
7907 /**
7908  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey001
7909  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_001
7910  * @tc.desc: Verify non-SOS page unsets freeze flag
7911  */
7912 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey001, TestSize.Level1)
7913 {
7914     KeyCommandHandler handler;
7915     handler.isFreezePowerKey_ = true;
7916 
7917     EXPECT_EQ(handler.SetIsFreezePowerKey("HomeScreen"), RET_OK);
7918 }
7919 
7920 /**
7921  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey002
7922  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_002
7923  * @tc.desc: Verify non-SOS page unsets freeze flag
7924  */
7925 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey002, TestSize.Level1)
7926 {
7927     KeyCommandHandler handler;
7928     handler.isFreezePowerKey_ = true;
7929 
7930     EXPECT_TRUE(handler.isFreezePowerKey_);
7931 }
7932 
7933 /**
7934  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey003
7935  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_003
7936  * @tc.desc: Verify SOS page sets freeze flag and resets state
7937  */
7938 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey003, TestSize.Level1)
7939 {
7940     KeyCommandHandler handler;
7941     handler.count_ = 5;
7942     handler.launchAbilityCount_ = 2;
7943     handler.repeatKeyCountMap_["key1"] = 3;
7944     handler.sosDelayTimerId_ = 100;
7945 
7946     EXPECT_EQ(handler.SetIsFreezePowerKey("SosCountdown"), RET_OK);
7947     EXPECT_TRUE(handler.isFreezePowerKey_);
7948     EXPECT_NE(handler.sosLaunchTime_, 123456789);
7949     EXPECT_EQ(handler.count_, 0);
7950     EXPECT_EQ(handler.launchAbilityCount_, 0);
7951     EXPECT_TRUE(handler.repeatKeyCountMap_.empty());
7952     EXPECT_NE(handler.sosDelayTimerId_, 200);
7953 }
7954 
7955 /**
7956  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey004
7957  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_004
7958  * @tc.desc: Verify no timer removal when no existing timer
7959  */
7960 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey004, TestSize.Level1)
7961 {
7962     KeyCommandHandler handler;
7963     handler.sosDelayTimerId_ = -1;  // No existing timer
7964 
7965     EXPECT_NE(handler.SetIsFreezePowerKey("SosCountdown"), RET_OK);
7966 }
7967 
7968 /**
7969  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey005
7970  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_005
7971  * @tc.desc: Verify timer callback unsets freeze flag
7972  */
7973 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey005, TestSize.Level1)
7974 {
7975     KeyCommandHandler handler;
7976     TimerCallback callback;
7977     handler.SetIsFreezePowerKey("SosCountdown");
7978     ASSERT_TRUE(callback);
7979 
7980     // Execute timer callback
7981     EXPECT_FALSE(handler.isFreezePowerKey_);
7982 }
7983 
7984 /**
7985  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey006
7986  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_006
7987  * @tc.desc: Verify state preservation on non-SOS calls
7988  */
7989 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey006, TestSize.Level1)
7990 {
7991     KeyCommandHandler handler;
7992     handler.count_ = 10;
7993     handler.launchAbilityCount_ = 5;
7994     handler.repeatKeyCountMap_["key2"] = 7;
7995     handler.sosDelayTimerId_ = 600;
7996 
7997     handler.SetIsFreezePowerKey("LockScreen");
7998 
7999     // Verify state unchanged
8000     EXPECT_EQ(handler.count_, 10);
8001 }
8002 
8003 
8004 /**
8005  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey007
8006  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_007
8007  * @tc.desc: Verify state preservation on non-SOS calls
8008  */
8009 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey007, TestSize.Level1)
8010 {
8011     KeyCommandHandler handler;
8012     handler.count_ = 10;
8013     handler.launchAbilityCount_ = 5;
8014     handler.repeatKeyCountMap_["key2"] = 7;
8015     handler.sosDelayTimerId_ = 600;
8016 
8017     handler.SetIsFreezePowerKey("LockScreen");
8018 
8019     EXPECT_EQ(handler.launchAbilityCount_, 5);
8020 }
8021 
8022 
8023 /**
8024  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey008
8025  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_008
8026  * @tc.desc: Verify state preservation on non-SOS calls
8027  */
8028 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey008, TestSize.Level1)
8029 {
8030     KeyCommandHandler handler;
8031     handler.count_ = 10;
8032     handler.launchAbilityCount_ = 5;
8033     handler.repeatKeyCountMap_["key2"] = 7;
8034     handler.sosDelayTimerId_ = 600;
8035 
8036     handler.SetIsFreezePowerKey("LockScreen");
8037 
8038     EXPECT_FALSE(handler.repeatKeyCountMap_.empty());
8039 }
8040 
8041 /**
8042  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey009
8043  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_009
8044  * @tc.desc: Verify state preservation on non-SOS calls
8045  */
8046 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey009, TestSize.Level1)
8047 {
8048     KeyCommandHandler handler;
8049     handler.count_ = 10;
8050     handler.launchAbilityCount_ = 5;
8051     handler.repeatKeyCountMap_["key2"] = 7;
8052     handler.sosDelayTimerId_ = 600;
8053 
8054     handler.SetIsFreezePowerKey("LockScreen");
8055 
8056     EXPECT_EQ(handler.sosDelayTimerId_, 600);
8057 }
8058 
8059 /**
8060  * @tc.name: KeyCommandHandlerTest_SetIsFreezePowerKey007
8061  * @tc.number: KeyCommandHandlerTest_SetIsFreezePowerKey_007
8062  * @tc.desc: Verify non-SOS page unsets freeze flag
8063  */
8064 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_SetIsFreezePowerKey007, TestSize.Level1)
8065 {
8066     KeyCommandHandler handler;
8067     handler.isFreezePowerKey_ = false;
8068 
8069     EXPECT_NE(handler.SetIsFreezePowerKey("HomeScreen"), RET_OK);
8070 }
8071 #endif // OHOS_BUILD_ENABLE_MISTOUCH_PREVENTION
8072 
8073 /**
8074  * @tc.name: KeyCommandHandlerTest_KnuckleGestureProcessor_002
8075  * @tc.desc: Test KnuckleGestureProcessor
8076  * @tc.type: FUNC
8077  * @tc.require:
8078  */
8079 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_KnuckleGestureProcessor_002, TestSize.Level1)
8080 {
8081     CALL_TEST_DEBUG;
8082     KeyCommandHandler handler;
8083     KnuckleGesture knuckleGesture;
8084     ASSERT_NE(touchEvent_, nullptr);
8085     ASSERT_NE(keyEvent_, nullptr);
8086     handler.tappingCount_ = 10;
8087     ASSERT_NO_FATAL_FAILURE(
8088         handler.KnuckleGestureProcessor(touchEvent_, knuckleGesture, KnuckleType::KNUCKLE_TYPE_DOUBLE));
8089 }
8090 
8091 /**
8092  * @tc.name: KeyCommandHandlerTest_ReportGestureInfo_002
8093  * @tc.desc: Test ReportGestureInfo
8094  * @tc.type: FUNC
8095  * @tc.require:
8096  */
8097 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportGestureInfo_002, TestSize.Level1)
8098 {
8099     CALL_TEST_DEBUG;
8100     KeyCommandHandler handler;
8101     KnuckleGesture knuckleGesture;
8102     ASSERT_NE(touchEvent_, nullptr);
8103     ASSERT_NE(keyEvent_, nullptr);
8104     ASSERT_NO_FATAL_FAILURE(handler.ReportGestureInfo());
8105 }
8106 
8107 /**
8108  * @tc.name: KeyCommandHandlerTest_IsMatchedAbility_002
8109  * @tc.desc: Test IsMatchedAbility
8110  * @tc.type: FUNC
8111  * @tc.require:
8112  */
8113 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsMatchedAbility_002, TestSize.Level1)
8114 {
8115     CALL_TEST_DEBUG;
8116     KeyCommandHandler handler;
8117     KnuckleGesture knuckleGesture;
8118     ASSERT_NE(touchEvent_, nullptr);
8119     ASSERT_NE(keyEvent_, nullptr);
8120     std::vector<float> gesturePoints;
8121     gesturePoints.push_back(10.0);
8122     gesturePoints.push_back(11.0);
8123     gesturePoints.push_back(12.0);
8124     float gestureLastX = 10.0;
8125     float gestureLastY = 10.0;
8126     ASSERT_NO_FATAL_FAILURE(handler.IsMatchedAbility(gesturePoints, gestureLastX, gestureLastY));
8127 }
8128 
8129 /**
8130  * @tc.name: KeyCommandHandlerTest_IsEnableCombineKey_005
8131  * @tc.desc: Test IsEnableCombineKey
8132  * @tc.type: FUNC
8133  * @tc.require:
8134  */
8135 HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_IsEnableCombineKey_005, TestSize.Level1)
8136 {
8137     CALL_TEST_DEBUG;
8138     KeyCommandHandler handler;
8139     KnuckleGesture knuckleGesture;
8140     ASSERT_NE(touchEvent_, nullptr);
8141     ASSERT_NE(keyEvent_, nullptr);
8142     handler.enableCombineKey_ = false;
8143     handler.isParseExcludeConfig_ = false;
8144     ASSERT_NO_FATAL_FAILURE(handler.IsEnableCombineKey(keyEvent_));
8145 }
8146 } // namespace MMI
8147 } // namespace OHOS
8148