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
37 namespace OHOS {
38 namespace ResourceSchedule {
39 namespace {
40 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
41 static const int32_t TEST_UID = 0;
42 static const int32_t TEST_PID = 1000;
43 static const int32_t TEST_INSTANCE_ID = 123456;
44 static const int32_t JSON_FORMAT = 4;
45 #endif
46 }
47 class ObserverEventTest : public testing::Test {
48 public:
49 static void SetUpTestCase();
50 static void TearDownTestCase();
SetUp()51 void SetUp() {}
TearDown()52 void TearDown() {}
53 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
54 static std::shared_ptr<HiSysEventObserver> hisysEventObserver_;
55 #ifdef MMI_ENABLE
56 static std::shared_ptr<MmiObserver> mmiObserver_;
57 #endif
58 #endif
59 static std::shared_ptr<ConnectionSubscriber> connectionSubscriber_;
60 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
61 static std::shared_ptr<DeviceMovementObserver> deviceMovementObserver_;
62 #endif
63 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
64 static std::shared_ptr<SchedTelephonyObserver> schedTelephonyObserver_;
65 #endif
66 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
67 static std::shared_ptr<AudioObserver> audioObserver_;
68 #endif
69 static std::shared_ptr<FoldDisplayModeObserver> foldDisplayModeObserver_;
70 };
71
72 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
73 std::shared_ptr<HiSysEventObserver> ObserverEventTest::hisysEventObserver_ = nullptr;
74 #ifdef MMI_ENABLE
75 std::shared_ptr<MmiObserver> ObserverEventTest::mmiObserver_ = nullptr;
76 #endif
77 #endif
78 std::shared_ptr<FoldDisplayModeObserver> ObserverEventTest::foldDisplayModeObserver_ = nullptr;
79 std::shared_ptr<ConnectionSubscriber> ObserverEventTest::connectionSubscriber_ = nullptr;
80 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
81 std::shared_ptr<DeviceMovementObserver> ObserverEventTest::deviceMovementObserver_ = nullptr;
82 #endif
83 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
84 std::shared_ptr<SchedTelephonyObserver> ObserverEventTest::schedTelephonyObserver_ = nullptr;
85 #endif
86 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
87 std::shared_ptr<AudioObserver> ObserverEventTest::audioObserver_ = nullptr;
88 #endif
89
SetUpTestCase()90 void ObserverEventTest::SetUpTestCase()
91 {
92 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
93 hisysEventObserver_ = std::make_shared<HiSysEventObserver>();
94 #ifdef MMI_ENABLE
95 mmiObserver_ = std::make_shared<MmiObserver>();
96 #endif
97 #endif
98 connectionSubscriber_ = std::make_shared<ConnectionSubscriber>();
99 foldDisplayModeObserver_ = std::make_shared<FoldDisplayModeObserver>();
100 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
101 deviceMovementObserver_ = std::make_shared<DeviceMovementObserver>();
102 #endif
103 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
104 schedTelephonyObserver_ = std::make_shared<SchedTelephonyObserver>();
105 #endif
106 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
107 audioObserver_ = std::make_shared<AudioObserver>();
108 #endif
109 }
110
TearDownTestCase()111 void ObserverEventTest::TearDownTestCase()
112 {
113 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
114 hisysEventObserver_ = nullptr;
115 #ifdef MMI_ENABLE
116 mmiObserver_ = nullptr;
117 #endif
118 #endif
119 connectionSubscriber_ = nullptr;
120 foldDisplayModeObserver_ = nullptr;
121 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
122 deviceMovementObserver_ = nullptr;
123 #endif
124 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
125 schedTelephonyObserver_ = nullptr;
126 #endif
127 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
128 audioObserver_ = nullptr;
129 #endif
130 }
131
132 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
133 /**
134 * @tc.name: hisysEventAvCodecEvent_001
135 * @tc.desc: test multimedia encoding and decoding event processing
136 * @tc.type: FUNC
137 * @tc.require: issueI8IDAO
138 */
139 HWTEST_F(ObserverEventTest, hisysEventAvCodecEvent_001, testing::ext::TestSize.Level1)
140 {
141 nlohmann::json sysEvent;
142 std::string eventName = "INVAILD";
143 sysEvent["name_"] = eventName;
144
145 // incorrect uid keyword
146 sysEvent["UID"] = TEST_UID;
147 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
148 EXPECT_NE(hisysEventObserver_, nullptr);
149
150 // incorrect pid keyword
151 sysEvent["CLIENT_UID"] = TEST_UID;
152 sysEvent["PID"] = TEST_PID;
153 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
154 EXPECT_NE(hisysEventObserver_, nullptr);
155
156 // incorrect instance id keyword
157 sysEvent["CLIENT_UID"] = TEST_UID;
158 sysEvent["CLIENT_PID"] = TEST_PID;
159 sysEvent["INSTANCE_ID"] = TEST_INSTANCE_ID;
160 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
161 EXPECT_NE(hisysEventObserver_, nullptr);
162
163 // codec start info state scene
164 sysEvent["CODEC_INSTANCE_ID"] = TEST_INSTANCE_ID;
165 eventName = "CODEC_START_INFO";
166 sysEvent["name_"] = eventName;
167 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
168 EXPECT_NE(hisysEventObserver_, nullptr);
169
170 // codec stop info state scene
171 eventName = "CODEC_STOP_INFO";
172 sysEvent["name_"] = eventName;
173 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
174 EXPECT_NE(hisysEventObserver_, nullptr);
175
176 // codec fault state scene
177 eventName = "FAULT";
178 sysEvent["name_"] = eventName;
179 hisysEventObserver_->ProcessAvCodecEvent(sysEvent, eventName);
180 EXPECT_NE(hisysEventObserver_, nullptr);
181 }
182
183 /**
184 * @tc.name: hisysEventRunningLockEvent_001
185 * @tc.desc: test running lock event processing
186 * @tc.type: FUNC
187 * @tc.require: issueI8IDAO
188 */
189 HWTEST_F(ObserverEventTest, hisysEventRunningLockEvent_001, testing::ext::TestSize.Level1)
190 {
191 nlohmann::json sysEvent;
192 std::string eventName = "INVAILD";
193 // incorrect uid keyword
194 sysEvent["uid"] = TEST_UID;
195 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
196 EXPECT_NE(hisysEventObserver_, nullptr);
197
198 // incorrect pid keyword
199 sysEvent["UID"] = TEST_UID;
200 sysEvent["pid"] = TEST_PID;
201 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
202 EXPECT_NE(hisysEventObserver_, nullptr);
203
204 // incorrect type keyword
205 sysEvent["PID"] = TEST_PID;
206 sysEvent["type"] = 0;
207 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
208 EXPECT_NE(hisysEventObserver_, nullptr);
209
210 // incorrect state keyword
211 sysEvent["TYPE"] = 0;
212 sysEvent["state"] = 0;
213 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
214 EXPECT_NE(hisysEventObserver_, nullptr);
215
216 // running lock state disable
217 sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_DISABLE;
218 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
219 EXPECT_NE(hisysEventObserver_, nullptr);
220
221 // running lock state enable
222 sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_ENABLE;
223 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
224 EXPECT_NE(hisysEventObserver_, nullptr);
225
226 // running lock state proxied
227 sysEvent["STATE"] = RunningLockState::RUNNINGLOCK_STATE_PROXIED;
228 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
229 sysEvent["STATE"] = -1;
230 hisysEventObserver_->ProcessRunningLockEvent(sysEvent, eventName);
231 EXPECT_NE(hisysEventObserver_, nullptr);
232 }
233
234 /**
235 * @tc.name: hisysEventCameraEvent_001
236 * @tc.desc: test hisysevent camera event processing
237 * @tc.type: FUNC
238 * @tc.require: issueI8IDAO
239 */
240 HWTEST_F(ObserverEventTest, hisysEventCameraEvent_001, testing::ext::TestSize.Level1)
241 {
242 nlohmann::json sysEvent;
243 std::string eventName = "INVAILD";
244 // incorrect uid keyword
245 sysEvent["uid"] = TEST_UID;
246 hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
247 EXPECT_NE(hisysEventObserver_, nullptr);
248
249 // incorrect pid keyword
250 sysEvent["UID"] = TEST_UID;
251 sysEvent["pid"] = TEST_PID;
252 hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
253 EXPECT_NE(hisysEventObserver_, nullptr);
254
255 // eventName test
256 sysEvent["PID"] = TEST_PID;
257 eventName = "CAMERA_CONNECT";
258 hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
259 EXPECT_NE(hisysEventObserver_, nullptr);
260
261 eventName = "CAMERA_DISCONNECT";
262 hisysEventObserver_->ProcessCameraEvent(sysEvent, eventName);
263 EXPECT_NE(hisysEventObserver_, nullptr);
264 }
265
266 /**
267 * @tc.name: hisysEventWifiEvent_001
268 * @tc.desc: test hisysevent wifi event processing
269 * @tc.type: FUNC
270 * @tc.require: issueI8IDAO
271 */
272 HWTEST_F(ObserverEventTest, hisysEventWifiEvent_001, testing::ext::TestSize.Level1)
273 {
274 nlohmann::json sysEvent;
275 std::string eventName = "INVAILD";
276 // incorrect uid keyword
277 sysEvent["uid"] = TEST_UID;
278 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
279 EXPECT_NE(hisysEventObserver_, nullptr);
280
281 // incorrect pid keyword
282 sysEvent["uid_"] = TEST_UID;
283 sysEvent["pid"] = TEST_PID;
284 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
285 EXPECT_NE(hisysEventObserver_, nullptr);
286
287 // incorrect eventname
288 sysEvent["pid_"] = TEST_PID;
289 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
290 EXPECT_NE(hisysEventObserver_, nullptr);
291
292 // wifi connection state: connected
293 eventName = "WIFI_CONNECTION";
294 sysEvent["TYPE"] = WifiState::CONNECTED;
295 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
296 EXPECT_NE(hisysEventObserver_, nullptr);
297
298 // wifi connection state: disconnected
299 sysEvent["TYPE"] = WifiState::DISCONNECTED;
300 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
301 EXPECT_NE(hisysEventObserver_, nullptr);
302
303 // wifi scan state
304 eventName = "WIFI_SCAN";
305 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
306 sysEvent["TYPE"] = -1;
307 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
308 eventName = "test";
309 hisysEventObserver_->ProcessWifiEvent(sysEvent, eventName);
310 EXPECT_NE(hisysEventObserver_, nullptr);
311 }
312
313 /**
314 * @tc.name: processHiSysEvent_001
315 * @tc.desc: the hisysevent onevent test
316 * @tc.type: FUNC
317 * @tc.require: issueI8IDAO
318 */
319 HWTEST_F(ObserverEventTest, processHiSysEvent_001, testing::ext::TestSize.Level1)
320 {
321 hisysEventObserver_->OnEvent(nullptr);
322 hisysEventObserver_->OnServiceDied();
323 nlohmann::json sysEvent;
324 sysEvent["domain_"] = "RUNNINGLOCK";
325 sysEvent["name_"] = "RUNNINGLOCK";
326 sysEvent["UID"] = TEST_UID;
327 sysEvent["PID"] = TEST_PID;
328 hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
329 sysEvent.dump(JSON_FORMAT)));
330 EXPECT_NE(hisysEventObserver_, nullptr);
331 }
332
333 /**
334 * @tc.name: processHiSysEvent_002
335 * @tc.desc: the process hisysevent test
336 * @tc.type: FUNC
337 * @tc.require: issueI8IDAO
338 */
339 HWTEST_F(ObserverEventTest, processHiSysEvent_002, testing::ext::TestSize.Level1)
340 {
341 nlohmann::json sysEvent;
342 std::string eventName = "INVAILD";
343 sysEvent["domain_"] = "AV_CODEC";
344 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
345 EXPECT_NE(hisysEventObserver_, nullptr);
346
347 sysEvent["domain_"] = "INVAILD";
348 eventName = "RUNNINGLOCK";
349 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
350 EXPECT_NE(hisysEventObserver_, nullptr);
351 }
352
353 /**
354 * @tc.name: processHiSysEvent_003
355 * @tc.desc: the process hisysevent test
356 * @tc.type: FUNC
357 * @tc.require: issuesIAJZVI
358 */
359 HWTEST_F(ObserverEventTest, processHiSysEvent_003, testing::ext::TestSize.Level1)
360 {
361 nlohmann::json sysEvent;
362 sysEvent["domain_"] = "INVAILD";
363 std::string eventName = "CAMERA_CONNECT";
364 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
365 eventName = "CAMERA_DISCONNECT";
366 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
367 eventName = "WIFI_CONNECTION";
368 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
369 eventName = "WIFI_SCAN";
370 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
371 eventName = "PLAYER_STATE";
372 hisysEventObserver_->ProcessHiSysEvent(eventName, sysEvent);
373 EXPECT_NE(hisysEventObserver_, nullptr);
374 }
375
376 #ifdef MMI_ENABLE
377 /**
378 * @tc.name: mmiObserverEvent_001
379 * @tc.desc: test multimodal input sync bundleName interface
380 * @tc.type: FUNC
381 * @tc.require: issueI8IDAO
382 */
383 HWTEST_F(ObserverEventTest, mmiObserverEvent_001, testing::ext::TestSize.Level1)
384 {
385 int32_t pid = TEST_PID;
386 int32_t uid = TEST_UID;
387 std::string bundleName;
388 int32_t status = 0;
389 // the scene of bundleName is null
390 mmiObserver_->SyncBundleName(pid, uid, bundleName, status);
391 EXPECT_NE(mmiObserver_, nullptr);
392
393 // the scene of bundleName is not null
394 bundleName = "inputmethod";
395 mmiObserver_->SyncBundleName(pid, uid, bundleName, status);
396 EXPECT_NE(mmiObserver_, nullptr);
397 }
398 #endif
399 #endif
400
401 /**
402 * @tc.name: deviceMovementObserverEvent_001
403 * @tc.desc: test multimodal input sync bundleName interface
404 * @tc.type: FUNC
405 * @tc.require: issueI8VZVN
406 */
407 HWTEST_F(ObserverEventTest, deviceMovementObserverEvent_001, testing::ext::TestSize.Level1)
408 {
409 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
410 // data is null
411 int32_t code = -1;
412 MessageParcel data;
413 MessageParcel reply;
414 MessageOption option;
415 int32_t testRequest = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
416 EXPECT_EQ(testRequest, -1);
417
418 //code is MOVEMENT_CHANGE
419 data.WriteInterfaceToken(DeviceMovementObserver::GetDescriptor());
420 code = static_cast<int32_t>(Msdp::ImovementCallback::MOVEMENT_CHANGE);
421 int32_t t1 = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
422 EXPECT_EQ(t1, 0);
423
424 //code is not MOVEMENT_CHANGE
425 code = -1;
426 int32_t t2 = deviceMovementObserver_->OnRemoteRequest(code, data, reply, option);
427 EXPECT_EQ(t2, -1);
428 #endif
429 }
430
431 /**
432 * @tc.name: schedTelephonyObserverEvent_001
433 * @tc.desc: test multimodal input sync bundleName interface
434 * @tc.type: FUNC
435 * @tc.require: issueI8VZVN
436 */
437 HWTEST_F(ObserverEventTest, schedTelephonyObserverEvent_001, testing::ext::TestSize.Level1)
438 {
439 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
440 int32_t slotId = 0;
441 int32_t callState = 0;
442 std::u16string phoneNumber;
443 schedTelephonyObserver_->OnCallStateUpdated(slotId, callState, phoneNumber);
444 EXPECT_TRUE(schedTelephonyObserver_ != nullptr);
445 #endif
446 }
447
448 /**
449 * @tc.name: connectionSubscriberEvent_001
450 * @tc.desc: test multimodal input sync bundleName interface
451 * @tc.type: FUNC
452 * @tc.require: issueI8VZVN
453 */
454 HWTEST_F(ObserverEventTest, connectionSubscriberEvent_001, testing::ext::TestSize.Level1)
455 {
456 //test the interface
457 AbilityRuntime::ConnectionData data;
458 AbilityRuntime::DlpStateData data1;
459 nlohmann::json payload;
460 connectionSubscriber_->MarshallingConnectionData(data, payload);
461 SUCCEED();
462 connectionSubscriber_->OnExtensionConnected(data);
463 SUCCEED();
464 connectionSubscriber_->OnExtensionDisconnected(data);
465 SUCCEED();
466 connectionSubscriber_->MarshallingDlpStateData(data1, payload);
467 SUCCEED();
468 connectionSubscriber_->OnDlpAbilityOpened(data1);
469 SUCCEED();
470 connectionSubscriber_->OnDlpAbilityClosed(data1);
471 SUCCEED();
472 connectionSubscriber_->OnServiceDied();
473 EXPECT_TRUE(connectionSubscriber_ != nullptr);
474 }
475
476 /**
477 * @tc.name: audioObserverObserverEvent_001
478 * @tc.desc: test multimodal input sync bundleName interface
479 * @tc.type: FUNC
480 * @tc.require: issueI8VZVN
481 */
482 HWTEST_F(ObserverEventTest, audioObserverEvent_001, testing::ext::TestSize.Level1)
483 {
484 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
485 std::shared_ptr<AudioStandard::AudioRendererChangeInfo> audioRendererChangeInfo =
486 std::make_shared<AudioStandard::AudioRendererChangeInfo>();
487 nlohmann::json payload;
488 audioObserver_->MarshallingAudioRendererChangeInfo(audioRendererChangeInfo, payload);
489 SUCCEED();
490 std::vector<std::shared_ptr<AudioStandard::AudioRendererChangeInfo>> audioRenderVector;
491 audioRenderVector.emplace_back(std::move(audioRendererChangeInfo));
492 audioObserver_->OnRendererStateChange(audioRenderVector);
493 SUCCEED();
494
495 //ringerMode equals mode_
496 AudioStandard::AudioRingerMode ringerMode = AudioStandard::AudioRingerMode::RINGER_MODE_NORMAL;
497 audioObserver_->OnRingerModeUpdated(ringerMode);
498 SUCCEED();
499 //ringerMode is not mode_
500 audioObserver_->OnRingerModeUpdated(ringerMode);
501 SUCCEED();
502
503 //test the interface of OnVolumeKeyEvent
504 AudioStandard::VolumeEvent volumeEvent;
505 audioObserver_->OnVolumeKeyEvent(volumeEvent);
506 SUCCEED();
507
508 //test the interface of OnAudioSceneChange
509 AudioStandard::AudioScene audioScene = AudioStandard::AudioScene::AUDIO_SCENE_DEFAULT;
510 audioObserver_->OnAudioSceneChange(audioScene);
511 SUCCEED();
512
513 // test the interface of OnPreferredOutputDeviceUpdated
514 std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> descs;
515 audioObserver_->OnPreferredOutputDeviceUpdated(descs);
516 EXPECT_TRUE(audioObserver_ != nullptr);
517 #endif
518 }
519
520 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
521 #ifdef MMI_ENABLE
522 /**
523 * @tc.name: mmiObserverEvent_002
524 * @tc.desc: test multimodal input get mmi status status interface
525 * @tc.type: FUNC
526 * @tc.require: issueI8ZIVH
527 */
528 HWTEST_F(ObserverEventTest, mmiObserverEvent_002, testing::ext::TestSize.Level1)
529 {
530 auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
531 EXPECT_NE(samgr, nullptr);
532 auto remoteObj = samgr->GetSystemAbility(MULTIMODAL_INPUT_SERVICE_ID);
533 if (!remoteObj) {
534 return;
535 }
536 auto instance = ObserverManager::GetInstance();
537 if (instance) {
538 instance->GetAllMmiStatusData();
539 }
540 SUCCEED();
541 }
542 #endif
543 #endif
544
545 #ifndef RESOURCE_REQUEST_REQUEST
546 /**
547 * @tc.name: foldDisplayModeObserver_001
548 * @tc.desc: test fold display mode status interface
549 * @tc.type: FUNC
550 * @tc.require: issueI8ZIVH
551 */
552 HWTEST_F(ObserverEventTest, foldDisplayModeObserver_001, testing::ext::TestSize.Level1)
553 {
554 const std::string DISPLAY_MODE_MAIN = "displayMain";
555 foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::MAIN);
556 EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_MAIN);
557
558 const std::string DISPLAY_MODE_FULL = "displayFull";
559 foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::FULL);
560 EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_FULL);
561
562 const std::string DISPLAY_MODE_SUB = "displaySub";
563 foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::SUB);
564 EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_SUB);
565
566 const std::string DISPLAY_MODE_UNKOWN = "displayUnknown";
567 foldDisplayModeObserver_->OnDisplayModeChanged(FoldDisplayMode::UNKNOWN);
568 EXPECT_EQ(foldDisplayModeObserver_->currentDisplayMode, DISPLAY_MODE_UNKOWN);
569 }
570
571 /**
572 * @tc.name: downLoadUploadObserver_001
573 * @tc.desc: Test downLoad Upload Observer
574 * @tc.type: FUNC
575 * @tc.require: issuesI9BU37
576 */
577 HWTEST_F(ObserverEventTest, downLoadUploadObserver_001, testing::ext::TestSize.Level1)
578 {
579 std::shared_ptr<DownLoadUploadObserver> downLoadUploadObserver_ =
580 std::make_shared<DownLoadUploadObserver>();
581 downLoadUploadObserver_->OnRunningTaskCountUpdate(1);
582 EXPECT_TRUE(downLoadUploadObserver_->isReportScene);
583 downLoadUploadObserver_->OnRunningTaskCountUpdate(0);
584 EXPECT_FALSE(downLoadUploadObserver_->isReportScene);
585 downLoadUploadObserver_->OnRunningTaskCountUpdate(-1);
586 EXPECT_FALSE(downLoadUploadObserver_->isReportScene);
587 downLoadUploadObserver_ = nullptr;
588 }
589 #endif
590 /**
591 * @tc.name: accountObserver_001
592 * @tc.desc: test account observer
593 * @tc.type: FUNC
594 * @tc.require: issuesI9SSQY
595 */
596 HWTEST_F(ObserverEventTest, accountObserver_001, testing::ext::TestSize.Level1)
597 {
598 AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo;
599 osAccountSubscribeInfo.SetOsAccountSubscribeType(AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVATING);
600 osAccountSubscribeInfo.SetName("ResschdeAccountActivatingSubscriberTest");
601 auto accountObserver = std::make_shared<AccountObserver>(osAccountSubscribeInfo);
602 accountObserver->OnAccountsChanged(200);
603 SUCCEED();
604 accountObserver->OnAccountsChanged(201);
605 SUCCEED();
606 accountObserver->OnAccountsChanged(-1);
607 EXPECT_TRUE(accountObserver != nullptr);
608 accountObserver = nullptr;
609 }
610
611 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
612 /**
613 * @tc.name: OnEvent_001
614 * @tc.desc: test account observer
615 * @tc.type: FUNC
616 * @tc.require: issuesI9SSQY
617 */
618 HWTEST_F(ObserverEventTest, OnEvent_001, testing::ext::TestSize.Level1)
619 {
620 nlohmann::json sysEvent;
621 sysEvent["domain_"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST";
622 hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
623 sysEvent.dump(JSON_FORMAT)));
624 sysEvent["name_"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
625 sysEvent["test1"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
626 sysEvent["test2"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
627 sysEvent["test3"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
628 sysEvent["test4"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
629 sysEvent["test5"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
630 sysEvent["test6"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
631 sysEvent["test7"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
632 sysEvent["test8"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
633 sysEvent["test9"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
634 sysEvent["test10"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
635 sysEvent["test11"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
636 sysEvent["test12"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
637 sysEvent["test13"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
638 sysEvent["test14"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
639 sysEvent["test15"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
640 sysEvent["test16"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
641 sysEvent["test17"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
642 sysEvent["test18"] = "RUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTESTRUNNINGLOCKTEST1";
643 sysEvent["UID"] = TEST_UID;
644 sysEvent["PID"] = TEST_PID;
645 hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
646 sysEvent.dump(JSON_FORMAT)));
647 sysEvent["domain_"] = 1;
648 hisysEventObserver_->OnEvent(std::make_shared<HiviewDFX::HiSysEventRecord>(
649 sysEvent.dump(JSON_FORMAT)));
650 EXPECT_NE(hisysEventObserver_, nullptr);
651 EXPECT_NE(hisysEventObserver_, nullptr);
652 }
653 #endif
654
655 /**
656 * @tc.name: DisableDataShareObserver_001
657 * @tc.desc: test account observer DisableDataShareObserver
658 * @tc.type: FUNC
659 * @tc.require: issuesI9SSQY
660 */
661 HWTEST_F(ObserverEventTest, DisableDataShareObserver_001, testing::ext::TestSize.Level1)
662 {
663 auto instance = ObserverManager::GetInstance();
664 if (instance) {
665 instance->DisableDataShareObserver();
666 }
667 EXPECT_TRUE(instance);
668 }
669
670 /**
671 * @tc.name: DisableAudioObserver_001
672 * @tc.desc: test account observer DisableAudioObserver
673 * @tc.type: FUNC
674 * @tc.require: issuesI9SSQY
675 */
676 HWTEST_F(ObserverEventTest, DisableAudioObserver_001, testing::ext::TestSize.Level1)
677 {
678 auto instance = ObserverManager::GetInstance();
679 if (instance) {
680 instance->DisableAudioObserver();
681 instance->InitAudioObserver();
682 instance->DisableAudioObserver();
683 }
684 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
685 EXPECT_EQ(instance->audioObserver_, nullptr);
686 #else
687 SUCCEED();
688 #endif
689 }
690
691 /**
692 * @tc.name: DisableDeviceMovementObserver_001
693 * @tc.desc: test account observer DisableDeviceMovementObserver
694 * @tc.type: FUNC
695 * @tc.require: issuesI9SSQY
696 */
697 HWTEST_F(ObserverEventTest, DisableDeviceMovementObserver_001, testing::ext::TestSize.Level1)
698 {
699 auto instance = ObserverManager::GetInstance();
700 if (instance) {
701 instance->DisableDeviceMovementObserver();
702 instance->InitDeviceMovementObserver();
703 instance->DisableDeviceMovementObserver();
704 }
705 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE
706 EXPECT_EQ(instance->deviceMovementObserver_, nullptr);
707 #else
708 SUCCEED();
709 #endif
710 }
711
712 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
713 #ifdef MMI_ENABLE
714 /**
715 * @tc.name: DisableMMiEventObserver_001
716 * @tc.desc: test account observer DisableMMiEventObserver
717 * @tc.type: FUNC
718 * @tc.require: issuesI9SSQY
719 */
720 HWTEST_F(ObserverEventTest, DisableMMiEventObserver_001, testing::ext::TestSize.Level1)
721 {
722 auto instance = ObserverManager::GetInstance();
723 if (instance) {
724 instance->DisableMMiEventObserver();
725 }
726 EXPECT_EQ(instance->mmiEventObserver_, nullptr);
727 }
728
729 /**
730 * @tc.name: DisableMMiEventObserver_002
731 * @tc.desc: test account observer DisableMMiEventObserver
732 * @tc.type: FUNC
733 * @tc.require: issuesI9SSQY
734 */
735 HWTEST_F(ObserverEventTest, DisableMMiEventObserver_002, testing::ext::TestSize.Level1)
736 {
737 auto instance = ObserverManager::GetInstance();
738 if (instance) {
739 instance->isNeedReport_ = true;
740 instance->InitMMiEventObserver();
741 instance->DisableMMiEventObserver();
742 }
743 EXPECT_EQ(instance->mmiEventObserver_, nullptr);
744 }
745 #endif
746 #endif
747
748 /**
749 * @tc.name: DisableConnectionSubscriber_001
750 * @tc.desc: test account observer DisableConnectionSubscriber
751 * @tc.type: FUNC
752 * @tc.require: issuesI9SSQY
753 */
754 HWTEST_F(ObserverEventTest, DisableConnectionSubscriber_001, testing::ext::TestSize.Level1)
755 {
756 auto instance = ObserverManager::GetInstance();
757 if (instance) {
758 instance->DisableConnectionSubscriber();
759 instance->InitConnectionSubscriber();
760 instance->DisableConnectionSubscriber();
761 }
762 EXPECT_EQ(instance->connectionSubscriber_, nullptr);
763 }
764
765 /**
766 * @tc.name: DisableAVSessionStateChangeListener_001
767 * @tc.desc: test account observer DisableAVSessionStateChangeListener
768 * @tc.type: FUNC
769 * @tc.require: issuesI9SSQY
770 */
771 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE
772 HWTEST_F(ObserverEventTest, DisableAVSessionStateChangeListener_001, testing::ext::TestSize.Level1)
773 {
774 auto instance = ObserverManager::GetInstance();
775 if (instance) {
776 instance->DisableAVSessionStateChangeListener();
777 }
778 EXPECT_EQ(instance->avSessionStateListener_, nullptr);
779 }
780 #endif
781
782 #ifndef RESOURCE_REQUEST_REQUEST
783 /**
784 * @tc.name: DisableDownloadUploadObserver_001
785 * @tc.desc: test account observer DisableDownloadUploadObserver
786 * @tc.type: FUNC
787 * @tc.require: issuesI9SSQY
788 */
789 HWTEST_F(ObserverEventTest, DisableDownloadUploadObserver_001, testing::ext::TestSize.Level1)
790 {
791 auto instance = ObserverManager::GetInstance();
792 if (instance) {
793 instance->DisableDownloadUploadObserver();
794 }
795 EXPECT_EQ(instance->downLoadUploadObserver_, nullptr);
796 }
797
798 /**
799 * @tc.name: InitDownloadUploadObserver_001
800 * @tc.desc: test account observer InitDownloadUploadObserver
801 * @tc.type: FUNC
802 * @tc.require: issuesI9SSQY
803 */
804 HWTEST_F(ObserverEventTest, InitDownloadUploadObserver_001, testing::ext::TestSize.Level1)
805 {
806 auto instance = ObserverManager::GetInstance();
807 if (instance) {
808 instance->InitDownloadUploadObserver();
809 }
810 EXPECT_NE(instance->downLoadUploadObserver_, nullptr);
811 }
812 #endif
813
814 /**
815 * @tc.name: DisableTelephonyObserver_001
816 * @tc.desc: test account observer DisableTelephonyObserver
817 * @tc.type: FUNC
818 * @tc.require: issuesI9SSQY
819 */
820 HWTEST_F(ObserverEventTest, DisableTelephonyObserver_001, testing::ext::TestSize.Level1)
821 {
822 auto instance = ObserverManager::GetInstance();
823 if (instance) {
824 instance->DisableTelephonyObserver();
825 }
826 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE
827 EXPECT_EQ(instance->telephonyObserver_, nullptr);
828 #else
829 SUCCEED();
830 #endif
831 }
832
833 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
834 /**
835 * @tc.name: DisableHiSysEventObserver_001
836 * @tc.desc: test account observer DisableHiSysEventObserver
837 * @tc.type: FUNC
838 * @tc.require: issuesI9SSQY
839 */
840 HWTEST_F(ObserverEventTest, DisableHiSysEventObserver_001, testing::ext::TestSize.Level1)
841 {
842 auto instance = ObserverManager::GetInstance();
843 if (instance) {
844 instance->DisableHiSysEventObserver();
845 }
846 EXPECT_EQ(instance->hiSysEventObserver_, nullptr);
847 }
848 #endif
849
850 /**
851 * @tc.name: DisableDisplayModeObserver_001
852 * @tc.desc: test account observer DisableDisplayModeObserver
853 * @tc.type: FUNC
854 * @tc.require: issuesI9SSQY
855 */
856 HWTEST_F(ObserverEventTest, DisableDisplayModeObserver_001, testing::ext::TestSize.Level1)
857 {
858 auto instance = ObserverManager::GetInstance();
859 if (instance) {
860 instance->foldDisplayModeObserver_ = nullptr;
861 instance->DisableDisplayModeObserver();
862 }
863 EXPECT_EQ(instance->foldDisplayModeObserver_, nullptr);
864 }
865
866 /**
867 * @tc.name: InitDisplayModeObserver_001
868 * @tc.desc: test account observer InitDisplayModeObserver
869 * @tc.type: FUNC
870 * @tc.require: issuesI9SSQY
871 */
872 HWTEST_F(ObserverEventTest, InitDisplayModeObserver_001, testing::ext::TestSize.Level1)
873 {
874 auto instance = ObserverManager::GetInstance();
875 if (instance) {
876 instance->foldDisplayModeObserver_ = nullptr;
877 instance->InitDisplayModeObserver();
878 instance->InitDisplayModeObserver();
879 instance->DisableDisplayModeObserver();
880 }
881 EXPECT_EQ(instance->foldDisplayModeObserver_, nullptr);
882 }
883
884 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE
885 #ifdef MMI_ENABLE
886 /**
887 * @tc.name: GetAllMmiStatusData_001
888 * @tc.desc: test account observer GetAllMmiStatusData
889 * @tc.type: FUNC
890 * @tc.require: issuesI9SSQY
891 */
892 HWTEST_F(ObserverEventTest, GetAllMmiStatusData_001, testing::ext::TestSize.Level1)
893 {
894 auto instance = ObserverManager::GetInstance();
895 EXPECT_NE(instance, nullptr);
896 if (instance) {
897 instance->GetAllMmiStatusData();
898 }
899 SUCCEED();
900 }
901 #endif
902 #endif
903
904 /**
905 * @tc.name: AddItemToSysAbilityListener_001
906 * @tc.desc: test AddItemToSysAbilityListener
907 * @tc.type: FUNC
908 * @tc.require: issuesIAJZVI
909 */
910 HWTEST_F(ObserverEventTest, AddItemToSysAbilityListener_001, testing::ext::TestSize.Level1)
911 {
912 sptr<ISystemAbilityManager> systemAbilityManager
913 = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
914 auto instance = ObserverManager::GetInstance();
915 if (instance) {
916 instance->AddItemToSysAbilityListener(DFX_SYS_EVENT_SERVICE_ABILITY_ID, systemAbilityManager);
917 instance->AddItemToSysAbilityListener(-1, systemAbilityManager);
918 }
919 EXPECT_FALSE(instance->sysAbilityListener_);
920 }
921
922 }
923 }