1 /*
2 * Copyright (c) 2023-2024 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 #include "power_wakeup_controller_test.h"
16 #include <fstream>
17 #include <thread>
18 #include <unistd.h>
19
20 #include "axis_event.h"
21 #include "input_device.h"
22 #include "pointer_event.h"
23 #include <datetime_ex.h>
24 #include <input_manager.h>
25 #include <securec.h>
26
27 #include "power_mgr_client.h"
28 #include "power_mgr_service.h"
29 #include "power_state_machine.h"
30 #include "setting_helper.h"
31 #include "json/reader.h"
32
33 using namespace testing::ext;
34 using namespace OHOS::PowerMgr;
35 using namespace OHOS;
36 using namespace std;
37 static sptr<PowerMgrService> g_service;
38 static constexpr int32_t SLEEP_WAIT_TIME_S = 2;
39 static constexpr int32_t SLEEP_WAIT_TIME_MS = 400;
40 static constexpr int32_t DISPLAY_OFF_TIME_MS = 600;
41 static constexpr int32_t RECOVER_DISPLAY_OFF_TIME_S = 30 * 1000;
42 static constexpr int32_t DISPLAY_POWER_MANAGER_ID = 3308;
43 static const std::string TEST_DEVICE_ID = "test_device_id";
44
45 class InputCallbackMock : public IInputEventConsumer {
46 public:
47 virtual void OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const;
48 virtual void OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const;
49 virtual void OnInputEvent(std::shared_ptr<AxisEvent> axisEvent) const;
50 };
51
SetUpTestCase(void)52 void PowerWakeupControllerTest::SetUpTestCase(void)
53 {
54 PowerMgrClient::GetInstance().SuspendDevice();
55 EXPECT_FALSE(PowerMgrClient::GetInstance().IsScreenOn());
56 g_service = DelayedSpSingleton<PowerMgrService>::GetInstance();
57 g_service->OnStart();
58 g_service->OnAddSystemAbility(DISPLAY_POWER_MANAGER_ID, TEST_DEVICE_ID);
59 }
60
TearDownTestCase(void)61 void PowerWakeupControllerTest::TearDownTestCase(void)
62 {
63 g_service->OnStop();
64 DelayedSpSingleton<PowerMgrService>::DestroyInstance();
65 }
66
67 namespace {
CreatePointerItem(int32_t pointerId,int32_t deviceId,const std::pair<int32_t,int32_t> & displayLocation,bool isPressed)68 MMI::PointerEvent::PointerItem CreatePointerItem(
69 int32_t pointerId, int32_t deviceId, const std::pair<int32_t, int32_t>& displayLocation, bool isPressed)
70 {
71 MMI::PointerEvent::PointerItem item;
72 item.SetPointerId(pointerId);
73 item.SetDeviceId(deviceId);
74 item.SetDisplayX(displayLocation.first);
75 item.SetDisplayY(displayLocation.second);
76 item.SetPressed(isPressed);
77 return item;
78 }
79
80 /**
81 * @tc.name: PowerWakeupControllerTest001
82 * @tc.desc: test ExecWakeupMonitorByReason(Normal and exception)
83 * @tc.type: FUNC
84 * @tc.require: issueI7COGR
85 */
86 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest001, TestSize.Level0)
87 {
88 GTEST_LOG_(INFO) << "PowerWakeup001: start";
89 g_service->WakeupControllerInit();
90 g_service->wakeupController_->ExecWakeupMonitorByReason(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
91 auto monitor = g_service->wakeupController_->monitorMap_[WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON];
92 EXPECT_TRUE(monitor != nullptr);
93
94 GTEST_LOG_(INFO) << "PowerWakeupControllerTest001: end";
95 }
96
97 /**
98 * @tc.name: PowerWakeupControllerTest002
99 * @tc.desc: test Wakeup(Normal)
100 * @tc.type: FUNC
101 * @tc.require: issueI7COGR
102 */
103 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest002, TestSize.Level0)
104 {
105 GTEST_LOG_(INFO) << "PowerWakeupControllerTest002: start";
106 sleep(SLEEP_WAIT_TIME_S);
107 g_service->WakeupControllerInit();
108 // test Normal
109 g_service->wakeupController_->Wakeup();
110 EXPECT_TRUE(g_service->wakeupController_ != nullptr);
111 GTEST_LOG_(INFO) << "PowerWakeupControllerTest002: end";
112 }
113
114 /**
115 * @tc.name: PowerWakeupControllerTest003
116 * @tc.desc: test ControlListener(Normal)
117 * @tc.type: FUNC
118 * @tc.require: issueI7COGR
119 */
120 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest003, TestSize.Level0)
121 {
122 GTEST_LOG_(INFO) << "PowerWakeupControllerTest003: start";
123
124 g_service->WakeupControllerInit();
125 g_service->SuspendControllerInit();
126
127 g_service->SuspendDevice(
128 static_cast<int64_t>(time(nullptr)), SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, false);
129 g_service->wakeupController_->ControlListener(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
130 EXPECT_TRUE(g_service->wakeupController_ != nullptr);
131 g_service->WakeupDevice(static_cast<int64_t>(time(nullptr)),
132 WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON, "PowerWakeupControllerTest003");
133 g_service->wakeupController_->ControlListener(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
134 EXPECT_TRUE(static_cast<uint32_t>(g_service->wakeupController_->stateMachine_->GetState()) ==
135 static_cast<uint32_t>(PowerState::AWAKE));
136
137 g_service->wakeupController_->stateMachine_->EmplaceAwake();
138 g_service->wakeupController_->ControlListener(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
139 EXPECT_TRUE(static_cast<uint32_t>(g_service->wakeupController_->stateMachine_->GetState()) ==
140 static_cast<uint32_t>(PowerState::AWAKE));
141
142 g_service->WakeupDevice(static_cast<int64_t>(time(nullptr)),
143 WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON, "PowerWakeupControllerTest003");
144 g_service->wakeupController_->ControlListener(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
145 EXPECT_TRUE(static_cast<uint32_t>(g_service->wakeupController_->stateMachine_->GetState()) ==
146 static_cast<uint32_t>(PowerState::AWAKE));
147
148 g_service->wakeupController_->stateMachine_->SetState(
149 PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_TIMEOUT);
150 g_service->suspendController_->stateMachine_->controllerMap_.clear();
151 g_service->wakeupController_->ControlListener(WakeupDeviceType ::WAKEUP_DEVICE_POWER_BUTTON);
152 EXPECT_TRUE(static_cast<uint32_t>(g_service->wakeupController_->stateMachine_->GetState()) ==
153 static_cast<uint32_t>(PowerState::INACTIVE));
154 g_service->suspendController_->stateMachine_->InitStateMap();
155
156 GTEST_LOG_(INFO) << "PowerWakeupControllerTest003: end";
157 }
158
159 /**
160 * @tc.name: PowerWakeupControllerTest004
161 * @tc.desc: test GetTargetPath
162 * @tc.type: FUNC
163 * @tc.require: issueI7G6OY
164 */
165 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest004, TestSize.Level0)
166 {
167 GTEST_LOG_(INFO) << "PowerWakeupControllerTest004: start";
168 std::string targetPath;
169 WakeupSourceParser::GetTargetPath(targetPath);
170 EXPECT_TRUE(targetPath.size() != 0);
171 GTEST_LOG_(INFO) << "PowerWakeupControllerTest004: end";
172 }
173
174 /**
175 * @tc.name: PowerWakeupControllerTest005
176 * @tc.desc: test CreateMonitor
177 * @tc.type: FUNC
178 * @tc.require: issueI7G6OY
179 */
180 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest005, TestSize.Level0)
181 {
182 GTEST_LOG_(INFO) << "PowerWakeupControllerTest005: start";
183 g_service->WakeupControllerInit();
184 WakeupSource source1(WakeupDeviceType::WAKEUP_DEVICE_SINGLE_CLICK, 1, 0);
185 std::shared_ptr<WakeupMonitor> monitor1 = WakeupMonitor::CreateMonitor(source1);
186 EXPECT_TRUE(monitor1 != nullptr);
187
188 WakeupSource source2(WakeupDeviceType::WAKEUP_DEVICE_MAX, 1, 0);
189 std::shared_ptr<WakeupMonitor> monitor2 = WakeupMonitor::CreateMonitor(source2);
190 EXPECT_TRUE(static_cast<uint32_t>(source2.reason_) == static_cast<uint32_t>(WakeupDeviceType::WAKEUP_DEVICE_MAX));
191 GTEST_LOG_(INFO) << "PowerWakeupControllerTest005: end";
192 }
193
194 /**
195 * @tc.name: PowerWakeupControllerTest006
196 * @tc.desc: test Cancel(Normal and exception)
197 * @tc.type: FUNC
198 * @tc.require: issueI7COGR
199 */
200 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest006, TestSize.Level0)
201 {
202 GTEST_LOG_(INFO) << "PowerWakeupControllerTest006: start";
203
204 g_service->WakeupControllerInit();
205 g_service->wakeupController_->Cancel();
206 EXPECT_TRUE(g_service->wakeupController_->monitorMap_.size() == 0);
207 GTEST_LOG_(INFO) << "PowerWakeupControllerTest006: end";
208 }
209
210 /**
211 * @tc.name: PowerWakeupControllerTest007
212 * @tc.desc: test OnInputEvent(Normal)
213 * @tc.type: FUNC
214 * @tc.require: issueI7COGR
215 */
216 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest007, TestSize.Level0)
217 {
218 GTEST_LOG_(INFO) << "PowerWakeupControllerTest007: start";
219 g_service->WakeupControllerInit();
220 InputCallback* callback = new InputCallback();
221 InputCallbackMock* callback_mock = reinterpret_cast<InputCallbackMock*>(callback);
222 std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
223 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
224
225 keyEvent->SetKeyCode(OHOS::MMI::KeyEvent::KEYCODE_F1);
226 callback_mock->OnInputEvent(keyEvent);
227 keyEvent->SetKeyCode(OHOS::MMI::KeyEvent::KEYCODE_0);
228 callback_mock->OnInputEvent(keyEvent);
229 keyEvent->SetKeyCode(OHOS::MMI::KeyEvent::KEYCODE_F2);
230 callback_mock->OnInputEvent(keyEvent);
231 delete callback;
232 EXPECT_TRUE(g_service->wakeupController_ != nullptr);
233 GTEST_LOG_(INFO) << "PowerWakeupControllerTest007: end";
234 }
235
236 /**
237 * @tc.name: PowerWakeupControllerTest008
238 * @tc.desc: test OnInputEvent(Normal 1)
239 * @tc.type: FUNC
240 * @tc.require: issueI7COGR
241 */
242 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest008, TestSize.Level0)
243 {
244 GTEST_LOG_(INFO) << "PowerWakeupControllerTest008: start";
245
246 g_service->WakeupControllerInit();
247
248 constexpr int32_t DRAG_DST_X {500};
249 constexpr int32_t DRAG_DST_Y {500};
250 int32_t deviceMouseId {0};
251
252 InputCallback* callback = new InputCallback();
253 InputCallbackMock* callback_mock = reinterpret_cast<InputCallbackMock*>(callback);
254 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
255 MMI::PointerEvent::PointerItem curPointerItem;
256 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
257 pointerEvent->SetPointerId(0);
258
259 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
260 curPointerItem = CreatePointerItem(0, deviceMouseId, {DRAG_DST_X, DRAG_DST_Y}, true);
261 pointerEvent->AddPointerItem(curPointerItem);
262 callback_mock->OnInputEvent(pointerEvent);
263
264 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
265 curPointerItem = CreatePointerItem(0, deviceMouseId, {DRAG_DST_X, DRAG_DST_Y}, true);
266 pointerEvent->AddPointerItem(curPointerItem);
267 callback_mock->OnInputEvent(pointerEvent);
268
269 pointerEvent->SetSourceType(PointerEvent::TOOL_TYPE_PEN);
270 curPointerItem = CreatePointerItem(0, deviceMouseId, {DRAG_DST_X, DRAG_DST_Y}, true);
271 pointerEvent->AddPointerItem(curPointerItem);
272 callback_mock->OnInputEvent(pointerEvent);
273 EXPECT_TRUE(g_service->wakeupController_ != nullptr);
274 delete callback;
275 }
276
277 /**
278 * @tc.name: PowerWakeupControllerTest009
279 * @tc.desc: test OnInputEvent(Normal 2)
280 * @tc.type: FUNC
281 * @tc.require: issueI7COGR
282 */
283 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest009, TestSize.Level0)
284 {
285 GTEST_LOG_(INFO) << "PowerWakeupControllerTest009: start";
286
287 g_service->WakeupControllerInit();
288
289 constexpr int32_t DRAG_DST_X {500};
290 constexpr int32_t DRAG_DST_Y {500};
291 int32_t deviceMouseId {0};
292
293 InputCallback* callback = new InputCallback();
294 InputCallbackMock* callback_mock = reinterpret_cast<InputCallbackMock*>(callback);
295 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
296 MMI::PointerEvent::PointerItem curPointerItem;
297 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
298 pointerEvent->SetPointerId(0);
299
300 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
301 curPointerItem = CreatePointerItem(0, deviceMouseId, {DRAG_DST_X, DRAG_DST_Y}, true);
302 pointerEvent->AddPointerItem(curPointerItem);
303 callback_mock->OnInputEvent(pointerEvent);
304
305 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
306 curPointerItem = CreatePointerItem(0, deviceMouseId, {DRAG_DST_X, DRAG_DST_Y}, true);
307 pointerEvent->AddPointerItem(curPointerItem);
308 callback_mock->OnInputEvent(pointerEvent);
309
310 std::shared_ptr<MMI::PointerEvent> pointerEvent2 = MMI::PointerEvent::Create();
311 pointerEvent2->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
312 pointerEvent2->SetPointerId(0);
313 curPointerItem = CreatePointerItem(1, PointerEvent::TOOL_TYPE_PEN, {DRAG_DST_X, DRAG_DST_Y}, true);
314 curPointerItem.SetToolType(PointerEvent::TOOL_TYPE_PEN);
315 pointerEvent2->AddPointerItem(curPointerItem);
316 callback_mock->OnInputEvent(pointerEvent2);
317
318 curPointerItem = CreatePointerItem(0, PointerEvent::TOOL_TYPE_PEN, {DRAG_DST_X, DRAG_DST_Y}, true);
319 curPointerItem.SetToolType(PointerEvent::TOOL_TYPE_PEN);
320 pointerEvent2->AddPointerItem(curPointerItem);
321 callback_mock->OnInputEvent(pointerEvent2);
322
323 delete callback;
324 EXPECT_TRUE(g_service->wakeupController_ != nullptr);
325 GTEST_LOG_(INFO) << "PowerWakeupControllerTest009: end";
326 }
327
328 /**
329 * @tc.name: PowerWakeupControllerTest010
330 * @tc.desc: test getSourceKeys
331 * @tc.type: FUNC
332 * @tc.require: issueI7COGR
333 */
334 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest010, TestSize.Level0)
335 {
336 GTEST_LOG_(INFO) << "PowerWakeupControllerTest010: start";
337
338 std::shared_ptr<WakeupSources> sources = WakeupSourceParser::ParseSources();
339 std::vector<std::string> tmp = sources->getSourceKeys();
340 EXPECT_TRUE(tmp.size() != 0);
341 GTEST_LOG_(INFO) << "PowerWakeupControllerTest010: end";
342 }
343
344 /**
345 * @tc.name: PowerWakeupControllerTest011
346 * @tc.desc: test ParseSourcesProc(exception)
347 * @tc.type: FUNC
348 * @tc.require: issueI7COGR
349 */
350 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest011, TestSize.Level0)
351 {
352 GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: start";
353
354 static const std::string jsonStr =
355 "{\"powerkey\": {\"enable\": false},\"keyborad\": {\"enable\": false},\"mouse\": {\"enable\": "
356 "false},\"touchscreen\": {\"enable\": false,\"click\": 2},\"touchpad\": {\"enable\": false},\"pen\": "
357 "{\"enable\": "
358 "false},\"lid\": {\"enable\": false},\"switch\": {\"enable\": true},\"xxx\": {\"enable\": false}}";
359
360 std::shared_ptr<WakeupSources> parseSources = std::make_shared<WakeupSources>();
361 Json::Reader reader;
362 Json::Value root;
363
364 if (!reader.parse(jsonStr.data(), jsonStr.data() + jsonStr.size(), root)) {
365 GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: json parse error";
366 }
367
368 Json::Value::Members members = root.getMemberNames();
369 for (auto iter = members.begin(); iter != members.end(); iter++) {
370 std::string key = *iter;
371 Json::Value valueObj = root[key];
372 WakeupSourceParser::ParseSourcesProc(parseSources, valueObj, key);
373 }
374 EXPECT_TRUE(parseSources->GetSourceList().size() != 0);
375 GTEST_LOG_(INFO) << "PowerWakeupControllerTest011: end";
376 }
377
378 /**
379 * @tc.name: PowerWakeupControllerTest012
380 * @tc.desc: test OnInputEvent KeyEvent RefreshActivity
381 * @tc.type: FUNC
382 */
383 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest012, TestSize.Level0)
384 {
385 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest012: start");
386 g_service->WakeupControllerInit();
387 g_service->SetDisplayOffTime(DISPLAY_OFF_TIME_MS);
388 g_service->WakeupDevice(static_cast<int64_t>(time(nullptr)),
389 WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON, "PowerWakeupControllerTest012");
390 EXPECT_TRUE(g_service->IsScreenOn());
391 usleep(SLEEP_WAIT_TIME_MS * 1000);
392 std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent = OHOS::MMI::KeyEvent::Create();
393 InputCallback callback;
394 callback.OnInputEvent(keyEvent);
395 usleep(SLEEP_WAIT_TIME_MS * 1000);
396 EXPECT_TRUE(g_service->IsScreenOn());
397 g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S);
398 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest012: end");
399 }
400
401 /**
402 * @tc.name: PowerWakeupControllerTest013
403 * @tc.desc: test OnInputEvent PointerEvent RefreshActivity
404 * @tc.type: FUNC
405 */
406 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest013, TestSize.Level0)
407 {
408 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest013: start");
409 g_service->WakeupControllerInit();
410 g_service->SetDisplayOffTime(DISPLAY_OFF_TIME_MS);
411 g_service->WakeupDevice(static_cast<int64_t>(time(nullptr)),
412 WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, "PowerWakeupControllerTest013");
413 EXPECT_TRUE(g_service->IsScreenOn());
414 usleep(SLEEP_WAIT_TIME_MS * 1000);
415 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
416 InputCallback callback;
417 callback.OnInputEvent(pointerEvent);
418 usleep(SLEEP_WAIT_TIME_MS * 1000);
419 EXPECT_TRUE(g_service->IsScreenOn());
420 g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S);
421 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest013: end");
422 }
423
424 /**
425 * @tc.name: PowerWakeupControllerTest014
426 * @tc.desc: test OnInputEvent AxisEvent RefreshActivity
427 * @tc.type: FUNC
428 */
429 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest014, TestSize.Level0)
430 {
431 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest014: start");
432 g_service->WakeupControllerInit();
433 g_service->SetDisplayOffTime(DISPLAY_OFF_TIME_MS);
434 g_service->WakeupDevice(static_cast<int64_t>(time(nullptr)),
435 WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, "PowerWakeupControllerTest014");
436 EXPECT_TRUE(g_service->IsScreenOn());
437 usleep(SLEEP_WAIT_TIME_MS * 1000);
438 std::shared_ptr<MMI::AxisEvent> axisEvent = MMI::AxisEvent::Create();
439 InputCallback callback;
440 callback.OnInputEvent(axisEvent);
441 usleep(SLEEP_WAIT_TIME_MS * 1000);
442 EXPECT_TRUE(g_service->IsScreenOn());
443 g_service->SetDisplayOffTime(RECOVER_DISPLAY_OFF_TIME_S);
444 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest014: end");
445 }
446
447 #ifdef POWER_WAKEUPDOUBLE_OR_PICKUP_ENABLE
448 /**
449 * @tc.name: PowerWakeupControllerTest015
450 * @tc.desc: test switch to turn on the screen by double click
451 * @tc.type: FUNC
452 */
453 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest015, TestSize.Level0)
454 {
455 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest015: start");
456 g_service->WakeupControllerInit();
457 auto wakeupController_ = g_service->GetWakeupController();
458 EXPECT_TRUE(wakeupController_ != nullptr);
459 wakeupController_->ChangeWakeupSourceConfig(true);
460 auto resCode = wakeupController_->SetWakeupDoubleClickSensor(true);
461 EXPECT_TRUE(resCode != -1);
462 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest015: end");
463 }
464
465 /**
466 * @tc.name: PowerWakeupControllerTest016
467 * @tc.desc: test switch to turn on the screen by raising your hand
468 * @tc.type: FUNC
469 */
470 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest016, TestSize.Level0)
471 {
472 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest016: start");
473 g_service->WakeupControllerInit();
474 auto wakeupController_ = g_service->GetWakeupController();
475 EXPECT_TRUE(wakeupController_ != nullptr);
476 wakeupController_->ChangePickupWakeupSourceConfig(true);
477 wakeupController_->PickupConnectMotionConfig(true);
478 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest016: end");
479 }
480 #endif
481
482 /**
483 * @tc.name: PowerWakeupControllerTest017
484 * @tc.desc: test keyboard wakeup and powerkey pressed at the same time
485 * @tc.type: FUNC
486 */
487
488 /**
489 * @tc.name: PowerWakeupControllerTest0018
490 * @tc.desc: test ExecWakeupMonitorByReason(WAKEUP_DEVICE_PEN)
491 * @tc.type: FUNC
492 * @tc.require: issueI9V16C
493 */
494 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest0018, TestSize.Level0)
495 {
496 GTEST_LOG_(INFO) << "PowerWakeup0018: start";
497 g_service->WakeupControllerInit();
498 g_service->wakeupController_->ExecWakeupMonitorByReason(WakeupDeviceType ::WAKEUP_DEVICE_PEN);
499 auto monitor = g_service->wakeupController_->monitorMap_[WakeupDeviceType ::WAKEUP_DEVICE_PEN];
500 EXPECT_TRUE(monitor != nullptr);
501
502 GTEST_LOG_(INFO) << "PowerWakeupControllerTest0018: end";
503 }
504
505 /**
506 * @tc.name: PowerWakeupControllerTest0019
507 * @tc.desc: test ExecWakeupMonitorByReason(WAKEUP_DEVICE_DOUBLE_CLICK)
508 * @tc.type: FUNC
509 * @tc.require: issueI9V16C
510 */
511 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest0019, TestSize.Level0)
512 {
513 GTEST_LOG_(INFO) << "PowerWakeup0019: start";
514 g_service->WakeupControllerInit();
515 g_service->wakeupController_->ExecWakeupMonitorByReason(WakeupDeviceType ::WAKEUP_DEVICE_DOUBLE_CLICK);
516 auto monitor = g_service->wakeupController_->monitorMap_[WakeupDeviceType ::WAKEUP_DEVICE_DOUBLE_CLICK];
517 EXPECT_TRUE(monitor != nullptr);
518
519 GTEST_LOG_(INFO) << "PowerWakeupControllerTest0019: end";
520 }
521
522 /**
523 * @tc.name: PowerWakeupControllerTest020
524 * @tc.desc: test simulate powerkey event when screenoff
525 * @tc.type: FUNC
526 */
527 HWTEST_F(PowerWakeupControllerTest, PowerWakeupControllerTest020, TestSize.Level0)
528 {
529 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest020: start");
530
531 g_service->WakeupControllerInit();
532 g_service->SuspendControllerInit();
533 g_service->SuspendDevice(
534 static_cast<int64_t>(time(nullptr)), SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, false);
535 EXPECT_FALSE(g_service->IsScreenOn());
536
537 auto inputManager = MMI::InputManager::GetInstance();
538 std::shared_ptr<MMI::KeyEvent> keyEventPowerkeyDown = MMI::KeyEvent::Create();
539 keyEventPowerkeyDown->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
540 keyEventPowerkeyDown->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER);
541 std::shared_ptr<MMI::KeyEvent> keyEventPowerkeyUp = MMI::KeyEvent::Create();
542 keyEventPowerkeyUp->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
543 keyEventPowerkeyUp->SetKeyCode(MMI::KeyEvent::KEYCODE_POWER);
544
545 inputManager->SimulateInputEvent(keyEventPowerkeyDown);
546 inputManager->SimulateInputEvent(keyEventPowerkeyUp);
547 inputManager->SimulateInputEvent(keyEventPowerkeyDown);
548 inputManager->SimulateInputEvent(keyEventPowerkeyUp);
549 sleep(1);
550 EXPECT_TRUE(g_service->IsScreenOn());
551
552 POWER_HILOGI(LABEL_TEST, "PowerWakeupControllerTest020: end");
553 }
554 } // namespace