• 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 "avsession_sysevent.h"
24 #include "avmeta_data.h"
25 #include "avplayback_state.h"
26 #include "avsession_info.h"
27 #include "avsession_service.h"
28 #include "audio_info.h"
29 #include "client_death_proxy.h"
30 #include "system_ability_definition.h"
31 #include "system_ability_ondemand_reason.h"
32 
33 using namespace testing::ext;
34 using namespace OHOS::AVSession;
35 using namespace OHOS::AudioStandard;
36 
37 namespace OHOS {
38 namespace AVSession {
39 
40 static AVMetaData g_metaData;
41 static AVPlaybackState g_playbackState;
42 static char g_testSessionTag[] = "test";
43 static char g_testAnotherBundleName[] = "testAnother.ohos.avsession";
44 static char g_testAnotherAbilityName[] = "testAnother.ability";
45 static OHOS::sptr<AVSessionService> g_AVSessionService {nullptr};
46 static const int32_t COLLABORATION_SA_ID = 70633;
47 static const int32_t CAST_ENGINE_SA_ID = 65546;
48 static const int32_t AVSESSION_CONTINUE = 1;
49 const int32_t KEYCODE_CLEAR = 5;
50 const int32_t KEYCODE_HEADSETHOOK = 6;
51 const int32_t KEYCODE_MEDIA_PLAY_PAUSE = 10;
52 static bool g_isCallOnSessionCreate = false;
53 static bool g_isCallOnSessionRelease = false;
54 static bool g_isCallOnTopSessionChange = false;
55 
56 #ifdef ENABLE_AVSESSION_SYSEVENT_CONTROL
57 static const int32_t REPORT_SIZE = 100;
58 static const int32_t CONTROL_COLD_START = 2;
59 #endif
60 
61 class TestISessionListener : public ISessionListener {
62     TestISessionListener() = default;
63     virtual ~TestISessionListener() = default;
OnSessionCreate(const AVSessionDescriptor & descriptor)64     ErrCode OnSessionCreate(const AVSessionDescriptor& descriptor) override
65     {
66         g_isCallOnSessionCreate = true;
67         return AVSESSION_SUCCESS;
68     };
OnSessionRelease(const AVSessionDescriptor & descriptor)69     ErrCode OnSessionRelease(const AVSessionDescriptor& descriptor) override
70     {
71         g_isCallOnSessionRelease = true;
72         return AVSESSION_SUCCESS;
73     };
OnTopSessionChange(const AVSessionDescriptor & descriptor)74     ErrCode OnTopSessionChange(const AVSessionDescriptor& descriptor) override
75     {
76         g_isCallOnTopSessionChange = true;
77         return AVSESSION_SUCCESS;
78     };
OnAudioSessionChecked(const int32_t uid)79     ErrCode OnAudioSessionChecked(const int32_t uid) override
80     {
81         return AVSESSION_SUCCESS;
82     };
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)83     ErrCode OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) override
84     {
85         return AVSESSION_SUCCESS;
86     };
OnDeviceLogEvent(const int32_t eventId,const int64_t param)87     ErrCode OnDeviceLogEvent(const int32_t eventId, const int64_t param) override
88     {
89         return AVSESSION_SUCCESS;
90     };
OnDeviceOffline(const std::string & deviceId)91     ErrCode OnDeviceOffline(const std::string& deviceId) override
92     {
93         return AVSESSION_SUCCESS;
94     };
OnDeviceStateChange(const DeviceState & deviceState)95     ErrCode OnDeviceStateChange(const DeviceState& deviceState) override
96     {
97         g_isCallOnTopSessionChange = true;
98         return AVSESSION_SUCCESS;
99     };
OnRemoteDistributedSessionChange(const std::vector<OHOS::sptr<IRemoteObject>> & sessionControllers)100     ErrCode OnRemoteDistributedSessionChange(
101         const std::vector<OHOS::sptr<IRemoteObject>>& sessionControllers) override
102     {
103         return AVSESSION_SUCCESS;
104     };
AsObject()105     OHOS::sptr<IRemoteObject> AsObject() override { return nullptr; };
106 };
107 
108 class TestSessionListener : public SessionListener {
109     TestSessionListener() = default;
110     virtual ~TestSessionListener() = default;
111     void OnSessionCreate(const AVSessionDescriptor& descriptor) override;
112     void OnSessionRelease(const AVSessionDescriptor& descriptor) override;
113     void OnTopSessionChange(const AVSessionDescriptor& descriptor) override;
OnAudioSessionChecked(const int32_t uid)114     void OnAudioSessionChecked(const int32_t uid) override {};
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)115     void OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) override {};
OnDeviceLogEvent(const DeviceLogEventCode eventId,const int64_t param)116     void OnDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override {};
OnDeviceOffline(const std::string & deviceId)117     void OnDeviceOffline(const std::string& deviceId) override {};
OnRemoteDistributedSessionChange(const std::vector<OHOS::sptr<IRemoteObject>> & sessionControllers)118     void OnRemoteDistributedSessionChange(
119         const std::vector<OHOS::sptr<IRemoteObject>>& sessionControllers) override {};
120 };
121 
OnSessionCreate(const AVSessionDescriptor & descriptor)122 void TestSessionListener::OnSessionCreate(const AVSessionDescriptor& descriptor)
123 {
124     g_isCallOnSessionCreate = true;
125 }
126 
OnSessionRelease(const AVSessionDescriptor & descriptor)127 void TestSessionListener::OnSessionRelease(const AVSessionDescriptor& descriptor)
128 {
129     g_isCallOnSessionRelease = true;
130 }
131 
OnTopSessionChange(const AVSessionDescriptor & descriptor)132 void TestSessionListener::OnTopSessionChange(const AVSessionDescriptor& descriptor)
133 {
134     g_isCallOnTopSessionChange = true;
135 }
136 
137 
138 class TestIClientDeath : public IClientDeath {
139     TestIClientDeath() = default;
140     virtual ~TestIClientDeath() = default;
AsObject()141     OHOS::sptr<IRemoteObject> AsObject() override
142     {
143         OHOS::AppExecFwk::ElementName elementName;
144         elementName.SetBundleName(g_testAnotherBundleName);
145         elementName.SetAbilityName(g_testAnotherAbilityName);
146         OHOS::sptr<AVSessionItem> avsessionHere_ = g_AVSessionService->CreateSessionInner(
147             g_testSessionTag, AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
148         std::string sessionId = avsessionHere_->GetSessionId();
149         OHOS::sptr<IRemoteObject> object = nullptr;
150         g_AVSessionService->CreateControllerInner(sessionId, object);
151         return object;
152     }
153 };
154 
155 class AVSessionServiceTestSecond : public testing::Test {
156 public:
157     static void SetUpTestCase();
158     static void TearDownTestCase();
159     void SetUp() override;
160     void TearDown() override;
161 
162     OHOS::sptr<AVSessionItem> CreateSession();
163     std::shared_ptr<AVSession> avsession_ = nullptr;
164 };
165 
SetUpTestCase()166 void AVSessionServiceTestSecond::SetUpTestCase()
167 {
168     SLOGI("set up AVSessionServiceTestSecond");
169     system("killall -9 com.example.hiMusicDemo");
170 }
171 
TearDownTestCase()172 void AVSessionServiceTestSecond::TearDownTestCase()
173 {
174 }
175 
SetUp()176 void AVSessionServiceTestSecond::SetUp()
177 {
178     SLOGI("set up test function in AVSessionServiceTestSecond");\
179     g_AVSessionService = new AVSessionService(OHOS::AVSESSION_SERVICE_ID);
180     g_AVSessionService->InitKeyEvent();
181 }
182 
TearDown()183 void AVSessionServiceTestSecond::TearDown()
184 {
185     SLOGI("tear down test function in AVSessionServiceTestSecond");
186     [[maybe_unused]] int32_t ret = AVSESSION_ERROR;
187     if (avsession_ != nullptr) {
188         ret = avsession_->Destroy();
189         avsession_ = nullptr;
190     }
191 }
192 
CreateSession()193 OHOS::sptr<AVSessionItem> AVSessionServiceTestSecond::CreateSession()
194 {
195     OHOS::AppExecFwk::ElementName elementName;
196     elementName.SetBundleName(g_testAnotherBundleName);
197     elementName.SetAbilityName(g_testAnotherAbilityName);
198     OHOS::sptr<AVSessionItem> avsessionHere =
199         g_AVSessionService->CreateSessionInner(g_testSessionTag, AVSession::SESSION_TYPE_AUDIO, false, elementName);
200     return avsessionHere;
201 }
202 
203 /**
204 * @tc.name: IsParamInvalid001
205 * @tc.desc: Verifying IsParamInvalid with an empty tag.
206 * @tc.type: FUNC
207 * @tc.require: #I5Y4MZ
208 */
209 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid001, TestSize.Level0)
210 {
211     SLOGD("IsParamInvalid001 begin!");
212     std::string tag = "";
213     int32_t type = AVSession::SESSION_TYPE_AUDIO;
214     OHOS::AppExecFwk::ElementName elementName;
215     elementName.SetBundleName(g_testAnotherBundleName);
216     elementName.SetAbilityName(g_testAnotherAbilityName);
217     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
218     EXPECT_FALSE(result);
219     SLOGD("IsParamInvalid001 end!");
220 }
221 
222 /**
223 * @tc.name: IsParamInvalid002
224 * @tc.desc: Verifying IsParamInvalid with an invalid session type.
225 * @tc.type: FUNC
226 * @tc.require: #I5Y4MZ
227 */
228 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid002, TestSize.Level0)
229 {
230     SLOGD("IsParamInvalid002 begin!");
231     std::string tag = "testTag";
232     int32_t type = AVSession::SESSION_TYPE_INVALID;
233     OHOS::AppExecFwk::ElementName elementName;
234     elementName.SetBundleName("com.example.bundle");
235     elementName.SetAbilityName("com.example.ability");
236     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
237     EXPECT_FALSE(result);
238     SLOGD("IsParamInvalid002 end!");
239 }
240 
241 /**
242 * @tc.name: IsParamInvalid003
243 * @tc.desc: Verifying IsParamInvalid with an empty bundle name.
244 * @tc.type: FUNC
245 * @tc.require: #I5Y4MZ
246 */
247 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid003, TestSize.Level0)
248 {
249     SLOGD("IsParamInvalid003 begin!");
250     std::string tag = "testTag";
251     int32_t type = AVSession::SESSION_TYPE_AUDIO;
252     OHOS::AppExecFwk::ElementName elementName;
253     elementName.SetBundleName("");
254     elementName.SetAbilityName(g_testAnotherAbilityName);
255     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
256     EXPECT_FALSE(result);
257     SLOGD("IsParamInvalid003 end!");
258 }
259 
260 /**
261 * @tc.name: IsParamInvalid004
262 * @tc.desc: Verifying IsParamInvalid with an empty ability name.
263 * @tc.type: FUNC
264 * @tc.require: #I5Y4MZ
265 */
266 static HWTEST_F(AVSessionServiceTestSecond, IsParamInvalid004, TestSize.Level0)
267 {
268     SLOGD("IsParamInvalid004 begin!");
269     std::string tag = "testTag";
270     int32_t type = AVSession::SESSION_TYPE_AUDIO;
271     OHOS::AppExecFwk::ElementName elementName;
272     elementName.SetBundleName(g_testAnotherBundleName);
273     elementName.SetAbilityName("");
274     bool result = g_AVSessionService->IsParamInvalid(tag, type, elementName);
275     EXPECT_FALSE(result);
276     SLOGD("IsParamInvalid004 end!");
277 }
278 
279 /**
280 * @tc.name: IsLocalDevice001
281 * @tc.desc: Verifying IsLocalDevice with a valid local network ID.
282 * @tc.type: FUNC
283 * @tc.require: #I5Y4MZ
284 */
285 static HWTEST_F(AVSessionServiceTestSecond, IsLocalDevice001, TestSize.Level0)
286 {
287     SLOGD("IsLocalDevice001 begin!");
288     const std::string networkId = "LocalDevice";
289     bool result = g_AVSessionService->IsLocalDevice(networkId);
290     EXPECT_TRUE(result);
291     SLOGD("IsLocalDevice001 end!");
292 }
293 
294 /**
295 * @tc.name: GetDeviceInfo002
296 * @tc.desc: Verifying GetDeviceInfo with a valid session item and descriptors.
297 * @tc.type: FUNC
298 * @tc.require: #I5Y4MZ
299 */
300 static HWTEST_F(AVSessionServiceTestSecond, GetDeviceInfo002, TestSize.Level0)
301 {
302     SLOGI("GetDeviceInfo002 begin!");
303     ASSERT_TRUE(g_AVSessionService != nullptr);
304     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
305     ASSERT_TRUE(historyDescriptor != nullptr);
306     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
307     ASSERT_TRUE(avsessionHere != nullptr);
308     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
309         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
310             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
311     };
312     g_AVSessionService->SetDeviceInfo(descriptors, avsessionHere);
313     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
314     EXPECT_NE(avsessionHere, nullptr);
315     SLOGI("GetDeviceInfo002 end!");
316 }
317 
318 /**
319 * @tc.name: CastAudioProcess001
320 * @tc.desc: Verifying CastAudioProcess with a valid session item and descriptors.
321 * @tc.type: FUNC
322 * @tc.require: #I5Y4MZ
323 */
324 static HWTEST_F(AVSessionServiceTestSecond, CastAudioProcess001, TestSize.Level0)
325 {
326     SLOGI("CastAudioProcess001 begin!");
327     EXPECT_TRUE(g_AVSessionService != nullptr);
328     OHOS::AppExecFwk::ElementName elementName;
329     elementName.SetBundleName(g_testAnotherBundleName);
330     elementName.SetAbilityName(g_testAnotherAbilityName);
331     OHOS::sptr<AVSessionItem> avsessionHere = g_AVSessionService->CreateSessionInner(g_testSessionTag,
332         AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
333     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors;
334     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
335     const std::string  sourceSessionInfo = "123443";
336     auto ret = g_AVSessionService->CastAudioProcess(descriptors, sourceSessionInfo, avsessionHere);
337     EXPECT_EQ(ret, AVSESSION_SUCCESS);
338     SLOGI("CastAudioProcess001 end!");
339 }
340 
341 /**
342 * @tc.name: CastAudioProcess002
343 * @tc.desc: Verifying CastAudioProcess with a valid session item and descriptors.
344 * @tc.type: FUNC
345 * @tc.require: #I5Y4MZ
346 */
347 static HWTEST_F(AVSessionServiceTestSecond, CastAudioProcess002, TestSize.Level0)
348 {
349     SLOGI("CastAudioProcess002 begin!");
350     ASSERT_TRUE(g_AVSessionService != nullptr);
351     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
352     ASSERT_TRUE(historyDescriptor != nullptr);
353     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
354     ASSERT_TRUE(avsessionHere != nullptr);
355     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
356         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
357             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
358     };
359     g_AVSessionService->SetDeviceInfo(descriptors, avsessionHere);
360     g_AVSessionService->GetDeviceInfo(avsessionHere, descriptors, descriptors, descriptors);
361     EXPECT_NE(avsessionHere, nullptr);
362     const std::string  sourceSessionInfo = "123443";
363     auto ret = g_AVSessionService->CastAudioProcess(descriptors, sourceSessionInfo, avsessionHere);
364     EXPECT_EQ(ret, AVSESSION_SUCCESS);
365     SLOGI("CastAudioProcess002 end!");
366 }
367 
368 /**
369 * @tc.name: CastAudioInner001
370 * @tc.desc: Verifying CastAudioInner with a valid session item and descriptors.
371 * @tc.type: FUNC
372 * @tc.require: #I5Y4MZ
373 */
374 static HWTEST_F(AVSessionServiceTestSecond, CastAudioInner001, TestSize.Level0)
375 {
376     SLOGI("CastAudioInner001 begin!");
377     ASSERT_TRUE(g_AVSessionService != nullptr);
378     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
379     ASSERT_TRUE(historyDescriptor != nullptr);
380     auto avsessionHere = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
381     ASSERT_TRUE(avsessionHere != nullptr);
382     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
383         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
384             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
385     };
386     const std::string  sourceSessionInfo = "123443";
387     auto ret = g_AVSessionService->CastAudioInner(descriptors, sourceSessionInfo, avsessionHere);
388     EXPECT_EQ(ret, AVSESSION_ERROR);
389     SLOGI("CastAudioInner001 end!");
390 }
391 
392 /**
393 * @tc.name: CancelCastAudioInner001
394 * @tc.desc: Verifying CancelCastAudioInner with a valid session item and descriptors.
395 * @tc.type: FUNC
396 * @tc.require: #I5Y4MZ
397 */
398 static HWTEST_F(AVSessionServiceTestSecond, CancelCastAudioInner001, TestSize.Level0)
399 {
400     SLOGI("CancelCastAudioInner001 begin!");
401     EXPECT_TRUE(g_AVSessionService != nullptr);
402     OHOS::AppExecFwk::ElementName elementName;
403     elementName.SetBundleName(g_testAnotherBundleName);
404     elementName.SetAbilityName(g_testAnotherAbilityName);
405     OHOS::sptr<AVSessionItem> avsessionHere = g_AVSessionService->CreateSessionInner(g_testSessionTag,
406         AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
407     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
408         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
409             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
410     };
411     const std::string  sourceSessionInfo = "123443";
412     auto ret = g_AVSessionService->CancelCastAudioInner(descriptors, sourceSessionInfo, avsessionHere);
413     EXPECT_EQ(ret, AVSESSION_SUCCESS);
414     SLOGI("CancelCastAudioInner001 end!");
415 }
416 
417 /**
418 * @tc.name: CastAudioForAll001
419 * @tc.desc: Verifying CastAudioForAll with valid descriptors.
420 * @tc.type: FUNC
421 * @tc.require: #I5Y4MZ
422 */
423 static HWTEST_F(AVSessionServiceTestSecond, CastAudioForAll001, TestSize.Level0)
424 {
425     SLOGI("CastAudioForAll001 begin!");
426     EXPECT_TRUE(g_AVSessionService != nullptr);
427     std::vector<OHOS::AudioStandard::AudioDeviceDescriptor> descriptors = {
428         OHOS::AudioStandard::AudioDeviceDescriptor(OHOS::AudioStandard::DeviceType::DEVICE_TYPE_EARPIECE,
429             OHOS::AudioStandard::DeviceRole::INPUT_DEVICE, 1, 1, "LocalDevice")
430     };
431     auto ret = g_AVSessionService->CastAudioForAll(descriptors);
432     EXPECT_EQ(ret, AVSESSION_ERROR);
433     SLOGI("CastAudioForAll001 end!");
434 }
435 
436 /**
437 * @tc.name: ClearControllerForClientDiedNoLock002
438 * @tc.desc: Verifying ClearControllerForClientDiedNoLock with a valid PID.
439 * @tc.type: FUNC
440 * @tc.require: #I5Y4MZ
441 */
442 static HWTEST_F(AVSessionServiceTestSecond, ClearControllerForClientDiedNoLock002, TestSize.Level0)
443 {
444     SLOGI("ClearControllerForClientDiedNoLock002 begin!");
445     EXPECT_TRUE(g_AVSessionService != nullptr);
446     pid_t pid = 1234;
447     g_AVSessionService->ClearControllerForClientDiedNoLock(pid);
448     EXPECT_TRUE(g_AVSessionService != nullptr);
449     SLOGI("ClearControllerForClientDiedNoLock002 end!");
450 }
451 
452 /**
453 * @tc.name: CheckAndCreateDir001
454 * @tc.desc: Verifying CheckAndCreateDir with a valid file path.
455 * @tc.type: FUNC
456 * @tc.require: #I5Y4MZ
457 */
458 static HWTEST_F(AVSessionServiceTestSecond, CheckAndCreateDir001, TestSize.Level0)
459 {
460     SLOGI("CheckAndCreateDir001 begin!");
461     EXPECT_TRUE(g_AVSessionService != nullptr);
462     const string filePath = "/data/path";
463     bool ret = g_AVSessionService->CheckAndCreateDir(filePath);
464     EXPECT_TRUE(ret);
465     SLOGI("CheckAndCreateDir001 end!");
466 }
467 
468 /**
469 * @tc.name: SaveStringToFileEx001
470 * @tc.desc: Verifying SaveStringToFileEx with a valid file path and content.
471 * @tc.type: FUNC
472 * @tc.require: #I5Y4MZ
473 */
474 static HWTEST_F(AVSessionServiceTestSecond, SaveStringToFileEx001, TestSize.Level0)
475 {
476     SLOGI("SaveStringToFileEx001 begin!");
477     std::string filePath =  "uripath";
478     std::string content = "123456";
479     bool ret = g_AVSessionService->SaveStringToFileEx(filePath, content);
480     EXPECT_EQ(ret, true);
481     SLOGI("SaveStringToFileEx001 end!");
482 }
483 
484 /**
485 * @tc.name: SaveStringToFileEx002
486 * @tc.desc: Verifying SaveStringToFileEx with an empty content.
487 * @tc.type: FUNC
488 * @tc.require: #I5Y4MZ
489 */
490 static HWTEST_F(AVSessionServiceTestSecond, SaveStringToFileEx002, TestSize.Level0)
491 {
492     SLOGI("SaveStringToFileEx002 begin!");
493     OHOS::AppExecFwk::ElementName elementName;
494     elementName.SetBundleName(g_testAnotherBundleName);
495     elementName.SetAbilityName(g_testAnotherAbilityName);
496     OHOS::sptr<AVSessionItem> avsessionItem = g_AVSessionService->CreateSessionInner(g_testSessionTag,
497         AVSession::SESSION_TYPE_AUDIO, false, elementName);
498 
499     std::string filePath = g_AVSessionService->GetAVSortDir();
500     std::string content = "";
501     bool ret = g_AVSessionService->SaveStringToFileEx(filePath, content);
502     EXPECT_EQ(ret, false);
503     SLOGI("SaveStringToFileEx002 end!");
504 }
505 
506 /**
507 * @tc.name: RemoveExpired001
508 * @tc.desc: Verifying RemoveExpired with an expired time point.
509 * @tc.type: FUNC
510 * @tc.require: #I5Y4MZ
511 */
512 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired001, TestSize.Level0)
513 {
514     SLOGD("RemoveExpired001 begin!");
515     std::list<std::chrono::system_clock::time_point> timeList;
516     auto now = std::chrono::system_clock::now();
517     int32_t timeThreshold = 5;
518     timeList.push_back(now - std::chrono::seconds(10));
519     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
520 
521     EXPECT_TRUE(timeList.empty());
522     SLOGD("RemoveExpired001 end!");
523 }
524 
525 /**
526 * @tc.name: RemoveExpired002
527 * @tc.desc: Verifying RemoveExpired with a non-expired time point.
528 * @tc.type: FUNC
529 * @tc.require: #I5Y4MZ
530 */
531 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired002, TestSize.Level0)
532 {
533     SLOGD("RemoveExpired002 begin!");
534     std::list<std::chrono::system_clock::time_point> timeList;
535     auto now = std::chrono::system_clock::now();
536     int32_t timeThreshold = 5;
537     timeList.push_back(now - std::chrono::seconds(3));
538 
539     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
540     EXPECT_EQ(timeList.size(), 1);
541     SLOGD("RemoveExpired002 end!");
542 }
543 
544 /**
545 * @tc.name: RemoveExpired003
546 * @tc.desc: Verifying RemoveExpired with an empty time list.
547 * @tc.type: FUNC
548 * @tc.require: #I5Y4MZ
549 */
550 static HWTEST_F(AVSessionServiceTestSecond, RemoveExpired003, TestSize.Level0)
551 {
552     SLOGD("RemoveExpired003 begin!");
553     std::list<std::chrono::system_clock::time_point> timeList;
554     auto now = std::chrono::system_clock::now();
555     int32_t timeThreshold = 5;
556     g_AVSessionService->RemoveExpired(timeList, now, timeThreshold);
557     EXPECT_TRUE(timeList.empty());
558     SLOGD("RemoveExpired003 end!");
559 }
560 
561 /**
562 * @tc.name: NotifyFlowControl001
563 * @tc.desc: Verifying NotifyFlowControl with a full flow control list.
564 * @tc.type: FUNC
565 * @tc.require: #I5Y4MZ
566 */
567 static HWTEST_F(AVSessionServiceTestSecond, NotifyFlowControl001, TestSize.Level0)
568 {
569     SLOGD("NotifyFlowControl001 begin!");
570     g_AVSessionService->flowControlPublishTimestampList_.clear();
571     const size_t count = 3;
572     for (size_t i = 0; i < count; ++i) {
573         g_AVSessionService->flowControlPublishTimestampList_.push_back(std::chrono::system_clock::now());
574     }
575     bool result = g_AVSessionService->NotifyFlowControl();
576     EXPECT_TRUE(result);
577     EXPECT_EQ(g_AVSessionService->flowControlPublishTimestampList_.size(), count);
578     SLOGD("NotifyFlowControl001 end!");
579 }
580 
581 /**
582 * @tc.name: NotifyFlowControl002
583 * @tc.desc: Verifying NotifyFlowControl with a non-full flow control list.
584 * @tc.type: FUNC
585 * @tc.require: #I5Y4MZ
586 */
587 static HWTEST_F(AVSessionServiceTestSecond, NotifyFlowControl002, TestSize.Level0)
588 {
589     SLOGD("NotifyFlowControl002 begin!");
590     const size_t count = 3;
591     g_AVSessionService->flowControlPublishTimestampList_.clear();
592     for (size_t i = 0; i < count - 1; ++i) {
593         g_AVSessionService->flowControlPublishTimestampList_.push_back(std::chrono::system_clock::now());
594     }
595     bool result = g_AVSessionService->NotifyFlowControl();
596     EXPECT_FALSE(result);
597     SLOGD("NotifyFlowControl002 end!");
598 }
599 
600 /**
601 * @tc.name: NotifyRemoteDistributedSessionControllersChanged001
602 * @tc.desc: Verifying NotifyRemoteDistributedSessionControllersChanged with a valid session controller.
603 * @tc.type: FUNC
604 * @tc.require: #I5Y4MZ
605 */
606 static HWTEST_F(AVSessionServiceTestSecond, NotifyRemoteDistributedSessionControllersChanged001, TestSize.Level0)
607 {
608     SLOGD("NotifyRemoteDistributedSessionControllersChanged001 begin!");
609     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
610     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
611     OHOS::sptr<OHOS::ISystemAbilityManager> mgr =
612         OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
613     EXPECT_TRUE(mgr != nullptr);
614     OHOS::sptr<IRemoteObject> obj = mgr->GetSystemAbility(OHOS::AVSESSION_SERVICE_ID);
615     sessionControllers.push_back(obj);
616     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
617     EXPECT_TRUE(g_AVSessionService != nullptr);
618     SLOGD("NotifyRemoteDistributedSessionControllersChanged001 end!");
619 }
620 
621 static HWTEST_F(AVSessionServiceTestSecond, OnReceiveEvent004, TestSize.Level0)
622 {
623     SLOGI("OnReceiveEvent004 begin!");
624     OHOS::EventFwk::CommonEventData eventData;
625     string action = OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF;
626     OHOS::AAFwk::Want want = eventData.GetWant();
627     want.SetAction(action);
628     eventData.SetWant(want);
629     OHOS::EventFwk::MatchingSkills matchingSkills;
630     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
631     EventSubscriber eventSubscriber(subscriberInfo, nullptr);
632     eventSubscriber.OnReceiveEvent(eventData);
633     EXPECT_EQ(0, AVSESSION_SUCCESS);
634     SLOGI("OnReceiveEvent004 end!");
635 }
636 
637 /**
638 * @tc.name: OnIdleWithSessions002
639 * @tc.desc: Verifying the OnIdle method with none zero count sessions.
640 * @tc.type: FUNC
641 * @tc.require: #I5Y4MZ
642 */
643 static HWTEST_F(AVSessionServiceTestSecond, OnIdleWithSessions002, TestSize.Level0)
644 {
645     SLOGD("OnIdleWithSessions002 begin!");
646     OHOS::sptr<AVSessionItem> item = nullptr;
647     g_AVSessionService->GetUsersManager().GetContainerFromAll().AddSession(getpid(), g_testAnotherAbilityName, item);
648     const OHOS::SystemAbilityOnDemandReason idleReason(
649         OHOS::OnDemandReasonId::INTERFACE_CALL, "INTERFACE_CALL", "TestValue", 12345);
650     int32_t result = g_AVSessionService->OnIdle(idleReason);
651     EXPECT_EQ(result, AVSESSION_ERROR);
652     SLOGD("OnIdleWithSessions002 end!");
653 }
654 
655 /**
656 * @tc.name: OnAddSystemAbility002
657 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is MULTIMODAL_INPUT_SERVICE_ID.
658 * @tc.type: FUNC
659 * @tc.require: #I5Y4MZ
660 */
661 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility002, TestSize.Level0)
662 {
663     SLOGD("OnAddSystemAbility002 begin!");
664     ASSERT_TRUE(g_AVSessionService != nullptr);
665     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
666     ASSERT_TRUE(historyDescriptor != nullptr);
667     g_AVSessionService->topSession_ = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
668 
669     int32_t systemAbilityId = OHOS::MULTIMODAL_INPUT_SERVICE_ID;
670     const std::string deviceId = "AUDIO";
671     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
672     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
673     SLOGD("OnAddSystemAbility002 end!");
674 }
675 
676 /**
677 * @tc.name: OnAddSystemAbility003
678 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is AUDIO_POLICY_SERVICE_ID.
679 * @tc.type: FUNC
680 * @tc.require: #I5Y4MZ
681 */
682 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility003, TestSize.Level0)
683 {
684     SLOGD("OnAddSystemAbility003 begin!");
685     int32_t systemAbilityId = OHOS::AUDIO_POLICY_SERVICE_ID;
686     const std::string deviceId = "AUDIO";
687     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
688     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
689     SLOGD("OnAddSystemAbility003 end!");
690 }
691 
692 /**
693 * @tc.name: OnAddSystemAbility004
694 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is APP_MGR_SERVICE_ID.
695 * @tc.type: FUNC
696 * @tc.require: #I5Y4MZ
697 */
698 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility004, TestSize.Level0)
699 {
700     SLOGD("OnAddSystemAbility004 begin!");
701     int32_t systemAbilityId = OHOS::APP_MGR_SERVICE_ID;
702     const std::string deviceId = "AUDIO";
703     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
704     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
705     SLOGD("OnAddSystemAbility004 end!");
706 }
707 
708 /**
709 * @tc.name: OnAddSystemAbility005
710 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID.
711 * @tc.type: FUNC
712 * @tc.require: #I5Y4MZ
713 */
714 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility005, TestSize.Level0)
715 {
716     SLOGD("OnAddSystemAbility005 begin!");
717     int32_t systemAbilityId = OHOS::DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID;
718     const std::string deviceId = "AUDIO";
719     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
720     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
721     SLOGD("OnAddSystemAbility005 end!");
722 }
723 
724 /**
725 * @tc.name: OnAddSystemAbility006
726 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is BUNDLE_MGR_SERVICE_SYS_ABILITY_ID.
727 * @tc.type: FUNC
728 * @tc.require: #I5Y4MZ
729 */
730 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility006, TestSize.Level0)
731 {
732     SLOGD("OnAddSystemAbility006 begin!");
733     int32_t systemAbilityId = OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID;
734     const std::string deviceId = "AUDIO";
735     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
736     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
737     SLOGD("OnAddSystemAbility006 end!");
738 }
739 
740 /**
741 * @tc.name: OnAddSystemAbility007
742 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is COLLABORATION_SA_ID.
743 * @tc.type: FUNC
744 * @tc.require: #I5Y4MZ
745 */
746 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility007, TestSize.Level0)
747 {
748     SLOGD("OnAddSystemAbility007 begin!");
749     int32_t systemAbilityId = COLLABORATION_SA_ID;
750     const std::string deviceId = "AUDIO";
751     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
752     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
753     SLOGD("OnAddSystemAbility007 end!");
754 }
755 
756 /**
757 * @tc.name: OnAddSystemAbility008
758 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is MEMORY_MANAGER_SA_ID.
759 * @tc.type: FUNC
760 * @tc.require: #I5Y4MZ
761 */
762 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility008, TestSize.Level0)
763 {
764     SLOGD("OnAddSystemAbility008 begin!");
765     int32_t systemAbilityId = OHOS::MEMORY_MANAGER_SA_ID;
766     const std::string deviceId = "AUDIO";
767     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
768     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
769     SLOGD("OnAddSystemAbility008 end!");
770 }
771 
772 /**
773 * @tc.name: OnAddSystemAbility009
774 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN.
775 * @tc.type: FUNC
776 * @tc.require: #I5Y4MZ
777 */
778 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility009, TestSize.Level0)
779 {
780     SLOGD("OnAddSystemAbility009 begin!");
781     int32_t systemAbilityId = OHOS::SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN;
782     const std::string deviceId = "AUDIO";
783     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
784     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
785     SLOGD("OnAddSystemAbility009 end!");
786 }
787 
788 /**
789 * @tc.name: OnAddSystemAbility010
790 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is COMMON_EVENT_SERVICE_ID.
791 * @tc.type: FUNC
792 * @tc.require: #I5Y4MZ
793 */
794 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility010, TestSize.Level0)
795 {
796     SLOGD("OnAddSystemAbility010 begin!");
797     int32_t systemAbilityId = OHOS::COMMON_EVENT_SERVICE_ID;
798     const std::string deviceId = "AUDIO";
799     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
800     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
801     SLOGD("OnAddSystemAbility010 end!");
802 }
803 
804 /**
805 * @tc.name: OnAddSystemAbility011
806 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is CAST_ENGINE_SA_ID.
807 * @tc.type: FUNC
808 * @tc.require: #I5Y4MZ
809 */
810 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility011, TestSize.Level0)
811 {
812     SLOGD("OnAddSystemAbility011 begin!");
813 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
814     int32_t systemAbilityId = CAST_ENGINE_SA_ID;
815     const std::string deviceId = "AUDIO";
816     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
817     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
818 #else
819     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
820 #endif
821     SLOGD("OnAddSystemAbility011 end!");
822 }
823 
824 /**
825 * @tc.name: OnAddSystemAbility012
826 * @tc.desc: Verifying the OnAddSystemAbility method with systemAbilityId is CAST_ENGINE_SA_ID and is2in1_ is true.
827 * @tc.type: FUNC
828 * @tc.require: #I5Y4MZ
829 */
830 static HWTEST_F(AVSessionServiceTestSecond, OnAddSystemAbility012, TestSize.Level0)
831 {
832     SLOGD("OnAddSystemAbility012 begin!");
833 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
834     int32_t systemAbilityId = CAST_ENGINE_SA_ID;
835     const std::string deviceId = "AUDIO";
836     g_AVSessionService->is2in1_ = true;
837     g_AVSessionService->OnAddSystemAbility(systemAbilityId, deviceId);
838     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
839 #else
840     EXPECT_EQ(g_AVSessionService->topSession_, nullptr);
841 #endif
842     SLOGD("OnAddSystemAbility012 end!");
843 }
844 
845 /**
846 * @tc.name: InitBMS002
847 * @tc.desc: Verifying the InitBMS method with invalid userid.
848 * @tc.type: FUNC
849 * @tc.require: #I5Y4MZ
850 */
851 static HWTEST_F(AVSessionServiceTestSecond, InitBMS002, TestSize.Level0)
852 {
853     SLOGD("InitBMS002 begin!");
854     ASSERT_TRUE(g_AVSessionService != nullptr);
855     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
856     ASSERT_TRUE(historyDescriptor != nullptr);
857     g_AVSessionService->topSession_ = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
858     g_AVSessionService->GetUsersManager().curUserId_ = -1;
859     g_AVSessionService->InitBMS();
860     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
861     SLOGD("InitBMS002 end!");
862 }
863 
864 /**
865 * @tc.name: NotifySessionCreate001
866 * @tc.desc: Verifying the NotifySessionCreate method with listener.
867 * @tc.type: FUNC
868 * @tc.require: #I5Y4MZ
869 */
870 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate001, TestSize.Level0)
871 {
872     SLOGD("NotifySessionCreate001 begin!");
873     AVSessionDescriptor aVSessionDescriptor;
874     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
875     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
876     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
877     EXPECT_EQ(g_isCallOnSessionCreate, true);
878     SLOGD("NotifySessionCreate001 end!");
879 }
880 
881 /**
882 * @tc.name: NotifySessionCreate002
883 * @tc.desc: Verifying the NotifySessionCreate method with nullptr listener.
884 * @tc.type: FUNC
885 * @tc.require: #I5Y4MZ
886 */
887 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate002, TestSize.Level0)
888 {
889     SLOGD("NotifySessionCreate002 begin!");
890     AVSessionDescriptor aVSessionDescriptor;
891     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
892     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
893     EXPECT_EQ(g_isCallOnSessionCreate, true);
894     SLOGD("NotifySessionCreate002 end!");
895 }
896 
897 /**
898 * @tc.name: NotifySessionCreate003
899 * @tc.desc: Verifying the NotifySessionCreate method with listener.
900 * @tc.type: FUNC
901 * @tc.require: #I5Y4MZ
902 */
903 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate003, TestSize.Level0)
904 {
905     SLOGD("NotifySessionCreate003 begin!");
906     AVSessionDescriptor aVSessionDescriptor;
907     TestSessionListener* listener = new TestSessionListener();
908     g_AVSessionService->innerSessionListeners_.push_back(listener);
909     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
910     EXPECT_EQ(g_isCallOnSessionCreate, true);
911     if (listener != nullptr) {
912         delete listener;
913         listener = nullptr;
914     }
915     SLOGD("NotifySessionCreate003 end!");
916 }
917 
918 /**
919 * @tc.name: NotifySessionCreate004
920 * @tc.desc: Verifying the NotifySessionCreate method with null listener.
921 * @tc.type: FUNC
922 * @tc.require: #I5Y4MZ
923 */
924 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionCreate004, TestSize.Level0)
925 {
926     SLOGD("NotifySessionCreate004 begin!");
927     AVSessionDescriptor aVSessionDescriptor;
928     g_AVSessionService->innerSessionListeners_.push_back(nullptr);
929     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
930     EXPECT_EQ(g_isCallOnSessionCreate, true);
931     SLOGD("NotifySessionCreate004 end!");
932 }
933 
934 /**
935 * @tc.name: NotifyTopSessionChanged001
936 * @tc.desc: Verifying the NotifyTopSessionChanged method with listener.
937 * @tc.type: FUNC
938 * @tc.require: #I5Y4MZ
939 */
940 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged001, TestSize.Level0)
941 {
942     SLOGD("NotifyTopSessionChanged001 begin!");
943     AVSessionDescriptor aVSessionDescriptor;
944     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
945     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
946     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
947     EXPECT_EQ(g_isCallOnTopSessionChange, true);
948     SLOGD("NotifyTopSessionChanged001 end!");
949 }
950 
951 /**
952 * @tc.name: NotifyTopSessionChanged002
953 * @tc.desc: Verifying the NotifyTopSessionChanged method with nullptr listener.
954 * @tc.type: FUNC
955 * @tc.require: #I5Y4MZ
956 */
957 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged002, TestSize.Level0)
958 {
959     SLOGD("NotifyTopSessionChanged002 begin!");
960     AVSessionDescriptor aVSessionDescriptor;
961     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
962     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
963     EXPECT_EQ(g_isCallOnTopSessionChange, true);
964     SLOGD("NotifyTopSessionChanged002 end!");
965 }
966 
967 /**
968 * @tc.name: NotifyTopSessionChanged003
969 * @tc.desc: Verifying the NotifySessionCreate method with null listener.
970 * @tc.type: FUNC
971 * @tc.require: #I5Y4MZ
972 */
973 static HWTEST_F(AVSessionServiceTestSecond, NotifyTopSessionChanged003, TestSize.Level0)
974 {
975     SLOGD("NotifyTopSessionChanged003 begin!");
976     AVSessionDescriptor aVSessionDescriptor;
977     g_AVSessionService->innerSessionListeners_.push_back(nullptr);
978     g_AVSessionService->NotifyTopSessionChanged(aVSessionDescriptor);
979     EXPECT_EQ(g_isCallOnTopSessionChange, true);
980     SLOGD("NotifyTopSessionChanged003 end!");
981 }
982 
983 /**
984 * @tc.name: NotifySessionRelease001
985 * @tc.desc: Verifying the NotifySessionRelease method with listener.
986 * @tc.type: FUNC
987 * @tc.require: #I5Y4MZ
988 */
989 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease001, TestSize.Level0)
990 {
991     SLOGD("NotifySessionRelease001 begin!");
992     AVSessionDescriptor aVSessionDescriptor;
993     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
994     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
995     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
996     EXPECT_EQ(g_isCallOnSessionRelease, true);
997     SLOGD("NotifySessionRelease001 end!");
998 }
999 
1000 /**
1001 * @tc.name: NotifySessionRelease002
1002 * @tc.desc: Verifying the NotifySessionRelease method with nullptr listener.
1003 * @tc.type: FUNC
1004 * @tc.require: #I5Y4MZ
1005 */
1006 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease002, TestSize.Level0)
1007 {
1008     SLOGD("NotifySessionRelease002 begin!");
1009     AVSessionDescriptor aVSessionDescriptor;
1010     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
1011     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
1012     EXPECT_EQ(g_isCallOnSessionRelease, true);
1013     SLOGD("NotifySessionRelease002 end!");
1014 }
1015 
1016 /**
1017 * @tc.name: NotifySessionRelease003
1018 * @tc.desc: Verifying the NotifySessionRelease method with listener.
1019 * @tc.type: FUNC
1020 * @tc.require: #I5Y4MZ
1021 */
1022 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease003, TestSize.Level0)
1023 {
1024     SLOGD("NotifySessionRelease003 begin!");
1025     AVSessionDescriptor aVSessionDescriptor;
1026     TestSessionListener* listener = new TestSessionListener();
1027     g_AVSessionService->innerSessionListeners_.push_back(listener);
1028     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
1029     EXPECT_EQ(g_isCallOnSessionRelease, true);
1030     g_isCallOnSessionRelease = false;
1031     if (listener != nullptr) {
1032         delete listener;
1033         listener = nullptr;
1034     }
1035     SLOGD("NotifySessionRelease003 end!");
1036 }
1037 
1038 
1039 /**
1040 * @tc.name: NotifySessionRelease004
1041 * @tc.desc: Verifying the NotifySessionRelease method with invalid uid.
1042 * @tc.type: FUNC
1043 * @tc.require: #I5Y4MZ
1044 */
1045 static HWTEST_F(AVSessionServiceTestSecond, NotifySessionRelease004, TestSize.Level0)
1046 {
1047     ASSERT_TRUE(g_AVSessionService != nullptr);
1048     AVSessionDescriptor aVSessionDescriptor;
1049     TestSessionListener* listener = new TestSessionListener();
1050     ASSERT_TRUE(listener != nullptr);
1051     g_AVSessionService->innerSessionListeners_.push_back(listener);
1052     aVSessionDescriptor.uid_ = AVSESSION_ERROR;
1053     g_AVSessionService->NotifySessionRelease(aVSessionDescriptor);
1054     EXPECT_EQ(g_isCallOnSessionRelease, true);
1055     g_isCallOnSessionRelease = false;
1056     if (listener != nullptr) {
1057         delete listener;
1058         listener = nullptr;
1059     }
1060 }
1061 
1062 /**
1063 * @tc.name: PlayStateCheck002
1064 * @tc.desc: Verifying the PlayStateCheck method with valid parameters.
1065 * @tc.type: FUNC
1066 * @tc.require: #I5Y4MZ
1067 */
1068 static HWTEST_F(AVSessionServiceTestSecond, PlayStateCheck002, TestSize.Level0)
1069 {
1070     SLOGD("PlayStateCheck002 begin!");
1071     auto avsessionHere = CreateSession();
1072     ASSERT_TRUE(avsessionHere != nullptr);
1073     avsessionHere->playbackState_.SetState(AVPlaybackState::PLAYBACK_STATE_PREPARE);
1074     avsessionHere->SetUid(1);
1075     avsessionHere->Activate();
1076     g_AVSessionService->UpdateTopSession(avsessionHere);
1077 
1078     StreamUsage streamUsage = StreamUsage::STREAM_USAGE_MEDIA;
1079     RendererState rendererState = RendererState::RENDERER_RUNNING;
1080     g_AVSessionService->PlayStateCheck(1, streamUsage, rendererState);
1081     EXPECT_NE(g_AVSessionService->topSession_, nullptr);
1082     avsessionHere->Destroy();
1083     SLOGD("PlayStateCheck002 end!");
1084 }
1085 
1086 /**
1087 * @tc.name: HandleKeyEvent001
1088 * @tc.desc: Verifying the HandleKeyEvent method with valid parameters.
1089 * @tc.type: FUNC
1090 * @tc.require: #I5Y4MZ
1091 */
1092 static HWTEST_F(AVSessionServiceTestSecond, HandleKeyEvent001, TestSize.Level0)
1093 {
1094     SLOGD("HandleKeyEvent001 begin!");
1095     ASSERT_TRUE(g_AVSessionService != nullptr);
1096     auto keyEvent = OHOS::MMI::KeyEvent(KEYCODE_CLEAR);
1097     keyEvent.SetKeyCode(KEYCODE_CLEAR);
1098     auto ret = g_AVSessionService->HandleKeyEvent(keyEvent);
1099     EXPECT_EQ(ret, AVSESSION_CONTINUE);
1100     SLOGD("HandleKeyEvent001 end!");
1101 }
1102 
1103 /**
1104 * @tc.name: HandleKeyEvent002
1105 * @tc.desc: Verifying the HandleKeyEvent method with valid parameters.
1106 * @tc.type: FUNC
1107 * @tc.require: #I5Y4MZ
1108 */
1109 static HWTEST_F(AVSessionServiceTestSecond, HandleKeyEvent002, TestSize.Level0)
1110 {
1111     SLOGD("HandleKeyEvent002 begin!");
1112     ASSERT_TRUE(g_AVSessionService != nullptr);
1113     auto keyEvent = OHOS::MMI::KeyEvent(KEYCODE_HEADSETHOOK);
1114     keyEvent.SetKeyCode(KEYCODE_HEADSETHOOK);
1115     auto ret = g_AVSessionService->HandleKeyEvent(keyEvent);
1116     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1117     SLOGD("HandleKeyEvent002 end!");
1118 }
1119 
1120 /**
1121 * @tc.name: HandleKeyEvent003
1122 * @tc.desc: Verifying the HandleKeyEvent method with valid parameters.
1123 * @tc.type: FUNC
1124 * @tc.require: #I5Y4MZ
1125 */
1126 static HWTEST_F(AVSessionServiceTestSecond, HandleKeyEvent003, TestSize.Level0)
1127 {
1128     SLOGD("HandleKeyEvent003 begin!");
1129     ASSERT_TRUE(g_AVSessionService != nullptr);
1130     auto keyEvent = OHOS::MMI::KeyEvent(KEYCODE_MEDIA_PLAY_PAUSE);
1131     keyEvent.SetKeyCode(KEYCODE_MEDIA_PLAY_PAUSE);
1132     auto ret = g_AVSessionService->HandleKeyEvent(keyEvent);
1133     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1134     SLOGD("HandleKeyEvent003 end!");
1135 }
1136 
1137 /**
1138 * @tc.name: HandleKeyEvent004
1139 * @tc.desc: Verifying the HandleKeyEvent method with valid parameters.
1140 * @tc.type: FUNC
1141 * @tc.require: #I5Y4MZ
1142 */
1143 static HWTEST_F(AVSessionServiceTestSecond, HandleKeyEvent004, TestSize.Level0)
1144 {
1145     SLOGD("HandleKeyEvent004 begin!");
1146     ASSERT_TRUE(g_AVSessionService != nullptr);
1147     auto avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1148     if (avsessionPre != nullptr) {
1149         SLOGE("StopCast001 but sessionPre exist, try clear");
1150         g_AVSessionService->GetContainer().RemoveSession(getpid());
1151     }
1152     std::vector<int> tempAudioPlayingUids {1, 2};
1153     auto avsessionHere = CreateSession();
1154     ASSERT_TRUE(avsessionHere != nullptr);
1155     tempAudioPlayingUids.push_back(avsessionHere->GetUid());
1156     g_AVSessionService->focusSessionStrategy_.SetAudioPlayingUids(tempAudioPlayingUids);
1157 
1158     auto keyEvent = OHOS::MMI::KeyEvent(KEYCODE_MEDIA_PLAY_PAUSE);
1159     keyEvent.SetKeyCode(KEYCODE_MEDIA_PLAY_PAUSE);
1160     auto ret = g_AVSessionService->HandleKeyEvent(keyEvent);
1161     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1162     avsessionHere->Destroy();
1163     SLOGD("HandleKeyEvent004 end!");
1164 }
1165 
1166 /**
1167 * @tc.name: SendSystemAVKeyEvent010
1168 * @tc.desc: Verifying the SendSystemAVKeyEvent method with valid parameters.
1169 * @tc.type: FUNC
1170 * @tc.require: #I5Y4MZ
1171 */
1172 static HWTEST_F(AVSessionServiceTestSecond, SendSystemAVKeyEvent010, TestSize.Level0)
1173 {
1174     SLOGD("SendSystemAVKeyEvent010 begin!");
1175     OHOS::AAFwk::Want bluetoothWant;
1176     std::string activeAddress = "00:00:00:00:00:00";
1177     bluetoothWant.SetParam("deviceId", activeAddress);
1178     auto keyEvent = OHOS::MMI::KeyEvent(KEYCODE_HEADSETHOOK);
1179     keyEvent.SetKeyCode(KEYCODE_HEADSETHOOK);
1180     auto ret = g_AVSessionService->SendSystemAVKeyEvent(keyEvent, bluetoothWant);
1181     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1182     SLOGD("SendSystemAVKeyEvent010 end!");
1183 }
1184 
1185 /**
1186 * @tc.name: ConvertKeyCodeToCommand001
1187 * @tc.desc: Verifying the ConvertKeyCodeToCommand method with valid parameters.
1188 * @tc.type: FUNC
1189 * @tc.require: #I5Y4MZ
1190 */
1191 static HWTEST_F(AVSessionServiceTestSecond, ConvertKeyCodeToCommand001, TestSize.Level0)
1192 {
1193     SLOGD("ConvertKeyCodeToCommand001 begin!");
1194     auto ret = g_AVSessionService->ConvertKeyCodeToCommand(OHOS::MMI::KeyEvent::KEYCODE_MEDIA_PAUSE);
1195     EXPECT_EQ(ret, AVControlCommand::SESSION_CMD_PAUSE);
1196     SLOGD("ConvertKeyCodeToCommand001 end!");
1197 }
1198 
1199 /**
1200 * @tc.name: NotifyRemoteDistributedSessionControllersChanged002
1201 * @tc.desc: Verifying NotifyRemoteDistributedSessionControllersChanged with valid parameters.
1202 * @tc.type: FUNC
1203 * @tc.require: #I5Y4MZ
1204 */
1205 static HWTEST_F(AVSessionServiceTestSecond, NotifyRemoteDistributedSessionControllersChanged002, TestSize.Level0)
1206 {
1207     SLOGD("NotifyRemoteDistributedSessionControllersChanged002 begin!");
1208     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
1209     OHOS::sptr<TestISessionListener> iListener = new TestISessionListener();
1210     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, iListener));
1211     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
1212     SLOGD("NotifyRemoteDistributedSessionControllersChanged002 end!");
1213 }
1214 
1215 /**
1216 * @tc.name: NotifyRemoteDistributedSessionControllersChanged003
1217 * @tc.desc: Verifying NotifyRemoteDistributedSessionControllersChanged with null listener.
1218 * @tc.type: FUNC
1219 * @tc.require: #I5Y4MZ
1220 */
1221 static HWTEST_F(AVSessionServiceTestSecond, NotifyRemoteDistributedSessionControllersChanged003, TestSize.Level0)
1222 {
1223     SLOGD("NotifyRemoteDistributedSessionControllersChanged003 begin!");
1224     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
1225     g_AVSessionService->GetUsersManager().sessionListenersMap_.insert(std::make_pair(1, nullptr));
1226     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
1227     SLOGD("NotifyRemoteDistributedSessionControllersChanged003 end!");
1228 }
1229 
1230 /**
1231 * @tc.name: NotifyRemoteDistributedSessionControllersChanged004
1232 * @tc.desc: the innerSessionListeners_ and listenerMap are not empty
1233 * @tc.type: FUNC
1234 * @tc.require: #I5Y4MZ
1235 */
1236 static HWTEST_F(AVSessionServiceTestSecond, NotifyRemoteDistributedSessionControllersChanged004, TestSize.Level0)
1237 {
1238     SLOGI("NotifyRemoteDistributedSessionControllersChanged004 begin!");
1239     pid_t pid = 3040;
1240     OHOS::sptr<ISessionListener> listener = nullptr;
1241     g_AVSessionService->AddSessionListener(pid, listener);
1242     g_AVSessionService->AddSessionListenerForAllUsers(pid, listener);
1243 
1244     pid_t pid2 = 3041;
1245     OHOS::sptr<ISessionListener> listener2 = new TestISessionListener();
1246     g_AVSessionService->AddSessionListener(pid2, listener2);
1247     g_AVSessionService->AddSessionListenerForAllUsers(pid2, listener2);
1248 
1249     g_AVSessionService->innerSessionListeners_.push_back(nullptr);
1250     auto sessionListeners = std::make_shared<TestSessionListener>();
1251     g_AVSessionService->innerSessionListeners_.push_back(sessionListeners.get());
1252     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers {};
1253     g_AVSessionService->NotifyRemoteDistributedSessionControllersChanged(sessionControllers);
1254 
1255     EXPECT_TRUE(!g_AVSessionService->innerSessionListeners_.empty());
1256     SLOGI("NotifyRemoteDistributedSessionControllersChanged004 end!");
1257 }
1258 
1259 /**
1260 * @tc.name: RemoveClientDeathObserver001
1261 * @tc.desc: observer != nullptr && recipient != nullptr
1262 * @tc.type: FUNC
1263 * @tc.require: #I5Y4MZ
1264 */
1265 static HWTEST_F(AVSessionServiceTestSecond, RemoveClientDeathObserver001, TestSize.Level0)
1266 {
1267     SLOGD("RemoveClientDeathObserver001 begin!");
1268     pid_t pid = 3030;
1269     auto mgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1270     ASSERT_TRUE(mgr != nullptr);
1271     auto object = mgr->GetSystemAbility(OHOS::AVSESSION_SERVICE_ID);
1272     ASSERT_TRUE(object != nullptr);
1273     OHOS::sptr<ClientDeathProxy> observer = OHOS::iface_cast<ClientDeathProxy>(object);
1274     ASSERT_TRUE(observer != nullptr);
__anonf073bc250102() 1275     auto func = []() -> void {};
1276     OHOS::sptr<ClientDeathRecipient> recipient = new ClientDeathRecipient(func);
1277     g_AVSessionService->AddClientDeathObserver(pid, observer, recipient);
1278     g_AVSessionService->RemoveClientDeathObserver(pid);
1279     bool ret = observer != nullptr && recipient != nullptr;
1280     EXPECT_EQ(ret, true);
1281     SLOGD("RemoveClientDeathObserver001 end!");
1282 }
1283 
1284 /**
1285 * @tc.name: RemoveClientDeathObserver002
1286 * @tc.desc: observer == nullptr && recipient != nullptr
1287 * @tc.type: FUNC
1288 * @tc.require: #I5Y4MZ
1289 */
1290 static HWTEST_F(AVSessionServiceTestSecond, RemoveClientDeathObserver002, TestSize.Level0)
1291 {
1292     SLOGD("RemoveClientDeathObserver002 begin!");
1293     pid_t pid = 3031;
1294     OHOS::sptr<IClientDeath> observer = nullptr;
__anonf073bc250202() 1295     auto func = []() -> void {};
1296     OHOS::sptr<ClientDeathRecipient> recipient = new ClientDeathRecipient(func);
1297     g_AVSessionService->AddClientDeathObserver(pid, observer, recipient);
1298     g_AVSessionService->RemoveClientDeathObserver(pid);
1299     bool ret = observer != nullptr && recipient != nullptr;
1300     EXPECT_EQ(ret, false);
1301     SLOGD("RemoveClientDeathObserver002 end!");
1302 }
1303 
1304 /**
1305 * @tc.name: RemoveClientDeathObserver003
1306 * @tc.desc: observer != nullptr && recipient == nullptr
1307 * @tc.type: FUNC
1308 * @tc.require: #I5Y4MZ
1309 */
1310 static HWTEST_F(AVSessionServiceTestSecond, RemoveClientDeathObserver003, TestSize.Level0)
1311 {
1312     SLOGD("RemoveClientDeathObserver003 begin!");
1313     pid_t pid = 3032;
1314     OHOS::sptr<IClientDeath> observer = new TestIClientDeath();
1315     OHOS::sptr<ClientDeathRecipient> recipient = nullptr;
1316     g_AVSessionService->AddClientDeathObserver(pid, observer, recipient);
1317     g_AVSessionService->RemoveClientDeathObserver(pid);
1318     bool ret = observer != nullptr && recipient != nullptr;
1319     EXPECT_EQ(ret, false);
1320     SLOGD("RemoveClientDeathObserver003 end!");
1321 }
1322 
1323 /**
1324 * @tc.name: RegisterClientDeathObserver001
1325 * @tc.desc: observer != nullptr && recipient == nullptr
1326 * @tc.type: FUNC
1327 * @tc.require: #I5Y4MZ
1328 */
1329 static HWTEST_F(AVSessionServiceTestSecond, RegisterClientDeathObserver001, TestSize.Level0)
1330 {
1331     SLOGD("RegisterClientDeathObserver001 begin!");
1332     auto mgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1333     ASSERT_TRUE(mgr != nullptr);
1334     auto object = mgr->GetSystemAbility(OHOS::AVSESSION_SERVICE_ID);
1335     ASSERT_TRUE(object != nullptr);
1336     OHOS::sptr<ClientDeathProxy> observer = OHOS::iface_cast<ClientDeathProxy>(object);
1337     ASSERT_TRUE(observer != nullptr);
1338     int32_t ret = g_AVSessionService->RegisterClientDeathObserver(observer);
1339     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1340     SLOGD("RegisterClientDeathObserver001 end!");
1341 }
1342 
1343 /**
1344 * @tc.name: GetTrustedDeviceName001
1345 * @tc.desc: fail to get trusted device name
1346 * @tc.type: FUNC
1347 * @tc.require: #I5Y4MZ
1348 */
1349 static HWTEST_F(AVSessionServiceTestSecond, GetTrustedDeviceName001, TestSize.Level0)
1350 {
1351     SLOGI("GetTrustedDeviceName001 begin!");
1352     std::string networkId = "@@##**&&";
1353     std::string deviceName = "";
1354     int32_t ret = g_AVSessionService->GetTrustedDeviceName(networkId, deviceName);
1355     EXPECT_EQ(ret, AVSESSION_ERROR);
1356     SLOGI("GetTrustedDeviceName001 end!");
1357 }
1358 
1359 /**
1360  * @tc.name: DoConnectProcessWithMigrateProxy001
1361  * @tc.desc: have found networkId in migrateAVSessionProxyMap_
1362  * @tc.type: FUNC
1363  * @tc.require: #I5Y4MZ
1364  */
1365 static HWTEST_F(AVSessionServiceTestSecond, DoConnectProcessWithMigrateProxy001, TestSize.Level0)
1366 {
1367     SLOGD("DoConnectProcessWithMigrateProxy001 begin!");
1368     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1369     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1370     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1371     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1372 
1373     std::string networkId = std::string(localeDevice.networkId);
1374     g_AVSessionService->migrateAVSessionProxyMap_.insert({networkId, nullptr});
1375     g_AVSessionService->DoConnectProcessWithMigrateProxy(localeDevice);
1376     EXPECT_TRUE(g_AVSessionService != nullptr);
1377     SLOGD("DoConnectProcessWithMigrateProxy001 end!");
1378 }
1379 
1380 /**
1381  * @tc.name: DoDisconnectProcessWithMigrate001
1382  * @tc.desc: have found networkId in migrateAVSessionProxyMap_
1383  * @tc.type: FUNC
1384  * @tc.require: #I5Y4MZ
1385  */
1386 static HWTEST_F(AVSessionServiceTestSecond, DoDisconnectProcessWithMigrate001, TestSize.Level0)
1387 {
1388     SLOGD("DoDisconnectProcessWithMigrate001 begin!");
1389     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1390     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1391     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1392     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1393     localeDevice.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1394 
1395     g_AVSessionService->localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1396     g_AVSessionService->DoDisconnectProcessWithMigrate(localeDevice);
1397     EXPECT_TRUE(g_AVSessionService != nullptr);
1398     g_AVSessionService->localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
1399     SLOGD("DoDisconnectProcessWithMigrate001 end!");
1400 }
1401 
1402 /**
1403  * @tc.name: DoDisconnectProcessWithMigrateServer001
1404  * @tc.desc: have found networkId in migrateAVSessionProxyMap_ but it is nullptr
1405  * @tc.type: FUNC
1406  * @tc.require: #I5Y4MZ
1407  */
1408 static HWTEST_F(AVSessionServiceTestSecond, DoDisconnectProcessWithMigrateServer001, TestSize.Level0)
1409 {
1410     SLOGD("DoDisconnectProcessWithMigrateServer001 begin!");
1411     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1412     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1413     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1414     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1415     localeDevice.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1416 
1417     std::string networkId = std::string(localeDevice.networkId);
1418     g_AVSessionService->migrateAVSessionServerMap_.insert({networkId, nullptr});
1419     g_AVSessionService->DoDisconnectProcessWithMigrateServer(localeDevice);
1420     EXPECT_TRUE(g_AVSessionService != nullptr);
1421     SLOGD("DoDisconnectProcessWithMigrateServer001 end!");
1422 }
1423 
1424 /**
1425  * @tc.name: DoDisconnectProcessWithMigrateServer002
1426  * @tc.desc: have not found networkId in migrateAVSessionProxyMap_
1427  * @tc.type: FUNC
1428  * @tc.require: #I5Y4MZ
1429  */
1430 static HWTEST_F(AVSessionServiceTestSecond, DoDisconnectProcessWithMigrateServer002, TestSize.Level0)
1431 {
1432     SLOGD("DoDisconnectProcessWithMigrateServer002 begin!");
1433     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1434     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1435     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1436     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1437     localeDevice.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1438     g_AVSessionService->DoDisconnectProcessWithMigrateServer(localeDevice);
1439     EXPECT_TRUE(g_AVSessionService != nullptr);
1440     SLOGD("DoDisconnectProcessWithMigrateServer002 end!");
1441 }
1442 
1443 /**
1444  * @tc.name: DoDisconnectProcessWithMigrateProxy001
1445  * @tc.desc: have not found networkId in migrateAVSessionProxyMap_
1446  * @tc.type: FUNC
1447  * @tc.require: #I5Y4MZ
1448  */
1449 static HWTEST_F(AVSessionServiceTestSecond, DoDisconnectProcessWithMigrateProxy001, TestSize.Level0)
1450 {
1451     SLOGD("DoDisconnectProcessWithMigrateProxy001 begin!");
1452     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1453     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1454     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1455     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1456     localeDevice.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1457     g_AVSessionService->DoDisconnectProcessWithMigrateProxy(localeDevice);
1458     EXPECT_TRUE(g_AVSessionService != nullptr);
1459     SLOGD("DoDisconnectProcessWithMigrateProxy001 end!");
1460 }
1461 
1462 /**
1463  * @tc.name: DoDisconnectProcessWithMigrateProxy002
1464  * @tc.desc: have found networkId in migrateAVSessionProxyMap_
1465  * @tc.type: FUNC
1466  * @tc.require: #I5Y4MZ
1467  */
1468 static HWTEST_F(AVSessionServiceTestSecond, DoDisconnectProcessWithMigrateProxy002, TestSize.Level0)
1469 {
1470     SLOGD("DoDisconnectProcessWithMigrateProxy002 begin!");
1471     OHOS::DistributedHardware::DmDeviceInfo localeDevice;
1472     memset_s(&localeDevice, sizeof(localeDevice), 0, sizeof(localeDevice));
1473     strcpy_s(localeDevice.deviceId, sizeof(localeDevice.deviceId) - 1, "<localeDeviceId>");
1474     strcpy_s(localeDevice.deviceName, sizeof(localeDevice.deviceName) - 1, "<localeDeviceName>");
1475     localeDevice.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
1476 
1477     std::string networkId = std::string(localeDevice.networkId);
1478     g_AVSessionService->migrateAVSessionProxyMap_.insert({networkId, nullptr});
1479     g_AVSessionService->DoDisconnectProcessWithMigrateProxy(localeDevice);
1480     EXPECT_TRUE(g_AVSessionService != nullptr);
1481     SLOGD("DoDisconnectProcessWithMigrateProxy002 end!");
1482 }
1483 
1484 /**
1485  * @tc.name: NotifyLocalFrontSessionChangeForMigrate001
1486  * @tc.desc: find server is nullptr in migrateAVSessionProxyMap_
1487  * @tc.type: FUNC
1488  * @tc.require: #I5Y4MZ
1489  */
1490 static HWTEST_F(AVSessionServiceTestSecond, NotifyLocalFrontSessionChangeForMigrate001, TestSize.Level0)
1491 {
1492     SLOGD("NotifyLocalFrontSessionChangeForMigrate001 begin!");
1493     std::string networkId = "test";
1494     OHOS::DistributedHardware::DmDeviceInfo localDevice;
1495     g_AVSessionService->migrateAVSessionServerMap_.insert({networkId, nullptr});
1496 
1497     std::string localFrontSessionIdUpdate = "test";
1498     g_AVSessionService->NotifyLocalFrontSessionChangeForMigrate(localFrontSessionIdUpdate);
1499     g_AVSessionService->DoDisconnectProcessWithMigrateServer(localDevice);
1500     EXPECT_TRUE(g_AVSessionService != nullptr);
1501     SLOGD("NotifyLocalFrontSessionChangeForMigrate001 end!");
1502 }
1503 
1504 /**
1505 * @tc.name: SuperLauncher002
1506 * @tc.desc: Verifying SuperLauncher with init state
1507 * @tc.type: FUNC
1508 * @tc.require: #I5Y4MZ
1509 */
1510 static HWTEST_F(AVSessionServiceTestSecond, SuperLauncher002, TestSize.Level0)
1511 {
1512     g_AVSessionService->SuperLauncher("adcdef", "HuaweiCast", "", "IDLE");
1513     EXPECT_EQ(g_AVSessionService->isSupportMirrorToStream_, false);
1514 }
1515 
1516 /**
1517 * @tc.name: SuperLauncher003
1518 * @tc.desc: Verifying SuperLauncher with init state
1519 * @tc.type: FUNC
1520 * @tc.require: #I5Y4MZ
1521 */
1522 static HWTEST_F(AVSessionServiceTestSecond, SuperLauncher003, TestSize.Level0)
1523 {
1524     g_AVSessionService->is2in1_ = true;
1525     g_AVSessionService->SuperLauncher("adcdef", "HuaweiCast", "a, b, c", "IDLE");
1526     EXPECT_EQ(g_AVSessionService->isSupportMirrorToStream_, false);
1527 }
1528 
1529 /**
1530 * @tc.name: NotifyMigrateStop001
1531 * @tc.desc: Verifying NotifyMigrateStop with init state
1532 * @tc.type: FUNC
1533 * @tc.require: #I5Y4MZ
1534 */
1535 static HWTEST_F(AVSessionServiceTestSecond, NotifyMigrateStop001, TestSize.Level0)
1536 {
1537     g_AVSessionService->NotifyMigrateStop("deviceId");
1538     EXPECT_NE(g_AVSessionService->migrateAVSession_, nullptr);
1539 }
1540 
1541 /**
1542 * @tc.name: SplitExtraInfo001
1543 * @tc.desc: Verifying SplitExtraInfo with init state
1544 * @tc.type: FUNC
1545 * @tc.require: #I5Y4MZ
1546 */
1547 static HWTEST_F(AVSessionServiceTestSecond, SplitExtraInfo001, TestSize.Level0)
1548 {
1549     const string supportInfo = "SUPPORT_MIRROR_TO_STREAM:true";
1550     g_AVSessionService->SplitExtraInfo(supportInfo);
1551     EXPECT_EQ(g_AVSessionService->isSupportMirrorToStream_, true);
1552 
1553     const string deviceInfo = "deviceId : dev01";
1554     g_AVSessionService->SplitExtraInfo(deviceInfo);
1555     EXPECT_NE(g_AVSessionService->castDeviceId_, "");
1556 
1557     const string nameInfo = "deviceName : device";
1558     g_AVSessionService->SplitExtraInfo(nameInfo);
1559     EXPECT_NE(g_AVSessionService->castDeviceName_, "");
1560 
1561     const string deviceTypeInfo = "deviceType : 1";
1562     g_AVSessionService->SplitExtraInfo(deviceTypeInfo);
1563     EXPECT_EQ(g_AVSessionService->castDeviceType_, 1);
1564 }
1565 
1566 /**
1567 * @tc.name: checkEnableCast001
1568 * @tc.desc: Verifying checkEnableCast with init state
1569 * @tc.type: FUNC
1570 * @tc.require: #I5Y4MZ
1571 */
1572 static HWTEST_F(AVSessionServiceTestSecond, checkEnableCast001, TestSize.Level0)
1573 {
1574     g_AVSessionService->isInCast_ = false;
1575     auto ret = g_AVSessionService->checkEnableCast(true);
1576     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1577 }
1578 
1579 /**
1580 * @tc.name: StopCast001
1581 * @tc.desc: Verifying StopCast with init state
1582 * @tc.type: FUNC
1583 * @tc.require: #I5Y4MZ
1584 */
1585 static HWTEST_F(AVSessionServiceTestSecond, StopCast001, TestSize.Level0)
1586 {
1587     auto avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1588     if (avsessionPre != nullptr) {
1589         SLOGE("StopCast001 but sessionPre exist, try clear");
1590         g_AVSessionService->GetContainer().RemoveSession(getpid());
1591     }
1592     auto avsessionHere = CreateSession();
1593     ASSERT_TRUE(avsessionHere != nullptr);
1594     g_AVSessionService->migrateAVSessionServerMap_.clear();
1595 
1596     avsessionHere->descriptor_.sessionTag_ = "RemoteCast";
1597     SessionToken sessionToken;
1598     sessionToken.sessionId = avsessionHere->GetSessionId();
1599     g_AVSessionService->isInCast_ = false;
1600     auto ret = g_AVSessionService->StopCast(sessionToken);
1601     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1602     avsessionHere->Destroy();
1603     avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1604     if (avsessionPre != nullptr) {
1605         SLOGE("StopCast001 but sessionPre still exist, try clear");
1606         g_AVSessionService->GetContainer().RemoveSession(getpid());
1607     }
1608 }
1609 
1610 /**
1611 * @tc.name: MirrorToStreamCast001
1612 * @tc.desc: Verifying MirrorToStreamCast with init state
1613 * @tc.type: FUNC
1614 * @tc.require: #I5Y4MZ
1615 */
1616 static HWTEST_F(AVSessionServiceTestSecond, MirrorToStreamCast001, TestSize.Level0)
1617 {
1618     auto avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1619     if (avsessionPre != nullptr) {
1620         SLOGE("MirrorToStreamCast001 but sessionPre exist, try clear");
1621         g_AVSessionService->GetContainer().RemoveSession(getpid());
1622     }
1623     auto avsessionHere = CreateSession();
1624     ASSERT_TRUE(avsessionHere != nullptr);
1625     g_AVSessionService->isSupportMirrorToStream_ = true;
1626     g_AVSessionService->castServiceNameStatePair_.second = "CONNECT_SUCC";
1627     g_AVSessionService->is2in1_ = false;
1628     auto ret = g_AVSessionService->MirrorToStreamCast(avsessionHere);
1629     EXPECT_EQ(ret, AVSESSION_SUCCESS);
1630     avsessionHere->Destroy();
1631     avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1632     if (avsessionPre != nullptr) {
1633         SLOGE("MirrorToStreamCast001 but sessionPre still exist, try clear");
1634         g_AVSessionService->GetContainer().RemoveSession(getpid());
1635     }
1636 }
1637 
1638 /**
1639 * @tc.name: GetDistributedSessionControllersInner001
1640 * @tc.desc: Verifying GetDistributedSessionControllersInner with init state
1641 * @tc.type: FUNC
1642 * @tc.require: #I5Y4MZ
1643 */
1644 static HWTEST_F(AVSessionServiceTestSecond, GetDistributedSessionControllersInner001, TestSize.Level0)
1645 {
1646     DistributedSessionType sessionType = DistributedSessionType::TYPE_SESSION_REMOTE;
1647     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
1648     auto ret = g_AVSessionService->GetDistributedSessionControllersInner(sessionType, sessionControllers);
1649     EXPECT_EQ(ret, ERR_REMOTE_CONNECTION_NOT_EXIST);
1650 }
1651 
1652 /**
1653 * @tc.name: GetDistributedSessionControllersInner002
1654 * @tc.desc: Verifying GetDistributedSessionControllersInner with init state
1655 * @tc.type: FUNC
1656 * @tc.require: #I5Y4MZ
1657 */
1658 static HWTEST_F(AVSessionServiceTestSecond, GetDistributedSessionControllersInner002, TestSize.Level0)
1659 {
1660     DistributedSessionType sessionType = DistributedSessionType::TYPE_SESSION_MIGRATE_IN;
1661     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
1662     auto ret = g_AVSessionService->GetDistributedSessionControllersInner(sessionType, sessionControllers);
1663     EXPECT_EQ(ret, ERR_REMOTE_CONNECTION_NOT_EXIST);
1664 }
1665 
1666 /**
1667 * @tc.name: OnDeviceLogEvent001
1668 * @tc.desc: Verifying the NotifySessionCreate method with listener.
1669 * @tc.type: FUNC
1670 * @tc.require: #I5Y4MZ
1671 */
1672 static HWTEST_F(AVSessionServiceTestSecond, OnDeviceLogEvent001, TestSize.Level0)
1673 {
1674     SLOGD("OnDeviceLogEvent001 begin!");
1675     AVSessionDescriptor aVSessionDescriptor;
1676     TestSessionListener* listener = new TestSessionListener();
1677     g_AVSessionService->innerSessionListeners_.push_back(listener);
1678     DeviceLogEventCode eventId = DeviceLogEventCode::DEVICE_LOG_FULL;
1679     listener->OnDeviceLogEvent(eventId, 0);
1680     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
1681     EXPECT_EQ(g_isCallOnSessionCreate, true);
1682     if (listener != nullptr) {
1683         delete listener;
1684         listener = nullptr;
1685     }
1686     SLOGD("OnDeviceLogEvent001 end!");
1687 }
1688 
1689 /**
1690 * @tc.name: OnDeviceOffline001
1691 * @tc.desc: Verifying the NotifySessionCreate method with listener.
1692 * @tc.type: FUNC
1693 * @tc.require: #I5Y4MZ
1694 */
1695 static HWTEST_F(AVSessionServiceTestSecond, OnDeviceOffline001, TestSize.Level0)
1696 {
1697     SLOGD("OnDeviceOffline001 begin!");
1698     AVSessionDescriptor aVSessionDescriptor;
1699     TestSessionListener* listener = new TestSessionListener();
1700     g_AVSessionService->innerSessionListeners_.push_back(listener);
1701     const std::string deviceId = "AUDIO";
1702     listener->OnDeviceOffline(deviceId);
1703     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
1704     EXPECT_EQ(g_isCallOnSessionCreate, true);
1705     if (listener != nullptr) {
1706         delete listener;
1707         listener = nullptr;
1708     }
1709     SLOGD("OnDeviceOffline001 end!");
1710 }
1711 
1712 /**
1713 * @tc.name: OnDeviceStateChange001
1714 * @tc.desc: Verifying the OnDeviceStateChange method with listener.
1715 * @tc.type: FUNC
1716 * @tc.require: #ICCINP
1717 */
1718 static HWTEST_F(AVSessionServiceTestSecond, OnDeviceStateChange001, TestSize.Level1)
1719 {
1720     SLOGD("OnDeviceStateChange001 begin!");
1721     AVSessionDescriptor aVSessionDescriptor;
1722     g_isCallOnTopSessionChange = false;
1723     auto listener = std::make_shared<TestSessionListener>();
1724     g_AVSessionService->innerSessionListeners_.push_back(listener.get());
1725     const std::string deviceId = "AUDIO";
1726     DeviceState state;
1727     state.deviceId = deviceId;
1728     listener->OnDeviceStateChange(state);
1729     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
1730     EXPECT_EQ(g_isCallOnSessionCreate, true);
1731     SLOGD("OnDeviceStateChange001 end!");
1732 }
1733 
1734 /**
1735 * @tc.name: OnRemoteDistributedSessionChange001
1736 * @tc.desc: Verifying the NotifySessionCreate method with listener.
1737 * @tc.type: FUNC
1738 * @tc.require: #I5Y4MZ
1739 */
1740 static HWTEST_F(AVSessionServiceTestSecond, OnRemoteDistributedSessionChange001, TestSize.Level0)
1741 {
1742     SLOGD("OnRemoteDistributedSessionChange001 begin!");
1743     AVSessionDescriptor aVSessionDescriptor;
1744     TestSessionListener* listener = new TestSessionListener();
1745     g_AVSessionService->innerSessionListeners_.push_back(listener);
1746     std::vector<OHOS::sptr<IRemoteObject>> sessionControllers;
1747     listener->OnRemoteDistributedSessionChange(sessionControllers);
1748     g_AVSessionService->NotifySessionCreate(aVSessionDescriptor);
1749     EXPECT_EQ(g_isCallOnSessionCreate, true);
1750     if (listener != nullptr) {
1751         delete listener;
1752         listener = nullptr;
1753     }
1754     SLOGD("OnRemoteDistributedSessionChange001 end!");
1755 }
1756 
1757 #ifdef ENABLE_AVSESSION_SYSEVENT_CONTROL
1758 /**
1759 * @tc.name: ReportSessionState001
1760 * @tc.desc: test ReportSessionState
1761 * @tc.type: FUNC
1762 * @tc.require: #IC7XD5
1763 */
1764 static HWTEST_F(AVSessionServiceTestSecond, ReportSessionState001, TestSize.Level0)
1765 {
1766     ASSERT_TRUE(g_AVSessionService != nullptr);
1767     sptr<AVSessionItem> session = nullptr;
1768     g_AVSessionService->ReportSessionState(session, SessionState::STATE_CREATE);
1769 
1770     auto stateInfo = AVSessionSysEvent::GetInstance().GetPlayingStateInfo(g_testAnotherBundleName);
1771     ASSERT_TRUE(stateInfo != nullptr);
1772     for (auto i = 0; i < REPORT_SIZE; i++) {
1773         stateInfo->state_.push_back(0);
1774     }
1775     AVSessionSysEvent::GetInstance().ReportPlayingState(g_testAnotherBundleName);
1776     EXPECT_EQ(stateInfo->state_.size(), 0);
1777 }
1778 
1779 /**
1780 * @tc.name: ReportSessionControl001
1781 * @tc.desc: test ReportSessionControl
1782 * @tc.type: FUNC
1783 * @tc.require: #IC7XD5
1784 */
1785 static HWTEST_F(AVSessionServiceTestSecond, ReportSessionControl001, TestSize.Level0)
1786 {
1787     ASSERT_TRUE(g_AVSessionService != nullptr);
1788     g_AVSessionService->ReportSessionControl(g_testAnotherBundleName, AVControlCommand::SESSION_CMD_PLAY);
1789     g_AVSessionService->ReportSessionControl(g_testAnotherBundleName, AVControlCommand::SESSION_CMD_PAUSE);
1790     g_AVSessionService->ReportSessionControl(g_testAnotherBundleName, CONTROL_COLD_START);
1791     g_AVSessionService->ReportSessionControl(g_testAnotherBundleName, REPORT_SIZE);
1792 
1793     auto stateInfo = AVSessionSysEvent::GetInstance().GetPlayingStateInfo(g_testAnotherBundleName);
1794     ASSERT_TRUE(stateInfo != nullptr);
1795     for (auto i = 0; i < REPORT_SIZE; i++) {
1796         stateInfo->control_.push_back(0);
1797     }
1798     AVSessionSysEvent::GetInstance().ReportPlayingState(g_testAnotherBundleName);
1799     EXPECT_EQ(stateInfo->control_.size(), 0);
1800 }
1801 #endif
1802 
1803 /**
1804  * @tc.name: HandleRemoveMediaCardEvent003
1805  * @tc.desc: Verifying the HandleRemoveMediaCardEvent method with a invalid uid.
1806  * @tc.type: FUNC
1807  * @tc.require: #I5Y4MZ
1808  */
1809 static HWTEST_F(AVSessionServiceTestSecond, HandleRemoveMediaCardEvent003, TestSize.Level0)
1810 {
1811     ASSERT_TRUE(g_AVSessionService != nullptr);
1812     OHOS::AppExecFwk::ElementName elementName;
1813     elementName.SetBundleName(g_testAnotherBundleName);
1814     elementName.SetAbilityName(g_testAnotherAbilityName);
1815     std::shared_ptr<AVSessionDescriptor> historyDescriptor = std::make_shared<AVSessionDescriptor>();
1816     g_AVSessionService->topSession_ = OHOS::sptr<AVSessionItem>::MakeSptr(*historyDescriptor);
1817     ASSERT_TRUE(g_AVSessionService->topSession_ != nullptr);
1818     bool ret = g_AVSessionService->topSession_->IsCasting();
1819     g_AVSessionService->topSession_->SetUid(AVSESSION_ERROR);
1820     g_AVSessionService->HandleRemoveMediaCardEvent();
1821     EXPECT_EQ(ret, false);
1822 }
1823 
1824 /**
1825  * @tc.name: UpdateFrontSession005
1826  * @tc.desc: Verifying the UpdateFrontSession method with a invalid uid.
1827  * @tc.type: FUNC
1828  * @tc.require: #I5Y4MZ
1829  */
1830 static HWTEST_F(AVSessionServiceTestSecond, UpdateFrontSession005, TestSize.Level0)
1831 {
1832     ASSERT_TRUE(g_AVSessionService != nullptr);
1833     OHOS::AppExecFwk::ElementName elementName;
1834     elementName.SetBundleName(g_testAnotherBundleName);
1835     elementName.SetAbilityName(g_testAnotherAbilityName);
1836     auto avsessionPre = g_AVSessionService->GetContainer().GetSession(getpid(), g_testAnotherAbilityName);
1837     if (avsessionPre != nullptr) {
1838         SLOGE("StopCast001 but sessionPre exist, try clear");
1839         g_AVSessionService->GetContainer().RemoveSession(getpid());
1840     }
1841     OHOS::sptr<AVSessionItem> avsessionHere = g_AVSessionService->CreateSessionInner(
1842         g_testSessionTag, AVSession::SESSION_TYPE_VOICE_CALL, false, elementName);
1843     ASSERT_TRUE(avsessionHere != nullptr);
1844     g_AVSessionService->UpdateTopSession(avsessionHere);
1845     g_AVSessionService->topSession_->SetUid(AVSESSION_ERROR);
1846     g_AVSessionService->UpdateFrontSession(avsessionHere, false);
1847     g_AVSessionService->HandleSessionRelease(avsessionHere->GetSessionId());
1848     avsessionHere->Destroy();
1849 }
1850 } //AVSession
1851 } //OHOS
1852