blob: 5f83a0dfa0cb983ff7d71854869ac2ce876cad18 [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,
44 GET_INPUT,
45 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
266 virtual audio_io_handle_t getInput(
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800267 audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800269 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700270 audio_channel_mask_t channelMask,
Eric Laurente83b55d2014-11-14 10:06:21 -0800271 audio_session_t audioSession,
Glenn Kastenb3b16602014-07-16 08:36:31 -0700272 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800276 data.writeInt32((int32_t) inputSource);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 data.writeInt32(samplingRate);
278 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700279 data.writeInt32(channelMask);
Eric Laurente83b55d2014-11-14 10:06:21 -0800280 data.writeInt32((int32_t)audioSession);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700281 data.writeInt32(flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700282 remote()->transact(GET_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700283 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700284 }
285
Eric Laurent4dc68062014-07-28 17:26:49 -0700286 virtual status_t startInput(audio_io_handle_t input,
287 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700288 {
289 Parcel data, reply;
290 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700291 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700292 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 remote()->transact(START_INPUT, data, &reply);
294 return static_cast <status_t> (reply.readInt32());
295 }
296
Eric Laurent4dc68062014-07-28 17:26:49 -0700297 virtual status_t stopInput(audio_io_handle_t input,
298 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700302 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700303 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700304 remote()->transact(STOP_INPUT, data, &reply);
305 return static_cast <status_t> (reply.readInt32());
306 }
307
Eric Laurent4dc68062014-07-28 17:26:49 -0700308 virtual void releaseInput(audio_io_handle_t input,
309 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700310 {
311 Parcel data, reply;
312 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700313 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700314 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 remote()->transact(RELEASE_INPUT, data, &reply);
316 }
317
Dima Zavinfce7a472011-04-19 22:30:36 -0700318 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700319 int indexMin,
320 int indexMax)
321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
324 data.writeInt32(static_cast <uint32_t>(stream));
325 data.writeInt32(indexMin);
326 data.writeInt32(indexMax);
327 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
328 return static_cast <status_t> (reply.readInt32());
329 }
330
Eric Laurent83844cc2011-11-18 16:43:31 -0800331 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
332 int index,
333 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
337 data.writeInt32(static_cast <uint32_t>(stream));
338 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800339 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 remote()->transact(SET_STREAM_VOLUME, data, &reply);
341 return static_cast <status_t> (reply.readInt32());
342 }
343
Eric Laurent83844cc2011-11-18 16:43:31 -0800344 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
345 int *index,
346 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
350 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800351 data.writeInt32(static_cast <uint32_t>(device));
352
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353 remote()->transact(GET_STREAM_VOLUME, data, &reply);
354 int lIndex = reply.readInt32();
355 if (index) *index = lIndex;
356 return static_cast <status_t> (reply.readInt32());
357 }
Eric Laurentde070132010-07-13 04:45:46 -0700358
Dima Zavinfce7a472011-04-19 22:30:36 -0700359 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700360 {
361 Parcel data, reply;
362 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
363 data.writeInt32(static_cast <uint32_t>(stream));
364 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
365 return reply.readInt32();
366 }
367
Eric Laurent63742522012-03-08 13:42:42 -0800368 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800369 {
370 Parcel data, reply;
371 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
372 data.writeInt32(static_cast <uint32_t>(stream));
373 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800374 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800375 }
376
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700377 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700378 {
379 Parcel data, reply;
380 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
381 data.write(desc, sizeof(effect_descriptor_t));
382 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
383 return static_cast <audio_io_handle_t> (reply.readInt32());
384 }
385
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700386 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700387 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700388 uint32_t strategy,
389 int session,
390 int id)
391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
394 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700395 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700396 data.writeInt32(strategy);
397 data.writeInt32(session);
398 data.writeInt32(id);
399 remote()->transact(REGISTER_EFFECT, data, &reply);
400 return static_cast <status_t> (reply.readInt32());
401 }
402
403 virtual status_t unregisterEffect(int id)
404 {
405 Parcel data, reply;
406 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
407 data.writeInt32(id);
408 remote()->transact(UNREGISTER_EFFECT, data, &reply);
409 return static_cast <status_t> (reply.readInt32());
410 }
411
Eric Laurentdb7c0792011-08-10 10:37:50 -0700412 virtual status_t setEffectEnabled(int id, bool enabled)
413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
416 data.writeInt32(id);
417 data.writeInt32(enabled);
418 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
419 return static_cast <status_t> (reply.readInt32());
420 }
421
Glenn Kastenfff6d712012-01-12 16:38:12 -0800422 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800426 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800427 data.writeInt32(inPastMs);
428 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
429 return reply.readInt32();
430 }
Eric Laurent57dae992011-07-24 13:36:09 -0700431
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800432 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
433 {
434 Parcel data, reply;
435 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
436 data.writeInt32((int32_t) stream);
437 data.writeInt32(inPastMs);
438 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
439 return reply.readInt32();
440 }
441
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700442 virtual bool isSourceActive(audio_source_t source) const
443 {
444 Parcel data, reply;
445 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
446 data.writeInt32((int32_t) source);
447 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
448 return reply.readInt32();
449 }
450
Eric Laurent57dae992011-07-24 13:36:09 -0700451 virtual status_t queryDefaultPreProcessing(int audioSession,
452 effect_descriptor_t *descriptors,
453 uint32_t *count)
454 {
455 if (descriptors == NULL || count == NULL) {
456 return BAD_VALUE;
457 }
458 Parcel data, reply;
459 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
460 data.writeInt32(audioSession);
461 data.writeInt32(*count);
462 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
463 if (status != NO_ERROR) {
464 return status;
465 }
466 status = static_cast <status_t> (reply.readInt32());
467 uint32_t retCount = reply.readInt32();
468 if (retCount != 0) {
469 uint32_t numDesc = (retCount < *count) ? retCount : *count;
470 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
471 }
472 *count = retCount;
473 return status;
474 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000475
476 virtual bool isOffloadSupported(const audio_offload_info_t& info)
477 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100478 Parcel data, reply;
479 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
480 data.write(&info, sizeof(audio_offload_info_t));
481 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700482 return reply.readInt32();
483 }
484
485 virtual status_t listAudioPorts(audio_port_role_t role,
486 audio_port_type_t type,
487 unsigned int *num_ports,
488 struct audio_port *ports,
489 unsigned int *generation)
490 {
491 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
492 generation == NULL) {
493 return BAD_VALUE;
494 }
495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
497 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
498 data.writeInt32(role);
499 data.writeInt32(type);
500 data.writeInt32(numPortsReq);
501 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
502 if (status == NO_ERROR) {
503 status = (status_t)reply.readInt32();
504 *num_ports = (unsigned int)reply.readInt32();
505 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700506 if (status == NO_ERROR) {
507 if (numPortsReq > *num_ports) {
508 numPortsReq = *num_ports;
509 }
510 if (numPortsReq > 0) {
511 reply.read(ports, numPortsReq * sizeof(struct audio_port));
512 }
513 *generation = reply.readInt32();
514 }
515 return status;
516 }
517
518 virtual status_t getAudioPort(struct audio_port *port)
519 {
520 if (port == NULL) {
521 return BAD_VALUE;
522 }
523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
525 data.write(port, sizeof(struct audio_port));
526 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
527 if (status != NO_ERROR ||
528 (status = (status_t)reply.readInt32()) != NO_ERROR) {
529 return status;
530 }
531 reply.read(port, sizeof(struct audio_port));
532 return status;
533 }
534
535 virtual status_t createAudioPatch(const struct audio_patch *patch,
536 audio_patch_handle_t *handle)
537 {
538 if (patch == NULL || handle == NULL) {
539 return BAD_VALUE;
540 }
541 Parcel data, reply;
542 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
543 data.write(patch, sizeof(struct audio_patch));
544 data.write(handle, sizeof(audio_patch_handle_t));
545 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
546 if (status != NO_ERROR ||
547 (status = (status_t)reply.readInt32()) != NO_ERROR) {
548 return status;
549 }
550 reply.read(handle, sizeof(audio_patch_handle_t));
551 return status;
552 }
553
554 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
555 {
556 Parcel data, reply;
557 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
558 data.write(&handle, sizeof(audio_patch_handle_t));
559 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
560 if (status != NO_ERROR) {
561 status = (status_t)reply.readInt32();
562 }
563 return status;
564 }
565
566 virtual status_t listAudioPatches(unsigned int *num_patches,
567 struct audio_patch *patches,
568 unsigned int *generation)
569 {
570 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
571 generation == NULL) {
572 return BAD_VALUE;
573 }
574 Parcel data, reply;
575 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
576 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
577 data.writeInt32(numPatchesReq);
578 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
579 if (status == NO_ERROR) {
580 status = (status_t)reply.readInt32();
581 *num_patches = (unsigned int)reply.readInt32();
582 }
583 if (status == NO_ERROR) {
584 if (numPatchesReq > *num_patches) {
585 numPatchesReq = *num_patches;
586 }
587 if (numPatchesReq > 0) {
588 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
589 }
590 *generation = reply.readInt32();
591 }
592 return status;
593 }
594
595 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
596 {
597 if (config == NULL) {
598 return BAD_VALUE;
599 }
600 Parcel data, reply;
601 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
602 data.write(config, sizeof(struct audio_port_config));
603 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
604 if (status != NO_ERROR) {
605 status = (status_t)reply.readInt32();
606 }
607 return status;
608 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700609
Eric Laurentb52c1522014-05-20 11:27:36 -0700610 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
611 {
612 Parcel data, reply;
613 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
614 data.writeStrongBinder(client->asBinder());
615 remote()->transact(REGISTER_CLIENT, data, &reply);
616 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700617
618 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
619 audio_io_handle_t *ioHandle,
620 audio_devices_t *device)
621 {
622 if (session == NULL || ioHandle == NULL || device == NULL) {
623 return BAD_VALUE;
624 }
625 Parcel data, reply;
626 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
627 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
628 if (status != NO_ERROR) {
629 return status;
630 }
631 status = (status_t)reply.readInt32();
632 if (status == NO_ERROR) {
633 *session = (audio_session_t)reply.readInt32();
634 *ioHandle = (audio_io_handle_t)reply.readInt32();
635 *device = (audio_devices_t)reply.readInt32();
636 }
637 return status;
638 }
639
640 virtual status_t releaseSoundTriggerSession(audio_session_t session)
641 {
642 Parcel data, reply;
643 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
644 data.writeInt32(session);
645 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
646 if (status != NO_ERROR) {
647 return status;
648 }
649 return (status_t)reply.readInt32();
650 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700651
652 virtual audio_mode_t getPhoneState()
653 {
654 Parcel data, reply;
655 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
656 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
657 if (status != NO_ERROR) {
658 return AUDIO_MODE_INVALID;
659 }
660 return (audio_mode_t)reply.readInt32();
661 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700662};
663
664IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
665
666// ----------------------------------------------------------------------
667
668
669status_t BnAudioPolicyService::onTransact(
670 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
671{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700672 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700673 case SET_DEVICE_CONNECTION_STATE: {
674 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700675 audio_devices_t device =
676 static_cast <audio_devices_t>(data.readInt32());
677 audio_policy_dev_state_t state =
678 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700679 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700680 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
681 state,
682 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700683 return NO_ERROR;
684 } break;
685
686 case GET_DEVICE_CONNECTION_STATE: {
687 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700688 audio_devices_t device =
689 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700690 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700691 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
692 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700693 return NO_ERROR;
694 } break;
695
696 case SET_PHONE_STATE: {
697 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700698 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
699 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700700 return NO_ERROR;
701 } break;
702
Eric Laurentc2f1f072009-07-17 12:17:14 -0700703 case SET_FORCE_USE: {
704 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700705 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
706 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700707 audio_policy_forced_cfg_t config =
708 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700709 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
710 return NO_ERROR;
711 } break;
712
713 case GET_FORCE_USE: {
714 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700715 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
716 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700717 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
718 return NO_ERROR;
719 } break;
720
721 case GET_OUTPUT: {
722 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700723 audio_stream_type_t stream =
724 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700725 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800726 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700727 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700728 audio_output_flags_t flags =
729 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100730 bool hasOffloadInfo = data.readInt32() != 0;
731 audio_offload_info_t offloadInfo;
732 if (hasOffloadInfo) {
733 data.read(&offloadInfo, sizeof(audio_offload_info_t));
734 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700735 audio_io_handle_t output = getOutput(stream,
736 samplingRate,
737 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700738 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100739 flags,
740 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700741 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700742 return NO_ERROR;
743 } break;
744
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700745 case GET_OUTPUT_FOR_ATTR: {
746 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800747 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800748 bool hasAttributes = data.readInt32() != 0;
749 if (hasAttributes) {
750 data.read(&attr, sizeof(audio_attributes_t));
751 }
752 audio_session_t session = (audio_session_t)data.readInt32();
753 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
754 bool hasStream = data.readInt32() != 0;
755 if (hasStream) {
756 stream = (audio_stream_type_t)data.readInt32();
757 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700758 uint32_t samplingRate = data.readInt32();
759 audio_format_t format = (audio_format_t) data.readInt32();
760 audio_channel_mask_t channelMask = data.readInt32();
761 audio_output_flags_t flags =
762 static_cast <audio_output_flags_t>(data.readInt32());
763 bool hasOffloadInfo = data.readInt32() != 0;
764 audio_offload_info_t offloadInfo;
765 if (hasOffloadInfo) {
766 data.read(&offloadInfo, sizeof(audio_offload_info_t));
767 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800768 audio_io_handle_t output;
769 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
770 &output, session, &stream,
771 samplingRate, format, channelMask,
772 flags, hasOffloadInfo ? &offloadInfo : NULL);
773 reply->writeInt32(status);
774 reply->writeInt32(output);
775 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700776 return NO_ERROR;
777 } break;
778
Eric Laurentc2f1f072009-07-17 12:17:14 -0700779 case START_OUTPUT: {
780 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700781 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800782 audio_stream_type_t stream =
783 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800784 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700785 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800786 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700787 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700788 return NO_ERROR;
789 } break;
790
791 case STOP_OUTPUT: {
792 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700793 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800794 audio_stream_type_t stream =
795 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800796 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700797 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800798 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700799 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700800 return NO_ERROR;
801 } break;
802
803 case RELEASE_OUTPUT: {
804 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700805 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800806 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
807 audio_session_t session = (audio_session_t)data.readInt32();
808 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700809 return NO_ERROR;
810 } break;
811
812 case GET_INPUT: {
813 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800814 audio_source_t inputSource = (audio_source_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700815 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800816 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700817 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800818 audio_session_t audioSession = (audio_session_t)data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700819 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700820 audio_io_handle_t input = getInput(inputSource,
821 samplingRate,
822 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700823 channelMask,
Glenn Kastenb3b16602014-07-16 08:36:31 -0700824 audioSession,
825 flags);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700826 reply->writeInt32(static_cast <int>(input));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700827 return NO_ERROR;
828 } break;
829
830 case START_INPUT: {
831 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700832 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700833 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
834 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700835 return NO_ERROR;
836 } break;
837
838 case STOP_INPUT: {
839 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700840 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700841 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
842 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700843 return NO_ERROR;
844 } break;
845
846 case RELEASE_INPUT: {
847 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700848 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700849 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
850 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700851 return NO_ERROR;
852 } break;
853
854 case INIT_STREAM_VOLUME: {
855 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700856 audio_stream_type_t stream =
857 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700858 int indexMin = data.readInt32();
859 int indexMax = data.readInt32();
860 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
861 return NO_ERROR;
862 } break;
863
864 case SET_STREAM_VOLUME: {
865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700866 audio_stream_type_t stream =
867 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700868 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800869 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
870 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
871 index,
872 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700873 return NO_ERROR;
874 } break;
875
876 case GET_STREAM_VOLUME: {
877 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700878 audio_stream_type_t stream =
879 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800880 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700881 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800882 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700883 reply->writeInt32(index);
884 reply->writeInt32(static_cast <uint32_t>(status));
885 return NO_ERROR;
886 } break;
887
Eric Laurentde070132010-07-13 04:45:46 -0700888 case GET_STRATEGY_FOR_STREAM: {
889 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700890 audio_stream_type_t stream =
891 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700892 reply->writeInt32(getStrategyForStream(stream));
893 return NO_ERROR;
894 } break;
895
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800896 case GET_DEVICES_FOR_STREAM: {
897 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700898 audio_stream_type_t stream =
899 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800900 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
901 return NO_ERROR;
902 } break;
903
Eric Laurentde070132010-07-13 04:45:46 -0700904 case GET_OUTPUT_FOR_EFFECT: {
905 CHECK_INTERFACE(IAudioPolicyService, data, reply);
906 effect_descriptor_t desc;
907 data.read(&desc, sizeof(effect_descriptor_t));
908 audio_io_handle_t output = getOutputForEffect(&desc);
909 reply->writeInt32(static_cast <int>(output));
910 return NO_ERROR;
911 } break;
912
913 case REGISTER_EFFECT: {
914 CHECK_INTERFACE(IAudioPolicyService, data, reply);
915 effect_descriptor_t desc;
916 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700917 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700918 uint32_t strategy = data.readInt32();
919 int session = data.readInt32();
920 int id = data.readInt32();
921 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700922 io,
Eric Laurentde070132010-07-13 04:45:46 -0700923 strategy,
924 session,
925 id)));
926 return NO_ERROR;
927 } break;
928
929 case UNREGISTER_EFFECT: {
930 CHECK_INTERFACE(IAudioPolicyService, data, reply);
931 int id = data.readInt32();
932 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
933 return NO_ERROR;
934 } break;
935
Eric Laurentdb7c0792011-08-10 10:37:50 -0700936 case SET_EFFECT_ENABLED: {
937 CHECK_INTERFACE(IAudioPolicyService, data, reply);
938 int id = data.readInt32();
939 bool enabled = static_cast <bool>(data.readInt32());
940 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
941 return NO_ERROR;
942 } break;
943
Eric Laurenteda6c362011-02-02 09:33:30 -0800944 case IS_STREAM_ACTIVE: {
945 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800946 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -0800947 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800948 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -0800949 return NO_ERROR;
950 } break;
951
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800952 case IS_STREAM_ACTIVE_REMOTELY: {
953 CHECK_INTERFACE(IAudioPolicyService, data, reply);
954 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
955 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800956 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800957 return NO_ERROR;
958 } break;
959
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700960 case IS_SOURCE_ACTIVE: {
961 CHECK_INTERFACE(IAudioPolicyService, data, reply);
962 audio_source_t source = (audio_source_t) data.readInt32();
963 reply->writeInt32( isSourceActive(source));
964 return NO_ERROR;
965 }
966
Eric Laurent57dae992011-07-24 13:36:09 -0700967 case QUERY_DEFAULT_PRE_PROCESSING: {
968 CHECK_INTERFACE(IAudioPolicyService, data, reply);
969 int audioSession = data.readInt32();
970 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -0800971 if (count > AudioEffect::kMaxPreProcessing) {
972 count = AudioEffect::kMaxPreProcessing;
973 }
Eric Laurent57dae992011-07-24 13:36:09 -0700974 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -0800975 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -0700976 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
977 reply->writeInt32(status);
978 if (status != NO_ERROR && status != NO_MEMORY) {
979 retCount = 0;
980 }
981 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -0800982 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -0700983 if (retCount < count) {
984 count = retCount;
985 }
986 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
987 }
988 delete[] descriptors;
989 return status;
990 }
991
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100992 case IS_OFFLOAD_SUPPORTED: {
993 CHECK_INTERFACE(IAudioPolicyService, data, reply);
994 audio_offload_info_t info;
995 data.read(&info, sizeof(audio_offload_info_t));
996 bool isSupported = isOffloadSupported(info);
997 reply->writeInt32(isSupported);
998 return NO_ERROR;
999 }
1000
Eric Laurent203b1a12014-04-01 10:34:16 -07001001 case LIST_AUDIO_PORTS: {
1002 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1003 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1004 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1005 unsigned int numPortsReq = data.readInt32();
1006 unsigned int numPorts = numPortsReq;
1007 unsigned int generation;
1008 struct audio_port *ports =
1009 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
1010 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1011 reply->writeInt32(status);
1012 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001013
1014 if (status == NO_ERROR) {
1015 if (numPortsReq > numPorts) {
1016 numPortsReq = numPorts;
1017 }
1018 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1019 reply->writeInt32(generation);
1020 }
1021 free(ports);
1022 return NO_ERROR;
1023 }
1024
1025 case GET_AUDIO_PORT: {
1026 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1027 struct audio_port port;
1028 data.read(&port, sizeof(struct audio_port));
1029 status_t status = getAudioPort(&port);
1030 reply->writeInt32(status);
1031 if (status == NO_ERROR) {
1032 reply->write(&port, sizeof(struct audio_port));
1033 }
1034 return NO_ERROR;
1035 }
1036
1037 case CREATE_AUDIO_PATCH: {
1038 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1039 struct audio_patch patch;
1040 data.read(&patch, sizeof(struct audio_patch));
1041 audio_patch_handle_t handle;
1042 data.read(&handle, sizeof(audio_patch_handle_t));
1043 status_t status = createAudioPatch(&patch, &handle);
1044 reply->writeInt32(status);
1045 if (status == NO_ERROR) {
1046 reply->write(&handle, sizeof(audio_patch_handle_t));
1047 }
1048 return NO_ERROR;
1049 }
1050
1051 case RELEASE_AUDIO_PATCH: {
1052 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1053 audio_patch_handle_t handle;
1054 data.read(&handle, sizeof(audio_patch_handle_t));
1055 status_t status = releaseAudioPatch(handle);
1056 reply->writeInt32(status);
1057 return NO_ERROR;
1058 }
1059
1060 case LIST_AUDIO_PATCHES: {
1061 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1062 unsigned int numPatchesReq = data.readInt32();
1063 unsigned int numPatches = numPatchesReq;
1064 unsigned int generation;
1065 struct audio_patch *patches =
1066 (struct audio_patch *)calloc(numPatchesReq,
1067 sizeof(struct audio_patch));
1068 status_t status = listAudioPatches(&numPatches, patches, &generation);
1069 reply->writeInt32(status);
1070 reply->writeInt32(numPatches);
1071 if (status == NO_ERROR) {
1072 if (numPatchesReq > numPatches) {
1073 numPatchesReq = numPatches;
1074 }
1075 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1076 reply->writeInt32(generation);
1077 }
1078 free(patches);
1079 return NO_ERROR;
1080 }
1081
1082 case SET_AUDIO_PORT_CONFIG: {
1083 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1084 struct audio_port_config config;
1085 data.read(&config, sizeof(struct audio_port_config));
1086 status_t status = setAudioPortConfig(&config);
1087 reply->writeInt32(status);
1088 return NO_ERROR;
1089 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001090
Eric Laurentb52c1522014-05-20 11:27:36 -07001091 case REGISTER_CLIENT: {
1092 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1093 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1094 data.readStrongBinder());
1095 registerClient(client);
1096 return NO_ERROR;
1097 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001098
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001099 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1100 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1101 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1102 data.readStrongBinder());
1103 audio_session_t session;
1104 audio_io_handle_t ioHandle;
1105 audio_devices_t device;
1106 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1107 reply->writeInt32(status);
1108 if (status == NO_ERROR) {
1109 reply->writeInt32(session);
1110 reply->writeInt32(ioHandle);
1111 reply->writeInt32(device);
1112 }
1113 return NO_ERROR;
1114 } break;
1115
1116 case RELEASE_SOUNDTRIGGER_SESSION: {
1117 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1118 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1119 data.readStrongBinder());
1120 audio_session_t session = (audio_session_t)data.readInt32();
1121 status_t status = releaseSoundTriggerSession(session);
1122 reply->writeInt32(status);
1123 return NO_ERROR;
1124 } break;
1125
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001126 case GET_PHONE_STATE: {
1127 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1128 reply->writeInt32((int32_t)getPhoneState());
1129 return NO_ERROR;
1130 } break;
1131
Eric Laurentc2f1f072009-07-17 12:17:14 -07001132 default:
1133 return BBinder::onTransact(code, data, reply, flags);
1134 }
1135}
1136
1137// ----------------------------------------------------------------------------
1138
1139}; // namespace android