blob: fc36a7f35b1ae061822bad0c7125fc9f4e7594a6 [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 Laurent554a2772015-04-10 11:29:24 -070074 START_AUDIO_SOURCE,
75 STOP_AUDIO_SOURCE
Eric Laurentc2f1f072009-07-17 12:17:14 -070076};
77
Eric Laurent1d670b12015-02-06 10:44:24 -080078#define MAX_ITEMS_PER_LIST 1024
79
Eric Laurentc2f1f072009-07-17 12:17:14 -070080class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
81{
82public:
83 BpAudioPolicyService(const sp<IBinder>& impl)
84 : BpInterface<IAudioPolicyService>(impl)
85 {
86 }
87
88 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070089 audio_devices_t device,
90 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080091 const char *device_address,
92 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070093 {
94 Parcel data, reply;
95 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
96 data.writeInt32(static_cast <uint32_t>(device));
97 data.writeInt32(static_cast <uint32_t>(state));
98 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -080099 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
101 return static_cast <status_t> (reply.readInt32());
102 }
103
Dima Zavinfce7a472011-04-19 22:30:36 -0700104 virtual audio_policy_dev_state_t getDeviceConnectionState(
105 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700106 const char *device_address)
107 {
108 Parcel data, reply;
109 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
110 data.writeInt32(static_cast <uint32_t>(device));
111 data.writeCString(device_address);
112 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700113 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700114 }
115
Glenn Kastenf78aee72012-01-04 11:00:47 -0800116 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 {
118 Parcel data, reply;
119 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
120 data.writeInt32(state);
121 remote()->transact(SET_PHONE_STATE, data, &reply);
122 return static_cast <status_t> (reply.readInt32());
123 }
124
Dima Zavinfce7a472011-04-19 22:30:36 -0700125 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700126 {
127 Parcel data, reply;
128 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
129 data.writeInt32(static_cast <uint32_t>(usage));
130 data.writeInt32(static_cast <uint32_t>(config));
131 remote()->transact(SET_FORCE_USE, data, &reply);
132 return static_cast <status_t> (reply.readInt32());
133 }
134
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700136 {
137 Parcel data, reply;
138 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
139 data.writeInt32(static_cast <uint32_t>(usage));
140 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700141 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700142 }
143
144 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700145 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800147 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700148 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000149 audio_output_flags_t flags,
150 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700151 {
152 Parcel data, reply;
153 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
154 data.writeInt32(static_cast <uint32_t>(stream));
155 data.writeInt32(samplingRate);
156 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700157 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700158 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800159 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100160 if (offloadInfo == NULL) {
161 data.writeInt32(0);
162 } else {
163 data.writeInt32(1);
164 data.write(offloadInfo, sizeof(audio_offload_info_t));
165 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700166 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700167 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700168 }
169
Eric Laurente83b55d2014-11-14 10:06:21 -0800170 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
171 audio_io_handle_t *output,
172 audio_session_t session,
173 audio_stream_type_t *stream,
174 uint32_t samplingRate,
175 audio_format_t format,
176 audio_channel_mask_t channelMask,
177 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700178 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800179 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700180 {
181 Parcel data, reply;
182 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
183 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800184 if (stream == NULL) {
185 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
186 return BAD_VALUE;
187 }
188 if (*stream == AUDIO_STREAM_DEFAULT) {
189 ALOGE("getOutputForAttr unspecified stream type");
190 return BAD_VALUE;
191 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700192 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800193 if (output == NULL) {
194 ALOGE("getOutputForAttr NULL output - shouldn't happen");
195 return BAD_VALUE;
196 }
197 if (attr == NULL) {
198 data.writeInt32(0);
199 } else {
200 data.writeInt32(1);
201 data.write(attr, sizeof(audio_attributes_t));
202 }
203 data.writeInt32(session);
204 if (stream == NULL) {
205 data.writeInt32(0);
206 } else {
207 data.writeInt32(1);
208 data.writeInt32(*stream);
209 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700210 data.writeInt32(samplingRate);
211 data.writeInt32(static_cast <uint32_t>(format));
212 data.writeInt32(channelMask);
213 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700214 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700215 // hasOffloadInfo
216 if (offloadInfo == NULL) {
217 data.writeInt32(0);
218 } else {
219 data.writeInt32(1);
220 data.write(offloadInfo, sizeof(audio_offload_info_t));
221 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800222 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
223 if (status != NO_ERROR) {
224 return status;
225 }
226 status = (status_t)reply.readInt32();
227 if (status != NO_ERROR) {
228 return status;
229 }
230 *output = (audio_io_handle_t)reply.readInt32();
231 if (stream != NULL) {
232 *stream = (audio_stream_type_t)reply.readInt32();
233 }
234 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700235 }
236
Eric Laurentde070132010-07-13 04:45:46 -0700237 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700238 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800239 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700240 {
241 Parcel data, reply;
242 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700243 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800244 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800245 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700246 remote()->transact(START_OUTPUT, data, &reply);
247 return static_cast <status_t> (reply.readInt32());
248 }
249
Eric Laurentde070132010-07-13 04:45:46 -0700250 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700251 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800252 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700253 {
254 Parcel data, reply;
255 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700256 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800257 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800258 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 remote()->transact(STOP_OUTPUT, data, &reply);
260 return static_cast <status_t> (reply.readInt32());
261 }
262
Eric Laurente83b55d2014-11-14 10:06:21 -0800263 virtual void releaseOutput(audio_io_handle_t output,
264 audio_stream_type_t stream,
265 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700266 {
267 Parcel data, reply;
268 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700269 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800270 data.writeInt32((int32_t)stream);
271 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 remote()->transact(RELEASE_OUTPUT, data, &reply);
273 }
274
Eric Laurentcaf7f482014-11-25 17:50:47 -0800275 virtual status_t getInputForAttr(const audio_attributes_t *attr,
276 audio_io_handle_t *input,
277 audio_session_t session,
278 uint32_t samplingRate,
279 audio_format_t format,
280 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600281 audio_input_flags_t flags,
282 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700283 {
284 Parcel data, reply;
285 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800286 if (attr == NULL) {
287 ALOGE("getInputForAttr NULL attr - shouldn't happen");
288 return BAD_VALUE;
289 }
290 if (input == NULL) {
291 ALOGE("getInputForAttr NULL input - shouldn't happen");
292 return BAD_VALUE;
293 }
294 data.write(attr, sizeof(audio_attributes_t));
295 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700296 data.writeInt32(samplingRate);
297 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700298 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700299 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600300 data.writeInt32(selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800301 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
302 if (status != NO_ERROR) {
303 return status;
304 }
305 status = reply.readInt32();
306 if (status != NO_ERROR) {
307 return status;
308 }
309 *input = (audio_io_handle_t)reply.readInt32();
310 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700311 }
312
Eric Laurent4dc68062014-07-28 17:26:49 -0700313 virtual status_t startInput(audio_io_handle_t input,
314 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700318 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700319 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700320 remote()->transact(START_INPUT, data, &reply);
321 return static_cast <status_t> (reply.readInt32());
322 }
323
Eric Laurent4dc68062014-07-28 17:26:49 -0700324 virtual status_t stopInput(audio_io_handle_t input,
325 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700329 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700330 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700331 remote()->transact(STOP_INPUT, data, &reply);
332 return static_cast <status_t> (reply.readInt32());
333 }
334
Eric Laurent4dc68062014-07-28 17:26:49 -0700335 virtual void releaseInput(audio_io_handle_t input,
336 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700340 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700341 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 remote()->transact(RELEASE_INPUT, data, &reply);
343 }
344
Dima Zavinfce7a472011-04-19 22:30:36 -0700345 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 int indexMin,
347 int indexMax)
348 {
349 Parcel data, reply;
350 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
351 data.writeInt32(static_cast <uint32_t>(stream));
352 data.writeInt32(indexMin);
353 data.writeInt32(indexMax);
354 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
355 return static_cast <status_t> (reply.readInt32());
356 }
357
Eric Laurent83844cc2011-11-18 16:43:31 -0800358 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
359 int index,
360 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
364 data.writeInt32(static_cast <uint32_t>(stream));
365 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800366 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700367 remote()->transact(SET_STREAM_VOLUME, data, &reply);
368 return static_cast <status_t> (reply.readInt32());
369 }
370
Eric Laurent83844cc2011-11-18 16:43:31 -0800371 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
372 int *index,
373 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
377 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800378 data.writeInt32(static_cast <uint32_t>(device));
379
Eric Laurentc2f1f072009-07-17 12:17:14 -0700380 remote()->transact(GET_STREAM_VOLUME, data, &reply);
381 int lIndex = reply.readInt32();
382 if (index) *index = lIndex;
383 return static_cast <status_t> (reply.readInt32());
384 }
Eric Laurentde070132010-07-13 04:45:46 -0700385
Dima Zavinfce7a472011-04-19 22:30:36 -0700386 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700387 {
388 Parcel data, reply;
389 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
390 data.writeInt32(static_cast <uint32_t>(stream));
391 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
392 return reply.readInt32();
393 }
394
Eric Laurent63742522012-03-08 13:42:42 -0800395 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
399 data.writeInt32(static_cast <uint32_t>(stream));
400 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800401 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800402 }
403
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700404 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
408 data.write(desc, sizeof(effect_descriptor_t));
409 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
410 return static_cast <audio_io_handle_t> (reply.readInt32());
411 }
412
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700413 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700414 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700415 uint32_t strategy,
416 int session,
417 int id)
418 {
419 Parcel data, reply;
420 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
421 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700422 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700423 data.writeInt32(strategy);
424 data.writeInt32(session);
425 data.writeInt32(id);
426 remote()->transact(REGISTER_EFFECT, data, &reply);
427 return static_cast <status_t> (reply.readInt32());
428 }
429
430 virtual status_t unregisterEffect(int id)
431 {
432 Parcel data, reply;
433 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
434 data.writeInt32(id);
435 remote()->transact(UNREGISTER_EFFECT, data, &reply);
436 return static_cast <status_t> (reply.readInt32());
437 }
438
Eric Laurentdb7c0792011-08-10 10:37:50 -0700439 virtual status_t setEffectEnabled(int id, bool enabled)
440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.writeInt32(id);
444 data.writeInt32(enabled);
445 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
446 return static_cast <status_t> (reply.readInt32());
447 }
448
Glenn Kastenfff6d712012-01-12 16:38:12 -0800449 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800450 {
451 Parcel data, reply;
452 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800453 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800454 data.writeInt32(inPastMs);
455 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
456 return reply.readInt32();
457 }
Eric Laurent57dae992011-07-24 13:36:09 -0700458
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800459 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
460 {
461 Parcel data, reply;
462 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
463 data.writeInt32((int32_t) stream);
464 data.writeInt32(inPastMs);
465 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
466 return reply.readInt32();
467 }
468
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700469 virtual bool isSourceActive(audio_source_t source) const
470 {
471 Parcel data, reply;
472 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
473 data.writeInt32((int32_t) source);
474 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
475 return reply.readInt32();
476 }
477
Eric Laurent57dae992011-07-24 13:36:09 -0700478 virtual status_t queryDefaultPreProcessing(int audioSession,
479 effect_descriptor_t *descriptors,
480 uint32_t *count)
481 {
482 if (descriptors == NULL || count == NULL) {
483 return BAD_VALUE;
484 }
485 Parcel data, reply;
486 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
487 data.writeInt32(audioSession);
488 data.writeInt32(*count);
489 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
490 if (status != NO_ERROR) {
491 return status;
492 }
493 status = static_cast <status_t> (reply.readInt32());
494 uint32_t retCount = reply.readInt32();
495 if (retCount != 0) {
496 uint32_t numDesc = (retCount < *count) ? retCount : *count;
497 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
498 }
499 *count = retCount;
500 return status;
501 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000502
503 virtual bool isOffloadSupported(const audio_offload_info_t& info)
504 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100505 Parcel data, reply;
506 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
507 data.write(&info, sizeof(audio_offload_info_t));
508 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700509 return reply.readInt32();
510 }
511
512 virtual status_t listAudioPorts(audio_port_role_t role,
513 audio_port_type_t type,
514 unsigned int *num_ports,
515 struct audio_port *ports,
516 unsigned int *generation)
517 {
518 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
519 generation == NULL) {
520 return BAD_VALUE;
521 }
522 Parcel data, reply;
523 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
524 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
525 data.writeInt32(role);
526 data.writeInt32(type);
527 data.writeInt32(numPortsReq);
528 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
529 if (status == NO_ERROR) {
530 status = (status_t)reply.readInt32();
531 *num_ports = (unsigned int)reply.readInt32();
532 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700533 if (status == NO_ERROR) {
534 if (numPortsReq > *num_ports) {
535 numPortsReq = *num_ports;
536 }
537 if (numPortsReq > 0) {
538 reply.read(ports, numPortsReq * sizeof(struct audio_port));
539 }
540 *generation = reply.readInt32();
541 }
542 return status;
543 }
544
545 virtual status_t getAudioPort(struct audio_port *port)
546 {
547 if (port == NULL) {
548 return BAD_VALUE;
549 }
550 Parcel data, reply;
551 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
552 data.write(port, sizeof(struct audio_port));
553 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
554 if (status != NO_ERROR ||
555 (status = (status_t)reply.readInt32()) != NO_ERROR) {
556 return status;
557 }
558 reply.read(port, sizeof(struct audio_port));
559 return status;
560 }
561
562 virtual status_t createAudioPatch(const struct audio_patch *patch,
563 audio_patch_handle_t *handle)
564 {
565 if (patch == NULL || handle == NULL) {
566 return BAD_VALUE;
567 }
568 Parcel data, reply;
569 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
570 data.write(patch, sizeof(struct audio_patch));
571 data.write(handle, sizeof(audio_patch_handle_t));
572 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
573 if (status != NO_ERROR ||
574 (status = (status_t)reply.readInt32()) != NO_ERROR) {
575 return status;
576 }
577 reply.read(handle, sizeof(audio_patch_handle_t));
578 return status;
579 }
580
581 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
582 {
583 Parcel data, reply;
584 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
585 data.write(&handle, sizeof(audio_patch_handle_t));
586 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
587 if (status != NO_ERROR) {
588 status = (status_t)reply.readInt32();
589 }
590 return status;
591 }
592
593 virtual status_t listAudioPatches(unsigned int *num_patches,
594 struct audio_patch *patches,
595 unsigned int *generation)
596 {
597 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
598 generation == NULL) {
599 return BAD_VALUE;
600 }
601 Parcel data, reply;
602 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
603 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
604 data.writeInt32(numPatchesReq);
605 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
606 if (status == NO_ERROR) {
607 status = (status_t)reply.readInt32();
608 *num_patches = (unsigned int)reply.readInt32();
609 }
610 if (status == NO_ERROR) {
611 if (numPatchesReq > *num_patches) {
612 numPatchesReq = *num_patches;
613 }
614 if (numPatchesReq > 0) {
615 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
616 }
617 *generation = reply.readInt32();
618 }
619 return status;
620 }
621
622 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
623 {
624 if (config == NULL) {
625 return BAD_VALUE;
626 }
627 Parcel data, reply;
628 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
629 data.write(config, sizeof(struct audio_port_config));
630 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
631 if (status != NO_ERROR) {
632 status = (status_t)reply.readInt32();
633 }
634 return status;
635 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700636
Eric Laurentb52c1522014-05-20 11:27:36 -0700637 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
638 {
639 Parcel data, reply;
640 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800641 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700642 remote()->transact(REGISTER_CLIENT, data, &reply);
643 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700644
645 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
646 audio_io_handle_t *ioHandle,
647 audio_devices_t *device)
648 {
649 if (session == NULL || ioHandle == NULL || device == NULL) {
650 return BAD_VALUE;
651 }
652 Parcel data, reply;
653 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
654 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
655 if (status != NO_ERROR) {
656 return status;
657 }
658 status = (status_t)reply.readInt32();
659 if (status == NO_ERROR) {
660 *session = (audio_session_t)reply.readInt32();
661 *ioHandle = (audio_io_handle_t)reply.readInt32();
662 *device = (audio_devices_t)reply.readInt32();
663 }
664 return status;
665 }
666
667 virtual status_t releaseSoundTriggerSession(audio_session_t session)
668 {
669 Parcel data, reply;
670 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
671 data.writeInt32(session);
672 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
673 if (status != NO_ERROR) {
674 return status;
675 }
676 return (status_t)reply.readInt32();
677 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700678
679 virtual audio_mode_t getPhoneState()
680 {
681 Parcel data, reply;
682 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
683 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
684 if (status != NO_ERROR) {
685 return AUDIO_MODE_INVALID;
686 }
687 return (audio_mode_t)reply.readInt32();
688 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800689
690 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
691 {
692 Parcel data, reply;
693 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
694 data.writeInt32(registration ? 1 : 0);
695 size_t size = mixes.size();
696 if (size > MAX_MIXES_PER_POLICY) {
697 size = MAX_MIXES_PER_POLICY;
698 }
699 size_t sizePosition = data.dataPosition();
700 data.writeInt32(size);
701 size_t finalSize = size;
702 for (size_t i = 0; i < size; i++) {
703 size_t position = data.dataPosition();
704 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
705 data.setDataPosition(position);
706 finalSize--;
707 }
708 }
709 if (size != finalSize) {
710 size_t position = data.dataPosition();
711 data.setDataPosition(sizePosition);
712 data.writeInt32(finalSize);
713 data.setDataPosition(position);
714 }
715 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
716 if (status == NO_ERROR) {
717 status = (status_t)reply.readInt32();
718 }
719 return status;
720 }
Eric Laurent554a2772015-04-10 11:29:24 -0700721
722 virtual status_t startAudioSource(const struct audio_port_config *source,
723 const audio_attributes_t *attributes,
724 audio_io_handle_t *handle)
725 {
726 Parcel data, reply;
727 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
728 if (source == NULL || attributes == NULL || handle == NULL) {
729 return BAD_VALUE;
730 }
731 data.write(source, sizeof(struct audio_port_config));
732 data.write(attributes, sizeof(audio_attributes_t));
733 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
734 if (status != NO_ERROR) {
735 return status;
736 }
737 status = (status_t)reply.readInt32();
738 if (status != NO_ERROR) {
739 return status;
740 }
741 *handle = (audio_io_handle_t)reply.readInt32();
742 return status;
743 }
744
745 virtual status_t stopAudioSource(audio_io_handle_t handle)
746 {
747 Parcel data, reply;
748 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
749 data.writeInt32(handle);
750 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
751 if (status != NO_ERROR) {
752 return status;
753 }
754 status = (status_t)reply.readInt32();
755 return status;
756 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700757};
758
759IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
760
761// ----------------------------------------------------------------------
762
763
764status_t BnAudioPolicyService::onTransact(
765 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
766{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700767 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700768 case SET_DEVICE_CONNECTION_STATE: {
769 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700770 audio_devices_t device =
771 static_cast <audio_devices_t>(data.readInt32());
772 audio_policy_dev_state_t state =
773 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700774 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800775 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700776 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
777 state,
Paul McLeane743a472015-01-28 11:07:31 -0800778 device_address,
779 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700780 return NO_ERROR;
781 } break;
782
783 case GET_DEVICE_CONNECTION_STATE: {
784 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700785 audio_devices_t device =
786 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700787 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700788 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
789 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700790 return NO_ERROR;
791 } break;
792
793 case SET_PHONE_STATE: {
794 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700795 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
796 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700797 return NO_ERROR;
798 } break;
799
Eric Laurentc2f1f072009-07-17 12:17:14 -0700800 case SET_FORCE_USE: {
801 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700802 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
803 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700804 audio_policy_forced_cfg_t config =
805 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700806 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
807 return NO_ERROR;
808 } break;
809
810 case GET_FORCE_USE: {
811 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700812 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
813 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700814 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
815 return NO_ERROR;
816 } break;
817
818 case GET_OUTPUT: {
819 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700820 audio_stream_type_t stream =
821 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700822 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800823 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700824 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700825 audio_output_flags_t flags =
826 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100827 bool hasOffloadInfo = data.readInt32() != 0;
828 audio_offload_info_t offloadInfo;
829 if (hasOffloadInfo) {
830 data.read(&offloadInfo, sizeof(audio_offload_info_t));
831 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700832 audio_io_handle_t output = getOutput(stream,
833 samplingRate,
834 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700835 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100836 flags,
837 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700838 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700839 return NO_ERROR;
840 } break;
841
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700842 case GET_OUTPUT_FOR_ATTR: {
843 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800844 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800845 bool hasAttributes = data.readInt32() != 0;
846 if (hasAttributes) {
847 data.read(&attr, sizeof(audio_attributes_t));
848 }
849 audio_session_t session = (audio_session_t)data.readInt32();
850 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
851 bool hasStream = data.readInt32() != 0;
852 if (hasStream) {
853 stream = (audio_stream_type_t)data.readInt32();
854 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700855 uint32_t samplingRate = data.readInt32();
856 audio_format_t format = (audio_format_t) data.readInt32();
857 audio_channel_mask_t channelMask = data.readInt32();
858 audio_output_flags_t flags =
859 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700860 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700861 bool hasOffloadInfo = data.readInt32() != 0;
862 audio_offload_info_t offloadInfo;
863 if (hasOffloadInfo) {
864 data.read(&offloadInfo, sizeof(audio_offload_info_t));
865 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800866 audio_io_handle_t output;
867 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
868 &output, session, &stream,
869 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700870 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800871 reply->writeInt32(status);
872 reply->writeInt32(output);
873 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700874 return NO_ERROR;
875 } break;
876
Eric Laurentc2f1f072009-07-17 12:17:14 -0700877 case START_OUTPUT: {
878 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700879 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800880 audio_stream_type_t stream =
881 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800882 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700883 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800884 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700885 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700886 return NO_ERROR;
887 } break;
888
889 case STOP_OUTPUT: {
890 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700891 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800892 audio_stream_type_t stream =
893 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800894 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700895 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800896 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700897 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700898 return NO_ERROR;
899 } break;
900
901 case RELEASE_OUTPUT: {
902 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700903 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800904 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
905 audio_session_t session = (audio_session_t)data.readInt32();
906 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700907 return NO_ERROR;
908 } break;
909
Eric Laurentcaf7f482014-11-25 17:50:47 -0800910 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700911 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800912 audio_attributes_t attr;
913 data.read(&attr, sizeof(audio_attributes_t));
914 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700915 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800916 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700917 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700918 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600919 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800920 audio_io_handle_t input;
921 status_t status = getInputForAttr(&attr, &input, session,
922 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600923 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800924 reply->writeInt32(status);
925 if (status == NO_ERROR) {
926 reply->writeInt32(input);
927 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700928 return NO_ERROR;
929 } break;
930
931 case START_INPUT: {
932 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700933 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700934 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
935 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 return NO_ERROR;
937 } break;
938
939 case STOP_INPUT: {
940 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700941 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700942 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
943 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700944 return NO_ERROR;
945 } break;
946
947 case RELEASE_INPUT: {
948 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700949 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700950 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
951 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700952 return NO_ERROR;
953 } break;
954
955 case INIT_STREAM_VOLUME: {
956 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700957 audio_stream_type_t stream =
958 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700959 int indexMin = data.readInt32();
960 int indexMax = data.readInt32();
961 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
962 return NO_ERROR;
963 } break;
964
965 case SET_STREAM_VOLUME: {
966 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700967 audio_stream_type_t stream =
968 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700969 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800970 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
971 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
972 index,
973 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700974 return NO_ERROR;
975 } break;
976
977 case GET_STREAM_VOLUME: {
978 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700979 audio_stream_type_t stream =
980 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800981 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700982 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800983 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700984 reply->writeInt32(index);
985 reply->writeInt32(static_cast <uint32_t>(status));
986 return NO_ERROR;
987 } break;
988
Eric Laurentde070132010-07-13 04:45:46 -0700989 case GET_STRATEGY_FOR_STREAM: {
990 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700991 audio_stream_type_t stream =
992 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700993 reply->writeInt32(getStrategyForStream(stream));
994 return NO_ERROR;
995 } break;
996
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800997 case GET_DEVICES_FOR_STREAM: {
998 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700999 audio_stream_type_t stream =
1000 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001001 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1002 return NO_ERROR;
1003 } break;
1004
Eric Laurentde070132010-07-13 04:45:46 -07001005 case GET_OUTPUT_FOR_EFFECT: {
1006 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1007 effect_descriptor_t desc;
1008 data.read(&desc, sizeof(effect_descriptor_t));
1009 audio_io_handle_t output = getOutputForEffect(&desc);
1010 reply->writeInt32(static_cast <int>(output));
1011 return NO_ERROR;
1012 } break;
1013
1014 case REGISTER_EFFECT: {
1015 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1016 effect_descriptor_t desc;
1017 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001018 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001019 uint32_t strategy = data.readInt32();
1020 int session = data.readInt32();
1021 int id = data.readInt32();
1022 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001023 io,
Eric Laurentde070132010-07-13 04:45:46 -07001024 strategy,
1025 session,
1026 id)));
1027 return NO_ERROR;
1028 } break;
1029
1030 case UNREGISTER_EFFECT: {
1031 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1032 int id = data.readInt32();
1033 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1034 return NO_ERROR;
1035 } break;
1036
Eric Laurentdb7c0792011-08-10 10:37:50 -07001037 case SET_EFFECT_ENABLED: {
1038 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1039 int id = data.readInt32();
1040 bool enabled = static_cast <bool>(data.readInt32());
1041 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1042 return NO_ERROR;
1043 } break;
1044
Eric Laurenteda6c362011-02-02 09:33:30 -08001045 case IS_STREAM_ACTIVE: {
1046 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001047 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001048 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001049 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001050 return NO_ERROR;
1051 } break;
1052
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001053 case IS_STREAM_ACTIVE_REMOTELY: {
1054 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1055 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1056 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001057 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001058 return NO_ERROR;
1059 } break;
1060
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001061 case IS_SOURCE_ACTIVE: {
1062 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1063 audio_source_t source = (audio_source_t) data.readInt32();
1064 reply->writeInt32( isSourceActive(source));
1065 return NO_ERROR;
1066 }
1067
Eric Laurent57dae992011-07-24 13:36:09 -07001068 case QUERY_DEFAULT_PRE_PROCESSING: {
1069 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1070 int audioSession = data.readInt32();
1071 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001072 if (count > AudioEffect::kMaxPreProcessing) {
1073 count = AudioEffect::kMaxPreProcessing;
1074 }
Eric Laurent57dae992011-07-24 13:36:09 -07001075 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001076 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001077 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1078 reply->writeInt32(status);
1079 if (status != NO_ERROR && status != NO_MEMORY) {
1080 retCount = 0;
1081 }
1082 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001083 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001084 if (retCount < count) {
1085 count = retCount;
1086 }
1087 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1088 }
1089 delete[] descriptors;
1090 return status;
1091 }
1092
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001093 case IS_OFFLOAD_SUPPORTED: {
1094 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1095 audio_offload_info_t info;
1096 data.read(&info, sizeof(audio_offload_info_t));
1097 bool isSupported = isOffloadSupported(info);
1098 reply->writeInt32(isSupported);
1099 return NO_ERROR;
1100 }
1101
Eric Laurent203b1a12014-04-01 10:34:16 -07001102 case LIST_AUDIO_PORTS: {
1103 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1104 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1105 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1106 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001107 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1108 numPortsReq = MAX_ITEMS_PER_LIST;
1109 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001110 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001111 struct audio_port *ports =
1112 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001113 if (ports == NULL) {
1114 reply->writeInt32(NO_MEMORY);
1115 reply->writeInt32(0);
1116 return NO_ERROR;
1117 }
1118 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001119 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1120 reply->writeInt32(status);
1121 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001122
1123 if (status == NO_ERROR) {
1124 if (numPortsReq > numPorts) {
1125 numPortsReq = numPorts;
1126 }
1127 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1128 reply->writeInt32(generation);
1129 }
1130 free(ports);
1131 return NO_ERROR;
1132 }
1133
1134 case GET_AUDIO_PORT: {
1135 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1136 struct audio_port port;
1137 data.read(&port, sizeof(struct audio_port));
1138 status_t status = getAudioPort(&port);
1139 reply->writeInt32(status);
1140 if (status == NO_ERROR) {
1141 reply->write(&port, sizeof(struct audio_port));
1142 }
1143 return NO_ERROR;
1144 }
1145
1146 case CREATE_AUDIO_PATCH: {
1147 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1148 struct audio_patch patch;
1149 data.read(&patch, sizeof(struct audio_patch));
1150 audio_patch_handle_t handle;
1151 data.read(&handle, sizeof(audio_patch_handle_t));
1152 status_t status = createAudioPatch(&patch, &handle);
1153 reply->writeInt32(status);
1154 if (status == NO_ERROR) {
1155 reply->write(&handle, sizeof(audio_patch_handle_t));
1156 }
1157 return NO_ERROR;
1158 }
1159
1160 case RELEASE_AUDIO_PATCH: {
1161 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1162 audio_patch_handle_t handle;
1163 data.read(&handle, sizeof(audio_patch_handle_t));
1164 status_t status = releaseAudioPatch(handle);
1165 reply->writeInt32(status);
1166 return NO_ERROR;
1167 }
1168
1169 case LIST_AUDIO_PATCHES: {
1170 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1171 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001172 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1173 numPatchesReq = MAX_ITEMS_PER_LIST;
1174 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001175 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001176 struct audio_patch *patches =
1177 (struct audio_patch *)calloc(numPatchesReq,
1178 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001179 if (patches == NULL) {
1180 reply->writeInt32(NO_MEMORY);
1181 reply->writeInt32(0);
1182 return NO_ERROR;
1183 }
1184 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001185 status_t status = listAudioPatches(&numPatches, patches, &generation);
1186 reply->writeInt32(status);
1187 reply->writeInt32(numPatches);
1188 if (status == NO_ERROR) {
1189 if (numPatchesReq > numPatches) {
1190 numPatchesReq = numPatches;
1191 }
1192 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1193 reply->writeInt32(generation);
1194 }
1195 free(patches);
1196 return NO_ERROR;
1197 }
1198
1199 case SET_AUDIO_PORT_CONFIG: {
1200 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1201 struct audio_port_config config;
1202 data.read(&config, sizeof(struct audio_port_config));
1203 status_t status = setAudioPortConfig(&config);
1204 reply->writeInt32(status);
1205 return NO_ERROR;
1206 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001207
Eric Laurentb52c1522014-05-20 11:27:36 -07001208 case REGISTER_CLIENT: {
1209 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1210 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1211 data.readStrongBinder());
1212 registerClient(client);
1213 return NO_ERROR;
1214 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001215
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001216 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1217 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1218 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1219 data.readStrongBinder());
1220 audio_session_t session;
1221 audio_io_handle_t ioHandle;
1222 audio_devices_t device;
1223 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1224 reply->writeInt32(status);
1225 if (status == NO_ERROR) {
1226 reply->writeInt32(session);
1227 reply->writeInt32(ioHandle);
1228 reply->writeInt32(device);
1229 }
1230 return NO_ERROR;
1231 } break;
1232
1233 case RELEASE_SOUNDTRIGGER_SESSION: {
1234 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1235 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1236 data.readStrongBinder());
1237 audio_session_t session = (audio_session_t)data.readInt32();
1238 status_t status = releaseSoundTriggerSession(session);
1239 reply->writeInt32(status);
1240 return NO_ERROR;
1241 } break;
1242
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001243 case GET_PHONE_STATE: {
1244 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1245 reply->writeInt32((int32_t)getPhoneState());
1246 return NO_ERROR;
1247 } break;
1248
Eric Laurentbaac1832014-12-01 17:52:59 -08001249 case REGISTER_POLICY_MIXES: {
1250 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1251 bool registration = data.readInt32() == 1;
1252 Vector<AudioMix> mixes;
1253 size_t size = (size_t)data.readInt32();
1254 if (size > MAX_MIXES_PER_POLICY) {
1255 size = MAX_MIXES_PER_POLICY;
1256 }
1257 for (size_t i = 0; i < size; i++) {
1258 AudioMix mix;
1259 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1260 mixes.add(mix);
1261 }
1262 }
1263 status_t status = registerPolicyMixes(mixes, registration);
1264 reply->writeInt32(status);
1265 return NO_ERROR;
1266 } break;
1267
Eric Laurent554a2772015-04-10 11:29:24 -07001268 case START_AUDIO_SOURCE: {
1269 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1270 struct audio_port_config source;
1271 data.read(&source, sizeof(struct audio_port_config));
1272 audio_attributes_t attributes;
1273 data.read(&attributes, sizeof(audio_attributes_t));
1274 audio_io_handle_t handle;
1275 status_t status = startAudioSource(&source, &attributes, &handle);
1276 reply->writeInt32(status);
1277 reply->writeInt32(handle);
1278 return NO_ERROR;
1279 } break;
1280
1281 case STOP_AUDIO_SOURCE: {
1282 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1283 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1284 status_t status = stopAudioSource(handle);
1285 reply->writeInt32(status);
1286 return NO_ERROR;
1287 } break;
1288
Eric Laurentc2f1f072009-07-17 12:17:14 -07001289 default:
1290 return BBinder::onTransact(code, data, reply, flags);
1291 }
1292}
1293
1294// ----------------------------------------------------------------------------
1295
Glenn Kasten40bc9062015-03-20 09:09:33 -07001296} // namespace android