• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "i_hpae_manager.h"
18 #include "manager/hdi_adapter_manager.h"
19 #include "util/id_handler.h"
20 
21 namespace OHOS {
22 namespace AudioStandard {
23 
24 const int32_t SYSTEM_ABILITY_ID = 3009;
25 const bool RUN_ON_CREATE = false;
26 bool g_hasServerInit = false;
27 const int32_t DEFAULT_SYSTEM_ABILITY_ID = -1000;
28 
InitA2dpOffloadManager(AudioPolicyServer * server)29 void InitA2dpOffloadManager(AudioPolicyServer* server)
30 {
31     server->audioPolicyService_.audioA2dpOffloadManager_ = std::make_shared<AudioA2dpOffloadManager>();
32     if (server->audioPolicyService_.audioA2dpOffloadManager_) {
33         server->audioPolicyService_.audioA2dpOffloadManager_->Init();
34     }
35 }
36 
GetServerPtr()37 AudioPolicyServer* GetServerUtil::GetServerPtr()
38 {
39     static AudioPolicyServer server(SYSTEM_ABILITY_ID, RUN_ON_CREATE);
40     if (!g_hasServerInit) {
41         AUDIO_INFO_LOG("AudioPolicyServiceUnitTest::GetServerPtr  server.OnStart()");
42         InitA2dpOffloadManager(&server);
43         IdHandler::GetInstance();
44         HdiAdapterManager::GetInstance();
45         HPAE::IHpaeManager::GetHpaeManager().Init();
46         server.OnStart();
47         server.OnDump();
48         server.OnAddSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID, "");
49 #ifdef FEATURE_MULTIMODALINPUT_INPUT
50         server.OnAddSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, "");
51 #endif
52         server.OnAddSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, "");
53         server.OnAddSystemAbility(POWER_MANAGER_SERVICE_ID, "");
54         server.OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, "");
55         server.audioPolicyService_.SetDefaultDeviceLoadFlag(true);
56         server.OnAddSystemAbility(DEFAULT_SYSTEM_ABILITY_ID, "");
57         server.OnAddSystemAbility(MEMORY_MANAGER_SA_ID, "");
58         g_hasServerInit = true;
59     }
60     return &server;
61 }
62 
GetServerPtr()63 static AudioPolicyServer* GetServerPtr()
64 {
65     return GetServerUtil::GetServerPtr();
66 }
67 } // namespace AudioStandard
68 } // namespace OHOS
69