• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 <gtest/gtest.h>
17 
18 #define private public
19 #include "account_observer.h"
20 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
21 #include "hisysevent_observer.h"
22 #ifdef MMI_ENABLE
23 #include "mmi_observer.h"
24 #endif
25 #endif
26 #include "fold_display_mode_observer.h"
27 #include "device_movement_observer.h"
28 #include "sched_telephony_observer.h"
29 #include "audio_observer.h"
30 #include "connection_subscriber.h"
31 #include "if_system_ability_manager.h"
32 #include "system_ability_definition.h"
33 #include "iservice_registry.h"
34 #include "observer_manager.h"
35 #include "download_upload_observer.h"
36 #include "app_state_observer.h"
37 #include "window_state_observer.h"
38 #include "background_task_observer.h"
39 #include "app_startup_scene_rec.h"
40 
41 namespace OHOS {
42 namespace ResourceSchedule {
43 namespace {
44 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
45     static const int32_t TEST_UID = 0;
46     static const int32_t TEST_PID = 1000;
47     static const int32_t TEST_INSTANCE_ID = 123456;
48     static const int32_t JSON_FORMAT = 4;
49 #ifdef MMI_ENABLE
50     static const int32_t MMI_TEST_UID = 0;
51     static const int32_t MMI_TEST_PID = 1000;
52 #endif
53 #endif
54 }
55 class ObserverEventTest : public testing::Test {
56 public:
57     static void SetUpTestCase();
58     static void TearDownTestCase();
SetUp()59     void SetUp() {}
TearDown()60     void TearDown() {}
61 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
62     static std::shared_ptr<HiSysEventObserver> hisysEventObserver_;
63 #ifdef MMI_ENABLE
64     static std::shared_ptr<MmiObserver> mmiObserver_;
65 #endif
66 #endif
67     static std::shared_ptr<ConnectionSubscriber> connectionSubscriber_;
68 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
69     static std::shared_ptr<DeviceMovementObserver> deviceMovementObserver_;
70 #endif
71 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
72     static std::shared_ptr<SchedTelephonyObserver> schedTelephonyObserver_;
73 #endif
74 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
75     static std::shared_ptr<AudioObserver> audioObserver_;
76 #endif
77     static std::shared_ptr<FoldDisplayModeObserver> foldDisplayModeObserver_;
78     static std::shared_ptr<FoldDisplayOrientationObserver> foldDisplayOrientationObserver_;
79 };
80 
81 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
82 std::shared_ptr<HiSysEventObserver> ObserverEventTest::hisysEventObserver_ = nullptr;
83 #ifdef MMI_ENABLE
84 std::shared_ptr<MmiObserver> ObserverEventTest::mmiObserver_ = nullptr;
85 #endif
86 #endif
87 std::shared_ptr<FoldDisplayModeObserver> ObserverEventTest::foldDisplayModeObserver_ = nullptr;
88 std::shared_ptr<FoldDisplayOrientationObserver> ObserverEventTest::foldDisplayOrientationObserver_ = nullptr;
89 std::shared_ptr<ConnectionSubscriber> ObserverEventTest::connectionSubscriber_ = nullptr;
90 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
91     std::shared_ptr<DeviceMovementObserver> ObserverEventTest::deviceMovementObserver_ = nullptr;
92 #endif
93 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
94     std::shared_ptr<SchedTelephonyObserver> ObserverEventTest::schedTelephonyObserver_ = nullptr;
95 #endif
96 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
97     std::shared_ptr<AudioObserver> ObserverEventTest::audioObserver_ = nullptr;
98 #endif
99 
SetUpTestCase()100 void ObserverEventTest::SetUpTestCase()
101 {
102 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
103     hisysEventObserver_ = std::make_shared<HiSysEventObserver>();
104 #ifdef MMI_ENABLE
105     mmiObserver_ = std::make_shared<MmiObserver>();
106 #endif
107 #endif
108     connectionSubscriber_ = std::make_shared<ConnectionSubscriber>();
109     foldDisplayModeObserver_ = std::make_shared<FoldDisplayModeObserver>();
110     foldDisplayOrientationObserver_ = std::make_shared<FoldDisplayOrientationObserver>();
111 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
112     deviceMovementObserver_ = std::make_shared<DeviceMovementObserver>();
113 #endif
114 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
115     schedTelephonyObserver_ = std::make_shared<SchedTelephonyObserver>();
116 #endif
117 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
118     audioObserver_ = std::make_shared<AudioObserver>();
119 #endif
120 }
121 
TearDownTestCase()122 void ObserverEventTest::TearDownTestCase()
123 {
124 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
125     hisysEventObserver_ = nullptr;
126 #ifdef MMI_ENABLE
127     mmiObserver_ = nullptr;
128 #endif
129 #endif
130     connectionSubscriber_ = nullptr;
131     foldDisplayModeObserver_ = nullptr;
132 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
133     deviceMovementObserver_ = nullptr;
134 #endif
135 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
136     schedTelephonyObserver_ = nullptr;
137 #endif
138 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
139     audioObserver_ = nullptr;
140 #endif
141 }
142 
143 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
144 /**
145  * @tc.name: hisysEventAvCodecEvent_001
146  * @tc.desc: test multimedia encoding and decoding event processing
147  * @tc.type: FUNC
148  * @tc.require: issueI8IDAO
149  */
150 HWTEST_F(ObserverEventTest, hisysEventAvCodecEvent_001, testing::ext::TestSize.Level1)
151 {
152     nlohmann::json sysEvent;
153     std::string eventName = "INVAILD";
154     sysEvent["name_"] = eventName;
155 
156     // incorrect uid keyword
157     sysEvent["UID"] = TEST_UID;
158     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
159     EXPECT_NE(hisysEventObserver_, nullptr);
160 
161     // incorrect pid keyword
162     sysEvent["CLIENT_UID"] = TEST_UID;
163     sysEvent["PID"] = TEST_PID;
164     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
165     EXPECT_NE(hisysEventObserver_, nullptr);
166 
167     // incorrect instance id keyword
168     sysEvent["CLIENT_UID"] = TEST_UID;
169     sysEvent["CLIENT_PID"] = TEST_PID;
170     sysEvent["INSTANCE_ID"] = TEST_INSTANCE_ID;
171     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
172     EXPECT_NE(hisysEventObserver_, nullptr);
173 
174     // codec start info state scene
175     sysEvent["CODEC_INSTANCE_ID"] = TEST_INSTANCE_ID;
176     eventName = "CODEC_START_INFO";
177     sysEvent["name_"] = eventName;
178     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
179     EXPECT_NE(hisysEventObserver_, nullptr);
180 
181     // codec stop info state scene
182     eventName = "CODEC_STOP_INFO";
183     sysEvent["name_"] = eventName;
184     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
185     EXPECT_NE(hisysEventObserver_, nullptr);
186 
187     // codec fault state scene
188     eventName = "FAULT";
189     sysEvent["name_"] = eventName;
190     hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
191     EXPECT_NE(hisysEventObserver_, nullptr);
192 }
193 
194 /**
195  * @tc.name: hisysEventRunningLockEvent_001
196  * @tc.desc: test running lock event processing
197  * @tc.type: FUNC
198  * @tc.require: issueI8IDAO
199  */
200 HWTEST_F(ObserverEventTest, hisysEventRunningLockEvent_001, testing::ext::TestSize.Level1)
201 {
202     nlohmann::json sysEvent;
203     std::string eventName = "INVAILD";
204     // incorrect uid keyword
205     sysEvent["uid"] = TEST_UID;
206     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
207     EXPECT_NE(hisysEventObserver_, nullptr);
208 
209     // incorrect pid keyword
210     sysEvent["UID"] = TEST_UID;
211     sysEvent["pid"] = TEST_PID;
212     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
213     EXPECT_NE(hisysEventObserver_, nullptr);
214 
215     // incorrect type keyword
216     sysEvent["PID"] = TEST_PID;
217     sysEvent["type"] = 0;
218     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
219     EXPECT_NE(hisysEventObserver_, nullptr);
220 
221     // incorrect state keyword
222     sysEvent["TYPE"] = 0;
223     sysEvent["state"] = 0;
224     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
225     EXPECT_NE(hisysEventObserver_, nullptr);
226 
227     // running lock state disable
228     sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_DISABLE;
229     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
230     EXPECT_NE(hisysEventObserver_, nullptr);
231 
232     // running lock state enable
233     sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_ENABLE;
234     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
235     EXPECT_NE(hisysEventObserver_, nullptr);
236 
237     // running lock state proxied
238     sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_PROXIED;
239     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
240     sysEvent["STATE"] = -1;
241     hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
242     EXPECT_NE(hisysEventObserver_, nullptr);
243 }
244 
245 /**
246  * @tc.name: hisysEventCameraEvent_001
247  * @tc.desc: test hisysevent camera event processing
248  * @tc.type: FUNC
249  * @tc.require: issueI8IDAO
250  */
251 HWTEST_F(ObserverEventTest, hisysEventCameraEvent_001, testing::ext::TestSize.Level1)
252 {
253     nlohmann::json sysEvent;
254     std::string eventName = "INVAILD";
255     // incorrect uid keyword
256     sysEvent["uid"] = TEST_UID;
257     hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
258     EXPECT_NE(hisysEventObserver_, nullptr);
259 
260     // incorrect pid keyword
261     sysEvent["UID"] = TEST_UID;
262     sysEvent["pid"] = TEST_PID;
263     hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
264     EXPECT_NE(hisysEventObserver_, nullptr);
265 
266     // eventName test
267     sysEvent["PID"] = TEST_PID;
268     eventName = "CAMERA_CONNECT";
269     hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
270     EXPECT_NE(hisysEventObserver_, nullptr);
271 
272     eventName = "CAMERA_DISCONNECT";
273     hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
274     EXPECT_NE(hisysEventObserver_, nullptr);
275 }
276 
277 /**
278  * @tc.name: hisysEventWifiEvent_001
279  * @tc.desc: test hisysevent wifi event processing
280  * @tc.type: FUNC
281  * @tc.require: issueI8IDAO
282  */
283 HWTEST_F(ObserverEventTest, hisysEventWifiEvent_001, testing::ext::TestSize.Level1)
284 {
285     nlohmann::json sysEvent;
286     std::string eventName = "INVAILD";
287     // incorrect uid keyword
288     sysEvent["uid"] = TEST_UID;
289     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
290     EXPECT_NE(hisysEventObserver_, nullptr);
291 
292     // incorrect pid keyword
293     sysEvent["uid_"] = TEST_UID;
294     sysEvent["pid"] = TEST_PID;
295     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
296     EXPECT_NE(hisysEventObserver_, nullptr);
297 
298     // incorrect eventname
299     sysEvent["pid_"] = TEST_PID;
300     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
301     EXPECT_NE(hisysEventObserver_, nullptr);
302 
303     // wifi connection state: connected
304     eventName = "WIFI_CONNECTION";
305     sysEvent["TYPE"] = WifiState::CONNECTED;
306     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
307     EXPECT_NE(hisysEventObserver_, nullptr);
308 
309     // wifi connection state: disconnected
310     sysEvent["TYPE"] = WifiState::DISCONNECTED;
311     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
312     EXPECT_NE(hisysEventObserver_, nullptr);
313 
314     // wifi scan state
315     eventName = "WIFI_SCAN";
316     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
317     sysEvent["TYPE"] = -1;
318     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
319     eventName = "test";
320     hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
321     EXPECT_NE(hisysEventObserver_, nullptr);
322 }
323 
324 /**
325  * @tc.name: processHiSysEvent_001
326  * @tc.desc: the hisysevent onevent test
327  * @tc.type: FUNC
328  * @tc.require: issueI8IDAO
329  */
330 HWTEST_F(ObserverEventTest, processHiSysEvent_001, testing::ext::TestSize.Level1)
331 {
332     hisysEventObserver_->OnEvent(nullptr);
333     hisysEventObserver_->OnServiceDied();
334     nlohmann::json sysEvent;
335     sysEvent["domain_"] = "RUNNINGLOCK";
336     sysEvent["name_"] = "RUNNINGLOCK";
337     sysEvent["UID"] = TEST_UID;
338     sysEvent["PID"] = TEST_PID;
339     hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
340         sysEvent.dump(JSON_FORMAT)));
341     EXPECT_NE(hisysEventObserver_, nullptr);
342 }
343 
344 /**
345  * @tc.name: processHiSysEvent_002
346  * @tc.desc: the process hisysevent test
347  * @tc.type: FUNC
348  * @tc.require: issueI8IDAO
349  */
350 HWTEST_F(ObserverEventTest, processHiSysEvent_002, testing::ext::TestSize.Level1)
351 {
352     nlohmann::json sysEvent;
353     std::string eventName = "INVAILD";
354     sysEvent["domain_"] = "AV_CODEC";
355     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
356     EXPECT_NE(hisysEventObserver_, nullptr);
357 
358     sysEvent["domain_"] = "INVAILD";
359     eventName = "RUNNINGLOCK";
360     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
361     EXPECT_NE(hisysEventObserver_, nullptr);
362 }
363 
364 /**
365  * @tc.name: processHiSysEvent_003
366  * @tc.desc: the process hisysevent test
367  * @tc.type: FUNC
368  * @tc.require: issuesIAJZVI
369  */
370 HWTEST_F(ObserverEventTest, processHiSysEvent_003, testing::ext::TestSize.Level1)
371 {
372     nlohmann::json sysEvent;
373     sysEvent["domain_"] = "INVAILD";
374     std::string eventName = "CAMERA_CONNECT";
375     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
376     eventName = "CAMERA_DISCONNECT";
377     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
378     eventName = "WIFI_CONNECTION";
379     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
380     eventName = "WIFI_SCAN";
381     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
382     eventName = "PLAYER_STATE";
383     hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
384     EXPECT_NE(hisysEventObserver_, nullptr);
385 }
386 
387 #ifdef MMI_ENABLE
388 /**
389  * @tc.name: mmiObserverEvent_001
390  * @tc.desc: test multimodal input sync bundleName interface
391  * @tc.type: FUNC
392  * @tc.require: issueI8IDAO
393  */
394 HWTEST_F(ObserverEventTest, mmiObserverEvent_001, testing::ext::TestSize.Level1)
395 {
396     int32_t pid = MMI_TEST_PID;
397     int32_t uid = MMI_TEST_UID;
398     std::string bundleName;
399     int32_t status = 0;
400     // the scene of bundleName is null
401     mmiObserver_->SyncBundleName(pid, uid, bundleName, status);
402     EXPECT_NE(mmiObserver_, nullptr);
403 
404     // the scene of bundleName is not null
405     bundleName = "inputmethod";
406     mmiObserver_->SyncBundleName(pid, uid, bundleName, status);
407     EXPECT_NE(mmiObserver_, nullptr);
408 }
409 #endif
410 #endif
411 
412 /**
413  * @tc.name: deviceMovementObserverEvent_001
414  * @tc.desc: test multimodal input sync bundleName interface
415  * @tc.type: FUNC
416  * @tc.require: issueI8VZVN
417  */
418 HWTEST_F(ObserverEventTest, deviceMovementObserverEvent_001, testing::ext::TestSize.Level1)
419 {
420 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
421     // data is null
422     int32_t code = -1;
423     MessageParcel data;
424     MessageParcel reply;
425     MessageOption option;
426     int32_t testRequest = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
427     EXPECT_EQ(testRequest, -1);
428 
429     //code is MOVEMENT_CHANGE
430     data.WriteInterfaceToken(DeviceMovementObserver::GetDescriptor());
431     code = static_cast<int32_t>(Msdp::ImovementCallback::MOVEMENT_CHANGE);
432     int32_t t1 = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
433     EXPECT_EQ(t1, 0);
434 
435     //code is not MOVEMENT_CHANGE
436     code = -1;
437     int32_t t2 = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
438     EXPECT_EQ(t2, -1);
439 #endif
440 }
441 
442 /**
443  * @tc.name: schedTelephonyObserverEvent_001
444  * @tc.desc: test multimodal input sync bundleName interface
445  * @tc.type: FUNC
446  * @tc.require: issueI8VZVN
447  */
448 HWTEST_F(ObserverEventTest, schedTelephonyObserverEvent_001, testing::ext::TestSize.Level1)
449 {
450 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
451     int32_t slotId = 0;
452     int32_t callState = 0;
453     std::u16string phoneNumber;
454     schedTelephonyObserver_->OnCallStateUpdated(slotId, callState, phoneNumber);
455     EXPECT_TRUE(schedTelephonyObserver_ != nullptr);
456 #endif
457 }
458 
459 /**
460  * @tc.name: connectionSubscriberEvent_001
461  * @tc.desc: test multimodal input sync bundleName interface
462  * @tc.type: FUNC
463  * @tc.require: issueI8VZVN
464  */
465 HWTEST_F(ObserverEventTest, connectionSubscriberEvent_001, testing::ext::TestSize.Level1)
466 {
467     //test the interface
468     AbilityRuntime::ConnectionData data;
469     AbilityRuntime::DlpStateData data1;
470     nlohmann::json payload;
471     connectionSubscriber_->MarshallingConnectionData(data, payload);
472     SUCCEED();
473     connectionSubscriber_->OnExtensionConnected(data);
474     SUCCEED();
475     connectionSubscriber_->OnExtensionDisconnected(data);
476     SUCCEED();
477     connectionSubscriber_->OnExtensionSuspended(data);
478     connectionSubscriber_->OnExtensionResumed(data);
479     connectionSubscriber_->MarshallingDlpStateData(data1, payload);
480     SUCCEED();
481     connectionSubscriber_->OnDlpAbilityOpened(data1);
482     SUCCEED();
483     connectionSubscriber_->OnDlpAbilityClosed(data1);
484     SUCCEED();
485     connectionSubscriber_->OnServiceDied();
486     EXPECT_TRUE(connectionSubscriber_ != nullptr);
487 }
488 
489 /**
490  * @tc.name: audioObserverObserverEvent_001
491  * @tc.desc: test multimodal input sync bundleName interface
492  * @tc.type: FUNC
493  * @tc.require: issueI8VZVN
494  */
495 HWTEST_F(ObserverEventTest, audioObserverEvent_001, testing::ext::TestSize.Level1)
496 {
497 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
498     std::shared_ptr<AudioStandard::AudioRendererChangeInfo> audioRendererChangeInfo =
499         std::make_shared<AudioStandard::AudioRendererChangeInfo>();
500     nlohmann::json payload;
501     audioObserver_->MarshallingAudioRendererChangeInfo(audioRendererChangeInfo, payload);
502     SUCCEED();
503     std::vector<std::shared_ptr<AudioStandard::AudioRendererChangeInfo>> audioRenderVector;
504     audioRenderVector.emplace_back(std::move(audioRendererChangeInfo));
505     audioObserver_->OnRendererStateChange(audioRenderVector);
506     SUCCEED();
507 
508     //ringerMode equals mode_
509     AudioStandard::AudioRingerMode ringerMode = AudioStandard::AudioRingerMode::RINGER_MODE_NORMAL;
510     audioObserver_->OnRingerModeUpdated(ringerMode);
511     SUCCEED();
512     //ringerMode is not mode_
513     audioObserver_->OnRingerModeUpdated(ringerMode);
514     SUCCEED();
515 
516     //test the interface of OnVolumeKeyEvent
517     AudioStandard::VolumeEvent volumeEvent;
518     audioObserver_->OnVolumeKeyEvent(volumeEvent);
519     SUCCEED();
520 
521     //test the interface of OnAudioSceneChange
522     AudioStandard::AudioScene audioScene = AudioStandard::AudioScene::AUDIO_SCENE_DEFAULT;
523     audioObserver_->OnAudioSceneChange(audioScene);
524     SUCCEED();
525 
526     // test the interface of OnPreferredOutputDeviceUpdated
527     std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> descs;
528     audioObserver_->OnPreferredOutputDeviceUpdated(descs);
529     EXPECT_TRUE(audioObserver_ != nullptr);
530     audioObserver_->processRenderStateMap_.clear();
531 #endif
532 }
533 
534 /**
535  * @tc.name: audioObserverObserverEvent_002
536  * @tc.desc: test HandleInnerAudioStateChange
537  * @tc.type: FUNC
538  * @tc.require: issueI8VZVN
539  */
540 HWTEST_F(ObserverEventTest, audioObserverEvent_002, testing::ext::TestSize.Level1)
541 {
542 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
543     std::shared_ptr<AudioStandard::AudioRendererChangeInfo> audioRendererChangeInfo = nullptr;
544     nlohmann::json payload;
545     std::unordered_set<int32_t> newRunningPid;
546     std::unordered_set<int32_t> newStopSessionPid;
547     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
548     audioRendererChangeInfo = std::make_shared<AudioStandard::AudioRendererChangeInfo>();
549     audioRendererChangeInfo->clientPid = 1;
550     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_INVALID;
551     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
552     EXPECT_EQ(newRunningPid.size(), 0);
553     newRunningPid.clear();
554     newStopSessionPid.clear();
555     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_RUNNING;
556     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
557     EXPECT_EQ(newRunningPid.size(), 1);
558     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
559     newRunningPid.clear();
560     newStopSessionPid.clear();
561     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_STOPPED;
562     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
563     EXPECT_EQ(newStopSessionPid.size(), 1);
564     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
565     newRunningPid.clear();
566     newStopSessionPid.clear();
567     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_RELEASED;
568     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
569     EXPECT_EQ(newStopSessionPid.size(), 1);
570     newRunningPid.clear();
571     newStopSessionPid.clear();
572     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_PAUSED;
573     audioObserver_->HandleInnerAudioStateChange(audioRendererChangeInfo, newRunningPid, newStopSessionPid);
574     EXPECT_EQ(newStopSessionPid.size(), 1);
575     newRunningPid.clear();
576     newStopSessionPid.clear();
577     audioObserver_->processRenderStateMap_.clear();
578 #endif
579 }
580 
581 /**
582  * @tc.name: audioObserverObserverEvent_003
583  * @tc.desc: test ProcessRunningSessionState
584  * @tc.type: FUNC
585  * @tc.require: issueI8VZVN
586  */
587 HWTEST_F(ObserverEventTest, audioObserverEvent_003, testing::ext::TestSize.Level1)
588 {
589 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
590     std::shared_ptr<AudioStandard::AudioRendererChangeInfo> audioRendererChangeInfo = nullptr;
591     std::unordered_set<int32_t> newRunningPid;
592     audioObserver_->ProcessRunningSessionState(audioRendererChangeInfo, newRunningPid);
593     audioRendererChangeInfo = std::make_shared<AudioStandard::AudioRendererChangeInfo>();
594     audioRendererChangeInfo->clientPid = 1;
595     audioRendererChangeInfo->rendererState = AudioStandard::RendererState::RENDERER_RUNNING;
596     audioObserver_->ProcessRunningSessionState(audioRendererChangeInfo, newRunningPid);
597     audioObserver_->ProcessRunningSessionState(audioRendererChangeInfo, newRunningPid);
598     EXPECT_EQ(newRunningPid.size(), 1);
599     audioObserver_->processRenderStateMap_.clear();
600 #endif
601 }
602 
603 /**
604  * @tc.name: audioObserverObserverEvent_004
605  * @tc.desc: test ProcessStopSessionState
606  * @tc.type: FUNC
607  * @tc.require: issueI8VZVN
608  */
609 HWTEST_F(ObserverEventTest, audioObserverEvent_004, testing::ext::TestSize.Level1)
610 {
611 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
612     std::shared_ptr<AudioStandard::AudioRendererChangeInfo> audioRendererChangeInfo = nullptr;
613     std::unordered_set<int32_t> newRunningPid;
614     std::unordered_set<int32_t> newStopSessionPid;
615     audioObserver_->ProcessStopSessionState(audioRendererChangeInfo, newStopSessionPid);
616     audioRendererChangeInfo = std::make_shared<AudioStandard::AudioRendererChangeInfo>();
617     audioRendererChangeInfo->clientPid = 1;
618     audioObserver_->ProcessStopSessionState(audioRendererChangeInfo, newStopSessionPid);
619     EXPECT_EQ(newStopSessionPid.size(), 1);
620     newStopSessionPid.clear();
621     audioObserver_->ProcessRunningSessionState(audioRendererChangeInfo, newRunningPid);
622     audioObserver_->ProcessStopSessionState(audioRendererChangeInfo, newStopSessionPid);
623     EXPECT_EQ(newStopSessionPid.size(), 1);
624     audioObserver_->processRenderStateMap_.clear();
625 #endif
626 }
627 
628 /**
629  * @tc.name: audioObserverObserverEvent_005
630  * @tc.desc: test HandleStartAudioStateEvent
631  * @tc.type: FUNC
632  * @tc.require: issueI8VZVN
633  */
634 HWTEST_F(ObserverEventTest, audioObserverEvent_005, testing::ext::TestSize.Level1)
635 {
636 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
637     std::unordered_set<int32_t> newRunningPid;
638     int32_t pid = 0;
639     newRunningPid.insert(pid);
640     audioObserver_->HandleStartAudioStateEvent(newRunningPid);
641     ProcessRenderState processRenderState;
642     audioObserver_->processRenderStateMap_[pid] = processRenderState;
643     audioObserver_->HandleStartAudioStateEvent(newRunningPid);
644     int32_t SessionId = 0;
645     processRenderState.renderRunningSessionSet.insert(SessionId);
646     audioObserver_->processRenderStateMap_[pid] = processRenderState;
647     audioObserver_->HandleStartAudioStateEvent(newRunningPid);
648     EXPECT_TRUE(audioObserver_->processRenderStateMap_.find(pid) != audioObserver_->processRenderStateMap_.end());
649     audioObserver_->processRenderStateMap_.clear();
650 #endif
651 }
652 
653 /**
654  * @tc.name: audioObserverObserverEvent_006
655  * @tc.desc: test HandleStopAudioStateEvent
656  * @tc.type: FUNC
657  * @tc.require: issueI8VZVN
658  */
659 HWTEST_F(ObserverEventTest, audioObserverEvent_006, testing::ext::TestSize.Level1)
660 {
661 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
662     int32_t pid = 0;
663     std::unordered_set<int32_t> newStopSessionPid;
664     newStopSessionPid.insert(pid);
665     audioObserver_->HandleStopAudioStateEvent(newStopSessionPid);
666     ProcessRenderState processRenderState;
667     int32_t SessionId = 0;
668     processRenderState.renderRunningSessionSet.insert(SessionId);
669     audioObserver_->processRenderStateMap_[pid] = processRenderState;
670     audioObserver_->HandleStopAudioStateEvent(newStopSessionPid);
671     processRenderState.renderRunningSessionSet.clear();
672     audioObserver_->processRenderStateMap_[pid] = processRenderState;
673     audioObserver_->HandleStopAudioStateEvent(newStopSessionPid);
674     EXPECT_TRUE(audioObserver_->processRenderStateMap_.find(pid) == audioObserver_->processRenderStateMap_.end());
675     audioObserver_->processRenderStateMap_.clear();
676 #endif
677 }
678 
679 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
680 #ifdef MMI_ENABLE
681 /**
682  * @tc.name: mmiObserverEvent_002
683  * @tc.desc: test multimodal input get mmi status status interface
684  * @tc.type: FUNC
685  * @tc.require: issueI8ZIVH
686  */
687 HWTEST_F(ObserverEventTest, mmiObserverEvent_002, testing::ext::TestSize.Level1)
688 {
689     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
690     EXPECT_NE(samgr, nullptr);
691     auto remoteObj = samgr->GetSystemAbility(MULTIMODAL_INPUT_SERVICE_ID);
692     auto instance = ObserverManager::GetInstance();
693     if (instance) {
694         instance->GetAllMmiStatusData();
695     }
696     SUCCEED();
697 }
698 #endif
699 #endif
700 
701 #ifdef RESOURCE_REQUEST_REQUEST
702 /**
703  * @tc.name: foldDisplayModeObserver_001
704  * @tc.desc: test fold display mode status interface
705  * @tc.type: FUNC
706  * @tc.require: issueI8ZIVH
707  */
708 HWTEST_F(ObserverEventTest, foldDisplayModeObserver_001, testing::ext::TestSize.Level1)
709 {
710     const std::string DISPLAY_MODE_MAIN = "displayMain";
711     foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::MAIN);
712     EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_MAIN);
713 
714     const std::string DISPLAY_MODE_FULL = "displayFull";
715     foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::FULL);
716     EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_FULL);
717 
718     const std::string DISPLAY_MODE_SUB = "displaySub";
719     foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::SUB);
720     EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_SUB);
721 
722     const std::string DISPLAY_MODE_UNKOWN = "displayUnknown";
723     foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::UNKNOWN);
724     EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_UNKOWN);
725 }
726 
727 /**
728  * @tc.name: downLoadUploadObserver_001
729  * @tc.desc: Test downLoad Upload Observer
730  * @tc.type: FUNC
731  * @tc.require: issuesI9BU37
732  */
733 HWTEST_F(ObserverEventTest, downLoadUploadObserver_001, testing::ext::TestSize.Level1)
734 {
735     std::shared_ptr<DownLoadUploadObserver> downLoadUploadObserver_ =
736         std::make_shared<DownLoadUploadObserver>();
737     downLoadUploadObserver_->OnRunningTaskCountUpdate(1);
738     EXPECT_TRUE(downLoadUploadObserver_->isReportScene);
739     downLoadUploadObserver_->OnRunningTaskCountUpdate(0);
740     EXPECT_FALSE(downLoadUploadObserver_->isReportScene);
741     downLoadUploadObserver_->OnRunningTaskCountUpdate(-1);
742     EXPECT_FALSE(downLoadUploadObserver_->isReportScene);
743     downLoadUploadObserver_ = nullptr;
744 }
745 #endif
746 /**
747  * @tc.name: accountObserver_001
748  * @tc.desc: test account observer
749  * @tc.type: FUNC
750  * @tc.require: issuesI9SSQY
751  */
752 HWTEST_F(ObserverEventTest, accountObserver_001, testing::ext::TestSize.Level1)
753 {
754     AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo;
755     osAccountSubscribeInfo.SetOsAccountSubscribeType(AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVATING);
756     osAccountSubscribeInfo.SetName("ResschdeAccountActivatingSubscriberTest");
757     auto accountObserver = std::make_shared<AccountObserver>(osAccountSubscribeInfo);
758     accountObserver->OnAccountsChanged(200);
759     SUCCEED();
760     accountObserver->OnAccountsChanged(201);
761     SUCCEED();
762     accountObserver->OnAccountsChanged(-1);
763     EXPECT_TRUE(accountObserver != nullptr);
764     accountObserver = nullptr;
765 }
766 
767 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
768 /**
769  * @tc.name: OnEvent_001
770  * @tc.desc: test account observer
771  * @tc.type: FUNC
772  * @tc.require: issuesI9SSQY
773  */
774 HWTEST_F(ObserverEventTest, OnEvent_001, testing::ext::TestSize.Level1)
775 {
776     nlohmann::json sysEvent;
777     sysEvent["domain_"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST";
778     hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
779         sysEvent.dump(JSON_FORMAT)));
780     sysEvent["name_"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
781     sysEvent["test1"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
782     sysEvent["test2"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
783     sysEvent["test3"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
784     sysEvent["test4"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
785     sysEvent["test5"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
786     sysEvent["test6"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
787     sysEvent["test7"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
788     sysEvent["test8"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
789     sysEvent["test9"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
790     sysEvent["test10"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
791     sysEvent["test11"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
792     sysEvent["test12"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
793     sysEvent["test13"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
794     sysEvent["test14"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
795     sysEvent["test15"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
796     sysEvent["test16"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
797     sysEvent["test17"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
798     sysEvent["test18"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
799     sysEvent["UID"] = TEST_UID;
800     sysEvent["PID"] = TEST_PID;
801     hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
802         sysEvent.dump(JSON_FORMAT)));
803     sysEvent["domain_"] = 1;
804     hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
805         sysEvent.dump(JSON_FORMAT)));
806     EXPECT_NE(hisysEventObserver_, nullptr);
807     EXPECT_NE(hisysEventObserver_, nullptr);
808 }
809 #endif
810 
811 /**
812  * @tc.name: DisableDataShareObserver_001
813  * @tc.desc: test account observer DisableDataShareObserver
814  * @tc.type: FUNC
815  * @tc.require: issuesI9SSQY
816  */
817 HWTEST_F(ObserverEventTest, DisableDataShareObserver_001, testing::ext::TestSize.Level1)
818 {
819     auto instance = ObserverManager::GetInstance();
820     if (instance) {
821         instance->DisableDataShareObserver();
822     }
823     EXPECT_TRUE(instance);
824 }
825 
826 /**
827  * @tc.name: DisableAudioObserver_001
828  * @tc.desc: test account observer DisableAudioObserver
829  * @tc.type: FUNC
830  * @tc.require: issuesI9SSQY
831  */
832 HWTEST_F(ObserverEventTest, DisableAudioObserver_001, testing::ext::TestSize.Level1)
833 {
834     auto instance = ObserverManager::GetInstance();
835     if (instance) {
836         instance->DisableAudioObserver();
837         instance->InitAudioObserver();
838         instance->DisableAudioObserver();
839     }
840 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
841     EXPECT_EQ(instance->audioObserver_, nullptr);
842 #else
843     SUCCEED();
844 #endif
845 }
846 
847 /**
848  * @tc.name: DisableDeviceMovementObserver_001
849  * @tc.desc: test account observer DisableDeviceMovementObserver
850  * @tc.type: FUNC
851  * @tc.require: issuesI9SSQY
852  */
853 HWTEST_F(ObserverEventTest, DisableDeviceMovementObserver_001, testing::ext::TestSize.Level1)
854 {
855     auto instance = ObserverManager::GetInstance();
856     if (instance) {
857         instance->DisableDeviceMovementObserver();
858         instance->InitDeviceMovementObserver();
859         instance->DisableDeviceMovementObserver();
860     }
861 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
862     EXPECT_EQ(instance->deviceMovementObserver_, nullptr);
863 #else
864     SUCCEED();
865 #endif
866 }
867 
868 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
869 #ifdef MMI_ENABLE
870 /**
871  * @tc.name: DisableMMiEventObserver_001
872  * @tc.desc: test account observer DisableMMiEventObserver
873  * @tc.type: FUNC
874  * @tc.require: issuesI9SSQY
875  */
876 HWTEST_F(ObserverEventTest, DisableMMiEventObserver_001, testing::ext::TestSize.Level1)
877 {
878     auto instance = ObserverManager::GetInstance();
879     if (instance) {
880         instance->DisableMMiEventObserver();
881     }
882     EXPECT_EQ(instance->mmiEventObserver_, nullptr);
883 }
884 
885 /**
886  * @tc.name: DisableMMiEventObserver_002
887  * @tc.desc: test account observer DisableMMiEventObserver
888  * @tc.type: FUNC
889  * @tc.require: issuesI9SSQY
890  */
891 HWTEST_F(ObserverEventTest, DisableMMiEventObserver_002, testing::ext::TestSize.Level1)
892 {
893     auto instance = ObserverManager::GetInstance();
894     if (instance) {
895         instance->isNeedReport_ = true;
896         instance->InitMMiEventObserver();
897         instance->DisableMMiEventObserver();
898     }
899     EXPECT_EQ(instance->mmiEventObserver_, nullptr);
900 }
901 #endif
902 #endif
903 
904 /**
905  * @tc.name: DisableConnectionSubscriber_001
906  * @tc.desc: test account observer DisableConnectionSubscriber
907  * @tc.type: FUNC
908  * @tc.require: issuesI9SSQY
909  */
910 HWTEST_F(ObserverEventTest, DisableConnectionSubscriber_001, testing::ext::TestSize.Level1)
911 {
912     auto instance = ObserverManager::GetInstance();
913     if (instance) {
914         instance->DisableConnectionSubscriber();
915         instance->InitConnectionSubscriber();
916         instance->DisableConnectionSubscriber();
917     }
918     EXPECT_EQ(instance->connectionSubscriber_, nullptr);
919 }
920 
921 /**
922  * @tc.name: DisableAVSessionStateChangeListener_001
923  * @tc.desc: test account observer DisableAVSessionStateChangeListener
924  * @tc.type: FUNC
925  * @tc.require: issuesI9SSQY
926  */
927 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE
928 HWTEST_F(ObserverEventTest, DisableAVSessionStateChangeListener_001, testing::ext::TestSize.Level1)
929 {
930     auto instance = ObserverManager::GetInstance();
931     if (instance) {
932         instance->DisableAVSessionStateChangeListener();
933     }
934     EXPECT_EQ(instance->avSessionStateListener_, nullptr);
935 }
936 #endif
937 
938 #ifdef RESOURCE_REQUEST_REQUEST
939 /**
940  * @tc.name: DisableDownloadUploadObserver_001
941  * @tc.desc: test account observer DisableDownloadUploadObserver
942  * @tc.type: FUNC
943  * @tc.require: issuesI9SSQY
944  */
945 HWTEST_F(ObserverEventTest, DisableDownloadUploadObserver_001, testing::ext::TestSize.Level1)
946 {
947     auto instance = ObserverManager::GetInstance();
948     if (instance) {
949         instance->DisableDownloadUploadObserver();
950     }
951     EXPECT_EQ(instance->downLoadUploadObserver_, nullptr);
952 }
953 
954 /**
955  * @tc.name: InitDownloadUploadObserver_001
956  * @tc.desc: test account observer InitDownloadUploadObserver
957  * @tc.type: FUNC
958  * @tc.require: issuesI9SSQY
959  */
960 HWTEST_F(ObserverEventTest, InitDownloadUploadObserver_001, testing::ext::TestSize.Level1)
961 {
962     auto instance = ObserverManager::GetInstance();
963     if (instance) {
964         instance->InitDownloadUploadObserver();
965     }
966     EXPECT_NE(instance->downLoadUploadObserver_, nullptr);
967 }
968 #endif
969 
970 /**
971  * @tc.name: DisableTelephonyObserver_001
972  * @tc.desc: test account observer DisableTelephonyObserver
973  * @tc.type: FUNC
974  * @tc.require: issuesI9SSQY
975  */
976 HWTEST_F(ObserverEventTest, DisableTelephonyObserver_001, testing::ext::TestSize.Level1)
977 {
978     auto instance = ObserverManager::GetInstance();
979     if (instance) {
980         instance->DisableTelephonyObserver();
981     }
982 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
983     EXPECT_EQ(instance->telephonyObserver_, nullptr);
984 #else
985     SUCCEED();
986 #endif
987 }
988 
989 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
990 /**
991  * @tc.name: DisableHiSysEventObserver_001
992  * @tc.desc: test account observer DisableHiSysEventObserver
993  * @tc.type: FUNC
994  * @tc.require: issuesI9SSQY
995  */
996 HWTEST_F(ObserverEventTest, DisableHiSysEventObserver_001, testing::ext::TestSize.Level1)
997 {
998     auto instance = ObserverManager::GetInstance();
999     if (instance) {
1000         instance->DisableHiSysEventObserver();
1001     }
1002     EXPECT_EQ(instance->hiSysEventObserver_, nullptr);
1003 }
1004 #endif
1005 
1006 /**
1007  * @tc.name: DisableDisplayModeObserver_001
1008  * @tc.desc: test account observer DisableDisplayModeObserver
1009  * @tc.type: FUNC
1010  * @tc.require: issuesI9SSQY
1011  */
1012 HWTEST_F(ObserverEventTest, DisableDisplayModeObserver_001, testing::ext::TestSize.Level1)
1013 {
1014     auto instance = ObserverManager::GetInstance();
1015     if (instance) {
1016         instance->DisableDisplayModeObserver();
1017     }
1018     EXPECT_EQ(instance->foldDisplayModeObserver_, nullptr);
1019 }
1020 
1021 /**
1022  * @tc.name: InitDisplayModeObserver_001
1023  * @tc.desc: test account observer InitDisplayModeObserver
1024  * @tc.type: FUNC
1025  * @tc.require: issuesI9SSQY
1026  */
1027 HWTEST_F(ObserverEventTest, InitDisplayModeObserver_001, testing::ext::TestSize.Level1)
1028 {
1029     auto instance = ObserverManager::GetInstance();
1030     if (instance) {
1031         instance->InitDisplayModeObserver();
1032         instance->InitDisplayModeObserver();
1033         instance->DisableDisplayModeObserver();
1034     }
1035     EXPECT_EQ(instance->foldDisplayModeObserver_, nullptr);
1036 }
1037 
1038 /**
1039  * @tc.name: InitDisplayOrientationObserver_001
1040  * @tc.desc: test account observer InitDisplayOrientationObserver
1041  * @tc.type: FUNC
1042  * @tc.require: issuesI9SSQY
1043  */
1044 HWTEST_F(ObserverEventTest, InitDisplayOrientationObserver_001, testing::ext::TestSize.Level1)
1045 {
1046     auto instance = ObserverManager::GetInstance();
1047     bool isFoldable = OHOS::Rosen::DisplayManager::GetInstance().IsFoldable();
1048     if (!isFoldable) {
1049         return;
1050     }
1051     if (instance) {
1052         instance->foldDisplayOrientationObserver_ = nullptr;
1053         instance->InitDisplayOrientationObserver();
1054         EXPECT_NE(instance->foldDisplayOrientationObserver_, nullptr);
1055         instance->DisableDisplayOrientationObserver();
1056         EXPECT_EQ(instance->foldDisplayOrientationObserver_, nullptr);
1057     }
1058     EXPECT_EQ(instance->foldDisplayOrientationObserver_, nullptr);
1059 }
1060 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
1061 #ifdef MMI_ENABLE
1062 /**
1063  * @tc.name: GetAllMmiStatusData_001
1064  * @tc.desc: test account observer GetAllMmiStatusData
1065  * @tc.type: FUNC
1066  * @tc.require: issuesI9SSQY
1067  */
1068 HWTEST_F(ObserverEventTest, GetAllMmiStatusData_001, testing::ext::TestSize.Level1)
1069 {
1070     auto instance = ObserverManager::GetInstance();
1071     EXPECT_NE(instance, nullptr);
1072     if (instance) {
1073         instance->GetAllMmiStatusData();
1074     }
1075     SUCCEED();
1076 }
1077 #endif
1078 #endif
1079 
1080 /**
1081  * @tc.name: AddItemToSysAbilityListener_001
1082  * @tc.desc: test AddItemToSysAbilityListener
1083  * @tc.type: FUNC
1084  * @tc.require: issuesIAJZVI
1085  */
1086 HWTEST_F(ObserverEventTest, AddItemToSysAbilityListener_001, testing::ext::TestSize.Level1)
1087 {
1088     sptr<ISystemAbilityManager> systemAbilityManager
1089         = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1090     auto instance = ObserverManager::GetInstance();
1091     if (instance) {
1092         instance->AddItemToSysAbilityListener(DFX_SYS_EVENT_SERVICE_ABILITY_ID, systemAbilityManager);
1093         instance->AddItemToSysAbilityListener(-1, systemAbilityManager);
1094     }
1095     EXPECT_FALSE(instance->sysAbilityListener_);
1096 }
1097 
1098 /**
1099  * @tc.name: ObserverManagerTest_001
1100  * @tc.desc: test ObserverManagerTest
1101  * @tc.type: FUNC
1102  * @tc.require: issuesIC5T7D
1103  */
1104 HWTEST_F(ObserverEventTest, ObserverManagerTest_001, testing::ext::TestSize.Level1)
1105 {
1106     auto instance = ObserverManager::GetInstance();
1107     EXPECT_NE(instance, nullptr);
1108     if (instance) {
1109         instance->sysAbilityListener_->OnAddSystemAbility(APP_MGR_SERVICE_ID, 0);
1110         instance->sysAbilityListener_->OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, 0);
1111         instance->sysAbilityListener_->OnAddSystemAbility(WINDOW_MANAGER_SERVICE_ID, 0);
1112         instance->sysAbilityListener_->OnRemoveSystemAbility(APP_MGR_SERVICE_ID, 0);
1113         instance->sysAbilityListener_->OnRemoveSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, 0);
1114         instance->sysAbilityListener_->OnRemoveSystemAbility(WINDOW_MANAGER_SERVICE_ID, 0);
1115     }
1116     SUCCEED();
1117 }
1118 
1119 /**
1120  * @tc.name: RmsApplicationStateObserver_001
1121  * @tc.desc: test for OnForegroundApplicationChanged, OnApplicationStateChanged
1122  * @tc.type: FUNC
1123  * @tc.require:
1124  * @tc.desc:
1125  */
1126 HWTEST_F(ObserverEventTest, RmsApplicationStateObserver_001, testing::ext::TestSize.Level1)
1127 {
1128     auto observer = std::make_shared<RmsApplicationStateObserver>();
1129     EXPECT_TRUE(observer != nullptr);
1130     AppExecFwk::AppStateData data;
1131     data.bundleName = "com.ohos.test";
1132     data.pid = 999;
1133     data.uid = 1000;
1134     data.state = 0;
1135     data.accessTokenId = 0;
1136     data.isFocused = false;
1137 
1138     observer->OnForegroundApplicationChanged(data);
1139     observer->OnApplicationStateChanged(data);
1140 
1141     data.uid = -1;
1142     observer->OnForegroundApplicationChanged(data);
1143     observer->OnApplicationStateChanged(data);
1144 
1145     data.uid = 1000;
1146     data.pid = -1;
1147     observer->OnForegroundApplicationChanged(data);
1148     observer->OnApplicationStateChanged(data);
1149 
1150     data.pid = 999;
1151     data.bundleName = "";
1152     observer->OnForegroundApplicationChanged(data);
1153     observer->OnApplicationStateChanged(data);
1154     sleep(1);
1155     SUCCEED();
1156 }
1157 
1158 /**
1159  * @tc.name: RmsApplicationStateObserver_002
1160  * @tc.desc: test for OnAbilityStateChanged, OnExtensionStateChanged
1161  * @tc.type: FUNC
1162  * @tc.require:
1163  * @tc.desc:
1164  */
1165 HWTEST_F(ObserverEventTest, RmsApplicationStateObserver_002, testing::ext::TestSize.Level1)
1166 {
1167     auto observer = std::make_shared<RmsApplicationStateObserver>();
1168     EXPECT_TRUE(observer != nullptr);
1169     AppStartupSceneRec::GetInstance().Init();
1170 
1171     AppExecFwk::AbilityStateData data;
1172     data.moduleName = "entry";
1173     data.bundleName = "com.ohos.test";
1174     data.abilityName = "MainAbility";
1175     data.abilityState = 0;
1176     data.pid = 999;
1177     data.uid = 1000;
1178     data.abilityRecordId = 111;
1179     data.abilityType = 0;
1180     data.isFocused = false;
1181     data.token = new RmsApplicationStateObserver();
1182     observer->OnAbilityStateChanged(data);
1183     observer->OnExtensionStateChanged(data);
1184     data.bundleName = "";
1185     data.uid = -1;
1186     observer->OnAbilityStateChanged(data);
1187     observer->OnExtensionStateChanged(data);
1188     sleep(1);
1189     SUCCEED();
1190 }
1191 
1192 /**
1193  * @tc.name: RmsApplicationStateObserver_003
1194  * @tc.desc: test for OnProcessCreated, OnProcessDied
1195  * @tc.type: FUNC
1196  * @tc.require:
1197  * @tc.desc:
1198  */
1199 HWTEST_F(ObserverEventTest, RmsApplicationStateObserver_003, testing::ext::TestSize.Level1)
1200 {
1201     auto observer = std::make_shared<RmsApplicationStateObserver>();
1202     EXPECT_TRUE(observer != nullptr);
1203     AppExecFwk::ProcessData data;
1204     data.bundleName = "com.ohos.test";
1205     data.pid = 999;
1206     data.uid = 1000;
1207     data.state = AppExecFwk::AppProcessState::APP_STATE_CREATE;
1208     data.isContinuousTask = false;
1209     data.isKeepAlive = false;
1210     data.isFocused = false;
1211 
1212     observer->OnProcessCreated(data);
1213     observer->OnProcessDied(data);
1214     data.bundleName = "";
1215     data.uid = -1;
1216     observer->OnProcessCreated(data);
1217     observer->OnProcessDied(data);
1218     sleep(1);
1219     SUCCEED();
1220 }
1221 
1222 /**
1223  * @tc.name: RmsApplicationStateObserver_004
1224  * @tc.desc: test for OnAppStateChanged, OnAppCacheStateChanged
1225  * @tc.type: FUNC
1226  * @tc.require:
1227  * @tc.desc:
1228  */
1229 HWTEST_F(ObserverEventTest, RmsApplicationStateObserver_004, testing::ext::TestSize.Level1)
1230 {
1231     auto observer = std::make_shared<RmsApplicationStateObserver>();
1232     EXPECT_TRUE(observer != nullptr);
1233     AppStateData appStateData;
1234     appStateData.pid = 100;
1235     appStateData.uid = 1000;
1236     appStateData.bundleName = "test";
1237     appStateData.extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
1238     observer->OnAppStateChanged(appStateData);
1239     observer->OnAppCacheStateChanged(appStateData);
1240     appStateData.uid = -1;
1241     observer->OnAppStateChanged(appStateData);
1242     observer->OnAppCacheStateChanged(appStateData);
1243 
1244     ProcessData processData;
1245     processData.pid = 100;
1246     processData.uid = 1000;
1247     processData.bundleName = "test";
1248     observer->OnProcessStateChanged(processData);
1249     processData.pid = -1;
1250     observer->OnProcessStateChanged(processData);
1251     SUCCEED();
1252 }
1253 
1254 /**
1255  * @tc.name: RmsApplicationStateObserver_005
1256  * @tc.desc: test for OnProcessPreForegroundChanged
1257  * @tc.type: FUNC
1258  */
1259 HWTEST_F(ObserverEventTest, RmsApplicationStateObserver_005, testing::ext::TestSize.Level1)
1260 {
1261     auto observer = std::make_shared<RmsApplicationStateObserver>();
1262     EXPECT_TRUE(observer != nullptr);
1263     PreloadProcessData processData;
1264     observer->OnProcessPreForegroundChanged(processData);
1265     processData.isPreForeground = true;
1266     processData.pid = 100;
1267     processData.uid = 1000;
1268     processData.bundleName = "test";
1269     observer->OnProcessPreForegroundChanged(processData);
1270 }
1271 
1272 /**
1273  * @tc.name: WindowStateObserver_001
1274  * @tc.desc: test for OnFocused, OnUnfocused
1275  * @tc.type: FUNC
1276  * @tc.require:
1277  * @tc.desc:
1278  */
1279 HWTEST_F(ObserverEventTest, WindowStateObserver_001, testing::ext::TestSize.Level1)
1280 {
1281     auto observer = std::make_shared<WindowStateObserver>();
1282     EXPECT_TRUE(observer != nullptr);
1283     sptr<Rosen::FocusChangeInfo> info = new Rosen::FocusChangeInfo();
1284     info->uid_ = 1000;
1285     info->pid_ = 999;
1286     observer->OnFocused(info);
1287     observer->OnUnfocused(info);
1288     observer->OnFocused(nullptr);
1289     observer->OnUnfocused(nullptr);
1290     auto windowModeObserver = std::make_shared<WindowModeObserver>();
1291     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_SPLIT);
1292     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_FLOATING);
1293     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_FULLSCREEN_FLOATING);
1294     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_FULLSCREEN);
1295     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_SPLIT_FLOATING);
1296     windowModeObserver->OnWindowModeUpdate(Rosen::WindowModeType::WINDOW_MODE_OTHER);
1297     auto pipStateObserver = std::make_shared<PiPStateObserver>();
1298     pipStateObserver->OnPiPStateChanged("test", false);
1299     sleep(1);
1300     SUCCEED();
1301 }
1302 
1303 /**
1304  * @tc.name: WindowStateObserver_002
1305  * @tc.desc: test for OnFocused, OnUnfocused
1306  * @tc.type: FUNC
1307  * @tc.require:
1308  * @tc.desc:
1309  */
1310 HWTEST_F(ObserverEventTest, WindowStateObserver_002, testing::ext::TestSize.Level1)
1311 {
1312     auto observer = std::make_shared<WindowVisibilityObserver>();
1313     EXPECT_TRUE(observer != nullptr);
1314     std::vector<sptr<Rosen::WindowVisibilityInfo> > windowVisibilityInfo;
1315     for (int32_t i = 0; i < 2; i++) {
1316         sptr<Rosen::WindowVisibilityInfo> info = new Rosen::WindowVisibilityInfo();
1317         windowVisibilityInfo.push_back(info);
1318     }
1319     windowVisibilityInfo.push_back(nullptr);
1320     observer->OnWindowVisibilityChanged(windowVisibilityInfo);
1321     SUCCEED();
1322 }
1323 
1324 /**
1325  * @tc.name: WindowDrawingContentObserver_001
1326  * @tc.desc: test for OnWindowDrawingContentChanged
1327  * @tc.type: FUNC
1328  * @tc.require:
1329  * @tc.desc:
1330  */
1331 HWTEST_F(ObserverEventTest, WindowDrawingContentObserver_001, testing::ext::TestSize.Level1)
1332 {
1333     auto observer = std::make_shared<WindowDrawingContentObserver>();
1334     EXPECT_TRUE(observer != nullptr);
1335 
1336     std::vector<sptr<WindowDrawingContentInfo>> changeInfo;
1337     OHOS::sptr<OHOS::Rosen::WindowDrawingContentInfo> info = new OHOS::Rosen::WindowDrawingContentInfo();
1338     changeInfo.push_back(info);
1339     observer->OnWindowDrawingContentChanged(changeInfo);
1340 }
1341 
1342 /**
1343  * @tc.name: BackgroundTaskObserver_001
1344  * @tc.desc: test for BackgroundTaskObserver
1345  * @tc.type: FUNC
1346  * @tc.require:
1347  * @tc.desc:
1348  */
1349 HWTEST_F(ObserverEventTest, BackgroundTaskObserver_001, testing::ext::TestSize.Level1)
1350 {
1351     auto observer = std::make_shared<BackgroundTaskObserver>();
1352     EXPECT_TRUE(observer != nullptr);
1353     std::shared_ptr<TransientTaskAppInfo> info = std::make_shared<TransientTaskAppInfo>("test", 1000, 1000);
1354     observer->OnTransientTaskStart(info);
1355     observer->OnTransientTaskEnd(info);
1356     observer->OnTransientTaskErr(info);
1357     observer->OnAppTransientTaskStart(info);
1358     observer->OnAppTransientTaskEnd(info);
1359     std::vector<uint32_t> typeIds = { 1 };
1360     std::shared_ptr<ContinuousTaskCallbackInfo> info2 = std::make_shared<ContinuousTaskCallbackInfo>(1,
1361         1000, 1000, "test", false, false, typeIds, -1, 0);
1362     observer->OnContinuousTaskStart(info2);
1363     observer->OnContinuousTaskStop(info2);
1364     observer->OnContinuousTaskUpdate(info2);
1365     std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> callbackInfo =
1366         std::make_shared<BackgroundTaskMgr::ResourceCallbackInfo>(1000, 1000, 1, "test");
1367     observer->OnAppEfficiencyResourcesApply(callbackInfo);
1368     observer->OnAppEfficiencyResourcesReset(callbackInfo);
1369     observer->OnProcEfficiencyResourcesApply(callbackInfo);
1370     observer->OnProcEfficiencyResourcesReset(callbackInfo);
1371 }
1372 }
1373 }