1 /*
2 * Copyright (c) 2024-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 "get_server_util.h"
17
18 namespace OHOS {
19 namespace AudioStandard {
20
21 const int32_t SYSTEM_ABILITY_ID = 3009;
22 const bool RUN_ON_CREATE = false;
23 bool g_hasServerInit = false;
24 const int32_t DEFAULT_SYSTEM_ABILITY_ID = -1000;
25
InitA2dpOffloadManager(AudioPolicyServer * server)26 void InitA2dpOffloadManager(AudioPolicyServer* server)
27 {
28 server->audioPolicyService_.audioA2dpOffloadManager_ = std::make_shared<AudioA2dpOffloadManager>();
29 if (server->audioPolicyService_.audioA2dpOffloadManager_) {
30 server->audioPolicyService_.audioA2dpOffloadManager_->Init();
31 }
32 }
33
GetServerPtr()34 AudioPolicyServer* GetServerUtil::GetServerPtr()
35 {
36 static AudioPolicyServer server(SYSTEM_ABILITY_ID, RUN_ON_CREATE);
37 if (!g_hasServerInit) {
38 AUDIO_INFO_LOG("AudioPolicyServiceUnitTest::GetServerPtr server.OnStart()");
39 InitA2dpOffloadManager(&server);
40 server.OnStart();
41 server.OnDump();
42 server.OnAddSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID, "");
43 #ifdef FEATURE_MULTIMODALINPUT_INPUT
44 server.OnAddSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, "");
45 #endif
46 server.OnAddSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, "");
47 server.OnAddSystemAbility(POWER_MANAGER_SERVICE_ID, "");
48 server.OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, "");
49 server.audioPolicyService_.SetDefaultDeviceLoadFlag(true);
50 server.OnAddSystemAbility(DEFAULT_SYSTEM_ABILITY_ID, "");
51 server.OnAddSystemAbility(MEMORY_MANAGER_SA_ID, "");
52 g_hasServerInit = true;
53 }
54 return &server;
55 }
56
GetServerPtr()57 static AudioPolicyServer* GetServerPtr()
58 {
59 return GetServerUtil::GetServerPtr();
60 }
61 } // namespace AudioStandard
62 } // namespace OHOS
63