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