blob: b58df2f57769588dec192ca1eeb3506b61b8a096 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25
Eric Laurent74adca92014-11-05 12:15:36 -080026#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070027#include <media/IAudioPolicyService.h>
28
Dima Zavin64760242011-05-11 14:15:23 -070029#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070030
Eric Laurentc2f1f072009-07-17 12:17:14 -070031namespace android {
32
33enum {
34 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
35 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080036 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070037 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080038 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_FORCE_USE,
40 GET_FORCE_USE,
41 GET_OUTPUT,
42 START_OUTPUT,
43 STOP_OUTPUT,
44 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080045 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070046 START_INPUT,
47 STOP_INPUT,
48 RELEASE_INPUT,
49 INIT_STREAM_VOLUME,
50 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070051 GET_STREAM_VOLUME,
52 GET_STRATEGY_FOR_STREAM,
53 GET_OUTPUT_FOR_EFFECT,
54 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080055 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080056 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070057 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070059 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080060 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000061 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070062 IS_OFFLOAD_SUPPORTED,
63 LIST_AUDIO_PORTS,
64 GET_AUDIO_PORT,
65 CREATE_AUDIO_PATCH,
66 RELEASE_AUDIO_PATCH,
67 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070068 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070069 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070070 GET_OUTPUT_FOR_ATTR,
71 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070072 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080073 GET_PHONE_STATE,
74 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070075 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070076 STOP_AUDIO_SOURCE,
77 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080078 SET_MASTER_MONO,
79 GET_MASTER_MONO,
Eric Laurentc2f1f072009-07-17 12:17:14 -070080};
81
Eric Laurent1d670b12015-02-06 10:44:24 -080082#define MAX_ITEMS_PER_LIST 1024
83
Eric Laurentc2f1f072009-07-17 12:17:14 -070084class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
85{
86public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070087 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -070088 : BpInterface<IAudioPolicyService>(impl)
89 {
90 }
91
92 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070093 audio_devices_t device,
94 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080095 const char *device_address,
96 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070097 {
98 Parcel data, reply;
99 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
100 data.writeInt32(static_cast <uint32_t>(device));
101 data.writeInt32(static_cast <uint32_t>(state));
102 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800103 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700104 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
105 return static_cast <status_t> (reply.readInt32());
106 }
107
Dima Zavinfce7a472011-04-19 22:30:36 -0700108 virtual audio_policy_dev_state_t getDeviceConnectionState(
109 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 const char *device_address)
111 {
112 Parcel data, reply;
113 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
114 data.writeInt32(static_cast <uint32_t>(device));
115 data.writeCString(device_address);
116 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700117 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700118 }
119
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800120 virtual status_t handleDeviceConfigChange(audio_devices_t device,
121 const char *device_address,
122 const char *device_name)
123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
126 data.writeInt32(static_cast <uint32_t>(device));
127 data.writeCString(device_address);
128 data.writeCString(device_name);
129 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
130 return static_cast <status_t> (reply.readInt32());
131 }
132
Glenn Kastenf78aee72012-01-04 11:00:47 -0800133 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
137 data.writeInt32(state);
138 remote()->transact(SET_PHONE_STATE, data, &reply);
139 return static_cast <status_t> (reply.readInt32());
140 }
141
Dima Zavinfce7a472011-04-19 22:30:36 -0700142 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700143 {
144 Parcel data, reply;
145 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
146 data.writeInt32(static_cast <uint32_t>(usage));
147 data.writeInt32(static_cast <uint32_t>(config));
148 remote()->transact(SET_FORCE_USE, data, &reply);
149 return static_cast <status_t> (reply.readInt32());
150 }
151
Dima Zavinfce7a472011-04-19 22:30:36 -0700152 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700153 {
154 Parcel data, reply;
155 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
156 data.writeInt32(static_cast <uint32_t>(usage));
157 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700158 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700159 }
160
161 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700162 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700163 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800164 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700165 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000166 audio_output_flags_t flags,
167 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700168 {
169 Parcel data, reply;
170 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
171 data.writeInt32(static_cast <uint32_t>(stream));
172 data.writeInt32(samplingRate);
173 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700174 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700175 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800176 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100177 if (offloadInfo == NULL) {
178 data.writeInt32(0);
179 } else {
180 data.writeInt32(1);
181 data.write(offloadInfo, sizeof(audio_offload_info_t));
182 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700183 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700184 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700185 }
186
Eric Laurente83b55d2014-11-14 10:06:21 -0800187 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
188 audio_io_handle_t *output,
189 audio_session_t session,
190 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700191 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800192 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800193 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700194 audio_port_handle_t selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800195 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700196 {
197 Parcel data, reply;
198 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
199 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800200 if (stream == NULL) {
201 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
202 return BAD_VALUE;
203 }
204 if (*stream == AUDIO_STREAM_DEFAULT) {
205 ALOGE("getOutputForAttr unspecified stream type");
206 return BAD_VALUE;
207 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700208 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800209 if (output == NULL) {
210 ALOGE("getOutputForAttr NULL output - shouldn't happen");
211 return BAD_VALUE;
212 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800213 if (portId == NULL) {
214 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
215 return BAD_VALUE;
216 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800217 if (attr == NULL) {
218 data.writeInt32(0);
219 } else {
220 data.writeInt32(1);
221 data.write(attr, sizeof(audio_attributes_t));
222 }
223 data.writeInt32(session);
224 if (stream == NULL) {
225 data.writeInt32(0);
226 } else {
227 data.writeInt32(1);
228 data.writeInt32(*stream);
229 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700230 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800231 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700232 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700233 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800234 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800235 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
236 if (status != NO_ERROR) {
237 return status;
238 }
239 status = (status_t)reply.readInt32();
240 if (status != NO_ERROR) {
241 return status;
242 }
243 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800244 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800245 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800246 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800247 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800248 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800249 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700250 }
251
Eric Laurentde070132010-07-13 04:45:46 -0700252 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700253 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700258 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800259 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800260 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700261 remote()->transact(START_OUTPUT, data, &reply);
262 return static_cast <status_t> (reply.readInt32());
263 }
264
Eric Laurentde070132010-07-13 04:45:46 -0700265 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700266 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800267 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 {
269 Parcel data, reply;
270 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700271 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800272 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800273 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 remote()->transact(STOP_OUTPUT, data, &reply);
275 return static_cast <status_t> (reply.readInt32());
276 }
277
Eric Laurente83b55d2014-11-14 10:06:21 -0800278 virtual void releaseOutput(audio_io_handle_t output,
279 audio_stream_type_t stream,
280 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700284 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800285 data.writeInt32((int32_t)stream);
286 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700287 remote()->transact(RELEASE_OUTPUT, data, &reply);
288 }
289
Eric Laurentcaf7f482014-11-25 17:50:47 -0800290 virtual status_t getInputForAttr(const audio_attributes_t *attr,
291 audio_io_handle_t *input,
292 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700293 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700294 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800295 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600296 audio_input_flags_t flags,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800297 audio_port_handle_t selectedDeviceId,
298 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800302 if (attr == NULL) {
303 ALOGE("getInputForAttr NULL attr - shouldn't happen");
304 return BAD_VALUE;
305 }
306 if (input == NULL) {
307 ALOGE("getInputForAttr NULL input - shouldn't happen");
308 return BAD_VALUE;
309 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800310 if (portId == NULL) {
311 ALOGE("getInputForAttr NULL portId - shouldn't happen");
312 return BAD_VALUE;
313 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800314 data.write(attr, sizeof(audio_attributes_t));
315 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700316 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700317 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800318 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700319 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600320 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800321 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800322 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
323 if (status != NO_ERROR) {
324 return status;
325 }
326 status = reply.readInt32();
327 if (status != NO_ERROR) {
328 return status;
329 }
330 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800331 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800332 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 }
334
Eric Laurent4dc68062014-07-28 17:26:49 -0700335 virtual status_t startInput(audio_io_handle_t input,
336 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700340 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700341 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 remote()->transact(START_INPUT, data, &reply);
343 return static_cast <status_t> (reply.readInt32());
344 }
345
Eric Laurent4dc68062014-07-28 17:26:49 -0700346 virtual status_t stopInput(audio_io_handle_t input,
347 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700348 {
349 Parcel data, reply;
350 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700351 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700352 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353 remote()->transact(STOP_INPUT, data, &reply);
354 return static_cast <status_t> (reply.readInt32());
355 }
356
Eric Laurent4dc68062014-07-28 17:26:49 -0700357 virtual void releaseInput(audio_io_handle_t input,
358 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700359 {
360 Parcel data, reply;
361 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700362 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700363 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 remote()->transact(RELEASE_INPUT, data, &reply);
365 }
366
Dima Zavinfce7a472011-04-19 22:30:36 -0700367 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700368 int indexMin,
369 int indexMax)
370 {
371 Parcel data, reply;
372 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
373 data.writeInt32(static_cast <uint32_t>(stream));
374 data.writeInt32(indexMin);
375 data.writeInt32(indexMax);
376 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
377 return static_cast <status_t> (reply.readInt32());
378 }
379
Eric Laurent83844cc2011-11-18 16:43:31 -0800380 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
381 int index,
382 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
386 data.writeInt32(static_cast <uint32_t>(stream));
387 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800388 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700389 remote()->transact(SET_STREAM_VOLUME, data, &reply);
390 return static_cast <status_t> (reply.readInt32());
391 }
392
Eric Laurent83844cc2011-11-18 16:43:31 -0800393 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
394 int *index,
395 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
399 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800400 data.writeInt32(static_cast <uint32_t>(device));
401
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 remote()->transact(GET_STREAM_VOLUME, data, &reply);
403 int lIndex = reply.readInt32();
404 if (index) *index = lIndex;
405 return static_cast <status_t> (reply.readInt32());
406 }
Eric Laurentde070132010-07-13 04:45:46 -0700407
Dima Zavinfce7a472011-04-19 22:30:36 -0700408 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
412 data.writeInt32(static_cast <uint32_t>(stream));
413 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
414 return reply.readInt32();
415 }
416
Eric Laurent63742522012-03-08 13:42:42 -0800417 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800418 {
419 Parcel data, reply;
420 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
421 data.writeInt32(static_cast <uint32_t>(stream));
422 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800423 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800424 }
425
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700426 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
430 data.write(desc, sizeof(effect_descriptor_t));
431 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
432 return static_cast <audio_io_handle_t> (reply.readInt32());
433 }
434
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700435 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700436 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700437 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800438 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700439 int id)
440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700444 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700445 data.writeInt32(strategy);
446 data.writeInt32(session);
447 data.writeInt32(id);
448 remote()->transact(REGISTER_EFFECT, data, &reply);
449 return static_cast <status_t> (reply.readInt32());
450 }
451
452 virtual status_t unregisterEffect(int id)
453 {
454 Parcel data, reply;
455 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
456 data.writeInt32(id);
457 remote()->transact(UNREGISTER_EFFECT, data, &reply);
458 return static_cast <status_t> (reply.readInt32());
459 }
460
Eric Laurentdb7c0792011-08-10 10:37:50 -0700461 virtual status_t setEffectEnabled(int id, bool enabled)
462 {
463 Parcel data, reply;
464 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
465 data.writeInt32(id);
466 data.writeInt32(enabled);
467 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
468 return static_cast <status_t> (reply.readInt32());
469 }
470
Glenn Kastenfff6d712012-01-12 16:38:12 -0800471 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800472 {
473 Parcel data, reply;
474 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800475 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800476 data.writeInt32(inPastMs);
477 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
478 return reply.readInt32();
479 }
Eric Laurent57dae992011-07-24 13:36:09 -0700480
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800481 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
482 {
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
485 data.writeInt32((int32_t) stream);
486 data.writeInt32(inPastMs);
487 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
488 return reply.readInt32();
489 }
490
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700491 virtual bool isSourceActive(audio_source_t source) const
492 {
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
495 data.writeInt32((int32_t) source);
496 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
497 return reply.readInt32();
498 }
499
Glenn Kastend848eb42016-03-08 13:42:11 -0800500 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700501 effect_descriptor_t *descriptors,
502 uint32_t *count)
503 {
504 if (descriptors == NULL || count == NULL) {
505 return BAD_VALUE;
506 }
507 Parcel data, reply;
508 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
509 data.writeInt32(audioSession);
510 data.writeInt32(*count);
511 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
512 if (status != NO_ERROR) {
513 return status;
514 }
515 status = static_cast <status_t> (reply.readInt32());
516 uint32_t retCount = reply.readInt32();
517 if (retCount != 0) {
518 uint32_t numDesc = (retCount < *count) ? retCount : *count;
519 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
520 }
521 *count = retCount;
522 return status;
523 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000524
525 virtual bool isOffloadSupported(const audio_offload_info_t& info)
526 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100527 Parcel data, reply;
528 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
529 data.write(&info, sizeof(audio_offload_info_t));
530 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700531 return reply.readInt32();
532 }
533
534 virtual status_t listAudioPorts(audio_port_role_t role,
535 audio_port_type_t type,
536 unsigned int *num_ports,
537 struct audio_port *ports,
538 unsigned int *generation)
539 {
540 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
541 generation == NULL) {
542 return BAD_VALUE;
543 }
544 Parcel data, reply;
545 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
546 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
547 data.writeInt32(role);
548 data.writeInt32(type);
549 data.writeInt32(numPortsReq);
550 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
551 if (status == NO_ERROR) {
552 status = (status_t)reply.readInt32();
553 *num_ports = (unsigned int)reply.readInt32();
554 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700555 if (status == NO_ERROR) {
556 if (numPortsReq > *num_ports) {
557 numPortsReq = *num_ports;
558 }
559 if (numPortsReq > 0) {
560 reply.read(ports, numPortsReq * sizeof(struct audio_port));
561 }
562 *generation = reply.readInt32();
563 }
564 return status;
565 }
566
567 virtual status_t getAudioPort(struct audio_port *port)
568 {
569 if (port == NULL) {
570 return BAD_VALUE;
571 }
572 Parcel data, reply;
573 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
574 data.write(port, sizeof(struct audio_port));
575 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
576 if (status != NO_ERROR ||
577 (status = (status_t)reply.readInt32()) != NO_ERROR) {
578 return status;
579 }
580 reply.read(port, sizeof(struct audio_port));
581 return status;
582 }
583
584 virtual status_t createAudioPatch(const struct audio_patch *patch,
585 audio_patch_handle_t *handle)
586 {
587 if (patch == NULL || handle == NULL) {
588 return BAD_VALUE;
589 }
590 Parcel data, reply;
591 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
592 data.write(patch, sizeof(struct audio_patch));
593 data.write(handle, sizeof(audio_patch_handle_t));
594 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
595 if (status != NO_ERROR ||
596 (status = (status_t)reply.readInt32()) != NO_ERROR) {
597 return status;
598 }
599 reply.read(handle, sizeof(audio_patch_handle_t));
600 return status;
601 }
602
603 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
604 {
605 Parcel data, reply;
606 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
607 data.write(&handle, sizeof(audio_patch_handle_t));
608 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
609 if (status != NO_ERROR) {
610 status = (status_t)reply.readInt32();
611 }
612 return status;
613 }
614
615 virtual status_t listAudioPatches(unsigned int *num_patches,
616 struct audio_patch *patches,
617 unsigned int *generation)
618 {
619 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
620 generation == NULL) {
621 return BAD_VALUE;
622 }
623 Parcel data, reply;
624 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
625 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
626 data.writeInt32(numPatchesReq);
627 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
628 if (status == NO_ERROR) {
629 status = (status_t)reply.readInt32();
630 *num_patches = (unsigned int)reply.readInt32();
631 }
632 if (status == NO_ERROR) {
633 if (numPatchesReq > *num_patches) {
634 numPatchesReq = *num_patches;
635 }
636 if (numPatchesReq > 0) {
637 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
638 }
639 *generation = reply.readInt32();
640 }
641 return status;
642 }
643
644 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
645 {
646 if (config == NULL) {
647 return BAD_VALUE;
648 }
649 Parcel data, reply;
650 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
651 data.write(config, sizeof(struct audio_port_config));
652 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
653 if (status != NO_ERROR) {
654 status = (status_t)reply.readInt32();
655 }
656 return status;
657 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700658
Eric Laurentb52c1522014-05-20 11:27:36 -0700659 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
660 {
661 Parcel data, reply;
662 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800663 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700664 remote()->transact(REGISTER_CLIENT, data, &reply);
665 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700666
Eric Laurente8726fe2015-06-26 09:39:24 -0700667 virtual void setAudioPortCallbacksEnabled(bool enabled)
668 {
669 Parcel data, reply;
670 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
671 data.writeInt32(enabled ? 1 : 0);
672 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
673 }
674
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700675 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
676 audio_io_handle_t *ioHandle,
677 audio_devices_t *device)
678 {
679 if (session == NULL || ioHandle == NULL || device == NULL) {
680 return BAD_VALUE;
681 }
682 Parcel data, reply;
683 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
684 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
685 if (status != NO_ERROR) {
686 return status;
687 }
688 status = (status_t)reply.readInt32();
689 if (status == NO_ERROR) {
690 *session = (audio_session_t)reply.readInt32();
691 *ioHandle = (audio_io_handle_t)reply.readInt32();
692 *device = (audio_devices_t)reply.readInt32();
693 }
694 return status;
695 }
696
697 virtual status_t releaseSoundTriggerSession(audio_session_t session)
698 {
699 Parcel data, reply;
700 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
701 data.writeInt32(session);
702 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
703 if (status != NO_ERROR) {
704 return status;
705 }
706 return (status_t)reply.readInt32();
707 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700708
709 virtual audio_mode_t getPhoneState()
710 {
711 Parcel data, reply;
712 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
713 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
714 if (status != NO_ERROR) {
715 return AUDIO_MODE_INVALID;
716 }
717 return (audio_mode_t)reply.readInt32();
718 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800719
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700720 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800721 {
722 Parcel data, reply;
723 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
724 data.writeInt32(registration ? 1 : 0);
725 size_t size = mixes.size();
726 if (size > MAX_MIXES_PER_POLICY) {
727 size = MAX_MIXES_PER_POLICY;
728 }
729 size_t sizePosition = data.dataPosition();
730 data.writeInt32(size);
731 size_t finalSize = size;
732 for (size_t i = 0; i < size; i++) {
733 size_t position = data.dataPosition();
734 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
735 data.setDataPosition(position);
736 finalSize--;
737 }
738 }
739 if (size != finalSize) {
740 size_t position = data.dataPosition();
741 data.setDataPosition(sizePosition);
742 data.writeInt32(finalSize);
743 data.setDataPosition(position);
744 }
745 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
746 if (status == NO_ERROR) {
747 status = (status_t)reply.readInt32();
748 }
749 return status;
750 }
Eric Laurent554a2772015-04-10 11:29:24 -0700751
752 virtual status_t startAudioSource(const struct audio_port_config *source,
753 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700754 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700755 {
756 Parcel data, reply;
757 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
758 if (source == NULL || attributes == NULL || handle == NULL) {
759 return BAD_VALUE;
760 }
761 data.write(source, sizeof(struct audio_port_config));
762 data.write(attributes, sizeof(audio_attributes_t));
763 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
764 if (status != NO_ERROR) {
765 return status;
766 }
767 status = (status_t)reply.readInt32();
768 if (status != NO_ERROR) {
769 return status;
770 }
Glenn Kasten559d4392016-03-29 13:42:57 -0700771 *handle = (audio_patch_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700772 return status;
773 }
774
Glenn Kasten559d4392016-03-29 13:42:57 -0700775 virtual status_t stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700776 {
777 Parcel data, reply;
778 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
779 data.writeInt32(handle);
780 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
781 if (status != NO_ERROR) {
782 return status;
783 }
784 status = (status_t)reply.readInt32();
785 return status;
786 }
Andy Hung2ddee192015-12-18 17:34:44 -0800787
788 virtual status_t setMasterMono(bool mono)
789 {
790 Parcel data, reply;
791 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
792 data.writeInt32(static_cast<int32_t>(mono));
793 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
794 if (status != NO_ERROR) {
795 return status;
796 }
797 return static_cast<status_t>(reply.readInt32());
798 }
799
800 virtual status_t getMasterMono(bool *mono)
801 {
802 if (mono == nullptr) {
803 return BAD_VALUE;
804 }
805 Parcel data, reply;
806 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
807
808 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
809 if (status != NO_ERROR) {
810 return status;
811 }
812 status = static_cast<status_t>(reply.readInt32());
813 if (status == NO_ERROR) {
814 *mono = static_cast<bool>(reply.readInt32());
815 }
816 return status;
817 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700818};
819
820IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
821
822// ----------------------------------------------------------------------
823
824
825status_t BnAudioPolicyService::onTransact(
826 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
827{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700828 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700829 case SET_DEVICE_CONNECTION_STATE: {
830 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700831 audio_devices_t device =
832 static_cast <audio_devices_t>(data.readInt32());
833 audio_policy_dev_state_t state =
834 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700835 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800836 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800837 if (device_address == nullptr || device_name == nullptr) {
838 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
839 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
840 } else {
841 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
842 state,
843 device_address,
844 device_name)));
845 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700846 return NO_ERROR;
847 } break;
848
849 case GET_DEVICE_CONNECTION_STATE: {
850 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700851 audio_devices_t device =
852 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700853 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800854 if (device_address == nullptr) {
855 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
856 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
857 } else {
858 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
859 device_address)));
860 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700861 return NO_ERROR;
862 } break;
863
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800864 case HANDLE_DEVICE_CONFIG_CHANGE: {
865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
866 audio_devices_t device =
867 static_cast <audio_devices_t>(data.readInt32());
868 const char *device_address = data.readCString();
869 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800870 if (device_address == nullptr || device_name == nullptr) {
871 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
872 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
873 } else {
874 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
875 device_address,
876 device_name)));
877 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800878 return NO_ERROR;
879 } break;
880
Eric Laurentc2f1f072009-07-17 12:17:14 -0700881 case SET_PHONE_STATE: {
882 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700883 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
884 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700885 return NO_ERROR;
886 } break;
887
Eric Laurentc2f1f072009-07-17 12:17:14 -0700888 case SET_FORCE_USE: {
889 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700890 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
891 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700892 audio_policy_forced_cfg_t config =
893 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700894 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
895 return NO_ERROR;
896 } break;
897
898 case GET_FORCE_USE: {
899 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700900 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
901 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700902 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
903 return NO_ERROR;
904 } break;
905
906 case GET_OUTPUT: {
907 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700908 audio_stream_type_t stream =
909 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700910 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800911 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700912 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700913 audio_output_flags_t flags =
914 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100915 bool hasOffloadInfo = data.readInt32() != 0;
916 audio_offload_info_t offloadInfo;
917 if (hasOffloadInfo) {
918 data.read(&offloadInfo, sizeof(audio_offload_info_t));
919 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700920 audio_io_handle_t output = getOutput(stream,
921 samplingRate,
922 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700923 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100924 flags,
925 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700926 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700927 return NO_ERROR;
928 } break;
929
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700930 case GET_OUTPUT_FOR_ATTR: {
931 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800932 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800933 bool hasAttributes = data.readInt32() != 0;
934 if (hasAttributes) {
935 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocardfbbe4212017-11-13 11:15:27 -0800936 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -0800937 }
938 audio_session_t session = (audio_session_t)data.readInt32();
939 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
940 bool hasStream = data.readInt32() != 0;
941 if (hasStream) {
942 stream = (audio_stream_type_t)data.readInt32();
943 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700944 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800945 audio_config_t config;
946 memset(&config, 0, sizeof(audio_config_t));
947 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700948 audio_output_flags_t flags =
949 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700950 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800951 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -0700952 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800953 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700954 &output, session, &stream, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800955 &config,
956 flags, selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800957 reply->writeInt32(status);
958 reply->writeInt32(output);
959 reply->writeInt32(stream);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800960 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700961 return NO_ERROR;
962 } break;
963
Eric Laurentc2f1f072009-07-17 12:17:14 -0700964 case START_OUTPUT: {
965 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700966 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800967 audio_stream_type_t stream =
968 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800969 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700970 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800971 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700972 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700973 return NO_ERROR;
974 } break;
975
976 case STOP_OUTPUT: {
977 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700978 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800979 audio_stream_type_t stream =
980 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800981 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700982 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800983 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700984 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700985 return NO_ERROR;
986 } break;
987
988 case RELEASE_OUTPUT: {
989 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700990 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800991 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
992 audio_session_t session = (audio_session_t)data.readInt32();
993 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700994 return NO_ERROR;
995 } break;
996
Eric Laurentcaf7f482014-11-25 17:50:47 -0800997 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700998 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800999 audio_attributes_t attr;
1000 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocardfbbe4212017-11-13 11:15:27 -08001001 sanetizeAudioAttributes(&attr);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001002 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001003 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001004 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001005 audio_config_base_t config;
1006 memset(&config, 0, sizeof(audio_config_base_t));
1007 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001008 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001009 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001010 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -07001011 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -07001012 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001013 &config,
1014 flags, selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001015 reply->writeInt32(status);
1016 if (status == NO_ERROR) {
1017 reply->writeInt32(input);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001018 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001019 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001020 return NO_ERROR;
1021 } break;
1022
1023 case START_INPUT: {
1024 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001025 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001026 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1027 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001028 return NO_ERROR;
1029 } break;
1030
1031 case STOP_INPUT: {
1032 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001033 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001034 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1035 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001036 return NO_ERROR;
1037 } break;
1038
1039 case RELEASE_INPUT: {
1040 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001041 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001042 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1043 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001044 return NO_ERROR;
1045 } break;
1046
1047 case INIT_STREAM_VOLUME: {
1048 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001049 audio_stream_type_t stream =
1050 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001051 int indexMin = data.readInt32();
1052 int indexMax = data.readInt32();
1053 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1054 return NO_ERROR;
1055 } break;
1056
1057 case SET_STREAM_VOLUME: {
1058 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001059 audio_stream_type_t stream =
1060 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001061 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001062 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1063 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1064 index,
1065 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001066 return NO_ERROR;
1067 } break;
1068
1069 case GET_STREAM_VOLUME: {
1070 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001071 audio_stream_type_t stream =
1072 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001073 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001074 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001075 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001076 reply->writeInt32(index);
1077 reply->writeInt32(static_cast <uint32_t>(status));
1078 return NO_ERROR;
1079 } break;
1080
Eric Laurentde070132010-07-13 04:45:46 -07001081 case GET_STRATEGY_FOR_STREAM: {
1082 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001083 audio_stream_type_t stream =
1084 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001085 reply->writeInt32(getStrategyForStream(stream));
1086 return NO_ERROR;
1087 } break;
1088
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001089 case GET_DEVICES_FOR_STREAM: {
1090 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001091 audio_stream_type_t stream =
1092 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001093 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1094 return NO_ERROR;
1095 } break;
1096
Eric Laurentde070132010-07-13 04:45:46 -07001097 case GET_OUTPUT_FOR_EFFECT: {
1098 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1099 effect_descriptor_t desc;
1100 data.read(&desc, sizeof(effect_descriptor_t));
1101 audio_io_handle_t output = getOutputForEffect(&desc);
1102 reply->writeInt32(static_cast <int>(output));
1103 return NO_ERROR;
1104 } break;
1105
1106 case REGISTER_EFFECT: {
1107 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1108 effect_descriptor_t desc;
1109 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001110 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001111 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001112 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001113 int id = data.readInt32();
1114 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001115 io,
Eric Laurentde070132010-07-13 04:45:46 -07001116 strategy,
1117 session,
1118 id)));
1119 return NO_ERROR;
1120 } break;
1121
1122 case UNREGISTER_EFFECT: {
1123 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1124 int id = data.readInt32();
1125 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1126 return NO_ERROR;
1127 } break;
1128
Eric Laurentdb7c0792011-08-10 10:37:50 -07001129 case SET_EFFECT_ENABLED: {
1130 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1131 int id = data.readInt32();
1132 bool enabled = static_cast <bool>(data.readInt32());
1133 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1134 return NO_ERROR;
1135 } break;
1136
Eric Laurenteda6c362011-02-02 09:33:30 -08001137 case IS_STREAM_ACTIVE: {
1138 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001139 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001140 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001141 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001142 return NO_ERROR;
1143 } break;
1144
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001145 case IS_STREAM_ACTIVE_REMOTELY: {
1146 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1147 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1148 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001149 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001150 return NO_ERROR;
1151 } break;
1152
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001153 case IS_SOURCE_ACTIVE: {
1154 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1155 audio_source_t source = (audio_source_t) data.readInt32();
1156 reply->writeInt32( isSourceActive(source));
1157 return NO_ERROR;
1158 }
1159
Eric Laurent57dae992011-07-24 13:36:09 -07001160 case QUERY_DEFAULT_PRE_PROCESSING: {
1161 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001162 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001163 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001164 if (count > AudioEffect::kMaxPreProcessing) {
1165 count = AudioEffect::kMaxPreProcessing;
1166 }
Eric Laurent57dae992011-07-24 13:36:09 -07001167 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001168 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001169 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1170 reply->writeInt32(status);
1171 if (status != NO_ERROR && status != NO_MEMORY) {
1172 retCount = 0;
1173 }
1174 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001175 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001176 if (retCount < count) {
1177 count = retCount;
1178 }
1179 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1180 }
1181 delete[] descriptors;
1182 return status;
1183 }
1184
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001185 case IS_OFFLOAD_SUPPORTED: {
1186 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1187 audio_offload_info_t info;
1188 data.read(&info, sizeof(audio_offload_info_t));
1189 bool isSupported = isOffloadSupported(info);
1190 reply->writeInt32(isSupported);
1191 return NO_ERROR;
1192 }
1193
Eric Laurent203b1a12014-04-01 10:34:16 -07001194 case LIST_AUDIO_PORTS: {
1195 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1196 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1197 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1198 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001199 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1200 numPortsReq = MAX_ITEMS_PER_LIST;
1201 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001202 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001203 struct audio_port *ports =
1204 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001205 if (ports == NULL) {
1206 reply->writeInt32(NO_MEMORY);
1207 reply->writeInt32(0);
1208 return NO_ERROR;
1209 }
1210 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001211 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1212 reply->writeInt32(status);
1213 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001214
1215 if (status == NO_ERROR) {
1216 if (numPortsReq > numPorts) {
1217 numPortsReq = numPorts;
1218 }
1219 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1220 reply->writeInt32(generation);
1221 }
1222 free(ports);
1223 return NO_ERROR;
1224 }
1225
1226 case GET_AUDIO_PORT: {
1227 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001228 struct audio_port port = {};
1229 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1230 ALOGE("b/23912202");
1231 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001232 status_t status = getAudioPort(&port);
1233 reply->writeInt32(status);
1234 if (status == NO_ERROR) {
1235 reply->write(&port, sizeof(struct audio_port));
1236 }
1237 return NO_ERROR;
1238 }
1239
1240 case CREATE_AUDIO_PATCH: {
1241 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1242 struct audio_patch patch;
1243 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001244 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001245 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1246 ALOGE("b/23912202");
1247 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001248 status_t status = createAudioPatch(&patch, &handle);
1249 reply->writeInt32(status);
1250 if (status == NO_ERROR) {
1251 reply->write(&handle, sizeof(audio_patch_handle_t));
1252 }
1253 return NO_ERROR;
1254 }
1255
1256 case RELEASE_AUDIO_PATCH: {
1257 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1258 audio_patch_handle_t handle;
1259 data.read(&handle, sizeof(audio_patch_handle_t));
1260 status_t status = releaseAudioPatch(handle);
1261 reply->writeInt32(status);
1262 return NO_ERROR;
1263 }
1264
1265 case LIST_AUDIO_PATCHES: {
1266 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1267 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001268 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1269 numPatchesReq = MAX_ITEMS_PER_LIST;
1270 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001271 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001272 struct audio_patch *patches =
1273 (struct audio_patch *)calloc(numPatchesReq,
1274 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001275 if (patches == NULL) {
1276 reply->writeInt32(NO_MEMORY);
1277 reply->writeInt32(0);
1278 return NO_ERROR;
1279 }
1280 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001281 status_t status = listAudioPatches(&numPatches, patches, &generation);
1282 reply->writeInt32(status);
1283 reply->writeInt32(numPatches);
1284 if (status == NO_ERROR) {
1285 if (numPatchesReq > numPatches) {
1286 numPatchesReq = numPatches;
1287 }
1288 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1289 reply->writeInt32(generation);
1290 }
1291 free(patches);
1292 return NO_ERROR;
1293 }
1294
1295 case SET_AUDIO_PORT_CONFIG: {
1296 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1297 struct audio_port_config config;
1298 data.read(&config, sizeof(struct audio_port_config));
1299 status_t status = setAudioPortConfig(&config);
1300 reply->writeInt32(status);
1301 return NO_ERROR;
1302 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001303
Eric Laurentb52c1522014-05-20 11:27:36 -07001304 case REGISTER_CLIENT: {
1305 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1306 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1307 data.readStrongBinder());
1308 registerClient(client);
1309 return NO_ERROR;
1310 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001311
Eric Laurente8726fe2015-06-26 09:39:24 -07001312 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1313 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1314 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1315 return NO_ERROR;
1316 } break;
1317
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001318 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1319 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1320 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1321 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001322 audio_session_t session = AUDIO_SESSION_NONE;
1323 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1324 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001325 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1326 reply->writeInt32(status);
1327 if (status == NO_ERROR) {
1328 reply->writeInt32(session);
1329 reply->writeInt32(ioHandle);
1330 reply->writeInt32(device);
1331 }
1332 return NO_ERROR;
1333 } break;
1334
1335 case RELEASE_SOUNDTRIGGER_SESSION: {
1336 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1337 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1338 data.readStrongBinder());
1339 audio_session_t session = (audio_session_t)data.readInt32();
1340 status_t status = releaseSoundTriggerSession(session);
1341 reply->writeInt32(status);
1342 return NO_ERROR;
1343 } break;
1344
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001345 case GET_PHONE_STATE: {
1346 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1347 reply->writeInt32((int32_t)getPhoneState());
1348 return NO_ERROR;
1349 } break;
1350
Eric Laurentbaac1832014-12-01 17:52:59 -08001351 case REGISTER_POLICY_MIXES: {
1352 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1353 bool registration = data.readInt32() == 1;
1354 Vector<AudioMix> mixes;
1355 size_t size = (size_t)data.readInt32();
1356 if (size > MAX_MIXES_PER_POLICY) {
1357 size = MAX_MIXES_PER_POLICY;
1358 }
1359 for (size_t i = 0; i < size; i++) {
1360 AudioMix mix;
1361 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1362 mixes.add(mix);
1363 }
1364 }
1365 status_t status = registerPolicyMixes(mixes, registration);
1366 reply->writeInt32(status);
1367 return NO_ERROR;
1368 } break;
1369
Eric Laurent554a2772015-04-10 11:29:24 -07001370 case START_AUDIO_SOURCE: {
1371 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1372 struct audio_port_config source;
1373 data.read(&source, sizeof(struct audio_port_config));
1374 audio_attributes_t attributes;
1375 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocardfbbe4212017-11-13 11:15:27 -08001376 sanetizeAudioAttributes(&attributes);
Glenn Kasten559d4392016-03-29 13:42:57 -07001377 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent554a2772015-04-10 11:29:24 -07001378 status_t status = startAudioSource(&source, &attributes, &handle);
1379 reply->writeInt32(status);
1380 reply->writeInt32(handle);
1381 return NO_ERROR;
1382 } break;
1383
1384 case STOP_AUDIO_SOURCE: {
1385 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten559d4392016-03-29 13:42:57 -07001386 audio_patch_handle_t handle = (audio_patch_handle_t) data.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -07001387 status_t status = stopAudioSource(handle);
1388 reply->writeInt32(status);
1389 return NO_ERROR;
1390 } break;
1391
Andy Hung2ddee192015-12-18 17:34:44 -08001392 case SET_MASTER_MONO: {
1393 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1394 bool mono = static_cast<bool>(data.readInt32());
1395 status_t status = setMasterMono(mono);
1396 reply->writeInt32(status);
1397 return NO_ERROR;
1398 } break;
1399
1400 case GET_MASTER_MONO: {
1401 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1402 bool mono;
1403 status_t status = getMasterMono(&mono);
1404 reply->writeInt32(status);
1405 if (status == NO_ERROR) {
1406 reply->writeInt32(static_cast<int32_t>(mono));
1407 }
1408 return NO_ERROR;
1409 } break;
1410
Eric Laurentc2f1f072009-07-17 12:17:14 -07001411 default:
1412 return BBinder::onTransact(code, data, reply, flags);
1413 }
1414}
1415
Kevin Rocardfbbe4212017-11-13 11:15:27 -08001416void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1417{
1418 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1419 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1420 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1421 }
1422 attr->tags[tagsMaxSize - 1] = '\0';
1423}
1424
Eric Laurentc2f1f072009-07-17 12:17:14 -07001425// ----------------------------------------------------------------------------
1426
Glenn Kasten40bc9062015-03-20 09:09:33 -07001427} // namespace android