• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <memory>
18 #include <fstream>
19 #include <cstdio>
20 
21 #include "avsession_log.h"
22 #include "avsession_errors.h"
23 #include "avmeta_data.h"
24 #include "avplayback_state.h"
25 #include "avsession_info.h"
26 #include "avsession_service.h"
27 #include "audio_info.h"
28 #include "system_ability_definition.h"
29 #include "system_ability_ondemand_reason.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS::AVSession;
33 using namespace OHOS::AudioStandard;
34 static AVMetaData g_metaData;
35 static AVPlaybackState g_playbackState;
36 static char g_testSessionTag[] = "test";
37 static char g_testAnotherBundleName[] = "testAnother.ohos.avsession";
38 static char g_testAnotherAbilityName[] = "testAnother.ability";
39 static OHOS::sptr<AVSessionService> g_AVSessionService {nullptr};
40 static const int32_t COLLABORATION_SA_ID = 70633;
41 static const int32_t CAST_ENGINE_SA_ID = 65546;
42 static bool g_isCallOnSessionCreate = false;
43 static bool g_isCallOnSessionRelease = false;
44 static bool g_isCallOnTopSessionChange = false;
45 
46 class TestISessionListener : public ISessionListener {
47     TestISessionListener() = default;
48     virtual ~TestISessionListener() = default;
49     void OnSessionCreate(const AVSessionDescriptor& descriptor) override;
50     void OnSessionRelease(const AVSessionDescriptor& descriptor) override;
51     void OnTopSessionChange(const AVSessionDescriptor& descriptor) override;
OnAudioSessionChecked(const int32_t uid)52     void OnAudioSessionChecked(const int32_t uid) override {};
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)53     void OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) override {};
OnDeviceLogEvent(const DeviceLogEventCode eventId,const int64_t param)54     void OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override {};
OnDeviceOffline(const std::string & deviceId)55     void OnDeviceOffline(const std::string& deviceId) override {};
OnRemoteDistributedSessionChange(const std::vector<OHOS::sptr<IRemoteObject>> & sessionControllers)56     void OnRemoteDistributedSessionChange(
57         const std::vector<OHOS::sptr<IRemoteObject>>& sessionControllers) override {};
AsObject()58     OHOS::sptr<IRemoteObject> AsObject() override { return nullptr; };
59 };
60 
OnSessionCreate(const AVSessionDescriptor & descriptor)61 void TestISessionListener::OnSessionCreate(const AVSessionDescriptor& descriptor)
62 {
63     g_isCallOnSessionCreate = true;
64 }
65 
OnSessionRelease(const AVSessionDescriptor & descriptor)66 void TestISessionListener::OnSessionRelease(const AVSessionDescriptor& descriptor)
67 {
68     g_isCallOnSessionRelease = true;
69 }
70 
OnTopSessionChange(const AVSessionDescriptor & descriptor)71 void TestISessionListener::OnTopSessionChange(const AVSessionDescriptor& descriptor)
72 {
73     g_isCallOnTopSessionChange = true;
74 }
75 
76 class TestSessionListener : public SessionListener {
77     TestSessionListener() = default;
78     virtual ~TestSessionListener() = default;
79     void OnSessionCreate(const AVSessionDescriptor& descriptor) override;
80     void OnSessionRelease(const AVSessionDescriptor& descriptor) override;
81     void OnTopSessionChange(const AVSessionDescriptor& descriptor) override;
OnAudioSessionChecked(const int32_t uid)82     void OnAudioSessionChecked(const int32_t uid) override {};
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)83     void OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) override {};
OnDeviceLogEvent(const DeviceLogEventCode eventId,const int64_t param)84     void OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override {};
OnDeviceOffline(const std::string & deviceId)85     void OnDeviceOffline(const std::string& deviceId) override {};
OnRemoteDistributedSessionChange(const std::vector<OHOS::sptr<IRemoteObject>> & sessionControllers)86     void OnRemoteDistributedSessionChange(
87         const std::vector<OHOS::sptr<IRemoteObject>>& sessionControllers) override {};
88 };
89 
OnSessionCreate(const AVSessionDescriptor & descriptor)90 void TestSessionListener::OnSessionCreate(const AVSessionDescriptor& descriptor)
91 {
92     g_isCallOnSessionCreate = true;
93 }
94 
OnSessionRelease(const AVSessionDescriptor & descriptor)95 void TestSessionListener::OnSessionRelease(const AVSessionDescriptor& descriptor)
96 {
97     g_isCallOnSessionRelease = true;
98 }
99 
OnTopSessionChange(const AVSessionDescriptor & descriptor)100 void TestSessionListener::OnTopSessionChange(const AVSessionDescriptor& descriptor)
101 {
102     g_isCallOnTopSessionChange = true;
103 }
104 
105 class AVSessionServiceTestSecond : public testing::Test {
106 public:
107     static void SetUpTestCase();
108     static void TearDownTestCase();
109     void SetUp() override;
110     void TearDown() override;
111 
112     OHOS::sptr<AVSessionItem> CreateSession();
113     std::shared_ptr<AVSession> avsession_ = nullptr;
114 };
115 
SetUpTestCase()116 void AVSessionServiceTestSecond::SetUpTestCase()
117 {
118     SLOGI("set up AVSessionServiceTestSecond");
119     system("killall -9 com.example.hiMusicDemo");
120 }
121 
TearDownTestCase()122 void AVSessionServiceTestSecond::TearDownTestCase()
123 {
124 }
125 
SetUp()126 void AVSessionServiceTestSecond::SetUp()
127 {
128     SLOGI("set up test function in AVSessionServiceTestSecond");\
129     g_AVSessionService = new AVSessionService(OHOS::AVSESSION_SERVICE_ID);
130     g_AVSessionService->InitKeyEvent();
131 }
132 
TearDown()133 void AVSessionServiceTestSecond::TearDown()
134 {
135     SLOGI("tear down test function in AVSessionServiceTestSecond");
136     [[maybe_unused]] int32_t ret = AVSESSION_ERROR;
137     if (avsession_ != nullptr) {
138         ret = avsession_->Destroy();
139         avsession_ = nullptr;
140     }
141 }
142 
CreateSession()143 OHOS::sptr<AVSessionItem> AVSessionServiceTestSecond::CreateSession()
144 {
145     OHOS::AppExecFwk::ElementName elementName;
146     elementName.SetBundleName(g_testAnotherBundleName);
147     elementName.SetAbilityName(g_testAnotherAbilityName);
148     OHOS::sptr<AVSessionItem> avsessionHere =
149         g_AVSessionService->CreateSessionInner(g_testSessionTag, AVSession::SESSION_TYPE_AUDIO, false, elementName);
150     return avsessionHere;
151 }
152 
153 /**
154 * @tc.name: IsParamInvalid001
155 * @tc.desc: Verifying IsParamInvalid with an empty tag.
156 * @tc.type: FUNC
157 * @tc.require: #I5Y4MZ
158 */
159 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid001, TestSize.Level1)
160 {
161     SLOGD("IsParamInvalid001 begin!");
162     std::string tag = "";
163     int32_t type = AVSession::SESSION_TYPE_AUDIO;
164     OHOS::AppExecFwk::ElementName elementName;
165     elementName.SetBundleName(g_testAnotherBundleName);
166     elementName.SetAbilityName(g_testAnotherAbilityName);
167     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
168     EXPECT_FALSE(result);
169     SLOGD("IsParamInvalid001 end!");
170 }
171 
172 /**
173 * @tc.name: IsParamInvalid002
174 * @tc.desc: Verifying IsParamInvalid with an invalid session type.
175 * @tc.type: FUNC
176 * @tc.require: #I5Y4MZ
177 */
178 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid002, TestSize.Level1)
179 {
180     SLOGD("IsParamInvalid002 begin!");
181     std::string tag = "testTag";
182     int32_t type = AVSession::SESSION_TYPE_INVALID;
183     OHOS::AppExecFwk::ElementName elementName;
184     elementName.SetBundleName("com.example.bundle");
185     elementName.SetAbilityName("com.example.ability");
186     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
187     EXPECT_FALSE(result);
188     SLOGD("IsParamInvalid002 end!");
189 }
190 
191 /**
192 * @tc.name: IsParamInvalid003
193 * @tc.desc: Verifying IsParamInvalid with an empty bundle name.
194 * @tc.type: FUNC
195 * @tc.require: #I5Y4MZ
196 */
197 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid003, TestSize.Level1)
198 {
199     SLOGD("IsParamInvalid003 begin!");
200     std::string tag = "testTag";
201     int32_t type = AVSession::SESSION_TYPE_AUDIO;
202     OHOS::AppExecFwk::ElementName elementName;
203     elementName.SetBundleName("");
204     elementName.SetAbilityName(g_testAnotherAbilityName);
205     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
206     EXPECT_FALSE(result);
207     SLOGD("IsParamInvalid003 end!");
208 }
209 
210 /**
211 * @tc.name: IsParamInvalid004
212 * @tc.desc: Verifying IsParamInvalid with an empty ability name.
213 * @tc.type: FUNC
214 * @tc.require: #I5Y4MZ
215 */
216 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid004, TestSize.Level1)
217 {
218     SLOGD("IsParamInvalid004 begin!");
219     std::string tag = "testTag";
220     int32_t type = AVSession::SESSION_TYPE_AUDIO;
221     OHOS::AppExecFwk::ElementName elementName;
222     elementName.SetBundleName(g_testAnotherBundleName);
223     elementName.SetAbilityName("");
224     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
225     EXPECT_FALSE(result);
226     SLOGD("IsParamInvalid004 end!");
227 }
228 
229 /**
230 * @tc.name: IsLocalDevice001
231 * @tc.desc: Verifying IsLocalDevice with a valid local network ID.
232 * @tc.type: FUNC
233 * @tc.require: #I5Y4MZ
234 */
235 static HWTEST_F(AVSessionServiceTestSecond, IsLocalDevice001, TestSize.Level1)
236 {
237     SLOGD("IsLocalDevice001 begin!");
238     const std::string networkId = "LocalDevice";
239     bool result = g_AVSessionService->IsLocalDevice(networkId);
240     EXPECT_TRUE(result);
241     SLOGD("IsLocalDevice001 end!");
242 }
243 
244 /**
245 * @tc.name: GetDeviceInfo002
246 * @tc.desc: Verifying GetDeviceInfo with a valid session item and descriptors.
247 * @tc.type: FUNC
248 * @tc.require: #I5Y4MZ
249 */
250 static HWTEST_F(AVSessionServiceTestSecond, GetDeviceInfo002, TestSize.Level1)
251 {
252     SLOGI("GetDeviceInfo002 begin!");
253     std::shared_ptr<AVSessionDescriptor> histroyDescriptor = std::make_shared<AVSessionDescriptor>();
254     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*histroyDescriptor);
255     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
256         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
257             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
258     };
259     g_AVSessionService->SetDeviceInfo(descriptors, avsessionHere);
260     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
261     EXPECT_NE(avsessionHere, nullptr);
262     SLOGI("GetDeviceInfo002 end!");
263 }
264 
265 /**
266 * @tc.name: CastAudioProcess001
267 * @tc.desc: Verifying CastAudioProcess with a valid session item and descriptors.
268 * @tc.type: FUNC
269 * @tc.require: #I5Y4MZ
270 */
271 static HWTEST_F(AVSessionServiceTestSecond, CastAudioProcess001, TestSize.Level1)
272 {
273     SLOGI("CastAudioProcess001 begin!");
274     EXPECT_TRUE(g_AVSessionService != nullptr);
275     OHOS::AppExecFwk::ElementName elementName;
276     elementName.SetBundleName(g_testAnotherBundleName);
277     elementName.SetAbilityName(g_testAnotherAbilityName);
278     OHOS::sptr<AVSessionItem> avsessionHere = g_AVSessionService->CreateSessionInner(g_testSessionTag,
279         AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
280     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors;
281     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
282     const std::string  sourceSessionInfo = "123443";
283     auto ret = g_AVSessionService->CastAudioProcess(descriptors, sourceSessionInfo, avsessionHere);
284     EXPECT_EQ(ret, AVSESSION_SUCCESS);
285     SLOGI("CastAudioProcess001 end!");
286 }
287 
288 /**
289 * @tc.name: CastAudioProcess002
290 * @tc.desc: Verifying CastAudioProcess with a valid session item and descriptors.
291 * @tc.type: FUNC
292 * @tc.require: #I5Y4MZ
293 */
294 static HWTEST_F(AVSessionServiceTestSecond, CastAudioProcess002, TestSize.Level1)
295 {
296     SLOGI("CastAudioProcess002 begin!");
297     std::shared_ptr<AVSessionDescriptor> histroyDescriptor = std::make_shared<AVSessionDescriptor>();
298     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*histroyDescriptor);
299     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
300         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
301             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
302     };
303     g_AVSessionService->SetDeviceInfo(descriptors, avsessionHere);
304     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
305     EXPECT_NE(avsessionHere, nullptr);
306     const std::string  sourceSessionInfo = "123443";
307     auto ret = g_AVSessionService->CastAudioProcess(descriptors, sourceSessionInfo, avsessionHere);
308     EXPECT_EQ(ret, AVSESSION_SUCCESS);
309     SLOGI("CastAudioProcess002 end!");
310 }
311 
312 /**
313 * @tc.name: CastAudioInner001
314 * @tc.desc: Verifying CastAudioInner with a valid session item and descriptors.
315 * @tc.type: FUNC
316 * @tc.require: #I5Y4MZ
317 */
318 static HWTEST_F(AVSessionServiceTestSecond, CastAudioInner001, TestSize.Level1)
319 {
320     SLOGI("CastAudioInner001 begin!");
321     EXPECT_TRUE(g_AVSessionService != nullptr);
322     std::shared_ptr<AVSessionDescriptor> histroyDescriptor = std::make_shared<AVSessionDescriptor>();
323     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*histroyDescriptor);
324     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
325         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
326             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
327     };
328     const std::string  sourceSessionInfo = "123443";
329     auto ret = g_AVSessionService->CastAudioInner(descriptors, sourceSessionInfo, avsessionHere);
330     EXPECT_EQ(ret, AVSESSION_ERROR);
331     SLOGI("CastAudioInner001 end!");
332 }
333 
334 /**
335 * @tc.name: CancelCastAudioInner001
336 * @tc.desc: Verifying CancelCastAudioInner with a valid session item and descriptors.
337 * @tc.type: FUNC
338 * @tc.require: #I5Y4MZ
339 */
340 static HWTEST_F(AVSessionServiceTestSecond, CancelCastAudioInner001, TestSize.Level1)
341 {
342     SLOGI("CancelCastAudioInner001 begin!");
343     EXPECT_TRUE(g_AVSessionService != nullptr);
344     OHOS::AppExecFwk::ElementName elementName;
345     elementName.SetBundleName(g_testAnotherBundleName);
346     elementName.SetAbilityName(g_testAnotherAbilityName);
347     OHOS::sptr<AVSessionItem> avsessionHere = g_AVSessionService->CreateSessionInner(g_testSessionTag,
348         AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
349     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
350         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
351             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
352     };
353     const std::string  sourceSessionInfo = "123443";
354     auto ret = g_AVSessionService->CancelCastAudioInner(descriptors, sourceSessionInfo, avsessionHere);
355     EXPECT_EQ(ret, AVSESSION_SUCCESS);
356     SLOGI("CancelCastAudioInner001 end!");
357 }
358 
359 /**
360 * @tc.name: CastAudioForAll001
361 * @tc.desc: Verifying CastAudioForAll with valid descriptors.
362 * @tc.type: FUNC
363 * @tc.require: #I5Y4MZ
364 */
365 static HWTEST_F(AVSessionServiceTestSecond, CastAudioForAll001, TestSize.Level1)
366 {
367     SLOGI("CastAudioForAll001 begin!");
368     EXPECT_TRUE(g_AVSessionService != nullptr);
369     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
370         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
371             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
372     };
373     auto ret = g_AVSessionService->CastAudioForAll(descriptors);
374     EXPECT_EQ(ret, AVSESSION_ERROR);
375     SLOGI("CastAudioForAll001 end!");
376 }
377 
378 /**
379 * @tc.name: ClearControllerForClientDiedNoLock002
380 * @tc.desc: Verifying ClearControllerForClientDiedNoLock with a valid PID.
381 * @tc.type: FUNC
382 * @tc.require: #I5Y4MZ
383 */
384 static HWTEST_F(AVSessionServiceTestSecond, ClearControllerForClientDiedNoLock002, TestSize.Level1)
385 {
386     SLOGI("ClearControllerForClientDiedNoLock002 begin!");
387     EXPECT_TRUE(g_AVSessionService != nullptr);
388     pid_t pid = 1234;
389     g_AVSessionService->ClearControllerForClientDiedNoLock(pid);
390     EXPECT_TRUE(g_AVSessionService != nullptr);
391     SLOGI("ClearControllerForClientDiedNoLock002 end!");
392 }
393 
394 /**
395 * @tc.name: CheckAndCreateDir001
396 * @tc.desc: Verifying CheckAndCreateDir with a valid file path.
397 * @tc.type: FUNC
398 * @tc.require: #I5Y4MZ
399 */
400 static HWTEST_F(AVSessionServiceTestSecond, CheckAndCreateDir001, TestSize.Level1)
401 {
402     SLOGI("CheckAndCreateDir001 begin!");
403     EXPECT_TRUE(g_AVSessionService != nullptr);
404     const string filePath = "/data/path";
405     bool ret = g_AVSessionService->CheckAndCreateDir(filePath);
406     EXPECT_TRUE(ret);
407     SLOGI("CheckAndCreateDir001 end!");
408 }
409 
410 /**
411 * @tc.name: SaveStringToFileEx001
412 * @tc.desc: Verifying SaveStringToFileEx with a valid file path and content.
413 * @tc.type: FUNC
414 * @tc.require: #I5Y4MZ
415 */
416 static HWTEST_F(AVSessionServiceTestSecond, SaveStringToFileEx001, TestSize.Level1)
417 {
418     SLOGI("SaveStringToFileEx001 begin!");
419     std::string filePath =  "uripath";
420     std::string content = "123456";
421     bool ret = g_AVSessionService->SaveStringToFileEx(filePath, content);
422     EXPECT_EQ(ret, true);
423     SLOGI("SaveStringToFileEx001 end!");
424 }
425 
426 /**
427 * @tc.name: SaveStringToFileEx002
428 * @tc.desc: Verifying SaveStringToFileEx with an empty content.
429 * @tc.type: FUNC
430 * @tc.require: #I5Y4MZ
431 */
432 static HWTEST_F(AVSessionServiceTestSecond, SaveStringToFileEx002, TestSize.Level1)
433 {
434     SLOGI("SaveStringToFileEx002 begin!");
435     OHOS::AppExecFwk::ElementName elementName;
436     elementName.SetBundleName(g_testAnotherBundleName);
437     elementName.SetAbilityName(g_testAnotherAbilityName);
438     OHOS::sptr<AVSessionItem> avsessionItem = g_AVSessionService->CreateSessionInner(g_testSessionTag,
439         AVSession::SESSION_TYPE_AUDIO, false, elementName);
440 
441     std::string filePath = g_AVSessionService->GetAVSortDir();
442     std::string content = "";
443     bool ret = g_AVSessionService->SaveStringToFileEx(filePath, content);
444     EXPECT_EQ(ret, false);
445     SLOGI("SaveStringToFileEx002 end!");
446 }
447 
448 /**
449 * @tc.name: RemoveExpired001
450 * @tc.desc: Verifying RemoveExpired with an expired time point.
451 * @tc.type: FUNC
452 * @tc.require: #I5Y4MZ
453 */
454 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired001, TestSize.Level1)
455 {
456     SLOGD("RemoveExpired001 begin!");
457     std::list<std::chrono::system_clock::time_point> timeList;
458     auto now = std::chrono::system_clock::now();
459     int32_t timeThreshold = 5;
460     timeList.push_back(now - std::chrono::seconds(10));
461     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
462 
463     EXPECT_TRUE(timeList.empty());
464     SLOGD("RemoveExpired001 end!");
465 }
466 
467 /**
468 * @tc.name: RemoveExpired002
469 * @tc.desc: Verifying RemoveExpired with a non-expired time point.
470 * @tc.type: FUNC
471 * @tc.require: #I5Y4MZ
472 */
473 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired002, TestSize.Level1)
474 {
475     SLOGD("RemoveExpired002 begin!");
476     std::list<std::chrono::system_clock::time_point> timeList;
477     auto now = std::chrono::system_clock::now();
478     int32_t timeThreshold = 5;
479     timeList.push_back(now - std::chrono::seconds(3));
480 
481     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
482     EXPECT_EQ(timeList.size(), 1);
483     SLOGD("RemoveExpired002 end!");
484 }
485 
486 /**
487 * @tc.name: RemoveExpired003
488 * @tc.desc: Verifying RemoveExpired with an empty time list.
489 * @tc.type: FUNC
490 * @tc.require: #I5Y4MZ
491 */
492 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired003, TestSize.Level1)
493 {
494     SLOGD("RemoveExpired003 begin!");
495     std::list<std::chrono::system_clock::time_point> timeList;
496     auto now = std::chrono::system_clock::now();
497     int32_t timeThreshold = 5;
498     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
499     EXPECT_TRUE(timeList.empty());
500     SLOGD("RemoveExpired003 end!");
501 }
502 
503 /**
504 * @tc.name: NotifyFlowControl001
505 * @tc.desc: Verifying NotifyFlowControl with a full flow control list.
506 * @tc.type: FUNC
507 * @tc.require: #I5Y4MZ
508 */
509 static HWTEST_F(AVSessionServiceTestSecond, NotifyFlowControl001, TestSize.Level1)
510 {
511     SLOGD("NotifyFlowControl001 begin!");
512     g_AVSessionService->flowControlPublishTimestampList_.clear();
513     const size_t count = 3;
514     for (size_t i = 0; i < count; ++i) {
515         g_AVSessionService->flowControlPublishTimestampList_.push_back(std::chrono::system_clock::now());
516     }
517     bool result = g_AVSessionService->NotifyFlowControl();
518     EXPECT_TRUE(result);
519     EXPECT_EQ(g_AVSessionService->flowControlPublishTimestampList_.size(), count);
520     SLOGD("NotifyFlowControl001 end!");
521 }
522 
523 /**
524 * @tc.name: NotifyFlowControl002
525 * @tc.desc: Verifying NotifyFlowControl with a non-full flow control list.
526 * @tc.type: FUNC
527 * @tc.require: #I5Y4MZ
528 */
529 static HWTEST_F(AVSessionServiceTestSecond, NotifyFlowControl002, TestSize.Level1)
530 {
531     SLOGD("NotifyFlowControl002 begin!");
532     const size_t count = 3;
533     g_AVSessionService->flowControlPublishTimestampList_.clear();
534     for (size_t i = 0; i < count - 1; ++i) {
535         g_AVSessionService->flowControlPublishTimestampList_.push_back(std::chrono::system_clock::now());
536     }
537     bool result = g_AVSessionService->NotifyFlowControl();
538     EXPECT_FALSE(result);
539     SLOGD("NotifyFlowControl002 end!");
540 }
541 
542 /**
543 * @tc.name: NotifyRemoteDistributedSessionControllersChanged001
544 * @tc.desc: Verifying NotifyRemoteDistributedSessionControllersChanged with a valid session controller.
545 * @tc.type: FUNC
546 * @tc.require: #I5Y4MZ
547 */
548 static HWTEST_F(AVSessionServiceTestSecond, NotifyRemoteDistributedSessionControllersChanged001, TestSize.Level1)
549 {
550     SLOGD("NotifyRemoteDistributedSessionControllersChanged001 begin!");
551     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
552     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
553     OHOS::sptr<OHOS::ISystemAbilityManager> mgr =
554         OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
555     EXPECT_TRUE(mgr != nullptr);
556     OHOS::sptr<IRemoteObject> obj = mgr->GetSystemAbility(OHOS::AVSESSION_SERVICE_ID);
557     sessionControllers.push_back(obj);
558     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
559     EXPECT_TRUE(g_AVSessionService != nullptr);
560     SLOGD("NotifyRemoteDistributedSessionControllersChanged001 end!");
561 }
562 
563 static HWTEST_F(AVSessionServiceTestSecond, OnReceiveEvent004, TestSize.Level1)
564 {
565     SLOGI("OnReceiveEvent004 begin!");
566     OHOS::EventFwk::CommonEventData eventData;
567     string action = OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
568     OHOS::AAFwk::Want want = eventData.GetWant();
569     want.SetAction(action);
570     eventData.SetWant(want);
571     OHOS::EventFwk::MatchingSkills matchingSkills;
572     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
573     EventSubscriber eventSubscriber(subscriberInfo, nullptr);
574     eventSubscriber.OnReceiveEvent(eventData);
575     EXPECT_EQ(0, AVSESSION_SUCCESS);
576     SLOGI("OnReceiveEvent004 end!");
577 }
578 
579 /**
580 * @tc.name: OnIdleWithSessions002
581 * @tc.desc: Verifying the OnIdle method with none zero count sessions.
582 * @tc.type: FUNC
583 * @tc.require: #I5Y4MZ
584 */
585 static HWTEST_F(AVSessionServiceTestSecond, OnIdleWithSessions002, TestSize.Level1)
586 {
587     SLOGD("OnIdleWithSessions002 begin!");
588     OHOS::sptr<AVSessionItem> item = nullptr;
589     g_AVSessionService->GetUsersManager().GetContainerFromAll().AddSession(getpid(), g_testAnotherAbilityName, item);
590     const OHOS::SystemAbilityOnDemandReason idleReason(
591         OHOS::OnDemandReasonId::INTERFACE_CALL, "INTERFACE_CALL", "TestValue", 12345);
592     int32_t result = g_AVSessionService->OnIdle(idleReason);
593     EXPECT_EQ(result, AVSESSION_ERROR);
594     SLOGD("OnIdleWithSessions002 end!");
595 }
596 
597 /**
598 * @tc.name: OnAddSystemAbility002
599 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is MULTIMODAL_INPUT_SERVICE_ID.
600 * @tc.type: FUNC
601 * @tc.require: #I5Y4MZ
602 */
603 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility002, TestSize.Level1)
604 {
605     SLOGD("OnAddSystemAbility002 begin!");
606     std::shared_ptr<AVSessionDescriptor> histroyDescriptor = std::make_shared<AVSessionDescriptor>();
607     g_AVSessionService->topSession_ = OHOS::sptr<AVSessionItem>::MakeSptr(*histroyDescriptor);
608 
609     int32_t systemAbilityId = OHOS::MULTIMODAL_INPUT_SERVICE_ID;
610     const std::string deviceId = "AUDIO";
611     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
612     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
613     SLOGD("OnAddSystemAbility002 end!");
614 }
615 
616 /**
617 * @tc.name: OnAddSystemAbility003
618 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is AUDIO_POLICY_SERVICE_ID.
619 * @tc.type: FUNC
620 * @tc.require: #I5Y4MZ
621 */
622 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility003, TestSize.Level1)
623 {
624     SLOGD("OnAddSystemAbility003 begin!");
625     int32_t systemAbilityId = OHOS::AUDIO_POLICY_SERVICE_ID;
626     const std::string deviceId = "AUDIO";
627     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
628     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
629     SLOGD("OnAddSystemAbility003 end!");
630 }
631 
632 /**
633 * @tc.name: OnAddSystemAbility004
634 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is APP_MGR_SERVICE_ID.
635 * @tc.type: FUNC
636 * @tc.require: #I5Y4MZ
637 */
638 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility004, TestSize.Level1)
639 {
640     SLOGD("OnAddSystemAbility004 begin!");
641     int32_t systemAbilityId = OHOS::APP_MGR_SERVICE_ID;
642     const std::string deviceId = "AUDIO";
643     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
644     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
645     SLOGD("OnAddSystemAbility004 end!");
646 }
647 
648 /**
649 * @tc.name: OnAddSystemAbility005
650 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID.
651 * @tc.type: FUNC
652 * @tc.require: #I5Y4MZ
653 */
654 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility005, TestSize.Level1)
655 {
656     SLOGD("OnAddSystemAbility005 begin!");
657     int32_t systemAbilityId = OHOS::DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID;
658     const std::string deviceId = "AUDIO";
659     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
660     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
661     SLOGD("OnAddSystemAbility005 end!");
662 }
663 
664 /**
665 * @tc.name: OnAddSystemAbility006
666 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is BUNDLE_MGR_SERVICE_SYS_ABILITY_ID.
667 * @tc.type: FUNC
668 * @tc.require: #I5Y4MZ
669 */
670 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility006, TestSize.Level1)
671 {
672     SLOGD("OnAddSystemAbility006 begin!");
673     int32_t systemAbilityId = OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID;
674     const std::string deviceId = "AUDIO";
675     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
676     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
677     SLOGD("OnAddSystemAbility006 end!");
678 }
679 
680 /**
681 * @tc.name: OnAddSystemAbility007
682 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is COLLABORATION_SA_ID.
683 * @tc.type: FUNC
684 * @tc.require: #I5Y4MZ
685 */
686 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility007, TestSize.Level1)
687 {
688     SLOGD("OnAddSystemAbility007 begin!");
689     int32_t systemAbilityId = COLLABORATION_SA_ID;
690     const std::string deviceId = "AUDIO";
691     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
692     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
693     SLOGD("OnAddSystemAbility007 end!");
694 }
695 
696 /**
697 * @tc.name: OnAddSystemAbility008
698 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is MEMORY_MANAGER_SA_ID.
699 * @tc.type: FUNC
700 * @tc.require: #I5Y4MZ
701 */
702 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility008, TestSize.Level1)
703 {
704     SLOGD("OnAddSystemAbility008 begin!");
705     int32_t systemAbilityId = OHOS::MEMORY_MANAGER_SA_ID;
706     const std::string deviceId = "AUDIO";
707     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
708     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
709     SLOGD("OnAddSystemAbility008 end!");
710 }
711 
712 /**
713 * @tc.name: OnAddSystemAbility009
714 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN.
715 * @tc.type: FUNC
716 * @tc.require: #I5Y4MZ
717 */
718 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility009, TestSize.Level1)
719 {
720     SLOGD("OnAddSystemAbility009 begin!");
721     int32_t systemAbilityId = OHOS::SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN;
722     const std::string deviceId = "AUDIO";
723     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
724     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
725     SLOGD("OnAddSystemAbility009 end!");
726 }
727 
728 /**
729 * @tc.name: OnAddSystemAbility010
730 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is COMMON_EVENT_SERVICE_ID.
731 * @tc.type: FUNC
732 * @tc.require: #I5Y4MZ
733 */
734 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility010, TestSize.Level1)
735 {
736     SLOGD("OnAddSystemAbility010 begin!");
737     int32_t systemAbilityId = OHOS::COMMON_EVENT_SERVICE_ID;
738     const std::string deviceId = "AUDIO";
739     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
740     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
741     SLOGD("OnAddSystemAbility010 end!");
742 }
743 
744 /**
745 * @tc.name: OnAddSystemAbility011
746 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is CAST_ENGINE_SA_ID.
747 * @tc.type: FUNC
748 * @tc.require: #I5Y4MZ
749 */
750 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility011, TestSize.Level1)
751 {
752     SLOGD("OnAddSystemAbility011 begin!");
753 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
754     int32_t systemAbilityId = CAST_ENGINE_SA_ID;
755     const std::string deviceId = "AUDIO";
756     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
757     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
758 #else
759     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
760 #endif
761     SLOGD("OnAddSystemAbility011 end!");
762 }
763 
764 /**
765 * @tc.name: OnAddSystemAbility012
766 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is CAST_ENGINE_SA_ID and is2in1_ is true.
767 * @tc.type: FUNC
768 * @tc.require: #I5Y4MZ
769 */
770 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility012, TestSize.Level1)
771 {
772     SLOGD("OnAddSystemAbility012 begin!");
773 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
774     int32_t systemAbilityId = CAST_ENGINE_SA_ID;
775     const std::string deviceId = "AUDIO";
776     g_AVSessionService->is2in1_ = true;
777     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
778     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
779 #else
780     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
781 #endif
782     SLOGD("OnAddSystemAbility012 end!");
783 }
784 
785 /**
786 * @tc.name: InitBMS002
787 * @tc.desc: Verifying the InitBMS method with invalid userid.
788 * @tc.type: FUNC
789 * @tc.require: #I5Y4MZ
790 */
791 static HWTEST_F(AVSessionServiceTestSecond, InitBMS002, TestSize.Level1)
792 {
793     SLOGD("InitBMS002 begin!");
794     std::shared_ptr<AVSessionDescriptor> histroyDescriptor = std::make_shared<AVSessionDescriptor>();
795     g_AVSessionService->topSession_ = OHOS::sptr<AVSessionItem>::MakeSptr(*histroyDescriptor);
796     g_AVSessionService->GetUsersManager().curUserId_ = -1;
797     g_AVSessionService->InitBMS();
798     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
799     SLOGD("InitBMS002 end!");
800 }
801 
802 /**
803 * @tc.name: NotifySessionCreate001
804 * @tc.desc: Verifying the NotifySessionCreate method with listener.
805 * @tc.type: FUNC
806 * @tc.require: #I5Y4MZ
807 */
808 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate001, TestSize.Level1)
809 {
810     SLOGD("NotifySessionCreate001 begin!");
811     AVSessionDescriptor aVSessionDescriptor;
812     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
813     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
814     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
815     EXPECT_EQ(g_isCallOnSessionCreate, true);
816     SLOGD("NotifySessionCreate001 end!");
817 }
818 
819 /**
820 * @tc.name: NotifySessionCreate002
821 * @tc.desc: Verifying the NotifySessionCreate method with nullptr listener.
822 * @tc.type: FUNC
823 * @tc.require: #I5Y4MZ
824 */
825 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate002, TestSize.Level1)
826 {
827     SLOGD("NotifySessionCreate002 begin!");
828     AVSessionDescriptor aVSessionDescriptor;
829     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
830     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
831     EXPECT_EQ(g_isCallOnSessionCreate, true);
832     SLOGD("NotifySessionCreate002 end!");
833 }
834 
835 /**
836 * @tc.name: NotifySessionCreate003
837 * @tc.desc: Verifying the NotifySessionCreate method with listener.
838 * @tc.type: FUNC
839 * @tc.require: #I5Y4MZ
840 */
841 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate003, TestSize.Level1)
842 {
843     SLOGD("NotifySessionCreate003 begin!");
844     AVSessionDescriptor aVSessionDescriptor;
845     TestSessionListener* listener = new TestSessionListener();
846     g_AVSessionService->innerSessionListeners_.push_back(listener);
847     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
848     EXPECT_EQ(g_isCallOnSessionCreate, true);
849     if (listener != nullptr) {
850         delete listener;
851         listener = nullptr;
852     }
853     SLOGD("NotifySessionCreate003 end!");
854 }
855 
856 /**
857 * @tc.name: NotifySessionCreate004
858 * @tc.desc: Verifying the NotifySessionCreate method with null listener.
859 * @tc.type: FUNC
860 * @tc.require: #I5Y4MZ
861 */
862 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate004, TestSize.Level1)
863 {
864     SLOGD("NotifySessionCreate004 begin!");
865     AVSessionDescriptor aVSessionDescriptor;
866     g_AVSessionService->innerSessionListeners_.push_back(nullptr);
867     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
868     EXPECT_EQ(g_isCallOnSessionCreate, true);
869     SLOGD("NotifySessionCreate004 end!");
870 }
871 
872 /**
873 * @tc.name: NotifyTopSessionChanged001
874 * @tc.desc: Verifying the NotifyTopSessionChanged method with listener.
875 * @tc.type: FUNC
876 * @tc.require: #I5Y4MZ
877 */
878 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged001, TestSize.Level1)
879 {
880     SLOGD("NotifyTopSessionChanged001 begin!");
881     AVSessionDescriptor aVSessionDescriptor;
882     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
883     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
884     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
885     EXPECT_EQ(g_isCallOnTopSessionChange, true);
886     SLOGD("NotifyTopSessionChanged001 end!");
887 }
888 
889 /**
890 * @tc.name: NotifyTopSessionChanged002
891 * @tc.desc: Verifying the NotifyTopSessionChanged method with nullptr listener.
892 * @tc.type: FUNC
893 * @tc.require: #I5Y4MZ
894 */
895 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged002, TestSize.Level1)
896 {
897     SLOGD("NotifyTopSessionChanged002 begin!");
898     AVSessionDescriptor aVSessionDescriptor;
899     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
900     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
901     EXPECT_EQ(g_isCallOnTopSessionChange, true);
902     SLOGD("NotifyTopSessionChanged002 end!");
903 }
904 
905 /**
906 * @tc.name: NotifyTopSessionChanged003
907 * @tc.desc: Verifying the NotifySessionCreate method with null listener.
908 * @tc.type: FUNC
909 * @tc.require: #I5Y4MZ
910 */
911 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged003, TestSize.Level1)
912 {
913     SLOGD("NotifyTopSessionChanged003 begin!");
914     AVSessionDescriptor aVSessionDescriptor;
915     g_AVSessionService->innerSessionListeners_.push_back(nullptr);
916     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
917     EXPECT_EQ(g_isCallOnTopSessionChange, true);
918     SLOGD("NotifyTopSessionChanged003 end!");
919 }
920 
921 /**
922 * @tc.name: NotifySessionRelease001
923 * @tc.desc: Verifying the NotifySessionRelease method with listener.
924 * @tc.type: FUNC
925 * @tc.require: #I5Y4MZ
926 */
927 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease001, TestSize.Level1)
928 {
929     SLOGD("NotifySessionRelease001 begin!");
930     AVSessionDescriptor aVSessionDescriptor;
931     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
932     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
933     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
934     EXPECT_EQ(g_isCallOnSessionRelease, true);
935     SLOGD("NotifySessionRelease001 end!");
936 }
937 
938 /**
939 * @tc.name: NotifySessionRelease002
940 * @tc.desc: Verifying the NotifySessionRelease method with nullptr listener.
941 * @tc.type: FUNC
942 * @tc.require: #I5Y4MZ
943 */
944 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease002, TestSize.Level1)
945 {
946     SLOGD("NotifySessionRelease002 begin!");
947     AVSessionDescriptor aVSessionDescriptor;
948     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
949     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
950     EXPECT_EQ(g_isCallOnSessionRelease, true);
951     SLOGD("NotifySessionRelease002 end!");
952 }
953 
954 /**
955 * @tc.name: NotifySessionRelease003
956 * @tc.desc: Verifying the NotifySessionRelease method with listener.
957 * @tc.type: FUNC
958 * @tc.require: #I5Y4MZ
959 */
960 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease003, TestSize.Level1)
961 {
962     SLOGD("NotifySessionRelease003 begin!");
963     AVSessionDescriptor aVSessionDescriptor;
964     TestSessionListener* listener = new TestSessionListener();
965     g_AVSessionService->innerSessionListeners_.push_back(listener);
966     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
967     EXPECT_EQ(g_isCallOnSessionRelease, true);
968     g_isCallOnSessionRelease = false;
969     if (listener != nullptr) {
970         delete listener;
971         listener = nullptr;
972     }
973     SLOGD("NotifySessionRelease003 end!");
974 }
975 
976 /**
977 * @tc.name: PlayStateCheck002
978 * @tc.desc: Verifying the PlayStateCheck method with valid parameters.
979 * @tc.type: FUNC
980 * @tc.require: #I5Y4MZ
981 */
982 static HWTEST_F(AVSessionServiceTestSecond, PlayStateCheck002, TestSize.Level1)
983 {
984     SLOGD("PlayStateCheck002 begin!");
985     auto avsessionHere = CreateSession();
986     ASSERT_TRUE(avsessionHere != nullptr);
987     avsessionHere->playbackState_.SetState(AVPlaybackState::PLAYBACK_STATE_PREPARE);
988     avsessionHere->SetUid(1);
989     avsessionHere->Activate();
990     g_AVSessionService->UpdateTopSession(avsessionHere);
991 
992     StreamUsage streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
993     RendererState rendererState = RendererState::RENDERER_RUNNING;
994     g_AVSessionService->PlayStateCheck(1, streamUsage, rendererState);
995     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
996     SLOGD("PlayStateCheck002 end!");
997 }
998