blob: afae7f52616c5bcc95080f1ef4b46cf00e316196 [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,
281 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700282 {
283 Parcel data, reply;
284 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800285 if (attr == NULL) {
286 ALOGE("getInputForAttr NULL attr - shouldn't happen");
287 return BAD_VALUE;
288 }
289 if (input == NULL) {
290 ALOGE("getInputForAttr NULL input - shouldn't happen");
291 return BAD_VALUE;
292 }
293 data.write(attr, sizeof(audio_attributes_t));
294 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700295 data.writeInt32(samplingRate);
296 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700297 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700298 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800299 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
300 if (status != NO_ERROR) {
301 return status;
302 }
303 status = reply.readInt32();
304 if (status != NO_ERROR) {
305 return status;
306 }
307 *input = (audio_io_handle_t)reply.readInt32();
308 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700309 }
310
Eric Laurent4dc68062014-07-28 17:26:49 -0700311 virtual status_t startInput(audio_io_handle_t input,
312 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700313 {
314 Parcel data, reply;
315 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700316 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700317 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700318 remote()->transact(START_INPUT, data, &reply);
319 return static_cast <status_t> (reply.readInt32());
320 }
321
Eric Laurent4dc68062014-07-28 17:26:49 -0700322 virtual status_t stopInput(audio_io_handle_t input,
323 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700324 {
325 Parcel data, reply;
326 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700327 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700328 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700329 remote()->transact(STOP_INPUT, data, &reply);
330 return static_cast <status_t> (reply.readInt32());
331 }
332
Eric Laurent4dc68062014-07-28 17:26:49 -0700333 virtual void releaseInput(audio_io_handle_t input,
334 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700338 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700339 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 remote()->transact(RELEASE_INPUT, data, &reply);
341 }
342
Dima Zavinfce7a472011-04-19 22:30:36 -0700343 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700344 int indexMin,
345 int indexMax)
346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
349 data.writeInt32(static_cast <uint32_t>(stream));
350 data.writeInt32(indexMin);
351 data.writeInt32(indexMax);
352 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
353 return static_cast <status_t> (reply.readInt32());
354 }
355
Eric Laurent83844cc2011-11-18 16:43:31 -0800356 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
357 int index,
358 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700359 {
360 Parcel data, reply;
361 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
362 data.writeInt32(static_cast <uint32_t>(stream));
363 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800364 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 remote()->transact(SET_STREAM_VOLUME, data, &reply);
366 return static_cast <status_t> (reply.readInt32());
367 }
368
Eric Laurent83844cc2011-11-18 16:43:31 -0800369 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
370 int *index,
371 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
375 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800376 data.writeInt32(static_cast <uint32_t>(device));
377
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 remote()->transact(GET_STREAM_VOLUME, data, &reply);
379 int lIndex = reply.readInt32();
380 if (index) *index = lIndex;
381 return static_cast <status_t> (reply.readInt32());
382 }
Eric Laurentde070132010-07-13 04:45:46 -0700383
Dima Zavinfce7a472011-04-19 22:30:36 -0700384 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700385 {
386 Parcel data, reply;
387 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
388 data.writeInt32(static_cast <uint32_t>(stream));
389 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
390 return reply.readInt32();
391 }
392
Eric Laurent63742522012-03-08 13:42:42 -0800393 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800394 {
395 Parcel data, reply;
396 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
397 data.writeInt32(static_cast <uint32_t>(stream));
398 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800399 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800400 }
401
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700402 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
406 data.write(desc, sizeof(effect_descriptor_t));
407 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
408 return static_cast <audio_io_handle_t> (reply.readInt32());
409 }
410
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700411 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700412 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700413 uint32_t strategy,
414 int session,
415 int id)
416 {
417 Parcel data, reply;
418 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
419 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700420 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700421 data.writeInt32(strategy);
422 data.writeInt32(session);
423 data.writeInt32(id);
424 remote()->transact(REGISTER_EFFECT, data, &reply);
425 return static_cast <status_t> (reply.readInt32());
426 }
427
428 virtual status_t unregisterEffect(int id)
429 {
430 Parcel data, reply;
431 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
432 data.writeInt32(id);
433 remote()->transact(UNREGISTER_EFFECT, data, &reply);
434 return static_cast <status_t> (reply.readInt32());
435 }
436
Eric Laurentdb7c0792011-08-10 10:37:50 -0700437 virtual status_t setEffectEnabled(int id, bool enabled)
438 {
439 Parcel data, reply;
440 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
441 data.writeInt32(id);
442 data.writeInt32(enabled);
443 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
444 return static_cast <status_t> (reply.readInt32());
445 }
446
Glenn Kastenfff6d712012-01-12 16:38:12 -0800447 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800448 {
449 Parcel data, reply;
450 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800451 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800452 data.writeInt32(inPastMs);
453 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
454 return reply.readInt32();
455 }
Eric Laurent57dae992011-07-24 13:36:09 -0700456
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800457 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
458 {
459 Parcel data, reply;
460 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
461 data.writeInt32((int32_t) stream);
462 data.writeInt32(inPastMs);
463 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
464 return reply.readInt32();
465 }
466
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700467 virtual bool isSourceActive(audio_source_t source) const
468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
471 data.writeInt32((int32_t) source);
472 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
473 return reply.readInt32();
474 }
475
Eric Laurent57dae992011-07-24 13:36:09 -0700476 virtual status_t queryDefaultPreProcessing(int audioSession,
477 effect_descriptor_t *descriptors,
478 uint32_t *count)
479 {
480 if (descriptors == NULL || count == NULL) {
481 return BAD_VALUE;
482 }
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
485 data.writeInt32(audioSession);
486 data.writeInt32(*count);
487 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
488 if (status != NO_ERROR) {
489 return status;
490 }
491 status = static_cast <status_t> (reply.readInt32());
492 uint32_t retCount = reply.readInt32();
493 if (retCount != 0) {
494 uint32_t numDesc = (retCount < *count) ? retCount : *count;
495 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
496 }
497 *count = retCount;
498 return status;
499 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000500
501 virtual bool isOffloadSupported(const audio_offload_info_t& info)
502 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100503 Parcel data, reply;
504 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
505 data.write(&info, sizeof(audio_offload_info_t));
506 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700507 return reply.readInt32();
508 }
509
510 virtual status_t listAudioPorts(audio_port_role_t role,
511 audio_port_type_t type,
512 unsigned int *num_ports,
513 struct audio_port *ports,
514 unsigned int *generation)
515 {
516 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
517 generation == NULL) {
518 return BAD_VALUE;
519 }
520 Parcel data, reply;
521 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
522 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
523 data.writeInt32(role);
524 data.writeInt32(type);
525 data.writeInt32(numPortsReq);
526 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
527 if (status == NO_ERROR) {
528 status = (status_t)reply.readInt32();
529 *num_ports = (unsigned int)reply.readInt32();
530 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700531 if (status == NO_ERROR) {
532 if (numPortsReq > *num_ports) {
533 numPortsReq = *num_ports;
534 }
535 if (numPortsReq > 0) {
536 reply.read(ports, numPortsReq * sizeof(struct audio_port));
537 }
538 *generation = reply.readInt32();
539 }
540 return status;
541 }
542
543 virtual status_t getAudioPort(struct audio_port *port)
544 {
545 if (port == NULL) {
546 return BAD_VALUE;
547 }
548 Parcel data, reply;
549 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
550 data.write(port, sizeof(struct audio_port));
551 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
552 if (status != NO_ERROR ||
553 (status = (status_t)reply.readInt32()) != NO_ERROR) {
554 return status;
555 }
556 reply.read(port, sizeof(struct audio_port));
557 return status;
558 }
559
560 virtual status_t createAudioPatch(const struct audio_patch *patch,
561 audio_patch_handle_t *handle)
562 {
563 if (patch == NULL || handle == NULL) {
564 return BAD_VALUE;
565 }
566 Parcel data, reply;
567 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
568 data.write(patch, sizeof(struct audio_patch));
569 data.write(handle, sizeof(audio_patch_handle_t));
570 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
571 if (status != NO_ERROR ||
572 (status = (status_t)reply.readInt32()) != NO_ERROR) {
573 return status;
574 }
575 reply.read(handle, sizeof(audio_patch_handle_t));
576 return status;
577 }
578
579 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
580 {
581 Parcel data, reply;
582 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
583 data.write(&handle, sizeof(audio_patch_handle_t));
584 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
585 if (status != NO_ERROR) {
586 status = (status_t)reply.readInt32();
587 }
588 return status;
589 }
590
591 virtual status_t listAudioPatches(unsigned int *num_patches,
592 struct audio_patch *patches,
593 unsigned int *generation)
594 {
595 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
596 generation == NULL) {
597 return BAD_VALUE;
598 }
599 Parcel data, reply;
600 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
601 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
602 data.writeInt32(numPatchesReq);
603 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
604 if (status == NO_ERROR) {
605 status = (status_t)reply.readInt32();
606 *num_patches = (unsigned int)reply.readInt32();
607 }
608 if (status == NO_ERROR) {
609 if (numPatchesReq > *num_patches) {
610 numPatchesReq = *num_patches;
611 }
612 if (numPatchesReq > 0) {
613 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
614 }
615 *generation = reply.readInt32();
616 }
617 return status;
618 }
619
620 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
621 {
622 if (config == NULL) {
623 return BAD_VALUE;
624 }
625 Parcel data, reply;
626 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
627 data.write(config, sizeof(struct audio_port_config));
628 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
629 if (status != NO_ERROR) {
630 status = (status_t)reply.readInt32();
631 }
632 return status;
633 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700634
Eric Laurentb52c1522014-05-20 11:27:36 -0700635 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
636 {
637 Parcel data, reply;
638 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800639 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700640 remote()->transact(REGISTER_CLIENT, data, &reply);
641 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700642
643 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
644 audio_io_handle_t *ioHandle,
645 audio_devices_t *device)
646 {
647 if (session == NULL || ioHandle == NULL || device == NULL) {
648 return BAD_VALUE;
649 }
650 Parcel data, reply;
651 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
652 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
653 if (status != NO_ERROR) {
654 return status;
655 }
656 status = (status_t)reply.readInt32();
657 if (status == NO_ERROR) {
658 *session = (audio_session_t)reply.readInt32();
659 *ioHandle = (audio_io_handle_t)reply.readInt32();
660 *device = (audio_devices_t)reply.readInt32();
661 }
662 return status;
663 }
664
665 virtual status_t releaseSoundTriggerSession(audio_session_t session)
666 {
667 Parcel data, reply;
668 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
669 data.writeInt32(session);
670 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
671 if (status != NO_ERROR) {
672 return status;
673 }
674 return (status_t)reply.readInt32();
675 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700676
677 virtual audio_mode_t getPhoneState()
678 {
679 Parcel data, reply;
680 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
681 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
682 if (status != NO_ERROR) {
683 return AUDIO_MODE_INVALID;
684 }
685 return (audio_mode_t)reply.readInt32();
686 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800687
688 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
689 {
690 Parcel data, reply;
691 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
692 data.writeInt32(registration ? 1 : 0);
693 size_t size = mixes.size();
694 if (size > MAX_MIXES_PER_POLICY) {
695 size = MAX_MIXES_PER_POLICY;
696 }
697 size_t sizePosition = data.dataPosition();
698 data.writeInt32(size);
699 size_t finalSize = size;
700 for (size_t i = 0; i < size; i++) {
701 size_t position = data.dataPosition();
702 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
703 data.setDataPosition(position);
704 finalSize--;
705 }
706 }
707 if (size != finalSize) {
708 size_t position = data.dataPosition();
709 data.setDataPosition(sizePosition);
710 data.writeInt32(finalSize);
711 data.setDataPosition(position);
712 }
713 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
714 if (status == NO_ERROR) {
715 status = (status_t)reply.readInt32();
716 }
717 return status;
718 }
Eric Laurent554a2772015-04-10 11:29:24 -0700719
720 virtual status_t startAudioSource(const struct audio_port_config *source,
721 const audio_attributes_t *attributes,
722 audio_io_handle_t *handle)
723 {
724 Parcel data, reply;
725 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
726 if (source == NULL || attributes == NULL || handle == NULL) {
727 return BAD_VALUE;
728 }
729 data.write(source, sizeof(struct audio_port_config));
730 data.write(attributes, sizeof(audio_attributes_t));
731 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
732 if (status != NO_ERROR) {
733 return status;
734 }
735 status = (status_t)reply.readInt32();
736 if (status != NO_ERROR) {
737 return status;
738 }
739 *handle = (audio_io_handle_t)reply.readInt32();
740 return status;
741 }
742
743 virtual status_t stopAudioSource(audio_io_handle_t handle)
744 {
745 Parcel data, reply;
746 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
747 data.writeInt32(handle);
748 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
749 if (status != NO_ERROR) {
750 return status;
751 }
752 status = (status_t)reply.readInt32();
753 return status;
754 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700755};
756
757IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
758
759// ----------------------------------------------------------------------
760
761
762status_t BnAudioPolicyService::onTransact(
763 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
764{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700765 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700766 case SET_DEVICE_CONNECTION_STATE: {
767 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700768 audio_devices_t device =
769 static_cast <audio_devices_t>(data.readInt32());
770 audio_policy_dev_state_t state =
771 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700772 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800773 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700774 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
775 state,
Paul McLeane743a472015-01-28 11:07:31 -0800776 device_address,
777 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700778 return NO_ERROR;
779 } break;
780
781 case GET_DEVICE_CONNECTION_STATE: {
782 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700783 audio_devices_t device =
784 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700785 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700786 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
787 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700788 return NO_ERROR;
789 } break;
790
791 case SET_PHONE_STATE: {
792 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700793 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
794 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700795 return NO_ERROR;
796 } break;
797
Eric Laurentc2f1f072009-07-17 12:17:14 -0700798 case SET_FORCE_USE: {
799 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700800 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
801 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700802 audio_policy_forced_cfg_t config =
803 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700804 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
805 return NO_ERROR;
806 } break;
807
808 case GET_FORCE_USE: {
809 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700810 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
811 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700812 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
813 return NO_ERROR;
814 } break;
815
816 case GET_OUTPUT: {
817 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700818 audio_stream_type_t stream =
819 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700820 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800821 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700822 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700823 audio_output_flags_t flags =
824 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100825 bool hasOffloadInfo = data.readInt32() != 0;
826 audio_offload_info_t offloadInfo;
827 if (hasOffloadInfo) {
828 data.read(&offloadInfo, sizeof(audio_offload_info_t));
829 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700830 audio_io_handle_t output = getOutput(stream,
831 samplingRate,
832 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700833 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100834 flags,
835 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700836 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700837 return NO_ERROR;
838 } break;
839
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700840 case GET_OUTPUT_FOR_ATTR: {
841 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800842 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800843 bool hasAttributes = data.readInt32() != 0;
844 if (hasAttributes) {
845 data.read(&attr, sizeof(audio_attributes_t));
846 }
847 audio_session_t session = (audio_session_t)data.readInt32();
848 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
849 bool hasStream = data.readInt32() != 0;
850 if (hasStream) {
851 stream = (audio_stream_type_t)data.readInt32();
852 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700853 uint32_t samplingRate = data.readInt32();
854 audio_format_t format = (audio_format_t) data.readInt32();
855 audio_channel_mask_t channelMask = data.readInt32();
856 audio_output_flags_t flags =
857 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700858 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700859 bool hasOffloadInfo = data.readInt32() != 0;
860 audio_offload_info_t offloadInfo;
861 if (hasOffloadInfo) {
862 data.read(&offloadInfo, sizeof(audio_offload_info_t));
863 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800864 audio_io_handle_t output;
865 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
866 &output, session, &stream,
867 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700868 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800869 reply->writeInt32(status);
870 reply->writeInt32(output);
871 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700872 return NO_ERROR;
873 } break;
874
Eric Laurentc2f1f072009-07-17 12:17:14 -0700875 case START_OUTPUT: {
876 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700877 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800878 audio_stream_type_t stream =
879 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800880 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700881 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800882 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700883 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700884 return NO_ERROR;
885 } break;
886
887 case STOP_OUTPUT: {
888 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700889 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800890 audio_stream_type_t stream =
891 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800892 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700893 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800894 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700895 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700896 return NO_ERROR;
897 } break;
898
899 case RELEASE_OUTPUT: {
900 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700901 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800902 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
903 audio_session_t session = (audio_session_t)data.readInt32();
904 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700905 return NO_ERROR;
906 } break;
907
Eric Laurentcaf7f482014-11-25 17:50:47 -0800908 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700909 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800910 audio_attributes_t attr;
911 data.read(&attr, sizeof(audio_attributes_t));
912 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700913 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800914 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700915 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700916 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800917 audio_io_handle_t input;
918 status_t status = getInputForAttr(&attr, &input, session,
919 samplingRate, format, channelMask,
920 flags);
921 reply->writeInt32(status);
922 if (status == NO_ERROR) {
923 reply->writeInt32(input);
924 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700925 return NO_ERROR;
926 } break;
927
928 case START_INPUT: {
929 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700930 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700931 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
932 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700933 return NO_ERROR;
934 } break;
935
936 case STOP_INPUT: {
937 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700938 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700939 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
940 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700941 return NO_ERROR;
942 } break;
943
944 case RELEASE_INPUT: {
945 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700946 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700947 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
948 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700949 return NO_ERROR;
950 } break;
951
952 case INIT_STREAM_VOLUME: {
953 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700954 audio_stream_type_t stream =
955 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700956 int indexMin = data.readInt32();
957 int indexMax = data.readInt32();
958 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
959 return NO_ERROR;
960 } break;
961
962 case SET_STREAM_VOLUME: {
963 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700964 audio_stream_type_t stream =
965 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700966 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800967 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
968 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
969 index,
970 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700971 return NO_ERROR;
972 } break;
973
974 case GET_STREAM_VOLUME: {
975 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700976 audio_stream_type_t stream =
977 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800978 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700979 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800980 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700981 reply->writeInt32(index);
982 reply->writeInt32(static_cast <uint32_t>(status));
983 return NO_ERROR;
984 } break;
985
Eric Laurentde070132010-07-13 04:45:46 -0700986 case GET_STRATEGY_FOR_STREAM: {
987 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700988 audio_stream_type_t stream =
989 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700990 reply->writeInt32(getStrategyForStream(stream));
991 return NO_ERROR;
992 } break;
993
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800994 case GET_DEVICES_FOR_STREAM: {
995 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700996 audio_stream_type_t stream =
997 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800998 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
999 return NO_ERROR;
1000 } break;
1001
Eric Laurentde070132010-07-13 04:45:46 -07001002 case GET_OUTPUT_FOR_EFFECT: {
1003 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1004 effect_descriptor_t desc;
1005 data.read(&desc, sizeof(effect_descriptor_t));
1006 audio_io_handle_t output = getOutputForEffect(&desc);
1007 reply->writeInt32(static_cast <int>(output));
1008 return NO_ERROR;
1009 } break;
1010
1011 case REGISTER_EFFECT: {
1012 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1013 effect_descriptor_t desc;
1014 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001015 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001016 uint32_t strategy = data.readInt32();
1017 int session = data.readInt32();
1018 int id = data.readInt32();
1019 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001020 io,
Eric Laurentde070132010-07-13 04:45:46 -07001021 strategy,
1022 session,
1023 id)));
1024 return NO_ERROR;
1025 } break;
1026
1027 case UNREGISTER_EFFECT: {
1028 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1029 int id = data.readInt32();
1030 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1031 return NO_ERROR;
1032 } break;
1033
Eric Laurentdb7c0792011-08-10 10:37:50 -07001034 case SET_EFFECT_ENABLED: {
1035 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1036 int id = data.readInt32();
1037 bool enabled = static_cast <bool>(data.readInt32());
1038 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1039 return NO_ERROR;
1040 } break;
1041
Eric Laurenteda6c362011-02-02 09:33:30 -08001042 case IS_STREAM_ACTIVE: {
1043 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001044 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001045 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001046 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001047 return NO_ERROR;
1048 } break;
1049
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001050 case IS_STREAM_ACTIVE_REMOTELY: {
1051 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1052 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1053 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001054 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001055 return NO_ERROR;
1056 } break;
1057
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001058 case IS_SOURCE_ACTIVE: {
1059 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1060 audio_source_t source = (audio_source_t) data.readInt32();
1061 reply->writeInt32( isSourceActive(source));
1062 return NO_ERROR;
1063 }
1064
Eric Laurent57dae992011-07-24 13:36:09 -07001065 case QUERY_DEFAULT_PRE_PROCESSING: {
1066 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1067 int audioSession = data.readInt32();
1068 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001069 if (count > AudioEffect::kMaxPreProcessing) {
1070 count = AudioEffect::kMaxPreProcessing;
1071 }
Eric Laurent57dae992011-07-24 13:36:09 -07001072 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001073 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001074 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1075 reply->writeInt32(status);
1076 if (status != NO_ERROR && status != NO_MEMORY) {
1077 retCount = 0;
1078 }
1079 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001080 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001081 if (retCount < count) {
1082 count = retCount;
1083 }
1084 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1085 }
1086 delete[] descriptors;
1087 return status;
1088 }
1089
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001090 case IS_OFFLOAD_SUPPORTED: {
1091 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1092 audio_offload_info_t info;
1093 data.read(&info, sizeof(audio_offload_info_t));
1094 bool isSupported = isOffloadSupported(info);
1095 reply->writeInt32(isSupported);
1096 return NO_ERROR;
1097 }
1098
Eric Laurent203b1a12014-04-01 10:34:16 -07001099 case LIST_AUDIO_PORTS: {
1100 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1101 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1102 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1103 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001104 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1105 numPortsReq = MAX_ITEMS_PER_LIST;
1106 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001107 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001108 struct audio_port *ports =
1109 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001110 if (ports == NULL) {
1111 reply->writeInt32(NO_MEMORY);
1112 reply->writeInt32(0);
1113 return NO_ERROR;
1114 }
1115 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001116 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1117 reply->writeInt32(status);
1118 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001119
1120 if (status == NO_ERROR) {
1121 if (numPortsReq > numPorts) {
1122 numPortsReq = numPorts;
1123 }
1124 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1125 reply->writeInt32(generation);
1126 }
1127 free(ports);
1128 return NO_ERROR;
1129 }
1130
1131 case GET_AUDIO_PORT: {
1132 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1133 struct audio_port port;
1134 data.read(&port, sizeof(struct audio_port));
1135 status_t status = getAudioPort(&port);
1136 reply->writeInt32(status);
1137 if (status == NO_ERROR) {
1138 reply->write(&port, sizeof(struct audio_port));
1139 }
1140 return NO_ERROR;
1141 }
1142
1143 case CREATE_AUDIO_PATCH: {
1144 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1145 struct audio_patch patch;
1146 data.read(&patch, sizeof(struct audio_patch));
1147 audio_patch_handle_t handle;
1148 data.read(&handle, sizeof(audio_patch_handle_t));
1149 status_t status = createAudioPatch(&patch, &handle);
1150 reply->writeInt32(status);
1151 if (status == NO_ERROR) {
1152 reply->write(&handle, sizeof(audio_patch_handle_t));
1153 }
1154 return NO_ERROR;
1155 }
1156
1157 case RELEASE_AUDIO_PATCH: {
1158 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1159 audio_patch_handle_t handle;
1160 data.read(&handle, sizeof(audio_patch_handle_t));
1161 status_t status = releaseAudioPatch(handle);
1162 reply->writeInt32(status);
1163 return NO_ERROR;
1164 }
1165
1166 case LIST_AUDIO_PATCHES: {
1167 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1168 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001169 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1170 numPatchesReq = MAX_ITEMS_PER_LIST;
1171 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001172 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001173 struct audio_patch *patches =
1174 (struct audio_patch *)calloc(numPatchesReq,
1175 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001176 if (patches == NULL) {
1177 reply->writeInt32(NO_MEMORY);
1178 reply->writeInt32(0);
1179 return NO_ERROR;
1180 }
1181 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001182 status_t status = listAudioPatches(&numPatches, patches, &generation);
1183 reply->writeInt32(status);
1184 reply->writeInt32(numPatches);
1185 if (status == NO_ERROR) {
1186 if (numPatchesReq > numPatches) {
1187 numPatchesReq = numPatches;
1188 }
1189 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1190 reply->writeInt32(generation);
1191 }
1192 free(patches);
1193 return NO_ERROR;
1194 }
1195
1196 case SET_AUDIO_PORT_CONFIG: {
1197 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1198 struct audio_port_config config;
1199 data.read(&config, sizeof(struct audio_port_config));
1200 status_t status = setAudioPortConfig(&config);
1201 reply->writeInt32(status);
1202 return NO_ERROR;
1203 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001204
Eric Laurentb52c1522014-05-20 11:27:36 -07001205 case REGISTER_CLIENT: {
1206 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1207 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1208 data.readStrongBinder());
1209 registerClient(client);
1210 return NO_ERROR;
1211 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001212
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001213 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1214 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1215 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1216 data.readStrongBinder());
1217 audio_session_t session;
1218 audio_io_handle_t ioHandle;
1219 audio_devices_t device;
1220 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1221 reply->writeInt32(status);
1222 if (status == NO_ERROR) {
1223 reply->writeInt32(session);
1224 reply->writeInt32(ioHandle);
1225 reply->writeInt32(device);
1226 }
1227 return NO_ERROR;
1228 } break;
1229
1230 case RELEASE_SOUNDTRIGGER_SESSION: {
1231 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1232 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1233 data.readStrongBinder());
1234 audio_session_t session = (audio_session_t)data.readInt32();
1235 status_t status = releaseSoundTriggerSession(session);
1236 reply->writeInt32(status);
1237 return NO_ERROR;
1238 } break;
1239
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001240 case GET_PHONE_STATE: {
1241 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1242 reply->writeInt32((int32_t)getPhoneState());
1243 return NO_ERROR;
1244 } break;
1245
Eric Laurentbaac1832014-12-01 17:52:59 -08001246 case REGISTER_POLICY_MIXES: {
1247 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1248 bool registration = data.readInt32() == 1;
1249 Vector<AudioMix> mixes;
1250 size_t size = (size_t)data.readInt32();
1251 if (size > MAX_MIXES_PER_POLICY) {
1252 size = MAX_MIXES_PER_POLICY;
1253 }
1254 for (size_t i = 0; i < size; i++) {
1255 AudioMix mix;
1256 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1257 mixes.add(mix);
1258 }
1259 }
1260 status_t status = registerPolicyMixes(mixes, registration);
1261 reply->writeInt32(status);
1262 return NO_ERROR;
1263 } break;
1264
Eric Laurent554a2772015-04-10 11:29:24 -07001265 case START_AUDIO_SOURCE: {
1266 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1267 struct audio_port_config source;
1268 data.read(&source, sizeof(struct audio_port_config));
1269 audio_attributes_t attributes;
1270 data.read(&attributes, sizeof(audio_attributes_t));
1271 audio_io_handle_t handle;
1272 status_t status = startAudioSource(&source, &attributes, &handle);
1273 reply->writeInt32(status);
1274 reply->writeInt32(handle);
1275 return NO_ERROR;
1276 } break;
1277
1278 case STOP_AUDIO_SOURCE: {
1279 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1280 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1281 status_t status = stopAudioSource(handle);
1282 reply->writeInt32(status);
1283 return NO_ERROR;
1284 } break;
1285
Eric Laurentc2f1f072009-07-17 12:17:14 -07001286 default:
1287 return BBinder::onTransact(code, data, reply, flags);
1288 }
1289}
1290
1291// ----------------------------------------------------------------------------
1292
Glenn Kasten40bc9062015-03-20 09:09:33 -07001293} // namespace android