blob: e8409566049779adc1e263d77cf4aecae7743af7 [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 Laurente360f0f2014-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
Eric Laurent2fdd16b2015-02-06 10:44:24 -080075#define MAX_ITEMS_PER_LIST 1024
76
Eric Laurentc2f1f072009-07-17 12:17:14 -070077class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
78{
79public:
80 BpAudioPolicyService(const sp<IBinder>& impl)
81 : BpInterface<IAudioPolicyService>(impl)
82 {
83 }
84
85 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070086 audio_devices_t device,
87 audio_policy_dev_state_t state,
Eric Laurentc2f1f072009-07-17 12:17:14 -070088 const char *device_address)
89 {
90 Parcel data, reply;
91 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
92 data.writeInt32(static_cast <uint32_t>(device));
93 data.writeInt32(static_cast <uint32_t>(state));
94 data.writeCString(device_address);
95 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
96 return static_cast <status_t> (reply.readInt32());
97 }
98
Dima Zavinfce7a472011-04-19 22:30:36 -070099 virtual audio_policy_dev_state_t getDeviceConnectionState(
100 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700101 const char *device_address)
102 {
103 Parcel data, reply;
104 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
105 data.writeInt32(static_cast <uint32_t>(device));
106 data.writeCString(device_address);
107 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700108 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109 }
110
Glenn Kastenf78aee72012-01-04 11:00:47 -0800111 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 {
113 Parcel data, reply;
114 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
115 data.writeInt32(state);
116 remote()->transact(SET_PHONE_STATE, data, &reply);
117 return static_cast <status_t> (reply.readInt32());
118 }
119
Dima Zavinfce7a472011-04-19 22:30:36 -0700120 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700121 {
122 Parcel data, reply;
123 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
124 data.writeInt32(static_cast <uint32_t>(usage));
125 data.writeInt32(static_cast <uint32_t>(config));
126 remote()->transact(SET_FORCE_USE, data, &reply);
127 return static_cast <status_t> (reply.readInt32());
128 }
129
Dima Zavinfce7a472011-04-19 22:30:36 -0700130 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700131 {
132 Parcel data, reply;
133 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
134 data.writeInt32(static_cast <uint32_t>(usage));
135 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700136 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700137 }
138
139 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700140 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700141 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800142 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700143 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000144 audio_output_flags_t flags,
145 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 {
147 Parcel data, reply;
148 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
149 data.writeInt32(static_cast <uint32_t>(stream));
150 data.writeInt32(samplingRate);
151 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700152 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700153 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800154 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100155 if (offloadInfo == NULL) {
156 data.writeInt32(0);
157 } else {
158 data.writeInt32(1);
159 data.write(offloadInfo, sizeof(audio_offload_info_t));
160 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700161 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700162 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700163 }
164
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700165 virtual audio_io_handle_t getOutputForAttr(
166 const audio_attributes_t *attr,
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)
172 {
173 Parcel data, reply;
174 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
175 if (attr == NULL) {
176 ALOGE("Writing NULL audio attributes - shouldn't happen");
177 return (audio_io_handle_t) 0;
178 }
179 data.write(attr, sizeof(audio_attributes_t));
180 data.writeInt32(samplingRate);
181 data.writeInt32(static_cast <uint32_t>(format));
182 data.writeInt32(channelMask);
183 data.writeInt32(static_cast <uint32_t>(flags));
184 // hasOffloadInfo
185 if (offloadInfo == NULL) {
186 data.writeInt32(0);
187 } else {
188 data.writeInt32(1);
189 data.write(offloadInfo, sizeof(audio_offload_info_t));
190 }
191 remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
192 return static_cast <audio_io_handle_t> (reply.readInt32());
193 }
194
Eric Laurentde070132010-07-13 04:45:46 -0700195 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700196 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700197 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700198 {
199 Parcel data, reply;
200 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700201 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800202 data.writeInt32((int32_t) stream);
Eric Laurentde070132010-07-13 04:45:46 -0700203 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700204 remote()->transact(START_OUTPUT, data, &reply);
205 return static_cast <status_t> (reply.readInt32());
206 }
207
Eric Laurentde070132010-07-13 04:45:46 -0700208 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700209 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700210 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700211 {
212 Parcel data, reply;
213 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700214 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800215 data.writeInt32((int32_t) stream);
Eric Laurentde070132010-07-13 04:45:46 -0700216 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700217 remote()->transact(STOP_OUTPUT, data, &reply);
218 return static_cast <status_t> (reply.readInt32());
219 }
220
221 virtual void releaseOutput(audio_io_handle_t output)
222 {
223 Parcel data, reply;
224 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700225 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700226 remote()->transact(RELEASE_OUTPUT, data, &reply);
227 }
228
229 virtual audio_io_handle_t getInput(
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800230 audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700231 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800232 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700233 audio_channel_mask_t channelMask,
Glenn Kastenb3b16602014-07-16 08:36:31 -0700234 int audioSession,
235 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700236 {
237 Parcel data, reply;
238 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800239 data.writeInt32((int32_t) inputSource);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700240 data.writeInt32(samplingRate);
241 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700242 data.writeInt32(channelMask);
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700243 data.writeInt32(audioSession);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700244 data.writeInt32(flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700245 remote()->transact(GET_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700246 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700247 }
248
Eric Laurent4dc68062014-07-28 17:26:49 -0700249 virtual status_t startInput(audio_io_handle_t input,
250 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 {
252 Parcel data, reply;
253 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700254 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700255 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700256 remote()->transact(START_INPUT, data, &reply);
257 return static_cast <status_t> (reply.readInt32());
258 }
259
Eric Laurent4dc68062014-07-28 17:26:49 -0700260 virtual status_t stopInput(audio_io_handle_t input,
261 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700265 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700266 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 remote()->transact(STOP_INPUT, data, &reply);
268 return static_cast <status_t> (reply.readInt32());
269 }
270
Eric Laurent4dc68062014-07-28 17:26:49 -0700271 virtual void releaseInput(audio_io_handle_t input,
272 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700276 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700277 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700278 remote()->transact(RELEASE_INPUT, data, &reply);
279 }
280
Dima Zavinfce7a472011-04-19 22:30:36 -0700281 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700282 int indexMin,
283 int indexMax)
284 {
285 Parcel data, reply;
286 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
287 data.writeInt32(static_cast <uint32_t>(stream));
288 data.writeInt32(indexMin);
289 data.writeInt32(indexMax);
290 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
291 return static_cast <status_t> (reply.readInt32());
292 }
293
Eric Laurent83844cc2011-11-18 16:43:31 -0800294 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
295 int index,
296 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700297 {
298 Parcel data, reply;
299 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
300 data.writeInt32(static_cast <uint32_t>(stream));
301 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800302 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700303 remote()->transact(SET_STREAM_VOLUME, data, &reply);
304 return static_cast <status_t> (reply.readInt32());
305 }
306
Eric Laurent83844cc2011-11-18 16:43:31 -0800307 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
308 int *index,
309 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700310 {
311 Parcel data, reply;
312 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
313 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800314 data.writeInt32(static_cast <uint32_t>(device));
315
Eric Laurentc2f1f072009-07-17 12:17:14 -0700316 remote()->transact(GET_STREAM_VOLUME, data, &reply);
317 int lIndex = reply.readInt32();
318 if (index) *index = lIndex;
319 return static_cast <status_t> (reply.readInt32());
320 }
Eric Laurentde070132010-07-13 04:45:46 -0700321
Dima Zavinfce7a472011-04-19 22:30:36 -0700322 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700323 {
324 Parcel data, reply;
325 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
326 data.writeInt32(static_cast <uint32_t>(stream));
327 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
328 return reply.readInt32();
329 }
330
Eric Laurent63742522012-03-08 13:42:42 -0800331 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800332 {
333 Parcel data, reply;
334 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
335 data.writeInt32(static_cast <uint32_t>(stream));
336 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800337 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800338 }
339
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700340 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700341 {
342 Parcel data, reply;
343 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
344 data.write(desc, sizeof(effect_descriptor_t));
345 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
346 return static_cast <audio_io_handle_t> (reply.readInt32());
347 }
348
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700349 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700350 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700351 uint32_t strategy,
352 int session,
353 int id)
354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
357 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700358 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700359 data.writeInt32(strategy);
360 data.writeInt32(session);
361 data.writeInt32(id);
362 remote()->transact(REGISTER_EFFECT, data, &reply);
363 return static_cast <status_t> (reply.readInt32());
364 }
365
366 virtual status_t unregisterEffect(int id)
367 {
368 Parcel data, reply;
369 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
370 data.writeInt32(id);
371 remote()->transact(UNREGISTER_EFFECT, data, &reply);
372 return static_cast <status_t> (reply.readInt32());
373 }
374
Eric Laurentdb7c0792011-08-10 10:37:50 -0700375 virtual status_t setEffectEnabled(int id, bool enabled)
376 {
377 Parcel data, reply;
378 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
379 data.writeInt32(id);
380 data.writeInt32(enabled);
381 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
382 return static_cast <status_t> (reply.readInt32());
383 }
384
Glenn Kastenfff6d712012-01-12 16:38:12 -0800385 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800386 {
387 Parcel data, reply;
388 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800389 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800390 data.writeInt32(inPastMs);
391 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
392 return reply.readInt32();
393 }
Eric Laurent57dae992011-07-24 13:36:09 -0700394
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800395 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
399 data.writeInt32((int32_t) stream);
400 data.writeInt32(inPastMs);
401 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
402 return reply.readInt32();
403 }
404
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700405 virtual bool isSourceActive(audio_source_t source) const
406 {
407 Parcel data, reply;
408 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
409 data.writeInt32((int32_t) source);
410 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
411 return reply.readInt32();
412 }
413
Eric Laurent57dae992011-07-24 13:36:09 -0700414 virtual status_t queryDefaultPreProcessing(int audioSession,
415 effect_descriptor_t *descriptors,
416 uint32_t *count)
417 {
418 if (descriptors == NULL || count == NULL) {
419 return BAD_VALUE;
420 }
421 Parcel data, reply;
422 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
423 data.writeInt32(audioSession);
424 data.writeInt32(*count);
425 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
426 if (status != NO_ERROR) {
427 return status;
428 }
429 status = static_cast <status_t> (reply.readInt32());
430 uint32_t retCount = reply.readInt32();
431 if (retCount != 0) {
432 uint32_t numDesc = (retCount < *count) ? retCount : *count;
433 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
434 }
435 *count = retCount;
436 return status;
437 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000438
439 virtual bool isOffloadSupported(const audio_offload_info_t& info)
440 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.write(&info, sizeof(audio_offload_info_t));
444 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700445 return reply.readInt32();
446 }
447
448 virtual status_t listAudioPorts(audio_port_role_t role,
449 audio_port_type_t type,
450 unsigned int *num_ports,
451 struct audio_port *ports,
452 unsigned int *generation)
453 {
454 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
455 generation == NULL) {
456 return BAD_VALUE;
457 }
458 Parcel data, reply;
459 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
460 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
461 data.writeInt32(role);
462 data.writeInt32(type);
463 data.writeInt32(numPortsReq);
464 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
465 if (status == NO_ERROR) {
466 status = (status_t)reply.readInt32();
467 *num_ports = (unsigned int)reply.readInt32();
468 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700469 if (status == NO_ERROR) {
470 if (numPortsReq > *num_ports) {
471 numPortsReq = *num_ports;
472 }
473 if (numPortsReq > 0) {
474 reply.read(ports, numPortsReq * sizeof(struct audio_port));
475 }
476 *generation = reply.readInt32();
477 }
478 return status;
479 }
480
481 virtual status_t getAudioPort(struct audio_port *port)
482 {
483 if (port == NULL) {
484 return BAD_VALUE;
485 }
486 Parcel data, reply;
487 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
488 data.write(port, sizeof(struct audio_port));
489 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
490 if (status != NO_ERROR ||
491 (status = (status_t)reply.readInt32()) != NO_ERROR) {
492 return status;
493 }
494 reply.read(port, sizeof(struct audio_port));
495 return status;
496 }
497
498 virtual status_t createAudioPatch(const struct audio_patch *patch,
499 audio_patch_handle_t *handle)
500 {
501 if (patch == NULL || handle == NULL) {
502 return BAD_VALUE;
503 }
504 Parcel data, reply;
505 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
506 data.write(patch, sizeof(struct audio_patch));
507 data.write(handle, sizeof(audio_patch_handle_t));
508 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
509 if (status != NO_ERROR ||
510 (status = (status_t)reply.readInt32()) != NO_ERROR) {
511 return status;
512 }
513 reply.read(handle, sizeof(audio_patch_handle_t));
514 return status;
515 }
516
517 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
518 {
519 Parcel data, reply;
520 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
521 data.write(&handle, sizeof(audio_patch_handle_t));
522 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
523 if (status != NO_ERROR) {
524 status = (status_t)reply.readInt32();
525 }
526 return status;
527 }
528
529 virtual status_t listAudioPatches(unsigned int *num_patches,
530 struct audio_patch *patches,
531 unsigned int *generation)
532 {
533 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
534 generation == NULL) {
535 return BAD_VALUE;
536 }
537 Parcel data, reply;
538 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
539 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
540 data.writeInt32(numPatchesReq);
541 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
542 if (status == NO_ERROR) {
543 status = (status_t)reply.readInt32();
544 *num_patches = (unsigned int)reply.readInt32();
545 }
546 if (status == NO_ERROR) {
547 if (numPatchesReq > *num_patches) {
548 numPatchesReq = *num_patches;
549 }
550 if (numPatchesReq > 0) {
551 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
552 }
553 *generation = reply.readInt32();
554 }
555 return status;
556 }
557
558 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
559 {
560 if (config == NULL) {
561 return BAD_VALUE;
562 }
563 Parcel data, reply;
564 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
565 data.write(config, sizeof(struct audio_port_config));
566 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
567 if (status != NO_ERROR) {
568 status = (status_t)reply.readInt32();
569 }
570 return status;
571 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700572
Eric Laurentb52c1522014-05-20 11:27:36 -0700573 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
574 {
575 Parcel data, reply;
576 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
577 data.writeStrongBinder(client->asBinder());
578 remote()->transact(REGISTER_CLIENT, data, &reply);
579 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700580
581 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
582 audio_io_handle_t *ioHandle,
583 audio_devices_t *device)
584 {
585 if (session == NULL || ioHandle == NULL || device == NULL) {
586 return BAD_VALUE;
587 }
588 Parcel data, reply;
589 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
590 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
591 if (status != NO_ERROR) {
592 return status;
593 }
594 status = (status_t)reply.readInt32();
595 if (status == NO_ERROR) {
596 *session = (audio_session_t)reply.readInt32();
597 *ioHandle = (audio_io_handle_t)reply.readInt32();
598 *device = (audio_devices_t)reply.readInt32();
599 }
600 return status;
601 }
602
603 virtual status_t releaseSoundTriggerSession(audio_session_t session)
604 {
605 Parcel data, reply;
606 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
607 data.writeInt32(session);
608 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
609 if (status != NO_ERROR) {
610 return status;
611 }
612 return (status_t)reply.readInt32();
613 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700614
615 virtual audio_mode_t getPhoneState()
616 {
617 Parcel data, reply;
618 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
619 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
620 if (status != NO_ERROR) {
621 return AUDIO_MODE_INVALID;
622 }
623 return (audio_mode_t)reply.readInt32();
624 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700625};
626
627IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
628
629// ----------------------------------------------------------------------
630
631
632status_t BnAudioPolicyService::onTransact(
633 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
634{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700635 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700636 case SET_DEVICE_CONNECTION_STATE: {
637 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700638 audio_devices_t device =
639 static_cast <audio_devices_t>(data.readInt32());
640 audio_policy_dev_state_t state =
641 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700642 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700643 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
644 state,
645 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700646 return NO_ERROR;
647 } break;
648
649 case GET_DEVICE_CONNECTION_STATE: {
650 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700651 audio_devices_t device =
652 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700653 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700654 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
655 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700656 return NO_ERROR;
657 } break;
658
659 case SET_PHONE_STATE: {
660 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700661 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
662 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700663 return NO_ERROR;
664 } break;
665
Eric Laurentc2f1f072009-07-17 12:17:14 -0700666 case SET_FORCE_USE: {
667 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700668 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
669 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700670 audio_policy_forced_cfg_t config =
671 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700672 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
673 return NO_ERROR;
674 } break;
675
676 case GET_FORCE_USE: {
677 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700678 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
679 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700680 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
681 return NO_ERROR;
682 } break;
683
684 case GET_OUTPUT: {
685 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700686 audio_stream_type_t stream =
687 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700688 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800689 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700690 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700691 audio_output_flags_t flags =
692 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100693 bool hasOffloadInfo = data.readInt32() != 0;
694 audio_offload_info_t offloadInfo;
695 if (hasOffloadInfo) {
696 data.read(&offloadInfo, sizeof(audio_offload_info_t));
697 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700698 audio_io_handle_t output = getOutput(stream,
699 samplingRate,
700 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700701 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100702 flags,
703 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700704 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700705 return NO_ERROR;
706 } break;
707
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700708 case GET_OUTPUT_FOR_ATTR: {
709 CHECK_INTERFACE(IAudioPolicyService, data, reply);
710 audio_attributes_t *attr = (audio_attributes_t *) calloc(1, sizeof(audio_attributes_t));
711 data.read(attr, sizeof(audio_attributes_t));
712 uint32_t samplingRate = data.readInt32();
713 audio_format_t format = (audio_format_t) data.readInt32();
714 audio_channel_mask_t channelMask = data.readInt32();
715 audio_output_flags_t flags =
716 static_cast <audio_output_flags_t>(data.readInt32());
717 bool hasOffloadInfo = data.readInt32() != 0;
718 audio_offload_info_t offloadInfo;
719 if (hasOffloadInfo) {
720 data.read(&offloadInfo, sizeof(audio_offload_info_t));
721 }
722 audio_io_handle_t output = getOutputForAttr(attr,
723 samplingRate,
724 format,
725 channelMask,
726 flags,
727 hasOffloadInfo ? &offloadInfo : NULL);
728 reply->writeInt32(static_cast <int>(output));
729 return NO_ERROR;
730 } break;
731
Eric Laurentc2f1f072009-07-17 12:17:14 -0700732 case START_OUTPUT: {
733 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700734 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800735 audio_stream_type_t stream =
736 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700737 int session = data.readInt32();
738 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800739 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700740 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700741 return NO_ERROR;
742 } break;
743
744 case STOP_OUTPUT: {
745 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700746 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800747 audio_stream_type_t stream =
748 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700749 int session = data.readInt32();
750 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800751 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700752 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700753 return NO_ERROR;
754 } break;
755
756 case RELEASE_OUTPUT: {
757 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700758 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700759 releaseOutput(output);
760 return NO_ERROR;
761 } break;
762
763 case GET_INPUT: {
764 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800765 audio_source_t inputSource = (audio_source_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700766 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800767 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700768 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700769 int audioSession = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700770 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700771 audio_io_handle_t input = getInput(inputSource,
772 samplingRate,
773 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700774 channelMask,
Glenn Kastenb3b16602014-07-16 08:36:31 -0700775 audioSession,
776 flags);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700777 reply->writeInt32(static_cast <int>(input));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700778 return NO_ERROR;
779 } break;
780
781 case START_INPUT: {
782 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700783 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700784 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
785 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700786 return NO_ERROR;
787 } break;
788
789 case STOP_INPUT: {
790 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700791 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700792 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
793 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700794 return NO_ERROR;
795 } break;
796
797 case RELEASE_INPUT: {
798 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700799 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700800 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
801 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700802 return NO_ERROR;
803 } break;
804
805 case INIT_STREAM_VOLUME: {
806 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700807 audio_stream_type_t stream =
808 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700809 int indexMin = data.readInt32();
810 int indexMax = data.readInt32();
811 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
812 return NO_ERROR;
813 } break;
814
815 case SET_STREAM_VOLUME: {
816 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700817 audio_stream_type_t stream =
818 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700819 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800820 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
821 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
822 index,
823 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700824 return NO_ERROR;
825 } break;
826
827 case GET_STREAM_VOLUME: {
828 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700829 audio_stream_type_t stream =
830 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800831 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -0700832 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -0800833 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834 reply->writeInt32(index);
835 reply->writeInt32(static_cast <uint32_t>(status));
836 return NO_ERROR;
837 } break;
838
Eric Laurentde070132010-07-13 04:45:46 -0700839 case GET_STRATEGY_FOR_STREAM: {
840 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700841 audio_stream_type_t stream =
842 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700843 reply->writeInt32(getStrategyForStream(stream));
844 return NO_ERROR;
845 } break;
846
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800847 case GET_DEVICES_FOR_STREAM: {
848 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700849 audio_stream_type_t stream =
850 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800851 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
852 return NO_ERROR;
853 } break;
854
Eric Laurentde070132010-07-13 04:45:46 -0700855 case GET_OUTPUT_FOR_EFFECT: {
856 CHECK_INTERFACE(IAudioPolicyService, data, reply);
857 effect_descriptor_t desc;
858 data.read(&desc, sizeof(effect_descriptor_t));
859 audio_io_handle_t output = getOutputForEffect(&desc);
860 reply->writeInt32(static_cast <int>(output));
861 return NO_ERROR;
862 } break;
863
864 case REGISTER_EFFECT: {
865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
866 effect_descriptor_t desc;
867 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700868 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700869 uint32_t strategy = data.readInt32();
870 int session = data.readInt32();
871 int id = data.readInt32();
872 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700873 io,
Eric Laurentde070132010-07-13 04:45:46 -0700874 strategy,
875 session,
876 id)));
877 return NO_ERROR;
878 } break;
879
880 case UNREGISTER_EFFECT: {
881 CHECK_INTERFACE(IAudioPolicyService, data, reply);
882 int id = data.readInt32();
883 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
884 return NO_ERROR;
885 } break;
886
Eric Laurentdb7c0792011-08-10 10:37:50 -0700887 case SET_EFFECT_ENABLED: {
888 CHECK_INTERFACE(IAudioPolicyService, data, reply);
889 int id = data.readInt32();
890 bool enabled = static_cast <bool>(data.readInt32());
891 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
892 return NO_ERROR;
893 } break;
894
Eric Laurenteda6c362011-02-02 09:33:30 -0800895 case IS_STREAM_ACTIVE: {
896 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800897 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -0800898 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800899 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -0800900 return NO_ERROR;
901 } break;
902
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800903 case IS_STREAM_ACTIVE_REMOTELY: {
904 CHECK_INTERFACE(IAudioPolicyService, data, reply);
905 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
906 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -0800907 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800908 return NO_ERROR;
909 } break;
910
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700911 case IS_SOURCE_ACTIVE: {
912 CHECK_INTERFACE(IAudioPolicyService, data, reply);
913 audio_source_t source = (audio_source_t) data.readInt32();
914 reply->writeInt32( isSourceActive(source));
915 return NO_ERROR;
916 }
917
Eric Laurent57dae992011-07-24 13:36:09 -0700918 case QUERY_DEFAULT_PRE_PROCESSING: {
919 CHECK_INTERFACE(IAudioPolicyService, data, reply);
920 int audioSession = data.readInt32();
921 uint32_t count = data.readInt32();
Eric Laurente360f0f2014-11-05 12:15:36 -0800922 if (count > AudioEffect::kMaxPreProcessing) {
923 count = AudioEffect::kMaxPreProcessing;
924 }
Eric Laurent57dae992011-07-24 13:36:09 -0700925 uint32_t retCount = count;
Eric Laurente360f0f2014-11-05 12:15:36 -0800926 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -0700927 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
928 reply->writeInt32(status);
929 if (status != NO_ERROR && status != NO_MEMORY) {
930 retCount = 0;
931 }
932 reply->writeInt32(retCount);
Eric Laurente360f0f2014-11-05 12:15:36 -0800933 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -0700934 if (retCount < count) {
935 count = retCount;
936 }
937 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
938 }
939 delete[] descriptors;
940 return status;
941 }
942
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100943 case IS_OFFLOAD_SUPPORTED: {
944 CHECK_INTERFACE(IAudioPolicyService, data, reply);
945 audio_offload_info_t info;
946 data.read(&info, sizeof(audio_offload_info_t));
947 bool isSupported = isOffloadSupported(info);
948 reply->writeInt32(isSupported);
949 return NO_ERROR;
950 }
951
Eric Laurent203b1a12014-04-01 10:34:16 -0700952 case LIST_AUDIO_PORTS: {
953 CHECK_INTERFACE(IAudioPolicyService, data, reply);
954 audio_port_role_t role = (audio_port_role_t)data.readInt32();
955 audio_port_type_t type = (audio_port_type_t)data.readInt32();
956 unsigned int numPortsReq = data.readInt32();
Eric Laurent2fdd16b2015-02-06 10:44:24 -0800957 if (numPortsReq > MAX_ITEMS_PER_LIST) {
958 numPortsReq = MAX_ITEMS_PER_LIST;
959 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700960 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -0700961 struct audio_port *ports =
962 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent2fdd16b2015-02-06 10:44:24 -0800963 if (ports == NULL) {
964 reply->writeInt32(NO_MEMORY);
965 reply->writeInt32(0);
966 return NO_ERROR;
967 }
968 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -0700969 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
970 reply->writeInt32(status);
971 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -0700972
973 if (status == NO_ERROR) {
974 if (numPortsReq > numPorts) {
975 numPortsReq = numPorts;
976 }
977 reply->write(ports, numPortsReq * sizeof(struct audio_port));
978 reply->writeInt32(generation);
979 }
980 free(ports);
981 return NO_ERROR;
982 }
983
984 case GET_AUDIO_PORT: {
985 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jia1c771982015-09-09 09:48:34 -0700986 struct audio_port port = {};
987 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
988 ALOGE("b/23912202");
989 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700990 status_t status = getAudioPort(&port);
991 reply->writeInt32(status);
992 if (status == NO_ERROR) {
993 reply->write(&port, sizeof(struct audio_port));
994 }
995 return NO_ERROR;
996 }
997
998 case CREATE_AUDIO_PATCH: {
999 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1000 struct audio_patch patch;
1001 data.read(&patch, sizeof(struct audio_patch));
Wei Jia1c771982015-09-09 09:48:34 -07001002 audio_patch_handle_t handle = {};
1003 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1004 ALOGE("b/23912202");
1005 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001006 status_t status = createAudioPatch(&patch, &handle);
1007 reply->writeInt32(status);
1008 if (status == NO_ERROR) {
1009 reply->write(&handle, sizeof(audio_patch_handle_t));
1010 }
1011 return NO_ERROR;
1012 }
1013
1014 case RELEASE_AUDIO_PATCH: {
1015 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1016 audio_patch_handle_t handle;
1017 data.read(&handle, sizeof(audio_patch_handle_t));
1018 status_t status = releaseAudioPatch(handle);
1019 reply->writeInt32(status);
1020 return NO_ERROR;
1021 }
1022
1023 case LIST_AUDIO_PATCHES: {
1024 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1025 unsigned int numPatchesReq = data.readInt32();
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001026 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1027 numPatchesReq = MAX_ITEMS_PER_LIST;
1028 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001029 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001030 struct audio_patch *patches =
1031 (struct audio_patch *)calloc(numPatchesReq,
1032 sizeof(struct audio_patch));
Eric Laurent2fdd16b2015-02-06 10:44:24 -08001033 if (patches == NULL) {
1034 reply->writeInt32(NO_MEMORY);
1035 reply->writeInt32(0);
1036 return NO_ERROR;
1037 }
1038 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001039 status_t status = listAudioPatches(&numPatches, patches, &generation);
1040 reply->writeInt32(status);
1041 reply->writeInt32(numPatches);
1042 if (status == NO_ERROR) {
1043 if (numPatchesReq > numPatches) {
1044 numPatchesReq = numPatches;
1045 }
1046 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1047 reply->writeInt32(generation);
1048 }
1049 free(patches);
1050 return NO_ERROR;
1051 }
1052
1053 case SET_AUDIO_PORT_CONFIG: {
1054 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1055 struct audio_port_config config;
1056 data.read(&config, sizeof(struct audio_port_config));
1057 status_t status = setAudioPortConfig(&config);
1058 reply->writeInt32(status);
1059 return NO_ERROR;
1060 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001061
Eric Laurentb52c1522014-05-20 11:27:36 -07001062 case REGISTER_CLIENT: {
1063 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1064 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1065 data.readStrongBinder());
1066 registerClient(client);
1067 return NO_ERROR;
1068 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001069
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001070 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1071 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1072 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1073 data.readStrongBinder());
Wei Jia3b768702015-09-10 09:47:29 -07001074 audio_session_t session = {};
1075 audio_io_handle_t ioHandle = {};
1076 audio_devices_t device = {};
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001077 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1078 reply->writeInt32(status);
1079 if (status == NO_ERROR) {
1080 reply->writeInt32(session);
1081 reply->writeInt32(ioHandle);
1082 reply->writeInt32(device);
1083 }
1084 return NO_ERROR;
1085 } break;
1086
1087 case RELEASE_SOUNDTRIGGER_SESSION: {
1088 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1089 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1090 data.readStrongBinder());
1091 audio_session_t session = (audio_session_t)data.readInt32();
1092 status_t status = releaseSoundTriggerSession(session);
1093 reply->writeInt32(status);
1094 return NO_ERROR;
1095 } break;
1096
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001097 case GET_PHONE_STATE: {
1098 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1099 reply->writeInt32((int32_t)getPhoneState());
1100 return NO_ERROR;
1101 } break;
1102
Eric Laurentc2f1f072009-07-17 12:17:14 -07001103 default:
1104 return BBinder::onTransact(code, data, reply, flags);
1105 }
1106}
1107
1108// ----------------------------------------------------------------------------
1109
1110}; // namespace android