blob: d91b73b5ee18fa38acedd3197375f0abbc2bd134 [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,
36 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080037 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 SET_FORCE_USE,
39 GET_FORCE_USE,
40 GET_OUTPUT,
41 START_OUTPUT,
42 STOP_OUTPUT,
43 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080044 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070045 START_INPUT,
46 STOP_INPUT,
47 RELEASE_INPUT,
48 INIT_STREAM_VOLUME,
49 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070050 GET_STREAM_VOLUME,
51 GET_STRATEGY_FOR_STREAM,
52 GET_OUTPUT_FOR_EFFECT,
53 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080054 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080055 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070056 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080057 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070058 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080059 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000060 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070061 IS_OFFLOAD_SUPPORTED,
62 LIST_AUDIO_PORTS,
63 GET_AUDIO_PORT,
64 CREATE_AUDIO_PATCH,
65 RELEASE_AUDIO_PATCH,
66 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070067 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070068 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070069 GET_OUTPUT_FOR_ATTR,
70 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070071 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080072 GET_PHONE_STATE,
73 REGISTER_POLICY_MIXES,
Eric Laurentc2f1f072009-07-17 12:17:14 -070074};
75
Eric Laurent2fdd16b2015-02-06 10:44:24 -080076#define MAX_ITEMS_PER_LIST 1024
77
Eric Laurentc2f1f072009-07-17 12:17:14 -070078class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
79{
80public:
81 BpAudioPolicyService(const sp<IBinder>& impl)
82 : BpInterface<IAudioPolicyService>(impl)
83 {
84 }
85
86 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070087 audio_devices_t device,
88 audio_policy_dev_state_t state,
Eric Laurentc2f1f072009-07-17 12:17:14 -070089 const char *device_address)
90 {
91 Parcel data, reply;
92 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
93 data.writeInt32(static_cast <uint32_t>(device));
94 data.writeInt32(static_cast <uint32_t>(state));
95 data.writeCString(device_address);
96 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
97 return static_cast <status_t> (reply.readInt32());
98 }
99
Dima Zavinfce7a472011-04-19 22:30:36 -0700100 virtual audio_policy_dev_state_t getDeviceConnectionState(
101 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700102 const char *device_address)
103 {
104 Parcel data, reply;
105 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
106 data.writeInt32(static_cast <uint32_t>(device));
107 data.writeCString(device_address);
108 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700109 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 }
111
Glenn Kastenf78aee72012-01-04 11:00:47 -0800112 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700113 {
114 Parcel data, reply;
115 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
116 data.writeInt32(state);
117 remote()->transact(SET_PHONE_STATE, data, &reply);
118 return static_cast <status_t> (reply.readInt32());
119 }
120
Dima Zavinfce7a472011-04-19 22:30:36 -0700121 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700122 {
123 Parcel data, reply;
124 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
125 data.writeInt32(static_cast <uint32_t>(usage));
126 data.writeInt32(static_cast <uint32_t>(config));
127 remote()->transact(SET_FORCE_USE, data, &reply);
128 return static_cast <status_t> (reply.readInt32());
129 }
130
Dima Zavinfce7a472011-04-19 22:30:36 -0700131 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700132 {
133 Parcel data, reply;
134 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
135 data.writeInt32(static_cast <uint32_t>(usage));
136 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700137 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700138 }
139
140 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700141 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700142 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800143 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700144 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000145 audio_output_flags_t flags,
146 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700147 {
148 Parcel data, reply;
149 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
150 data.writeInt32(static_cast <uint32_t>(stream));
151 data.writeInt32(samplingRate);
152 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700153 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700154 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800155 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100156 if (offloadInfo == NULL) {
157 data.writeInt32(0);
158 } else {
159 data.writeInt32(1);
160 data.write(offloadInfo, sizeof(audio_offload_info_t));
161 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700162 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700163 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164 }
165
Eric Laurente83b55d2014-11-14 10:06:21 -0800166 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
167 audio_io_handle_t *output,
168 audio_session_t session,
169 audio_stream_type_t *stream,
170 uint32_t samplingRate,
171 audio_format_t format,
172 audio_channel_mask_t channelMask,
173 audio_output_flags_t flags,
174 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700175 {
176 Parcel data, reply;
177 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
178 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800179 if (stream == NULL) {
180 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
181 return BAD_VALUE;
182 }
183 if (*stream == AUDIO_STREAM_DEFAULT) {
184 ALOGE("getOutputForAttr unspecified stream type");
185 return BAD_VALUE;
186 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700187 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800188 if (output == NULL) {
189 ALOGE("getOutputForAttr NULL output - shouldn't happen");
190 return BAD_VALUE;
191 }
192 if (attr == NULL) {
193 data.writeInt32(0);
194 } else {
195 data.writeInt32(1);
196 data.write(attr, sizeof(audio_attributes_t));
197 }
198 data.writeInt32(session);
199 if (stream == NULL) {
200 data.writeInt32(0);
201 } else {
202 data.writeInt32(1);
203 data.writeInt32(*stream);
204 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700205 data.writeInt32(samplingRate);
206 data.writeInt32(static_cast <uint32_t>(format));
207 data.writeInt32(channelMask);
208 data.writeInt32(static_cast <uint32_t>(flags));
209 // hasOffloadInfo
210 if (offloadInfo == NULL) {
211 data.writeInt32(0);
212 } else {
213 data.writeInt32(1);
214 data.write(offloadInfo, sizeof(audio_offload_info_t));
215 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800216 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
217 if (status != NO_ERROR) {
218 return status;
219 }
220 status = (status_t)reply.readInt32();
221 if (status != NO_ERROR) {
222 return status;
223 }
224 *output = (audio_io_handle_t)reply.readInt32();
225 if (stream != NULL) {
226 *stream = (audio_stream_type_t)reply.readInt32();
227 }
228 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700229 }
230
Eric Laurentde070132010-07-13 04:45:46 -0700231 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700232 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800233 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700234 {
235 Parcel data, reply;
236 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700237 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800238 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800239 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700240 remote()->transact(START_OUTPUT, data, &reply);
241 return static_cast <status_t> (reply.readInt32());
242 }
243
Eric Laurentde070132010-07-13 04:45:46 -0700244 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700245 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800246 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700247 {
248 Parcel data, reply;
249 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700250 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800251 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800252 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700253 remote()->transact(STOP_OUTPUT, data, &reply);
254 return static_cast <status_t> (reply.readInt32());
255 }
256
Eric Laurente83b55d2014-11-14 10:06:21 -0800257 virtual void releaseOutput(audio_io_handle_t output,
258 audio_stream_type_t stream,
259 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700260 {
261 Parcel data, reply;
262 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700263 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800264 data.writeInt32((int32_t)stream);
265 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700266 remote()->transact(RELEASE_OUTPUT, data, &reply);
267 }
268
Eric Laurentcaf7f482014-11-25 17:50:47 -0800269 virtual status_t getInputForAttr(const audio_attributes_t *attr,
270 audio_io_handle_t *input,
271 audio_session_t session,
272 uint32_t samplingRate,
273 audio_format_t format,
274 audio_channel_mask_t channelMask,
275 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800279 if (attr == NULL) {
280 ALOGE("getInputForAttr NULL attr - shouldn't happen");
281 return BAD_VALUE;
282 }
283 if (input == NULL) {
284 ALOGE("getInputForAttr NULL input - shouldn't happen");
285 return BAD_VALUE;
286 }
287 data.write(attr, sizeof(audio_attributes_t));
288 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 data.writeInt32(samplingRate);
290 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700291 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700292 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800293 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
294 if (status != NO_ERROR) {
295 return status;
296 }
297 status = reply.readInt32();
298 if (status != NO_ERROR) {
299 return status;
300 }
301 *input = (audio_io_handle_t)reply.readInt32();
302 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700303 }
304
Eric Laurent4dc68062014-07-28 17:26:49 -0700305 virtual status_t startInput(audio_io_handle_t input,
306 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700307 {
308 Parcel data, reply;
309 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700310 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700311 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700312 remote()->transact(START_INPUT, data, &reply);
313 return static_cast <status_t> (reply.readInt32());
314 }
315
Eric Laurent4dc68062014-07-28 17:26:49 -0700316 virtual status_t stopInput(audio_io_handle_t input,
317 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700321 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700322 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700323 remote()->transact(STOP_INPUT, data, &reply);
324 return static_cast <status_t> (reply.readInt32());
325 }
326
Eric Laurent4dc68062014-07-28 17:26:49 -0700327 virtual void releaseInput(audio_io_handle_t input,
328 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700329 {
330 Parcel data, reply;
331 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700332 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700333 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 remote()->transact(RELEASE_INPUT, data, &reply);
335 }
336
Dima Zavinfce7a472011-04-19 22:30:36 -0700337 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 int indexMin,
339 int indexMax)
340 {
341 Parcel data, reply;
342 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
343 data.writeInt32(static_cast <uint32_t>(stream));
344 data.writeInt32(indexMin);
345 data.writeInt32(indexMax);
346 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
347 return static_cast <status_t> (reply.readInt32());
348 }
349
Eric Laurent83844cc2011-11-18 16:43:31 -0800350 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
351 int index,
352 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353 {
354 Parcel data, reply;
355 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
356 data.writeInt32(static_cast <uint32_t>(stream));
357 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800358 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700359 remote()->transact(SET_STREAM_VOLUME, data, &reply);
360 return static_cast <status_t> (reply.readInt32());
361 }
362
Eric Laurent83844cc2011-11-18 16:43:31 -0800363 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
364 int *index,
365 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700366 {
367 Parcel data, reply;
368 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
369 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800370 data.writeInt32(static_cast <uint32_t>(device));
371
Eric Laurentc2f1f072009-07-17 12:17:14 -0700372 remote()->transact(GET_STREAM_VOLUME, data, &reply);
373 int lIndex = reply.readInt32();
374 if (index) *index = lIndex;
375 return static_cast <status_t> (reply.readInt32());
376 }
Eric Laurentde070132010-07-13 04:45:46 -0700377
Dima Zavinfce7a472011-04-19 22:30:36 -0700378 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700379 {
380 Parcel data, reply;
381 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
382 data.writeInt32(static_cast <uint32_t>(stream));
383 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
384 return reply.readInt32();
385 }
386
Eric Laurent63742522012-03-08 13:42:42 -0800387 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800388 {
389 Parcel data, reply;
390 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
391 data.writeInt32(static_cast <uint32_t>(stream));
392 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800393 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800394 }
395
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700396 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
400 data.write(desc, sizeof(effect_descriptor_t));
401 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
402 return static_cast <audio_io_handle_t> (reply.readInt32());
403 }
404
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700405 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700406 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700407 uint32_t strategy,
408 int session,
409 int id)
410 {
411 Parcel data, reply;
412 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
413 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700414 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700415 data.writeInt32(strategy);
416 data.writeInt32(session);
417 data.writeInt32(id);
418 remote()->transact(REGISTER_EFFECT, data, &reply);
419 return static_cast <status_t> (reply.readInt32());
420 }
421
422 virtual status_t unregisterEffect(int id)
423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
426 data.writeInt32(id);
427 remote()->transact(UNREGISTER_EFFECT, data, &reply);
428 return static_cast <status_t> (reply.readInt32());
429 }
430
Eric Laurentdb7c0792011-08-10 10:37:50 -0700431 virtual status_t setEffectEnabled(int id, bool enabled)
432 {
433 Parcel data, reply;
434 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
435 data.writeInt32(id);
436 data.writeInt32(enabled);
437 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
438 return static_cast <status_t> (reply.readInt32());
439 }
440
Glenn Kastenfff6d712012-01-12 16:38:12 -0800441 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800442 {
443 Parcel data, reply;
444 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800445 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800446 data.writeInt32(inPastMs);
447 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
448 return reply.readInt32();
449 }
Eric Laurent57dae992011-07-24 13:36:09 -0700450
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800451 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
452 {
453 Parcel data, reply;
454 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
455 data.writeInt32((int32_t) stream);
456 data.writeInt32(inPastMs);
457 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
458 return reply.readInt32();
459 }
460
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700461 virtual bool isSourceActive(audio_source_t source) const
462 {
463 Parcel data, reply;
464 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
465 data.writeInt32((int32_t) source);
466 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
467 return reply.readInt32();
468 }
469
Eric Laurent57dae992011-07-24 13:36:09 -0700470 virtual status_t queryDefaultPreProcessing(int audioSession,
471 effect_descriptor_t *descriptors,
472 uint32_t *count)
473 {
474 if (descriptors == NULL || count == NULL) {
475 return BAD_VALUE;
476 }
477 Parcel data, reply;
478 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
479 data.writeInt32(audioSession);
480 data.writeInt32(*count);
481 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
482 if (status != NO_ERROR) {
483 return status;
484 }
485 status = static_cast <status_t> (reply.readInt32());
486 uint32_t retCount = reply.readInt32();
487 if (retCount != 0) {
488 uint32_t numDesc = (retCount < *count) ? retCount : *count;
489 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
490 }
491 *count = retCount;
492 return status;
493 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000494
495 virtual bool isOffloadSupported(const audio_offload_info_t& info)
496 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100497 Parcel data, reply;
498 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
499 data.write(&info, sizeof(audio_offload_info_t));
500 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700501 return reply.readInt32();
502 }
503
504 virtual status_t listAudioPorts(audio_port_role_t role,
505 audio_port_type_t type,
506 unsigned int *num_ports,
507 struct audio_port *ports,
508 unsigned int *generation)
509 {
510 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
511 generation == NULL) {
512 return BAD_VALUE;
513 }
514 Parcel data, reply;
515 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
516 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
517 data.writeInt32(role);
518 data.writeInt32(type);
519 data.writeInt32(numPortsReq);
520 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
521 if (status == NO_ERROR) {
522 status = (status_t)reply.readInt32();
523 *num_ports = (unsigned int)reply.readInt32();
524 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700525 if (status == NO_ERROR) {
526 if (numPortsReq > *num_ports) {
527 numPortsReq = *num_ports;
528 }
529 if (numPortsReq > 0) {
530 reply.read(ports, numPortsReq * sizeof(struct audio_port));
531 }
532 *generation = reply.readInt32();
533 }
534 return status;
535 }
536
537 virtual status_t getAudioPort(struct audio_port *port)
538 {
539 if (port == NULL) {
540 return BAD_VALUE;
541 }
542 Parcel data, reply;
543 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
544 data.write(port, sizeof(struct audio_port));
545 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
546 if (status != NO_ERROR ||
547 (status = (status_t)reply.readInt32()) != NO_ERROR) {
548 return status;
549 }
550 reply.read(port, sizeof(struct audio_port));
551 return status;
552 }
553
554 virtual status_t createAudioPatch(const struct audio_patch *patch,
555 audio_patch_handle_t *handle)
556 {
557 if (patch == NULL || handle == NULL) {
558 return BAD_VALUE;
559 }
560 Parcel data, reply;
561 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
562 data.write(patch, sizeof(struct audio_patch));
563 data.write(handle, sizeof(audio_patch_handle_t));
564 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
565 if (status != NO_ERROR ||
566 (status = (status_t)reply.readInt32()) != NO_ERROR) {
567 return status;
568 }
569 reply.read(handle, sizeof(audio_patch_handle_t));
570 return status;
571 }
572
573 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
574 {
575 Parcel data, reply;
576 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
577 data.write(&handle, sizeof(audio_patch_handle_t));
578 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
579 if (status != NO_ERROR) {
580 status = (status_t)reply.readInt32();
581 }
582 return status;
583 }
584
585 virtual status_t listAudioPatches(unsigned int *num_patches,
586 struct audio_patch *patches,
587 unsigned int *generation)
588 {
589 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
590 generation == NULL) {
591 return BAD_VALUE;
592 }
593 Parcel data, reply;
594 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
595 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
596 data.writeInt32(numPatchesReq);
597 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
598 if (status == NO_ERROR) {
599 status = (status_t)reply.readInt32();
600 *num_patches = (unsigned int)reply.readInt32();
601 }
602 if (status == NO_ERROR) {
603 if (numPatchesReq > *num_patches) {
604 numPatchesReq = *num_patches;
605 }
606 if (numPatchesReq > 0) {
607 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
608 }
609 *generation = reply.readInt32();
610 }
611 return status;
612 }
613
614 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
615 {
616 if (config == NULL) {
617 return BAD_VALUE;
618 }
619 Parcel data, reply;
620 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
621 data.write(config, sizeof(struct audio_port_config));
622 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
623 if (status != NO_ERROR) {
624 status = (status_t)reply.readInt32();
625 }
626 return status;
627 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700628
Eric Laurentb52c1522014-05-20 11:27:36 -0700629 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
630 {
631 Parcel data, reply;
632 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
633 data.writeStrongBinder(client->asBinder());
634 remote()->transact(REGISTER_CLIENT, data, &reply);
635 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700636
637 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
638 audio_io_handle_t *ioHandle,
639 audio_devices_t *device)
640 {
641 if (session == NULL || ioHandle == NULL || device == NULL) {
642 return BAD_VALUE;
643 }
644 Parcel data, reply;
645 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
646 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
647 if (status != NO_ERROR) {
648 return status;
649 }
650 status = (status_t)reply.readInt32();
651 if (status == NO_ERROR) {
652 *session = (audio_session_t)reply.readInt32();
653 *ioHandle = (audio_io_handle_t)reply.readInt32();
654 *device = (audio_devices_t)reply.readInt32();
655 }
656 return status;
657 }
658
659 virtual status_t releaseSoundTriggerSession(audio_session_t session)
660 {
661 Parcel data, reply;
662 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
663 data.writeInt32(session);
664 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
665 if (status != NO_ERROR) {
666 return status;
667 }
668 return (status_t)reply.readInt32();
669 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700670
671 virtual audio_mode_t getPhoneState()
672 {
673 Parcel data, reply;
674 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
675 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
676 if (status != NO_ERROR) {
677 return AUDIO_MODE_INVALID;
678 }
679 return (audio_mode_t)reply.readInt32();
680 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800681
682 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
683 {
684 Parcel data, reply;
685 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
686 data.writeInt32(registration ? 1 : 0);
687 size_t size = mixes.size();
688 if (size > MAX_MIXES_PER_POLICY) {
689 size = MAX_MIXES_PER_POLICY;
690 }
691 size_t sizePosition = data.dataPosition();
692 data.writeInt32(size);
693 size_t finalSize = size;
694 for (size_t i = 0; i < size; i++) {
695 size_t position = data.dataPosition();
696 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
697 data.setDataPosition(position);
698 finalSize--;
699 }
700 }
701 if (size != finalSize) {
702 size_t position = data.dataPosition();
703 data.setDataPosition(sizePosition);
704 data.writeInt32(finalSize);
705 data.setDataPosition(position);
706 }
707 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
708 if (status == NO_ERROR) {
709 status = (status_t)reply.readInt32();
710 }
711 return status;
712 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700713};
714
715IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
716
717// ----------------------------------------------------------------------
718
719
720status_t BnAudioPolicyService::onTransact(
721 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
722{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700723 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700724 case SET_DEVICE_CONNECTION_STATE: {
725 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700726 audio_devices_t device =
727 static_cast <audio_devices_t>(data.readInt32());
728 audio_policy_dev_state_t state =
729 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700730 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700731 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
732 state,
733 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700734 return NO_ERROR;
735 } break;
736
737 case GET_DEVICE_CONNECTION_STATE: {
738 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700739 audio_devices_t device =
740 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700741 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700742 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
743 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700744 return NO_ERROR;
745 } break;
746
747 case SET_PHONE_STATE: {
748 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700749 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
750 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700751 return NO_ERROR;
752 } break;
753
Eric Laurentc2f1f072009-07-17 12:17:14 -0700754 case SET_FORCE_USE: {
755 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700756 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
757 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700758 audio_policy_forced_cfg_t config =
759 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700760 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
761 return NO_ERROR;
762 } break;
763
764 case GET_FORCE_USE: {
765 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700766 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
767 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700768 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
769 return NO_ERROR;
770 } break;
771
772 case GET_OUTPUT: {
773 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700774 audio_stream_type_t stream =
775 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700776 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800777 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700778 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700779 audio_output_flags_t flags =
780 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100781 bool hasOffloadInfo = data.readInt32() != 0;
782 audio_offload_info_t offloadInfo;
783 if (hasOffloadInfo) {
784 data.read(&offloadInfo, sizeof(audio_offload_info_t));
785 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700786 audio_io_handle_t output = getOutput(stream,
787 samplingRate,
788 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700789 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100790 flags,
791 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700792 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700793 return NO_ERROR;
794 } break;
795
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700796 case GET_OUTPUT_FOR_ATTR: {
797 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800798 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800799 bool hasAttributes = data.readInt32() != 0;
800 if (hasAttributes) {
801 data.read(&attr, sizeof(audio_attributes_t));
802 }
803 audio_session_t session = (audio_session_t)data.readInt32();
804 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
805 bool hasStream = data.readInt32() != 0;
806 if (hasStream) {
807 stream = (audio_stream_type_t)data.readInt32();
808 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700809 uint32_t samplingRate = data.readInt32();
810 audio_format_t format = (audio_format_t) data.readInt32();
811 audio_channel_mask_t channelMask = data.readInt32();
812 audio_output_flags_t flags =
813 static_cast <audio_output_flags_t>(data.readInt32());
814 bool hasOffloadInfo = data.readInt32() != 0;
815 audio_offload_info_t offloadInfo;
816 if (hasOffloadInfo) {
817 data.read(&offloadInfo, sizeof(audio_offload_info_t));
818 }
Robert Shiha946d842015-09-02 16:46:59 -0700819 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800820 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
821 &output, session, &stream,
822 samplingRate, format, channelMask,
823 flags, hasOffloadInfo ? &offloadInfo : NULL);
824 reply->writeInt32(status);
825 reply->writeInt32(output);
826 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700827 return NO_ERROR;
828 } break;
829
Eric Laurentc2f1f072009-07-17 12:17:14 -0700830 case START_OUTPUT: {
831 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700832 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800833 audio_stream_type_t stream =
834 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800835 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700836 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800837 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700838 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700839 return NO_ERROR;
840 } break;
841
842 case STOP_OUTPUT: {
843 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700844 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800845 audio_stream_type_t stream =
846 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800847 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700848 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800849 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700850 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700851 return NO_ERROR;
852 } break;
853
854 case RELEASE_OUTPUT: {
855 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700856 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800857 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
858 audio_session_t session = (audio_session_t)data.readInt32();
859 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700860 return NO_ERROR;
861 } break;
862
Eric Laurentcaf7f482014-11-25 17:50:47 -0800863 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700864 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800865 audio_attributes_t attr;
866 data.read(&attr, sizeof(audio_attributes_t));
867 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700868 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800869 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700870 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700871 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800872 audio_io_handle_t input;
873 status_t status = getInputForAttr(&attr, &input, session,
874 samplingRate, format, channelMask,
875 flags);
876 reply->writeInt32(status);
877 if (status == NO_ERROR) {
878 reply->writeInt32(input);
879 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700880 return NO_ERROR;
881 } break;
882
883 case START_INPUT: {
884 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700885 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700886 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
887 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700888 return NO_ERROR;
889 } break;
890
891 case STOP_INPUT: {
892 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700893 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700894 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
895 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700896 return NO_ERROR;
897 } break;
898
899 case RELEASE_INPUT: {
900 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700901 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700902 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
903 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700904 return NO_ERROR;
905 } break;
906
907 case INIT_STREAM_VOLUME: {
908 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700909 audio_stream_type_t stream =
910 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700911 int indexMin = data.readInt32();
912 int indexMax = data.readInt32();
913 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
914 return NO_ERROR;
915 } break;
916
917 case SET_STREAM_VOLUME: {
918 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700919 audio_stream_type_t stream =
920 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700921 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800922 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
923 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
924 index,
925 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700926 return NO_ERROR;
927 } break;
928
929 case GET_STREAM_VOLUME: {
930 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700931 audio_stream_type_t stream =
932 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800933 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700934 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800935 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 reply->writeInt32(index);
937 reply->writeInt32(static_cast <uint32_t>(status));
938 return NO_ERROR;
939 } break;
940
Eric Laurentde070132010-07-13 04:45:46 -0700941 case GET_STRATEGY_FOR_STREAM: {
942 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700943 audio_stream_type_t stream =
944 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700945 reply->writeInt32(getStrategyForStream(stream));
946 return NO_ERROR;
947 } break;
948
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800949 case GET_DEVICES_FOR_STREAM: {
950 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700951 audio_stream_type_t stream =
952 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800953 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
954 return NO_ERROR;
955 } break;
956
Eric Laurentde070132010-07-13 04:45:46 -0700957 case GET_OUTPUT_FOR_EFFECT: {
958 CHECK_INTERFACE(IAudioPolicyService, data, reply);
959 effect_descriptor_t desc;
960 data.read(&desc, sizeof(effect_descriptor_t));
961 audio_io_handle_t output = getOutputForEffect(&desc);
962 reply->writeInt32(static_cast <int>(output));
963 return NO_ERROR;
964 } break;
965
966 case REGISTER_EFFECT: {
967 CHECK_INTERFACE(IAudioPolicyService, data, reply);
968 effect_descriptor_t desc;
969 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700970 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700971 uint32_t strategy = data.readInt32();
972 int session = data.readInt32();
973 int id = data.readInt32();
974 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700975 io,
Eric Laurentde070132010-07-13 04:45:46 -0700976 strategy,
977 session,
978 id)));
979 return NO_ERROR;
980 } break;
981
982 case UNREGISTER_EFFECT: {
983 CHECK_INTERFACE(IAudioPolicyService, data, reply);
984 int id = data.readInt32();
985 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
986 return NO_ERROR;
987 } break;
988
Eric Laurentdb7c0792011-08-10 10:37:50 -0700989 case SET_EFFECT_ENABLED: {
990 CHECK_INTERFACE(IAudioPolicyService, data, reply);
991 int id = data.readInt32();
992 bool enabled = static_cast <bool>(data.readInt32());
993 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
994 return NO_ERROR;
995 } break;
996
Eric Laurenteda6c362011-02-02 09:33:30 -0800997 case IS_STREAM_ACTIVE: {
998 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800999 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001000 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001001 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001002 return NO_ERROR;
1003 } break;
1004
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001005 case IS_STREAM_ACTIVE_REMOTELY: {
1006 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1007 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1008 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001009 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001010 return NO_ERROR;
1011 } break;
1012
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001013 case IS_SOURCE_ACTIVE: {
1014 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1015 audio_source_t source = (audio_source_t) data.readInt32();
1016 reply->writeInt32( isSourceActive(source));
1017 return NO_ERROR;
1018 }
1019
Eric Laurent57dae992011-07-24 13:36:09 -07001020 case QUERY_DEFAULT_PRE_PROCESSING: {
1021 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1022 int audioSession = data.readInt32();
1023 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001024 if (count > AudioEffect::kMaxPreProcessing) {
1025 count = AudioEffect::kMaxPreProcessing;
1026 }
Eric Laurent57dae992011-07-24 13:36:09 -07001027 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001028 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001029 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1030 reply->writeInt32(status);
1031 if (status != NO_ERROR && status != NO_MEMORY) {
1032 retCount = 0;
1033 }
1034 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001035 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001036 if (retCount < count) {
1037 count = retCount;
1038 }
1039 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1040 }
1041 delete[] descriptors;
1042 return status;
1043 }
1044
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001045 case IS_OFFLOAD_SUPPORTED: {
1046 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1047 audio_offload_info_t info;
1048 data.read(&info, sizeof(audio_offload_info_t));
1049 bool isSupported = isOffloadSupported(info);
1050 reply->writeInt32(isSupported);
1051 return NO_ERROR;
1052 }
1053
Eric Laurent203b1a12014-04-01 10:34:16 -07001054 case LIST_AUDIO_PORTS: {
1055 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1056 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1057 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1058 unsigned int numPortsReq = data.readInt32();
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001059 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1060 numPortsReq = MAX_ITEMS_PER_LIST;
1061 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001062 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001063 struct audio_port *ports =
1064 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001065 if (ports == NULL) {
1066 reply->writeInt32(NO_MEMORY);
1067 reply->writeInt32(0);
1068 return NO_ERROR;
1069 }
1070 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001071 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1072 reply->writeInt32(status);
1073 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001074
1075 if (status == NO_ERROR) {
1076 if (numPortsReq > numPorts) {
1077 numPortsReq = numPorts;
1078 }
1079 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1080 reply->writeInt32(generation);
1081 }
1082 free(ports);
1083 return NO_ERROR;
1084 }
1085
1086 case GET_AUDIO_PORT: {
1087 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1088 struct audio_port port;
1089 data.read(&port, sizeof(struct audio_port));
1090 status_t status = getAudioPort(&port);
1091 reply->writeInt32(status);
1092 if (status == NO_ERROR) {
1093 reply->write(&port, sizeof(struct audio_port));
1094 }
1095 return NO_ERROR;
1096 }
1097
1098 case CREATE_AUDIO_PATCH: {
1099 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1100 struct audio_patch patch;
1101 data.read(&patch, sizeof(struct audio_patch));
1102 audio_patch_handle_t handle;
1103 data.read(&handle, sizeof(audio_patch_handle_t));
1104 status_t status = createAudioPatch(&patch, &handle);
1105 reply->writeInt32(status);
1106 if (status == NO_ERROR) {
1107 reply->write(&handle, sizeof(audio_patch_handle_t));
1108 }
1109 return NO_ERROR;
1110 }
1111
1112 case RELEASE_AUDIO_PATCH: {
1113 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1114 audio_patch_handle_t handle;
1115 data.read(&handle, sizeof(audio_patch_handle_t));
1116 status_t status = releaseAudioPatch(handle);
1117 reply->writeInt32(status);
1118 return NO_ERROR;
1119 }
1120
1121 case LIST_AUDIO_PATCHES: {
1122 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1123 unsigned int numPatchesReq = data.readInt32();
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001124 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1125 numPatchesReq = MAX_ITEMS_PER_LIST;
1126 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001127 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001128 struct audio_patch *patches =
1129 (struct audio_patch *)calloc(numPatchesReq,
1130 sizeof(struct audio_patch));
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001131 if (patches == NULL) {
1132 reply->writeInt32(NO_MEMORY);
1133 reply->writeInt32(0);
1134 return NO_ERROR;
1135 }
1136 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001137 status_t status = listAudioPatches(&numPatches, patches, &generation);
1138 reply->writeInt32(status);
1139 reply->writeInt32(numPatches);
1140 if (status == NO_ERROR) {
1141 if (numPatchesReq > numPatches) {
1142 numPatchesReq = numPatches;
1143 }
1144 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1145 reply->writeInt32(generation);
1146 }
1147 free(patches);
1148 return NO_ERROR;
1149 }
1150
1151 case SET_AUDIO_PORT_CONFIG: {
1152 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1153 struct audio_port_config config;
1154 data.read(&config, sizeof(struct audio_port_config));
1155 status_t status = setAudioPortConfig(&config);
1156 reply->writeInt32(status);
1157 return NO_ERROR;
1158 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001159
Eric Laurentb52c1522014-05-20 11:27:36 -07001160 case REGISTER_CLIENT: {
1161 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1162 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1163 data.readStrongBinder());
1164 registerClient(client);
1165 return NO_ERROR;
1166 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001167
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001168 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1169 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1170 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1171 data.readStrongBinder());
1172 audio_session_t session;
1173 audio_io_handle_t ioHandle;
1174 audio_devices_t device;
1175 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1176 reply->writeInt32(status);
1177 if (status == NO_ERROR) {
1178 reply->writeInt32(session);
1179 reply->writeInt32(ioHandle);
1180 reply->writeInt32(device);
1181 }
1182 return NO_ERROR;
1183 } break;
1184
1185 case RELEASE_SOUNDTRIGGER_SESSION: {
1186 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1187 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1188 data.readStrongBinder());
1189 audio_session_t session = (audio_session_t)data.readInt32();
1190 status_t status = releaseSoundTriggerSession(session);
1191 reply->writeInt32(status);
1192 return NO_ERROR;
1193 } break;
1194
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001195 case GET_PHONE_STATE: {
1196 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1197 reply->writeInt32((int32_t)getPhoneState());
1198 return NO_ERROR;
1199 } break;
1200
Eric Laurentbaac1832014-12-01 17:52:59 -08001201 case REGISTER_POLICY_MIXES: {
1202 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1203 bool registration = data.readInt32() == 1;
1204 Vector<AudioMix> mixes;
1205 size_t size = (size_t)data.readInt32();
1206 if (size > MAX_MIXES_PER_POLICY) {
1207 size = MAX_MIXES_PER_POLICY;
1208 }
1209 for (size_t i = 0; i < size; i++) {
1210 AudioMix mix;
1211 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1212 mixes.add(mix);
1213 }
1214 }
1215 status_t status = registerPolicyMixes(mixes, registration);
1216 reply->writeInt32(status);
1217 return NO_ERROR;
1218 } break;
1219
Eric Laurentc2f1f072009-07-17 12:17:14 -07001220 default:
1221 return BBinder::onTransact(code, data, reply, flags);
1222 }
1223}
1224
1225// ----------------------------------------------------------------------------
1226
1227}; // namespace android