blob: b1750550761c93a8a85db98b02ca34bd403a89e8 [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
76class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
77{
78public:
79 BpAudioPolicyService(const sp<IBinder>& impl)
80 : BpInterface<IAudioPolicyService>(impl)
81 {
82 }
83
84 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070085 audio_devices_t device,
86 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080087 const char *device_address,
88 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070089 {
90 Parcel data, reply;
91 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
92 data.writeInt32(static_cast <uint32_t>(device));
93 data.writeInt32(static_cast <uint32_t>(state));
94 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -080095 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -070096 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());
Marco Nelissenf8880202014-11-14 07:58:25 -0800633 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700634 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();
Paul McLeane743a472015-01-28 11:07:31 -0800731 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700732 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
733 state,
Paul McLeane743a472015-01-28 11:07:31 -0800734 device_address,
735 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700736 return NO_ERROR;
737 } break;
738
739 case GET_DEVICE_CONNECTION_STATE: {
740 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700741 audio_devices_t device =
742 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700743 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700744 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
745 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700746 return NO_ERROR;
747 } break;
748
749 case SET_PHONE_STATE: {
750 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700751 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
752 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700753 return NO_ERROR;
754 } break;
755
Eric Laurentc2f1f072009-07-17 12:17:14 -0700756 case SET_FORCE_USE: {
757 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700758 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
759 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700760 audio_policy_forced_cfg_t config =
761 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700762 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
763 return NO_ERROR;
764 } break;
765
766 case GET_FORCE_USE: {
767 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700768 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
769 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700770 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
771 return NO_ERROR;
772 } break;
773
774 case GET_OUTPUT: {
775 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700776 audio_stream_type_t stream =
777 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700778 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800779 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700780 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700781 audio_output_flags_t flags =
782 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100783 bool hasOffloadInfo = data.readInt32() != 0;
784 audio_offload_info_t offloadInfo;
785 if (hasOffloadInfo) {
786 data.read(&offloadInfo, sizeof(audio_offload_info_t));
787 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700788 audio_io_handle_t output = getOutput(stream,
789 samplingRate,
790 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700791 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100792 flags,
793 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700794 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700795 return NO_ERROR;
796 } break;
797
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700798 case GET_OUTPUT_FOR_ATTR: {
799 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800800 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800801 bool hasAttributes = data.readInt32() != 0;
802 if (hasAttributes) {
803 data.read(&attr, sizeof(audio_attributes_t));
804 }
805 audio_session_t session = (audio_session_t)data.readInt32();
806 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
807 bool hasStream = data.readInt32() != 0;
808 if (hasStream) {
809 stream = (audio_stream_type_t)data.readInt32();
810 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700811 uint32_t samplingRate = data.readInt32();
812 audio_format_t format = (audio_format_t) data.readInt32();
813 audio_channel_mask_t channelMask = data.readInt32();
814 audio_output_flags_t flags =
815 static_cast <audio_output_flags_t>(data.readInt32());
816 bool hasOffloadInfo = data.readInt32() != 0;
817 audio_offload_info_t offloadInfo;
818 if (hasOffloadInfo) {
819 data.read(&offloadInfo, sizeof(audio_offload_info_t));
820 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800821 audio_io_handle_t output;
822 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
823 &output, session, &stream,
824 samplingRate, format, channelMask,
825 flags, hasOffloadInfo ? &offloadInfo : NULL);
826 reply->writeInt32(status);
827 reply->writeInt32(output);
828 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700829 return NO_ERROR;
830 } break;
831
Eric Laurentc2f1f072009-07-17 12:17:14 -0700832 case START_OUTPUT: {
833 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700834 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800835 audio_stream_type_t stream =
836 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800837 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700838 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800839 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700840 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700841 return NO_ERROR;
842 } break;
843
844 case STOP_OUTPUT: {
845 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700846 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800847 audio_stream_type_t stream =
848 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800849 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700850 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800851 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700852 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700853 return NO_ERROR;
854 } break;
855
856 case RELEASE_OUTPUT: {
857 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700858 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800859 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
860 audio_session_t session = (audio_session_t)data.readInt32();
861 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 return NO_ERROR;
863 } break;
864
Eric Laurentcaf7f482014-11-25 17:50:47 -0800865 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700866 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800867 audio_attributes_t attr;
868 data.read(&attr, sizeof(audio_attributes_t));
869 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700870 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800871 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700872 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700873 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800874 audio_io_handle_t input;
875 status_t status = getInputForAttr(&attr, &input, session,
876 samplingRate, format, channelMask,
877 flags);
878 reply->writeInt32(status);
879 if (status == NO_ERROR) {
880 reply->writeInt32(input);
881 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700882 return NO_ERROR;
883 } break;
884
885 case START_INPUT: {
886 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700887 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700888 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
889 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700890 return NO_ERROR;
891 } break;
892
893 case STOP_INPUT: {
894 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700895 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700896 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
897 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700898 return NO_ERROR;
899 } break;
900
901 case RELEASE_INPUT: {
902 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700903 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700904 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
905 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700906 return NO_ERROR;
907 } break;
908
909 case INIT_STREAM_VOLUME: {
910 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700911 audio_stream_type_t stream =
912 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700913 int indexMin = data.readInt32();
914 int indexMax = data.readInt32();
915 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
916 return NO_ERROR;
917 } break;
918
919 case SET_STREAM_VOLUME: {
920 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700921 audio_stream_type_t stream =
922 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700923 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800924 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
925 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
926 index,
927 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700928 return NO_ERROR;
929 } break;
930
931 case GET_STREAM_VOLUME: {
932 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700933 audio_stream_type_t stream =
934 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800935 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800937 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700938 reply->writeInt32(index);
939 reply->writeInt32(static_cast <uint32_t>(status));
940 return NO_ERROR;
941 } break;
942
Eric Laurentde070132010-07-13 04:45:46 -0700943 case GET_STRATEGY_FOR_STREAM: {
944 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700945 audio_stream_type_t stream =
946 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700947 reply->writeInt32(getStrategyForStream(stream));
948 return NO_ERROR;
949 } break;
950
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800951 case GET_DEVICES_FOR_STREAM: {
952 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700953 audio_stream_type_t stream =
954 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800955 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
956 return NO_ERROR;
957 } break;
958
Eric Laurentde070132010-07-13 04:45:46 -0700959 case GET_OUTPUT_FOR_EFFECT: {
960 CHECK_INTERFACE(IAudioPolicyService, data, reply);
961 effect_descriptor_t desc;
962 data.read(&desc, sizeof(effect_descriptor_t));
963 audio_io_handle_t output = getOutputForEffect(&desc);
964 reply->writeInt32(static_cast <int>(output));
965 return NO_ERROR;
966 } break;
967
968 case REGISTER_EFFECT: {
969 CHECK_INTERFACE(IAudioPolicyService, data, reply);
970 effect_descriptor_t desc;
971 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700972 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700973 uint32_t strategy = data.readInt32();
974 int session = data.readInt32();
975 int id = data.readInt32();
976 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700977 io,
Eric Laurentde070132010-07-13 04:45:46 -0700978 strategy,
979 session,
980 id)));
981 return NO_ERROR;
982 } break;
983
984 case UNREGISTER_EFFECT: {
985 CHECK_INTERFACE(IAudioPolicyService, data, reply);
986 int id = data.readInt32();
987 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
988 return NO_ERROR;
989 } break;
990
Eric Laurentdb7c0792011-08-10 10:37:50 -0700991 case SET_EFFECT_ENABLED: {
992 CHECK_INTERFACE(IAudioPolicyService, data, reply);
993 int id = data.readInt32();
994 bool enabled = static_cast <bool>(data.readInt32());
995 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
996 return NO_ERROR;
997 } break;
998
Eric Laurenteda6c362011-02-02 09:33:30 -0800999 case IS_STREAM_ACTIVE: {
1000 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001001 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001002 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001003 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001004 return NO_ERROR;
1005 } break;
1006
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001007 case IS_STREAM_ACTIVE_REMOTELY: {
1008 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1009 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1010 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001011 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001012 return NO_ERROR;
1013 } break;
1014
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001015 case IS_SOURCE_ACTIVE: {
1016 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1017 audio_source_t source = (audio_source_t) data.readInt32();
1018 reply->writeInt32( isSourceActive(source));
1019 return NO_ERROR;
1020 }
1021
Eric Laurent57dae992011-07-24 13:36:09 -07001022 case QUERY_DEFAULT_PRE_PROCESSING: {
1023 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1024 int audioSession = data.readInt32();
1025 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001026 if (count > AudioEffect::kMaxPreProcessing) {
1027 count = AudioEffect::kMaxPreProcessing;
1028 }
Eric Laurent57dae992011-07-24 13:36:09 -07001029 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001030 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001031 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1032 reply->writeInt32(status);
1033 if (status != NO_ERROR && status != NO_MEMORY) {
1034 retCount = 0;
1035 }
1036 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001037 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001038 if (retCount < count) {
1039 count = retCount;
1040 }
1041 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1042 }
1043 delete[] descriptors;
1044 return status;
1045 }
1046
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001047 case IS_OFFLOAD_SUPPORTED: {
1048 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1049 audio_offload_info_t info;
1050 data.read(&info, sizeof(audio_offload_info_t));
1051 bool isSupported = isOffloadSupported(info);
1052 reply->writeInt32(isSupported);
1053 return NO_ERROR;
1054 }
1055
Eric Laurent203b1a12014-04-01 10:34:16 -07001056 case LIST_AUDIO_PORTS: {
1057 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1058 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1059 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1060 unsigned int numPortsReq = data.readInt32();
1061 unsigned int numPorts = numPortsReq;
1062 unsigned int generation;
1063 struct audio_port *ports =
1064 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
1065 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1066 reply->writeInt32(status);
1067 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001068
1069 if (status == NO_ERROR) {
1070 if (numPortsReq > numPorts) {
1071 numPortsReq = numPorts;
1072 }
1073 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1074 reply->writeInt32(generation);
1075 }
1076 free(ports);
1077 return NO_ERROR;
1078 }
1079
1080 case GET_AUDIO_PORT: {
1081 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1082 struct audio_port port;
1083 data.read(&port, sizeof(struct audio_port));
1084 status_t status = getAudioPort(&port);
1085 reply->writeInt32(status);
1086 if (status == NO_ERROR) {
1087 reply->write(&port, sizeof(struct audio_port));
1088 }
1089 return NO_ERROR;
1090 }
1091
1092 case CREATE_AUDIO_PATCH: {
1093 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1094 struct audio_patch patch;
1095 data.read(&patch, sizeof(struct audio_patch));
1096 audio_patch_handle_t handle;
1097 data.read(&handle, sizeof(audio_patch_handle_t));
1098 status_t status = createAudioPatch(&patch, &handle);
1099 reply->writeInt32(status);
1100 if (status == NO_ERROR) {
1101 reply->write(&handle, sizeof(audio_patch_handle_t));
1102 }
1103 return NO_ERROR;
1104 }
1105
1106 case RELEASE_AUDIO_PATCH: {
1107 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1108 audio_patch_handle_t handle;
1109 data.read(&handle, sizeof(audio_patch_handle_t));
1110 status_t status = releaseAudioPatch(handle);
1111 reply->writeInt32(status);
1112 return NO_ERROR;
1113 }
1114
1115 case LIST_AUDIO_PATCHES: {
1116 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1117 unsigned int numPatchesReq = data.readInt32();
1118 unsigned int numPatches = numPatchesReq;
1119 unsigned int generation;
1120 struct audio_patch *patches =
1121 (struct audio_patch *)calloc(numPatchesReq,
1122 sizeof(struct audio_patch));
1123 status_t status = listAudioPatches(&numPatches, patches, &generation);
1124 reply->writeInt32(status);
1125 reply->writeInt32(numPatches);
1126 if (status == NO_ERROR) {
1127 if (numPatchesReq > numPatches) {
1128 numPatchesReq = numPatches;
1129 }
1130 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1131 reply->writeInt32(generation);
1132 }
1133 free(patches);
1134 return NO_ERROR;
1135 }
1136
1137 case SET_AUDIO_PORT_CONFIG: {
1138 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1139 struct audio_port_config config;
1140 data.read(&config, sizeof(struct audio_port_config));
1141 status_t status = setAudioPortConfig(&config);
1142 reply->writeInt32(status);
1143 return NO_ERROR;
1144 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001145
Eric Laurentb52c1522014-05-20 11:27:36 -07001146 case REGISTER_CLIENT: {
1147 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1148 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1149 data.readStrongBinder());
1150 registerClient(client);
1151 return NO_ERROR;
1152 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001153
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001154 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1155 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1156 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1157 data.readStrongBinder());
1158 audio_session_t session;
1159 audio_io_handle_t ioHandle;
1160 audio_devices_t device;
1161 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1162 reply->writeInt32(status);
1163 if (status == NO_ERROR) {
1164 reply->writeInt32(session);
1165 reply->writeInt32(ioHandle);
1166 reply->writeInt32(device);
1167 }
1168 return NO_ERROR;
1169 } break;
1170
1171 case RELEASE_SOUNDTRIGGER_SESSION: {
1172 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1173 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1174 data.readStrongBinder());
1175 audio_session_t session = (audio_session_t)data.readInt32();
1176 status_t status = releaseSoundTriggerSession(session);
1177 reply->writeInt32(status);
1178 return NO_ERROR;
1179 } break;
1180
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001181 case GET_PHONE_STATE: {
1182 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1183 reply->writeInt32((int32_t)getPhoneState());
1184 return NO_ERROR;
1185 } break;
1186
Eric Laurentbaac1832014-12-01 17:52:59 -08001187 case REGISTER_POLICY_MIXES: {
1188 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1189 bool registration = data.readInt32() == 1;
1190 Vector<AudioMix> mixes;
1191 size_t size = (size_t)data.readInt32();
1192 if (size > MAX_MIXES_PER_POLICY) {
1193 size = MAX_MIXES_PER_POLICY;
1194 }
1195 for (size_t i = 0; i < size; i++) {
1196 AudioMix mix;
1197 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1198 mixes.add(mix);
1199 }
1200 }
1201 status_t status = registerPolicyMixes(mixes, registration);
1202 reply->writeInt32(status);
1203 return NO_ERROR;
1204 } break;
1205
Eric Laurentc2f1f072009-07-17 12:17:14 -07001206 default:
1207 return BBinder::onTransact(code, data, reply, flags);
1208 }
1209}
1210
1211// ----------------------------------------------------------------------------
1212
1213}; // namespace android