• 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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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.Level1)
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_CREATE_FILE_ERR);
630     nlohmann::json json1;
631     EXPECT_EQ(DelayedSingleton<DataStorageHelper>::GetInstance()->ParseJsonValueFromFile(json1, ""),
632         ERR_BGTASK_DATA_STORAGE_ERR);
633     EXPECT_FALSE(DelayedSingleton<DataStorageHelper>::GetInstance()->CreateNodeFile(""));
634     std::string fullPath;
635     EXPECT_FALSE(DelayedSingleton<DataStorageHelper>::GetInstance()->ConvertFullPath("", fullPath));
636 }
637 
638 /**
639  * @tc.name: DataStorageHelper_002
640  * @tc.desc: test ParseFastSuspendDozeTime.
641  * @tc.type: FUNC
642  * @tc.require: issue#I99360
643  */
644 HWTEST_F(BgTaskMiscUnitTest, DataStorageHelper_002, TestSize.Level1)
645 {
646     int time = -1;
647     // 文件路径错误
648     std::string file("");
649     DelayedSingleton<DataStorageHelper>::GetInstance()->ParseFastSuspendDozeTime(file, time);
650     EXPECT_EQ(time, -1);
651     // 文件路径正确
652     file = "/etc/efficiency_manager/suspend_manager_config.json";
653     DelayedSingleton<DataStorageHelper>::GetInstance()->ParseFastSuspendDozeTime(file, time);
654     SUCCEED();
655 }
656 
657 /**
658  * @tc.name: DecisionMakerTest_003
659  * @tc.desc: test Watchdog class.
660  * @tc.type: FUNC
661  * @tc.require: issueI4QT3W issueI4QU0V
662  */
663 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_003, TestSize.Level1)
664 {
665     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
666     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
667     auto timerManager =
668         std::make_shared<TimerManager>(bgtaskService, AppExecFwk::EventRunner::Create("tdd_test_handler"));
669     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
670     auto applicationStateObserver = sptr<DecisionMaker::ApplicationStateObserver>(
671         new (std::nothrow) DecisionMaker::ApplicationStateObserver(*decisionMaker));
672 
673     AppExecFwk::AppStateData appStateData;
674     appStateData.uid = 1;
675     appStateData.bundleName = "bundleName1";
676     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND);
677     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
678     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOCUS);
679     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
680 
681     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
682     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
683     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
684     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
685     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
686     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
687     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
688     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND);
689     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
690     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_FOCUS);
691     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
692 
693     decisionMaker->pkgDelaySuspendInfoMap_.clear();
694     appStateData.state = static_cast<int32_t>(AppExecFwk::ApplicationState::APP_STATE_BACKGROUND);
695     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
696     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
697     applicationStateObserver->OnForegroundApplicationChanged(appStateData);
698     EXPECT_EQ((int32_t)decisionMaker->pkgDelaySuspendInfoMap_.size(), 1);
699 }
700 
701 /**
702  * @tc.name: DecisionMakerTest_004
703  * @tc.desc: test PauseTransientTaskTimeForInner.
704  * @tc.type: FUNC
705  * @tc.require: issueI936BL
706  */
707 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_004, TestSize.Level1)
708 {
709     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
710     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
711     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
712         AppExecFwk::EventRunner::Create("tdd_test_handler"));
713     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
714 
715     decisionMaker->pkgBgDurationMap_.clear();
716     std::string name = "bundleName1";
717     int32_t uid = 1;
718     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_BGTASK_FOREGROUND);
719 
720     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
721     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
722     decisionMaker->pkgDelaySuspendInfoMap_.clear();
723     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_BGTASK_NOREQUEST_TASK);
724 
725     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
726     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
727     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
728     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
729     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
730     EXPECT_EQ(decisionMaker->PauseTransientTaskTimeForInner(uid, name), ERR_OK);
731 }
732 
733 /**
734  * @tc.name: DecisionMakerTest_005
735  * @tc.desc: test StartTransientTaskTimeForInner.
736  * @tc.type: FUNC
737  * @tc.require: issueI936BL
738  */
739 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_005, TestSize.Level1)
740 {
741     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
742     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
743     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
744         AppExecFwk::EventRunner::Create("tdd_test_handler"));
745     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
746 
747     decisionMaker->pkgBgDurationMap_.clear();
748     std::string name = "bundleName1";
749     int32_t uid = 1;
750     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_BGTASK_FOREGROUND);
751 
752     auto keyInfo = std::make_shared<KeyInfo>("bundleName1", 1);
753     decisionMaker->pkgBgDurationMap_[keyInfo] = TimeProvider::GetCurrentTime() - ALLOW_REQUEST_TIME_BG - 1;
754     decisionMaker->pkgDelaySuspendInfoMap_.clear();
755     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_BGTASK_NOREQUEST_TASK);
756 
757     auto keyInfo1 = std::make_shared<KeyInfo>("bundleName1", 1);
758     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName1", 1, timerManager);
759     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
760     pkgDelaySuspendInfo->requestList_.push_back(delayInfo);
761     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo1] = pkgDelaySuspendInfo;
762     EXPECT_EQ(decisionMaker->StartTransientTaskTimeForInner(uid, name), ERR_OK);
763 }
764 
765 /**
766  * @tc.name: DecisionMakerTest_006
767  * @tc.desc: test GetRequestListByKey.
768  * @tc.type: FUNC
769  * @tc.require: issueIB08SV
770  */
771 HWTEST_F(BgTaskMiscUnitTest, DecisionMakerTest_006, TestSize.Level1)
772 {
773     auto deviceInfoManeger = std::make_shared<DeviceInfoManager>();
774     auto bgtaskService = sptr<BackgroundTaskMgrService>(new BackgroundTaskMgrService());
775     auto timerManager = std::make_shared<TimerManager>(bgtaskService,
776         AppExecFwk::EventRunner::Create("tdd_test_handler"));
777     auto decisionMaker = std::make_shared<DecisionMaker>(timerManager, deviceInfoManeger);
778 
779     vector<int32_t> requestIdList;
780     requestIdList = decisionMaker->GetRequestIdListByKey(nullptr);
781     EXPECT_TRUE(requestIdList.empty());
782 
783     auto keyInfo = std::make_shared<KeyInfo>("bundleName", 1, 1);
784     decisionMaker->pkgDelaySuspendInfoMap_.clear();
785     requestIdList = decisionMaker->GetRequestIdListByKey(keyInfo);
786     EXPECT_TRUE(requestIdList.empty());
787 
788     decisionMaker->pkgDelaySuspendInfoMap_.clear();
789     auto pkgDelaySuspendInfo = std::make_shared<PkgDelaySuspendInfo>("bundleName", 1, timerManager);
790     auto delayInfo1 = std::make_shared<DelaySuspendInfoEx>(1);
791     pkgDelaySuspendInfo->requestList_.push_back(delayInfo1);
792     decisionMaker->pkgDelaySuspendInfoMap_[keyInfo] = pkgDelaySuspendInfo;
793     requestIdList = decisionMaker->GetRequestIdListByKey(keyInfo);
794     EXPECT_FALSE(requestIdList.empty());
795 }
796 
797 /**
798  * @tc.name: DelaySuspendInfoEx_001
799  * @tc.desc: test DelaySuspendInfoEx.
800  * @tc.type: FUNC
801  * @tc.require: issueI4QT3W issueI4QU0V
802  */
803 HWTEST_F(BgTaskMiscUnitTest, DelaySuspendInfoEx_001, TestSize.Level1)
804 {
805     auto delayInfo = std::make_shared<DelaySuspendInfoEx>(1);
806     delayInfo->baseTime_ = 1;
807     delayInfo->StartAccounting();
808     delayInfo->baseTime_ = 0;
809     delayInfo->StopAccounting();
810     EXPECT_EQ(delayInfo->spendTime_, 0);
811 }
812 
813 /**
814  * @tc.name: SystemEventObserverTest_001
815  * @tc.desc: test SystemEventObserver class.
816  * @tc.type: FUNC
817  * @tc.require: issueI4QT3W issueI4QU0V
818  */
819 HWTEST_F(BgTaskMiscUnitTest, SystemEventObserver_001, TestSize.Level1)
820 {
821     EventFwk::MatchingSkills matchingSkills;
822     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
823     EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills);
824     auto systemEventListener = std::make_shared<SystemEventObserver>(commonEventSubscribeInfo);
825 
826     EventFwk::CommonEventData eventData = EventFwk::CommonEventData();
827     systemEventListener->OnReceiveEvent(eventData);
828 
829     auto handler = std::make_shared<OHOS::AppExecFwk::EventHandler>(nullptr);
830     systemEventListener->SetEventHandler(handler);
831     systemEventListener->OnReceiveEventContinuousTask(eventData);
832     auto bgContinuousTaskMgr = std::make_shared<BgContinuousTaskMgr>();
833     systemEventListener->SetBgContinuousTaskMgr(bgContinuousTaskMgr);
834     systemEventListener->OnReceiveEventContinuousTask(eventData);
835     AAFwk::Want want = AAFwk::Want();
836     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
837     eventData.SetWant(want);
838     systemEventListener->OnReceiveEventContinuousTask(eventData);
839     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_ADDED);
840     eventData.SetWant(want);
841     systemEventListener->OnReceiveEventContinuousTask(eventData);
842     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
843     eventData.SetWant(want);
844     systemEventListener->OnReceiveEventContinuousTask(eventData);
845 
846     EventFwk::CommonEventData eventData2 = EventFwk::CommonEventData();
847     AAFwk::Want want2 = AAFwk::Want();
848     want2.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
849     eventData2.SetWant(want2);
850     systemEventListener->OnReceiveEventEfficiencyRes(eventData2);
851     EXPECT_TRUE(true);
852 }
853 }
854 }
855