• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 const char *g_audioServerCodeStrs[] = {
34     "GET_AUDIO_PARAMETER",
35     "SET_AUDIO_PARAMETER",
36     "GET_EXTRA_AUDIO_PARAMETERS",
37     "SET_EXTRA_AUDIO_PARAMETERS",
38     "SET_MICROPHONE_MUTE",
39     "SET_AUDIO_SCENE",
40     "UPDATE_ROUTE_REQ",
41     "UPDATE_ROUTES_REQ",
42     "UPDATE_DUAL_TONE_REQ",
43     "GET_TRANSACTION_ID",
44     "SET_PARAMETER_CALLBACK",
45     "GET_REMOTE_AUDIO_PARAMETER",
46     "SET_REMOTE_AUDIO_PARAMETER",
47     "NOTIFY_DEVICE_INFO",
48     "CHECK_REMOTE_DEVICE_STATE",
49     "SET_VOICE_VOLUME",
50     "SET_AUDIO_MONO_STATE",
51     "SET_AUDIO_BALANCE_VALUE",
52     "CREATE_AUDIOPROCESS",
53     "LOAD_AUDIO_EFFECT_LIBRARIES",
54     "REQUEST_THREAD_PRIORITY",
55     "CREATE_AUDIO_EFFECT_CHAIN_MANAGER",
56     "SET_OUTPUT_DEVICE_SINK",
57     "CREATE_PLAYBACK_CAPTURER_MANAGER",
58     "REGISET_POLICY_PROVIDER",
59     "SET_WAKEUP_CLOSE_CALLBACK",
60     "UPDATE_SPATIALIZATION_STATE",
61     "UPDATE_SPATIAL_DEVICE_TYPE",
62     "OFFLOAD_SET_VOLUME",
63     "NOTIFY_STREAM_VOLUME_CHANGED",
64     "SET_SPATIALIZATION_SCENE_TYPE",
65     "GET_MAX_AMPLITUDE",
66     "RESET_AUDIO_ENDPOINT",
67     "RESET_ROUTE_FOR_DISCONNECT",
68     "GET_EFFECT_LATENCY",
69     "UPDATE_LATENCY_TIMESTAMP",
70     "SET_ASR_AEC_MODE",
71     "GET_ASR_AEC_MODE",
72     "SET_ASR_NOISE_SUPPRESSION_MODE",
73     "GET_ASR_NOISE_SUPPRESSION_MODE",
74     "SET_ASR_WHISPER_DETECTION_MODE",
75     "GET_ASR_WHISPER_DETECTION_MODE",
76     "SET_ASR_VOICE_CONTROL_MODE",
77     "SET_ASR_VOICE_MUTE_MODE",
78     "IS_WHISPERING",
79     "GET_EFFECT_OFFLOAD_ENABLED",
80     "SUSPEND_RENDERSINK",
81     "RESTORE_RENDERSINK",
82     "LOAD_HDI_EFFECT_MODEL",
83     "GET_AUDIO_EFFECT_PROPERTY_V3",
84     "SET_AUDIO_EFFECT_PROPERTY_V3",
85     "UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED",
86     "SET_SINK_MUTE_FOR_SWITCH_DEVICE",
87     "SET_ROTATION_TO_EFFECT",
88     "UPDATE_SESSION_CONNECTION_STATE",
89     "SET_SINGLE_STREAM_MUTE",
90     "CREATE_IPC_OFFLINE_STREAM",
91     "GET_OFFLINE_AUDIO_EFFECT_CHAINS",
92     "GET_STANDBY_STATUS",
93 };
94 constexpr size_t codeNums = sizeof(g_audioServerCodeStrs) / sizeof(const char *);
95 static_assert(codeNums == (static_cast<size_t> (AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX) + 1),
96     "keep same with AudioServerInterfaceCode");
97 }
LoadEffectLibrariesReadData(vector<Library> & libList,vector<Effect> & effectList,MessageParcel & data,int32_t countLib,int32_t countEff)98 static void LoadEffectLibrariesReadData(vector<Library>& libList, vector<Effect>& effectList, MessageParcel &data,
99     int32_t countLib, int32_t countEff)
100 {
101     int32_t i;
102     for (i = 0; i < countLib; i++) {
103         string libName = data.ReadString();
104         string libPath = data.ReadString();
105         libList.push_back({libName, libPath});
106     }
107     for (i = 0; i < countEff; i++) {
108         string effectName = data.ReadString();
109         string libName = data.ReadString();
110         effectList.push_back({effectName, libName});
111     }
112 }
113 
LoadEffectLibrariesWriteReply(const vector<Effect> & successEffectList,MessageParcel & reply)114 static void LoadEffectLibrariesWriteReply(const vector<Effect>& successEffectList, MessageParcel &reply)
115 {
116     reply.WriteInt32(successEffectList.size());
117     for (Effect effect: successEffectList) {
118         reply.WriteString(effect.name);
119         reply.WriteString(effect.libraryName);
120     }
121 }
122 
HandleGetAudioParameter(MessageParcel & data,MessageParcel & reply)123 int AudioManagerStub::HandleGetAudioParameter(MessageParcel &data, MessageParcel &reply)
124 {
125     const std::string key = data.ReadString();
126     const std::string value = GetAudioParameter(key);
127     reply.WriteString(value);
128     return AUDIO_OK;
129 }
130 
HandleSetAudioParameter(MessageParcel & data,MessageParcel & reply)131 int AudioManagerStub::HandleSetAudioParameter(MessageParcel &data, MessageParcel &reply)
132 {
133     const std::string key = data.ReadString();
134     const std::string value = data.ReadString();
135     SetAudioParameter(key, value);
136     return AUDIO_OK;
137 }
138 
HandleSetAsrAecMode(MessageParcel & data,MessageParcel & reply)139 int AudioManagerStub::HandleSetAsrAecMode(MessageParcel &data, MessageParcel &reply)
140 {
141     AsrAecMode asrAecMode = (static_cast<AsrAecMode>(data.ReadInt32()));
142     int32_t result = SetAsrAecMode(asrAecMode);
143     reply.WriteInt32(result);
144     return AUDIO_OK;
145 }
146 
HandleGetAsrAecMode(MessageParcel & data,MessageParcel & reply)147 int AudioManagerStub::HandleGetAsrAecMode(MessageParcel &data, MessageParcel &reply)
148 {
149     AsrAecMode asrAecMode = (static_cast<AsrAecMode>(data.ReadInt32()));
150     int32_t ret = GetAsrAecMode(asrAecMode);
151     CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrAec Mode audio parameters failed");
152     reply.WriteInt32(int32_t(asrAecMode));
153     return AUDIO_OK;
154 }
155 
HandleSetAsrNoiseSuppressionMode(MessageParcel & data,MessageParcel & reply)156 int AudioManagerStub::HandleSetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply)
157 {
158     AsrNoiseSuppressionMode asrNoiseSuppressionMode = (static_cast<AsrNoiseSuppressionMode>(data.ReadInt32()));
159     int32_t result = SetAsrNoiseSuppressionMode(asrNoiseSuppressionMode);
160     reply.WriteInt32(result);
161     return AUDIO_OK;
162 }
163 
HandleGetAsrNoiseSuppressionMode(MessageParcel & data,MessageParcel & reply)164 int AudioManagerStub::HandleGetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply)
165 {
166     AsrNoiseSuppressionMode asrNoiseSuppressionMode = (static_cast<AsrNoiseSuppressionMode>(data.ReadInt32()));
167     int32_t ret = GetAsrNoiseSuppressionMode(asrNoiseSuppressionMode);
168     CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrNoiseSuppression Mode audio parameters failed");
169     reply.WriteInt32(int32_t(asrNoiseSuppressionMode));
170     return AUDIO_OK;
171 }
172 
HandleSetAsrWhisperDetectionMode(MessageParcel & data,MessageParcel & reply)173 int AudioManagerStub::HandleSetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply)
174 {
175     AsrWhisperDetectionMode asrWhisperDetectionMode = (static_cast<AsrWhisperDetectionMode>(data.ReadInt32()));
176     int32_t result = SetAsrWhisperDetectionMode(asrWhisperDetectionMode);
177     reply.WriteInt32(result);
178     return AUDIO_OK;
179 }
180 
HandleGetAsrWhisperDetectionMode(MessageParcel & data,MessageParcel & reply)181 int AudioManagerStub::HandleGetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply)
182 {
183     AsrWhisperDetectionMode asrWhisperDetectionMode = (static_cast<AsrWhisperDetectionMode>(data.ReadInt32()));
184     int32_t ret = GetAsrWhisperDetectionMode(asrWhisperDetectionMode);
185     CHECK_AND_RETURN_RET_LOG(ret == 0, AUDIO_ERR, "Get AsrWhisperDetection Mode audio parameters failed");
186     reply.WriteInt32(int32_t(asrWhisperDetectionMode));
187     return AUDIO_OK;
188 }
189 
HandleSetAsrVoiceControlMode(MessageParcel & data,MessageParcel & reply)190 int AudioManagerStub::HandleSetAsrVoiceControlMode(MessageParcel &data, MessageParcel &reply)
191 {
192     AsrVoiceControlMode asrVoiceControlMode = (static_cast<AsrVoiceControlMode>(data.ReadInt32()));
193     bool on = data.ReadBool();
194     int32_t result = SetAsrVoiceControlMode(asrVoiceControlMode, on);
195     reply.WriteInt32(result);
196     return AUDIO_OK;
197 }
198 
HandleSetAsrVoiceMuteMode(MessageParcel & data,MessageParcel & reply)199 int AudioManagerStub::HandleSetAsrVoiceMuteMode(MessageParcel &data, MessageParcel &reply)
200 {
201     AsrVoiceMuteMode asrVoiceMuteMode = (static_cast<AsrVoiceMuteMode>(data.ReadInt32()));
202     bool on = data.ReadBool();
203     int32_t result = SetAsrVoiceMuteMode(asrVoiceMuteMode, on);
204     reply.WriteInt32(result);
205     return AUDIO_OK;
206 }
207 
HandleIsWhispering(MessageParcel & data,MessageParcel & reply)208 int AudioManagerStub::HandleIsWhispering(MessageParcel &data, MessageParcel &reply)
209 {
210     const std::string key = data.ReadString();
211     const std::string value = data.ReadString();
212     int32_t result = IsWhispering();
213     return result;
214 }
215 
HandleGetEffectOffloadEnabled(MessageParcel & data,MessageParcel & reply)216 int AudioManagerStub::HandleGetEffectOffloadEnabled(MessageParcel &data, MessageParcel &reply)
217 {
218     bool result = GetEffectOffloadEnabled();
219     return result;
220 }
221 
HandleGetExtraAudioParameters(MessageParcel & data,MessageParcel & reply)222 int AudioManagerStub::HandleGetExtraAudioParameters(MessageParcel &data, MessageParcel &reply)
223 {
224     const std::string mainKey = data.ReadString();
225     int32_t num = data.ReadInt32();
226     CHECK_AND_RETURN_RET_LOG(num >= 0 && num <= AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT,
227         AUDIO_ERR, "Get extra audio parameters failed");
228     std::vector<std::string> subKeys = {};
229     for (int32_t i = 0; i < num; i++) {
230         std::string subKey = data.ReadString();
231         subKeys.push_back(subKey);
232     }
233 
234     std::vector<std::pair<std::string, std::string>> values;
235     int32_t result = GetExtraParameters(mainKey, subKeys, values);
236     reply.WriteInt32(static_cast<int32_t>(values.size()));
237     for (auto it = values.begin(); it != values.end(); it++) {
238         reply.WriteString(static_cast<std::string>(it->first));
239         reply.WriteString(static_cast<std::string>(it->second));
240     }
241     reply.WriteInt32(result);
242     return AUDIO_OK;
243 }
244 
HandleSetExtraAudioParameters(MessageParcel & data,MessageParcel & reply)245 int AudioManagerStub::HandleSetExtraAudioParameters(MessageParcel &data, MessageParcel &reply)
246 {
247     const std::string mainKey = data.ReadString();
248     std::vector<std::pair<std::string, std::string>> audioParametersSubKVPairs;
249     int32_t mapSize = data.ReadInt32();
250     CHECK_AND_RETURN_RET_LOG(mapSize >= 0 && mapSize <= AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT,
251         AUDIO_ERR, "Set extra audio parameters failed");
252     for (int32_t i = 0; i < mapSize; i++) {
253         std::string subKey = data.ReadString();
254         std::string value = data.ReadString();
255         audioParametersSubKVPairs.push_back(std::make_pair(subKey, value));
256     }
257     int32_t result = SetExtraParameters(mainKey, audioParametersSubKVPairs);
258     reply.WriteInt32(result);
259     return AUDIO_OK;
260 }
261 
HandleSetMicrophoneMute(MessageParcel & data,MessageParcel & reply)262 int AudioManagerStub::HandleSetMicrophoneMute(MessageParcel &data, MessageParcel &reply)
263 {
264     bool isMute = data.ReadBool();
265     int32_t result = SetMicrophoneMute(isMute);
266     reply.WriteInt32(result);
267     return AUDIO_OK;
268 }
269 
HandleSetAudioScene(MessageParcel & data,MessageParcel & reply)270 int AudioManagerStub::HandleSetAudioScene(MessageParcel &data, MessageParcel &reply)
271 {
272     AudioScene audioScene = (static_cast<AudioScene>(data.ReadInt32()));
273     std::vector<DeviceType> activeOutputDevices;
274     int32_t vecSize = data.ReadInt32();
275     CHECK_AND_RETURN_RET_LOG(vecSize > 0 && static_cast<size_t>(vecSize) <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
276         AUDIO_ERR, "HandleSetAudioScene failed");
277     for (int32_t i = 0; i < vecSize; i++) {
278         DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
279         activeOutputDevices.push_back(deviceType);
280     }
281     DeviceType activeInputDevice = (static_cast<DeviceType>(data.ReadInt32()));
282     BluetoothOffloadState a2dpOffloadFlag =  static_cast<BluetoothOffloadState>(data.ReadInt32());
283     int32_t result = SetAudioScene(audioScene, activeOutputDevices, activeInputDevice, a2dpOffloadFlag);
284     reply.WriteInt32(result);
285     return AUDIO_OK;
286 }
287 
HandleUpdateActiveDeviceRoute(MessageParcel & data,MessageParcel & reply)288 int AudioManagerStub::HandleUpdateActiveDeviceRoute(MessageParcel &data, MessageParcel &reply)
289 {
290     DeviceType type = static_cast<DeviceType>(data.ReadInt32());
291     DeviceFlag flag = static_cast<DeviceFlag>(data.ReadInt32());
292     BluetoothOffloadState a2dpOffloadFlag =  static_cast<BluetoothOffloadState>(data.ReadInt32());
293     int32_t ret = UpdateActiveDeviceRoute(type, flag, a2dpOffloadFlag);
294     reply.WriteInt32(ret);
295     return AUDIO_OK;
296 }
297 
HandleUpdateActiveDevicesRoute(MessageParcel & data,MessageParcel & reply)298 int AudioManagerStub::HandleUpdateActiveDevicesRoute(MessageParcel &data, MessageParcel &reply)
299 {
300     std::vector<std::pair<DeviceType, DeviceFlag>> activeDevices;
301     int32_t vecSize = data.ReadInt32();
302     CHECK_AND_RETURN_RET_LOG(vecSize > 0 && static_cast<size_t>(vecSize) <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
303         AUDIO_ERR, "HandleUpdateActiveDevicesRoute failed");
304     for (int32_t i = 0; i < vecSize; i++) {
305         DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
306         DeviceFlag deviceFlag = (static_cast<DeviceFlag>(data.ReadInt32()));
307         activeDevices.push_back(std::make_pair(deviceType, deviceFlag));
308     }
309     BluetoothOffloadState a2dpOffloadFlag =  static_cast<BluetoothOffloadState>(data.ReadInt32());
310     int32_t ret = UpdateActiveDevicesRoute(activeDevices, a2dpOffloadFlag);
311     reply.WriteInt32(ret);
312     return AUDIO_OK;
313 }
314 
HandleDualToneState(MessageParcel & data,MessageParcel & reply)315 int AudioManagerStub::HandleDualToneState(MessageParcel &data, MessageParcel &reply)
316 {
317     bool enable = data.ReadBool();
318     int32_t sessionId = data.ReadInt32();
319 
320     int32_t ret = UpdateDualToneState(enable, sessionId);
321     reply.WriteInt32(ret);
322     return AUDIO_OK;
323 }
324 
HandleGetTransactionId(MessageParcel & data,MessageParcel & reply)325 int AudioManagerStub::HandleGetTransactionId(MessageParcel &data, MessageParcel &reply)
326 {
327     DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
328     DeviceRole deviceRole = (static_cast<DeviceRole>(data.ReadInt32()));
329     uint64_t transactionId = GetTransactionId(deviceType, deviceRole);
330     reply.WriteUint64(transactionId);
331     return AUDIO_OK;
332 }
333 
HandleSetParameterCallback(MessageParcel & data,MessageParcel & reply)334 int AudioManagerStub::HandleSetParameterCallback(MessageParcel &data, MessageParcel &reply)
335 {
336     sptr<IRemoteObject> object = data.ReadRemoteObject();
337     CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR, "SET_PARAMETER_CALLBACK obj is null");
338     int32_t result = SetParameterCallback(object);
339     reply.WriteInt32(result);
340     return AUDIO_OK;
341 }
342 
HandleGetRemoteAudioParameter(MessageParcel & data,MessageParcel & reply)343 int AudioManagerStub::HandleGetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply)
344 {
345     const std::string networkId = data.ReadString();
346     AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
347     const std::string condition = data.ReadString();
348     const std::string value = GetAudioParameter(networkId, key, condition);
349     reply.WriteString(value);
350     return AUDIO_OK;
351 }
352 
HandleSetRemoteAudioParameter(MessageParcel & data,MessageParcel & reply)353 int AudioManagerStub::HandleSetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply)
354 {
355     const std::string networkId = data.ReadString();
356     AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
357     const std::string condtion = data.ReadString();
358     const std::string value = data.ReadString();
359     SetAudioParameter(networkId, key, condtion, value);
360     return AUDIO_OK;
361 }
362 
HandleNotifyDeviceInfo(MessageParcel & data,MessageParcel & reply)363 int AudioManagerStub::HandleNotifyDeviceInfo(MessageParcel &data, MessageParcel &reply)
364 {
365     const std::string networkId = data.ReadString();
366     const bool connected = data.ReadBool();
367     NotifyDeviceInfo(networkId, connected);
368     return AUDIO_OK;
369 }
370 
HandleCheckRemoteDeviceState(MessageParcel & data,MessageParcel & reply)371 int AudioManagerStub::HandleCheckRemoteDeviceState(MessageParcel &data, MessageParcel &reply)
372 {
373     std::string networkId = data.ReadString();
374     DeviceRole deviceRole = static_cast<DeviceRole>(data.ReadInt32());
375     bool isStartDevice = data.ReadBool();
376     int32_t result = CheckRemoteDeviceState(networkId, deviceRole, isStartDevice);
377     reply.WriteInt32(result);
378     return AUDIO_OK;
379 }
380 
HandleSetVoiceVolume(MessageParcel & data,MessageParcel & reply)381 int AudioManagerStub::HandleSetVoiceVolume(MessageParcel &data, MessageParcel &reply)
382 {
383     const float volume = data.ReadFloat();
384     int32_t result = SetVoiceVolume(volume);
385     reply.WriteInt32(result);
386     return AUDIO_OK;
387 }
388 
HandleSetAudioMonoState(MessageParcel & data,MessageParcel & reply)389 int AudioManagerStub::HandleSetAudioMonoState(MessageParcel &data, MessageParcel &reply)
390 {
391     bool audioMonoState = data.ReadBool();
392     SetAudioMonoState(audioMonoState);
393     return AUDIO_OK;
394 }
395 
HandleSetAudioBalanceValue(MessageParcel & data,MessageParcel & reply)396 int AudioManagerStub::HandleSetAudioBalanceValue(MessageParcel &data, MessageParcel &reply)
397 {
398     float audioBalanceValue = data.ReadFloat();
399     SetAudioBalanceValue(audioBalanceValue);
400     return AUDIO_OK;
401 }
402 
HandleCreateAudioProcess(MessageParcel & data,MessageParcel & reply)403 int AudioManagerStub::HandleCreateAudioProcess(MessageParcel &data, MessageParcel &reply)
404 {
405     AudioProcessConfig config;
406     ProcessConfig::ReadConfigFromParcel(config, data);
407     int32_t errorCode = 0;
408     sptr<IRemoteObject> process = CreateAudioProcess(config, errorCode);
409     CHECK_AND_RETURN_RET_LOG(process != nullptr, AUDIO_ERR,
410         "CREATE_AUDIOPROCESS AudioManagerStub CreateAudioProcess failed");
411     reply.WriteRemoteObject(process);
412     reply.WriteInt32(errorCode);
413     return AUDIO_OK;
414 }
415 
HandleLoadAudioEffectLibraries(MessageParcel & data,MessageParcel & reply)416 int AudioManagerStub::HandleLoadAudioEffectLibraries(MessageParcel &data, MessageParcel &reply)
417 {
418     vector<Library> libList = {};
419     vector<Effect> effectList = {};
420     int32_t countLib = data.ReadInt32();
421     int32_t countEff = data.ReadInt32();
422     CHECK_AND_RETURN_RET_LOG((countLib >= 0) && (countLib <= AUDIO_EFFECT_COUNT_UPPER_LIMIT) &&
423         (countEff >= 0) && (countEff <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), AUDIO_ERR,
424         "LOAD_AUDIO_EFFECT_LIBRARIES read data failed");
425     LoadEffectLibrariesReadData(libList, effectList, data, countLib, countEff);
426     if (countLib > 0) {
427         // load lib and reply success list
428         vector<Effect> successEffectList = {};
429         bool loadSuccess = LoadAudioEffectLibraries(libList, effectList, successEffectList);
430         CHECK_AND_RETURN_RET_LOG(loadSuccess, AUDIO_ERR, "Load audio effect libraries failed, please check log");
431         LoadEffectLibrariesWriteReply(successEffectList, reply);
432     }
433     return AUDIO_OK;
434 }
435 
HandleRequestThreadPriority(MessageParcel & data,MessageParcel & reply)436 int AudioManagerStub::HandleRequestThreadPriority(MessageParcel &data, MessageParcel &reply)
437 {
438     uint32_t tid = data.ReadUint32();
439     string bundleName = data.ReadString();
440     RequestThreadPriority(tid, bundleName);
441     return AUDIO_OK;
442 }
443 
UnmarshellEffectChainMgrParam(EffectChainManagerParam & effectChainMgrParam,MessageParcel & data)444 static bool UnmarshellEffectChainMgrParam(EffectChainManagerParam &effectChainMgrParam, MessageParcel &data)
445 {
446     effectChainMgrParam.maxExtraNum = static_cast <uint32_t>(data.ReadInt32());
447     effectChainMgrParam.defaultSceneName = data.ReadString();
448 
449     int32_t containSize = data.ReadInt32();
450     CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT,
451         false, "Create audio effect prioscene failed, please check log");
452     while (containSize--) {
453         effectChainMgrParam.priorSceneList.emplace_back(data.ReadString());
454     }
455 
456     containSize = data.ReadInt32();
457     CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT,
458         false, "Create audio effect chain name map failed, please check log");
459     while (containSize--) {
460         string key = data.ReadString();
461         string value = data.ReadString();
462         effectChainMgrParam.sceneTypeToChainNameMap[key] = value;
463     }
464 
465     containSize = data.ReadInt32();
466     CHECK_AND_RETURN_RET_LOG(containSize >= 0 && containSize <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT,
467         false, "Create audio effect default property failed, please check log");
468     while (containSize--) {
469         string key = data.ReadString();
470         string value = data.ReadString();
471         effectChainMgrParam.effectDefaultProperty[key] = value;
472     }
473     return true;
474 }
475 
HandleCreateAudioEffectChainManager(MessageParcel & data,MessageParcel & reply)476 int AudioManagerStub::HandleCreateAudioEffectChainManager(MessageParcel &data, MessageParcel &reply)
477 {
478     int32_t i;
479     vector<EffectChain> effectChains = {};
480     vector<int32_t> countEffect = {};
481     int32_t countChains = data.ReadInt32();
482     CHECK_AND_RETURN_RET_LOG(countChains >= 0 && countChains <= AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT,
483         AUDIO_ERR, "Create audio effect chains failed, invalid countChains");
484     for (i = 0; i < countChains; i++) {
485         int32_t count = data.ReadInt32();
486         CHECK_AND_RETURN_RET_LOG(count >= 0 && count <= AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT,
487             AUDIO_ERR, "Create audio effect chains failed, invalid count");
488         countEffect.emplace_back(count);
489     }
490 
491     for (int32_t count: countEffect) {
492         EffectChain effectChain;
493         effectChain.name = data.ReadString();
494         for (i = 0; i < count; i++) {
495             effectChain.apply.emplace_back(data.ReadString());
496         }
497         effectChains.emplace_back(effectChain);
498     }
499 
500     EffectChainManagerParam effectParam;
501     EffectChainManagerParam enhanceParam;
502     if (!UnmarshellEffectChainMgrParam(effectParam, data) || !UnmarshellEffectChainMgrParam(enhanceParam, data)) {
503         return AUDIO_ERR;
504     }
505 
506     bool createSuccess = CreateEffectChainManager(effectChains, effectParam, enhanceParam);
507     CHECK_AND_RETURN_RET_LOG(createSuccess, AUDIO_ERR,
508         "Create audio effect chain manager failed, please check log");
509     return AUDIO_OK;
510 }
511 
HandleSetOutputDeviceSink(MessageParcel & data,MessageParcel & reply)512 int AudioManagerStub::HandleSetOutputDeviceSink(MessageParcel &data, MessageParcel &reply)
513 {
514     int32_t deviceType = data.ReadInt32();
515     CHECK_AND_RETURN_RET_LOG(deviceType >= DEVICE_TYPE_NONE && deviceType <= DEVICE_TYPE_MAX, AUDIO_ERR,
516         "Set output device sink failed, please check log");
517     std::string sinkName = data.ReadString();
518     SetOutputDeviceSink(deviceType, sinkName);
519     return AUDIO_OK;
520 }
521 
HandleCreatePlaybackCapturerManager(MessageParcel & data,MessageParcel & reply)522 int AudioManagerStub::HandleCreatePlaybackCapturerManager(MessageParcel &data, MessageParcel &reply)
523 {
524     bool ret = CreatePlaybackCapturerManager();
525     reply.WriteBool(ret);
526     return AUDIO_OK;
527 }
528 
HandleRegiestPolicyProvider(MessageParcel & data,MessageParcel & reply)529 int AudioManagerStub::HandleRegiestPolicyProvider(MessageParcel &data, MessageParcel &reply)
530 {
531     sptr<IRemoteObject> object = data.ReadRemoteObject();
532     CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR, "obj is null");
533     int32_t result = RegiestPolicyProvider(object);
534     reply.WriteInt32(result);
535     return AUDIO_OK;
536 }
537 
HandleSetWakeupSourceCallback(MessageParcel & data,MessageParcel & reply)538 int AudioManagerStub::HandleSetWakeupSourceCallback(MessageParcel &data, MessageParcel &reply)
539 {
540     sptr<IRemoteObject> object = data.ReadRemoteObject();
541     CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_ERR,
542         "SET_WAKEUP_CLOSE_CALLBACK obj is null");
543     int32_t result = SetWakeupSourceCallback(object);
544     reply.WriteInt32(result);
545     return AUDIO_OK;
546 }
547 
HandleUpdateSpatializationState(MessageParcel & data,MessageParcel & reply)548 int AudioManagerStub::HandleUpdateSpatializationState(MessageParcel &data, MessageParcel &reply)
549 {
550     AudioSpatializationState spatializationState;
551     spatializationState.spatializationEnabled = data.ReadBool();
552     spatializationState.headTrackingEnabled = data.ReadBool();
553     int32_t ret = UpdateSpatializationState(spatializationState);
554     reply.WriteInt32(ret);
555     return AUDIO_OK;
556 }
557 
HandleUpdateSpatialDeviceType(MessageParcel & data,MessageParcel & reply)558 int AudioManagerStub::HandleUpdateSpatialDeviceType(MessageParcel& data, MessageParcel& reply)
559 {
560     AudioSpatialDeviceType spatialDeviceType = static_cast<AudioSpatialDeviceType>(data.ReadInt32());
561     int32_t ret = UpdateSpatialDeviceType(spatialDeviceType);
562     reply.WriteInt32(ret);
563     return AUDIO_OK;
564 }
565 
HandleOffloadSetVolume(MessageParcel & data,MessageParcel & reply)566 int AudioManagerStub::HandleOffloadSetVolume(MessageParcel &data, MessageParcel &reply)
567 {
568     const float volume = data.ReadFloat();
569     int32_t result = OffloadSetVolume(volume);
570     reply.WriteInt32(result);
571     return AUDIO_OK;
572 }
573 
HandleNotifyStreamVolumeChanged(MessageParcel & data,MessageParcel & reply)574 int AudioManagerStub::HandleNotifyStreamVolumeChanged(MessageParcel &data, MessageParcel &reply)
575 {
576     AudioStreamType type = static_cast<AudioStreamType>(data.ReadInt32());
577     float volume = data.ReadFloat();
578     int32_t ret = NotifyStreamVolumeChanged(type, volume);
579     reply.WriteInt32(ret);
580 
581     return AUDIO_OK;
582 }
583 
HandleSetSpatializationSceneType(MessageParcel & data,MessageParcel & reply)584 int AudioManagerStub::HandleSetSpatializationSceneType(MessageParcel &data, MessageParcel &reply)
585 {
586     AudioSpatializationSceneType spatializationSceneType = static_cast<AudioSpatializationSceneType>(data.ReadInt32());
587     int32_t ret = SetSpatializationSceneType(spatializationSceneType);
588     reply.WriteInt32(ret);
589     return AUDIO_OK;
590 }
591 
HandleResetRouteForDisconnect(MessageParcel & data,MessageParcel & reply)592 int AudioManagerStub::HandleResetRouteForDisconnect(MessageParcel &data, MessageParcel &reply)
593 {
594     DeviceType deviceType = static_cast<DeviceType>(data.ReadInt32());
595     int32_t ret = ResetRouteForDisconnect(deviceType);
596     reply.WriteInt32(ret);
597     return AUDIO_OK;
598 }
599 
HandleGetEffectLatency(MessageParcel & data,MessageParcel & reply)600 int AudioManagerStub::HandleGetEffectLatency(MessageParcel &data, MessageParcel &reply)
601 {
602     string sessionId = data.ReadString();
603     uint32_t ret = GetEffectLatency(sessionId);
604     reply.WriteUint32(ret);
605     return AUDIO_OK;
606 }
607 
HandleUpdateLatencyTimestamp(MessageParcel & data,MessageParcel & reply)608 int AudioManagerStub::HandleUpdateLatencyTimestamp(MessageParcel &data, MessageParcel &reply)
609 {
610     std::string timestamp = data.ReadString();
611     bool isRenderer = data.ReadBool();
612     UpdateLatencyTimestamp(timestamp, isRenderer);
613     return AUDIO_OK;
614 }
615 
HandleGetMaxAmplitude(MessageParcel & data,MessageParcel & reply)616 int AudioManagerStub::HandleGetMaxAmplitude(MessageParcel &data, MessageParcel &reply)
617 {
618     bool isOutputDevice = data.ReadBool();
619     int32_t deviceType = data.ReadInt32();
620     float result = GetMaxAmplitude(isOutputDevice, deviceType);
621     reply.WriteFloat(result);
622     return AUDIO_OK;
623 }
624 
HandleResetAudioEndpoint(MessageParcel & data,MessageParcel & reply)625 int AudioManagerStub::HandleResetAudioEndpoint(MessageParcel &data, MessageParcel &reply)
626 {
627     ResetAudioEndpoint();
628     return AUDIO_OK;
629 }
630 
HandleSuspendRenderSink(MessageParcel & data,MessageParcel & reply)631 int AudioManagerStub::HandleSuspendRenderSink(MessageParcel &data, MessageParcel &reply)
632 {
633     std::string sinkName = data.ReadString();
634     int32_t ret = SuspendRenderSink(sinkName);
635     reply.WriteInt32(ret);
636     return AUDIO_OK;
637 }
638 
HandleRestoreRenderSink(MessageParcel & data,MessageParcel & reply)639 int AudioManagerStub::HandleRestoreRenderSink(MessageParcel &data, MessageParcel &reply)
640 {
641     std::string sinkName = data.ReadString();
642     int32_t ret = RestoreRenderSink(sinkName);
643     reply.WriteInt32(ret);
644     return AUDIO_OK;
645 }
646 
HandleLoadHdiEffectModel(MessageParcel & data,MessageParcel & reply)647 int AudioManagerStub::HandleLoadHdiEffectModel(MessageParcel &data, MessageParcel &reply)
648 {
649     LoadHdiEffectModel();
650     return AUDIO_OK;
651 }
652 
HandleUpdateEffectBtOffloadSupported(MessageParcel & data,MessageParcel & reply)653 int AudioManagerStub::HandleUpdateEffectBtOffloadSupported(MessageParcel &data, MessageParcel &reply)
654 {
655     UpdateEffectBtOffloadSupported(data.ReadBool());
656     return AUDIO_OK;
657 }
658 
HandleSetSinkMuteForSwitchDevice(MessageParcel & data,MessageParcel & reply)659 int AudioManagerStub::HandleSetSinkMuteForSwitchDevice(MessageParcel &data, MessageParcel &reply)
660 {
661     const std::string deviceClass = data.ReadString();
662     int32_t duration = data.ReadInt32();
663     int32_t mute = data.ReadBool();
664     int32_t result = SetSinkMuteForSwitchDevice(deviceClass, duration, mute);
665     reply.WriteInt32(result);
666     return AUDIO_OK;
667 }
668 
HandleSetRotationToEffect(MessageParcel & data,MessageParcel & reply)669 int AudioManagerStub::HandleSetRotationToEffect(MessageParcel &data, MessageParcel &reply)
670 {
671     SetRotationToEffect(data.ReadUint32());
672     return AUDIO_OK;
673 }
674 
HandleUpdateSessionConnectionState(MessageParcel & data,MessageParcel & reply)675 int AudioManagerStub::HandleUpdateSessionConnectionState(MessageParcel &data, MessageParcel &reply)
676 {
677     int32_t sessionID = data.ReadInt32();
678     int32_t state = data.ReadInt32();
679     UpdateSessionConnectionState(sessionID, state);
680     return AUDIO_OK;
681 }
682 
HandleFifthPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)683 int AudioManagerStub::HandleFifthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
684     MessageOption &option)
685 {
686     switch (code) {
687         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINK_MUTE_FOR_SWITCH_DEVICE):
688             return HandleSetSinkMuteForSwitchDevice(data, reply);
689         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT):
690             return HandleSetRotationToEffect(data, reply);
691         case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SESSION_CONNECTION_STATE):
692             return HandleUpdateSessionConnectionState(data, reply);
693         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINGLE_STREAM_MUTE):
694             return HandleSetNonInterruptMute(data, reply);
695         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY_V3):
696             return HandleGetAudioEffectPropertyV3(data, reply);
697         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY_V3):
698             return HandleSetAudioEffectPropertyV3(data, reply);
699         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_STANDBY_STATUS):
700             return HandleGetStandbyStatus(data, reply);
701         default:
702             AUDIO_ERR_LOG("default case, need check AudioManagerStub");
703             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
704     }
705 }
706 
HandleCreateIpcOfflineStream(MessageParcel & data,MessageParcel & reply)707 int AudioManagerStub::HandleCreateIpcOfflineStream(MessageParcel &data, MessageParcel &reply)
708 {
709     int32_t errorCode = 0;
710     sptr<IRemoteObject> process = CreateIpcOfflineStream(errorCode);
711     CHECK_AND_RETURN_RET_LOG(process != nullptr, AUDIO_ERR,
712         "CREATE_IPC_OFFLINE_STREAM AudioManagerStub CreateIpcOfflineStream failed");
713     reply.WriteRemoteObject(process);
714     reply.WriteInt32(errorCode);
715     return AUDIO_OK;
716 }
717 
HandleGetOfflineAudioEffectChains(MessageParcel & data,MessageParcel & reply)718 int AudioManagerStub::HandleGetOfflineAudioEffectChains(MessageParcel &data, MessageParcel &reply)
719 {
720     vector<string> effectChains{};
721     int32_t errCode = GetOfflineAudioEffectChains(effectChains);
722     reply.WriteInt32(effectChains.size());
723     for (auto &chainName : effectChains) {
724         reply.WriteString(chainName);
725     }
726     reply.WriteInt32(errCode);
727     return AUDIO_OK;
728 }
729 
HandleFourthPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)730 int AudioManagerStub::HandleFourthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
731     MessageOption &option)
732 {
733     switch (code) {
734         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_NOISE_SUPPRESSION_MODE):
735             return HandleGetAsrNoiseSuppressionMode(data, reply);
736         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_WHISPER_DETECTION_MODE):
737             return HandleSetAsrWhisperDetectionMode(data, reply);
738         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_WHISPER_DETECTION_MODE):
739             return HandleGetAsrWhisperDetectionMode(data, reply);
740         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_CONTROL_MODE):
741             return HandleSetAsrVoiceControlMode(data, reply);
742         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_MUTE_MODE):
743             return HandleSetAsrVoiceMuteMode(data, reply);
744         case static_cast<uint32_t>(AudioServerInterfaceCode::IS_WHISPERING):
745             return HandleIsWhispering(data, reply);
746         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_OFFLOAD_ENABLED):
747             return HandleGetEffectOffloadEnabled(data, reply);
748         case static_cast<uint32_t>(AudioServerInterfaceCode::SUSPEND_RENDERSINK):
749             return HandleSuspendRenderSink(data, reply);
750         case static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_RENDERSINK):
751             return HandleRestoreRenderSink(data, reply);
752         case static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_EFFECT_MODEL):
753             return HandleLoadHdiEffectModel(data, reply);
754         case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED):
755             return HandleUpdateEffectBtOffloadSupported(data, reply);
756         default:
757             return HandleFifthPartCode(code, data, reply, option);
758     }
759 }
760 
HandleThirdPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)761 int AudioManagerStub::HandleThirdPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
762     MessageOption &option)
763 {
764     switch (code) {
765         case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_STREAM_VOLUME_CHANGED):
766             return HandleNotifyStreamVolumeChanged(data, reply);
767         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE):
768             return HandleSetSpatializationSceneType(data, reply);
769         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_MAX_AMPLITUDE):
770             return HandleGetMaxAmplitude(data, reply);
771         case static_cast<uint32_t>(AudioServerInterfaceCode::RESET_AUDIO_ENDPOINT):
772             return HandleResetAudioEndpoint(data, reply);
773         case static_cast<uint32_t>(AudioServerInterfaceCode::RESET_ROUTE_FOR_DISCONNECT):
774             return HandleResetRouteForDisconnect(data, reply);
775         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_LATENCY):
776             return HandleGetEffectLatency(data, reply);
777         case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_LATENCY_TIMESTAMP):
778             return HandleUpdateLatencyTimestamp(data, reply);
779         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_AEC_MODE):
780             return HandleSetAsrAecMode(data, reply);
781         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_AEC_MODE):
782             return HandleGetAsrAecMode(data, reply);
783         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_NOISE_SUPPRESSION_MODE):
784             return HandleSetAsrNoiseSuppressionMode(data, reply);
785         case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_IPC_OFFLINE_STREAM):
786             return HandleCreateIpcOfflineStream(data, reply);
787         case static_cast<uint32_t>(AudioServerInterfaceCode::GET_OFFLINE_AUDIO_EFFECT_CHAINS):
788             return HandleGetOfflineAudioEffectChains(data, reply);
789         default:
790             return HandleFourthPartCode(code, data, reply, option);
791     }
792 }
793 
HandleSecondPartCode(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)794 int AudioManagerStub::HandleSecondPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply,
795     MessageOption &option)
796 {
797     switch (code) {
798         case static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_REMOTE_DEVICE_STATE):
799             return HandleCheckRemoteDeviceState(data, reply);
800         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_VOICE_VOLUME):
801             return HandleSetVoiceVolume(data, reply);
802         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_MONO_STATE):
803             return HandleSetAudioMonoState(data, reply);
804         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_BALANCE_VALUE):
805             return HandleSetAudioBalanceValue(data, reply);
806         case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIOPROCESS):
807             return HandleCreateAudioProcess(data, reply);
808         case static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_AUDIO_EFFECT_LIBRARIES):
809             return HandleLoadAudioEffectLibraries(data, reply);
810         case static_cast<uint32_t>(AudioServerInterfaceCode::REQUEST_THREAD_PRIORITY):
811             return HandleRequestThreadPriority(data, reply);
812         case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER):
813             return HandleCreateAudioEffectChainManager(data, reply);
814         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_OUTPUT_DEVICE_SINK):
815             return HandleSetOutputDeviceSink(data, reply);
816         case static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_PLAYBACK_CAPTURER_MANAGER):
817             return HandleCreatePlaybackCapturerManager(data, reply);
818         case static_cast<uint32_t>(AudioServerInterfaceCode::REGISET_POLICY_PROVIDER):
819             return HandleRegiestPolicyProvider(data, reply);
820         case static_cast<uint32_t>(AudioServerInterfaceCode::SET_WAKEUP_CLOSE_CALLBACK):
821             return HandleSetWakeupSourceCallback(data, reply);
822         case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIALIZATION_STATE):
823             return HandleUpdateSpatializationState(data, reply);
824         case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE):
825             return HandleUpdateSpatialDeviceType(data, reply);
826         case static_cast<uint32_t>(AudioServerInterfaceCode::OFFLOAD_SET_VOLUME):
827             return HandleOffloadSetVolume(data, reply);
828         default:
829             return HandleThirdPartCode(code, data, reply, option);
830     }
831 }
832 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)833 int AudioManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
834 {
835     CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(),
836         -1, "ReadInterfaceToken failed");
837     Trace trace(code >= codeNums ? "invalid audio server code!" : g_audioServerCodeStrs[code]);
838     if (code <= static_cast<uint32_t>(AudioServerInterfaceCode::AUDIO_SERVER_CODE_MAX)) {
839         switch (code) {
840             case static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_PARAMETER):
841                 return HandleGetAudioParameter(data, reply);
842             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_PARAMETER):
843                 return HandleSetAudioParameter(data, reply);
844             case static_cast<uint32_t>(AudioServerInterfaceCode::GET_EXTRA_AUDIO_PARAMETERS):
845                 return HandleGetExtraAudioParameters(data, reply);
846             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_EXTRA_AUDIO_PARAMETERS):
847                 return HandleSetExtraAudioParameters(data, reply);
848             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_MICROPHONE_MUTE):
849                 return HandleSetMicrophoneMute(data, reply);
850             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_SCENE):
851                 return HandleSetAudioScene(data, reply);
852             case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTE_REQ):
853                 return HandleUpdateActiveDeviceRoute(data, reply);
854             case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTES_REQ):
855                 return HandleUpdateActiveDevicesRoute(data, reply);
856             case static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_DUAL_TONE_REQ):
857                 return HandleDualToneState(data, reply);
858             case static_cast<uint32_t>(AudioServerInterfaceCode::GET_TRANSACTION_ID):
859                 return HandleGetTransactionId(data, reply);
860             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_PARAMETER_CALLBACK):
861                 return HandleSetParameterCallback(data, reply);
862             case static_cast<uint32_t>(AudioServerInterfaceCode::GET_REMOTE_AUDIO_PARAMETER):
863                 return HandleGetRemoteAudioParameter(data, reply);
864             case static_cast<uint32_t>(AudioServerInterfaceCode::SET_REMOTE_AUDIO_PARAMETER):
865                 return HandleSetRemoteAudioParameter(data, reply);
866             case static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_DEVICE_INFO):
867                 return HandleNotifyDeviceInfo(data, reply);
868             default:
869                 return HandleSecondPartCode(code, data, reply, option);
870         }
871     }
872     AUDIO_ERR_LOG("default case, need check AudioManagerStub");
873     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
874 }
875 
HandleSetAudioEffectPropertyV3(MessageParcel & data,MessageParcel & reply)876 int AudioManagerStub::HandleSetAudioEffectPropertyV3(MessageParcel &data, MessageParcel &reply)
877 {
878     int32_t size = data.ReadInt32();
879     CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
880         ERROR_INVALID_PARAM, "audio enhance property array size invalid");
881     AudioEffectPropertyArrayV3 propertyArray = {};
882     for (int32_t i = 0; i < size; i++) {
883         AudioEffectPropertyV3 prop = {};
884         prop.Unmarshalling(data);
885         propertyArray.property.push_back(prop);
886     }
887     int32_t result = SetAudioEffectProperty(propertyArray);
888     reply.WriteInt32(result);
889     return AUDIO_OK;
890 }
891 
HandleGetAudioEffectPropertyV3(MessageParcel & data,MessageParcel & reply)892 int AudioManagerStub::HandleGetAudioEffectPropertyV3(MessageParcel &data, MessageParcel &reply)
893 {
894     AudioEffectPropertyArrayV3 propertyArray = {};
895     int32_t result = GetAudioEffectProperty(propertyArray);
896     int32_t size = static_cast<int32_t>(propertyArray.property.size());
897     CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
898         ERROR_INVALID_PARAM, "audio enhance property array size invalid");
899     reply.WriteInt32(size);
900     for (int32_t i = 0; i < size; i++) {
901         propertyArray.property[i].Marshalling(reply);
902     }
903     reply.WriteInt32(result);
904     return AUDIO_OK;
905 }
906 
HandleSetNonInterruptMute(MessageParcel & data,MessageParcel & reply)907 int AudioManagerStub::HandleSetNonInterruptMute(MessageParcel &data, MessageParcel &reply)
908 {
909     uint32_t sessionId = data.ReadUint32();
910     bool muteFlag = data.ReadBool();
911     SetNonInterruptMute(sessionId, muteFlag);
912     return AUDIO_OK;
913 }
914 
HandleGetStandbyStatus(MessageParcel & data,MessageParcel & reply)915 int AudioManagerStub::HandleGetStandbyStatus(MessageParcel &data, MessageParcel &reply)
916 {
917     uint32_t sessionId = data.ReadUint32();
918     bool isStandby = false;
919     int64_t enterStandbyTime = 0;
920     int32_t result = GetStandbyStatus(sessionId, isStandby, enterStandbyTime);
921 
922     reply.WriteInt32(result);
923     reply.WriteBool(isStandby);
924     reply.WriteInt64(enterStandbyTime);
925     return AUDIO_OK;
926 }
927 } // namespace AudioStandard
928 } // namespace OHOS
929