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 #define private public
16 #define protected public
17 
18 #include <functional>
19 #include <chrono>
20 #include <thread>
21 #include <message_parcel.h>
22 
23 #include "gtest/gtest.h"
24 #include "gtest/hwext/gtest-multithread.h"
25 #include "singleton.h"
26 
27 #include "common_event_support.h"
28 #include "common_event_observer.h"
29 #include "allow_type.h"
30 #include "standby_service_client.h"
31 #include "standby_service.h"
32 #include "standby_service_impl.h"
33 #include "standby_state_subscriber.h"
34 #include "standby_state_subscriber.h"
35 #include "standby_service_subscriber_stub.h"
36 #include "device_standby_switch.h"
37 
38 #include "state_manager_adapter.h"
39 #include "constraint_manager_adapter.h"
40 #include "listener_manager_adapter.h"
41 #include "strategy_manager_adapter.h"
42 #include "standby_config_manager.h"
43 #include "charge_state_monitor.h"
44 #ifdef STANDBY_SENSORS_SENSOR_ENABLE
45 #include "motion_sensor_monitor.h"
46 #endif
47 #ifdef STANDBY_MULTIMODALINPUT_INPUT_ENABLE
48 #include "input_manager.h"
49 #endif
50 #ifdef ENABLE_BACKGROUND_TASK_MGR
51 #include "background_task_listener.h"
52 #endif
53 #include "input_manager_listener.h"
54 #include "common_constant.h"
55 #include "dark_state.h"
56 
57 using namespace testing::ext;
58 using namespace testing::mt;
59 
60 namespace OHOS {
61 namespace DevStandbyMgr {
62 namespace {
63     const vector<std::string> COMMON_EVENT_LIST = {
64         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON,
65         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF,
66         EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING,
67         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED,
68         EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING,
69         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED,
70         EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON,
71         EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED,
72     };
73     constexpr int32_t SLEEP_TIMEOUT = 500;
74 }
75 
76 class StandbyPluginUnitTest : public testing::Test {
77 public:
78     static void SetUpTestCase();
79     static void TearDownTestCase();
SetUp()80     void SetUp() override {}
TearDown()81     void TearDown() override {}
82 
SleepForFC()83     inline static void SleepForFC()
84     {
85         std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMEOUT));
86     }
87 private:
88     static std::shared_ptr<ConstraintManagerAdapter> constraintManager_;
89     static std::shared_ptr<ListenerManagerAdapter> listenerManager_;
90     static std::shared_ptr<StrategyManagerAdapter> strategyManager_;
91     static std::shared_ptr<StateManagerAdapter> standbyStateManager_;
92 };
93 
TearDownTestCase()94 void StandbyPluginUnitTest::TearDownTestCase()
95 {
96     SleepForFC();
97     StandbyServiceImpl::GetInstance()->UnInit();
98     if (StandbyServiceImpl::GetInstance()->handler_) {
99         StandbyServiceImpl::GetInstance()->handler_->RemoveAllEvents();
100         auto runner = StandbyServiceImpl::GetInstance()->handler_->GetEventRunner();
101         if (runner) {
102             runner->Stop();
103             runner = nullptr;
104         }
105         StandbyServiceImpl::GetInstance()->handler_ = nullptr;
106     }
107 }
108 
109 std::shared_ptr<ConstraintManagerAdapter> StandbyPluginUnitTest::constraintManager_ {nullptr};
110 std::shared_ptr<ListenerManagerAdapter> StandbyPluginUnitTest::listenerManager_ {nullptr};
111 std::shared_ptr<StrategyManagerAdapter> StandbyPluginUnitTest::strategyManager_ {nullptr};
112 std::shared_ptr<StateManagerAdapter> StandbyPluginUnitTest::standbyStateManager_ {nullptr};
113 
SetUpTestCase()114 void StandbyPluginUnitTest::SetUpTestCase()
115 {
116     StandbyServiceImpl::GetInstance()->Init();
117     SleepForFC();
118 
119     constraintManager_ = std::make_shared<ConstraintManagerAdapter>();
120     listenerManager_ = std::make_shared<ListenerManagerAdapter>();
121     strategyManager_ = std::make_shared<StrategyManagerAdapter>();
122     standbyStateManager_ = std::make_shared<StateManagerAdapter>();
123 
124     StandbyServiceImpl::GetInstance()->constraintManager_ = constraintManager_;
125     StandbyServiceImpl::GetInstance()->listenerManager_ = listenerManager_;
126     StandbyServiceImpl::GetInstance()->strategyManager_ = strategyManager_;
127     StandbyServiceImpl::GetInstance()->standbyStateManager_ = standbyStateManager_;
128     StandbyServiceImpl::GetInstance()->InitReadyState();
129     SleepForFC();
130 }
131 
132 /**
133  * @tc.name: StandbyPluginUnitTest_001
134  * @tc.desc: test Init of StandbyPlugin.
135  * @tc.type: FUNC
136  * @tc.require:
137  */
138 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_001, TestSize.Level1)
139 {
140     listenerManager_->StopListener();
141     listenerManager_->UnInit();
142     constraintManager_->UnInit();
143     strategyManager_->strategyList_.clear();
144     standbyStateManager_->UnInit();
145     standbyStateManager_->Init();
146     strategyManager_->Init();
147     constraintManager_->Init();
148     listenerManager_->Init();
149     listenerManager_->StartListener();
150     EXPECT_NE(listenerManager_, nullptr);
151 }
152 
153 /**
154  * @tc.name: StandbyPluginUnitTest_002
155  * @tc.desc: test RegisterPolicy of StandbyPlugin.
156  * @tc.type: FUNC
157  * @tc.require:
158  */
159 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_002, TestSize.Level1)
160 {
161     strategyManager_->RegisterPolicy({"NETWORK", "TIMER", "RUNNING_LOCK", "WORK_SCHEDULER", ""});
162     EXPECT_FALSE(strategyManager_->strategyList_.empty());
163 }
164 
165 /**
166  * @tc.name: StandbyPluginUnitTest_003
167  * @tc.desc: test HandleEvent of StandbyPlugin.
168  * @tc.type: FUNC
169  * @tc.require:
170  */
171 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_003, TestSize.Level1)
172 {
173     StandbyMessage message(StandbyMessageType::PHASE_TRANSIT);
174     standbyStateManager_->HandleEvent(message);
175     strategyManager_->HandleEvent(message);
176     StandbyMessage commonEventMessage(StandbyMessageType::COMMON_EVENT);
177     standbyStateManager_->HandleEvent(commonEventMessage);
178     strategyManager_->HandleEvent(commonEventMessage);
179     StandbyMessage conditionChangeMessage(StandbyMessageType::RES_CTRL_CONDITION_CHANGED);
180     standbyStateManager_->HandleEvent(conditionChangeMessage);
181     strategyManager_->HandleEvent(conditionChangeMessage);
182     EXPECT_NE(listenerManager_, nullptr);
183 }
184 
185 /**
186  * @tc.name: StandbyPluginUnitTest_004
187  * @tc.desc: test TransitToState of StandbyStateManager.
188  * @tc.type: FUNC
189  * @tc.require:
190  */
191 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_004, TestSize.Level1)
192 {
193     for (const auto& eventName : COMMON_EVENT_LIST) {
194         StandbyMessage message;
195         message.action_ = eventName;
196         standbyStateManager_->HandleCommonEvent(message);
197     }
198     standbyStateManager_->TransitToState(StandbyState::WORKING);
199     SleepForFC();
200     EXPECT_NE(standbyStateManager_, nullptr);
201 }
202 
203 /**
204  * @tc.name: StandbyPluginUnitTest_005
205  * @tc.desc: test ChargeStateMonitor of StandbyPlugin.
206  * @tc.type: FUNC
207  * @tc.require:
208  */
209 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_005, TestSize.Level1)
210 {
211     auto chargeStateMonitor = std::make_shared<ChargeStateMonitor>();
212     chargeStateMonitor->Init();
213     chargeStateMonitor->StartMonitoring();
214     EXPECT_NE(chargeStateMonitor, nullptr);
215 }
216 
217 /**
218  * @tc.name: StandbyPluginUnitTest_006
219  * @tc.desc: test ChargeStateMonitor of StandbyPlugin.
220  * @tc.type: FUNC
221  * @tc.require:
222  */
223 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_006, TestSize.Level1)
224 {
225     StandbyConfigManager::GetInstance()->standbySwitchMap_[DETECT_MOTION_CONFIG] = false;
226     constraintManager_->UnInit();
227     constraintManager_->Init();
228     StandbyConfigManager::GetInstance()->standbySwitchMap_[DETECT_MOTION_CONFIG] = true;
229     constraintManager_->UnInit();
230     constraintManager_->Init();
231     constraintManager_->isEvaluation_ = true;
232     constraintManager_->StopEvalution();
233     constraintManager_->isEvaluation_ = false;
234     constraintManager_->curMonitor_ = nullptr;
235     constraintManager_->StopEvalution();
236     constraintManager_->isEvaluation_ = true;
237     ConstraintEvalParam params;
238     constraintManager_->StartEvalution(params);
239     constraintManager_->isEvaluation_ = false;
240     constraintManager_->StartEvalution(params);
241     std::shared_ptr<ChargeStateMonitor> monitor = nullptr;
242     constraintManager_->RegisterConstraintCallback(params, monitor);
243     constraintManager_->StartEvalution(params);
244     constraintManager_->constraintMap_.erase(params.GetHashValue());
245     ConstraintEvalParam repeatedMotionParams{StandbyState::SLEEP, SleepStatePhase::END, StandbyState::SLEEP,
246             SleepStatePhase::END};
247     repeatedMotionParams.isRepeatedDetection_ = true;
248     constraintManager_->StartEvalution(repeatedMotionParams);
249     SleepForFC();
250     ConstraintEvalParam motionDetectParams{StandbyState::NAP, NapStatePhase::END, StandbyState::SLEEP,
251             SleepStatePhase::SYS_RES_DEEP};
252     constraintManager_->StartEvalution(motionDetectParams);
253     constraintManager_->StopEvalution();
254     standbyStateManager_->ExitStandby(StandbyState::WORKING);
255     SleepForFC();
256     EXPECT_FALSE(constraintManager_->isEvaluation_);
257 }
258 
259 #ifdef STANDBY_SENSORS_SENSOR_ENABLE
260 /**
261  * @tc.name: StandbyPluginUnitTest_007
262  * @tc.desc: test MotionSensorMonitor of StandbyPlugin.
263  * @tc.type: FUNC
264  * @tc.require:
265  */
266 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_007, TestSize.Level1)
267 {
268     ConstraintEvalParam repeatedMotionParams{};
269     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
270             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
271     repeatedMotionConstraint->StopMonitoring();
272     repeatedMotionConstraint->isMonitoring_ = true;
273     repeatedMotionConstraint->StopMonitoring();
274     repeatedMotionConstraint->isMonitoring_ = false;
275     repeatedMotionConstraint->StopMonitoring();
276     EXPECT_FALSE(repeatedMotionConstraint->isMonitoring_);
277 }
278 #endif
279 
280 /**
281  * @tc.name: StandbyPluginUnitTest_008
282  * @tc.desc: test CheckTransitionValid of StandbyPlugin.
283  * @tc.type: FUNC
284  * @tc.require:
285  */
286 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_008, TestSize.Level1)
287 {
288     for (auto &statePtr : standbyStateManager_->indexToState_) {
289         for (uint32_t nextState = StandbyState::WORKING; nextState <= StandbyState::SLEEP; ++nextState) {
290             statePtr->CheckTransitionValid(nextState);
291         }
292     }
293     EXPECT_TRUE(standbyStateManager_->CheckTransitionValid(StandbyState::WORKING, StandbyState::WORKING));
294 }
295 
296 /**
297  * @tc.name: StandbyPluginUnitTest_009
298  * @tc.desc: test TransitToState of StandbyPlugin.
299  * @tc.type: FUNC
300  * @tc.require:
301  */
302 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_009, TestSize.Level1)
303 {
304     standbyStateManager_->isEvalution_=true;
305     standbyStateManager_->ExitStandby(StandbyState::WORKING);
306     standbyStateManager_->isEvalution_=false;
307     standbyStateManager_->ExitStandby(StandbyState::WORKING);
308     standbyStateManager_->TransitToState(standbyStateManager_->curStatePtr_->GetCurState());
309     standbyStateManager_->TransitToState(StandbyState::MAINTENANCE);
310     standbyStateManager_->TransitToState(StandbyState::NAP);
311     SleepForFC();
312     standbyStateManager_->TransitToState(StandbyState::MAINTENANCE);
313     standbyStateManager_->TransitToState(StandbyState::NAP);
314     standbyStateManager_->TransitToState(StandbyState::WORKING);
315     standbyStateManager_->SendNotification(StandbyState::WORKING, true);
316     standbyStateManager_->SendNotification(StandbyState::WORKING, false);
317 
318     standbyStateManager_->isBlocked_ = true;
319     standbyStateManager_->EnterStandby(StandbyState::WORKING);
320     standbyStateManager_->isBlocked_ = false;
321     standbyStateManager_->EnterStandby(StandbyState::WORKING);
322     standbyStateManager_->TransitToState(StandbyState::WORKING);
323     EXPECT_NE(standbyStateManager_->GetCurState(), StandbyState::NAP);
324 }
325 
326 /**
327  * @tc.name: StandbyPluginUnitTest_010
328  * @tc.desc: test NapState of StandbyPlugin.
329  * @tc.type: FUNC
330  * @tc.require:
331  */
332 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_010, TestSize.Level1)
333 {
334     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(false);
335     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(true);
336 
337     standbyStateManager_->darkStatePtr_->curPhase_ = NapStatePhase::CONNECTION;
338     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
339     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
340     SleepForFC();
341     standbyStateManager_->darkStatePtr_->curPhase_ = NapStatePhase::SYS_RES_LIGHT;
342     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
343     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
344     SleepForFC();
345     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
346     standbyStateManager_->napStatePtr_->EndEvalCurrentState(true);
347     SleepForFC();
348     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::MAINTENANCE);
349 
350     standbyStateManager_->darkStatePtr_->stateManager_.reset();
351     standbyStateManager_->darkStatePtr_->EndEvalCurrentState(false);
352     standbyStateManager_->darkStatePtr_->stateManager_ = standbyStateManager_;
353 
354     standbyStateManager_->maintStatePtr_->stateManager_.reset();
355     standbyStateManager_->maintStatePtr_->BeginState();
356     standbyStateManager_->maintStatePtr_->stateManager_ = standbyStateManager_;
357 }
358 
359 /**
360  * @tc.name: StandbyPluginUnitTest_011
361  * @tc.desc: test SleepState of StandbyPlugin.
362  * @tc.type: FUNC
363  * @tc.require:
364  */
365 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_011, TestSize.Level1)
366 {
367     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
368     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
369 
370     standbyStateManager_->sleepStatePtr_->curPhase_ = SleepStatePhase::SYS_RES_DEEP;
371     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
372     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
373     SleepForFC();
374     standbyStateManager_->sleepStatePtr_->curPhase_ = SleepStatePhase::APP_RES_HARDWARE;
375     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
376     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
377     SleepForFC();
378     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
379     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(true);
380     SleepForFC();
381     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::WORKING);
382 }
383 
384 /**
385  * @tc.name: StandbyPluginUnitTest_012
386  * @tc.desc: test TransitToStateInner of StandbyPlugin.
387  * @tc.type: FUNC
388  * @tc.require:
389  */
390 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_012, TestSize.Level1)
391 {
392     standbyStateManager_->TransitToStateInner(StandbyState::WORKING);
393     standbyStateManager_->TransitToStateInner(StandbyState::DARK);
394     standbyStateManager_->TransitToStateInner(StandbyState::NAP);
395     SleepForFC();
396     standbyStateManager_->TransitToStateInner(StandbyState::MAINTENANCE);
397     standbyStateManager_->TransitToStateInner(StandbyState::NAP);
398     standbyStateManager_->TransitToStateInner(StandbyState::SLEEP);
399     SleepForFC();
400     standbyStateManager_->TransitToStateInner(StandbyState::MAINTENANCE);
401     standbyStateManager_->TransitToStateInner(StandbyState::SLEEP);
402     EXPECT_NE(standbyStateManager_->curStatePtr_->GetCurState(), StandbyState::WORKING);
403 }
404 
405 #ifdef STANDBY_SENSORS_SENSOR_ENABLE
406 /**
407  * @tc.name: StandbyPluginUnitTest_014
408  * @tc.desc: test MotionSensorMonitor of AddEnergy.
409  * @tc.type: FUNC
410  * @tc.require:
411  */
412 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0014, TestSize.Level1)
413 {
414     ConstraintEvalParam repeatedMotionParams{};
415     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
416             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
417     AccelData* accelData = new AccelData();
418     repeatedMotionConstraint->AddEnergy(accelData);
419     repeatedMotionConstraint->hasPrevAccelData_ = true;
420     repeatedMotionConstraint->AddEnergy(accelData);
421     EXPECT_TRUE(repeatedMotionConstraint->hasPrevAccelData_ == true);
422 }
423 
424 /**
425  * @tc.name: StandbyPluginUnitTest_015
426  * @tc.desc: test MotionSensorMonitor of Init.
427  * @tc.type: FUNC
428  * @tc.require:
429  */
430 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0015, TestSize.Level1)
431 {
432     ConstraintEvalParam repeatedMotionParams{};
433     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
434             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
435     repeatedMotionConstraint->Init();
436     repeatedMotionConstraint->params_.isRepeatedDetection_ = true;
437     repeatedMotionConstraint->Init();
438     repeatedMotionConstraint->params_.isRepeatedDetection_ = false;
439     EXPECT_TRUE(repeatedMotionConstraint->Init() == true);
440 }
441 
442 /**
443  * @tc.name: StandbyPluginUnitTest_016
444  * @tc.desc: test MotionSensorMonitor of PeriodlyStartMotionDetection.
445  * @tc.type: FUNC
446  * @tc.require:
447  */
448 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0016, TestSize.Level1)
449 {
450     ConstraintEvalParam repeatedMotionParams{};
451     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
452             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
453     repeatedMotionConstraint->PeriodlyStartMotionDetection();
454     repeatedMotionConstraint->energy_ = 1;
455     repeatedMotionConstraint->PeriodlyStartMotionDetection();
456     EXPECT_TRUE(repeatedMotionConstraint->StartMonitoringInner() == ERR_OK);
457     repeatedMotionConstraint->isMonitoring_ = false;
458     repeatedMotionConstraint->StartMonitoringInner();
459 }
460 
461 /**
462  * @tc.name: StandbyPluginUnitTest_017
463  * @tc.desc: test MotionSensorMonitor of StartSensor.
464  * @tc.type: FUNC
465  * @tc.require:
466  */
467 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0017, TestSize.Level1)
468 {
469     ConstraintEvalParam repeatedMotionParams{};
470     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
471             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
472     int32_t sensorTypeId = 1;
473     SensorUser sensorUser;
474     repeatedMotionConstraint->isMonitoring_ = false;
475     repeatedMotionConstraint->StartSensor();
476     repeatedMotionConstraint->isMonitoring_ = true;
477     repeatedMotionConstraint->StartSensor();
478     sensorTypeId = repeatedMotionConstraint->detectionTimeOut_;
479     repeatedMotionConstraint->StartSensor();
480     EXPECT_TRUE(repeatedMotionConstraint->StartSensor() == ERR_OK);
481 }
482 
483 /**
484  * @tc.name: StandbyPluginUnitTest_018
485  * @tc.desc: test MotionSensorMonitor of StopSensor.
486  * @tc.type: FUNC
487  * @tc.require:
488  */
489 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0018, TestSize.Level1)
490 {
491     ConstraintEvalParam repeatedMotionParams{};
492     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
493             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
494     int32_t sensorTypeId = 1;
495     SensorUser sensorUser;
496     repeatedMotionConstraint->isMonitoring_ = false;
497     repeatedMotionConstraint->StopSensor();
498     repeatedMotionConstraint->isMonitoring_ = true;
499     repeatedMotionConstraint->StopSensor();
500     sensorTypeId = repeatedMotionConstraint->detectionTimeOut_;
501     repeatedMotionConstraint->StartSensor();
502     EXPECT_TRUE(repeatedMotionConstraint->isMonitoring_ == true);
503 }
504 #endif // STANDBY_SENSORS_SENSOR_ENABLE
505 
506 /**
507  * @tc.name: StandbyPluginUnitTest_019
508  * @tc.desc: test ConstraintManagerAdapter of Init.
509  * @tc.type: FUNC
510  * @tc.require:
511  */
512 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0019, TestSize.Level1)
513 {
514     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
515     repeatedMotionConstraint->Init();
516     EXPECT_TRUE(repeatedMotionConstraint->Init());
517     StandbyServiceImpl::GetInstance()->GetStateManager();
518     repeatedMotionConstraint->Init();
519 }
520 
521 /**
522  * @tc.name: StandbyPluginUnitTest_020
523  * @tc.desc: test ConstraintManagerAdapter of StartEvalution.
524  * @tc.type: FUNC
525  * @tc.require:
526  */
527 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0020, TestSize.Level1)
528 {
529     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
530     ConstraintEvalParam params;
531     repeatedMotionConstraint->StartEvalution(params);
532     repeatedMotionConstraint->isEvaluation_ = false;
533     repeatedMotionConstraint->StartEvalution(params);
534     repeatedMotionConstraint->isEvaluation_ = true;
535     repeatedMotionConstraint->UnInit();
536     EXPECT_FALSE(repeatedMotionConstraint->StartEvalution(params) == ERR_OK);
537 }
538 
539 /**
540  * @tc.name: StandbyPluginUnitTest_021
541  * @tc.desc: test ConstraintManagerAdapter of StopEvalution.
542  * @tc.type: FUNC
543  * @tc.require:
544  */
545 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0021, TestSize.Level1)
546 {
547     auto repeatedMotionConstraint = std::make_shared<ConstraintManagerAdapter>();
548     repeatedMotionConstraint->StopEvalution();
549     repeatedMotionConstraint->isEvaluation_ = false;
550     repeatedMotionConstraint->StopEvalution();
551     repeatedMotionConstraint->isEvaluation_ = true;
552     repeatedMotionConstraint->UnInit();
553     EXPECT_FALSE(repeatedMotionConstraint->StopEvalution() == ERR_OK);
554 }
555 
556 /**
557  * @tc.name: StandbyPluginUnitTest_022
558  * @tc.desc: test ChargeStateMonitor of StartMonitoring.
559  * @tc.type: FUNC
560  * @tc.require:
561  */
562 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0022, TestSize.Level1)
563 {
564     auto repeatedChargeStateMonitor = std::make_shared<ChargeStateMonitor>();
565     repeatedChargeStateMonitor->StartMonitoring();
566     standbyStateManager_->napStatePtr_->EndEvalCurrentState(false);
567     repeatedChargeStateMonitor->StartMonitoring();
568     EXPECT_TRUE(repeatedChargeStateMonitor->Init());
569 }
570 
571 /**
572  * @tc.name: StandbyPluginUnitTest_023
573  * @tc.desc: test StateManagerAdapter of UnInit.
574  * @tc.type: FUNC
575  * @tc.require:
576  */
577 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0023, TestSize.Level1)
578 {
579     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->Init());
580 }
581 
582 /**
583  * @tc.name: StandbyPluginUnitTest_024
584  * @tc.desc: test StateManagerAdapter of HandleEvent.
585  * @tc.type: FUNC
586  * @tc.require:
587  */
588 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0024, TestSize.Level1)
589 {
590     StandbyMessage message;
591     message.eventId_ = StandbyMessageType::COMMON_EVENT;
592     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
593     message.eventId_ = StandbyMessageType::RES_CTRL_CONDITION_CHANGED;
594     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
595     message.eventId_ = 1234;
596     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleEvent(message);
597     EXPECT_TRUE(message.eventId_ != StandbyMessageType::COMMON_EVENT);
598 }
599 
600 /**
601  * @tc.name: StandbyPluginUnitTest_025
602  * @tc.desc: test StateManagerAdapter of HandleCommonEvent.
603  * @tc.type: FUNC
604  * @tc.require:
605  */
606 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0025, TestSize.Level1)
607 {
608     StandbyMessage message;
609     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON;
610     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
611     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING;
612     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
613     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED;
614     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
615     DelayedSingleton<StateManagerAdapter>::GetInstance()->Init();
616     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
617     message.action_ = "1234";
618     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
619     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
620     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
621     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING;
622     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleCommonEvent(message);
623     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->indexToState_.size() != 0);
624 }
625 
626 /**
627  * @tc.name: StandbyPluginUnitTest_026
628  * @tc.desc: test StateManagerAdapter of HandleScrOffHalfHour.
629  * @tc.type: FUNC
630  * @tc.require:
631  */
632 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0026, TestSize.Level1)
633 {
634     StandbyMessage message;
635     DelayedSingleton<StateManagerAdapter>::GetInstance()->scrOffHalfHourTimerId_ = 0;
636     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
637     DelayedSingleton<StateManagerAdapter>::GetInstance()->scrOffHalfHourTimerId_ = 1;
638     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
639     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
640     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
641     message.action_ = EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON;
642     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
643     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->isScreenOn_);
644     message.action_ = "1234";
645     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleScrOffHalfHour(message);
646 }
647 
648 /**
649  * @tc.name: StandbyPluginUnitTest_027
650  * @tc.desc: test StateManagerAdapter of HandleOpenCloseLid.
651  * @tc.type: FUNC
652  * @tc.require:
653  */
654 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0027, TestSize.Level1)
655 {
656     StandbyMessage message;
657     message.action_ = LID_OPEN;
658     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
659     message.action_ = LID_CLOSE;
660     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
661     message.action_ = "1234";
662     DelayedSingleton<StateManagerAdapter>::GetInstance()->HandleOpenCloseLid(message);
663     EXPECT_TRUE(DelayedSingleton<StateManagerAdapter>::GetInstance()->TransitToState(0) == ERR_OK);
664 }
665 
666 /**
667  * @tc.name: StandbyPluginUnitTest_028
668  * @tc.desc: test StateManagerAdapter of EndEvalCurrentState.
669  * @tc.type: FUNC
670  * @tc.require:
671  */
672 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0028, TestSize.Level1)
673 {
674     auto evalResult = true;
675     standbyStateManager_->isEvalution_ = false;
676     EXPECT_TRUE(standbyStateManager_->EndEvalCurrentState(evalResult) == ERR_STANDBY_STATE_TIMING_SEQ_ERROR);
677     standbyStateManager_->isEvalution_ = true;
678     standbyStateManager_->EndEvalCurrentState(evalResult);
679 }
680 
681 /**
682  * @tc.name: StandbyPluginUnitTest_029
683  * @tc.desc: test StateManagerAdapter of StopEvalution.
684  * @tc.type: FUNC
685  * @tc.require:
686  */
687 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0029, TestSize.Level1)
688 {
689     standbyStateManager_->isEvalution_ = false;
690     standbyStateManager_->StopEvalution();
691     standbyStateManager_->isEvalution_ = true;
692     standbyStateManager_->StopEvalution();
693     EXPECT_TRUE(standbyStateManager_->isEvalution_ == false);
694 }
695 
696 /**
697  * @tc.name: StandbyPluginUnitTest_030
698  * @tc.desc: test ListenerManagerAdapter of StartListener.
699  * @tc.type: FUNC
700  * @tc.require:
701  */
702 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0030, TestSize.Level1)
703 {
704     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StartListener();
705     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->messageListenerList_.clear();
706     EXPECT_TRUE(DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StartListener() == ERR_OK);
707 }
708 
709 /**
710  * @tc.name: StandbyPluginUnitTest_031
711  * @tc.desc: test ListenerManagerAdapter of StopListener.
712  * @tc.type: FUNC
713  * @tc.require:
714  */
715 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0031, TestSize.Level1)
716 {
717     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StopListener();
718     DelayedSingleton<ListenerManagerAdapter>::GetInstance()->messageListenerList_.clear();
719     EXPECT_TRUE(DelayedSingleton<ListenerManagerAdapter>::GetInstance()->StopListener() == ERR_OK);
720 }
721 
722 #ifdef STANDBY_SENSORS_SENSOR_ENABLE
723 /**
724  * @tc.name: StandbyPluginUnitTest_032
725  * @tc.desc: test MotionSensorMonitor of AcceleromterCallback.
726  * @tc.type: FUNC
727  * @tc.require:
728  */
729 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0032, TestSize.Level1)
730 {
731     ConstraintEvalParam repeatedMotionParams{};
732     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
733             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
734     SensorEvent event;
735     repeatedMotionConstraint->Init();
736     GravityData data = {0, 0, 0};
737     event.sensorTypeId = SENSOR_TYPE_ID_NONE;
738     event.data = reinterpret_cast<uint8_t*>(&data);
739     repeatedMotionConstraint->AcceleromterCallback(&event);
740     EXPECT_TRUE(repeatedMotionConstraint->GetEnergy() == 0);
741     repeatedMotionConstraint->energy_ = 10000;
742     repeatedMotionConstraint->AcceleromterCallback(&event);
743     repeatedMotionConstraint->AcceleromterCallback(nullptr);
744 }
745 
746 /**
747  * @tc.name: StandbyPluginUnitTest_033
748  * @tc.desc: test MotionSensorMonitor of AcceleromterCallback.
749  * @tc.type: FUNC
750  * @tc.require:
751  */
752 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0033, TestSize.Level1)
753 {
754     ConstraintEvalParam repeatedMotionParams{};
755     auto repeatedMotionConstraint = std::make_shared<MotionSensorMonitor>(PERIODLY_TASK_DECTION_TIMEOUT,
756             PERIODLY_TASK_REST_TIMEOUT, PERIODLY_TASK_TOTAL_TIMEOUT, repeatedMotionParams);
757     SensorEvent event;
758     repeatedMotionConstraint->Init();
759     GravityData data = {0, 0, 0};
760     event.sensorTypeId = SENSOR_TYPE_ID_NONE;
761     event.data = reinterpret_cast<uint8_t*>(&data);
762     repeatedMotionConstraint->RepeatAcceleromterCallback(&event);
763     EXPECT_NE(repeatedMotionConstraint->GetEnergy(), 0);
764     repeatedMotionConstraint->energy_ = 10000;
765     repeatedMotionConstraint->RepeatAcceleromterCallback(&event);
766     repeatedMotionConstraint->RepeatAcceleromterCallback(nullptr);
767 }
768 #endif
769 
770 /**
771  * @tc.name: StandbyPluginUnitTest_034
772  * @tc.desc: test StateManagerAdapter of OnScreenOffHalfHourInner.
773  * @tc.type: FUNC
774  * @tc.require:
775  */
776 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0034, TestSize.Level1)
777 {
778     bool scrOffHalfHourCtrl = true;
779     bool repeated = true;
780     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
781     repeated = false;
782     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
783     scrOffHalfHourCtrl = false;
784     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
785     repeated = true;
786     standbyStateManager_->OnScreenOffHalfHourInner(scrOffHalfHourCtrl, repeated);
787     EXPECT_TRUE(standbyStateManager_->scrOffHalfHourCtrl_ == false);
788 
789     standbyStateManager_->curStatePtr_ = standbyStateManager_->sleepStatePtr_;
790     standbyStateManager_->preStatePtr_ = standbyStateManager_->maintStatePtr_;
791     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
792 
793     standbyStateManager_->curStatePtr_ = standbyStateManager_->maintStatePtr_;
794     standbyStateManager_->preStatePtr_ = standbyStateManager_->sleepStatePtr_;
795     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
796 
797     standbyStateManager_->curStatePtr_ = standbyStateManager_->workingStatePtr_;
798     standbyStateManager_->preStatePtr_ = standbyStateManager_->sleepStatePtr_;
799     standbyStateManager_->OnScreenOffHalfHourInner(true, false);
800 }
801 
802 /**
803  * @tc.name: StandbyPluginUnitTest_035
804  * @tc.desc: test StateManagerAdapter of ShellDump.
805  * @tc.type: FUNC
806  * @tc.require:
807  */
808 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0035, TestSize.Level1)
809 {
810     std::vector<std::string> argsInStr {};
811     std::string result;
812     int32_t dumpFirstParam = 0;
813     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
814     standbyStateManager_->ShellDump(argsInStr, result);
815     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-D");
816     standbyStateManager_->ShellDump(argsInStr, result);
817     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-E");
818     standbyStateManager_->ShellDump(argsInStr, result);
819     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "-S");
820     standbyStateManager_->ShellDump(argsInStr, result);
821     EXPECT_TRUE(argsInStr.size() != 0);
822 }
823 
824 /**
825  * @tc.name: StandbyPluginUnitTest_036
826  * @tc.desc: test StateManagerAdapter of DumpEnterSpecifiedState.
827  * @tc.type: FUNC
828  * @tc.require:
829  */
830 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0036, TestSize.Level1)
831 {
832     std::vector<std::string> argsInStr {};
833     std::string result;
834     int32_t dumpFirstParam = 0;
835     int32_t dumpThirdParam = 2;
836     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
837     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
838     argsInStr.insert(argsInStr.begin() + dumpThirdParam, "false");
839     standbyStateManager_->DumpEnterSpecifiedState(argsInStr, result);
840     argsInStr.insert(argsInStr.begin() + dumpThirdParam, "0");
841     standbyStateManager_->DumpEnterSpecifiedState(argsInStr, result);
842     EXPECT_TRUE(argsInStr.size() != 0);
843 }
844 
845 /**
846  * @tc.name: StandbyPluginUnitTest_037
847  * @tc.desc: test StateManagerAdapter of DumpActivateMotion.
848  * @tc.type: FUNC
849  * @tc.require:
850  */
851 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0037, TestSize.Level1)
852 {
853     std::vector<std::string> argsInStr {};
854     std::string result;
855     int32_t dumpFirstParam = 0;
856     int32_t dumpSecondParam = 1;
857     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
858     argsInStr.insert(argsInStr.begin() + dumpFirstParam, "0");
859     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--motion");
860     standbyStateManager_->DumpActivateMotion(argsInStr, result);
861     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--blocked");
862     standbyStateManager_->DumpActivateMotion(argsInStr, result);
863     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "--halfhour");
864     standbyStateManager_->DumpActivateMotion(argsInStr, result);
865     argsInStr.insert(argsInStr.begin() + dumpSecondParam, "0");
866     standbyStateManager_->DumpActivateMotion(argsInStr, result);
867     EXPECT_TRUE(argsInStr.size() != 0);
868 }
869 
870 #ifdef STANDBY_MULTIMODALINPUT_INPUT_ENABLE
871 /**
872  * @tc.name: StandbyPluginUnitTest_038
873  * @tc.desc: test InputManagerListener.
874  * @tc.type: FUNC
875  * @tc.require:
876  */
877 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_0038, TestSize.Level1)
878 {
879     auto inputManagerListener = std::make_shared<InputManagerListener>();
880     inputManagerListener->subscriberId_ = -1;
881     inputManagerListener->StopListener();
882     inputManagerListener->OnCallbackEvent(MMI::SwitchEvent::SWITCH_OFF);
883     inputManagerListener->OnCallbackEvent(MMI::SwitchEvent::SWITCH_ON);
884     EXPECT_TRUE(inputManagerListener->subscriberId_ <= 0);
885 }
886 #endif
887 
888 #ifdef ENABLE_BACKGROUND_TASK_MGR
889 /**
890  * @tc.name: StandbyPluginUnitTest_039
891  * @tc.desc: test BackgroundTaskListener.
892  * @tc.type: FUNC
893  * @tc.require:
894  */
895 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_039, TestSize.Level1)
896 {
897     auto backgroundTaskListener = std::make_shared<BackgroundTaskListener>();
898     backgroundTaskListener->StartListener();
899     backgroundTaskListener->StopListener();
900     backgroundTaskListener->bgTaskListenerImpl_ = nullptr;
901     backgroundTaskListener->StartListener();
902     EXPECT_NE(backgroundTaskListener->StopListener(), ERR_OK);
903 }
904 #endif
905 
906 /**
907  * @tc.name: StandbyPluginUnitTest_040
908  * @tc.desc: test ListenerManagerAdapter.
909  * @tc.type: FUNC
910  * @tc.require:
911  */
912 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_040, TestSize.Level1)
913 {
914     StandbyConfigManager::GetInstance()->strategyList_.emplace_back("RUNNING_LOCK");
915     listenerManager_->StopListener();
916     listenerManager_->UnInit();
917     listenerManager_->StartListener();
918     listenerManager_->Init();
919     StandbyConfigManager::GetInstance()->strategyList_.emplace_back("NETWORK");
920     listenerManager_->StopListener();
921     listenerManager_->UnInit();
922     listenerManager_->StartListener();
923     listenerManager_->Init();
924     EXPECT_FALSE(listenerManager_->listenerPluginMap_.empty());
925 }
926 
927 /**
928  * @tc.name: StandbyPluginUnitTest_041
929  * @tc.desc: test StartTransitNextState.
930  * @tc.type: FUNC
931  * @tc.require:
932  */
933 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_041, TestSize.Level1)
934 {
935     standbyStateManager_->sleepStatePtr_->stateManager_.reset();
936     standbyStateManager_->sleepStatePtr_->TransitToPhaseInner(0, 0);
937     standbyStateManager_->sleepStatePtr_->StartTransitNextState(standbyStateManager_->sleepStatePtr_);
938     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
939     standbyStateManager_->sleepStatePtr_->stateManager_ = standbyStateManager_;
940     standbyStateManager_->isEvalution_ = true;
941     standbyStateManager_->sleepStatePtr_->nextState_ = 0;
942     standbyStateManager_->sleepStatePtr_->StartTransitNextState(standbyStateManager_->sleepStatePtr_);
943     SleepForFC();
944     EXPECT_FALSE(standbyStateManager_->sleepStatePtr_ == nullptr);
945 }
946 
947 /**
948  * @tc.name: StandbyPluginUnitTest_042
949  * @tc.desc: test StopTimedTask.
950  * @tc.type: FUNC
951  * @tc.require:
952  */
953 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_042, TestSize.Level1)
954 {
955     standbyStateManager_->workingStatePtr_->timedTaskMap_.emplace("", -1);
956     standbyStateManager_->workingStatePtr_->StopTimedTask("");
957     standbyStateManager_->workingStatePtr_->StopTimedTask("test");
958     standbyStateManager_->workingStatePtr_->DestroyAllTimedTask();
959     SleepForFC();
960     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
961 
962     standbyStateManager_->workingStatePtr_->stateManager_.reset();
963     standbyStateManager_->workingStatePtr_->EndState();
964     standbyStateManager_->workingStatePtr_->EndEvalCurrentState(false);
965     standbyStateManager_->workingStatePtr_->IsInFinalPhase();
966     standbyStateManager_->workingStatePtr_->stateManager_ = standbyStateManager_;
967 }
968 
969 /**
970  * @tc.name: StandbyPluginUnitTest_043
971  * @tc.desc: test StopTimedTask.
972  * @tc.type: FUNC
973  * @tc.require:
974  */
975 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_043, TestSize.Level1)
976 {
977     standbyStateManager_->workingStatePtr_->timedTaskMap_.emplace("", -1);
978     standbyStateManager_->workingStatePtr_->StopTimedTask("");
979     standbyStateManager_->workingStatePtr_->StopTimedTask("test");
980     standbyStateManager_->workingStatePtr_->DestroyAllTimedTask();
981     SleepForFC();
982     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
983 }
984 
985 /**
986  * @tc.name: StandbyPluginUnitTest_044
987  * @tc.desc: test SleepState.
988  * @tc.type: FUNC
989  * @tc.require:
990  */
991 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_044, TestSize.Level1)
992 {
993     std::string result {""};
994     standbyStateManager_->sleepStatePtr_->ShellDump({"-D", "--repeat"}, result);
995     standbyStateManager_->sleepStatePtr_->ShellDump({"-S", "--r"}, result);
996     standbyStateManager_->sleepStatePtr_->ShellDump({"-S", "--repeat"}, result);
997     standbyStateManager_->sleepStatePtr_->EndEvalCurrentState(false);
998     SleepForFC();
999     EXPECT_TRUE(standbyStateManager_->workingStatePtr_->timedTaskMap_.empty());
1000 }
1001 
1002 /**
1003  * @tc.name: StandbyPluginUnitTest_045
1004  * @tc.desc: test SleepState.
1005  * @tc.type: FUNC
1006  * @tc.require:
1007  */
1008 HWTEST_F(StandbyPluginUnitTest, StandbyPluginUnitTest_045, TestSize.Level1)
1009 {
1010     standbyStateManager_->napStatePtr_->OnStateBlocked();
1011     standbyStateManager_->maintStatePtr_->EndEvalCurrentState(false);
1012     std::shared_ptr<IStateManagerAdapter> stateManager = std::make_shared<StateManagerAdapter>();
1013     stateManager->SetEvalution(true);
1014     stateManager->IsScrOffHalfHourCtrl();
1015     EXPECT_NE(standbyStateManager_, nullptr);
1016 }
1017 }  // namespace DevStandbyMgr
1018 }  // namespace OHOS
1019