blob: 4b8653250565bd3fc90d73bccaaad2dbf888b3d5 [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 Laurent1d670b12015-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,
Paul McLeane743a472015-01-28 11:07:31 -080089 const char *device_address,
90 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070091 {
92 Parcel data, reply;
93 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
94 data.writeInt32(static_cast <uint32_t>(device));
95 data.writeInt32(static_cast <uint32_t>(state));
96 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -080097 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -070098 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
99 return static_cast <status_t> (reply.readInt32());
100 }
101
Dima Zavinfce7a472011-04-19 22:30:36 -0700102 virtual audio_policy_dev_state_t getDeviceConnectionState(
103 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700104 const char *device_address)
105 {
106 Parcel data, reply;
107 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
108 data.writeInt32(static_cast <uint32_t>(device));
109 data.writeCString(device_address);
110 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700111 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 }
113
Glenn Kastenf78aee72012-01-04 11:00:47 -0800114 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700115 {
116 Parcel data, reply;
117 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
118 data.writeInt32(state);
119 remote()->transact(SET_PHONE_STATE, data, &reply);
120 return static_cast <status_t> (reply.readInt32());
121 }
122
Dima Zavinfce7a472011-04-19 22:30:36 -0700123 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700124 {
125 Parcel data, reply;
126 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
127 data.writeInt32(static_cast <uint32_t>(usage));
128 data.writeInt32(static_cast <uint32_t>(config));
129 remote()->transact(SET_FORCE_USE, data, &reply);
130 return static_cast <status_t> (reply.readInt32());
131 }
132
Dima Zavinfce7a472011-04-19 22:30:36 -0700133 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
137 data.writeInt32(static_cast <uint32_t>(usage));
138 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700140 }
141
142 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700143 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700144 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800145 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700146 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000147 audio_output_flags_t flags,
148 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 {
150 Parcel data, reply;
151 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
152 data.writeInt32(static_cast <uint32_t>(stream));
153 data.writeInt32(samplingRate);
154 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700155 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700156 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800157 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100158 if (offloadInfo == NULL) {
159 data.writeInt32(0);
160 } else {
161 data.writeInt32(1);
162 data.write(offloadInfo, sizeof(audio_offload_info_t));
163 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700165 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700166 }
167
Eric Laurente83b55d2014-11-14 10:06:21 -0800168 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
169 audio_io_handle_t *output,
170 audio_session_t session,
171 audio_stream_type_t *stream,
172 uint32_t samplingRate,
173 audio_format_t format,
174 audio_channel_mask_t channelMask,
175 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700176 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800177 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700178 {
179 Parcel data, reply;
180 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
181 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800182 if (stream == NULL) {
183 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
184 return BAD_VALUE;
185 }
186 if (*stream == AUDIO_STREAM_DEFAULT) {
187 ALOGE("getOutputForAttr unspecified stream type");
188 return BAD_VALUE;
189 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700190 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800191 if (output == NULL) {
192 ALOGE("getOutputForAttr NULL output - shouldn't happen");
193 return BAD_VALUE;
194 }
195 if (attr == NULL) {
196 data.writeInt32(0);
197 } else {
198 data.writeInt32(1);
199 data.write(attr, sizeof(audio_attributes_t));
200 }
201 data.writeInt32(session);
202 if (stream == NULL) {
203 data.writeInt32(0);
204 } else {
205 data.writeInt32(1);
206 data.writeInt32(*stream);
207 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700208 data.writeInt32(samplingRate);
209 data.writeInt32(static_cast <uint32_t>(format));
210 data.writeInt32(channelMask);
211 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700212 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700213 // hasOffloadInfo
214 if (offloadInfo == NULL) {
215 data.writeInt32(0);
216 } else {
217 data.writeInt32(1);
218 data.write(offloadInfo, sizeof(audio_offload_info_t));
219 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800220 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
221 if (status != NO_ERROR) {
222 return status;
223 }
224 status = (status_t)reply.readInt32();
225 if (status != NO_ERROR) {
226 return status;
227 }
228 *output = (audio_io_handle_t)reply.readInt32();
229 if (stream != NULL) {
230 *stream = (audio_stream_type_t)reply.readInt32();
231 }
232 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700233 }
234
Eric Laurentde070132010-07-13 04:45:46 -0700235 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700236 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800237 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700238 {
239 Parcel data, reply;
240 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700241 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800242 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800243 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700244 remote()->transact(START_OUTPUT, data, &reply);
245 return static_cast <status_t> (reply.readInt32());
246 }
247
Eric Laurentde070132010-07-13 04:45:46 -0700248 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700249 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800250 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 {
252 Parcel data, reply;
253 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700254 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800255 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800256 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700257 remote()->transact(STOP_OUTPUT, data, &reply);
258 return static_cast <status_t> (reply.readInt32());
259 }
260
Eric Laurente83b55d2014-11-14 10:06:21 -0800261 virtual void releaseOutput(audio_io_handle_t output,
262 audio_stream_type_t stream,
263 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700267 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800268 data.writeInt32((int32_t)stream);
269 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700270 remote()->transact(RELEASE_OUTPUT, data, &reply);
271 }
272
Eric Laurentcaf7f482014-11-25 17:50:47 -0800273 virtual status_t getInputForAttr(const audio_attributes_t *attr,
274 audio_io_handle_t *input,
275 audio_session_t session,
276 uint32_t samplingRate,
277 audio_format_t format,
278 audio_channel_mask_t channelMask,
279 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800283 if (attr == NULL) {
284 ALOGE("getInputForAttr NULL attr - shouldn't happen");
285 return BAD_VALUE;
286 }
287 if (input == NULL) {
288 ALOGE("getInputForAttr NULL input - shouldn't happen");
289 return BAD_VALUE;
290 }
291 data.write(attr, sizeof(audio_attributes_t));
292 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 data.writeInt32(samplingRate);
294 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700295 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700296 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800297 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
298 if (status != NO_ERROR) {
299 return status;
300 }
301 status = reply.readInt32();
302 if (status != NO_ERROR) {
303 return status;
304 }
305 *input = (audio_io_handle_t)reply.readInt32();
306 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700307 }
308
Eric Laurent4dc68062014-07-28 17:26:49 -0700309 virtual status_t startInput(audio_io_handle_t input,
310 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700311 {
312 Parcel data, reply;
313 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700314 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700315 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700316 remote()->transact(START_INPUT, data, &reply);
317 return static_cast <status_t> (reply.readInt32());
318 }
319
Eric Laurent4dc68062014-07-28 17:26:49 -0700320 virtual status_t stopInput(audio_io_handle_t input,
321 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700322 {
323 Parcel data, reply;
324 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700325 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700326 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327 remote()->transact(STOP_INPUT, data, &reply);
328 return static_cast <status_t> (reply.readInt32());
329 }
330
Eric Laurent4dc68062014-07-28 17:26:49 -0700331 virtual void releaseInput(audio_io_handle_t input,
332 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 {
334 Parcel data, reply;
335 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700336 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700337 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 remote()->transact(RELEASE_INPUT, data, &reply);
339 }
340
Dima Zavinfce7a472011-04-19 22:30:36 -0700341 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 int indexMin,
343 int indexMax)
344 {
345 Parcel data, reply;
346 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
347 data.writeInt32(static_cast <uint32_t>(stream));
348 data.writeInt32(indexMin);
349 data.writeInt32(indexMax);
350 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
351 return static_cast <status_t> (reply.readInt32());
352 }
353
Eric Laurent83844cc2011-11-18 16:43:31 -0800354 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
355 int index,
356 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700357 {
358 Parcel data, reply;
359 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
360 data.writeInt32(static_cast <uint32_t>(stream));
361 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800362 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700363 remote()->transact(SET_STREAM_VOLUME, data, &reply);
364 return static_cast <status_t> (reply.readInt32());
365 }
366
Eric Laurent83844cc2011-11-18 16:43:31 -0800367 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
368 int *index,
369 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700370 {
371 Parcel data, reply;
372 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
373 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800374 data.writeInt32(static_cast <uint32_t>(device));
375
Eric Laurentc2f1f072009-07-17 12:17:14 -0700376 remote()->transact(GET_STREAM_VOLUME, data, &reply);
377 int lIndex = reply.readInt32();
378 if (index) *index = lIndex;
379 return static_cast <status_t> (reply.readInt32());
380 }
Eric Laurentde070132010-07-13 04:45:46 -0700381
Dima Zavinfce7a472011-04-19 22:30:36 -0700382 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
386 data.writeInt32(static_cast <uint32_t>(stream));
387 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
388 return reply.readInt32();
389 }
390
Eric Laurent63742522012-03-08 13:42:42 -0800391 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
395 data.writeInt32(static_cast <uint32_t>(stream));
396 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800397 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800398 }
399
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700400 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
404 data.write(desc, sizeof(effect_descriptor_t));
405 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
406 return static_cast <audio_io_handle_t> (reply.readInt32());
407 }
408
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700409 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700410 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700411 uint32_t strategy,
412 int session,
413 int id)
414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
417 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700418 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700419 data.writeInt32(strategy);
420 data.writeInt32(session);
421 data.writeInt32(id);
422 remote()->transact(REGISTER_EFFECT, data, &reply);
423 return static_cast <status_t> (reply.readInt32());
424 }
425
426 virtual status_t unregisterEffect(int id)
427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
430 data.writeInt32(id);
431 remote()->transact(UNREGISTER_EFFECT, data, &reply);
432 return static_cast <status_t> (reply.readInt32());
433 }
434
Eric Laurentdb7c0792011-08-10 10:37:50 -0700435 virtual status_t setEffectEnabled(int id, bool enabled)
436 {
437 Parcel data, reply;
438 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
439 data.writeInt32(id);
440 data.writeInt32(enabled);
441 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
442 return static_cast <status_t> (reply.readInt32());
443 }
444
Glenn Kastenfff6d712012-01-12 16:38:12 -0800445 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800446 {
447 Parcel data, reply;
448 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800449 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800450 data.writeInt32(inPastMs);
451 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
452 return reply.readInt32();
453 }
Eric Laurent57dae992011-07-24 13:36:09 -0700454
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800455 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
456 {
457 Parcel data, reply;
458 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
459 data.writeInt32((int32_t) stream);
460 data.writeInt32(inPastMs);
461 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
462 return reply.readInt32();
463 }
464
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700465 virtual bool isSourceActive(audio_source_t source) const
466 {
467 Parcel data, reply;
468 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
469 data.writeInt32((int32_t) source);
470 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
471 return reply.readInt32();
472 }
473
Eric Laurent57dae992011-07-24 13:36:09 -0700474 virtual status_t queryDefaultPreProcessing(int audioSession,
475 effect_descriptor_t *descriptors,
476 uint32_t *count)
477 {
478 if (descriptors == NULL || count == NULL) {
479 return BAD_VALUE;
480 }
481 Parcel data, reply;
482 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
483 data.writeInt32(audioSession);
484 data.writeInt32(*count);
485 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
486 if (status != NO_ERROR) {
487 return status;
488 }
489 status = static_cast <status_t> (reply.readInt32());
490 uint32_t retCount = reply.readInt32();
491 if (retCount != 0) {
492 uint32_t numDesc = (retCount < *count) ? retCount : *count;
493 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
494 }
495 *count = retCount;
496 return status;
497 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000498
499 virtual bool isOffloadSupported(const audio_offload_info_t& info)
500 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100501 Parcel data, reply;
502 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
503 data.write(&info, sizeof(audio_offload_info_t));
504 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700505 return reply.readInt32();
506 }
507
508 virtual status_t listAudioPorts(audio_port_role_t role,
509 audio_port_type_t type,
510 unsigned int *num_ports,
511 struct audio_port *ports,
512 unsigned int *generation)
513 {
514 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
515 generation == NULL) {
516 return BAD_VALUE;
517 }
518 Parcel data, reply;
519 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
520 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
521 data.writeInt32(role);
522 data.writeInt32(type);
523 data.writeInt32(numPortsReq);
524 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
525 if (status == NO_ERROR) {
526 status = (status_t)reply.readInt32();
527 *num_ports = (unsigned int)reply.readInt32();
528 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700529 if (status == NO_ERROR) {
530 if (numPortsReq > *num_ports) {
531 numPortsReq = *num_ports;
532 }
533 if (numPortsReq > 0) {
534 reply.read(ports, numPortsReq * sizeof(struct audio_port));
535 }
536 *generation = reply.readInt32();
537 }
538 return status;
539 }
540
541 virtual status_t getAudioPort(struct audio_port *port)
542 {
543 if (port == NULL) {
544 return BAD_VALUE;
545 }
546 Parcel data, reply;
547 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
548 data.write(port, sizeof(struct audio_port));
549 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
550 if (status != NO_ERROR ||
551 (status = (status_t)reply.readInt32()) != NO_ERROR) {
552 return status;
553 }
554 reply.read(port, sizeof(struct audio_port));
555 return status;
556 }
557
558 virtual status_t createAudioPatch(const struct audio_patch *patch,
559 audio_patch_handle_t *handle)
560 {
561 if (patch == NULL || handle == NULL) {
562 return BAD_VALUE;
563 }
564 Parcel data, reply;
565 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
566 data.write(patch, sizeof(struct audio_patch));
567 data.write(handle, sizeof(audio_patch_handle_t));
568 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
569 if (status != NO_ERROR ||
570 (status = (status_t)reply.readInt32()) != NO_ERROR) {
571 return status;
572 }
573 reply.read(handle, sizeof(audio_patch_handle_t));
574 return status;
575 }
576
577 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
578 {
579 Parcel data, reply;
580 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
581 data.write(&handle, sizeof(audio_patch_handle_t));
582 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
583 if (status != NO_ERROR) {
584 status = (status_t)reply.readInt32();
585 }
586 return status;
587 }
588
589 virtual status_t listAudioPatches(unsigned int *num_patches,
590 struct audio_patch *patches,
591 unsigned int *generation)
592 {
593 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
594 generation == NULL) {
595 return BAD_VALUE;
596 }
597 Parcel data, reply;
598 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
599 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
600 data.writeInt32(numPatchesReq);
601 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
602 if (status == NO_ERROR) {
603 status = (status_t)reply.readInt32();
604 *num_patches = (unsigned int)reply.readInt32();
605 }
606 if (status == NO_ERROR) {
607 if (numPatchesReq > *num_patches) {
608 numPatchesReq = *num_patches;
609 }
610 if (numPatchesReq > 0) {
611 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
612 }
613 *generation = reply.readInt32();
614 }
615 return status;
616 }
617
618 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
619 {
620 if (config == NULL) {
621 return BAD_VALUE;
622 }
623 Parcel data, reply;
624 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
625 data.write(config, sizeof(struct audio_port_config));
626 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
627 if (status != NO_ERROR) {
628 status = (status_t)reply.readInt32();
629 }
630 return status;
631 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700632
Eric Laurentb52c1522014-05-20 11:27:36 -0700633 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
634 {
635 Parcel data, reply;
636 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800637 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700638 remote()->transact(REGISTER_CLIENT, data, &reply);
639 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700640
641 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
642 audio_io_handle_t *ioHandle,
643 audio_devices_t *device)
644 {
645 if (session == NULL || ioHandle == NULL || device == NULL) {
646 return BAD_VALUE;
647 }
648 Parcel data, reply;
649 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
650 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
651 if (status != NO_ERROR) {
652 return status;
653 }
654 status = (status_t)reply.readInt32();
655 if (status == NO_ERROR) {
656 *session = (audio_session_t)reply.readInt32();
657 *ioHandle = (audio_io_handle_t)reply.readInt32();
658 *device = (audio_devices_t)reply.readInt32();
659 }
660 return status;
661 }
662
663 virtual status_t releaseSoundTriggerSession(audio_session_t session)
664 {
665 Parcel data, reply;
666 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
667 data.writeInt32(session);
668 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
669 if (status != NO_ERROR) {
670 return status;
671 }
672 return (status_t)reply.readInt32();
673 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700674
675 virtual audio_mode_t getPhoneState()
676 {
677 Parcel data, reply;
678 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
679 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
680 if (status != NO_ERROR) {
681 return AUDIO_MODE_INVALID;
682 }
683 return (audio_mode_t)reply.readInt32();
684 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800685
686 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
687 {
688 Parcel data, reply;
689 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
690 data.writeInt32(registration ? 1 : 0);
691 size_t size = mixes.size();
692 if (size > MAX_MIXES_PER_POLICY) {
693 size = MAX_MIXES_PER_POLICY;
694 }
695 size_t sizePosition = data.dataPosition();
696 data.writeInt32(size);
697 size_t finalSize = size;
698 for (size_t i = 0; i < size; i++) {
699 size_t position = data.dataPosition();
700 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
701 data.setDataPosition(position);
702 finalSize--;
703 }
704 }
705 if (size != finalSize) {
706 size_t position = data.dataPosition();
707 data.setDataPosition(sizePosition);
708 data.writeInt32(finalSize);
709 data.setDataPosition(position);
710 }
711 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
712 if (status == NO_ERROR) {
713 status = (status_t)reply.readInt32();
714 }
715 return status;
716 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700717};
718
719IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
720
721// ----------------------------------------------------------------------
722
723
724status_t BnAudioPolicyService::onTransact(
725 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
726{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700727 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700728 case SET_DEVICE_CONNECTION_STATE: {
729 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700730 audio_devices_t device =
731 static_cast <audio_devices_t>(data.readInt32());
732 audio_policy_dev_state_t state =
733 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700734 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800735 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700736 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
737 state,
Paul McLeane743a472015-01-28 11:07:31 -0800738 device_address,
739 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700740 return NO_ERROR;
741 } break;
742
743 case GET_DEVICE_CONNECTION_STATE: {
744 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700745 audio_devices_t device =
746 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700747 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700748 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
749 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700750 return NO_ERROR;
751 } break;
752
753 case SET_PHONE_STATE: {
754 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700755 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
756 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700757 return NO_ERROR;
758 } break;
759
Eric Laurentc2f1f072009-07-17 12:17:14 -0700760 case SET_FORCE_USE: {
761 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700762 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
763 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700764 audio_policy_forced_cfg_t config =
765 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700766 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
767 return NO_ERROR;
768 } break;
769
770 case GET_FORCE_USE: {
771 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700772 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
773 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700774 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
775 return NO_ERROR;
776 } break;
777
778 case GET_OUTPUT: {
779 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700780 audio_stream_type_t stream =
781 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700782 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800783 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700784 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700785 audio_output_flags_t flags =
786 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100787 bool hasOffloadInfo = data.readInt32() != 0;
788 audio_offload_info_t offloadInfo;
789 if (hasOffloadInfo) {
790 data.read(&offloadInfo, sizeof(audio_offload_info_t));
791 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700792 audio_io_handle_t output = getOutput(stream,
793 samplingRate,
794 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700795 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100796 flags,
797 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700798 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700799 return NO_ERROR;
800 } break;
801
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700802 case GET_OUTPUT_FOR_ATTR: {
803 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800804 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800805 bool hasAttributes = data.readInt32() != 0;
806 if (hasAttributes) {
807 data.read(&attr, sizeof(audio_attributes_t));
808 }
809 audio_session_t session = (audio_session_t)data.readInt32();
810 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
811 bool hasStream = data.readInt32() != 0;
812 if (hasStream) {
813 stream = (audio_stream_type_t)data.readInt32();
814 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700815 uint32_t samplingRate = data.readInt32();
816 audio_format_t format = (audio_format_t) data.readInt32();
817 audio_channel_mask_t channelMask = data.readInt32();
818 audio_output_flags_t flags =
819 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700820 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700821 bool hasOffloadInfo = data.readInt32() != 0;
822 audio_offload_info_t offloadInfo;
823 if (hasOffloadInfo) {
824 data.read(&offloadInfo, sizeof(audio_offload_info_t));
825 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800826 audio_io_handle_t output;
827 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
828 &output, session, &stream,
829 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700830 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800831 reply->writeInt32(status);
832 reply->writeInt32(output);
833 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700834 return NO_ERROR;
835 } break;
836
Eric Laurentc2f1f072009-07-17 12:17:14 -0700837 case START_OUTPUT: {
838 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700839 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800840 audio_stream_type_t stream =
841 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800842 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700843 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800844 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700845 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700846 return NO_ERROR;
847 } break;
848
849 case STOP_OUTPUT: {
850 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700851 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800852 audio_stream_type_t stream =
853 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800854 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700855 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800856 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700857 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700858 return NO_ERROR;
859 } break;
860
861 case RELEASE_OUTPUT: {
862 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700863 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800864 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
865 audio_session_t session = (audio_session_t)data.readInt32();
866 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700867 return NO_ERROR;
868 } break;
869
Eric Laurentcaf7f482014-11-25 17:50:47 -0800870 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700871 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800872 audio_attributes_t attr;
873 data.read(&attr, sizeof(audio_attributes_t));
874 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700875 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800876 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700877 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700878 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800879 audio_io_handle_t input;
880 status_t status = getInputForAttr(&attr, &input, session,
881 samplingRate, format, channelMask,
882 flags);
883 reply->writeInt32(status);
884 if (status == NO_ERROR) {
885 reply->writeInt32(input);
886 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700887 return NO_ERROR;
888 } break;
889
890 case START_INPUT: {
891 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700892 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700893 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
894 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700895 return NO_ERROR;
896 } break;
897
898 case STOP_INPUT: {
899 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700900 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700901 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
902 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700903 return NO_ERROR;
904 } break;
905
906 case RELEASE_INPUT: {
907 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700908 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700909 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
910 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700911 return NO_ERROR;
912 } break;
913
914 case INIT_STREAM_VOLUME: {
915 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700916 audio_stream_type_t stream =
917 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700918 int indexMin = data.readInt32();
919 int indexMax = data.readInt32();
920 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
921 return NO_ERROR;
922 } break;
923
924 case SET_STREAM_VOLUME: {
925 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700926 audio_stream_type_t stream =
927 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700928 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800929 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
930 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
931 index,
932 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700933 return NO_ERROR;
934 } break;
935
936 case GET_STREAM_VOLUME: {
937 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700938 audio_stream_type_t stream =
939 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800940 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700941 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800942 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700943 reply->writeInt32(index);
944 reply->writeInt32(static_cast <uint32_t>(status));
945 return NO_ERROR;
946 } break;
947
Eric Laurentde070132010-07-13 04:45:46 -0700948 case GET_STRATEGY_FOR_STREAM: {
949 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700950 audio_stream_type_t stream =
951 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700952 reply->writeInt32(getStrategyForStream(stream));
953 return NO_ERROR;
954 } break;
955
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800956 case GET_DEVICES_FOR_STREAM: {
957 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700958 audio_stream_type_t stream =
959 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800960 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
961 return NO_ERROR;
962 } break;
963
Eric Laurentde070132010-07-13 04:45:46 -0700964 case GET_OUTPUT_FOR_EFFECT: {
965 CHECK_INTERFACE(IAudioPolicyService, data, reply);
966 effect_descriptor_t desc;
967 data.read(&desc, sizeof(effect_descriptor_t));
968 audio_io_handle_t output = getOutputForEffect(&desc);
969 reply->writeInt32(static_cast <int>(output));
970 return NO_ERROR;
971 } break;
972
973 case REGISTER_EFFECT: {
974 CHECK_INTERFACE(IAudioPolicyService, data, reply);
975 effect_descriptor_t desc;
976 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700977 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700978 uint32_t strategy = data.readInt32();
979 int session = data.readInt32();
980 int id = data.readInt32();
981 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700982 io,
Eric Laurentde070132010-07-13 04:45:46 -0700983 strategy,
984 session,
985 id)));
986 return NO_ERROR;
987 } break;
988
989 case UNREGISTER_EFFECT: {
990 CHECK_INTERFACE(IAudioPolicyService, data, reply);
991 int id = data.readInt32();
992 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
993 return NO_ERROR;
994 } break;
995
Eric Laurentdb7c0792011-08-10 10:37:50 -0700996 case SET_EFFECT_ENABLED: {
997 CHECK_INTERFACE(IAudioPolicyService, data, reply);
998 int id = data.readInt32();
999 bool enabled = static_cast <bool>(data.readInt32());
1000 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1001 return NO_ERROR;
1002 } break;
1003
Eric Laurenteda6c362011-02-02 09:33:30 -08001004 case IS_STREAM_ACTIVE: {
1005 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001006 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001007 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001008 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001009 return NO_ERROR;
1010 } break;
1011
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001012 case IS_STREAM_ACTIVE_REMOTELY: {
1013 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1014 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1015 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001016 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001017 return NO_ERROR;
1018 } break;
1019
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001020 case IS_SOURCE_ACTIVE: {
1021 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1022 audio_source_t source = (audio_source_t) data.readInt32();
1023 reply->writeInt32( isSourceActive(source));
1024 return NO_ERROR;
1025 }
1026
Eric Laurent57dae992011-07-24 13:36:09 -07001027 case QUERY_DEFAULT_PRE_PROCESSING: {
1028 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1029 int audioSession = data.readInt32();
1030 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001031 if (count > AudioEffect::kMaxPreProcessing) {
1032 count = AudioEffect::kMaxPreProcessing;
1033 }
Eric Laurent57dae992011-07-24 13:36:09 -07001034 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001035 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001036 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1037 reply->writeInt32(status);
1038 if (status != NO_ERROR && status != NO_MEMORY) {
1039 retCount = 0;
1040 }
1041 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001042 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001043 if (retCount < count) {
1044 count = retCount;
1045 }
1046 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1047 }
1048 delete[] descriptors;
1049 return status;
1050 }
1051
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001052 case IS_OFFLOAD_SUPPORTED: {
1053 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1054 audio_offload_info_t info;
1055 data.read(&info, sizeof(audio_offload_info_t));
1056 bool isSupported = isOffloadSupported(info);
1057 reply->writeInt32(isSupported);
1058 return NO_ERROR;
1059 }
1060
Eric Laurent203b1a12014-04-01 10:34:16 -07001061 case LIST_AUDIO_PORTS: {
1062 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1063 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1064 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1065 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001066 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1067 numPortsReq = MAX_ITEMS_PER_LIST;
1068 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001069 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001070 struct audio_port *ports =
1071 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001072 if (ports == NULL) {
1073 reply->writeInt32(NO_MEMORY);
1074 reply->writeInt32(0);
1075 return NO_ERROR;
1076 }
1077 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001078 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1079 reply->writeInt32(status);
1080 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001081
1082 if (status == NO_ERROR) {
1083 if (numPortsReq > numPorts) {
1084 numPortsReq = numPorts;
1085 }
1086 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1087 reply->writeInt32(generation);
1088 }
1089 free(ports);
1090 return NO_ERROR;
1091 }
1092
1093 case GET_AUDIO_PORT: {
1094 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1095 struct audio_port port;
1096 data.read(&port, sizeof(struct audio_port));
1097 status_t status = getAudioPort(&port);
1098 reply->writeInt32(status);
1099 if (status == NO_ERROR) {
1100 reply->write(&port, sizeof(struct audio_port));
1101 }
1102 return NO_ERROR;
1103 }
1104
1105 case CREATE_AUDIO_PATCH: {
1106 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1107 struct audio_patch patch;
1108 data.read(&patch, sizeof(struct audio_patch));
1109 audio_patch_handle_t handle;
1110 data.read(&handle, sizeof(audio_patch_handle_t));
1111 status_t status = createAudioPatch(&patch, &handle);
1112 reply->writeInt32(status);
1113 if (status == NO_ERROR) {
1114 reply->write(&handle, sizeof(audio_patch_handle_t));
1115 }
1116 return NO_ERROR;
1117 }
1118
1119 case RELEASE_AUDIO_PATCH: {
1120 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1121 audio_patch_handle_t handle;
1122 data.read(&handle, sizeof(audio_patch_handle_t));
1123 status_t status = releaseAudioPatch(handle);
1124 reply->writeInt32(status);
1125 return NO_ERROR;
1126 }
1127
1128 case LIST_AUDIO_PATCHES: {
1129 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1130 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001131 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1132 numPatchesReq = MAX_ITEMS_PER_LIST;
1133 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001134 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001135 struct audio_patch *patches =
1136 (struct audio_patch *)calloc(numPatchesReq,
1137 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001138 if (patches == NULL) {
1139 reply->writeInt32(NO_MEMORY);
1140 reply->writeInt32(0);
1141 return NO_ERROR;
1142 }
1143 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001144 status_t status = listAudioPatches(&numPatches, patches, &generation);
1145 reply->writeInt32(status);
1146 reply->writeInt32(numPatches);
1147 if (status == NO_ERROR) {
1148 if (numPatchesReq > numPatches) {
1149 numPatchesReq = numPatches;
1150 }
1151 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1152 reply->writeInt32(generation);
1153 }
1154 free(patches);
1155 return NO_ERROR;
1156 }
1157
1158 case SET_AUDIO_PORT_CONFIG: {
1159 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1160 struct audio_port_config config;
1161 data.read(&config, sizeof(struct audio_port_config));
1162 status_t status = setAudioPortConfig(&config);
1163 reply->writeInt32(status);
1164 return NO_ERROR;
1165 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001166
Eric Laurentb52c1522014-05-20 11:27:36 -07001167 case REGISTER_CLIENT: {
1168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1169 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1170 data.readStrongBinder());
1171 registerClient(client);
1172 return NO_ERROR;
1173 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001174
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001175 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1176 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1177 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1178 data.readStrongBinder());
1179 audio_session_t session;
1180 audio_io_handle_t ioHandle;
1181 audio_devices_t device;
1182 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1183 reply->writeInt32(status);
1184 if (status == NO_ERROR) {
1185 reply->writeInt32(session);
1186 reply->writeInt32(ioHandle);
1187 reply->writeInt32(device);
1188 }
1189 return NO_ERROR;
1190 } break;
1191
1192 case RELEASE_SOUNDTRIGGER_SESSION: {
1193 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1194 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1195 data.readStrongBinder());
1196 audio_session_t session = (audio_session_t)data.readInt32();
1197 status_t status = releaseSoundTriggerSession(session);
1198 reply->writeInt32(status);
1199 return NO_ERROR;
1200 } break;
1201
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001202 case GET_PHONE_STATE: {
1203 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1204 reply->writeInt32((int32_t)getPhoneState());
1205 return NO_ERROR;
1206 } break;
1207
Eric Laurentbaac1832014-12-01 17:52:59 -08001208 case REGISTER_POLICY_MIXES: {
1209 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1210 bool registration = data.readInt32() == 1;
1211 Vector<AudioMix> mixes;
1212 size_t size = (size_t)data.readInt32();
1213 if (size > MAX_MIXES_PER_POLICY) {
1214 size = MAX_MIXES_PER_POLICY;
1215 }
1216 for (size_t i = 0; i < size; i++) {
1217 AudioMix mix;
1218 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1219 mixes.add(mix);
1220 }
1221 }
1222 status_t status = registerPolicyMixes(mixes, registration);
1223 reply->writeInt32(status);
1224 return NO_ERROR;
1225 } break;
1226
Eric Laurentc2f1f072009-07-17 12:17:14 -07001227 default:
1228 return BBinder::onTransact(code, data, reply, flags);
1229 }
1230}
1231
1232// ----------------------------------------------------------------------------
1233
Glenn Kasten40bc9062015-03-20 09:09:33 -07001234} // namespace android