• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <functional>
17 #include <chrono>
18 #include <thread>
19 #include <gtest/gtest.h>
20 
21 #include "ability_state_data.h"
22 #include "app_state_data.h"
23 #include "app_state_observer.h"
24 #include "background_task_mgr_service.h"
25 #include "bg_continuous_task_mgr.h"
26 #include "bg_efficiency_resources_mgr.h"
27 #include "bundle_info.h"
28 #include "bundle_manager_helper.h"
29 #include "common_event_data.h"
30 #include "continuous_task_record.h"
31 #include "decision_maker.h"
32 #include "delay_suspend_info_ex.h"
33 #include "device_info_manager.h"
34 #include "event_info.h"
35 #include "event_handler.h"
36 #include "event_runner.h"
37 #include "input_manager.h"
38 #include "key_info.h"
39 #include "notification.h"
40 #include "notification_sorting_map.h"
41 #include "notification_tools.h"
42 #include "pkg_delay_suspend_info.h"
43 #include "process_data.h"
44 #include "singleton.h"
45 #include "string_wrapper.h"
46 #include "suspend_controller.h"
47 #include "task_notification_subscriber.h"
48 #include "time_provider.h"
49 #include "timer_manager.h"
50 #include "watchdog.h"
51 
52 using namespace testing::ext;
53 
54 namespace OHOS {
55 extern void SetPublishContinuousTaskNotificationFlag(int32_t flag);
56 extern void SetCancelContinuousTaskNotificationFlag(int32_t flag);
57 extern void SetGetAllActiveNotificationsFlag(int32_t flag);
58 
59 namespace BackgroundTaskMgr {
60 namespace {
61 static constexpr int32_t SLEEP_TIME = 500;
62 static constexpr int32_t BGTASKMGR_UID = 3051;
63 static constexpr int32_t TEST_NUM_ONE = 1;
64 static constexpr int32_t TEST_NUM_TWO = 2;
65 static constexpr int32_t MIN_ALLOW_QUOTA_TIME = 10 * MSEC_PER_SEC; // 10s
66 }
67 
68 class BgTaskMiscUnitTest : public testing::Test {
69 public:
70     static void SetUpTestCase();
71     static void TearDownTestCase();
72     void SetUp();
73     void TearDown();
SleepForFC()74     inline void SleepForFC()
75     {
76         std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
77     }
78 };
79 
SetUpTestCase()80 void BgTaskMiscUnitTest::SetUpTestCase() {}
81 
TearDownTestCase()82 void BgTaskMiscUnitTest::TearDownTestCase() {}
83 
SetUp()84 void BgTaskMiscUnitTest::SetUp() {}
85 
TearDown()86 void BgTaskMiscUnitTest::TearDown() {}
87 
88 /**
89  * @tc.name: AppStateObserverTest_001
90  * @tc.desc: test AppStateObserver class CheckParamValid method.
91  * @tc.type: FUNC
92  * @tc.require: issueI4QT3W issueI4QU0V issueIB08SV
93  */
94 HWTEST_F(BgTaskMiscUnitTest, AppStateObserverTest_001, TestSize.Level2)
95 {
96     sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new AppStateObserver());
97     AppExecFwk::ProcessData processData = AppExecFwk::ProcessData();
98     appStateObserver->OnProcessDied(processData);
99     appStateObserver->OnProcessDiedEfficiencyRes(processData);
100     AppExecFwk::AbilityStateData abilityStateData = AppExecFwk::AbilityStateData();
101     appStateObserver->OnAbilityStateChanged(abilityStateData);
102     AppExecFwk::AppStateData appStateDataCache = AppExecFwk::AppStateData();
103     // state is invalid
104     appStateDataCache.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_SET_COLD_START);
105     appStateObserver->OnAppCacheStateChanged(appStateDataCache);
106     // handle is null
107     appStateDataCache.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_CACHED);
108     appStateObserver->OnAppCacheStateChanged(appStateDataCache);
109     auto handler = std::make_shared<OHOS::AppExecFwk::EventHandler>(nullptr);
110     appStateObserver->SetEventHandler(handler);
111     appStateDataCache.uid = 1;
112     appStateDataCache.pid = 1;
113     appStateDataCache.bundleName = "bundleName";
114     appStateObserver->OnAppCacheStateChanged(appStateDataCache);
115     abilityStateData.abilityState = static_cast<int32_t>(AppExecFwk::AbilityState::ABILITY_STATE_TERMINATED);
116     appStateObserver->OnAbilityStateChanged(abilityStateData);
117     abilityStateData.abilityState = static_cast<int32_t>(AppExecFwk::AbilityState::ABILITY_STATE_CREATE);
118     appStateObserver->OnAbilityStateChanged(abilityStateData);
119     abilityStateData.abilityState = static_cast<int32_t>(AppExecFwk::AbilityState::ABILITY_STATE_TERMINATED);
120     appStateObserver->OnAbilityStateChanged(abilityStateData);
121     AppExecFwk::AppStateData appStateData = AppExecFwk::AppStateData();
122     appStateObserver->OnAppStopped(appStateData);
123     appStateData.uid = 1;
124     appStateData.bundleName = "bundleName";
125     appStateObserver->OnAppStopped(appStateData);
126     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_TERMINATED);
127     appStateObserver->OnAppStopped(appStateData);
128     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_END);
129     appStateObserver->OnAppStopped(appStateData);
130     EXPECT_TRUE(appStateObserver->ValidateAppStateData(appStateData));
131 }
132 
133 /**
134  * @tc.name: BundleManagerHelperTest_001
135  * @tc.desc: test BundleManagerHelper class.
136  * @tc.type: FUNC
137  * @tc.require: issueI4QT3W issueI4QU0V
138  */
139 HWTEST_F(BgTaskMiscUnitTest, BundleManagerHelperTest_001, TestSize.Level2)
140 {
141     EXPECT_EQ(BundleManagerHelper::GetInstance()->GetClientBundleName(1), "");
142     EXPECT_FALSE(BundleManagerHelper::GetInstance()->CheckPermission("permission"));
143     EXPECT_FALSE(BundleManagerHelper::GetInstance()->IsSystemApp(1LLU));
144     AppExecFwk::BundleInfo bundleInfo;
145     EXPECT_FALSE(BundleManagerHelper::GetInstance()->GetBundleInfo("bundleName",
146         AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo));
147     AppExecFwk::ApplicationInfo applicationInfo;
148     EXPECT_FALSE(BundleManagerHelper::GetInstance()->GetApplicationInfo("bundleName",
149         AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, 100, applicationInfo));
150     BundleManagerHelper::GetInstance()->OnRemoteDied(nullptr);
151     BundleManagerHelper::GetInstance()->bundleMgr_ = nullptr;
152     BundleManagerHelper::GetInstance()->OnRemoteDied(nullptr);
153     AAFwk::Want want;
154     want.SetAction("action.system.home");
155     want.AddEntity("entity.system.home");
156     want.SetElementName("", "bundleName", "", "");
157     AppExecFwk::AbilityInfo abilityInfo;
158     BundleManagerHelper::GetInstance()->QueryAbilityInfo(want,
159         AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, 0, abilityInfo);
160     BundleManagerHelper::GetInstance()->bundleMgr_ = nullptr;
161     BundleManagerHelper::GetInstance()->QueryAbilityInfo(want,
162         AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, 0, abilityInfo);
163 }
164 
165 /**
166  * @tc.name: ContinuousTaskRecordTest_001
167  * @tc.desc: test ContinuousTaskRecord class.
168  * @tc.type: FUNC
169  * @tc.require: issueI4QT3W issueI4QU0V
170  */
171 HWTEST_F(BgTaskMiscUnitTest, ContinuousTaskRecordTest_001, TestSize.Level2)
172 {
173     ContinuousTaskRecord record = ContinuousTaskRecord();
174     std::string str1 = record.ParseToJsonStr();
175     EXPECT_NE(str1, "");
176     record.wantAgentInfo_ = std::make_shared<WantAgentInfo>();
177     std::string str2 = record.ParseToJsonStr();
178     EXPECT_NE(str2, "");
179     ContinuousTaskRecord record2 = ContinuousTaskRecord();
180     nlohmann::json json2 = nlohmann::json::parse("", nullptr, false);
181     EXPECT_FALSE(record2.ParseFromJson(json2));
182     nlohmann::json json3;
183     json3["bundleName"] = "bundleName";
184     EXPECT_FALSE(record2.ParseFromJson(json3));
185     nlohmann::json json4 = nlohmann::json::parse(str1, nullptr, false);
186     ContinuousTaskRecord record3 = ContinuousTaskRecord();
187     EXPECT_TRUE(record3.ParseFromJson(json4));
188     nlohmann::json json5 = nlohmann::json::parse(str2, nullptr, false);
189     ContinuousTaskRecord record4 = ContinuousTaskRecord();
190     EXPECT_TRUE(record4.ParseFromJson(json5));
191 }
192 
193 /**
194  * @tc.name: NotificationToolsTest_001
195  * @tc.desc: test NotificationTools class.
196  * @tc.type: FUNC
197  * @tc.require: issueI4QT3W issueI4QU0V
198  */
199 HWTEST_F(BgTaskMiscUnitTest, NotificationToolsTest_001, TestSize.Level2)
200 {
201 #ifdef DISTRIBUTED_NOTIFICATION_ENABLE
202     auto taskRecord = std::make_shared<ContinuousTaskRecord>();
203     NotificationTools::GetInstance()->PublishNotification(taskRecord, "appName", "prompt", 1);
204     SetPublishContinuousTaskNotificationFlag(1);
205     EXPECT_EQ(NotificationTools::GetInstance()->PublishNotification(taskRecord, "appName", "prompt", 1),
206         ERR_BGTASK_NOTIFICATION_ERR);
207     NotificationTools::GetInstance()->CancelNotification("label", 0);
208     SetCancelContinuousTaskNotificationFlag(1);
209     EXPECT_EQ(NotificationTools::GetInstance()->CancelNotification("label", 0), ERR_BGTASK_NOTIFICATION_ERR);
210     std::set<std::string> notificationLabels;
211     NotificationTools::GetInstance()->GetAllActiveNotificationsLabels(notificationLabels);
212 
213     std::map<std::string, std::pair<std::string, std::string>> newPromptInfos;
214     newPromptInfos.emplace("label", std::make_pair<std::string, std::string>("test1", "test2"));
215     SetGetAllActiveNotificationsFlag(TEST_NUM_ONE);
216     SetPublishContinuousTaskNotificationFlag(0);
217     SetPublishContinuousTaskNotificationFlag(0);
218     NotificationTools::GetInstance()->RefreshContinuousNotifications(newPromptInfos, 0);
219     SetGetAllActiveNotificationsFlag(TEST_NUM_TWO);
220     SetPublishContinuousTaskNotificationFlag(1);
221     NotificationTools::GetInstance()->RefreshContinuousNotifications(newPromptInfos, 0);
222 #endif
223 }
224 
225 /**
226  * @tc.name: TaskNotificationSubscriber_001
227  * @tc.desc: test TaskNotificationSubscriber class.
228  * @tc.type: FUNC
229  * @tc.require: issueI4QT3W issueI4QU0V issueIBSI0L
230  */
231 HWTEST_F(BgTaskMiscUnitTest, TaskNotificationSubscriber_001, TestSize.Level2)
232 {
233     auto subscriber = std::make_shared<TaskNotificationSubscriber>();
234     subscriber->OnCanceled(nullptr, nullptr, 1);
235     auto notificationMap = std::make_shared<Notification::NotificationSortingMap>();
236     auto notificationRequest = sptr<Notification::NotificationRequest>(new Notification::NotificationRequest());
237     auto notification = std::make_shared<Notification::Notification>(notificationRequest);
238     subscriber->OnCanceled(notification, notificationMap, 1);
239     BgContinuousTaskMgr::GetInstance()->bgTaskUid_ = BGTASKMGR_UID;
240 
241     notification->request_->creatorUid_ = BGTASKMGR_UID;
242     subscriber->OnCanceled(notification, notificationMap, 1);
243     notification->request_->label_ = "label";
244     subscriber->OnCanceled(notification, notificationMap, 1);
245     notification->request_->label_ = "bgmode_1";
246     subscriber->OnCanceled(notification, notificationMap, 1);
247     notification->request_->label_ = "bgmode_1_1";
248     subscriber->OnCanceled(notification, notificationMap, 1);
249     notification->request_->label_ = "bgmode_1_1_1";
250     subscriber->OnCanceled(notification, notificationMap,
251         Notification::NotificationConstant::APP_CANCEL_REASON_DELETE);
252 
253     subscriber->OnCanceled(notification, notificationMap,
254         Notification::NotificationConstant::USER_STOPPED_REASON_DELETE);
255 
256     std::shared_ptr<AAFwk::WantParams> extraInfo = std::make_shared<AAFwk::WantParams>();
257     extraInfo->SetParam("abilityName", AAFwk::String::Box("abilityName"));
258     notification->request_->additionalParams_ = extraInfo;
259     subscriber->OnCanceled(notification, notificationMap,
260         Notification::NotificationConstant::USER_STOPPED_REASON_DELETE);
261 
262     std::shared_ptr<ContinuousTaskRecord> continuousTaskRecord = std::make_shared<ContinuousTaskRecord>();
263     BgContinuousTaskMgr::GetInstance()->continuousTaskInfosMap_["1_abilityName"] = continuousTaskRecord;
264     subscriber->OnCanceled(notification, notificationMap,
265         Notification::NotificationConstant::USER_STOPPED_REASON_DELETE);
266     EXPECT_TRUE(true);
267 }
268 
269 /**
270  * @tc.name: TaskNotificationSubscriber_002
271  * @tc.desc: test TaskNotificationSubscriber class.
272  * @tc.type: FUNC
273  * @tc.require: issueIBSI0L
274  */
275 HWTEST_F(BgTaskMiscUnitTest, TaskNotificationSubscriber_002, TestSize.Level2)
276 {
277     auto subscriber = std::make_shared<TaskNotificationSubscriber>();
278     subscriber->OnConsumed(nullptr, nullptr);
279     subscriber->OnUpdate(nullptr);
280     subscriber->OnDied();
281     subscriber->OnDoNotDisturbDateChange(nullptr);
282     subscriber->OnEnabledNotificationChanged(nullptr);
283     subscriber->OnBadgeChanged(nullptr);
284     subscriber->OnBadgeEnabledChanged(nullptr);
285     const std::vector<std::shared_ptr<Notification::Notification>> requestList;
286     auto notificationMap = std::make_shared<Notification::NotificationSortingMap>();
287     subscriber->OnBatchCanceled(requestList, notificationMap, 1);
288     subscriber->OnDisconnected();
289     EXPECT_TRUE(true);
290 }
291 
292 /**
293  * @tc.name: DecisionMakerTest_001
294  * @tc.desc: test DecisionMaker class decide method.
295  * @tc.type: FUNC
296  * @tc.require: issueI4QT3W issueI4QU0V
297  */
298 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_001, TestSize.Level2)
299 {
300     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
301     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
302     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
303         AppExecFwk::EventRunner::Create("tdd_test_handler"));
304     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
305     decisionMaker->lastRequestTime_ = TimeProvider::GetCurrentTime();
306     EXPECT_EQ(decisionMaker->Decide(nullptr, nullptr), ERR_BGTASK_NO_MEMORY);
307 
308     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
309     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
310     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
311     EXPECT_EQ(decisionMaker->Decide(keyInfo, delayInfo), ERR_BGTASK_NOT_IN_PRESET_TIME);
312     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime();
313     EXPECT_EQ(decisionMaker->Decide(keyInfo, nullptr), ERR_BGTASK_NO_MEMORY);
314 
315     auto keyInfo2 = std::make_shared<KeyInfo>("bundleName2", 2);
316     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName2", 2, timerManager);
317     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1);
318     auto delayInfo2 = std::make_shared<DelaySuspendInfoEx>(2);
319     auto delayInfo3 = std::make_shared<DelaySuspendInfoEx>(3);
320     pkgDelaySuspendInfo->requestList_.push_back(delayInfo1);
321     pkgDelaySuspendInfo->requestList_.push_back(delayInfo2);
322     pkgDelaySuspendInfo->requestList_.push_back(delayInfo3);
323     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo2] = pkgDelaySuspendInfo;
324     EXPECT_EQ(decisionMaker->Decide(keyInfo2, delayInfo1), ERR_BGTASK_EXCEEDS_THRESHOLD);
325     decisionMaker->pkgDelaySuspendInfoMap_.clear();
326     deviceInfoManeger->isScreenOn_ = true;
327     EXPECT_EQ(decisionMaker->Decide(keyInfo, delayInfo1), ERR_OK);
328     decisionMaker->pkgDelaySuspendInfoMap_.clear();
329     deviceInfoManeger->isScreenOn_ = false;
330     EXPECT_EQ(decisionMaker->Decide(keyInfo, delayInfo1), ERR_OK);
331 }
332 
333 /**
334  * @tc.name: DecisionMakerTest_002
335  * @tc.desc: test DecisionMaker class misc method.
336  * @tc.type: FUNC
337  * @tc.require: issueI4QT3W issueI4QU0V
338  */
339 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_002, TestSize.Level2)
340 {
341     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
342     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
343     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
344         AppExecFwk::EventRunner::Create("tdd_test_handler"));
345     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
346 
347     decisionMaker->RemoveRequest(nullptr, -1);
348     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
349     decisionMaker->RemoveRequest(keyInfo, -1);
350 
351     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
352     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1);
353     pkgDelaySuspendInfo->requestList_.push_back(delayInfo1);
354     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
355     decisionMaker->RemoveRequest(keyInfo, -1);
356     decisionMaker->RemoveRequest(keyInfo, 1);
357 
358     decisionMaker->pkgDelaySuspendInfoMap_.clear();
359     EXPECT_EQ(decisionMaker->GetRemainingDelayTime(nullptr, -1), -1);
360     EXPECT_EQ(decisionMaker->GetRemainingDelayTime(nullptr, -1), -1);
361     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
362     EXPECT_EQ(decisionMaker->GetRemainingDelayTime(keyInfo, -1), 0);
363 
364     EXPECT_EQ(decisionMaker->GetQuota(nullptr), -1);
365     decisionMaker->pkgDelaySuspendInfoMap_.clear();
366     EXPECT_EQ(decisionMaker->GetQuota(keyInfo), INIT_QUOTA);
367     pkgDelaySuspendInfo->quota_ = -1;
368     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
369     EXPECT_EQ(decisionMaker->GetQuota(keyInfo), 0);
370     EXPECT_FALSE(decisionMaker->IsFrontApp("pkgName", 1));
371 
372     decisionMaker->requestId_ = INT_MAX;
373     EXPECT_EQ(decisionMaker->NewDelaySuspendRequestId(), 1);
374     EXPECT_EQ(decisionMaker->NewDelaySuspendRequestId(), TEST_NUM_TWO);
375 
376     decisionMaker->lastRequestTime_ = TimeProvider::GetCurrentTime() - 1;
377     decisionMaker->ResetDayQuotaLocked();
378     decisionMaker->lastRequestTime_ = TimeProvider::GetCurrentTime() - QUOTA_UPDATE - 1;
379     decisionMaker->pkgDelaySuspendInfoMap_.clear();
380     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
381     auto keyInfo2 = std::make_shared<KeyInfo>("bundleName2", TEST_NUM_TWO);
382     auto pkgDelaySuspendInfo2 = std::make_shared<PkgDelaySuspendInfo>("bundleName2", TEST_NUM_TWO, timerManager);
383     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo2] = pkgDelaySuspendInfo2;
384     decisionMaker->ResetDayQuotaLocked();
385 
386     EventInfo eventInfo = EventInfo();
387     eventInfo.eventId_ = 0;
388     decisionMaker->OnInputEvent(eventInfo);
389     eventInfo.eventId_ = EVENT_SCREEN_ON;
390     decisionMaker->OnInputEvent(eventInfo);
391     eventInfo.eventId_ = EVENT_SCREEN_OFF;
392     decisionMaker->OnInputEvent(eventInfo);
393     eventInfo.eventId_ = EVENT_SCREEN_UNLOCK;
394     decisionMaker->OnInputEvent(eventInfo);
395     EXPECT_TRUE(true);
396 }
397 
398 /**
399  * @tc.name: DeviceInfoManagerTest_001
400  * @tc.desc: test DeviceInfoManager class.
401  * @tc.type: FUNC
402  * @tc.require: issueI4QT3W issueI4QU0V
403  */
404 HWTEST_F(BgTaskMiscUnitTest, DeviceInfoManagerTest_001, TestSize.Level2)
405 {
406     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
407     deviceInfoManeger->isDump_ = true;
408     EventInfo eventInfo = EventInfo();
409     std::vector<std::string> args;
410     args.emplace_back("test");
411     eventInfo.SetStringArgs(args);
412     deviceInfoManeger->OnInputEvent(eventInfo);
413     args.clear();
414     args.emplace_back("dump");
415     eventInfo.SetStringArgs(args);
416     deviceInfoManeger->isDump_ = false;
417     eventInfo.eventId_ = EVENT_SCREEN_ON;
418     deviceInfoManeger->OnInputEvent(eventInfo);
419     eventInfo.eventId_ = EVENT_SCREEN_OFF;
420     deviceInfoManeger->OnInputEvent(eventInfo);
421     eventInfo.eventId_ = EVENT_SCREEN_UNLOCK;
422     deviceInfoManeger->OnInputEvent(eventInfo);
423     eventInfo.eventId_ = EVENT_BATTERY_LOW;
424     deviceInfoManeger->OnInputEvent(eventInfo);
425     eventInfo.eventId_ = EVENT_BATTERY_OKAY;
426     deviceInfoManeger->OnInputEvent(eventInfo);
427     eventInfo.eventId_ = EVENT_MAX;
428     deviceInfoManeger->OnInputEvent(eventInfo);
429     EXPECT_TRUE(true);
430 }
431 
432 /**
433  * @tc.name: PkgDelaySuspendInfoTest_001
434  * @tc.desc: test PkgDelaySuspendInfo class.
435  * @tc.type: FUNC
436  * @tc.require: issueI4QT3W issueI4QU0V
437  */
438 HWTEST_F(BgTaskMiscUnitTest, PkgDelaySuspendInfoTest_001, TestSize.Level2)
439 {
440     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
441     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
442         AppExecFwk::EventRunner::Create("tdd_test_handler"));
443     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
444     pkgDelaySuspendInfo->isCounting_ = true;
445     pkgDelaySuspendInfo->baseTime_ = (int32_t)TimeProvider::GetCurrentTime() + MIN_ALLOW_QUOTA_TIME;
446     EXPECT_EQ(pkgDelaySuspendInfo->IsAllowRequest(), ERR_OK);
447     pkgDelaySuspendInfo->quota_ = 0;
448     pkgDelaySuspendInfo->baseTime_ = (int32_t)TimeProvider::GetCurrentTime();
449     EXPECT_EQ(pkgDelaySuspendInfo->IsAllowRequest(), ERR_BGTASK_TIME_INSUFFICIENT);
450     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1, 1);
451     auto delayInfo2 = std::make_shared<DelaySuspendInfoEx>(1, 2);
452     pkgDelaySuspendInfo->AddRequest(delayInfo1, 1);
453     pkgDelaySuspendInfo->AddRequest(delayInfo1, 1);
454     pkgDelaySuspendInfo->AddRequest(delayInfo2, 1);
455     EXPECT_EQ(pkgDelaySuspendInfo->IsAllowRequest(), ERR_BGTASK_EXCEEDS_THRESHOLD);
456     pkgDelaySuspendInfo->RemoveRequest(1);
457     pkgDelaySuspendInfo->RemoveRequest(1);
458     pkgDelaySuspendInfo->RemoveRequest(2);
459 
460     pkgDelaySuspendInfo->requestList_.clear();
461     EXPECT_EQ(pkgDelaySuspendInfo->GetRemainDelayTime(-1), 0);
462     delayInfo1->actualDelayTime_ = 1;
463     auto delayInfo3 = std::make_shared<DelaySuspendInfoEx>(1, 1, 1);
464     pkgDelaySuspendInfo->requestList_.emplace_back(delayInfo3);
465     EXPECT_EQ(pkgDelaySuspendInfo->GetRemainDelayTime(-1), 0);
466     EXPECT_EQ(pkgDelaySuspendInfo->GetRemainDelayTime(1), 1);
467 }
468 
469 /**
470  * @tc.name: PkgDelaySuspendInfoTest_002
471  * @tc.desc: test PkgDelaySuspendInfo class.
472  * @tc.type: FUNC
473  * @tc.require: issueI4QT3W issueI4QU0V
474  */
475 HWTEST_F(BgTaskMiscUnitTest, PkgDelaySuspendInfoTest_002, TestSize.Level2)
476 {
477     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
478     auto timerManager =
479         std::make_shared<TimerManager>(bgtaskService, AppExecFwk::EventRunner::Create("tdd_test_handler"));
480     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
481     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1, 1);
482 
483     pkgDelaySuspendInfo->requestList_.clear();
484     pkgDelaySuspendInfo->StartAccounting(1);
485     pkgDelaySuspendInfo->AddRequest(delayInfo1, 1);
486     pkgDelaySuspendInfo->StartAccounting(2);
487     pkgDelaySuspendInfo->StartAccounting(-1);
488     pkgDelaySuspendInfo->isCounting_ = false;
489     pkgDelaySuspendInfo->baseTime_ = 0;
490     pkgDelaySuspendInfo->StartAccounting(1);
491     pkgDelaySuspendInfo->isCounting_ = true;
492     pkgDelaySuspendInfo->baseTime_ = 1;
493     pkgDelaySuspendInfo->StartAccounting(1);
494 
495     pkgDelaySuspendInfo->requestList_.clear();
496     pkgDelaySuspendInfo->StopAccounting(1);
497     pkgDelaySuspendInfo->AddRequest(delayInfo1, 1);
498     pkgDelaySuspendInfo->StopAccounting(-1);
499     pkgDelaySuspendInfo->baseTime_ = 0;
500     pkgDelaySuspendInfo->StopAccounting(1);
501     pkgDelaySuspendInfo->baseTime_ = 1;
502     pkgDelaySuspendInfo->StopAccounting(1);
503     pkgDelaySuspendInfo->requestList_.clear();
504     pkgDelaySuspendInfo->StopAccountingAll();
505     pkgDelaySuspendInfo->AddRequest(delayInfo1, 1);
506     pkgDelaySuspendInfo->baseTime_ = 0;
507     pkgDelaySuspendInfo->StopAccounting(1);
508     pkgDelaySuspendInfo->baseTime_ = 1;
509     pkgDelaySuspendInfo->StopAccounting(1);
510 
511     pkgDelaySuspendInfo->isCounting_ = true;
512     pkgDelaySuspendInfo->quota_ = 0;
513     pkgDelaySuspendInfo->baseTime_ = (int32_t)TimeProvider::GetCurrentTime() - 1;
514     pkgDelaySuspendInfo->UpdateQuota(false);
515     pkgDelaySuspendInfo->quota_ = 0;
516     pkgDelaySuspendInfo->baseTime_ = (int32_t)TimeProvider::GetCurrentTime() + 1;
517     pkgDelaySuspendInfo->UpdateQuota(true);
518     EXPECT_TRUE(true);
519 }
520 
521 /**
522  * @tc.name: SuspendControllerTest_001
523  * @tc.desc: test SuspendController.
524  * @tc.type: FUNC
525  * @tc.require: issueI4QT3W issueI4QU0V
526  */
527 HWTEST_F(BgTaskMiscUnitTest, SuspendControllerTest_001, TestSize.Level2)
528 {
529     SuspendController suspendController = SuspendController();
530     auto keyInfo = std::make_shared<KeyInfo>("bundleName", 1);
531     suspendController.RequestSuspendDelay(nullptr);
532     suspendController.RequestSuspendDelay(keyInfo);
533     suspendController.CancelSuspendDelay(nullptr);
534     suspendController.CancelSuspendDelay(keyInfo);
535     EXPECT_TRUE(true);
536 }
537 
538 /**
539  * @tc.name: WatchdogTest_001
540  * @tc.desc: test Watchdog class.
541  * @tc.type: FUNC
542  * @tc.require: issueI4QT3W issueI4QU0V
543  */
544 HWTEST_F(BgTaskMiscUnitTest, WatchdogTest_001, TestSize.Level2)
545 {
546     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
547     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
548     auto timerManager =
549         std::make_shared<TimerManager>(bgtaskService, AppExecFwk::EventRunner::Create("tdd_test_handler"));
550     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
551     auto watchdog = std::make_shared<Watchdog>(bgtaskService, decisionMaker,
552         AppExecFwk::EventRunner::Create("tdd_test_handler"));
553     EXPECT_TRUE(watchdog->KillApplicationByUid("bundleName", 1, 1));
554     EXPECT_TRUE(watchdog->KillApplicationByUid("bundleName", 1, 1));
555 }
556 
557 /**
558  * @tc.name: ConfigChangeObserver_001
559  * @tc.desc: test ConfigChangeObserver class.
560  * @tc.type: FUNC
561  * @tc.require: issueI4QT3W issueI4QU0V
562  */
563 HWTEST_F(BgTaskMiscUnitTest, ConfigChangeObserver_001, TestSize.Level2)
564 {
565     // Given
566     sptr<ConfigChangeObserver> configChangeObserver1 = sptr<ConfigChangeObserver>(
567         new ConfigChangeObserver(nullptr, nullptr));
568 
569     // When & Then
570     EXPECT_FALSE(configChangeObserver1->CheckExpired());
571 }
572 
573 /**
574  * @tc.name: ConfigChangeObserver_002
575  * @tc.desc: test ConfigChangeObserver class.
576  * @tc.type: FUNC
577  * @tc.require: issueI4QT3W issueI4QU0V
578  */
579 HWTEST_F(BgTaskMiscUnitTest, ConfigChangeObserver_002, TestSize.Level2)
580 {
581     // Given
582     auto handler = std::make_shared<OHOS::AppExecFwk::EventHandler>(nullptr);
583     auto bgContinuousTaskMgr = std::make_shared<BgContinuousTaskMgr>();
584     sptr<ConfigChangeObserver> configChangeObserver2 = sptr<ConfigChangeObserver>(
585         new ConfigChangeObserver(handler, nullptr));
586 
587     // When & Then
588     EXPECT_FALSE(configChangeObserver2->CheckExpired());
589 }
590 
591 /**
592  * @tc.name: ConfigChangeObserver_003
593  * @tc.desc: test ConfigChangeObserver class.
594  * @tc.type: FUNC
595  * @tc.require: issueI4QT3W issueI4QU0V
596  */
597 HWTEST_F(BgTaskMiscUnitTest, ConfigChangeObserver_003, TestSize.Level2)
598 {
599     // Given
600     auto handler = std::make_shared<OHOS::AppExecFwk::EventHandler>(nullptr);
601     auto bgContinuousTaskMgr = std::make_shared<BgContinuousTaskMgr>();
602     sptr<ConfigChangeObserver> configChangeObserver3 = sptr<ConfigChangeObserver>(
603         new ConfigChangeObserver(handler, bgContinuousTaskMgr));
604 
605     // When & Then
606     EXPECT_TRUE(configChangeObserver3->CheckExpired());
607 
608     AppExecFwk::Configuration configuration;
609     configChangeObserver3->OnConfigurationUpdated(configuration);
610     SUCCEED();
611 }
612 
613 /**
614  * @tc.name: DataStorageHelper_001
615  * @tc.desc: test Watchdog class.
616  * @tc.type: FUNC
617  * @tc.require: issueI4QT3W issueI4QU0V
618  */
619 HWTEST_F(BgTaskMiscUnitTest, DataStorageHelper_001, TestSize.Level2)
620 {
621     std::unordered_map<std::string, std::shared_ptr<ContinuousTaskRecord>> continuousTaskInfosMap1;
622     auto continuousTaskRecord = std::make_shared<ContinuousTaskRecord>();
623     continuousTaskInfosMap1.emplace("key", continuousTaskRecord);
624     DelayedSingleton<DataStorageHelper>::GetInstance()->RefreshTaskRecord(continuousTaskInfosMap1);
625     std::unordered_map<std::string, std::shared_ptr<ContinuousTaskRecord>> continuousTaskInfosMap2;
626     EXPECT_EQ(DelayedSingleton<DataStorageHelper>::GetInstance()->RestoreTaskRecord(continuousTaskInfosMap2),
627         ERR_OK);
628     EXPECT_EQ(DelayedSingleton<DataStorageHelper>::GetInstance()->SaveJsonValueToFile("", ""),
629         ERR_BGTASK_GET_ACTUAL_FILE_ERR);
630     nlohmann::json json1;
631     EXPECT_EQ(DelayedSingleton<DataStorageHelper>::GetInstance()->ParseJsonValueFromFile(json1, ""),
632         ERR_BGTASK_DATA_STORAGE_ERR);
633     std::string fullPath;
634     EXPECT_FALSE(DelayedSingleton<DataStorageHelper>::GetInstance()->ConvertFullPath("", fullPath));
635 }
636 
637 /**
638  * @tc.name: DataStorageHelper_002
639  * @tc.desc: test ParseFastSuspendDozeTime.
640  * @tc.type: FUNC
641  * @tc.require: issue#I99360
642  */
643 HWTEST_F(BgTaskMiscUnitTest, DataStorageHelper_002, TestSize.Level2)
644 {
645     int time = -1;
646     // 文件路径错误
647     std::string file("");
648     EXPECT_FALSE(DelayedSingleton<DataStorageHelper>::GetInstance()->ParseFastSuspendDozeTime(file, time));
649     // 文件路径正确
650     file = "/etc/efficiency_manager/suspend_manager_config.json";
651     EXPECT_FALSE(DelayedSingleton<DataStorageHelper>::GetInstance()->ParseFastSuspendDozeTime(file, time));
652 }
653 
654 /**
655  * @tc.name: DecisionMakerTest_003
656  * @tc.desc: test Watchdog class.
657  * @tc.type: FUNC
658  * @tc.require: issueI4QT3W issueI4QU0V
659  */
660 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_003, TestSize.Level2)
661 {
662     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
663     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
664     auto timerManager =
665         std::make_shared<TimerManager>(bgtaskService, AppExecFwk::EventRunner::Create("tdd_test_handler"));
666     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
667     auto applicationStateObserver = sptr<DecisionMaker::ApplicationStateObserver>(
668         new (std::nothrow) DecisionMaker::ApplicationStateObserver(*decisionMaker));
669 
670     AppExecFwk::AppStateData appStateData;
671     appStateData.uid = 1;
672     appStateData.bundleName = "bundleName1";
673     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND);
674     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
675     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOCUS);
676     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
677 
678     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
679     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
680     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
681     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
682     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
683     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
684     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
685     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND);
686     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
687     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOCUS);
688     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
689 
690     decisionMaker->pkgDelaySuspendInfoMap_.clear();
691     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_BACKGROUND);
692     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
693     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
694     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
695     EXPECT_EQ((int32_t)decisionMaker->pkgDelaySuspendInfoMap_.size(), 1);
696 }
697 
698 /**
699  * @tc.name: DecisionMakerTest_004
700  * @tc.desc: test PauseTransientTaskTimeForInner.
701  * @tc.type: FUNC
702  * @tc.require: issueI936BL
703  */
704 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_004, TestSize.Level2)
705 {
706     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
707     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
708     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
709         AppExecFwk::EventRunner::Create("tdd_test_handler"));
710     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
711 
712     decisionMaker->pkgBgDurationMap_.clear();
713     std::string name = "bundleName1";
714     int32_t uid = 1;
715     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_BGTASK_FOREGROUND);
716 
717     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
718     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
719     decisionMaker->pkgDelaySuspendInfoMap_.clear();
720     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_BGTASK_NOREQUEST_TASK);
721 
722     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
723     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
724     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
725     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
726     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
727     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_OK);
728 }
729 
730 /**
731  * @tc.name: DecisionMakerTest_005
732  * @tc.desc: test StartTransientTaskTimeForInner.
733  * @tc.type: FUNC
734  * @tc.require: issueI936BL
735  */
736 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_005, TestSize.Level2)
737 {
738     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
739     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
740     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
741         AppExecFwk::EventRunner::Create("tdd_test_handler"));
742     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
743 
744     decisionMaker->pkgBgDurationMap_.clear();
745     std::string name = "bundleName1";
746     int32_t uid = 1;
747     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_BGTASK_FOREGROUND);
748 
749     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
750     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
751     decisionMaker->pkgDelaySuspendInfoMap_.clear();
752     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_BGTASK_NOREQUEST_TASK);
753 
754     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
755     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
756     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
757     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
758     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
759     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_OK);
760 }
761 
762 /**
763  * @tc.name: DecisionMakerTest_006
764  * @tc.desc: test GetRequestListByKey.
765  * @tc.type: FUNC
766  * @tc.require: issueIB08SV
767  */
768 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_006, TestSize.Level2)
769 {
770     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
771     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
772     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
773         AppExecFwk::EventRunner::Create("tdd_test_handler"));
774     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
775 
776     vector<int32_t> requestIdList;
777     requestIdList = decisionMaker->GetRequestIdListByKey(nullptr);
778     EXPECT_TRUE(requestIdList.empty());
779 
780     auto keyInfo = std::make_shared<KeyInfo>("bundleName", 1, 1);
781     decisionMaker->pkgDelaySuspendInfoMap_.clear();
782     requestIdList = decisionMaker->GetRequestIdListByKey(keyInfo);
783     EXPECT_TRUE(requestIdList.empty());
784 
785     decisionMaker->pkgDelaySuspendInfoMap_.clear();
786     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName", 1, timerManager);
787     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1);
788     pkgDelaySuspendInfo->requestList_.push_back(delayInfo1);
789     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
790     requestIdList = decisionMaker->GetRequestIdListByKey(keyInfo);
791     EXPECT_FALSE(requestIdList.empty());
792 }
793 
794 /**
795  * @tc.name: DelaySuspendInfoEx_001
796  * @tc.desc: test DelaySuspendInfoEx.
797  * @tc.type: FUNC
798  * @tc.require: issueI4QT3W issueI4QU0V
799  */
800 HWTEST_F(BgTaskMiscUnitTest, DelaySuspendInfoEx_001, TestSize.Level2)
801 {
802     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
803     delayInfo->baseTime_ = 1;
804     delayInfo->StartAccounting();
805     delayInfo->baseTime_ = 0;
806     delayInfo->StopAccounting();
807     EXPECT_EQ(delayInfo->spendTime_, 0);
808 }
809 
810 /**
811  * @tc.name: SystemEventObserverTest_001
812  * @tc.desc: test SystemEventObserver class.
813  * @tc.type: FUNC
814  * @tc.require: issueI4QT3W issueI4QU0V
815  */
816 HWTEST_F(BgTaskMiscUnitTest, SystemEventObserver_001, TestSize.Level2)
817 {
818     EventFwk::MatchingSkills matchingSkills;
819     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
820     EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills);
821     auto systemEventListener = std::make_shared<SystemEventObserver>(commonEventSubscribeInfo);
822 
823     EventFwk::CommonEventData eventData = EventFwk::CommonEventData();
824     systemEventListener->OnReceiveEvent(eventData);
825 
826     auto handler = std::make_shared<OHOS::AppExecFwk::EventHandler>(nullptr);
827     systemEventListener->SetEventHandler(handler);
828     systemEventListener->OnReceiveEventContinuousTask(eventData);
829     auto bgContinuousTaskMgr = std::make_shared<BgContinuousTaskMgr>();
830     systemEventListener->SetBgContinuousTaskMgr(bgContinuousTaskMgr);
831     systemEventListener->OnReceiveEventContinuousTask(eventData);
832     AAFwk::Want want = AAFwk::Want();
833     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
834     eventData.SetWant(want);
835     systemEventListener->OnReceiveEventContinuousTask(eventData);
836     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_ADDED);
837     eventData.SetWant(want);
838     systemEventListener->OnReceiveEventContinuousTask(eventData);
839     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
840     eventData.SetWant(want);
841     systemEventListener->OnReceiveEventContinuousTask(eventData);
842 
843     EventFwk::CommonEventData eventData2 = EventFwk::CommonEventData();
844     AAFwk::Want want2 = AAFwk::Want();
845     want2.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
846     eventData2.SetWant(want2);
847     systemEventListener->OnReceiveEventEfficiencyRes(eventData2);
848     EXPECT_TRUE(true);
849 }
850 }
851 }
852