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 "AudioManagerStub"
17 #endif
18
19 #include "audio_manager_base.h"
20 #include "audio_system_manager.h"
21 #include "audio_service_log.h"
22 #include "i_audio_process.h"
23 #include "audio_effect_server.h"
24 #include "audio_asr.h"
25 #include "audio_utils.h"
26
27 using namespace std;
28
29 namespace OHOS {
30 namespace AudioStandard {
31 namespace {
32 constexpr int32_t AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT = 40;
33 constexpr int32_t AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT = 64;
34 constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32;
35 constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16;
36 constexpr int32_t AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT = 7;
37 constexpr int32_t AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT = 20;
38 #ifndef HAS_FEATURE_INNERCAPTURER
39 constexpr int32_t ERROR = -1;
40 #endif
41
42 const char *g_audioServerCodeStrs[] = {
43 "GET_AUDIO_PARAMETER",
44 "SET_AUDIO_PARAMETER",
45 "GET_EXTRA_AUDIO_PARAMETERS",
46 "SET_EXTRA_AUDIO_PARAMETERS",
47 "SET_MICROPHONE_MUTE",
48 "SET_AUDIO_SCENE",
49 "UPDATE_ROUTE_REQ",
50 "UPDATE_ROUTES_REQ",
51 "UPDATE_DUAL_TONE_REQ",
52 "GET_TRANSACTION_ID",
53 "SET_PARAMETER_CALLBACK",
54 "GET_REMOTE_AUDIO_PARAMETER",
55 "SET_REMOTE_AUDIO_PARAMETER",
56 "NOTIFY_DEVICE_INFO",
57 "CHECK_REMOTE_DEVICE_STATE",
58 "SET_VOICE_VOLUME",
59 "SET_AUDIO_MONO_STATE",
60 "SET_AUDIO_BALANCE_VALUE",
61 "CREATE_AUDIOPROCESS",
62 "LOAD_AUDIO_EFFECT_LIBRARIES",
63 "CREATE_AUDIO_EFFECT_CHAIN_MANAGER",
64 "SET_OUTPUT_DEVICE_SINK",
65 "CREATE_PLAYBACK_CAPTURER_MANAGER",
66 "REGISET_POLICY_PROVIDER",
67 "SET_WAKEUP_CLOSE_CALLBACK",
68 "SET_CAPTURE_SILENT_STATE",
69 "UPDATE_SPATIALIZATION_STATE",
70 "UPDATE_SPATIAL_DEVICE_TYPE",
71 "OFFLOAD_SET_VOLUME",
72 "NOTIFY_STREAM_VOLUME_CHANGED",
73 "SET_SPATIALIZATION_SCENE_TYPE",
74 "GET_MAX_AMPLITUDE",
75 "RESET_AUDIO_ENDPOINT",
76 "RESET_ROUTE_FOR_DISCONNECT",
77 "GET_EFFECT_LATENCY",
78 "UPDATE_LATENCY_TIMESTAMP",
79 "SET_ASR_AEC_MODE",
80 "GET_ASR_AEC_MODE",
81 "SET_ASR_NOISE_SUPPRESSION_MODE",
82 "SET_OFFLOAD_MODE",
83 "UNSET_OFFLOAD_MODE",
84 "CHECK_HIBERNATE_STATE",
85 "GET_ASR_NOISE_SUPPRESSION_MODE",
86 "SET_ASR_WHISPER_DETECTION_MODE",
87 "GET_ASR_WHISPER_DETECTION_MODE",
88 "SET_ASR_VOICE_CONTROL_MODE",
89 "SET_ASR_VOICE_MUTE_MODE",
90 "IS_WHISPERING",
91 "GET_EFFECT_OFFLOAD_ENABLED",
92 "SUSPEND_RENDERSINK",
93 "RESTORE_RENDERSINK",
94 "LOAD_HDI_EFFECT_MODEL",
95 "GET_AUDIO_EFFECT_PROPERTY_V3",
96 "SET_AUDIO_EFFECT_PROPERTY_V3",
97 "GET_AUDIO_ENHANCE_PROPERTY",
98 "GET_AUDIO_EFFECT_PROPERTY",
99 "SET_AUDIO_ENHANCE_PROPERTY",
100 "SET_AUDIO_EFFECT_PROPERTY",
101 "UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED",
102 "SET_SINK_MUTE_FOR_SWITCH_DEVICE",
103 "SET_ROTATION_TO_EFFECT",
104 "UPDATE_SESSION_CONNECTION_STATE",
105 "SET_SINGLE_STREAM_MUTE",
106 "RESTORE_SESSION",
107 "GET_ALL_SINK_INPUTS",
108 "SET_DEFAULT_ADAPTER_ENABLE",
109 "CREATE_IPC_OFFLINE_STREAM",
110 "GET_OFFLINE_AUDIO_EFFECT_CHAINS",
111 "GET_STANDBY_STATUS",
112 "GENERATE_SESSION_ID",
113 "NOTIFY_ACCOUNTS_CHANGED",
114 "NOTIFY_AUDIO_POLICY_READY",
115 "SET_CAPTURE_LIMIT",
116 "LOAD_HDI_ADAPTER",
117 "UNLOAD_HDI_ADAPTER",
118 "CHECK_CAPTURE_LIMIT",
119 "RELEASE_CAPTURE_LIMIT",
120 "DEVICE_CONNECTED_FLAG",
121 "NOTIFY_SETTINGS_DATA_READY",
122 };
123 constexpr size_t codeNums = sizeof(g_audioServerCodeStrs) / sizeof(const char *);
124 static_assert(codeNums == (static_cast<size_t> (AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX) + 1),
125 "keep same with AudioServerInterfaceCode");
126 }
LoadEffectLibrariesReadData(vector<Library> & libList,vector<Effect> & effectList,MessageParcel & data,int32_t countLib,int32_t countEff)127 static void LoadEffectLibrariesReadData(vector<Library>& libList, vector<Effect>& effectList, MessageParcel &data,
128 int32_t countLib, int32_t countEff)
129 {
130 int32_t i;
131 for (i = 0; i < countLib; i++) {
132 string libName = data.ReadString();
133 string libPath = data.ReadString();
134 libList.push_back({libName, libPath});
135 }
136 for (i = 0; i < countEff; i++) {
137 string effectName = data.ReadString();
138 string libName = data.ReadString();
139 effectList.push_back({effectName, libName});
140 }
141 }
142
LoadEffectLibrariesWriteReply(const vector<Effect> & successEffectList,MessageParcel & reply)143 static void LoadEffectLibrariesWriteReply(const vector<Effect>& successEffectList, MessageParcel &reply)
144 {
145 reply.WriteInt32(successEffectList.size());
146 for (Effect effect: successEffectList) {
147 reply.WriteString(effect.name);
148 reply.WriteString(effect.libraryName);
149 }
150 }
151
HandleGetAudioParameter(MessageParcel & data,MessageParcel & reply)152 int AudioManagerStub::HandleGetAudioParameter(MessageParcel &data, MessageParcel &reply)
153 {
154 const std::string key = data.ReadString();
155 const std::string value = GetAudioParameter(key);
156 reply.WriteString(value);
157 return AUDIO_OK;
158 }
159
HandleSetAudioParameter(MessageParcel & data,MessageParcel & reply)160 int AudioManagerStub::HandleSetAudioParameter(MessageParcel &data, MessageParcel &reply)
161 {
162 const std::string key = data.ReadString();
163 const std::string value = data.ReadString();
164 SetAudioParameter(key, value);
165 return AUDIO_OK;
166 }
167
HandleSetAsrAecMode(MessageParcel & data,MessageParcel & reply)168 int AudioManagerStub::HandleSetAsrAecMode(MessageParcel &data, MessageParcel &reply)
169 {
170 AsrAecMode asrAecMode = (static_cast<AsrAecMode>(data.ReadInt32()));
171 int32_t result = SetAsrAecMode(asrAecMode);
172 reply.WriteInt32(result);
173 return AUDIO_OK;
174 }
175
HandleGetAsrAecMode(MessageParcel & data,MessageParcel & reply)176 int AudioManagerStub::HandleGetAsrAecMode(MessageParcel &data, MessageParcel &reply)
177 {
178 AsrAecMode asrAecMode = (static_cast<AsrAecMode>(data.ReadInt32()));
179 int32_t ret = GetAsrAecMode(asrAecMode);
180 CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrAec Mode audio parameters failed");
181 reply.WriteInt32(int32_t(asrAecMode));
182 return AUDIO_OK;
183 }
184
HandleSetOffloadMode(MessageParcel & data,MessageParcel & reply)185 int AudioManagerStub::HandleSetOffloadMode(MessageParcel &data, MessageParcel &reply)
186 {
187 uint32_t sessionId = data.ReadUint32();
188 int32_t state = data.ReadInt32();
189 bool isAppBack = data.ReadBool();
190 int32_t result = SetOffloadMode(sessionId, state, isAppBack);
191 reply.WriteInt32(result);
192 return AUDIO_OK;
193 }
194
HandleUnsetOffloadMode(MessageParcel & data,MessageParcel & reply)195 int AudioManagerStub::HandleUnsetOffloadMode(MessageParcel &data, MessageParcel &reply)
196 {
197 uint32_t sessionId = data.ReadUint32();
198 int32_t result = UnsetOffloadMode(sessionId);
199 reply.WriteInt32(result);
200 return AUDIO_OK;
201 }
202
HandleCheckHibernateState(MessageParcel & data,MessageParcel & reply)203 int AudioManagerStub::HandleCheckHibernateState(MessageParcel &data, MessageParcel &reply)
204 {
205 bool onHibernate = data.ReadBool();
206 CheckHibernateState(onHibernate);
207 return AUDIO_OK;
208 }
209
HandleSetAsrNoiseSuppressionMode(MessageParcel & data,MessageParcel & reply)210 int AudioManagerStub::HandleSetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply)
211 {
212 AsrNoiseSuppressionMode asrNoiseSuppressionMode = (static_cast<AsrNoiseSuppressionMode>(data.ReadInt32()));
213 int32_t result = SetAsrNoiseSuppressionMode(asrNoiseSuppressionMode);
214 reply.WriteInt32(result);
215 return AUDIO_OK;
216 }
217
HandleGetAsrNoiseSuppressionMode(MessageParcel & data,MessageParcel & reply)218 int AudioManagerStub::HandleGetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply)
219 {
220 AsrNoiseSuppressionMode asrNoiseSuppressionMode = (static_cast<AsrNoiseSuppressionMode>(data.ReadInt32()));
221 int32_t ret = GetAsrNoiseSuppressionMode(asrNoiseSuppressionMode);
222 CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrNoiseSuppression Mode audio parameters failed");
223 reply.WriteInt32(int32_t(asrNoiseSuppressionMode));
224 return AUDIO_OK;
225 }
226
HandleSetAsrWhisperDetectionMode(MessageParcel & data,MessageParcel & reply)227 int AudioManagerStub::HandleSetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply)
228 {
229 AsrWhisperDetectionMode asrWhisperDetectionMode = (static_cast<AsrWhisperDetectionMode>(data.ReadInt32()));
230 int32_t result = SetAsrWhisperDetectionMode(asrWhisperDetectionMode);
231 reply.WriteInt32(result);
232 return AUDIO_OK;
233 }
234
HandleGetAsrWhisperDetectionMode(MessageParcel & data,MessageParcel & reply)235 int AudioManagerStub::HandleGetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply)
236 {
237 AsrWhisperDetectionMode asrWhisperDetectionMode = (static_cast<AsrWhisperDetectionMode>(data.ReadInt32()));
238 int32_t ret = GetAsrWhisperDetectionMode(asrWhisperDetectionMode);
239 CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrWhisperDetection Mode audio parameters failed");
240 reply.WriteInt32(int32_t(asrWhisperDetectionMode));
241 return AUDIO_OK;
242 }
243
HandleSetAsrVoiceControlMode(MessageParcel & data,MessageParcel & reply)244 int AudioManagerStub::HandleSetAsrVoiceControlMode(MessageParcel &data, MessageParcel &reply)
245 {
246 AsrVoiceControlMode asrVoiceControlMode = (static_cast<AsrVoiceControlMode>(data.ReadInt32()));
247 bool on = data.ReadBool();
248 int32_t result = SetAsrVoiceControlMode(asrVoiceControlMode, on);
249 reply.WriteInt32(result);
250 return AUDIO_OK;
251 }
252
HandleSetAsrVoiceMuteMode(MessageParcel & data,MessageParcel & reply)253 int AudioManagerStub::HandleSetAsrVoiceMuteMode(MessageParcel &data, MessageParcel &reply)
254 {
255 AsrVoiceMuteMode asrVoiceMuteMode = (static_cast<AsrVoiceMuteMode>(data.ReadInt32()));
256 bool on = data.ReadBool();
257 int32_t result = SetAsrVoiceMuteMode(asrVoiceMuteMode, on);
258 reply.WriteInt32(result);
259 return AUDIO_OK;
260 }
261
HandleIsWhispering(MessageParcel & data,MessageParcel & reply)262 int AudioManagerStub::HandleIsWhispering(MessageParcel &data, MessageParcel &reply)
263 {
264 const std::string key = data.ReadString();
265 const std::string value = data.ReadString();
266 int32_t result = IsWhispering();
267 return result;
268 }
269
HandleGetEffectOffloadEnabled(MessageParcel & data,MessageParcel & reply)270 int AudioManagerStub::HandleGetEffectOffloadEnabled(MessageParcel &data, MessageParcel &reply)
271 {
272 bool result = GetEffectOffloadEnabled();
273 return result;
274 }
275
HandleGetExtraAudioParameters(MessageParcel & data,MessageParcel & reply)276 int AudioManagerStub::HandleGetExtraAudioParameters(MessageParcel &data, MessageParcel &reply)
277 {
278 const std::string mainKey = data.ReadString();
279 int32_t num = data.ReadInt32();
280 CHECK_AND_RETURN_RET_LOG(num >= 0 && num <= AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT,
281 AUDIO_ERR, "Get extra audio parameters failed");
282 std::vector<std::string> subKeys = {};
283 for (int32_t i = 0; i < num; i++) {
284 std::string subKey = data.ReadString();
285 subKeys.push_back(subKey);
286 }
287
288 std::vector<std::pair<std::string, std::string>> values;
289 int32_t result = GetExtraParameters(mainKey, subKeys, values);
290 reply.WriteInt32(static_cast<int32_t>(values.size()));
291 for (auto it = values.begin(); it != values.end(); it++) {
292 reply.WriteString(static_cast<std::string>(it->first));
293 reply.WriteString(static_cast<std::string>(it->second));
294 }
295 reply.WriteInt32(result);
296 return AUDIO_OK;
297 }
298
HandleSetExtraAudioParameters(MessageParcel & data,MessageParcel & reply)299 int AudioManagerStub::HandleSetExtraAudioParameters(MessageParcel &data, MessageParcel &reply)
300 {
301 const std::string mainKey = data.ReadString();
302 std::vector<std::pair<std::string, std::string>> audioParametersSubKVPairs;
303 int32_t mapSize = data.ReadInt32();
304 CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT,
305 AUDIO_ERR, "Set extra audio parameters failed");
306 for (int32_t i = 0; i < mapSize; i++) {
307 std::string subKey = data.ReadString();
308 std::string value = data.ReadString();
309 audioParametersSubKVPairs.push_back(std::make_pair(subKey, value));
310 }
311 int32_t result = SetExtraParameters(mainKey, audioParametersSubKVPairs);
312 reply.WriteInt32(result);
313 return AUDIO_OK;
314 }
315
HandleSetMicrophoneMute(MessageParcel & data,MessageParcel & reply)316 int AudioManagerStub::HandleSetMicrophoneMute(MessageParcel &data, MessageParcel &reply)
317 {
318 bool isMute = data.ReadBool();
319 int32_t result = SetMicrophoneMute(isMute);
320 reply.WriteInt32(result);
321 return AUDIO_OK;
322 }
323
HandleSetAudioScene(MessageParcel & data,MessageParcel & reply)324 int AudioManagerStub::HandleSetAudioScene(MessageParcel &data, MessageParcel &reply)
325 {
326 AudioScene audioScene = (static_cast<AudioScene>(data.ReadInt32()));
327 std::vector<DeviceType> activeOutputDevices;
328 int32_t vecSize = data.ReadInt32();
329 CHECK_AND_RETURN_RET_LOG(vecSize > 0 && static_cast<size_t>(vecSize) <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
330 AUDIO_ERR, "HandleSetAudioScene failed");
331 for (int32_t i = 0; i < vecSize; i++) {
332 DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
333 activeOutputDevices.push_back(deviceType);
334 }
335 DeviceType activeInputDevice = (static_cast<DeviceType>(data.ReadInt32()));
336 BluetoothOffloadState a2dpOffloadFlag = static_cast<BluetoothOffloadState>(data.ReadInt32());
337 int32_t result = SetAudioScene(audioScene, activeOutputDevices, activeInputDevice, a2dpOffloadFlag);
338 reply.WriteInt32(result);
339 return AUDIO_OK;
340 }
341
HandleUpdateActiveDeviceRoute(MessageParcel & data,MessageParcel & reply)342 int AudioManagerStub::HandleUpdateActiveDeviceRoute(MessageParcel &data, MessageParcel &reply)
343 {
344 DeviceType type = static_cast<DeviceType>(data.ReadInt32());
345 DeviceFlag flag = static_cast<DeviceFlag>(data.ReadInt32());
346 BluetoothOffloadState a2dpOffloadFlag = static_cast<BluetoothOffloadState>(data.ReadInt32());
347 int32_t ret = UpdateActiveDeviceRoute(type, flag, a2dpOffloadFlag);
348 reply.WriteInt32(ret);
349 return AUDIO_OK;
350 }
351
HandleUpdateActiveDevicesRoute(MessageParcel & data,MessageParcel & reply)352 int AudioManagerStub::HandleUpdateActiveDevicesRoute(MessageParcel &data, MessageParcel &reply)
353 {
354 std::vector<std::pair<DeviceType, DeviceFlag>> activeDevices;
355 int32_t vecSize = data.ReadInt32();
356 CHECK_AND_RETURN_RET_LOG(vecSize > 0 && static_cast<size_t>(vecSize) <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
357 AUDIO_ERR, "HandleUpdateActiveDevicesRoute failed");
358 for (int32_t i = 0; i < vecSize; i++) {
359 DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
360 DeviceFlag deviceFlag = (static_cast<DeviceFlag>(data.ReadInt32()));
361 activeDevices.push_back(std::make_pair(deviceType, deviceFlag));
362 }
363 BluetoothOffloadState a2dpOffloadFlag = static_cast<BluetoothOffloadState>(data.ReadInt32());
364 std::string deviceName = data.ReadString();
365 int32_t ret = UpdateActiveDevicesRoute(activeDevices, a2dpOffloadFlag, deviceName);
366 reply.WriteInt32(ret);
367 return AUDIO_OK;
368 }
369
HandleDualToneState(MessageParcel & data,MessageParcel & reply)370 int AudioManagerStub::HandleDualToneState(MessageParcel &data, MessageParcel &reply)
371 {
372 bool enable = data.ReadBool();
373 int32_t sessionId = data.ReadInt32();
374
375 int32_t ret = UpdateDualToneState(enable, sessionId);
376 reply.WriteInt32(ret);
377 return AUDIO_OK;
378 }
379
HandleGetTransactionId(MessageParcel & data,MessageParcel & reply)380 int AudioManagerStub::HandleGetTransactionId(MessageParcel &data, MessageParcel &reply)
381 {
382 DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
383 DeviceRole deviceRole = (static_cast<DeviceRole>(data.ReadInt32()));
384 uint64_t transactionId = GetTransactionId(deviceType, deviceRole);
385 reply.WriteUint64(transactionId);
386 return AUDIO_OK;
387 }
388
HandleSetParameterCallback(MessageParcel & data,MessageParcel & reply)389 int AudioManagerStub::HandleSetParameterCallback(MessageParcel &data, MessageParcel &reply)
390 {
391 sptr<IRemoteObject> object = data.ReadRemoteObject();
392 CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR, "SET_PARAMETER_CALLBACK obj is null");
393 int32_t result = SetParameterCallback(object);
394 reply.WriteInt32(result);
395 return AUDIO_OK;
396 }
397
HandleGetRemoteAudioParameter(MessageParcel & data,MessageParcel & reply)398 int AudioManagerStub::HandleGetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply)
399 {
400 const std::string networkId = data.ReadString();
401 AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
402 const std::string condition = data.ReadString();
403 const std::string value = GetAudioParameter(networkId, key, condition);
404 reply.WriteString(value);
405 return AUDIO_OK;
406 }
407
HandleSetRemoteAudioParameter(MessageParcel & data,MessageParcel & reply)408 int AudioManagerStub::HandleSetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply)
409 {
410 const std::string networkId = data.ReadString();
411 AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
412 const std::string condtion = data.ReadString();
413 const std::string value = data.ReadString();
414 SetAudioParameter(networkId, key, condtion, value);
415 return AUDIO_OK;
416 }
417
HandleNotifyDeviceInfo(MessageParcel & data,MessageParcel & reply)418 int AudioManagerStub::HandleNotifyDeviceInfo(MessageParcel &data, MessageParcel &reply)
419 {
420 const std::string networkId = data.ReadString();
421 const bool connected = data.ReadBool();
422 NotifyDeviceInfo(networkId, connected);
423 return AUDIO_OK;
424 }
425
HandleCheckRemoteDeviceState(MessageParcel & data,MessageParcel & reply)426 int AudioManagerStub::HandleCheckRemoteDeviceState(MessageParcel &data, MessageParcel &reply)
427 {
428 std::string networkId = data.ReadString();
429 DeviceRole deviceRole = static_cast<DeviceRole>(data.ReadInt32());
430 bool isStartDevice = data.ReadBool();
431 int32_t result = CheckRemoteDeviceState(networkId, deviceRole, isStartDevice);
432 reply.WriteInt32(result);
433 return AUDIO_OK;
434 }
435
HandleSetVoiceVolume(MessageParcel & data,MessageParcel & reply)436 int AudioManagerStub::HandleSetVoiceVolume(MessageParcel &data, MessageParcel &reply)
437 {
438 const float volume = data.ReadFloat();
439 int32_t result = SetVoiceVolume(volume);
440 reply.WriteInt32(result);
441 return AUDIO_OK;
442 }
443
HandleSetAudioMonoState(MessageParcel & data,MessageParcel & reply)444 int AudioManagerStub::HandleSetAudioMonoState(MessageParcel &data, MessageParcel &reply)
445 {
446 bool audioMonoState = data.ReadBool();
447 SetAudioMonoState(audioMonoState);
448 return AUDIO_OK;
449 }
450
HandleSetAudioBalanceValue(MessageParcel & data,MessageParcel & reply)451 int AudioManagerStub::HandleSetAudioBalanceValue(MessageParcel &data, MessageParcel &reply)
452 {
453 float audioBalanceValue = data.ReadFloat();
454 SetAudioBalanceValue(audioBalanceValue);
455 return AUDIO_OK;
456 }
457
HandleCreateAudioProcess(MessageParcel & data,MessageParcel & reply)458 int AudioManagerStub::HandleCreateAudioProcess(MessageParcel &data, MessageParcel &reply)
459 {
460 AudioProcessConfig config;
461 ProcessConfig::ReadConfigFromParcel(config, data);
462 int32_t errorCode = 0;
463 AudioPlaybackCaptureConfig filterConfig;
464 ProcessConfig::ReadInnerCapConfigFromParcel(filterConfig, data);
465 sptr<IRemoteObject> process = CreateAudioProcess(config, errorCode, filterConfig);
466 if (process == nullptr) {
467 AUDIO_ERR_LOG("CREATE_AUDIOPROCESS AudioManagerStub CreateAudioProcess failed");
468 if (errorCode == 0) {
469 errorCode = AUDIO_ERR;
470 }
471 reply.WriteInt32(errorCode);
472 // Only ipc failed need return err. Here using errorCode send information.
473 return AUDIO_OK;
474 }
475
476 reply.WriteInt32(errorCode);
477 reply.WriteRemoteObject(process);
478 return AUDIO_OK;
479 }
480
HandleLoadAudioEffectLibraries(MessageParcel & data,MessageParcel & reply)481 int AudioManagerStub::HandleLoadAudioEffectLibraries(MessageParcel &data, MessageParcel &reply)
482 {
483 vector<Library> libList = {};
484 vector<Effect> effectList = {};
485 int32_t countLib = data.ReadInt32();
486 int32_t countEff = data.ReadInt32();
487 CHECK_AND_RETURN_RET_LOG((countLib >= 0) && (countLib <= AUDIO_EFFECT_COUNT_UPPER_LIMIT) &&
488 (countEff >= 0) && (countEff <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), AUDIO_ERR,
489 "LOAD_AUDIO_EFFECT_LIBRARIES read data failed");
490 LoadEffectLibrariesReadData(libList, effectList, data, countLib, countEff);
491 if (countLib > 0) {
492 // load lib and reply success list
493 vector<Effect> successEffectList = {};
494 bool loadSuccess = LoadAudioEffectLibraries(libList, effectList, successEffectList);
495 CHECK_AND_RETURN_RET_LOG(loadSuccess, AUDIO_ERR, "Load audio effect libraries failed, please check log");
496 LoadEffectLibrariesWriteReply(successEffectList, reply);
497 }
498 return AUDIO_OK;
499 }
500
UnmarshallEffectChainMgrParam(EffectChainManagerParam & effectChainMgrParam,MessageParcel & data)501 static bool UnmarshallEffectChainMgrParam(EffectChainManagerParam &effectChainMgrParam, MessageParcel &data)
502 {
503 effectChainMgrParam.maxExtraNum = static_cast<uint32_t>(data.ReadInt32());
504 effectChainMgrParam.defaultSceneName = data.ReadString();
505
506 int32_t containSize = data.ReadInt32();
507 CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT,
508 false, "Create audio effect priorscene failed, please check log");
509 while (containSize--) {
510 effectChainMgrParam.priorSceneList.emplace_back(data.ReadString());
511 }
512
513 containSize = data.ReadInt32();
514
515 CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT,
516 false, "Create audio effect chain name map failed, please check log");
517 while (containSize--) {
518 string key = data.ReadString();
519 string value = data.ReadString();
520 effectChainMgrParam.sceneTypeToChainNameMap[key] = value;
521 }
522
523 containSize = data.ReadInt32();
524 CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT,
525 false, "Create audio effect default property failed, please check log");
526 while (containSize--) {
527 string key = data.ReadString();
528 string value = data.ReadString();
529 effectChainMgrParam.effectDefaultProperty[key] = value;
530 }
531 return true;
532 }
533
HandleCreateAudioEffectChainManager(MessageParcel & data,MessageParcel & reply)534 int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, MessageParcel &reply)
535 {
536 int32_t i;
537 vector<EffectChain> effectChains = {};
538 vector<int32_t> countEffect = {};
539 int32_t countChains = data.ReadInt32();
540 CHECK_AND_RETURN_RET_LOG(countChains >= 0 && countChains <= AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT,
541 AUDIO_ERR, "Create audio effect chains failed, invalid countChains");
542 for (i = 0; i < countChains; i++) {
543 int32_t count = data.ReadInt32();
544 CHECK_AND_RETURN_RET_LOG(count >= 0 && count <= AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT,
545 AUDIO_ERR, "Create audio effect chains failed, effect countChains");
546 countEffect.emplace_back(count);
547 }
548
549 for (int32_t count: countEffect) {
550 EffectChain effectChain;
551 effectChain.name = data.ReadString();
552 for (i = 0; i < count; i++) {
553 effectChain.apply.emplace_back(data.ReadString());
554 }
555 effectChains.emplace_back(effectChain);
556 }
557
558 EffectChainManagerParam effectParam;
559 EffectChainManagerParam enhanceParam;
560 if (!UnmarshallEffectChainMgrParam(effectParam, data) || !UnmarshallEffectChainMgrParam(enhanceParam, data)) {
561 return AUDIO_ERR;
562 }
563 bool createSuccess = CreateEffectChainManager(effectChains, effectParam, enhanceParam);
564 CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR,
565 "Create audio effect chain manager failed, please check log");
566 return AUDIO_OK;
567 }
568
HandleSetOutputDeviceSink(MessageParcel & data,MessageParcel & reply)569 int AudioManagerStub::HandleSetOutputDeviceSink(MessageParcel &data, MessageParcel &reply)
570 {
571 int32_t deviceType = data.ReadInt32();
572 CHECK_AND_RETURN_RET_LOG(deviceType >= DEVICE_TYPE_NONE && deviceType <= DEVICE_TYPE_MAX, AUDIO_ERR,
573 "Set output device sink failed, please check log");
574 std::string sinkName = data.ReadString();
575 SetOutputDeviceSink(deviceType, sinkName);
576 return AUDIO_OK;
577 }
578
HandleCreatePlaybackCapturerManager(MessageParcel & data,MessageParcel & reply)579 int AudioManagerStub::HandleCreatePlaybackCapturerManager(MessageParcel &data, MessageParcel &reply)
580 {
581 #ifdef HAS_FEATURE_INNERCAPTURER
582 bool ret = CreatePlaybackCapturerManager();
583 reply.WriteBool(ret);
584 return AUDIO_OK;
585 #else
586 return ERROR;
587 #endif
588 }
589
HandleRegiestPolicyProvider(MessageParcel & data,MessageParcel & reply)590 int AudioManagerStub::HandleRegiestPolicyProvider(MessageParcel &data, MessageParcel &reply)
591 {
592 sptr<IRemoteObject> object = data.ReadRemoteObject();
593 CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR, "obj is null");
594 int32_t result = RegiestPolicyProvider(object);
595 reply.WriteInt32(result);
596 return AUDIO_OK;
597 }
598
HandleSetWakeupSourceCallback(MessageParcel & data,MessageParcel & reply)599 int AudioManagerStub::HandleSetWakeupSourceCallback(MessageParcel &data, MessageParcel &reply)
600 {
601 sptr<IRemoteObject> object = data.ReadRemoteObject();
602 CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR,
603 "SET_WAKEUP_CLOSE_CALLBACK obj is null");
604 int32_t result = SetWakeupSourceCallback(object);
605 reply.WriteInt32(result);
606 return AUDIO_OK;
607 }
608
HandleUpdateSpatializationState(MessageParcel & data,MessageParcel & reply)609 int AudioManagerStub::HandleUpdateSpatializationState(MessageParcel &data, MessageParcel &reply)
610 {
611 AudioSpatializationState spatializationState;
612 spatializationState.spatializationEnabled = data.ReadBool();
613 spatializationState.headTrackingEnabled = data.ReadBool();
614 int32_t ret = UpdateSpatializationState(spatializationState);
615 reply.WriteInt32(ret);
616 return AUDIO_OK;
617 }
618
HandleUpdateSpatialDeviceType(MessageParcel & data,MessageParcel & reply)619 int AudioManagerStub::HandleUpdateSpatialDeviceType(MessageParcel& data, MessageParcel& reply)
620 {
621 AudioSpatialDeviceType spatialDeviceType = static_cast<AudioSpatialDeviceType>(data.ReadInt32());
622 int32_t ret = UpdateSpatialDeviceType(spatialDeviceType);
623 reply.WriteInt32(ret);
624 return AUDIO_OK;
625 }
626
HandleOffloadSetVolume(MessageParcel & data,MessageParcel & reply)627 int AudioManagerStub::HandleOffloadSetVolume(MessageParcel &data, MessageParcel &reply)
628 {
629 const float volume = data.ReadFloat();
630 int32_t result = OffloadSetVolume(volume);
631 reply.WriteInt32(result);
632 return AUDIO_OK;
633 }
634
HandleNotifyStreamVolumeChanged(MessageParcel & data,MessageParcel & reply)635 int AudioManagerStub::HandleNotifyStreamVolumeChanged(MessageParcel &data, MessageParcel &reply)
636 {
637 AudioStreamType type = static_cast<AudioStreamType>(data.ReadInt32());
638 float volume = data.ReadFloat();
639 int32_t ret = NotifyStreamVolumeChanged(type, volume);
640 reply.WriteInt32(ret);
641
642 return AUDIO_OK;
643 }
644
HandleSetSpatializationSceneType(MessageParcel & data,MessageParcel & reply)645 int AudioManagerStub::HandleSetSpatializationSceneType(MessageParcel &data, MessageParcel &reply)
646 {
647 AudioSpatializationSceneType spatializationSceneType = static_cast<AudioSpatializationSceneType>(data.ReadInt32());
648 int32_t ret = SetSpatializationSceneType(spatializationSceneType);
649 reply.WriteInt32(ret);
650 return AUDIO_OK;
651 }
652
HandleResetRouteForDisconnect(MessageParcel & data,MessageParcel & reply)653 int AudioManagerStub::HandleResetRouteForDisconnect(MessageParcel &data, MessageParcel &reply)
654 {
655 DeviceType deviceType = static_cast<DeviceType>(data.ReadInt32());
656 int32_t ret = ResetRouteForDisconnect(deviceType);
657 reply.WriteInt32(ret);
658 return AUDIO_OK;
659 }
660
HandleGetEffectLatency(MessageParcel & data,MessageParcel & reply)661 int AudioManagerStub::HandleGetEffectLatency(MessageParcel &data, MessageParcel &reply)
662 {
663 string sessionId = data.ReadString();
664 uint32_t ret = GetEffectLatency(sessionId);
665 reply.WriteUint32(ret);
666 return AUDIO_OK;
667 }
668
HandleGetMaxAmplitude(MessageParcel & data,MessageParcel & reply)669 int AudioManagerStub::HandleGetMaxAmplitude(MessageParcel &data, MessageParcel &reply)
670 {
671 bool isOutputDevice = data.ReadBool();
672 std::string deviceClass = data.ReadString();
673 SourceType sourceType = static_cast<SourceType>(data.ReadInt32());
674 float result = GetMaxAmplitude(isOutputDevice, deviceClass, sourceType);
675 reply.WriteFloat(result);
676 return AUDIO_OK;
677 }
678
HandleResetAudioEndpoint(MessageParcel & data,MessageParcel & reply)679 int AudioManagerStub::HandleResetAudioEndpoint(MessageParcel &data, MessageParcel &reply)
680 {
681 ResetAudioEndpoint();
682 return AUDIO_OK;
683 }
684
HandleSuspendRenderSink(MessageParcel & data,MessageParcel & reply)685 int AudioManagerStub::HandleSuspendRenderSink(MessageParcel &data, MessageParcel &reply)
686 {
687 std::string sinkName = data.ReadString();
688 int32_t ret = SuspendRenderSink(sinkName);
689 reply.WriteInt32(ret);
690 return AUDIO_OK;
691 }
692
HandleRestoreRenderSink(MessageParcel & data,MessageParcel & reply)693 int AudioManagerStub::HandleRestoreRenderSink(MessageParcel &data, MessageParcel &reply)
694 {
695 std::string sinkName = data.ReadString();
696 int32_t ret = RestoreRenderSink(sinkName);
697 reply.WriteInt32(ret);
698 return AUDIO_OK;
699 }
700
HandleUpdateLatencyTimestamp(MessageParcel & data,MessageParcel & reply)701 int AudioManagerStub::HandleUpdateLatencyTimestamp(MessageParcel &data, MessageParcel &reply)
702 {
703 std::string timestamp = data.ReadString();
704 bool isRenderer = data.ReadBool();
705 UpdateLatencyTimestamp(timestamp, isRenderer);
706 return AUDIO_OK;
707 }
708
HandleSetRotationToEffect(MessageParcel & data,MessageParcel & reply)709 int AudioManagerStub::HandleSetRotationToEffect(MessageParcel &data, MessageParcel &reply)
710 {
711 SetRotationToEffect(data.ReadUint32());
712 return AUDIO_OK;
713 }
714
HandleRestoreSession(MessageParcel & data,MessageParcel & reply)715 int AudioManagerStub::HandleRestoreSession(MessageParcel &data, MessageParcel &reply)
716 {
717 RestoreInfo restoreInfo;
718 uint32_t sessionID = data.ReadUint32();
719 restoreInfo.restoreReason = static_cast<RestoreReason>(data.ReadInt32());
720 restoreInfo.deviceChangeReason = data.ReadInt32();
721 restoreInfo.targetStreamFlag = data.ReadInt32();
722 RestoreSession(sessionID, restoreInfo);
723 return AUDIO_OK;
724 }
725
HandleCreateIpcOfflineStream(MessageParcel & data,MessageParcel & reply)726 int AudioManagerStub::HandleCreateIpcOfflineStream(MessageParcel &data, MessageParcel &reply)
727 {
728 int32_t errorCode = 0;
729 sptr<IRemoteObject> process = CreateIpcOfflineStream(errorCode);
730 CHECK_AND_RETURN_RET_LOG(process != nullptr, AUDIO_ERR,
731 "CREATE_IPC_OFFLINE_STREAM AudioManagerStub CreateIpcOfflineStream failed");
732 reply.WriteRemoteObject(process);
733 reply.WriteInt32(errorCode);
734 return AUDIO_OK;
735 }
736
HandleGetOfflineAudioEffectChains(MessageParcel & data,MessageParcel & reply)737 int AudioManagerStub::HandleGetOfflineAudioEffectChains(MessageParcel &data, MessageParcel &reply)
738 {
739 vector<string> effectChains{};
740 int32_t errCode = GetOfflineAudioEffectChains(effectChains);
741 reply.WriteInt32(effectChains.size());
742 for (auto &chainName : effectChains) {
743 reply.WriteString(chainName);
744 }
745 reply.WriteInt32(errCode);
746 return AUDIO_OK;
747 }
748
HandleFourthPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)749 int AudioManagerStub::HandleFourthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
750 MessageOption &option)
751 {
752 switch (code) {
753 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_NOISE_SUPPRESSION_MODE):
754 return HandleGetAsrNoiseSuppressionMode(data, reply);
755 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_WHISPER_DETECTION_MODE):
756 return HandleSetAsrWhisperDetectionMode(data, reply);
757 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_WHISPER_DETECTION_MODE):
758 return HandleGetAsrWhisperDetectionMode(data, reply);
759 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_CONTROL_MODE):
760 return HandleSetAsrVoiceControlMode(data, reply);
761 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_MUTE_MODE):
762 return HandleSetAsrVoiceMuteMode(data, reply);
763 case static_cast<uint32_t>(AudioServerInterfaceCode::IS_WHISPERING):
764 return HandleIsWhispering(data, reply);
765 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_OFFLOAD_ENABLED):
766 return HandleGetEffectOffloadEnabled(data, reply);
767 case static_cast<uint32_t>(AudioServerInterfaceCode::SUSPEND_RENDERSINK):
768 return HandleSuspendRenderSink(data, reply);
769 case static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_RENDERSINK):
770 return HandleRestoreRenderSink(data, reply);
771 case static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_EFFECT_MODEL):
772 return HandleLoadHdiEffectModel(data, reply);
773 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED):
774 return HandleUpdateEffectBtOffloadSupported(data, reply);
775 case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_ACCOUNTS_CHANGED):
776 return HandleNotifyAccountsChanged(data, reply);
777 case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_AUDIO_POLICY_READY):
778 return HandleNotifyAudioPolicyReady(data, reply);
779 case static_cast<uint32_t>(AudioServerInterfaceCode::DEVICE_CONNECTED_FLAG):
780 return HandleDeviceConnectedFlag(data, reply);
781 case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_SETTINGS_DATA_READY):
782 return HandleNotifySettingsDataReady(data, reply);
783 default:
784 return HandleFifthPartCode(code, data, reply, option);
785 }
786 }
787
HandleFifthPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)788 int AudioManagerStub::HandleFifthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
789 MessageOption &option)
790 {
791 switch (code) {
792 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINK_MUTE_FOR_SWITCH_DEVICE):
793 return HandleSetSinkMuteForSwitchDevice(data, reply);
794 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT):
795 return HandleSetRotationToEffect(data, reply);
796 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SESSION_CONNECTION_STATE):
797 return HandleUpdateSessionConnectionState(data, reply);
798 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINGLE_STREAM_MUTE):
799 return HandleSetNonInterruptMute(data, reply);
800 case static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_SESSION):
801 return HandleRestoreSession(data, reply);
802 case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_IPC_OFFLINE_STREAM):
803 return HandleCreateIpcOfflineStream(data, reply);
804 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_OFFLINE_AUDIO_EFFECT_CHAINS):
805 return HandleGetOfflineAudioEffectChains(data, reply);
806 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_STANDBY_STATUS):
807 return HandleGetStandbyStatus(data, reply);
808 case static_cast<uint32_t>(AudioServerInterfaceCode::GENERATE_SESSION_ID):
809 return HandleGenerateSessionId(data, reply);
810 #ifdef HAS_FEATURE_INNERCAPTURER
811 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_CAPTURE_LIMIT):
812 return HandleSetInnerCapLimit(data, reply);
813 case static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_CAPTURE_LIMIT):
814 return HandleCheckCaptureLimit(data, reply);
815 case static_cast<uint32_t>(AudioServerInterfaceCode::RELEASE_CAPTURE_LIMIT):
816 return HandleReleaseCaptureLimit(data, reply);
817 #endif
818 case static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_ADAPTER):
819 return HandleLoadHdiAdapter(data, reply);
820 case static_cast<uint32_t>(AudioServerInterfaceCode::UNLOAD_HDI_ADAPTER):
821 return HandleUnloadHdiAdapter(data, reply);
822 default:
823 AUDIO_ERR_LOG("default case, need check AudioManagerStub");
824 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
825 }
826 }
827
HandleThirdPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)828 int AudioManagerStub::HandleThirdPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
829 MessageOption &option)
830 {
831 switch (code) {
832 case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_STREAM_VOLUME_CHANGED):
833 return HandleNotifyStreamVolumeChanged(data, reply);
834 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE):
835 return HandleSetSpatializationSceneType(data, reply);
836 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_MAX_AMPLITUDE):
837 return HandleGetMaxAmplitude(data, reply);
838 case static_cast<uint32_t>(AudioServerInterfaceCode::RESET_AUDIO_ENDPOINT):
839 return HandleResetAudioEndpoint(data, reply);
840 case static_cast<uint32_t>(AudioServerInterfaceCode::RESET_ROUTE_FOR_DISCONNECT):
841 return HandleResetRouteForDisconnect(data, reply);
842 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_LATENCY):
843 return HandleGetEffectLatency(data, reply);
844 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_LATENCY_TIMESTAMP):
845 return HandleUpdateLatencyTimestamp(data, reply);
846 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_AEC_MODE):
847 return HandleSetAsrAecMode(data, reply);
848 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_AEC_MODE):
849 return HandleGetAsrAecMode(data, reply);
850 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_NOISE_SUPPRESSION_MODE):
851 return HandleSetAsrNoiseSuppressionMode(data, reply);
852 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_OFFLOAD_MODE):
853 return HandleSetOffloadMode(data, reply);
854 case static_cast<uint32_t>(AudioServerInterfaceCode::UNSET_OFFLOAD_MODE):
855 return HandleUnsetOffloadMode(data, reply);
856 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY_V3):
857 return HandleGetAudioEffectPropertyV3(data, reply);
858 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY_V3):
859 return HandleSetAudioEffectPropertyV3(data, reply);
860 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY):
861 return HandleGetAudioEnhanceProperty(data, reply);
862 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY):
863 return HandleGetAudioEffectProperty(data, reply);
864 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY):
865 return HandleSetAudioEnhanceProperty(data, reply);
866 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY):
867 return HandleSetAudioEffectProperty(data, reply);
868 default:
869 return HandleFourthPartCode(code, data, reply, option);
870 }
871 }
872
HandleSecondPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)873 int AudioManagerStub::HandleSecondPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
874 MessageOption &option)
875 {
876 switch (code) {
877 case static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_REMOTE_DEVICE_STATE):
878 return HandleCheckRemoteDeviceState(data, reply);
879 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_VOICE_VOLUME):
880 return HandleSetVoiceVolume(data, reply);
881 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_MONO_STATE):
882 return HandleSetAudioMonoState(data, reply);
883 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_BALANCE_VALUE):
884 return HandleSetAudioBalanceValue(data, reply);
885 case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIOPROCESS):
886 return HandleCreateAudioProcess(data, reply);
887 case static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_AUDIO_EFFECT_LIBRARIES):
888 return HandleLoadAudioEffectLibraries(data, reply);
889 case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER):
890 return HandleCreateAudioEffectChainManager(data, reply);
891 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_OUTPUT_DEVICE_SINK):
892 return HandleSetOutputDeviceSink(data, reply);
893 case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_PLAYBACK_CAPTURER_MANAGER):
894 return HandleCreatePlaybackCapturerManager(data, reply);
895 case static_cast<uint32_t>(AudioServerInterfaceCode::REGISET_POLICY_PROVIDER):
896 return HandleRegiestPolicyProvider(data, reply);
897 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_WAKEUP_CLOSE_CALLBACK):
898 return HandleSetWakeupSourceCallback(data, reply);
899 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIALIZATION_STATE):
900 return HandleUpdateSpatializationState(data, reply);
901 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE):
902 return HandleUpdateSpatialDeviceType(data, reply);
903 case static_cast<uint32_t>(AudioServerInterfaceCode::OFFLOAD_SET_VOLUME):
904 return HandleOffloadSetVolume(data, reply);
905 case static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_HIBERNATE_STATE):
906 return HandleCheckHibernateState(data, reply);
907 default:
908 return HandleThirdPartCode(code, data, reply, option);
909 }
910 }
911
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)912 int AudioManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
913 {
914 CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(),
915 -1, "ReadInterfaceToken failed");
916 Trace trace(code >= codeNums ? "invalid audio server code!" : g_audioServerCodeStrs[code]);
917 if (code <= static_cast<uint32_t>(AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX)) {
918 switch (code) {
919 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_PARAMETER):
920 return HandleGetAudioParameter(data, reply);
921 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_PARAMETER):
922 return HandleSetAudioParameter(data, reply);
923 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EXTRA_AUDIO_PARAMETERS):
924 return HandleGetExtraAudioParameters(data, reply);
925 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_EXTRA_AUDIO_PARAMETERS):
926 return HandleSetExtraAudioParameters(data, reply);
927 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_MICROPHONE_MUTE):
928 return HandleSetMicrophoneMute(data, reply);
929 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_SCENE):
930 return HandleSetAudioScene(data, reply);
931 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTE_REQ):
932 return HandleUpdateActiveDeviceRoute(data, reply);
933 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTES_REQ):
934 return HandleUpdateActiveDevicesRoute(data, reply);
935 case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_DUAL_TONE_REQ):
936 return HandleDualToneState(data, reply);
937 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_TRANSACTION_ID):
938 return HandleGetTransactionId(data, reply);
939 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_PARAMETER_CALLBACK):
940 return HandleSetParameterCallback(data, reply);
941 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_REMOTE_AUDIO_PARAMETER):
942 return HandleGetRemoteAudioParameter(data, reply);
943 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_REMOTE_AUDIO_PARAMETER):
944 return HandleSetRemoteAudioParameter(data, reply);
945 case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_DEVICE_INFO):
946 return HandleNotifyDeviceInfo(data, reply);
947 case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ALL_SINK_INPUTS):
948 return HandleGetAllSinkInputs(data, reply);
949 case static_cast<uint32_t>(AudioServerInterfaceCode::SET_DEFAULT_ADAPTER_ENABLE):
950 return HandleSetDefaultAdapterEnable(data, reply);
951 default:
952 return HandleSecondPartCode(code, data, reply, option);
953 }
954 }
955 AUDIO_ERR_LOG("default case, need check AudioManagerStub");
956 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
957 }
958
HandleLoadHdiEffectModel(MessageParcel & data,MessageParcel & reply)959 int AudioManagerStub::HandleLoadHdiEffectModel(MessageParcel &data, MessageParcel &reply)
960 {
961 LoadHdiEffectModel();
962 return AUDIO_OK;
963 }
964
HandleSetAudioEffectPropertyV3(MessageParcel & data,MessageParcel & reply)965 int AudioManagerStub::HandleSetAudioEffectPropertyV3(MessageParcel &data, MessageParcel &reply)
966 {
967 int32_t size = data.ReadInt32();
968 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
969 ERROR_INVALID_PARAM, "audio enhance property array size invalid");
970 AudioEffectPropertyArrayV3 propertyArray = {};
971 for (int32_t i = 0; i < size; i++) {
972 AudioEffectPropertyV3 prop = {};
973 prop.Unmarshalling(data);
974 propertyArray.property.push_back(prop);
975 }
976 int32_t result = SetAudioEffectProperty(propertyArray);
977 reply.WriteInt32(result);
978 return AUDIO_OK;
979 }
980
HandleGetAudioEffectPropertyV3(MessageParcel & data,MessageParcel & reply)981 int AudioManagerStub::HandleGetAudioEffectPropertyV3(MessageParcel &data, MessageParcel &reply)
982 {
983 AudioEffectPropertyArrayV3 propertyArray = {};
984 int32_t result = GetAudioEffectProperty(propertyArray);
985 int32_t size = static_cast<int32_t>(propertyArray.property.size());
986 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
987 ERROR_INVALID_PARAM, "audio enhance property array size invalid");
988 reply.WriteInt32(size);
989 for (int32_t i = 0; i < size; i++) {
990 propertyArray.property[i].Marshalling(reply);
991 }
992 reply.WriteInt32(result);
993 return AUDIO_OK;
994 }
995
HandleSetAudioEffectProperty(MessageParcel & data,MessageParcel & reply)996 int AudioManagerStub::HandleSetAudioEffectProperty(MessageParcel &data, MessageParcel &reply)
997 {
998 int32_t size = data.ReadInt32();
999 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1000 ERROR_INVALID_PARAM, "Audio enhance property array size invalid");
1001 AudioEffectPropertyArray propertyArray = {};
1002 for (int32_t i = 0; i < size; i++) {
1003 AudioEffectProperty prop = {};
1004 prop.Unmarshalling(data);
1005 propertyArray.property.push_back(prop);
1006 }
1007 int32_t result = SetAudioEffectProperty(propertyArray);
1008 reply.WriteInt32(result);
1009 return AUDIO_OK;
1010 }
1011
HandleGetAudioEffectProperty(MessageParcel & data,MessageParcel & reply)1012 int AudioManagerStub::HandleGetAudioEffectProperty(MessageParcel &data, MessageParcel &reply)
1013 {
1014 AudioEffectPropertyArray propertyArray = {};
1015 int32_t result = GetAudioEffectProperty(propertyArray);
1016 int32_t size = static_cast<int32_t>(propertyArray.property.size());
1017 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1018 ERROR_INVALID_PARAM, "Audio enhance property array size invalid");
1019 reply.WriteInt32(size);
1020 for (int32_t i = 0; i < size; i++) {
1021 propertyArray.property[i].Marshalling(reply);
1022 }
1023 reply.WriteInt32(result);
1024 return AUDIO_OK;
1025 }
1026
HandleSetAudioEnhanceProperty(MessageParcel & data,MessageParcel & reply)1027 int AudioManagerStub::HandleSetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply)
1028 {
1029 int32_t size = data.ReadInt32();
1030 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1031 ERROR_INVALID_PARAM, "Audio enhance property array size invalid");
1032 AudioEnhancePropertyArray propertyArray = {};
1033 for (int32_t i = 0; i < size; i++) {
1034 AudioEnhanceProperty prop = {};
1035 prop.Unmarshalling(data);
1036 propertyArray.property.push_back(prop);
1037 }
1038 DeviceType deviceType = static_cast<DeviceType>(data.ReadInt32());
1039 int32_t result = SetAudioEnhanceProperty(propertyArray, deviceType);
1040 reply.WriteInt32(result);
1041 return AUDIO_OK;
1042 }
1043
HandleGetAudioEnhanceProperty(MessageParcel & data,MessageParcel & reply)1044 int AudioManagerStub::HandleGetAudioEnhanceProperty(MessageParcel &data, MessageParcel &reply)
1045 {
1046 AudioEnhancePropertyArray propertyArray = {};
1047 DeviceType deviceType = static_cast<DeviceType>(data.ReadInt32());
1048 int32_t result = GetAudioEnhanceProperty(propertyArray, deviceType);
1049 int32_t size = static_cast<int32_t>(propertyArray.property.size());
1050 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1051 ERROR_INVALID_PARAM, "Audio enhance property array size invalid");
1052 reply.WriteInt32(size);
1053 for (int32_t i = 0; i < size; i++) {
1054 propertyArray.property[i].Marshalling(reply);
1055 }
1056 reply.WriteInt32(result);
1057 return AUDIO_OK;
1058 }
1059
HandleUpdateEffectBtOffloadSupported(MessageParcel & data,MessageParcel & reply)1060 int AudioManagerStub::HandleUpdateEffectBtOffloadSupported(MessageParcel &data, MessageParcel &reply)
1061 {
1062 UpdateEffectBtOffloadSupported(data.ReadBool());
1063 return AUDIO_OK;
1064 }
1065
HandleSetSinkMuteForSwitchDevice(MessageParcel & data,MessageParcel & reply)1066 int AudioManagerStub::HandleSetSinkMuteForSwitchDevice(MessageParcel &data, MessageParcel &reply)
1067 {
1068 const std::string deviceClass = data.ReadString();
1069 int32_t duration = data.ReadInt32();
1070 int32_t mute = data.ReadBool();
1071 int32_t result = SetSinkMuteForSwitchDevice(deviceClass, duration, mute);
1072 reply.WriteInt32(result);
1073 return AUDIO_OK;
1074 }
1075
HandleUpdateSessionConnectionState(MessageParcel & data,MessageParcel & reply)1076 int AudioManagerStub::HandleUpdateSessionConnectionState(MessageParcel &data, MessageParcel &reply)
1077 {
1078 int32_t sessionID = data.ReadInt32();
1079 int32_t state = data.ReadInt32();
1080 UpdateSessionConnectionState(sessionID, state);
1081 return AUDIO_OK;
1082 }
1083
HandleSetNonInterruptMute(MessageParcel & data,MessageParcel & reply)1084 int AudioManagerStub::HandleSetNonInterruptMute(MessageParcel &data, MessageParcel &reply)
1085 {
1086 uint32_t sessionId = data.ReadUint32();
1087 bool muteFlag = data.ReadBool();
1088 SetNonInterruptMute(sessionId, muteFlag);
1089 return AUDIO_OK;
1090 }
1091
HandleGetStandbyStatus(MessageParcel & data,MessageParcel & reply)1092 int AudioManagerStub::HandleGetStandbyStatus(MessageParcel &data, MessageParcel &reply)
1093 {
1094 uint32_t sessionId = data.ReadUint32();
1095 bool isStandby = false;
1096 int64_t enterStandbyTime = 0;
1097 int32_t result = GetStandbyStatus(sessionId, isStandby, enterStandbyTime);
1098
1099 reply.WriteInt32(result);
1100 reply.WriteBool(isStandby);
1101 reply.WriteInt64(enterStandbyTime);
1102 return AUDIO_OK;
1103 }
1104
HandleGenerateSessionId(MessageParcel & data,MessageParcel & reply)1105 int AudioManagerStub::HandleGenerateSessionId(MessageParcel &data, MessageParcel &reply)
1106 {
1107 uint32_t sessionId = data.ReadUint32();
1108 int32_t ret = GenerateSessionId(sessionId);
1109 CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "generate session id failed");
1110 reply.WriteUint32(sessionId);
1111 return AUDIO_OK;
1112 }
1113
HandleNotifyAccountsChanged(MessageParcel & data,MessageParcel & reply)1114 int AudioManagerStub::HandleNotifyAccountsChanged(MessageParcel &data, MessageParcel &reply)
1115 {
1116 NotifyAccountsChanged();
1117 return AUDIO_OK;
1118 }
1119
HandleGetAllSinkInputs(MessageParcel & data,MessageParcel & reply)1120 int AudioManagerStub::HandleGetAllSinkInputs(MessageParcel &data, MessageParcel &reply)
1121 {
1122 std::vector<SinkInput> sinkInputs;
1123 GetAllSinkInputs(sinkInputs);
1124 size_t size = sinkInputs.size();
1125 reply.WriteUint64(size);
1126 for (auto &sinkInput : sinkInputs) {
1127 sinkInput.Marshalling(reply);
1128 }
1129 return AUDIO_OK;
1130 }
1131
HandleSetDefaultAdapterEnable(MessageParcel & data,MessageParcel & reply)1132 int AudioManagerStub::HandleSetDefaultAdapterEnable(MessageParcel &data, MessageParcel &reply)
1133 {
1134 bool isEnable = data.ReadBool();
1135 SetDefaultAdapterEnable(isEnable);
1136 return AUDIO_OK;
1137 }
1138
HandleNotifyAudioPolicyReady(MessageParcel & data,MessageParcel & reply)1139 int AudioManagerStub::HandleNotifyAudioPolicyReady(MessageParcel &data, MessageParcel &reply)
1140 {
1141 NotifyAudioPolicyReady();
1142 return AUDIO_OK;
1143 }
1144
1145 #ifdef HAS_FEATURE_INNERCAPTURER
HandleSetInnerCapLimit(MessageParcel & data,MessageParcel & reply)1146 int AudioManagerStub::HandleSetInnerCapLimit(MessageParcel &data, MessageParcel &reply)
1147 {
1148 uint32_t innerCapId = data.ReadUint32();
1149 reply.WriteInt32(SetInnerCapLimit(innerCapId));
1150 return AUDIO_OK;
1151 }
1152
HandleCheckCaptureLimit(MessageParcel & data,MessageParcel & reply)1153 int AudioManagerStub::HandleCheckCaptureLimit(MessageParcel &data, MessageParcel &reply)
1154 {
1155 AudioPlaybackCaptureConfig filterConfig;
1156 ProcessConfig::ReadInnerCapConfigFromParcel(filterConfig, data);
1157 int32_t innerCapId = 0;
1158 reply.WriteInt32(CheckCaptureLimit(filterConfig, innerCapId));
1159 return AUDIO_OK;
1160 }
1161
HandleReleaseCaptureLimit(MessageParcel & data,MessageParcel & reply)1162 int AudioManagerStub::HandleReleaseCaptureLimit(MessageParcel &data, MessageParcel &reply)
1163 {
1164 int32_t innerCapId = data.ReadInt32();
1165 reply.WriteInt32(ReleaseCaptureLimit(innerCapId));
1166 return AUDIO_OK;
1167 }
1168 #endif
1169
HandleLoadHdiAdapter(MessageParcel & data,MessageParcel & reply)1170 int AudioManagerStub::HandleLoadHdiAdapter(MessageParcel &data, MessageParcel &reply)
1171 {
1172 uint32_t devMgrType = data.ReadUint32();
1173 const std::string adapterName = data.ReadString();
1174 int32_t result = LoadHdiAdapter(devMgrType, adapterName);
1175 reply.WriteInt32(result);
1176 return AUDIO_OK;
1177 }
1178
HandleUnloadHdiAdapter(MessageParcel & data,MessageParcel & reply)1179 int AudioManagerStub::HandleUnloadHdiAdapter(MessageParcel &data, MessageParcel &reply)
1180 {
1181 uint32_t devMgrType = data.ReadUint32();
1182 const std::string adapterName = data.ReadString();
1183 bool force = data.ReadBool();
1184 UnloadHdiAdapter(devMgrType, adapterName, force);
1185 return AUDIO_OK;
1186 }
1187
HandleDeviceConnectedFlag(MessageParcel & data,MessageParcel & reply)1188 int AudioManagerStub::HandleDeviceConnectedFlag(MessageParcel &data, MessageParcel &reply)
1189 {
1190 bool flag = data.ReadBool();
1191 SetDeviceConnectedFlag(flag);
1192 return AUDIO_OK;
1193 }
1194
HandleNotifySettingsDataReady(MessageParcel & data,MessageParcel & reply)1195 int AudioManagerStub::HandleNotifySettingsDataReady(MessageParcel &data, MessageParcel &reply)
1196 {
1197 NotifySettingsDataReady();
1198 return AUDIO_OK;
1199 }
1200 } // namespace AudioStandard
1201 } // namespace OHOS
1202