blob: f2ff27b314de89393052f3c209a7ba3c807e97e4 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25
Eric Laurent74adca92014-11-05 12:15:36 -080026#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070027#include <media/IAudioPolicyService.h>
28
Dima Zavin64760242011-05-11 14:15:23 -070029#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070030
Eric Laurentc2f1f072009-07-17 12:17:14 -070031namespace android {
32
33enum {
34 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
35 GET_DEVICE_CONNECTION_STATE,
36 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080037 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 SET_FORCE_USE,
39 GET_FORCE_USE,
40 GET_OUTPUT,
41 START_OUTPUT,
42 STOP_OUTPUT,
43 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080044 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070045 START_INPUT,
46 STOP_INPUT,
47 RELEASE_INPUT,
48 INIT_STREAM_VOLUME,
49 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070050 GET_STREAM_VOLUME,
51 GET_STRATEGY_FOR_STREAM,
52 GET_OUTPUT_FOR_EFFECT,
53 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080054 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080055 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070056 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080057 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070058 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080059 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000060 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070061 IS_OFFLOAD_SUPPORTED,
62 LIST_AUDIO_PORTS,
63 GET_AUDIO_PORT,
64 CREATE_AUDIO_PATCH,
65 RELEASE_AUDIO_PATCH,
66 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070067 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070068 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070069 GET_OUTPUT_FOR_ATTR,
70 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070071 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080072 GET_PHONE_STATE,
73 REGISTER_POLICY_MIXES,
Eric Laurentc2f1f072009-07-17 12:17:14 -070074};
75
Eric Laurent1d670b12015-02-06 10:44:24 -080076#define MAX_ITEMS_PER_LIST 1024
77
Eric Laurentc2f1f072009-07-17 12:17:14 -070078class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
79{
80public:
81 BpAudioPolicyService(const sp<IBinder>& impl)
82 : BpInterface<IAudioPolicyService>(impl)
83 {
84 }
85
86 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070087 audio_devices_t device,
88 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080089 const char *device_address,
90 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070091 {
92 Parcel data, reply;
93 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
94 data.writeInt32(static_cast <uint32_t>(device));
95 data.writeInt32(static_cast <uint32_t>(state));
96 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -080097 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -070098 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
99 return static_cast <status_t> (reply.readInt32());
100 }
101
Dima Zavinfce7a472011-04-19 22:30:36 -0700102 virtual audio_policy_dev_state_t getDeviceConnectionState(
103 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700104 const char *device_address)
105 {
106 Parcel data, reply;
107 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
108 data.writeInt32(static_cast <uint32_t>(device));
109 data.writeCString(device_address);
110 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700111 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 }
113
Glenn Kastenf78aee72012-01-04 11:00:47 -0800114 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700115 {
116 Parcel data, reply;
117 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
118 data.writeInt32(state);
119 remote()->transact(SET_PHONE_STATE, data, &reply);
120 return static_cast <status_t> (reply.readInt32());
121 }
122
Dima Zavinfce7a472011-04-19 22:30:36 -0700123 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700124 {
125 Parcel data, reply;
126 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
127 data.writeInt32(static_cast <uint32_t>(usage));
128 data.writeInt32(static_cast <uint32_t>(config));
129 remote()->transact(SET_FORCE_USE, data, &reply);
130 return static_cast <status_t> (reply.readInt32());
131 }
132
Dima Zavinfce7a472011-04-19 22:30:36 -0700133 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
137 data.writeInt32(static_cast <uint32_t>(usage));
138 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700140 }
141
142 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700143 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700144 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800145 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700146 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000147 audio_output_flags_t flags,
148 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 {
150 Parcel data, reply;
151 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
152 data.writeInt32(static_cast <uint32_t>(stream));
153 data.writeInt32(samplingRate);
154 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700155 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700156 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800157 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100158 if (offloadInfo == NULL) {
159 data.writeInt32(0);
160 } else {
161 data.writeInt32(1);
162 data.write(offloadInfo, sizeof(audio_offload_info_t));
163 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700165 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700166 }
167
Eric Laurente83b55d2014-11-14 10:06:21 -0800168 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
169 audio_io_handle_t *output,
170 audio_session_t session,
171 audio_stream_type_t *stream,
172 uint32_t samplingRate,
173 audio_format_t format,
174 audio_channel_mask_t channelMask,
175 audio_output_flags_t flags,
176 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700177 {
178 Parcel data, reply;
179 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
180 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800181 if (stream == NULL) {
182 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
183 return BAD_VALUE;
184 }
185 if (*stream == AUDIO_STREAM_DEFAULT) {
186 ALOGE("getOutputForAttr unspecified stream type");
187 return BAD_VALUE;
188 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700189 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800190 if (output == NULL) {
191 ALOGE("getOutputForAttr NULL output - shouldn't happen");
192 return BAD_VALUE;
193 }
194 if (attr == NULL) {
195 data.writeInt32(0);
196 } else {
197 data.writeInt32(1);
198 data.write(attr, sizeof(audio_attributes_t));
199 }
200 data.writeInt32(session);
201 if (stream == NULL) {
202 data.writeInt32(0);
203 } else {
204 data.writeInt32(1);
205 data.writeInt32(*stream);
206 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700207 data.writeInt32(samplingRate);
208 data.writeInt32(static_cast <uint32_t>(format));
209 data.writeInt32(channelMask);
210 data.writeInt32(static_cast <uint32_t>(flags));
211 // hasOffloadInfo
212 if (offloadInfo == NULL) {
213 data.writeInt32(0);
214 } else {
215 data.writeInt32(1);
216 data.write(offloadInfo, sizeof(audio_offload_info_t));
217 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800218 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
219 if (status != NO_ERROR) {
220 return status;
221 }
222 status = (status_t)reply.readInt32();
223 if (status != NO_ERROR) {
224 return status;
225 }
226 *output = (audio_io_handle_t)reply.readInt32();
227 if (stream != NULL) {
228 *stream = (audio_stream_type_t)reply.readInt32();
229 }
230 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700231 }
232
Eric Laurentde070132010-07-13 04:45:46 -0700233 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700234 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800235 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700236 {
237 Parcel data, reply;
238 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700239 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800240 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800241 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700242 remote()->transact(START_OUTPUT, data, &reply);
243 return static_cast <status_t> (reply.readInt32());
244 }
245
Eric Laurentde070132010-07-13 04:45:46 -0700246 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700247 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800248 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700249 {
250 Parcel data, reply;
251 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700252 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800253 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 remote()->transact(STOP_OUTPUT, data, &reply);
256 return static_cast <status_t> (reply.readInt32());
257 }
258
Eric Laurente83b55d2014-11-14 10:06:21 -0800259 virtual void releaseOutput(audio_io_handle_t output,
260 audio_stream_type_t stream,
261 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700265 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800266 data.writeInt32((int32_t)stream);
267 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 remote()->transact(RELEASE_OUTPUT, data, &reply);
269 }
270
Eric Laurentcaf7f482014-11-25 17:50:47 -0800271 virtual status_t getInputForAttr(const audio_attributes_t *attr,
272 audio_io_handle_t *input,
273 audio_session_t session,
274 uint32_t samplingRate,
275 audio_format_t format,
276 audio_channel_mask_t channelMask,
277 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800281 if (attr == NULL) {
282 ALOGE("getInputForAttr NULL attr - shouldn't happen");
283 return BAD_VALUE;
284 }
285 if (input == NULL) {
286 ALOGE("getInputForAttr NULL input - shouldn't happen");
287 return BAD_VALUE;
288 }
289 data.write(attr, sizeof(audio_attributes_t));
290 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700291 data.writeInt32(samplingRate);
292 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700293 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700294 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800295 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
296 if (status != NO_ERROR) {
297 return status;
298 }
299 status = reply.readInt32();
300 if (status != NO_ERROR) {
301 return status;
302 }
303 *input = (audio_io_handle_t)reply.readInt32();
304 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700305 }
306
Eric Laurent4dc68062014-07-28 17:26:49 -0700307 virtual status_t startInput(audio_io_handle_t input,
308 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700312 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700313 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700314 remote()->transact(START_INPUT, data, &reply);
315 return static_cast <status_t> (reply.readInt32());
316 }
317
Eric Laurent4dc68062014-07-28 17:26:49 -0700318 virtual status_t stopInput(audio_io_handle_t input,
319 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700320 {
321 Parcel data, reply;
322 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700323 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700324 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700325 remote()->transact(STOP_INPUT, data, &reply);
326 return static_cast <status_t> (reply.readInt32());
327 }
328
Eric Laurent4dc68062014-07-28 17:26:49 -0700329 virtual void releaseInput(audio_io_handle_t input,
330 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700331 {
332 Parcel data, reply;
333 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700334 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700335 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700336 remote()->transact(RELEASE_INPUT, data, &reply);
337 }
338
Dima Zavinfce7a472011-04-19 22:30:36 -0700339 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 int indexMin,
341 int indexMax)
342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
345 data.writeInt32(static_cast <uint32_t>(stream));
346 data.writeInt32(indexMin);
347 data.writeInt32(indexMax);
348 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
349 return static_cast <status_t> (reply.readInt32());
350 }
351
Eric Laurent83844cc2011-11-18 16:43:31 -0800352 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
353 int index,
354 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355 {
356 Parcel data, reply;
357 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
358 data.writeInt32(static_cast <uint32_t>(stream));
359 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800360 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 remote()->transact(SET_STREAM_VOLUME, data, &reply);
362 return static_cast <status_t> (reply.readInt32());
363 }
364
Eric Laurent83844cc2011-11-18 16:43:31 -0800365 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
366 int *index,
367 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700368 {
369 Parcel data, reply;
370 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
371 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800372 data.writeInt32(static_cast <uint32_t>(device));
373
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 remote()->transact(GET_STREAM_VOLUME, data, &reply);
375 int lIndex = reply.readInt32();
376 if (index) *index = lIndex;
377 return static_cast <status_t> (reply.readInt32());
378 }
Eric Laurentde070132010-07-13 04:45:46 -0700379
Dima Zavinfce7a472011-04-19 22:30:36 -0700380 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700381 {
382 Parcel data, reply;
383 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
384 data.writeInt32(static_cast <uint32_t>(stream));
385 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
386 return reply.readInt32();
387 }
388
Eric Laurent63742522012-03-08 13:42:42 -0800389 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800390 {
391 Parcel data, reply;
392 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
393 data.writeInt32(static_cast <uint32_t>(stream));
394 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800395 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800396 }
397
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700398 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700399 {
400 Parcel data, reply;
401 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
402 data.write(desc, sizeof(effect_descriptor_t));
403 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
404 return static_cast <audio_io_handle_t> (reply.readInt32());
405 }
406
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700407 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700408 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700409 uint32_t strategy,
410 int session,
411 int id)
412 {
413 Parcel data, reply;
414 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
415 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700416 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700417 data.writeInt32(strategy);
418 data.writeInt32(session);
419 data.writeInt32(id);
420 remote()->transact(REGISTER_EFFECT, data, &reply);
421 return static_cast <status_t> (reply.readInt32());
422 }
423
424 virtual status_t unregisterEffect(int id)
425 {
426 Parcel data, reply;
427 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
428 data.writeInt32(id);
429 remote()->transact(UNREGISTER_EFFECT, data, &reply);
430 return static_cast <status_t> (reply.readInt32());
431 }
432
Eric Laurentdb7c0792011-08-10 10:37:50 -0700433 virtual status_t setEffectEnabled(int id, bool enabled)
434 {
435 Parcel data, reply;
436 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
437 data.writeInt32(id);
438 data.writeInt32(enabled);
439 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
440 return static_cast <status_t> (reply.readInt32());
441 }
442
Glenn Kastenfff6d712012-01-12 16:38:12 -0800443 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800444 {
445 Parcel data, reply;
446 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800447 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800448 data.writeInt32(inPastMs);
449 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
450 return reply.readInt32();
451 }
Eric Laurent57dae992011-07-24 13:36:09 -0700452
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800453 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
457 data.writeInt32((int32_t) stream);
458 data.writeInt32(inPastMs);
459 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
460 return reply.readInt32();
461 }
462
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700463 virtual bool isSourceActive(audio_source_t source) const
464 {
465 Parcel data, reply;
466 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
467 data.writeInt32((int32_t) source);
468 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
469 return reply.readInt32();
470 }
471
Eric Laurent57dae992011-07-24 13:36:09 -0700472 virtual status_t queryDefaultPreProcessing(int audioSession,
473 effect_descriptor_t *descriptors,
474 uint32_t *count)
475 {
476 if (descriptors == NULL || count == NULL) {
477 return BAD_VALUE;
478 }
479 Parcel data, reply;
480 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
481 data.writeInt32(audioSession);
482 data.writeInt32(*count);
483 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
484 if (status != NO_ERROR) {
485 return status;
486 }
487 status = static_cast <status_t> (reply.readInt32());
488 uint32_t retCount = reply.readInt32();
489 if (retCount != 0) {
490 uint32_t numDesc = (retCount < *count) ? retCount : *count;
491 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
492 }
493 *count = retCount;
494 return status;
495 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000496
497 virtual bool isOffloadSupported(const audio_offload_info_t& info)
498 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100499 Parcel data, reply;
500 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
501 data.write(&info, sizeof(audio_offload_info_t));
502 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700503 return reply.readInt32();
504 }
505
506 virtual status_t listAudioPorts(audio_port_role_t role,
507 audio_port_type_t type,
508 unsigned int *num_ports,
509 struct audio_port *ports,
510 unsigned int *generation)
511 {
512 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
513 generation == NULL) {
514 return BAD_VALUE;
515 }
516 Parcel data, reply;
517 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
518 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
519 data.writeInt32(role);
520 data.writeInt32(type);
521 data.writeInt32(numPortsReq);
522 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
523 if (status == NO_ERROR) {
524 status = (status_t)reply.readInt32();
525 *num_ports = (unsigned int)reply.readInt32();
526 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700527 if (status == NO_ERROR) {
528 if (numPortsReq > *num_ports) {
529 numPortsReq = *num_ports;
530 }
531 if (numPortsReq > 0) {
532 reply.read(ports, numPortsReq * sizeof(struct audio_port));
533 }
534 *generation = reply.readInt32();
535 }
536 return status;
537 }
538
539 virtual status_t getAudioPort(struct audio_port *port)
540 {
541 if (port == NULL) {
542 return BAD_VALUE;
543 }
544 Parcel data, reply;
545 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
546 data.write(port, sizeof(struct audio_port));
547 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
548 if (status != NO_ERROR ||
549 (status = (status_t)reply.readInt32()) != NO_ERROR) {
550 return status;
551 }
552 reply.read(port, sizeof(struct audio_port));
553 return status;
554 }
555
556 virtual status_t createAudioPatch(const struct audio_patch *patch,
557 audio_patch_handle_t *handle)
558 {
559 if (patch == NULL || handle == NULL) {
560 return BAD_VALUE;
561 }
562 Parcel data, reply;
563 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
564 data.write(patch, sizeof(struct audio_patch));
565 data.write(handle, sizeof(audio_patch_handle_t));
566 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
567 if (status != NO_ERROR ||
568 (status = (status_t)reply.readInt32()) != NO_ERROR) {
569 return status;
570 }
571 reply.read(handle, sizeof(audio_patch_handle_t));
572 return status;
573 }
574
575 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
576 {
577 Parcel data, reply;
578 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
579 data.write(&handle, sizeof(audio_patch_handle_t));
580 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
581 if (status != NO_ERROR) {
582 status = (status_t)reply.readInt32();
583 }
584 return status;
585 }
586
587 virtual status_t listAudioPatches(unsigned int *num_patches,
588 struct audio_patch *patches,
589 unsigned int *generation)
590 {
591 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
592 generation == NULL) {
593 return BAD_VALUE;
594 }
595 Parcel data, reply;
596 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
597 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
598 data.writeInt32(numPatchesReq);
599 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
600 if (status == NO_ERROR) {
601 status = (status_t)reply.readInt32();
602 *num_patches = (unsigned int)reply.readInt32();
603 }
604 if (status == NO_ERROR) {
605 if (numPatchesReq > *num_patches) {
606 numPatchesReq = *num_patches;
607 }
608 if (numPatchesReq > 0) {
609 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
610 }
611 *generation = reply.readInt32();
612 }
613 return status;
614 }
615
616 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
617 {
618 if (config == NULL) {
619 return BAD_VALUE;
620 }
621 Parcel data, reply;
622 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
623 data.write(config, sizeof(struct audio_port_config));
624 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
625 if (status != NO_ERROR) {
626 status = (status_t)reply.readInt32();
627 }
628 return status;
629 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700630
Eric Laurentb52c1522014-05-20 11:27:36 -0700631 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
632 {
633 Parcel data, reply;
634 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800635 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700636 remote()->transact(REGISTER_CLIENT, data, &reply);
637 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700638
639 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
640 audio_io_handle_t *ioHandle,
641 audio_devices_t *device)
642 {
643 if (session == NULL || ioHandle == NULL || device == NULL) {
644 return BAD_VALUE;
645 }
646 Parcel data, reply;
647 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
648 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
649 if (status != NO_ERROR) {
650 return status;
651 }
652 status = (status_t)reply.readInt32();
653 if (status == NO_ERROR) {
654 *session = (audio_session_t)reply.readInt32();
655 *ioHandle = (audio_io_handle_t)reply.readInt32();
656 *device = (audio_devices_t)reply.readInt32();
657 }
658 return status;
659 }
660
661 virtual status_t releaseSoundTriggerSession(audio_session_t session)
662 {
663 Parcel data, reply;
664 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
665 data.writeInt32(session);
666 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
667 if (status != NO_ERROR) {
668 return status;
669 }
670 return (status_t)reply.readInt32();
671 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700672
673 virtual audio_mode_t getPhoneState()
674 {
675 Parcel data, reply;
676 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
677 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
678 if (status != NO_ERROR) {
679 return AUDIO_MODE_INVALID;
680 }
681 return (audio_mode_t)reply.readInt32();
682 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800683
684 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
685 {
686 Parcel data, reply;
687 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
688 data.writeInt32(registration ? 1 : 0);
689 size_t size = mixes.size();
690 if (size > MAX_MIXES_PER_POLICY) {
691 size = MAX_MIXES_PER_POLICY;
692 }
693 size_t sizePosition = data.dataPosition();
694 data.writeInt32(size);
695 size_t finalSize = size;
696 for (size_t i = 0; i < size; i++) {
697 size_t position = data.dataPosition();
698 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
699 data.setDataPosition(position);
700 finalSize--;
701 }
702 }
703 if (size != finalSize) {
704 size_t position = data.dataPosition();
705 data.setDataPosition(sizePosition);
706 data.writeInt32(finalSize);
707 data.setDataPosition(position);
708 }
709 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
710 if (status == NO_ERROR) {
711 status = (status_t)reply.readInt32();
712 }
713 return status;
714 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700715};
716
717IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
718
719// ----------------------------------------------------------------------
720
721
722status_t BnAudioPolicyService::onTransact(
723 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
724{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700725 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700726 case SET_DEVICE_CONNECTION_STATE: {
727 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700728 audio_devices_t device =
729 static_cast <audio_devices_t>(data.readInt32());
730 audio_policy_dev_state_t state =
731 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700732 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800733 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700734 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
735 state,
Paul McLeane743a472015-01-28 11:07:31 -0800736 device_address,
737 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700738 return NO_ERROR;
739 } break;
740
741 case GET_DEVICE_CONNECTION_STATE: {
742 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700743 audio_devices_t device =
744 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700745 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700746 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
747 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700748 return NO_ERROR;
749 } break;
750
751 case SET_PHONE_STATE: {
752 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700753 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
754 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700755 return NO_ERROR;
756 } break;
757
Eric Laurentc2f1f072009-07-17 12:17:14 -0700758 case SET_FORCE_USE: {
759 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700760 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
761 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700762 audio_policy_forced_cfg_t config =
763 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700764 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
765 return NO_ERROR;
766 } break;
767
768 case GET_FORCE_USE: {
769 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700770 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
771 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700772 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
773 return NO_ERROR;
774 } break;
775
776 case GET_OUTPUT: {
777 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700778 audio_stream_type_t stream =
779 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700780 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800781 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700782 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700783 audio_output_flags_t flags =
784 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100785 bool hasOffloadInfo = data.readInt32() != 0;
786 audio_offload_info_t offloadInfo;
787 if (hasOffloadInfo) {
788 data.read(&offloadInfo, sizeof(audio_offload_info_t));
789 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700790 audio_io_handle_t output = getOutput(stream,
791 samplingRate,
792 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700793 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100794 flags,
795 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700796 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700797 return NO_ERROR;
798 } break;
799
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700800 case GET_OUTPUT_FOR_ATTR: {
801 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800802 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800803 bool hasAttributes = data.readInt32() != 0;
804 if (hasAttributes) {
805 data.read(&attr, sizeof(audio_attributes_t));
806 }
807 audio_session_t session = (audio_session_t)data.readInt32();
808 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
809 bool hasStream = data.readInt32() != 0;
810 if (hasStream) {
811 stream = (audio_stream_type_t)data.readInt32();
812 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700813 uint32_t samplingRate = data.readInt32();
814 audio_format_t format = (audio_format_t) data.readInt32();
815 audio_channel_mask_t channelMask = data.readInt32();
816 audio_output_flags_t flags =
817 static_cast <audio_output_flags_t>(data.readInt32());
818 bool hasOffloadInfo = data.readInt32() != 0;
819 audio_offload_info_t offloadInfo;
820 if (hasOffloadInfo) {
821 data.read(&offloadInfo, sizeof(audio_offload_info_t));
822 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800823 audio_io_handle_t output;
824 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
825 &output, session, &stream,
826 samplingRate, format, channelMask,
827 flags, hasOffloadInfo ? &offloadInfo : NULL);
828 reply->writeInt32(status);
829 reply->writeInt32(output);
830 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700831 return NO_ERROR;
832 } break;
833
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834 case START_OUTPUT: {
835 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700836 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800837 audio_stream_type_t stream =
838 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800839 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700840 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800841 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700842 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700843 return NO_ERROR;
844 } break;
845
846 case STOP_OUTPUT: {
847 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700848 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800849 audio_stream_type_t stream =
850 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800851 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700852 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800853 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700854 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700855 return NO_ERROR;
856 } break;
857
858 case RELEASE_OUTPUT: {
859 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700860 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800861 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
862 audio_session_t session = (audio_session_t)data.readInt32();
863 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700864 return NO_ERROR;
865 } break;
866
Eric Laurentcaf7f482014-11-25 17:50:47 -0800867 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700868 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800869 audio_attributes_t attr;
870 data.read(&attr, sizeof(audio_attributes_t));
871 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700872 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800873 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700874 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700875 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800876 audio_io_handle_t input;
877 status_t status = getInputForAttr(&attr, &input, session,
878 samplingRate, format, channelMask,
879 flags);
880 reply->writeInt32(status);
881 if (status == NO_ERROR) {
882 reply->writeInt32(input);
883 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700884 return NO_ERROR;
885 } break;
886
887 case START_INPUT: {
888 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700889 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700890 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
891 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700892 return NO_ERROR;
893 } break;
894
895 case STOP_INPUT: {
896 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700897 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700898 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
899 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700900 return NO_ERROR;
901 } break;
902
903 case RELEASE_INPUT: {
904 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700905 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700906 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
907 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700908 return NO_ERROR;
909 } break;
910
911 case INIT_STREAM_VOLUME: {
912 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700913 audio_stream_type_t stream =
914 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700915 int indexMin = data.readInt32();
916 int indexMax = data.readInt32();
917 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
918 return NO_ERROR;
919 } break;
920
921 case SET_STREAM_VOLUME: {
922 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700923 audio_stream_type_t stream =
924 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700925 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800926 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
927 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
928 index,
929 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700930 return NO_ERROR;
931 } break;
932
933 case GET_STREAM_VOLUME: {
934 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700935 audio_stream_type_t stream =
936 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800937 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700938 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800939 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700940 reply->writeInt32(index);
941 reply->writeInt32(static_cast <uint32_t>(status));
942 return NO_ERROR;
943 } break;
944
Eric Laurentde070132010-07-13 04:45:46 -0700945 case GET_STRATEGY_FOR_STREAM: {
946 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700947 audio_stream_type_t stream =
948 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700949 reply->writeInt32(getStrategyForStream(stream));
950 return NO_ERROR;
951 } break;
952
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800953 case GET_DEVICES_FOR_STREAM: {
954 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700955 audio_stream_type_t stream =
956 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800957 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
958 return NO_ERROR;
959 } break;
960
Eric Laurentde070132010-07-13 04:45:46 -0700961 case GET_OUTPUT_FOR_EFFECT: {
962 CHECK_INTERFACE(IAudioPolicyService, data, reply);
963 effect_descriptor_t desc;
964 data.read(&desc, sizeof(effect_descriptor_t));
965 audio_io_handle_t output = getOutputForEffect(&desc);
966 reply->writeInt32(static_cast <int>(output));
967 return NO_ERROR;
968 } break;
969
970 case REGISTER_EFFECT: {
971 CHECK_INTERFACE(IAudioPolicyService, data, reply);
972 effect_descriptor_t desc;
973 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700974 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700975 uint32_t strategy = data.readInt32();
976 int session = data.readInt32();
977 int id = data.readInt32();
978 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700979 io,
Eric Laurentde070132010-07-13 04:45:46 -0700980 strategy,
981 session,
982 id)));
983 return NO_ERROR;
984 } break;
985
986 case UNREGISTER_EFFECT: {
987 CHECK_INTERFACE(IAudioPolicyService, data, reply);
988 int id = data.readInt32();
989 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
990 return NO_ERROR;
991 } break;
992
Eric Laurentdb7c0792011-08-10 10:37:50 -0700993 case SET_EFFECT_ENABLED: {
994 CHECK_INTERFACE(IAudioPolicyService, data, reply);
995 int id = data.readInt32();
996 bool enabled = static_cast <bool>(data.readInt32());
997 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
998 return NO_ERROR;
999 } break;
1000
Eric Laurenteda6c362011-02-02 09:33:30 -08001001 case IS_STREAM_ACTIVE: {
1002 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001003 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001004 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001005 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001006 return NO_ERROR;
1007 } break;
1008
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001009 case IS_STREAM_ACTIVE_REMOTELY: {
1010 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1011 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1012 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001013 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001014 return NO_ERROR;
1015 } break;
1016
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001017 case IS_SOURCE_ACTIVE: {
1018 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1019 audio_source_t source = (audio_source_t) data.readInt32();
1020 reply->writeInt32( isSourceActive(source));
1021 return NO_ERROR;
1022 }
1023
Eric Laurent57dae992011-07-24 13:36:09 -07001024 case QUERY_DEFAULT_PRE_PROCESSING: {
1025 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1026 int audioSession = data.readInt32();
1027 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001028 if (count > AudioEffect::kMaxPreProcessing) {
1029 count = AudioEffect::kMaxPreProcessing;
1030 }
Eric Laurent57dae992011-07-24 13:36:09 -07001031 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001032 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001033 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1034 reply->writeInt32(status);
1035 if (status != NO_ERROR && status != NO_MEMORY) {
1036 retCount = 0;
1037 }
1038 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001039 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001040 if (retCount < count) {
1041 count = retCount;
1042 }
1043 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1044 }
1045 delete[] descriptors;
1046 return status;
1047 }
1048
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001049 case IS_OFFLOAD_SUPPORTED: {
1050 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1051 audio_offload_info_t info;
1052 data.read(&info, sizeof(audio_offload_info_t));
1053 bool isSupported = isOffloadSupported(info);
1054 reply->writeInt32(isSupported);
1055 return NO_ERROR;
1056 }
1057
Eric Laurent203b1a12014-04-01 10:34:16 -07001058 case LIST_AUDIO_PORTS: {
1059 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1060 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1061 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1062 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001063 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1064 numPortsReq = MAX_ITEMS_PER_LIST;
1065 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001066 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001067 struct audio_port *ports =
1068 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001069 if (ports == NULL) {
1070 reply->writeInt32(NO_MEMORY);
1071 reply->writeInt32(0);
1072 return NO_ERROR;
1073 }
1074 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001075 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1076 reply->writeInt32(status);
1077 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001078
1079 if (status == NO_ERROR) {
1080 if (numPortsReq > numPorts) {
1081 numPortsReq = numPorts;
1082 }
1083 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1084 reply->writeInt32(generation);
1085 }
1086 free(ports);
1087 return NO_ERROR;
1088 }
1089
1090 case GET_AUDIO_PORT: {
1091 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1092 struct audio_port port;
1093 data.read(&port, sizeof(struct audio_port));
1094 status_t status = getAudioPort(&port);
1095 reply->writeInt32(status);
1096 if (status == NO_ERROR) {
1097 reply->write(&port, sizeof(struct audio_port));
1098 }
1099 return NO_ERROR;
1100 }
1101
1102 case CREATE_AUDIO_PATCH: {
1103 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1104 struct audio_patch patch;
1105 data.read(&patch, sizeof(struct audio_patch));
1106 audio_patch_handle_t handle;
1107 data.read(&handle, sizeof(audio_patch_handle_t));
1108 status_t status = createAudioPatch(&patch, &handle);
1109 reply->writeInt32(status);
1110 if (status == NO_ERROR) {
1111 reply->write(&handle, sizeof(audio_patch_handle_t));
1112 }
1113 return NO_ERROR;
1114 }
1115
1116 case RELEASE_AUDIO_PATCH: {
1117 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1118 audio_patch_handle_t handle;
1119 data.read(&handle, sizeof(audio_patch_handle_t));
1120 status_t status = releaseAudioPatch(handle);
1121 reply->writeInt32(status);
1122 return NO_ERROR;
1123 }
1124
1125 case LIST_AUDIO_PATCHES: {
1126 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1127 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001128 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1129 numPatchesReq = MAX_ITEMS_PER_LIST;
1130 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001131 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001132 struct audio_patch *patches =
1133 (struct audio_patch *)calloc(numPatchesReq,
1134 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001135 if (patches == NULL) {
1136 reply->writeInt32(NO_MEMORY);
1137 reply->writeInt32(0);
1138 return NO_ERROR;
1139 }
1140 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001141 status_t status = listAudioPatches(&numPatches, patches, &generation);
1142 reply->writeInt32(status);
1143 reply->writeInt32(numPatches);
1144 if (status == NO_ERROR) {
1145 if (numPatchesReq > numPatches) {
1146 numPatchesReq = numPatches;
1147 }
1148 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1149 reply->writeInt32(generation);
1150 }
1151 free(patches);
1152 return NO_ERROR;
1153 }
1154
1155 case SET_AUDIO_PORT_CONFIG: {
1156 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1157 struct audio_port_config config;
1158 data.read(&config, sizeof(struct audio_port_config));
1159 status_t status = setAudioPortConfig(&config);
1160 reply->writeInt32(status);
1161 return NO_ERROR;
1162 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001163
Eric Laurentb52c1522014-05-20 11:27:36 -07001164 case REGISTER_CLIENT: {
1165 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1166 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1167 data.readStrongBinder());
1168 registerClient(client);
1169 return NO_ERROR;
1170 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001171
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001172 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1173 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1174 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1175 data.readStrongBinder());
1176 audio_session_t session;
1177 audio_io_handle_t ioHandle;
1178 audio_devices_t device;
1179 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1180 reply->writeInt32(status);
1181 if (status == NO_ERROR) {
1182 reply->writeInt32(session);
1183 reply->writeInt32(ioHandle);
1184 reply->writeInt32(device);
1185 }
1186 return NO_ERROR;
1187 } break;
1188
1189 case RELEASE_SOUNDTRIGGER_SESSION: {
1190 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1191 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1192 data.readStrongBinder());
1193 audio_session_t session = (audio_session_t)data.readInt32();
1194 status_t status = releaseSoundTriggerSession(session);
1195 reply->writeInt32(status);
1196 return NO_ERROR;
1197 } break;
1198
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001199 case GET_PHONE_STATE: {
1200 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1201 reply->writeInt32((int32_t)getPhoneState());
1202 return NO_ERROR;
1203 } break;
1204
Eric Laurentbaac1832014-12-01 17:52:59 -08001205 case REGISTER_POLICY_MIXES: {
1206 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1207 bool registration = data.readInt32() == 1;
1208 Vector<AudioMix> mixes;
1209 size_t size = (size_t)data.readInt32();
1210 if (size > MAX_MIXES_PER_POLICY) {
1211 size = MAX_MIXES_PER_POLICY;
1212 }
1213 for (size_t i = 0; i < size; i++) {
1214 AudioMix mix;
1215 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1216 mixes.add(mix);
1217 }
1218 }
1219 status_t status = registerPolicyMixes(mixes, registration);
1220 reply->writeInt32(status);
1221 return NO_ERROR;
1222 } break;
1223
Eric Laurentc2f1f072009-07-17 12:17:14 -07001224 default:
1225 return BBinder::onTransact(code, data, reply, flags);
1226 }
1227}
1228
1229// ----------------------------------------------------------------------------
1230
1231}; // namespace android