blob: 70551c4033d528c2c875265995c23f24261d3623 [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,
Eric Laurentc2f1f072009-07-17 12:17:14 -070087 const char *device_address)
88 {
89 Parcel data, reply;
90 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
91 data.writeInt32(static_cast <uint32_t>(device));
92 data.writeInt32(static_cast <uint32_t>(state));
93 data.writeCString(device_address);
94 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
95 return static_cast <status_t> (reply.readInt32());
96 }
97
Dima Zavinfce7a472011-04-19 22:30:36 -070098 virtual audio_policy_dev_state_t getDeviceConnectionState(
99 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100 const char *device_address)
101 {
102 Parcel data, reply;
103 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
104 data.writeInt32(static_cast <uint32_t>(device));
105 data.writeCString(device_address);
106 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700107 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700108 }
109
Glenn Kastenf78aee72012-01-04 11:00:47 -0800110 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700111 {
112 Parcel data, reply;
113 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
114 data.writeInt32(state);
115 remote()->transact(SET_PHONE_STATE, data, &reply);
116 return static_cast <status_t> (reply.readInt32());
117 }
118
Dima Zavinfce7a472011-04-19 22:30:36 -0700119 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700120 {
121 Parcel data, reply;
122 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
123 data.writeInt32(static_cast <uint32_t>(usage));
124 data.writeInt32(static_cast <uint32_t>(config));
125 remote()->transact(SET_FORCE_USE, data, &reply);
126 return static_cast <status_t> (reply.readInt32());
127 }
128
Dima Zavinfce7a472011-04-19 22:30:36 -0700129 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 {
131 Parcel data, reply;
132 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
133 data.writeInt32(static_cast <uint32_t>(usage));
134 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700136 }
137
138 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700140 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800141 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700142 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000143 audio_output_flags_t flags,
144 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 {
146 Parcel data, reply;
147 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
148 data.writeInt32(static_cast <uint32_t>(stream));
149 data.writeInt32(samplingRate);
150 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700151 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700152 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800153 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100154 if (offloadInfo == NULL) {
155 data.writeInt32(0);
156 } else {
157 data.writeInt32(1);
158 data.write(offloadInfo, sizeof(audio_offload_info_t));
159 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700160 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700161 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700162 }
163
Eric Laurente83b55d2014-11-14 10:06:21 -0800164 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
165 audio_io_handle_t *output,
166 audio_session_t session,
167 audio_stream_type_t *stream,
168 uint32_t samplingRate,
169 audio_format_t format,
170 audio_channel_mask_t channelMask,
171 audio_output_flags_t flags,
172 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700173 {
174 Parcel data, reply;
175 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
176 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800177 if (stream == NULL) {
178 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
179 return BAD_VALUE;
180 }
181 if (*stream == AUDIO_STREAM_DEFAULT) {
182 ALOGE("getOutputForAttr unspecified stream type");
183 return BAD_VALUE;
184 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700185 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800186 if (output == NULL) {
187 ALOGE("getOutputForAttr NULL output - shouldn't happen");
188 return BAD_VALUE;
189 }
190 if (attr == NULL) {
191 data.writeInt32(0);
192 } else {
193 data.writeInt32(1);
194 data.write(attr, sizeof(audio_attributes_t));
195 }
196 data.writeInt32(session);
197 if (stream == NULL) {
198 data.writeInt32(0);
199 } else {
200 data.writeInt32(1);
201 data.writeInt32(*stream);
202 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700203 data.writeInt32(samplingRate);
204 data.writeInt32(static_cast <uint32_t>(format));
205 data.writeInt32(channelMask);
206 data.writeInt32(static_cast <uint32_t>(flags));
207 // hasOffloadInfo
208 if (offloadInfo == NULL) {
209 data.writeInt32(0);
210 } else {
211 data.writeInt32(1);
212 data.write(offloadInfo, sizeof(audio_offload_info_t));
213 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800214 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
215 if (status != NO_ERROR) {
216 return status;
217 }
218 status = (status_t)reply.readInt32();
219 if (status != NO_ERROR) {
220 return status;
221 }
222 *output = (audio_io_handle_t)reply.readInt32();
223 if (stream != NULL) {
224 *stream = (audio_stream_type_t)reply.readInt32();
225 }
226 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700227 }
228
Eric Laurentde070132010-07-13 04:45:46 -0700229 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700230 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800231 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700232 {
233 Parcel data, reply;
234 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700235 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800236 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800237 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700238 remote()->transact(START_OUTPUT, data, &reply);
239 return static_cast <status_t> (reply.readInt32());
240 }
241
Eric Laurentde070132010-07-13 04:45:46 -0700242 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700243 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800244 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700248 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800249 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800250 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 remote()->transact(STOP_OUTPUT, data, &reply);
252 return static_cast <status_t> (reply.readInt32());
253 }
254
Eric Laurente83b55d2014-11-14 10:06:21 -0800255 virtual void releaseOutput(audio_io_handle_t output,
256 audio_stream_type_t stream,
257 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700261 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800262 data.writeInt32((int32_t)stream);
263 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 remote()->transact(RELEASE_OUTPUT, data, &reply);
265 }
266
Eric Laurentcaf7f482014-11-25 17:50:47 -0800267 virtual status_t getInputForAttr(const audio_attributes_t *attr,
268 audio_io_handle_t *input,
269 audio_session_t session,
270 uint32_t samplingRate,
271 audio_format_t format,
272 audio_channel_mask_t channelMask,
273 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800277 if (attr == NULL) {
278 ALOGE("getInputForAttr NULL attr - shouldn't happen");
279 return BAD_VALUE;
280 }
281 if (input == NULL) {
282 ALOGE("getInputForAttr NULL input - shouldn't happen");
283 return BAD_VALUE;
284 }
285 data.write(attr, sizeof(audio_attributes_t));
286 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700287 data.writeInt32(samplingRate);
288 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700289 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700290 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800291 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
292 if (status != NO_ERROR) {
293 return status;
294 }
295 status = reply.readInt32();
296 if (status != NO_ERROR) {
297 return status;
298 }
299 *input = (audio_io_handle_t)reply.readInt32();
300 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700301 }
302
Eric Laurent4dc68062014-07-28 17:26:49 -0700303 virtual status_t startInput(audio_io_handle_t input,
304 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700305 {
306 Parcel data, reply;
307 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700308 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700309 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700310 remote()->transact(START_INPUT, data, &reply);
311 return static_cast <status_t> (reply.readInt32());
312 }
313
Eric Laurent4dc68062014-07-28 17:26:49 -0700314 virtual status_t stopInput(audio_io_handle_t input,
315 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700319 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700320 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700321 remote()->transact(STOP_INPUT, data, &reply);
322 return static_cast <status_t> (reply.readInt32());
323 }
324
Eric Laurent4dc68062014-07-28 17:26:49 -0700325 virtual void releaseInput(audio_io_handle_t input,
326 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327 {
328 Parcel data, reply;
329 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700330 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700331 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700332 remote()->transact(RELEASE_INPUT, data, &reply);
333 }
334
Dima Zavinfce7a472011-04-19 22:30:36 -0700335 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700336 int indexMin,
337 int indexMax)
338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
341 data.writeInt32(static_cast <uint32_t>(stream));
342 data.writeInt32(indexMin);
343 data.writeInt32(indexMax);
344 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
345 return static_cast <status_t> (reply.readInt32());
346 }
347
Eric Laurent83844cc2011-11-18 16:43:31 -0800348 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
349 int index,
350 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 {
352 Parcel data, reply;
353 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
354 data.writeInt32(static_cast <uint32_t>(stream));
355 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800356 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700357 remote()->transact(SET_STREAM_VOLUME, data, &reply);
358 return static_cast <status_t> (reply.readInt32());
359 }
360
Eric Laurent83844cc2011-11-18 16:43:31 -0800361 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
362 int *index,
363 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
367 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800368 data.writeInt32(static_cast <uint32_t>(device));
369
Eric Laurentc2f1f072009-07-17 12:17:14 -0700370 remote()->transact(GET_STREAM_VOLUME, data, &reply);
371 int lIndex = reply.readInt32();
372 if (index) *index = lIndex;
373 return static_cast <status_t> (reply.readInt32());
374 }
Eric Laurentde070132010-07-13 04:45:46 -0700375
Dima Zavinfce7a472011-04-19 22:30:36 -0700376 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700377 {
378 Parcel data, reply;
379 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
380 data.writeInt32(static_cast <uint32_t>(stream));
381 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
382 return reply.readInt32();
383 }
384
Eric Laurent63742522012-03-08 13:42:42 -0800385 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800386 {
387 Parcel data, reply;
388 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
389 data.writeInt32(static_cast <uint32_t>(stream));
390 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800391 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800392 }
393
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700394 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700395 {
396 Parcel data, reply;
397 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
398 data.write(desc, sizeof(effect_descriptor_t));
399 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
400 return static_cast <audio_io_handle_t> (reply.readInt32());
401 }
402
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700403 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700404 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700405 uint32_t strategy,
406 int session,
407 int id)
408 {
409 Parcel data, reply;
410 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
411 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700412 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700413 data.writeInt32(strategy);
414 data.writeInt32(session);
415 data.writeInt32(id);
416 remote()->transact(REGISTER_EFFECT, data, &reply);
417 return static_cast <status_t> (reply.readInt32());
418 }
419
420 virtual status_t unregisterEffect(int id)
421 {
422 Parcel data, reply;
423 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
424 data.writeInt32(id);
425 remote()->transact(UNREGISTER_EFFECT, data, &reply);
426 return static_cast <status_t> (reply.readInt32());
427 }
428
Eric Laurentdb7c0792011-08-10 10:37:50 -0700429 virtual status_t setEffectEnabled(int id, bool enabled)
430 {
431 Parcel data, reply;
432 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
433 data.writeInt32(id);
434 data.writeInt32(enabled);
435 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
436 return static_cast <status_t> (reply.readInt32());
437 }
438
Glenn Kastenfff6d712012-01-12 16:38:12 -0800439 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800443 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800444 data.writeInt32(inPastMs);
445 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
446 return reply.readInt32();
447 }
Eric Laurent57dae992011-07-24 13:36:09 -0700448
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800449 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
450 {
451 Parcel data, reply;
452 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
453 data.writeInt32((int32_t) stream);
454 data.writeInt32(inPastMs);
455 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
456 return reply.readInt32();
457 }
458
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700459 virtual bool isSourceActive(audio_source_t source) const
460 {
461 Parcel data, reply;
462 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
463 data.writeInt32((int32_t) source);
464 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
465 return reply.readInt32();
466 }
467
Eric Laurent57dae992011-07-24 13:36:09 -0700468 virtual status_t queryDefaultPreProcessing(int audioSession,
469 effect_descriptor_t *descriptors,
470 uint32_t *count)
471 {
472 if (descriptors == NULL || count == NULL) {
473 return BAD_VALUE;
474 }
475 Parcel data, reply;
476 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
477 data.writeInt32(audioSession);
478 data.writeInt32(*count);
479 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
480 if (status != NO_ERROR) {
481 return status;
482 }
483 status = static_cast <status_t> (reply.readInt32());
484 uint32_t retCount = reply.readInt32();
485 if (retCount != 0) {
486 uint32_t numDesc = (retCount < *count) ? retCount : *count;
487 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
488 }
489 *count = retCount;
490 return status;
491 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000492
493 virtual bool isOffloadSupported(const audio_offload_info_t& info)
494 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
497 data.write(&info, sizeof(audio_offload_info_t));
498 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700499 return reply.readInt32();
500 }
501
502 virtual status_t listAudioPorts(audio_port_role_t role,
503 audio_port_type_t type,
504 unsigned int *num_ports,
505 struct audio_port *ports,
506 unsigned int *generation)
507 {
508 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
509 generation == NULL) {
510 return BAD_VALUE;
511 }
512 Parcel data, reply;
513 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
514 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
515 data.writeInt32(role);
516 data.writeInt32(type);
517 data.writeInt32(numPortsReq);
518 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
519 if (status == NO_ERROR) {
520 status = (status_t)reply.readInt32();
521 *num_ports = (unsigned int)reply.readInt32();
522 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700523 if (status == NO_ERROR) {
524 if (numPortsReq > *num_ports) {
525 numPortsReq = *num_ports;
526 }
527 if (numPortsReq > 0) {
528 reply.read(ports, numPortsReq * sizeof(struct audio_port));
529 }
530 *generation = reply.readInt32();
531 }
532 return status;
533 }
534
535 virtual status_t getAudioPort(struct audio_port *port)
536 {
537 if (port == NULL) {
538 return BAD_VALUE;
539 }
540 Parcel data, reply;
541 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
542 data.write(port, sizeof(struct audio_port));
543 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
544 if (status != NO_ERROR ||
545 (status = (status_t)reply.readInt32()) != NO_ERROR) {
546 return status;
547 }
548 reply.read(port, sizeof(struct audio_port));
549 return status;
550 }
551
552 virtual status_t createAudioPatch(const struct audio_patch *patch,
553 audio_patch_handle_t *handle)
554 {
555 if (patch == NULL || handle == NULL) {
556 return BAD_VALUE;
557 }
558 Parcel data, reply;
559 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
560 data.write(patch, sizeof(struct audio_patch));
561 data.write(handle, sizeof(audio_patch_handle_t));
562 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
563 if (status != NO_ERROR ||
564 (status = (status_t)reply.readInt32()) != NO_ERROR) {
565 return status;
566 }
567 reply.read(handle, sizeof(audio_patch_handle_t));
568 return status;
569 }
570
571 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
572 {
573 Parcel data, reply;
574 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
575 data.write(&handle, sizeof(audio_patch_handle_t));
576 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
577 if (status != NO_ERROR) {
578 status = (status_t)reply.readInt32();
579 }
580 return status;
581 }
582
583 virtual status_t listAudioPatches(unsigned int *num_patches,
584 struct audio_patch *patches,
585 unsigned int *generation)
586 {
587 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
588 generation == NULL) {
589 return BAD_VALUE;
590 }
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
593 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
594 data.writeInt32(numPatchesReq);
595 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
596 if (status == NO_ERROR) {
597 status = (status_t)reply.readInt32();
598 *num_patches = (unsigned int)reply.readInt32();
599 }
600 if (status == NO_ERROR) {
601 if (numPatchesReq > *num_patches) {
602 numPatchesReq = *num_patches;
603 }
604 if (numPatchesReq > 0) {
605 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
606 }
607 *generation = reply.readInt32();
608 }
609 return status;
610 }
611
612 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
613 {
614 if (config == NULL) {
615 return BAD_VALUE;
616 }
617 Parcel data, reply;
618 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
619 data.write(config, sizeof(struct audio_port_config));
620 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
621 if (status != NO_ERROR) {
622 status = (status_t)reply.readInt32();
623 }
624 return status;
625 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700626
Eric Laurentb52c1522014-05-20 11:27:36 -0700627 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
628 {
629 Parcel data, reply;
630 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
631 data.writeStrongBinder(client->asBinder());
632 remote()->transact(REGISTER_CLIENT, data, &reply);
633 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700634
635 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
636 audio_io_handle_t *ioHandle,
637 audio_devices_t *device)
638 {
639 if (session == NULL || ioHandle == NULL || device == NULL) {
640 return BAD_VALUE;
641 }
642 Parcel data, reply;
643 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
644 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
645 if (status != NO_ERROR) {
646 return status;
647 }
648 status = (status_t)reply.readInt32();
649 if (status == NO_ERROR) {
650 *session = (audio_session_t)reply.readInt32();
651 *ioHandle = (audio_io_handle_t)reply.readInt32();
652 *device = (audio_devices_t)reply.readInt32();
653 }
654 return status;
655 }
656
657 virtual status_t releaseSoundTriggerSession(audio_session_t session)
658 {
659 Parcel data, reply;
660 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
661 data.writeInt32(session);
662 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
663 if (status != NO_ERROR) {
664 return status;
665 }
666 return (status_t)reply.readInt32();
667 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700668
669 virtual audio_mode_t getPhoneState()
670 {
671 Parcel data, reply;
672 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
673 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
674 if (status != NO_ERROR) {
675 return AUDIO_MODE_INVALID;
676 }
677 return (audio_mode_t)reply.readInt32();
678 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800679
680 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
681 {
682 Parcel data, reply;
683 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
684 data.writeInt32(registration ? 1 : 0);
685 size_t size = mixes.size();
686 if (size > MAX_MIXES_PER_POLICY) {
687 size = MAX_MIXES_PER_POLICY;
688 }
689 size_t sizePosition = data.dataPosition();
690 data.writeInt32(size);
691 size_t finalSize = size;
692 for (size_t i = 0; i < size; i++) {
693 size_t position = data.dataPosition();
694 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
695 data.setDataPosition(position);
696 finalSize--;
697 }
698 }
699 if (size != finalSize) {
700 size_t position = data.dataPosition();
701 data.setDataPosition(sizePosition);
702 data.writeInt32(finalSize);
703 data.setDataPosition(position);
704 }
705 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
706 if (status == NO_ERROR) {
707 status = (status_t)reply.readInt32();
708 }
709 return status;
710 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700711};
712
713IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
714
715// ----------------------------------------------------------------------
716
717
718status_t BnAudioPolicyService::onTransact(
719 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
720{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700721 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700722 case SET_DEVICE_CONNECTION_STATE: {
723 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700724 audio_devices_t device =
725 static_cast <audio_devices_t>(data.readInt32());
726 audio_policy_dev_state_t state =
727 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700728 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700729 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
730 state,
731 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700732 return NO_ERROR;
733 } break;
734
735 case GET_DEVICE_CONNECTION_STATE: {
736 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700737 audio_devices_t device =
738 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700739 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700740 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
741 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700742 return NO_ERROR;
743 } break;
744
745 case SET_PHONE_STATE: {
746 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700747 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
748 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700749 return NO_ERROR;
750 } break;
751
Eric Laurentc2f1f072009-07-17 12:17:14 -0700752 case SET_FORCE_USE: {
753 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700754 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
755 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700756 audio_policy_forced_cfg_t config =
757 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700758 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
759 return NO_ERROR;
760 } break;
761
762 case GET_FORCE_USE: {
763 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700764 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
765 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700766 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
767 return NO_ERROR;
768 } break;
769
770 case GET_OUTPUT: {
771 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700772 audio_stream_type_t stream =
773 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700774 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800775 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700776 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700777 audio_output_flags_t flags =
778 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100779 bool hasOffloadInfo = data.readInt32() != 0;
780 audio_offload_info_t offloadInfo;
781 if (hasOffloadInfo) {
782 data.read(&offloadInfo, sizeof(audio_offload_info_t));
783 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700784 audio_io_handle_t output = getOutput(stream,
785 samplingRate,
786 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700787 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100788 flags,
789 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700790 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700791 return NO_ERROR;
792 } break;
793
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700794 case GET_OUTPUT_FOR_ATTR: {
795 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800796 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800797 bool hasAttributes = data.readInt32() != 0;
798 if (hasAttributes) {
799 data.read(&attr, sizeof(audio_attributes_t));
800 }
801 audio_session_t session = (audio_session_t)data.readInt32();
802 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
803 bool hasStream = data.readInt32() != 0;
804 if (hasStream) {
805 stream = (audio_stream_type_t)data.readInt32();
806 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700807 uint32_t samplingRate = data.readInt32();
808 audio_format_t format = (audio_format_t) data.readInt32();
809 audio_channel_mask_t channelMask = data.readInt32();
810 audio_output_flags_t flags =
811 static_cast <audio_output_flags_t>(data.readInt32());
812 bool hasOffloadInfo = data.readInt32() != 0;
813 audio_offload_info_t offloadInfo;
814 if (hasOffloadInfo) {
815 data.read(&offloadInfo, sizeof(audio_offload_info_t));
816 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800817 audio_io_handle_t output;
818 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
819 &output, session, &stream,
820 samplingRate, format, channelMask,
821 flags, hasOffloadInfo ? &offloadInfo : NULL);
822 reply->writeInt32(status);
823 reply->writeInt32(output);
824 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700825 return NO_ERROR;
826 } break;
827
Eric Laurentc2f1f072009-07-17 12:17:14 -0700828 case START_OUTPUT: {
829 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700830 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800831 audio_stream_type_t stream =
832 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800833 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700834 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800835 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700836 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700837 return NO_ERROR;
838 } break;
839
840 case STOP_OUTPUT: {
841 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700842 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800843 audio_stream_type_t stream =
844 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800845 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700846 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800847 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700848 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700849 return NO_ERROR;
850 } break;
851
852 case RELEASE_OUTPUT: {
853 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700854 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800855 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
856 audio_session_t session = (audio_session_t)data.readInt32();
857 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700858 return NO_ERROR;
859 } break;
860
Eric Laurentcaf7f482014-11-25 17:50:47 -0800861 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800863 audio_attributes_t attr;
864 data.read(&attr, sizeof(audio_attributes_t));
865 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700866 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800867 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700868 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700869 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800870 audio_io_handle_t input;
871 status_t status = getInputForAttr(&attr, &input, session,
872 samplingRate, format, channelMask,
873 flags);
874 reply->writeInt32(status);
875 if (status == NO_ERROR) {
876 reply->writeInt32(input);
877 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700878 return NO_ERROR;
879 } break;
880
881 case START_INPUT: {
882 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700883 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700884 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
885 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700886 return NO_ERROR;
887 } break;
888
889 case STOP_INPUT: {
890 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700891 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700892 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
893 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700894 return NO_ERROR;
895 } break;
896
897 case RELEASE_INPUT: {
898 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700899 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700900 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
901 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700902 return NO_ERROR;
903 } break;
904
905 case INIT_STREAM_VOLUME: {
906 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700907 audio_stream_type_t stream =
908 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700909 int indexMin = data.readInt32();
910 int indexMax = data.readInt32();
911 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
912 return NO_ERROR;
913 } break;
914
915 case SET_STREAM_VOLUME: {
916 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700917 audio_stream_type_t stream =
918 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700919 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800920 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
921 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
922 index,
923 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700924 return NO_ERROR;
925 } break;
926
927 case GET_STREAM_VOLUME: {
928 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700929 audio_stream_type_t stream =
930 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800931 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700932 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800933 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700934 reply->writeInt32(index);
935 reply->writeInt32(static_cast <uint32_t>(status));
936 return NO_ERROR;
937 } break;
938
Eric Laurentde070132010-07-13 04:45:46 -0700939 case GET_STRATEGY_FOR_STREAM: {
940 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700941 audio_stream_type_t stream =
942 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700943 reply->writeInt32(getStrategyForStream(stream));
944 return NO_ERROR;
945 } break;
946
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800947 case GET_DEVICES_FOR_STREAM: {
948 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700949 audio_stream_type_t stream =
950 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800951 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
952 return NO_ERROR;
953 } break;
954
Eric Laurentde070132010-07-13 04:45:46 -0700955 case GET_OUTPUT_FOR_EFFECT: {
956 CHECK_INTERFACE(IAudioPolicyService, data, reply);
957 effect_descriptor_t desc;
958 data.read(&desc, sizeof(effect_descriptor_t));
959 audio_io_handle_t output = getOutputForEffect(&desc);
960 reply->writeInt32(static_cast <int>(output));
961 return NO_ERROR;
962 } break;
963
964 case REGISTER_EFFECT: {
965 CHECK_INTERFACE(IAudioPolicyService, data, reply);
966 effect_descriptor_t desc;
967 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700968 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700969 uint32_t strategy = data.readInt32();
970 int session = data.readInt32();
971 int id = data.readInt32();
972 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700973 io,
Eric Laurentde070132010-07-13 04:45:46 -0700974 strategy,
975 session,
976 id)));
977 return NO_ERROR;
978 } break;
979
980 case UNREGISTER_EFFECT: {
981 CHECK_INTERFACE(IAudioPolicyService, data, reply);
982 int id = data.readInt32();
983 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
984 return NO_ERROR;
985 } break;
986
Eric Laurentdb7c0792011-08-10 10:37:50 -0700987 case SET_EFFECT_ENABLED: {
988 CHECK_INTERFACE(IAudioPolicyService, data, reply);
989 int id = data.readInt32();
990 bool enabled = static_cast <bool>(data.readInt32());
991 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
992 return NO_ERROR;
993 } break;
994
Eric Laurenteda6c362011-02-02 09:33:30 -0800995 case IS_STREAM_ACTIVE: {
996 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800997 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -0800998 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800999 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001000 return NO_ERROR;
1001 } break;
1002
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001003 case IS_STREAM_ACTIVE_REMOTELY: {
1004 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1005 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1006 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001007 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001008 return NO_ERROR;
1009 } break;
1010
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001011 case IS_SOURCE_ACTIVE: {
1012 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1013 audio_source_t source = (audio_source_t) data.readInt32();
1014 reply->writeInt32( isSourceActive(source));
1015 return NO_ERROR;
1016 }
1017
Eric Laurent57dae992011-07-24 13:36:09 -07001018 case QUERY_DEFAULT_PRE_PROCESSING: {
1019 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1020 int audioSession = data.readInt32();
1021 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001022 if (count > AudioEffect::kMaxPreProcessing) {
1023 count = AudioEffect::kMaxPreProcessing;
1024 }
Eric Laurent57dae992011-07-24 13:36:09 -07001025 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001026 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001027 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1028 reply->writeInt32(status);
1029 if (status != NO_ERROR && status != NO_MEMORY) {
1030 retCount = 0;
1031 }
1032 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001033 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001034 if (retCount < count) {
1035 count = retCount;
1036 }
1037 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1038 }
1039 delete[] descriptors;
1040 return status;
1041 }
1042
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001043 case IS_OFFLOAD_SUPPORTED: {
1044 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1045 audio_offload_info_t info;
1046 data.read(&info, sizeof(audio_offload_info_t));
1047 bool isSupported = isOffloadSupported(info);
1048 reply->writeInt32(isSupported);
1049 return NO_ERROR;
1050 }
1051
Eric Laurent203b1a12014-04-01 10:34:16 -07001052 case LIST_AUDIO_PORTS: {
1053 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1054 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1055 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1056 unsigned int numPortsReq = data.readInt32();
1057 unsigned int numPorts = numPortsReq;
1058 unsigned int generation;
1059 struct audio_port *ports =
1060 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
1061 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1062 reply->writeInt32(status);
1063 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001064
1065 if (status == NO_ERROR) {
1066 if (numPortsReq > numPorts) {
1067 numPortsReq = numPorts;
1068 }
1069 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1070 reply->writeInt32(generation);
1071 }
1072 free(ports);
1073 return NO_ERROR;
1074 }
1075
1076 case GET_AUDIO_PORT: {
1077 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1078 struct audio_port port;
1079 data.read(&port, sizeof(struct audio_port));
1080 status_t status = getAudioPort(&port);
1081 reply->writeInt32(status);
1082 if (status == NO_ERROR) {
1083 reply->write(&port, sizeof(struct audio_port));
1084 }
1085 return NO_ERROR;
1086 }
1087
1088 case CREATE_AUDIO_PATCH: {
1089 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1090 struct audio_patch patch;
1091 data.read(&patch, sizeof(struct audio_patch));
1092 audio_patch_handle_t handle;
1093 data.read(&handle, sizeof(audio_patch_handle_t));
1094 status_t status = createAudioPatch(&patch, &handle);
1095 reply->writeInt32(status);
1096 if (status == NO_ERROR) {
1097 reply->write(&handle, sizeof(audio_patch_handle_t));
1098 }
1099 return NO_ERROR;
1100 }
1101
1102 case RELEASE_AUDIO_PATCH: {
1103 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1104 audio_patch_handle_t handle;
1105 data.read(&handle, sizeof(audio_patch_handle_t));
1106 status_t status = releaseAudioPatch(handle);
1107 reply->writeInt32(status);
1108 return NO_ERROR;
1109 }
1110
1111 case LIST_AUDIO_PATCHES: {
1112 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1113 unsigned int numPatchesReq = data.readInt32();
1114 unsigned int numPatches = numPatchesReq;
1115 unsigned int generation;
1116 struct audio_patch *patches =
1117 (struct audio_patch *)calloc(numPatchesReq,
1118 sizeof(struct audio_patch));
1119 status_t status = listAudioPatches(&numPatches, patches, &generation);
1120 reply->writeInt32(status);
1121 reply->writeInt32(numPatches);
1122 if (status == NO_ERROR) {
1123 if (numPatchesReq > numPatches) {
1124 numPatchesReq = numPatches;
1125 }
1126 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1127 reply->writeInt32(generation);
1128 }
1129 free(patches);
1130 return NO_ERROR;
1131 }
1132
1133 case SET_AUDIO_PORT_CONFIG: {
1134 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1135 struct audio_port_config config;
1136 data.read(&config, sizeof(struct audio_port_config));
1137 status_t status = setAudioPortConfig(&config);
1138 reply->writeInt32(status);
1139 return NO_ERROR;
1140 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001141
Eric Laurentb52c1522014-05-20 11:27:36 -07001142 case REGISTER_CLIENT: {
1143 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1144 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1145 data.readStrongBinder());
1146 registerClient(client);
1147 return NO_ERROR;
1148 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001149
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001150 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1151 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1152 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1153 data.readStrongBinder());
1154 audio_session_t session;
1155 audio_io_handle_t ioHandle;
1156 audio_devices_t device;
1157 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1158 reply->writeInt32(status);
1159 if (status == NO_ERROR) {
1160 reply->writeInt32(session);
1161 reply->writeInt32(ioHandle);
1162 reply->writeInt32(device);
1163 }
1164 return NO_ERROR;
1165 } break;
1166
1167 case RELEASE_SOUNDTRIGGER_SESSION: {
1168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1169 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1170 data.readStrongBinder());
1171 audio_session_t session = (audio_session_t)data.readInt32();
1172 status_t status = releaseSoundTriggerSession(session);
1173 reply->writeInt32(status);
1174 return NO_ERROR;
1175 } break;
1176
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001177 case GET_PHONE_STATE: {
1178 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1179 reply->writeInt32((int32_t)getPhoneState());
1180 return NO_ERROR;
1181 } break;
1182
Eric Laurentbaac1832014-12-01 17:52:59 -08001183 case REGISTER_POLICY_MIXES: {
1184 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1185 bool registration = data.readInt32() == 1;
1186 Vector<AudioMix> mixes;
1187 size_t size = (size_t)data.readInt32();
1188 if (size > MAX_MIXES_PER_POLICY) {
1189 size = MAX_MIXES_PER_POLICY;
1190 }
1191 for (size_t i = 0; i < size; i++) {
1192 AudioMix mix;
1193 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1194 mixes.add(mix);
1195 }
1196 }
1197 status_t status = registerPolicyMixes(mixes, registration);
1198 reply->writeInt32(status);
1199 return NO_ERROR;
1200 } break;
1201
Eric Laurentc2f1f072009-07-17 12:17:14 -07001202 default:
1203 return BBinder::onTransact(code, data, reply, flags);
1204 }
1205}
1206
1207// ----------------------------------------------------------------------------
1208
1209}; // namespace android