1 /*
2 * Copyright (c) 2021-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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioServerProxy"
17 #endif
18
19 #include "audio_server_proxy.h"
20 #include <ability_manager_client.h>
21 #include "iservice_registry.h"
22 #include "parameter.h"
23 #include "parameters.h"
24 #include "audio_service_log.h"
25 #include "audio_inner_call.h"
26 #include "media_monitor_manager.h"
27 #include "audio_policy_utils.h"
28 #include "istandard_audio_service.h"
29
30 namespace OHOS {
31 namespace AudioStandard {
32
GetAudioServerProxy()33 const sptr<IStandardAudioService> AudioServerProxy::GetAudioServerProxy()
34 {
35 AUDIO_DEBUG_LOG("[Policy Service] Start get audio policy service proxy.");
36 std::lock_guard<std::mutex> lock(adProxyMutex_);
37 auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
38 CHECK_AND_RETURN_RET_LOG(samgr != nullptr, nullptr, "[Policy Service] Get samgr failed.");
39
40 sptr<IRemoteObject> object = samgr->GetSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID);
41 CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr,
42 "[Policy Service] audio service remote object is NULL.");
43
44 const sptr<IStandardAudioService> gsp = iface_cast<IStandardAudioService>(object);
45 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, nullptr,
46 "[Policy Service] init gsp is NULL.");
47 return gsp;
48 }
49
SetAudioSceneProxy(AudioScene audioScene,BluetoothOffloadState state)50 int32_t AudioServerProxy::SetAudioSceneProxy(AudioScene audioScene, BluetoothOffloadState state)
51 {
52 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
53 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
54 std::string identity = IPCSkeleton::ResetCallingIdentity();
55 bool scoExcludeFlag = false;
56 if (AudioPolicyUtils::GetInstance().GetScoExcluded()) {
57 scoExcludeFlag = true;
58 }
59 int32_t result = gsp->SetAudioScene(audioScene, state, scoExcludeFlag);
60 IPCSkeleton::SetCallingIdentity(identity);
61 return result;
62 }
63
GetMaxAmplitudeProxy(bool flag,std::string portName,SourceType sourceType)64 float AudioServerProxy::GetMaxAmplitudeProxy(bool flag, std::string portName, SourceType sourceType)
65 {
66 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
67 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, 0, "Service proxy unavailable");
68
69 std::string identity = IPCSkeleton::ResetCallingIdentity();
70 float maxAmplitude = 0;
71 int32_t rest = gsp->GetMaxAmplitude(flag, portName, sourceType, maxAmplitude);
72 IPCSkeleton::SetCallingIdentity(identity);
73 return maxAmplitude;
74 }
75
GetVolumeDataCount(std::string sinkName)76 int64_t AudioServerProxy::GetVolumeDataCount(std::string sinkName)
77 {
78 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
79 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, 0, "Service proxy unavailable");
80
81 std::string identity = IPCSkeleton::ResetCallingIdentity();
82 int64_t volumeDataCount = 0;
83 gsp->GetVolumeDataCount(sinkName, volumeDataCount);
84 IPCSkeleton::SetCallingIdentity(identity);
85 return volumeDataCount;
86 }
87
UpdateEffectBtOffloadSupportedProxy(const bool & isSupported)88 void AudioServerProxy::UpdateEffectBtOffloadSupportedProxy(const bool &isSupported)
89 {
90 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
91 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
92 std::string identity = IPCSkeleton::ResetCallingIdentity();
93 gsp->UpdateEffectBtOffloadSupported(isSupported);
94 IPCSkeleton::SetCallingIdentity(identity);
95 return;
96 }
97
SetOutputDeviceSinkProxy(DeviceType deviceType,std::string sinkName)98 void AudioServerProxy::SetOutputDeviceSinkProxy(DeviceType deviceType, std::string sinkName)
99 {
100 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
101 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
102 std::string identity = IPCSkeleton::ResetCallingIdentity();
103 gsp->SetOutputDeviceSink(deviceType, sinkName);
104 IPCSkeleton::SetCallingIdentity(identity);
105 }
106
SetActiveOutputDeviceProxy(DeviceType deviceType)107 void AudioServerProxy::SetActiveOutputDeviceProxy(DeviceType deviceType)
108 {
109 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
110 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
111 std::string identity = IPCSkeleton::ResetCallingIdentity();
112 gsp->SetActiveOutputDevice(deviceType);
113 IPCSkeleton::SetCallingIdentity(identity);
114 }
115
GetEffectOffloadEnabledProxy()116 bool AudioServerProxy::GetEffectOffloadEnabledProxy()
117 {
118 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
119 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
120 std::string identity = IPCSkeleton::ResetCallingIdentity();
121 bool effectOffloadFlag = false;
122 int32_t res = gsp->GetEffectOffloadEnabled(effectOffloadFlag);
123 IPCSkeleton::SetCallingIdentity(identity);
124 CHECK_AND_RETURN_RET_LOG(res == SUCCESS, false, "GetEffectOffloadEnabled failed");
125 return effectOffloadFlag;
126 }
127
UpdateActiveDevicesRouteProxy(std::vector<std::pair<DeviceType,DeviceFlag>> & activeDevices,BluetoothOffloadState state,const std::string & deviceName)128 int32_t AudioServerProxy::UpdateActiveDevicesRouteProxy(std::vector<std::pair<DeviceType, DeviceFlag>> &activeDevices,
129 BluetoothOffloadState state, const std::string &deviceName)
130 {
131 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
132 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
133 std::string identity = IPCSkeleton::ResetCallingIdentity();
134 std::vector<IntPair> activeDevicesInt;
135 for (auto &device : activeDevices) {
136 activeDevicesInt.push_back({static_cast<int32_t>(device.first), static_cast<int32_t>(device.second)});
137 }
138 int32_t ret = gsp->UpdateActiveDevicesRoute(activeDevicesInt, state, deviceName);
139 IPCSkeleton::SetCallingIdentity(identity);
140 return ret;
141 }
142
SetDmDeviceTypeProxy(uint16_t dmDeviceType,DeviceType deviceType)143 void AudioServerProxy::SetDmDeviceTypeProxy(uint16_t dmDeviceType, DeviceType deviceType)
144 {
145 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
146 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
147 std::string identity = IPCSkeleton::ResetCallingIdentity();
148 gsp->SetDmDeviceType(dmDeviceType, deviceType);
149 IPCSkeleton::SetCallingIdentity(identity);
150 }
151
UpdateDualToneStateProxy(const bool & enable,const int32_t & sessionId)152 int32_t AudioServerProxy::UpdateDualToneStateProxy(const bool &enable, const int32_t &sessionId)
153 {
154 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
155 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
156 std::string identity = IPCSkeleton::ResetCallingIdentity();
157 int32_t ret = gsp->UpdateDualToneState(enable, sessionId);
158 IPCSkeleton::SetCallingIdentity(identity);
159 return ret;
160 }
161
UpdateSessionConnectionStateProxy(const int32_t & sessionID,const int32_t & state)162 void AudioServerProxy::UpdateSessionConnectionStateProxy(const int32_t &sessionID, const int32_t &state)
163 {
164 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
165 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
166
167 std::string identity = IPCSkeleton::ResetCallingIdentity();
168 gsp->UpdateSessionConnectionState(sessionID, state);
169 IPCSkeleton::SetCallingIdentity(identity);
170 }
171
CheckRemoteDeviceStateProxy(std::string networkId,DeviceRole deviceRole,bool isStartDevice)172 int32_t AudioServerProxy::CheckRemoteDeviceStateProxy(std::string networkId, DeviceRole deviceRole, bool isStartDevice)
173 {
174 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
175 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
176 std::string identity = IPCSkeleton::ResetCallingIdentity();
177 int32_t res = gsp->CheckRemoteDeviceState(networkId, deviceRole, isStartDevice);
178 IPCSkeleton::SetCallingIdentity(identity);
179 return res;
180 }
181
SetAudioParameterProxy(const std::string & key,const std::string & value)182 void AudioServerProxy::SetAudioParameterProxy(const std::string &key, const std::string &value)
183 {
184 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
185 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
186 std::string identity = IPCSkeleton::ResetCallingIdentity();
187 gsp->SetAudioParameter(key, value);
188 IPCSkeleton::SetCallingIdentity(identity);
189 }
190
ResetAudioEndpointProxy()191 void AudioServerProxy::ResetAudioEndpointProxy()
192 {
193 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
194 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
195 std::string identity = IPCSkeleton::ResetCallingIdentity();
196 gsp->ResetAudioEndpoint();
197 IPCSkeleton::SetCallingIdentity(identity);
198 }
199
GetAllSinkInputsProxy(std::vector<SinkInput> & sinkInputs)200 void AudioServerProxy::GetAllSinkInputsProxy(std::vector<SinkInput> &sinkInputs)
201 {
202 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
203 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
204 std::string identity = IPCSkeleton::ResetCallingIdentity();
205 gsp->GetAllSinkInputs(sinkInputs);
206 IPCSkeleton::SetCallingIdentity(identity);
207 }
208
SetDefaultAdapterEnableProxy(bool isEnable)209 void AudioServerProxy::SetDefaultAdapterEnableProxy(bool isEnable)
210 {
211 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
212 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
213 std::string identity = IPCSkeleton::ResetCallingIdentity();
214 gsp->SetDefaultAdapterEnable(isEnable);
215 IPCSkeleton::SetCallingIdentity(identity);
216 }
217
NotifyStreamVolumeChangedProxy(AudioStreamType streamType,float volume)218 bool AudioServerProxy::NotifyStreamVolumeChangedProxy(AudioStreamType streamType, float volume)
219 {
220 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
221 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
222 std::string identity = IPCSkeleton::ResetCallingIdentity();
223 gsp->NotifyStreamVolumeChanged(streamType, volume);
224 IPCSkeleton::SetCallingIdentity(identity);
225 return true;
226 }
227
OffloadSetVolumeProxy(float volume,const std::string & deviceClass,const std::string & networkId)228 void AudioServerProxy::OffloadSetVolumeProxy(float volume, const std::string &deviceClass, const std::string &networkId)
229 {
230 const sptr <IStandardAudioService> gsp = GetAudioServerProxy();
231 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
232 std::string identity = IPCSkeleton::ResetCallingIdentity();
233 gsp->OffloadSetVolume(volume, deviceClass, networkId);
234 IPCSkeleton::SetCallingIdentity(identity);
235 }
236
SetVoiceVolumeProxy(float volume)237 void AudioServerProxy::SetVoiceVolumeProxy(float volume)
238 {
239 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
240 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
241 std::string identity = IPCSkeleton::ResetCallingIdentity();
242 gsp->SetVoiceVolume(volume);
243 IPCSkeleton::SetCallingIdentity(identity);
244 }
245
UnsetOffloadModeProxy(uint32_t sessionId)246 void AudioServerProxy::UnsetOffloadModeProxy(uint32_t sessionId)
247 {
248 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
249 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
250 std::string identity = IPCSkeleton::ResetCallingIdentity();
251 gsp->UnsetOffloadMode(sessionId);
252 IPCSkeleton::SetCallingIdentity(identity);
253 }
254
SetOffloadModeProxy(uint32_t sessionId,int32_t state,bool isAppBack)255 void AudioServerProxy::SetOffloadModeProxy(uint32_t sessionId, int32_t state, bool isAppBack)
256 {
257 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
258 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
259 std::string identity = IPCSkeleton::ResetCallingIdentity();
260 gsp->SetOffloadMode(sessionId, state, isAppBack);
261 IPCSkeleton::SetCallingIdentity(identity);
262 }
263
CheckHibernateStateProxy(bool hibernate)264 void AudioServerProxy::CheckHibernateStateProxy(bool hibernate)
265 {
266 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
267 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
268 std::string identity = IPCSkeleton::ResetCallingIdentity();
269 gsp->CheckHibernateState(hibernate);
270 IPCSkeleton::SetCallingIdentity(identity);
271 }
272
RestoreSessionProxy(const uint32_t & sessionID,RestoreInfo restoreInfo)273 void AudioServerProxy::RestoreSessionProxy(const uint32_t &sessionID, RestoreInfo restoreInfo)
274 {
275 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
276 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
277 std::string identity = IPCSkeleton::ResetCallingIdentity();
278 RestoreInfoIpc restoreInfoIpc;
279 restoreInfoIpc.restoreInfo = restoreInfo;
280 gsp->RestoreSession(sessionID, restoreInfoIpc);
281 IPCSkeleton::SetCallingIdentity(identity);
282 }
283
GetAudioEnhancePropertyProxy(AudioEnhancePropertyArray & propertyArray,DeviceType deviceType)284 int32_t AudioServerProxy::GetAudioEnhancePropertyProxy(AudioEnhancePropertyArray &propertyArray,
285 DeviceType deviceType)
286 {
287 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
288 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
289 std::string identity = IPCSkeleton::ResetCallingIdentity();
290 int32_t ret = gsp->GetAudioEnhanceProperty(propertyArray, deviceType);
291 IPCSkeleton::SetCallingIdentity(identity);
292 return ret;
293 }
294
SetAudioEnhancePropertyProxy(const AudioEnhancePropertyArray & propertyArray,DeviceType deviceType)295 int32_t AudioServerProxy::SetAudioEnhancePropertyProxy(const AudioEnhancePropertyArray &propertyArray,
296 DeviceType deviceType)
297 {
298 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
299 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
300 std::string identity = IPCSkeleton::ResetCallingIdentity();
301 int32_t ret = gsp->SetAudioEnhanceProperty(propertyArray, deviceType);
302 IPCSkeleton::SetCallingIdentity(identity);
303 return ret;
304 }
305
SetMicrophoneMuteProxy(bool isMute)306 int32_t AudioServerProxy::SetMicrophoneMuteProxy(bool isMute)
307 {
308 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
309 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
310 std::string identity = IPCSkeleton::ResetCallingIdentity();
311 int32_t ret = gsp->SetMicrophoneMute(isMute);
312 IPCSkeleton::SetCallingIdentity(identity);
313 return ret;
314 }
315
SetSinkMuteForSwitchDeviceProxy(const std::string & devceClass,int32_t durationUs,bool mute)316 void AudioServerProxy::SetSinkMuteForSwitchDeviceProxy(const std::string &devceClass, int32_t durationUs, bool mute)
317 {
318 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
319 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
320 std::string identity = IPCSkeleton::ResetCallingIdentity();
321 gsp->SetSinkMuteForSwitchDevice(devceClass, durationUs, mute);
322 IPCSkeleton::SetCallingIdentity(identity);
323 }
324
SuspendRenderSinkProxy(const std::string & sinkName)325 void AudioServerProxy::SuspendRenderSinkProxy(const std::string &sinkName)
326 {
327 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
328 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
329 std::string identity = IPCSkeleton::ResetCallingIdentity();
330 gsp->SuspendRenderSink(sinkName);
331 IPCSkeleton::SetCallingIdentity(identity);
332 }
333
RestoreRenderSinkProxy(const std::string & sinkName)334 void AudioServerProxy::RestoreRenderSinkProxy(const std::string &sinkName)
335 {
336 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
337 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
338 std::string identity = IPCSkeleton::ResetCallingIdentity();
339 gsp->RestoreRenderSink(sinkName);
340 IPCSkeleton::SetCallingIdentity(identity);
341 }
342
LoadHdiEffectModelProxy()343 void AudioServerProxy::LoadHdiEffectModelProxy()
344 {
345 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
346 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
347 std::string identity = IPCSkeleton::ResetCallingIdentity();
348 gsp->LoadHdiEffectModel();
349 IPCSkeleton::SetCallingIdentity(identity);
350 }
351
NotifyDeviceInfoProxy(std::string networkId,bool connected)352 void AudioServerProxy::NotifyDeviceInfoProxy(std::string networkId, bool connected)
353 {
354 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
355 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
356 std::string identity = IPCSkeleton::ResetCallingIdentity();
357 gsp->NotifyDeviceInfo(networkId, connected);
358 IPCSkeleton::SetCallingIdentity(identity);
359 }
360
GetAudioParameterProxy(const std::string & key)361 std::string AudioServerProxy::GetAudioParameterProxy(const std::string &key)
362 {
363 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
364 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, "", "Service proxy unavailable");
365 std::string identity = IPCSkeleton::ResetCallingIdentity();
366 std::string value = "";
367 gsp->GetAudioParameter(key, value);
368 IPCSkeleton::SetCallingIdentity(identity);
369 return value;
370 }
371
GetAudioParameterProxy(const std::string & networkId,const AudioParamKey key,const std::string & condition)372 std::string AudioServerProxy::GetAudioParameterProxy(const std::string& networkId, const AudioParamKey key,
373 const std::string& condition)
374 {
375 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
376 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, "", "Service proxy unavailable");
377 std::string identity = IPCSkeleton::ResetCallingIdentity();
378 std::string value = "";
379 gsp->GetAudioParameter(networkId, key, condition, value);
380 IPCSkeleton::SetCallingIdentity(identity);
381 return value;
382 }
383
ResetRouteForDisconnectProxy(DeviceType type)384 void AudioServerProxy::ResetRouteForDisconnectProxy(DeviceType type)
385 {
386 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
387 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
388 std::string identity = IPCSkeleton::ResetCallingIdentity();
389 gsp->ResetRouteForDisconnect(type);
390 IPCSkeleton::SetCallingIdentity(identity);
391 }
392
CreatePlaybackCapturerManagerProxy()393 bool AudioServerProxy::CreatePlaybackCapturerManagerProxy()
394 {
395 #ifdef HAS_FEATURE_INNERCAPTURER
396 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
397 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
398 std::string identity = IPCSkeleton::ResetCallingIdentity();
399 bool isSuccess = false;
400 gsp->CreatePlaybackCapturerManager(isSuccess);
401 IPCSkeleton::SetCallingIdentity(identity);
402 return isSuccess;
403 #else
404 return false;
405 #endif
406 }
407
LoadAudioEffectLibrariesProxy(const std::vector<Library> libraries,const std::vector<Effect> effects,std::vector<Effect> & successEffectList)408 bool AudioServerProxy::LoadAudioEffectLibrariesProxy(const std::vector<Library> libraries,
409 const std::vector<Effect> effects, std::vector<Effect>& successEffectList)
410 {
411 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
412 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
413 std::string identity = IPCSkeleton::ResetCallingIdentity();
414 bool hasEffectsLoaded = false;
415 int32_t res = gsp->LoadAudioEffectLibraries(libraries, effects, successEffectList, hasEffectsLoaded);
416 IPCSkeleton::SetCallingIdentity(identity);
417 return hasEffectsLoaded;
418 }
419
CreateEffectChainManagerProxy(std::vector<EffectChain> & effectChains,const EffectChainManagerParam & effectParam,const EffectChainManagerParam & enhanceParam)420 bool AudioServerProxy::CreateEffectChainManagerProxy(std::vector<EffectChain> &effectChains,
421 const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam)
422 {
423 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
424 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
425 std::string identity = IPCSkeleton::ResetCallingIdentity();
426 int32_t res = gsp->CreateEffectChainManager(effectChains, effectParam, enhanceParam);
427 bool isSuccess = res == SUCCESS;
428 IPCSkeleton::SetCallingIdentity(identity);
429 CHECK_AND_RETURN_RET_LOG(res == SUCCESS, false, "CreateEffectChainManager failed");
430 return isSuccess;
431 }
432
RegiestPolicyProviderProxy(const sptr<IRemoteObject> & object)433 int32_t AudioServerProxy::RegiestPolicyProviderProxy(const sptr<IRemoteObject> &object)
434 {
435 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
436 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
437 std::string identity = IPCSkeleton::ResetCallingIdentity();
438 int32_t ret = gsp->RegiestPolicyProvider(object);
439 IPCSkeleton::SetCallingIdentity(identity);
440 return ret;
441 }
442
RegistCoreServiceProviderProxy(const sptr<IRemoteObject> & object)443 int32_t AudioServerProxy::RegistCoreServiceProviderProxy(const sptr<IRemoteObject> &object)
444 {
445 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
446 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
447 std::string identity = IPCSkeleton::ResetCallingIdentity();
448 int32_t ret = gsp->RegistCoreServiceProvider(object);
449 IPCSkeleton::SetCallingIdentity(identity);
450 return ret;
451 }
452
SetParameterCallbackProxy(const sptr<IRemoteObject> & object)453 void AudioServerProxy::SetParameterCallbackProxy(const sptr<IRemoteObject>& object)
454 {
455 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
456 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
457 std::string identity = IPCSkeleton::ResetCallingIdentity();
458 gsp->SetParameterCallback(object);
459 IPCSkeleton::SetCallingIdentity(identity);
460 }
461
SetAudioEffectPropertyProxy(const AudioEffectPropertyArrayV3 & propertyArray,const DeviceType & deviceType)462 int32_t AudioServerProxy::SetAudioEffectPropertyProxy(const AudioEffectPropertyArrayV3 &propertyArray,
463 const DeviceType& deviceType)
464 {
465 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
466 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
467 std::string identity = IPCSkeleton::ResetCallingIdentity();
468 (void) deviceType;
469 int32_t ret = gsp->SetAudioEffectProperty(propertyArray, DeviceType::DEVICE_TYPE_NONE);
470 IPCSkeleton::SetCallingIdentity(identity);
471 return ret;
472 }
473
GetAudioEffectPropertyProxy(AudioEffectPropertyArrayV3 & propertyArray)474 int32_t AudioServerProxy::GetAudioEffectPropertyProxy(AudioEffectPropertyArrayV3 &propertyArray)
475 {
476 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
477 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
478 std::string identity = IPCSkeleton::ResetCallingIdentity();
479 int32_t ret = gsp->GetAudioEffectProperty(propertyArray, DeviceType::DEVICE_TYPE_NONE);
480 IPCSkeleton::SetCallingIdentity(identity);
481 return ret;
482 }
483
SetAudioEffectPropertyProxy(const AudioEffectPropertyArray & propertyArray)484 int32_t AudioServerProxy::SetAudioEffectPropertyProxy(const AudioEffectPropertyArray &propertyArray)
485 {
486 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
487 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
488 std::string identity = IPCSkeleton::ResetCallingIdentity();
489 int32_t ret = gsp->SetAudioEffectProperty(propertyArray);
490 IPCSkeleton::SetCallingIdentity(identity);
491 return ret;
492 }
493
GetAudioEffectPropertyProxy(AudioEffectPropertyArray & propertyArray)494 int32_t AudioServerProxy::GetAudioEffectPropertyProxy(AudioEffectPropertyArray &propertyArray)
495 {
496 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
497 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_HANDLE, "Service proxy unavailable");
498 std::string identity = IPCSkeleton::ResetCallingIdentity();
499 int32_t ret = gsp->GetAudioEffectProperty(propertyArray);
500 IPCSkeleton::SetCallingIdentity(identity);
501 return ret;
502 }
503
SetRotationToEffectProxy(const uint32_t rotate)504 void AudioServerProxy::SetRotationToEffectProxy(const uint32_t rotate)
505 {
506 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
507 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
508 std::string identity = IPCSkeleton::ResetCallingIdentity();
509 gsp->SetRotationToEffect(rotate);
510 IPCSkeleton::SetCallingIdentity(identity);
511 }
512
SetAudioMonoStateProxy(bool audioMono)513 void AudioServerProxy::SetAudioMonoStateProxy(bool audioMono)
514 {
515 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
516 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
517 std::string identity = IPCSkeleton::ResetCallingIdentity();
518 gsp->SetAudioMonoState(audioMono);
519 IPCSkeleton::SetCallingIdentity(identity);
520 }
521
SetAudioBalanceValueProxy(float audioBalance)522 void AudioServerProxy::SetAudioBalanceValueProxy(float audioBalance)
523 {
524 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
525 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
526 std::string identity = IPCSkeleton::ResetCallingIdentity();
527 gsp->SetAudioBalanceValue(audioBalance);
528 IPCSkeleton::SetCallingIdentity(identity);
529 }
530
NotifyAccountsChanged()531 void AudioServerProxy::NotifyAccountsChanged()
532 {
533 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
534 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
535 std::string identity = IPCSkeleton::ResetCallingIdentity();
536 gsp->NotifyAccountsChanged();
537 IPCSkeleton::SetCallingIdentity(identity);
538 }
539
NotifySettingsDataReady()540 void AudioServerProxy::NotifySettingsDataReady()
541 {
542 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
543 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
544 std::string identity = IPCSkeleton::ResetCallingIdentity();
545 gsp->NotifySettingsDataReady();
546 IPCSkeleton::SetCallingIdentity(identity);
547 }
548
NotifyAudioPolicyReady()549 void AudioServerProxy::NotifyAudioPolicyReady()
550 {
551 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
552 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
553 std::string identity = IPCSkeleton::ResetCallingIdentity();
554 gsp->NotifyAudioPolicyReady();
555 IPCSkeleton::SetCallingIdentity(identity);
556 }
557
558 #ifdef HAS_FEATURE_INNERCAPTURER
SetInnerCapLimitProxy(uint32_t innerCapLimit)559 int32_t AudioServerProxy::SetInnerCapLimitProxy(uint32_t innerCapLimit)
560 {
561 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
562 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
563 std::string identity = IPCSkeleton::ResetCallingIdentity();
564 int32_t res = gsp->SetInnerCapLimit(innerCapLimit);
565 IPCSkeleton::SetCallingIdentity(identity);
566 return res;
567 }
568 #endif
569
LoadHdiAdapterProxy(uint32_t devMgrType,const std::string & adapterName)570 int32_t AudioServerProxy::LoadHdiAdapterProxy(uint32_t devMgrType, const std::string &adapterName)
571 {
572 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
573 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_OPERATION_FAILED, "Service proxy unavailable");
574 std::string identity = IPCSkeleton::ResetCallingIdentity();
575 int32_t res = gsp->LoadHdiAdapter(devMgrType, adapterName);
576 IPCSkeleton::SetCallingIdentity(identity);
577 return res;
578 }
579
UnloadHdiAdapterProxy(uint32_t devMgrType,const std::string & adapterName,bool force)580 void AudioServerProxy::UnloadHdiAdapterProxy(uint32_t devMgrType, const std::string &adapterName, bool force)
581 {
582 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
583 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
584 std::string identity = IPCSkeleton::ResetCallingIdentity();
585 gsp->UnloadHdiAdapter(devMgrType, adapterName, force);
586 IPCSkeleton::SetCallingIdentity(identity);
587 }
588
CreateHdiSinkPortProxy(const std::string & deviceClass,const std::string & idInfo,const IAudioSinkAttr & attr)589 uint32_t AudioServerProxy::CreateHdiSinkPortProxy(const std::string &deviceClass, const std::string &idInfo,
590 const IAudioSinkAttr &attr)
591 {
592 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
593 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, HDI_INVALID_ID, "Service proxy unavailable");
594 std::string identity = IPCSkeleton::ResetCallingIdentity();
595 uint32_t renderId = 0;
596 int32_t res = gsp->CreateHdiSinkPort(deviceClass, idInfo, attr, renderId);
597 IPCSkeleton::SetCallingIdentity(identity);
598 CHECK_AND_RETURN_RET_LOG(res == SUCCESS, HDI_INVALID_ID, "CreateHdiSinkPort failed");
599 return renderId;
600 }
601
CreateHdiSourcePortProxy(const std::string & deviceClass,const std::string & idInfo,const IAudioSourceAttr & attr)602 uint32_t AudioServerProxy::CreateHdiSourcePortProxy(const std::string &deviceClass, const std::string &idInfo,
603 const IAudioSourceAttr &attr)
604 {
605 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
606 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, HDI_INVALID_ID, "Service proxy unavailable");
607 std::string identity = IPCSkeleton::ResetCallingIdentity();
608 uint32_t captureId = 0;
609 int32_t res = gsp->CreateHdiSourcePort(deviceClass, idInfo, attr, captureId);
610 IPCSkeleton::SetCallingIdentity(identity);
611 CHECK_AND_RETURN_RET_LOG(res == SUCCESS, HDI_INVALID_ID, "CreateHdiSourcePort failed");
612 return captureId;
613 }
614
DestroyHdiPortProxy(uint32_t id)615 void AudioServerProxy::DestroyHdiPortProxy(uint32_t id)
616 {
617 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
618 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
619 std::string identity = IPCSkeleton::ResetCallingIdentity();
620 gsp->DestroyHdiPort(id);
621 IPCSkeleton::SetCallingIdentity(identity);
622 }
623
SetDeviceConnectedFlag(bool flag)624 void AudioServerProxy::SetDeviceConnectedFlag(bool flag)
625 {
626 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
627 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
628 std::string identity = IPCSkeleton::ResetCallingIdentity();
629 gsp->SetDeviceConnectedFlag(flag);
630 IPCSkeleton::SetCallingIdentity(identity);
631 }
632
IsAcousticEchoCancelerSupported(SourceType sourceType)633 bool AudioServerProxy::IsAcousticEchoCancelerSupported(SourceType sourceType)
634 {
635 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
636 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
637 std::string identity = IPCSkeleton::ResetCallingIdentity();
638 bool isSupported = false;
639 gsp->IsAcousticEchoCancelerSupported(sourceType, isSupported);
640 IPCSkeleton::SetCallingIdentity(identity);
641 return isSupported;
642 }
643
SetKaraokeParameters(const std::string & parameters)644 bool AudioServerProxy::SetKaraokeParameters(const std::string ¶meters)
645 {
646 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
647 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
648 std::string identity = IPCSkeleton::ResetCallingIdentity();
649 bool res = false;
650 gsp->SetKaraokeParameters(parameters, res);
651 IPCSkeleton::SetCallingIdentity(identity);
652 return res;
653 }
654
IsAudioLoopbackSupported(AudioLoopbackMode mode)655 bool AudioServerProxy::IsAudioLoopbackSupported(AudioLoopbackMode mode)
656 {
657 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
658 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "Service proxy unavailable");
659 std::string identity = IPCSkeleton::ResetCallingIdentity();
660 bool res = false;
661 gsp->IsAudioLoopbackSupported(mode, res);
662 IPCSkeleton::SetCallingIdentity(identity);
663 return res;
664 }
665
SetLatestMuteState(const uint32_t sessionId,const bool muteFlag)666 void AudioServerProxy::SetLatestMuteState(const uint32_t sessionId, const bool muteFlag)
667 {
668 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
669 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
670 std::string identity = IPCSkeleton::ResetCallingIdentity();
671 gsp->SetLatestMuteState(sessionId, muteFlag);
672 IPCSkeleton::SetCallingIdentity(identity);
673 }
674
SetSessionMuteState(const uint32_t sessionId,const bool insert,const bool muteFlag)675 void AudioServerProxy::SetSessionMuteState(const uint32_t sessionId, const bool insert, const bool muteFlag)
676 {
677 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
678 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
679 std::string identity = IPCSkeleton::ResetCallingIdentity();
680 gsp->SetSessionMuteState(sessionId, insert, muteFlag);
681 IPCSkeleton::SetCallingIdentity(identity);
682 }
683
SetBtHdiInvalidState()684 void AudioServerProxy::SetBtHdiInvalidState()
685 {
686 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
687 CHECK_AND_RETURN_LOG(gsp != nullptr, "Service proxy unavailable");
688 std::string identity = IPCSkeleton::ResetCallingIdentity();
689 gsp->SetBtHdiInvalidState();
690 IPCSkeleton::SetCallingIdentity(identity);
691 }
692
ForceStopAudioStreamProxy(StopAudioType audioType)693 int32_t AudioServerProxy::ForceStopAudioStreamProxy(StopAudioType audioType)
694 {
695 const sptr<IStandardAudioService> gsp = GetAudioServerProxy();
696 CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_OPERATION, "Service proxy unavailable");
697 std::string identity = IPCSkeleton::ResetCallingIdentity();
698 int32_t res = gsp->ForceStopAudioStream(audioType);
699 IPCSkeleton::SetCallingIdentity(identity);
700 return res;
701 }
702 }
703 }
704