blob: 5873a30abc5bb181ee2d76c2af3f086d1cc4a1b2 [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,
72 GET_PHONE_STATE
Eric Laurentc2f1f072009-07-17 12:17:14 -070073};
74
75class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
76{
77public:
78 BpAudioPolicyService(const sp<IBinder>& impl)
79 : BpInterface<IAudioPolicyService>(impl)
80 {
81 }
82
83 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070084 audio_devices_t device,
85 audio_policy_dev_state_t state,
Eric Laurentc2f1f072009-07-17 12:17:14 -070086 const char *device_address)
87 {
88 Parcel data, reply;
89 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
90 data.writeInt32(static_cast <uint32_t>(device));
91 data.writeInt32(static_cast <uint32_t>(state));
92 data.writeCString(device_address);
93 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
94 return static_cast <status_t> (reply.readInt32());
95 }
96
Dima Zavinfce7a472011-04-19 22:30:36 -070097 virtual audio_policy_dev_state_t getDeviceConnectionState(
98 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -070099 const char *device_address)
100 {
101 Parcel data, reply;
102 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
103 data.writeInt32(static_cast <uint32_t>(device));
104 data.writeCString(device_address);
105 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700106 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700107 }
108
Glenn Kastenf78aee72012-01-04 11:00:47 -0800109 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
113 data.writeInt32(state);
114 remote()->transact(SET_PHONE_STATE, data, &reply);
115 return static_cast <status_t> (reply.readInt32());
116 }
117
Dima Zavinfce7a472011-04-19 22:30:36 -0700118 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700119 {
120 Parcel data, reply;
121 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
122 data.writeInt32(static_cast <uint32_t>(usage));
123 data.writeInt32(static_cast <uint32_t>(config));
124 remote()->transact(SET_FORCE_USE, data, &reply);
125 return static_cast <status_t> (reply.readInt32());
126 }
127
Dima Zavinfce7a472011-04-19 22:30:36 -0700128 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 {
130 Parcel data, reply;
131 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
132 data.writeInt32(static_cast <uint32_t>(usage));
133 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700134 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700135 }
136
137 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700138 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700139 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800140 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700141 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000142 audio_output_flags_t flags,
143 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700144 {
145 Parcel data, reply;
146 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
147 data.writeInt32(static_cast <uint32_t>(stream));
148 data.writeInt32(samplingRate);
149 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700150 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700151 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800152 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100153 if (offloadInfo == NULL) {
154 data.writeInt32(0);
155 } else {
156 data.writeInt32(1);
157 data.write(offloadInfo, sizeof(audio_offload_info_t));
158 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700159 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700160 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700161 }
162
Eric Laurente83b55d2014-11-14 10:06:21 -0800163 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
164 audio_io_handle_t *output,
165 audio_session_t session,
166 audio_stream_type_t *stream,
167 uint32_t samplingRate,
168 audio_format_t format,
169 audio_channel_mask_t channelMask,
170 audio_output_flags_t flags,
171 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700172 {
173 Parcel data, reply;
174 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
175 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800176 if (stream == NULL) {
177 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
178 return BAD_VALUE;
179 }
180 if (*stream == AUDIO_STREAM_DEFAULT) {
181 ALOGE("getOutputForAttr unspecified stream type");
182 return BAD_VALUE;
183 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700184 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800185 if (output == NULL) {
186 ALOGE("getOutputForAttr NULL output - shouldn't happen");
187 return BAD_VALUE;
188 }
189 if (attr == NULL) {
190 data.writeInt32(0);
191 } else {
192 data.writeInt32(1);
193 data.write(attr, sizeof(audio_attributes_t));
194 }
195 data.writeInt32(session);
196 if (stream == NULL) {
197 data.writeInt32(0);
198 } else {
199 data.writeInt32(1);
200 data.writeInt32(*stream);
201 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700202 data.writeInt32(samplingRate);
203 data.writeInt32(static_cast <uint32_t>(format));
204 data.writeInt32(channelMask);
205 data.writeInt32(static_cast <uint32_t>(flags));
206 // hasOffloadInfo
207 if (offloadInfo == NULL) {
208 data.writeInt32(0);
209 } else {
210 data.writeInt32(1);
211 data.write(offloadInfo, sizeof(audio_offload_info_t));
212 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800213 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
214 if (status != NO_ERROR) {
215 return status;
216 }
217 status = (status_t)reply.readInt32();
218 if (status != NO_ERROR) {
219 return status;
220 }
221 *output = (audio_io_handle_t)reply.readInt32();
222 if (stream != NULL) {
223 *stream = (audio_stream_type_t)reply.readInt32();
224 }
225 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700226 }
227
Eric Laurentde070132010-07-13 04:45:46 -0700228 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700229 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800230 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700231 {
232 Parcel data, reply;
233 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700234 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800235 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800236 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700237 remote()->transact(START_OUTPUT, data, &reply);
238 return static_cast <status_t> (reply.readInt32());
239 }
240
Eric Laurentde070132010-07-13 04:45:46 -0700241 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700242 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800243 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700244 {
245 Parcel data, reply;
246 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700247 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800248 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800249 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700250 remote()->transact(STOP_OUTPUT, data, &reply);
251 return static_cast <status_t> (reply.readInt32());
252 }
253
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 virtual void releaseOutput(audio_io_handle_t output,
255 audio_stream_type_t stream,
256 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700257 {
258 Parcel data, reply;
259 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700260 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800261 data.writeInt32((int32_t)stream);
262 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700263 remote()->transact(RELEASE_OUTPUT, data, &reply);
264 }
265
Eric Laurentcaf7f482014-11-25 17:50:47 -0800266 virtual status_t getInputForAttr(const audio_attributes_t *attr,
267 audio_io_handle_t *input,
268 audio_session_t session,
269 uint32_t samplingRate,
270 audio_format_t format,
271 audio_channel_mask_t channelMask,
272 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800276 if (attr == NULL) {
277 ALOGE("getInputForAttr NULL attr - shouldn't happen");
278 return BAD_VALUE;
279 }
280 if (input == NULL) {
281 ALOGE("getInputForAttr NULL input - shouldn't happen");
282 return BAD_VALUE;
283 }
284 data.write(attr, sizeof(audio_attributes_t));
285 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700286 data.writeInt32(samplingRate);
287 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700288 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700289 data.writeInt32(flags);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800290 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
291 if (status != NO_ERROR) {
292 return status;
293 }
294 status = reply.readInt32();
295 if (status != NO_ERROR) {
296 return status;
297 }
298 *input = (audio_io_handle_t)reply.readInt32();
299 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700300 }
301
Eric Laurent4dc68062014-07-28 17:26:49 -0700302 virtual status_t startInput(audio_io_handle_t input,
303 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700304 {
305 Parcel data, reply;
306 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700307 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700308 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700309 remote()->transact(START_INPUT, data, &reply);
310 return static_cast <status_t> (reply.readInt32());
311 }
312
Eric Laurent4dc68062014-07-28 17:26:49 -0700313 virtual status_t stopInput(audio_io_handle_t input,
314 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700318 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700319 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700320 remote()->transact(STOP_INPUT, data, &reply);
321 return static_cast <status_t> (reply.readInt32());
322 }
323
Eric Laurent4dc68062014-07-28 17:26:49 -0700324 virtual void releaseInput(audio_io_handle_t input,
325 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700329 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700330 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700331 remote()->transact(RELEASE_INPUT, data, &reply);
332 }
333
Dima Zavinfce7a472011-04-19 22:30:36 -0700334 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 int indexMin,
336 int indexMax)
337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
340 data.writeInt32(static_cast <uint32_t>(stream));
341 data.writeInt32(indexMin);
342 data.writeInt32(indexMax);
343 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
344 return static_cast <status_t> (reply.readInt32());
345 }
346
Eric Laurent83844cc2011-11-18 16:43:31 -0800347 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
348 int index,
349 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 {
351 Parcel data, reply;
352 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
353 data.writeInt32(static_cast <uint32_t>(stream));
354 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800355 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 remote()->transact(SET_STREAM_VOLUME, data, &reply);
357 return static_cast <status_t> (reply.readInt32());
358 }
359
Eric Laurent83844cc2011-11-18 16:43:31 -0800360 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
361 int *index,
362 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700363 {
364 Parcel data, reply;
365 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
366 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800367 data.writeInt32(static_cast <uint32_t>(device));
368
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 remote()->transact(GET_STREAM_VOLUME, data, &reply);
370 int lIndex = reply.readInt32();
371 if (index) *index = lIndex;
372 return static_cast <status_t> (reply.readInt32());
373 }
Eric Laurentde070132010-07-13 04:45:46 -0700374
Dima Zavinfce7a472011-04-19 22:30:36 -0700375 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700376 {
377 Parcel data, reply;
378 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
379 data.writeInt32(static_cast <uint32_t>(stream));
380 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
381 return reply.readInt32();
382 }
383
Eric Laurent63742522012-03-08 13:42:42 -0800384 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800385 {
386 Parcel data, reply;
387 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
388 data.writeInt32(static_cast <uint32_t>(stream));
389 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800390 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800391 }
392
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700393 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700394 {
395 Parcel data, reply;
396 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
397 data.write(desc, sizeof(effect_descriptor_t));
398 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
399 return static_cast <audio_io_handle_t> (reply.readInt32());
400 }
401
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700402 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700403 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700404 uint32_t strategy,
405 int session,
406 int id)
407 {
408 Parcel data, reply;
409 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
410 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700411 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700412 data.writeInt32(strategy);
413 data.writeInt32(session);
414 data.writeInt32(id);
415 remote()->transact(REGISTER_EFFECT, data, &reply);
416 return static_cast <status_t> (reply.readInt32());
417 }
418
419 virtual status_t unregisterEffect(int id)
420 {
421 Parcel data, reply;
422 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
423 data.writeInt32(id);
424 remote()->transact(UNREGISTER_EFFECT, data, &reply);
425 return static_cast <status_t> (reply.readInt32());
426 }
427
Eric Laurentdb7c0792011-08-10 10:37:50 -0700428 virtual status_t setEffectEnabled(int id, bool enabled)
429 {
430 Parcel data, reply;
431 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
432 data.writeInt32(id);
433 data.writeInt32(enabled);
434 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
435 return static_cast <status_t> (reply.readInt32());
436 }
437
Glenn Kastenfff6d712012-01-12 16:38:12 -0800438 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800439 {
440 Parcel data, reply;
441 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800442 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800443 data.writeInt32(inPastMs);
444 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
445 return reply.readInt32();
446 }
Eric Laurent57dae992011-07-24 13:36:09 -0700447
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800448 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
449 {
450 Parcel data, reply;
451 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
452 data.writeInt32((int32_t) stream);
453 data.writeInt32(inPastMs);
454 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
455 return reply.readInt32();
456 }
457
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700458 virtual bool isSourceActive(audio_source_t source) const
459 {
460 Parcel data, reply;
461 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
462 data.writeInt32((int32_t) source);
463 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
464 return reply.readInt32();
465 }
466
Eric Laurent57dae992011-07-24 13:36:09 -0700467 virtual status_t queryDefaultPreProcessing(int audioSession,
468 effect_descriptor_t *descriptors,
469 uint32_t *count)
470 {
471 if (descriptors == NULL || count == NULL) {
472 return BAD_VALUE;
473 }
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
476 data.writeInt32(audioSession);
477 data.writeInt32(*count);
478 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
479 if (status != NO_ERROR) {
480 return status;
481 }
482 status = static_cast <status_t> (reply.readInt32());
483 uint32_t retCount = reply.readInt32();
484 if (retCount != 0) {
485 uint32_t numDesc = (retCount < *count) ? retCount : *count;
486 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
487 }
488 *count = retCount;
489 return status;
490 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000491
492 virtual bool isOffloadSupported(const audio_offload_info_t& info)
493 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
496 data.write(&info, sizeof(audio_offload_info_t));
497 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700498 return reply.readInt32();
499 }
500
501 virtual status_t listAudioPorts(audio_port_role_t role,
502 audio_port_type_t type,
503 unsigned int *num_ports,
504 struct audio_port *ports,
505 unsigned int *generation)
506 {
507 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
508 generation == NULL) {
509 return BAD_VALUE;
510 }
511 Parcel data, reply;
512 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
513 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
514 data.writeInt32(role);
515 data.writeInt32(type);
516 data.writeInt32(numPortsReq);
517 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
518 if (status == NO_ERROR) {
519 status = (status_t)reply.readInt32();
520 *num_ports = (unsigned int)reply.readInt32();
521 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700522 if (status == NO_ERROR) {
523 if (numPortsReq > *num_ports) {
524 numPortsReq = *num_ports;
525 }
526 if (numPortsReq > 0) {
527 reply.read(ports, numPortsReq * sizeof(struct audio_port));
528 }
529 *generation = reply.readInt32();
530 }
531 return status;
532 }
533
534 virtual status_t getAudioPort(struct audio_port *port)
535 {
536 if (port == NULL) {
537 return BAD_VALUE;
538 }
539 Parcel data, reply;
540 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
541 data.write(port, sizeof(struct audio_port));
542 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
543 if (status != NO_ERROR ||
544 (status = (status_t)reply.readInt32()) != NO_ERROR) {
545 return status;
546 }
547 reply.read(port, sizeof(struct audio_port));
548 return status;
549 }
550
551 virtual status_t createAudioPatch(const struct audio_patch *patch,
552 audio_patch_handle_t *handle)
553 {
554 if (patch == NULL || handle == NULL) {
555 return BAD_VALUE;
556 }
557 Parcel data, reply;
558 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
559 data.write(patch, sizeof(struct audio_patch));
560 data.write(handle, sizeof(audio_patch_handle_t));
561 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
562 if (status != NO_ERROR ||
563 (status = (status_t)reply.readInt32()) != NO_ERROR) {
564 return status;
565 }
566 reply.read(handle, sizeof(audio_patch_handle_t));
567 return status;
568 }
569
570 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
571 {
572 Parcel data, reply;
573 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
574 data.write(&handle, sizeof(audio_patch_handle_t));
575 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
576 if (status != NO_ERROR) {
577 status = (status_t)reply.readInt32();
578 }
579 return status;
580 }
581
582 virtual status_t listAudioPatches(unsigned int *num_patches,
583 struct audio_patch *patches,
584 unsigned int *generation)
585 {
586 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
587 generation == NULL) {
588 return BAD_VALUE;
589 }
590 Parcel data, reply;
591 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
592 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
593 data.writeInt32(numPatchesReq);
594 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
595 if (status == NO_ERROR) {
596 status = (status_t)reply.readInt32();
597 *num_patches = (unsigned int)reply.readInt32();
598 }
599 if (status == NO_ERROR) {
600 if (numPatchesReq > *num_patches) {
601 numPatchesReq = *num_patches;
602 }
603 if (numPatchesReq > 0) {
604 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
605 }
606 *generation = reply.readInt32();
607 }
608 return status;
609 }
610
611 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
612 {
613 if (config == NULL) {
614 return BAD_VALUE;
615 }
616 Parcel data, reply;
617 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
618 data.write(config, sizeof(struct audio_port_config));
619 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
620 if (status != NO_ERROR) {
621 status = (status_t)reply.readInt32();
622 }
623 return status;
624 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700625
Eric Laurentb52c1522014-05-20 11:27:36 -0700626 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
627 {
628 Parcel data, reply;
629 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
630 data.writeStrongBinder(client->asBinder());
631 remote()->transact(REGISTER_CLIENT, data, &reply);
632 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700633
634 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
635 audio_io_handle_t *ioHandle,
636 audio_devices_t *device)
637 {
638 if (session == NULL || ioHandle == NULL || device == NULL) {
639 return BAD_VALUE;
640 }
641 Parcel data, reply;
642 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
643 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
644 if (status != NO_ERROR) {
645 return status;
646 }
647 status = (status_t)reply.readInt32();
648 if (status == NO_ERROR) {
649 *session = (audio_session_t)reply.readInt32();
650 *ioHandle = (audio_io_handle_t)reply.readInt32();
651 *device = (audio_devices_t)reply.readInt32();
652 }
653 return status;
654 }
655
656 virtual status_t releaseSoundTriggerSession(audio_session_t session)
657 {
658 Parcel data, reply;
659 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
660 data.writeInt32(session);
661 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
662 if (status != NO_ERROR) {
663 return status;
664 }
665 return (status_t)reply.readInt32();
666 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700667
668 virtual audio_mode_t getPhoneState()
669 {
670 Parcel data, reply;
671 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
672 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
673 if (status != NO_ERROR) {
674 return AUDIO_MODE_INVALID;
675 }
676 return (audio_mode_t)reply.readInt32();
677 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700678};
679
680IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
681
682// ----------------------------------------------------------------------
683
684
685status_t BnAudioPolicyService::onTransact(
686 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
687{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700688 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700689 case SET_DEVICE_CONNECTION_STATE: {
690 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700691 audio_devices_t device =
692 static_cast <audio_devices_t>(data.readInt32());
693 audio_policy_dev_state_t state =
694 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700695 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700696 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
697 state,
698 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700699 return NO_ERROR;
700 } break;
701
702 case GET_DEVICE_CONNECTION_STATE: {
703 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700704 audio_devices_t device =
705 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700706 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700707 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
708 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700709 return NO_ERROR;
710 } break;
711
712 case SET_PHONE_STATE: {
713 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700714 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
715 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700716 return NO_ERROR;
717 } break;
718
Eric Laurentc2f1f072009-07-17 12:17:14 -0700719 case SET_FORCE_USE: {
720 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700721 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
722 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700723 audio_policy_forced_cfg_t config =
724 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700725 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
726 return NO_ERROR;
727 } break;
728
729 case GET_FORCE_USE: {
730 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700731 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
732 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700733 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
734 return NO_ERROR;
735 } break;
736
737 case GET_OUTPUT: {
738 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700739 audio_stream_type_t stream =
740 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700741 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800742 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700743 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700744 audio_output_flags_t flags =
745 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100746 bool hasOffloadInfo = data.readInt32() != 0;
747 audio_offload_info_t offloadInfo;
748 if (hasOffloadInfo) {
749 data.read(&offloadInfo, sizeof(audio_offload_info_t));
750 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700751 audio_io_handle_t output = getOutput(stream,
752 samplingRate,
753 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700754 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100755 flags,
756 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700757 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700758 return NO_ERROR;
759 } break;
760
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700761 case GET_OUTPUT_FOR_ATTR: {
762 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800763 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800764 bool hasAttributes = data.readInt32() != 0;
765 if (hasAttributes) {
766 data.read(&attr, sizeof(audio_attributes_t));
767 }
768 audio_session_t session = (audio_session_t)data.readInt32();
769 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
770 bool hasStream = data.readInt32() != 0;
771 if (hasStream) {
772 stream = (audio_stream_type_t)data.readInt32();
773 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700774 uint32_t samplingRate = data.readInt32();
775 audio_format_t format = (audio_format_t) data.readInt32();
776 audio_channel_mask_t channelMask = data.readInt32();
777 audio_output_flags_t flags =
778 static_cast <audio_output_flags_t>(data.readInt32());
779 bool hasOffloadInfo = data.readInt32() != 0;
780 audio_offload_info_t offloadInfo;
781 if (hasOffloadInfo) {
782 data.read(&offloadInfo, sizeof(audio_offload_info_t));
783 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800784 audio_io_handle_t output;
785 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
786 &output, session, &stream,
787 samplingRate, format, channelMask,
788 flags, hasOffloadInfo ? &offloadInfo : NULL);
789 reply->writeInt32(status);
790 reply->writeInt32(output);
791 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700792 return NO_ERROR;
793 } break;
794
Eric Laurentc2f1f072009-07-17 12:17:14 -0700795 case START_OUTPUT: {
796 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700797 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800798 audio_stream_type_t stream =
799 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800800 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700801 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800802 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700803 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700804 return NO_ERROR;
805 } break;
806
807 case STOP_OUTPUT: {
808 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700809 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800810 audio_stream_type_t stream =
811 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800812 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700813 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800814 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700815 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700816 return NO_ERROR;
817 } break;
818
819 case RELEASE_OUTPUT: {
820 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700821 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800822 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
823 audio_session_t session = (audio_session_t)data.readInt32();
824 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700825 return NO_ERROR;
826 } break;
827
Eric Laurentcaf7f482014-11-25 17:50:47 -0800828 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700829 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800830 audio_attributes_t attr;
831 data.read(&attr, sizeof(audio_attributes_t));
832 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700833 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800834 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700835 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700836 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800837 audio_io_handle_t input;
838 status_t status = getInputForAttr(&attr, &input, session,
839 samplingRate, format, channelMask,
840 flags);
841 reply->writeInt32(status);
842 if (status == NO_ERROR) {
843 reply->writeInt32(input);
844 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845 return NO_ERROR;
846 } break;
847
848 case START_INPUT: {
849 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700850 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700851 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
852 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700853 return NO_ERROR;
854 } break;
855
856 case STOP_INPUT: {
857 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700858 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700859 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
860 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700861 return NO_ERROR;
862 } break;
863
864 case RELEASE_INPUT: {
865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700866 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700867 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
868 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700869 return NO_ERROR;
870 } break;
871
872 case INIT_STREAM_VOLUME: {
873 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700874 audio_stream_type_t stream =
875 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700876 int indexMin = data.readInt32();
877 int indexMax = data.readInt32();
878 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
879 return NO_ERROR;
880 } break;
881
882 case SET_STREAM_VOLUME: {
883 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700884 audio_stream_type_t stream =
885 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700886 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800887 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
888 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
889 index,
890 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700891 return NO_ERROR;
892 } break;
893
894 case GET_STREAM_VOLUME: {
895 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700896 audio_stream_type_t stream =
897 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800898 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700899 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800900 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700901 reply->writeInt32(index);
902 reply->writeInt32(static_cast <uint32_t>(status));
903 return NO_ERROR;
904 } break;
905
Eric Laurentde070132010-07-13 04:45:46 -0700906 case GET_STRATEGY_FOR_STREAM: {
907 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700908 audio_stream_type_t stream =
909 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700910 reply->writeInt32(getStrategyForStream(stream));
911 return NO_ERROR;
912 } break;
913
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800914 case GET_DEVICES_FOR_STREAM: {
915 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700916 audio_stream_type_t stream =
917 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800918 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
919 return NO_ERROR;
920 } break;
921
Eric Laurentde070132010-07-13 04:45:46 -0700922 case GET_OUTPUT_FOR_EFFECT: {
923 CHECK_INTERFACE(IAudioPolicyService, data, reply);
924 effect_descriptor_t desc;
925 data.read(&desc, sizeof(effect_descriptor_t));
926 audio_io_handle_t output = getOutputForEffect(&desc);
927 reply->writeInt32(static_cast <int>(output));
928 return NO_ERROR;
929 } break;
930
931 case REGISTER_EFFECT: {
932 CHECK_INTERFACE(IAudioPolicyService, data, reply);
933 effect_descriptor_t desc;
934 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700935 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700936 uint32_t strategy = data.readInt32();
937 int session = data.readInt32();
938 int id = data.readInt32();
939 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700940 io,
Eric Laurentde070132010-07-13 04:45:46 -0700941 strategy,
942 session,
943 id)));
944 return NO_ERROR;
945 } break;
946
947 case UNREGISTER_EFFECT: {
948 CHECK_INTERFACE(IAudioPolicyService, data, reply);
949 int id = data.readInt32();
950 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
951 return NO_ERROR;
952 } break;
953
Eric Laurentdb7c0792011-08-10 10:37:50 -0700954 case SET_EFFECT_ENABLED: {
955 CHECK_INTERFACE(IAudioPolicyService, data, reply);
956 int id = data.readInt32();
957 bool enabled = static_cast <bool>(data.readInt32());
958 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
959 return NO_ERROR;
960 } break;
961
Eric Laurenteda6c362011-02-02 09:33:30 -0800962 case IS_STREAM_ACTIVE: {
963 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800964 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -0800965 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800966 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -0800967 return NO_ERROR;
968 } break;
969
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800970 case IS_STREAM_ACTIVE_REMOTELY: {
971 CHECK_INTERFACE(IAudioPolicyService, data, reply);
972 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
973 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800974 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800975 return NO_ERROR;
976 } break;
977
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700978 case IS_SOURCE_ACTIVE: {
979 CHECK_INTERFACE(IAudioPolicyService, data, reply);
980 audio_source_t source = (audio_source_t) data.readInt32();
981 reply->writeInt32( isSourceActive(source));
982 return NO_ERROR;
983 }
984
Eric Laurent57dae992011-07-24 13:36:09 -0700985 case QUERY_DEFAULT_PRE_PROCESSING: {
986 CHECK_INTERFACE(IAudioPolicyService, data, reply);
987 int audioSession = data.readInt32();
988 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -0800989 if (count > AudioEffect::kMaxPreProcessing) {
990 count = AudioEffect::kMaxPreProcessing;
991 }
Eric Laurent57dae992011-07-24 13:36:09 -0700992 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -0800993 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -0700994 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
995 reply->writeInt32(status);
996 if (status != NO_ERROR && status != NO_MEMORY) {
997 retCount = 0;
998 }
999 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001000 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001001 if (retCount < count) {
1002 count = retCount;
1003 }
1004 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1005 }
1006 delete[] descriptors;
1007 return status;
1008 }
1009
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001010 case IS_OFFLOAD_SUPPORTED: {
1011 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1012 audio_offload_info_t info;
1013 data.read(&info, sizeof(audio_offload_info_t));
1014 bool isSupported = isOffloadSupported(info);
1015 reply->writeInt32(isSupported);
1016 return NO_ERROR;
1017 }
1018
Eric Laurent203b1a12014-04-01 10:34:16 -07001019 case LIST_AUDIO_PORTS: {
1020 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1021 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1022 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1023 unsigned int numPortsReq = data.readInt32();
1024 unsigned int numPorts = numPortsReq;
1025 unsigned int generation;
1026 struct audio_port *ports =
1027 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
1028 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1029 reply->writeInt32(status);
1030 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001031
1032 if (status == NO_ERROR) {
1033 if (numPortsReq > numPorts) {
1034 numPortsReq = numPorts;
1035 }
1036 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1037 reply->writeInt32(generation);
1038 }
1039 free(ports);
1040 return NO_ERROR;
1041 }
1042
1043 case GET_AUDIO_PORT: {
1044 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1045 struct audio_port port;
1046 data.read(&port, sizeof(struct audio_port));
1047 status_t status = getAudioPort(&port);
1048 reply->writeInt32(status);
1049 if (status == NO_ERROR) {
1050 reply->write(&port, sizeof(struct audio_port));
1051 }
1052 return NO_ERROR;
1053 }
1054
1055 case CREATE_AUDIO_PATCH: {
1056 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1057 struct audio_patch patch;
1058 data.read(&patch, sizeof(struct audio_patch));
1059 audio_patch_handle_t handle;
1060 data.read(&handle, sizeof(audio_patch_handle_t));
1061 status_t status = createAudioPatch(&patch, &handle);
1062 reply->writeInt32(status);
1063 if (status == NO_ERROR) {
1064 reply->write(&handle, sizeof(audio_patch_handle_t));
1065 }
1066 return NO_ERROR;
1067 }
1068
1069 case RELEASE_AUDIO_PATCH: {
1070 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1071 audio_patch_handle_t handle;
1072 data.read(&handle, sizeof(audio_patch_handle_t));
1073 status_t status = releaseAudioPatch(handle);
1074 reply->writeInt32(status);
1075 return NO_ERROR;
1076 }
1077
1078 case LIST_AUDIO_PATCHES: {
1079 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1080 unsigned int numPatchesReq = data.readInt32();
1081 unsigned int numPatches = numPatchesReq;
1082 unsigned int generation;
1083 struct audio_patch *patches =
1084 (struct audio_patch *)calloc(numPatchesReq,
1085 sizeof(struct audio_patch));
1086 status_t status = listAudioPatches(&numPatches, patches, &generation);
1087 reply->writeInt32(status);
1088 reply->writeInt32(numPatches);
1089 if (status == NO_ERROR) {
1090 if (numPatchesReq > numPatches) {
1091 numPatchesReq = numPatches;
1092 }
1093 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1094 reply->writeInt32(generation);
1095 }
1096 free(patches);
1097 return NO_ERROR;
1098 }
1099
1100 case SET_AUDIO_PORT_CONFIG: {
1101 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1102 struct audio_port_config config;
1103 data.read(&config, sizeof(struct audio_port_config));
1104 status_t status = setAudioPortConfig(&config);
1105 reply->writeInt32(status);
1106 return NO_ERROR;
1107 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001108
Eric Laurentb52c1522014-05-20 11:27:36 -07001109 case REGISTER_CLIENT: {
1110 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1111 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1112 data.readStrongBinder());
1113 registerClient(client);
1114 return NO_ERROR;
1115 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001116
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001117 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1118 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1119 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1120 data.readStrongBinder());
1121 audio_session_t session;
1122 audio_io_handle_t ioHandle;
1123 audio_devices_t device;
1124 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1125 reply->writeInt32(status);
1126 if (status == NO_ERROR) {
1127 reply->writeInt32(session);
1128 reply->writeInt32(ioHandle);
1129 reply->writeInt32(device);
1130 }
1131 return NO_ERROR;
1132 } break;
1133
1134 case RELEASE_SOUNDTRIGGER_SESSION: {
1135 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1136 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1137 data.readStrongBinder());
1138 audio_session_t session = (audio_session_t)data.readInt32();
1139 status_t status = releaseSoundTriggerSession(session);
1140 reply->writeInt32(status);
1141 return NO_ERROR;
1142 } break;
1143
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001144 case GET_PHONE_STATE: {
1145 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1146 reply->writeInt32((int32_t)getPhoneState());
1147 return NO_ERROR;
1148 } break;
1149
Eric Laurentc2f1f072009-07-17 12:17:14 -07001150 default:
1151 return BBinder::onTransact(code, data, reply, flags);
1152 }
1153}
1154
1155// ----------------------------------------------------------------------------
1156
1157}; // namespace android