blob: fd18f177d937aee8e5fbb2ecd3586066dbd184b5 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25
Eric Laurent74adca92014-11-05 12:15:36 -080026#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070027#include <media/IAudioPolicyService.h>
28
Dima Zavin64760242011-05-11 14:15:23 -070029#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070030
Eric Laurentc2f1f072009-07-17 12:17:14 -070031namespace android {
32
33enum {
34 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
35 GET_DEVICE_CONNECTION_STATE,
36 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080037 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 SET_FORCE_USE,
39 GET_FORCE_USE,
40 GET_OUTPUT,
41 START_OUTPUT,
42 STOP_OUTPUT,
43 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080044 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070045 START_INPUT,
46 STOP_INPUT,
47 RELEASE_INPUT,
48 INIT_STREAM_VOLUME,
49 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070050 GET_STREAM_VOLUME,
51 GET_STRATEGY_FOR_STREAM,
52 GET_OUTPUT_FOR_EFFECT,
53 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080054 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080055 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070056 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080057 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070058 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080059 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000060 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070061 IS_OFFLOAD_SUPPORTED,
62 LIST_AUDIO_PORTS,
63 GET_AUDIO_PORT,
64 CREATE_AUDIO_PATCH,
65 RELEASE_AUDIO_PATCH,
66 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070067 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070068 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070069 GET_OUTPUT_FOR_ATTR,
70 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070071 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080072 GET_PHONE_STATE,
73 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070074 START_AUDIO_SOURCE,
75 STOP_AUDIO_SOURCE
Eric Laurentc2f1f072009-07-17 12:17:14 -070076};
77
Eric Laurent1d670b12015-02-06 10:44:24 -080078#define MAX_ITEMS_PER_LIST 1024
79
Eric Laurentc2f1f072009-07-17 12:17:14 -070080class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
81{
82public:
83 BpAudioPolicyService(const sp<IBinder>& impl)
84 : BpInterface<IAudioPolicyService>(impl)
85 {
86 }
87
88 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070089 audio_devices_t device,
90 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080091 const char *device_address,
92 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070093 {
94 Parcel data, reply;
95 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
96 data.writeInt32(static_cast <uint32_t>(device));
97 data.writeInt32(static_cast <uint32_t>(state));
98 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -080099 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
101 return static_cast <status_t> (reply.readInt32());
102 }
103
Dima Zavinfce7a472011-04-19 22:30:36 -0700104 virtual audio_policy_dev_state_t getDeviceConnectionState(
105 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700106 const char *device_address)
107 {
108 Parcel data, reply;
109 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
110 data.writeInt32(static_cast <uint32_t>(device));
111 data.writeCString(device_address);
112 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700113 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700114 }
115
Glenn Kastenf78aee72012-01-04 11:00:47 -0800116 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 {
118 Parcel data, reply;
119 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
120 data.writeInt32(state);
121 remote()->transact(SET_PHONE_STATE, data, &reply);
122 return static_cast <status_t> (reply.readInt32());
123 }
124
Dima Zavinfce7a472011-04-19 22:30:36 -0700125 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700126 {
127 Parcel data, reply;
128 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
129 data.writeInt32(static_cast <uint32_t>(usage));
130 data.writeInt32(static_cast <uint32_t>(config));
131 remote()->transact(SET_FORCE_USE, data, &reply);
132 return static_cast <status_t> (reply.readInt32());
133 }
134
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700136 {
137 Parcel data, reply;
138 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
139 data.writeInt32(static_cast <uint32_t>(usage));
140 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700141 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700142 }
143
144 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700145 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800147 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700148 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000149 audio_output_flags_t flags,
150 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700151 {
152 Parcel data, reply;
153 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
154 data.writeInt32(static_cast <uint32_t>(stream));
155 data.writeInt32(samplingRate);
156 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700157 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700158 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800159 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100160 if (offloadInfo == NULL) {
161 data.writeInt32(0);
162 } else {
163 data.writeInt32(1);
164 data.write(offloadInfo, sizeof(audio_offload_info_t));
165 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700166 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700167 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700168 }
169
Eric Laurente83b55d2014-11-14 10:06:21 -0800170 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
171 audio_io_handle_t *output,
172 audio_session_t session,
173 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700174 uid_t uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800175 uint32_t samplingRate,
176 audio_format_t format,
177 audio_channel_mask_t channelMask,
178 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700179 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800180 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700181 {
182 Parcel data, reply;
183 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
184 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800185 if (stream == NULL) {
186 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
187 return BAD_VALUE;
188 }
189 if (*stream == AUDIO_STREAM_DEFAULT) {
190 ALOGE("getOutputForAttr unspecified stream type");
191 return BAD_VALUE;
192 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700193 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800194 if (output == NULL) {
195 ALOGE("getOutputForAttr NULL output - shouldn't happen");
196 return BAD_VALUE;
197 }
198 if (attr == NULL) {
199 data.writeInt32(0);
200 } else {
201 data.writeInt32(1);
202 data.write(attr, sizeof(audio_attributes_t));
203 }
204 data.writeInt32(session);
205 if (stream == NULL) {
206 data.writeInt32(0);
207 } else {
208 data.writeInt32(1);
209 data.writeInt32(*stream);
210 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700211 data.writeInt32(uid);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700212 data.writeInt32(samplingRate);
213 data.writeInt32(static_cast <uint32_t>(format));
214 data.writeInt32(channelMask);
215 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700216 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700217 // hasOffloadInfo
218 if (offloadInfo == NULL) {
219 data.writeInt32(0);
220 } else {
221 data.writeInt32(1);
222 data.write(offloadInfo, sizeof(audio_offload_info_t));
223 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800224 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
225 if (status != NO_ERROR) {
226 return status;
227 }
228 status = (status_t)reply.readInt32();
229 if (status != NO_ERROR) {
230 return status;
231 }
232 *output = (audio_io_handle_t)reply.readInt32();
233 if (stream != NULL) {
234 *stream = (audio_stream_type_t)reply.readInt32();
235 }
236 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700237 }
238
Eric Laurentde070132010-07-13 04:45:46 -0700239 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700240 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800241 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700242 {
243 Parcel data, reply;
244 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700245 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800246 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800247 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700248 remote()->transact(START_OUTPUT, data, &reply);
249 return static_cast <status_t> (reply.readInt32());
250 }
251
Eric Laurentde070132010-07-13 04:45:46 -0700252 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700253 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700258 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800259 data.writeInt32((int32_t) stream);
Eric Laurente83b55d2014-11-14 10:06:21 -0800260 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700261 remote()->transact(STOP_OUTPUT, data, &reply);
262 return static_cast <status_t> (reply.readInt32());
263 }
264
Eric Laurente83b55d2014-11-14 10:06:21 -0800265 virtual void releaseOutput(audio_io_handle_t output,
266 audio_stream_type_t stream,
267 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 {
269 Parcel data, reply;
270 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700271 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800272 data.writeInt32((int32_t)stream);
273 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 remote()->transact(RELEASE_OUTPUT, data, &reply);
275 }
276
Eric Laurentcaf7f482014-11-25 17:50:47 -0800277 virtual status_t getInputForAttr(const audio_attributes_t *attr,
278 audio_io_handle_t *input,
279 audio_session_t session,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700280 uid_t uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800281 uint32_t samplingRate,
282 audio_format_t format,
283 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600284 audio_input_flags_t flags,
285 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700286 {
287 Parcel data, reply;
288 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800289 if (attr == NULL) {
290 ALOGE("getInputForAttr NULL attr - shouldn't happen");
291 return BAD_VALUE;
292 }
293 if (input == NULL) {
294 ALOGE("getInputForAttr NULL input - shouldn't happen");
295 return BAD_VALUE;
296 }
297 data.write(attr, sizeof(audio_attributes_t));
298 data.writeInt32(session);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700299 data.writeInt32(uid);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700300 data.writeInt32(samplingRate);
301 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700302 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700303 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600304 data.writeInt32(selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800305 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
306 if (status != NO_ERROR) {
307 return status;
308 }
309 status = reply.readInt32();
310 if (status != NO_ERROR) {
311 return status;
312 }
313 *input = (audio_io_handle_t)reply.readInt32();
314 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 }
316
Eric Laurent4dc68062014-07-28 17:26:49 -0700317 virtual status_t startInput(audio_io_handle_t input,
318 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700322 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700323 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700324 remote()->transact(START_INPUT, data, &reply);
325 return static_cast <status_t> (reply.readInt32());
326 }
327
Eric Laurent4dc68062014-07-28 17:26:49 -0700328 virtual status_t stopInput(audio_io_handle_t input,
329 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700330 {
331 Parcel data, reply;
332 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700333 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700334 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 remote()->transact(STOP_INPUT, data, &reply);
336 return static_cast <status_t> (reply.readInt32());
337 }
338
Eric Laurent4dc68062014-07-28 17:26:49 -0700339 virtual void releaseInput(audio_io_handle_t input,
340 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700341 {
342 Parcel data, reply;
343 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700344 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700345 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 remote()->transact(RELEASE_INPUT, data, &reply);
347 }
348
Dima Zavinfce7a472011-04-19 22:30:36 -0700349 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 int indexMin,
351 int indexMax)
352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
355 data.writeInt32(static_cast <uint32_t>(stream));
356 data.writeInt32(indexMin);
357 data.writeInt32(indexMax);
358 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
359 return static_cast <status_t> (reply.readInt32());
360 }
361
Eric Laurent83844cc2011-11-18 16:43:31 -0800362 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
363 int index,
364 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 {
366 Parcel data, reply;
367 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
368 data.writeInt32(static_cast <uint32_t>(stream));
369 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800370 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700371 remote()->transact(SET_STREAM_VOLUME, data, &reply);
372 return static_cast <status_t> (reply.readInt32());
373 }
374
Eric Laurent83844cc2011-11-18 16:43:31 -0800375 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
376 int *index,
377 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 {
379 Parcel data, reply;
380 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
381 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800382 data.writeInt32(static_cast <uint32_t>(device));
383
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 remote()->transact(GET_STREAM_VOLUME, data, &reply);
385 int lIndex = reply.readInt32();
386 if (index) *index = lIndex;
387 return static_cast <status_t> (reply.readInt32());
388 }
Eric Laurentde070132010-07-13 04:45:46 -0700389
Dima Zavinfce7a472011-04-19 22:30:36 -0700390 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
394 data.writeInt32(static_cast <uint32_t>(stream));
395 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
396 return reply.readInt32();
397 }
398
Eric Laurent63742522012-03-08 13:42:42 -0800399 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800400 {
401 Parcel data, reply;
402 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
403 data.writeInt32(static_cast <uint32_t>(stream));
404 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800405 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800406 }
407
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700408 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
412 data.write(desc, sizeof(effect_descriptor_t));
413 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
414 return static_cast <audio_io_handle_t> (reply.readInt32());
415 }
416
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700417 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700418 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700419 uint32_t strategy,
420 int session,
421 int id)
422 {
423 Parcel data, reply;
424 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
425 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700426 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700427 data.writeInt32(strategy);
428 data.writeInt32(session);
429 data.writeInt32(id);
430 remote()->transact(REGISTER_EFFECT, data, &reply);
431 return static_cast <status_t> (reply.readInt32());
432 }
433
434 virtual status_t unregisterEffect(int id)
435 {
436 Parcel data, reply;
437 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
438 data.writeInt32(id);
439 remote()->transact(UNREGISTER_EFFECT, data, &reply);
440 return static_cast <status_t> (reply.readInt32());
441 }
442
Eric Laurentdb7c0792011-08-10 10:37:50 -0700443 virtual status_t setEffectEnabled(int id, bool enabled)
444 {
445 Parcel data, reply;
446 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
447 data.writeInt32(id);
448 data.writeInt32(enabled);
449 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
450 return static_cast <status_t> (reply.readInt32());
451 }
452
Glenn Kastenfff6d712012-01-12 16:38:12 -0800453 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800457 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800458 data.writeInt32(inPastMs);
459 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
460 return reply.readInt32();
461 }
Eric Laurent57dae992011-07-24 13:36:09 -0700462
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800463 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
464 {
465 Parcel data, reply;
466 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
467 data.writeInt32((int32_t) stream);
468 data.writeInt32(inPastMs);
469 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
470 return reply.readInt32();
471 }
472
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700473 virtual bool isSourceActive(audio_source_t source) const
474 {
475 Parcel data, reply;
476 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
477 data.writeInt32((int32_t) source);
478 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
479 return reply.readInt32();
480 }
481
Eric Laurent57dae992011-07-24 13:36:09 -0700482 virtual status_t queryDefaultPreProcessing(int audioSession,
483 effect_descriptor_t *descriptors,
484 uint32_t *count)
485 {
486 if (descriptors == NULL || count == NULL) {
487 return BAD_VALUE;
488 }
489 Parcel data, reply;
490 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
491 data.writeInt32(audioSession);
492 data.writeInt32(*count);
493 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
494 if (status != NO_ERROR) {
495 return status;
496 }
497 status = static_cast <status_t> (reply.readInt32());
498 uint32_t retCount = reply.readInt32();
499 if (retCount != 0) {
500 uint32_t numDesc = (retCount < *count) ? retCount : *count;
501 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
502 }
503 *count = retCount;
504 return status;
505 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000506
507 virtual bool isOffloadSupported(const audio_offload_info_t& info)
508 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100509 Parcel data, reply;
510 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
511 data.write(&info, sizeof(audio_offload_info_t));
512 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700513 return reply.readInt32();
514 }
515
516 virtual status_t listAudioPorts(audio_port_role_t role,
517 audio_port_type_t type,
518 unsigned int *num_ports,
519 struct audio_port *ports,
520 unsigned int *generation)
521 {
522 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
523 generation == NULL) {
524 return BAD_VALUE;
525 }
526 Parcel data, reply;
527 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
528 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
529 data.writeInt32(role);
530 data.writeInt32(type);
531 data.writeInt32(numPortsReq);
532 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
533 if (status == NO_ERROR) {
534 status = (status_t)reply.readInt32();
535 *num_ports = (unsigned int)reply.readInt32();
536 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700537 if (status == NO_ERROR) {
538 if (numPortsReq > *num_ports) {
539 numPortsReq = *num_ports;
540 }
541 if (numPortsReq > 0) {
542 reply.read(ports, numPortsReq * sizeof(struct audio_port));
543 }
544 *generation = reply.readInt32();
545 }
546 return status;
547 }
548
549 virtual status_t getAudioPort(struct audio_port *port)
550 {
551 if (port == NULL) {
552 return BAD_VALUE;
553 }
554 Parcel data, reply;
555 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
556 data.write(port, sizeof(struct audio_port));
557 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
558 if (status != NO_ERROR ||
559 (status = (status_t)reply.readInt32()) != NO_ERROR) {
560 return status;
561 }
562 reply.read(port, sizeof(struct audio_port));
563 return status;
564 }
565
566 virtual status_t createAudioPatch(const struct audio_patch *patch,
567 audio_patch_handle_t *handle)
568 {
569 if (patch == NULL || handle == NULL) {
570 return BAD_VALUE;
571 }
572 Parcel data, reply;
573 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
574 data.write(patch, sizeof(struct audio_patch));
575 data.write(handle, sizeof(audio_patch_handle_t));
576 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
577 if (status != NO_ERROR ||
578 (status = (status_t)reply.readInt32()) != NO_ERROR) {
579 return status;
580 }
581 reply.read(handle, sizeof(audio_patch_handle_t));
582 return status;
583 }
584
585 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
586 {
587 Parcel data, reply;
588 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
589 data.write(&handle, sizeof(audio_patch_handle_t));
590 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
591 if (status != NO_ERROR) {
592 status = (status_t)reply.readInt32();
593 }
594 return status;
595 }
596
597 virtual status_t listAudioPatches(unsigned int *num_patches,
598 struct audio_patch *patches,
599 unsigned int *generation)
600 {
601 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
602 generation == NULL) {
603 return BAD_VALUE;
604 }
605 Parcel data, reply;
606 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
607 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
608 data.writeInt32(numPatchesReq);
609 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
610 if (status == NO_ERROR) {
611 status = (status_t)reply.readInt32();
612 *num_patches = (unsigned int)reply.readInt32();
613 }
614 if (status == NO_ERROR) {
615 if (numPatchesReq > *num_patches) {
616 numPatchesReq = *num_patches;
617 }
618 if (numPatchesReq > 0) {
619 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
620 }
621 *generation = reply.readInt32();
622 }
623 return status;
624 }
625
626 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
627 {
628 if (config == NULL) {
629 return BAD_VALUE;
630 }
631 Parcel data, reply;
632 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
633 data.write(config, sizeof(struct audio_port_config));
634 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
635 if (status != NO_ERROR) {
636 status = (status_t)reply.readInt32();
637 }
638 return status;
639 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700640
Eric Laurentb52c1522014-05-20 11:27:36 -0700641 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
642 {
643 Parcel data, reply;
644 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800645 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700646 remote()->transact(REGISTER_CLIENT, data, &reply);
647 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700648
649 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
650 audio_io_handle_t *ioHandle,
651 audio_devices_t *device)
652 {
653 if (session == NULL || ioHandle == NULL || device == NULL) {
654 return BAD_VALUE;
655 }
656 Parcel data, reply;
657 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
658 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
659 if (status != NO_ERROR) {
660 return status;
661 }
662 status = (status_t)reply.readInt32();
663 if (status == NO_ERROR) {
664 *session = (audio_session_t)reply.readInt32();
665 *ioHandle = (audio_io_handle_t)reply.readInt32();
666 *device = (audio_devices_t)reply.readInt32();
667 }
668 return status;
669 }
670
671 virtual status_t releaseSoundTriggerSession(audio_session_t session)
672 {
673 Parcel data, reply;
674 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
675 data.writeInt32(session);
676 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
677 if (status != NO_ERROR) {
678 return status;
679 }
680 return (status_t)reply.readInt32();
681 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700682
683 virtual audio_mode_t getPhoneState()
684 {
685 Parcel data, reply;
686 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
687 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
688 if (status != NO_ERROR) {
689 return AUDIO_MODE_INVALID;
690 }
691 return (audio_mode_t)reply.readInt32();
692 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800693
694 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
695 {
696 Parcel data, reply;
697 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
698 data.writeInt32(registration ? 1 : 0);
699 size_t size = mixes.size();
700 if (size > MAX_MIXES_PER_POLICY) {
701 size = MAX_MIXES_PER_POLICY;
702 }
703 size_t sizePosition = data.dataPosition();
704 data.writeInt32(size);
705 size_t finalSize = size;
706 for (size_t i = 0; i < size; i++) {
707 size_t position = data.dataPosition();
708 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
709 data.setDataPosition(position);
710 finalSize--;
711 }
712 }
713 if (size != finalSize) {
714 size_t position = data.dataPosition();
715 data.setDataPosition(sizePosition);
716 data.writeInt32(finalSize);
717 data.setDataPosition(position);
718 }
719 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
720 if (status == NO_ERROR) {
721 status = (status_t)reply.readInt32();
722 }
723 return status;
724 }
Eric Laurent554a2772015-04-10 11:29:24 -0700725
726 virtual status_t startAudioSource(const struct audio_port_config *source,
727 const audio_attributes_t *attributes,
728 audio_io_handle_t *handle)
729 {
730 Parcel data, reply;
731 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
732 if (source == NULL || attributes == NULL || handle == NULL) {
733 return BAD_VALUE;
734 }
735 data.write(source, sizeof(struct audio_port_config));
736 data.write(attributes, sizeof(audio_attributes_t));
737 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
738 if (status != NO_ERROR) {
739 return status;
740 }
741 status = (status_t)reply.readInt32();
742 if (status != NO_ERROR) {
743 return status;
744 }
745 *handle = (audio_io_handle_t)reply.readInt32();
746 return status;
747 }
748
749 virtual status_t stopAudioSource(audio_io_handle_t handle)
750 {
751 Parcel data, reply;
752 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
753 data.writeInt32(handle);
754 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
755 if (status != NO_ERROR) {
756 return status;
757 }
758 status = (status_t)reply.readInt32();
759 return status;
760 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700761};
762
763IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
764
765// ----------------------------------------------------------------------
766
767
768status_t BnAudioPolicyService::onTransact(
769 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
770{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700771 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700772 case SET_DEVICE_CONNECTION_STATE: {
773 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700774 audio_devices_t device =
775 static_cast <audio_devices_t>(data.readInt32());
776 audio_policy_dev_state_t state =
777 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700778 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800779 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700780 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
781 state,
Paul McLeane743a472015-01-28 11:07:31 -0800782 device_address,
783 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700784 return NO_ERROR;
785 } break;
786
787 case GET_DEVICE_CONNECTION_STATE: {
788 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700789 audio_devices_t device =
790 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700791 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700792 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
793 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700794 return NO_ERROR;
795 } break;
796
797 case SET_PHONE_STATE: {
798 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700799 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
800 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700801 return NO_ERROR;
802 } break;
803
Eric Laurentc2f1f072009-07-17 12:17:14 -0700804 case SET_FORCE_USE: {
805 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700806 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
807 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700808 audio_policy_forced_cfg_t config =
809 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700810 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
811 return NO_ERROR;
812 } break;
813
814 case GET_FORCE_USE: {
815 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700816 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
817 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700818 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
819 return NO_ERROR;
820 } break;
821
822 case GET_OUTPUT: {
823 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700824 audio_stream_type_t stream =
825 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700826 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800827 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700828 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700829 audio_output_flags_t flags =
830 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100831 bool hasOffloadInfo = data.readInt32() != 0;
832 audio_offload_info_t offloadInfo;
833 if (hasOffloadInfo) {
834 data.read(&offloadInfo, sizeof(audio_offload_info_t));
835 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700836 audio_io_handle_t output = getOutput(stream,
837 samplingRate,
838 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700839 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100840 flags,
841 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700842 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700843 return NO_ERROR;
844 } break;
845
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700846 case GET_OUTPUT_FOR_ATTR: {
847 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800848 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800849 bool hasAttributes = data.readInt32() != 0;
850 if (hasAttributes) {
851 data.read(&attr, sizeof(audio_attributes_t));
852 }
853 audio_session_t session = (audio_session_t)data.readInt32();
854 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
855 bool hasStream = data.readInt32() != 0;
856 if (hasStream) {
857 stream = (audio_stream_type_t)data.readInt32();
858 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700859 uid_t uid = (uid_t)data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700860 uint32_t samplingRate = data.readInt32();
861 audio_format_t format = (audio_format_t) data.readInt32();
862 audio_channel_mask_t channelMask = data.readInt32();
863 audio_output_flags_t flags =
864 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700865 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700866 bool hasOffloadInfo = data.readInt32() != 0;
867 audio_offload_info_t offloadInfo;
868 if (hasOffloadInfo) {
869 data.read(&offloadInfo, sizeof(audio_offload_info_t));
870 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800871 audio_io_handle_t output;
872 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700873 &output, session, &stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800874 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700875 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800876 reply->writeInt32(status);
877 reply->writeInt32(output);
878 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700879 return NO_ERROR;
880 } break;
881
Eric Laurentc2f1f072009-07-17 12:17:14 -0700882 case START_OUTPUT: {
883 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700884 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800885 audio_stream_type_t stream =
886 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800887 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700888 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800889 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700890 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700891 return NO_ERROR;
892 } break;
893
894 case STOP_OUTPUT: {
895 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700896 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800897 audio_stream_type_t stream =
898 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800899 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700900 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800901 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700902 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700903 return NO_ERROR;
904 } break;
905
906 case RELEASE_OUTPUT: {
907 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700908 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800909 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
910 audio_session_t session = (audio_session_t)data.readInt32();
911 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700912 return NO_ERROR;
913 } break;
914
Eric Laurentcaf7f482014-11-25 17:50:47 -0800915 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700916 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800917 audio_attributes_t attr;
918 data.read(&attr, sizeof(audio_attributes_t));
919 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700920 uid_t uid = (uid_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700921 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800922 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700923 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700924 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600925 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800926 audio_io_handle_t input;
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700927 status_t status = getInputForAttr(&attr, &input, session, uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800928 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600929 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800930 reply->writeInt32(status);
931 if (status == NO_ERROR) {
932 reply->writeInt32(input);
933 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700934 return NO_ERROR;
935 } break;
936
937 case START_INPUT: {
938 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700939 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700940 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
941 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700942 return NO_ERROR;
943 } break;
944
945 case STOP_INPUT: {
946 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700947 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700948 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
949 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700950 return NO_ERROR;
951 } break;
952
953 case RELEASE_INPUT: {
954 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700955 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700956 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
957 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700958 return NO_ERROR;
959 } break;
960
961 case INIT_STREAM_VOLUME: {
962 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700963 audio_stream_type_t stream =
964 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700965 int indexMin = data.readInt32();
966 int indexMax = data.readInt32();
967 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
968 return NO_ERROR;
969 } break;
970
971 case SET_STREAM_VOLUME: {
972 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700973 audio_stream_type_t stream =
974 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700975 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -0800976 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
977 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
978 index,
979 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700980 return NO_ERROR;
981 } break;
982
983 case GET_STREAM_VOLUME: {
984 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700985 audio_stream_type_t stream =
986 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -0800987 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700988 int index;
Eric Laurent83844cc2011-11-18 16:43:31 -0800989 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700990 reply->writeInt32(index);
991 reply->writeInt32(static_cast <uint32_t>(status));
992 return NO_ERROR;
993 } break;
994
Eric Laurentde070132010-07-13 04:45:46 -0700995 case GET_STRATEGY_FOR_STREAM: {
996 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700997 audio_stream_type_t stream =
998 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -0700999 reply->writeInt32(getStrategyForStream(stream));
1000 return NO_ERROR;
1001 } break;
1002
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001003 case GET_DEVICES_FOR_STREAM: {
1004 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001005 audio_stream_type_t stream =
1006 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001007 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1008 return NO_ERROR;
1009 } break;
1010
Eric Laurentde070132010-07-13 04:45:46 -07001011 case GET_OUTPUT_FOR_EFFECT: {
1012 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1013 effect_descriptor_t desc;
1014 data.read(&desc, sizeof(effect_descriptor_t));
1015 audio_io_handle_t output = getOutputForEffect(&desc);
1016 reply->writeInt32(static_cast <int>(output));
1017 return NO_ERROR;
1018 } break;
1019
1020 case REGISTER_EFFECT: {
1021 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1022 effect_descriptor_t desc;
1023 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001024 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001025 uint32_t strategy = data.readInt32();
1026 int session = data.readInt32();
1027 int id = data.readInt32();
1028 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001029 io,
Eric Laurentde070132010-07-13 04:45:46 -07001030 strategy,
1031 session,
1032 id)));
1033 return NO_ERROR;
1034 } break;
1035
1036 case UNREGISTER_EFFECT: {
1037 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1038 int id = data.readInt32();
1039 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1040 return NO_ERROR;
1041 } break;
1042
Eric Laurentdb7c0792011-08-10 10:37:50 -07001043 case SET_EFFECT_ENABLED: {
1044 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1045 int id = data.readInt32();
1046 bool enabled = static_cast <bool>(data.readInt32());
1047 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1048 return NO_ERROR;
1049 } break;
1050
Eric Laurenteda6c362011-02-02 09:33:30 -08001051 case IS_STREAM_ACTIVE: {
1052 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001053 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001054 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001055 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001056 return NO_ERROR;
1057 } break;
1058
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001059 case IS_STREAM_ACTIVE_REMOTELY: {
1060 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1061 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1062 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001063 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001064 return NO_ERROR;
1065 } break;
1066
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001067 case IS_SOURCE_ACTIVE: {
1068 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1069 audio_source_t source = (audio_source_t) data.readInt32();
1070 reply->writeInt32( isSourceActive(source));
1071 return NO_ERROR;
1072 }
1073
Eric Laurent57dae992011-07-24 13:36:09 -07001074 case QUERY_DEFAULT_PRE_PROCESSING: {
1075 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1076 int audioSession = data.readInt32();
1077 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001078 if (count > AudioEffect::kMaxPreProcessing) {
1079 count = AudioEffect::kMaxPreProcessing;
1080 }
Eric Laurent57dae992011-07-24 13:36:09 -07001081 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001082 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001083 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1084 reply->writeInt32(status);
1085 if (status != NO_ERROR && status != NO_MEMORY) {
1086 retCount = 0;
1087 }
1088 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001089 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001090 if (retCount < count) {
1091 count = retCount;
1092 }
1093 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1094 }
1095 delete[] descriptors;
1096 return status;
1097 }
1098
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001099 case IS_OFFLOAD_SUPPORTED: {
1100 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1101 audio_offload_info_t info;
1102 data.read(&info, sizeof(audio_offload_info_t));
1103 bool isSupported = isOffloadSupported(info);
1104 reply->writeInt32(isSupported);
1105 return NO_ERROR;
1106 }
1107
Eric Laurent203b1a12014-04-01 10:34:16 -07001108 case LIST_AUDIO_PORTS: {
1109 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1110 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1111 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1112 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001113 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1114 numPortsReq = MAX_ITEMS_PER_LIST;
1115 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001116 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001117 struct audio_port *ports =
1118 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001119 if (ports == NULL) {
1120 reply->writeInt32(NO_MEMORY);
1121 reply->writeInt32(0);
1122 return NO_ERROR;
1123 }
1124 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001125 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1126 reply->writeInt32(status);
1127 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001128
1129 if (status == NO_ERROR) {
1130 if (numPortsReq > numPorts) {
1131 numPortsReq = numPorts;
1132 }
1133 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1134 reply->writeInt32(generation);
1135 }
1136 free(ports);
1137 return NO_ERROR;
1138 }
1139
1140 case GET_AUDIO_PORT: {
1141 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1142 struct audio_port port;
1143 data.read(&port, sizeof(struct audio_port));
1144 status_t status = getAudioPort(&port);
1145 reply->writeInt32(status);
1146 if (status == NO_ERROR) {
1147 reply->write(&port, sizeof(struct audio_port));
1148 }
1149 return NO_ERROR;
1150 }
1151
1152 case CREATE_AUDIO_PATCH: {
1153 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1154 struct audio_patch patch;
1155 data.read(&patch, sizeof(struct audio_patch));
1156 audio_patch_handle_t handle;
1157 data.read(&handle, sizeof(audio_patch_handle_t));
1158 status_t status = createAudioPatch(&patch, &handle);
1159 reply->writeInt32(status);
1160 if (status == NO_ERROR) {
1161 reply->write(&handle, sizeof(audio_patch_handle_t));
1162 }
1163 return NO_ERROR;
1164 }
1165
1166 case RELEASE_AUDIO_PATCH: {
1167 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1168 audio_patch_handle_t handle;
1169 data.read(&handle, sizeof(audio_patch_handle_t));
1170 status_t status = releaseAudioPatch(handle);
1171 reply->writeInt32(status);
1172 return NO_ERROR;
1173 }
1174
1175 case LIST_AUDIO_PATCHES: {
1176 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1177 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001178 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1179 numPatchesReq = MAX_ITEMS_PER_LIST;
1180 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001181 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001182 struct audio_patch *patches =
1183 (struct audio_patch *)calloc(numPatchesReq,
1184 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001185 if (patches == NULL) {
1186 reply->writeInt32(NO_MEMORY);
1187 reply->writeInt32(0);
1188 return NO_ERROR;
1189 }
1190 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001191 status_t status = listAudioPatches(&numPatches, patches, &generation);
1192 reply->writeInt32(status);
1193 reply->writeInt32(numPatches);
1194 if (status == NO_ERROR) {
1195 if (numPatchesReq > numPatches) {
1196 numPatchesReq = numPatches;
1197 }
1198 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1199 reply->writeInt32(generation);
1200 }
1201 free(patches);
1202 return NO_ERROR;
1203 }
1204
1205 case SET_AUDIO_PORT_CONFIG: {
1206 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1207 struct audio_port_config config;
1208 data.read(&config, sizeof(struct audio_port_config));
1209 status_t status = setAudioPortConfig(&config);
1210 reply->writeInt32(status);
1211 return NO_ERROR;
1212 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001213
Eric Laurentb52c1522014-05-20 11:27:36 -07001214 case REGISTER_CLIENT: {
1215 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1216 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1217 data.readStrongBinder());
1218 registerClient(client);
1219 return NO_ERROR;
1220 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001221
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001222 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1223 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1224 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1225 data.readStrongBinder());
1226 audio_session_t session;
1227 audio_io_handle_t ioHandle;
1228 audio_devices_t device;
1229 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1230 reply->writeInt32(status);
1231 if (status == NO_ERROR) {
1232 reply->writeInt32(session);
1233 reply->writeInt32(ioHandle);
1234 reply->writeInt32(device);
1235 }
1236 return NO_ERROR;
1237 } break;
1238
1239 case RELEASE_SOUNDTRIGGER_SESSION: {
1240 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1241 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1242 data.readStrongBinder());
1243 audio_session_t session = (audio_session_t)data.readInt32();
1244 status_t status = releaseSoundTriggerSession(session);
1245 reply->writeInt32(status);
1246 return NO_ERROR;
1247 } break;
1248
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001249 case GET_PHONE_STATE: {
1250 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1251 reply->writeInt32((int32_t)getPhoneState());
1252 return NO_ERROR;
1253 } break;
1254
Eric Laurentbaac1832014-12-01 17:52:59 -08001255 case REGISTER_POLICY_MIXES: {
1256 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1257 bool registration = data.readInt32() == 1;
1258 Vector<AudioMix> mixes;
1259 size_t size = (size_t)data.readInt32();
1260 if (size > MAX_MIXES_PER_POLICY) {
1261 size = MAX_MIXES_PER_POLICY;
1262 }
1263 for (size_t i = 0; i < size; i++) {
1264 AudioMix mix;
1265 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1266 mixes.add(mix);
1267 }
1268 }
1269 status_t status = registerPolicyMixes(mixes, registration);
1270 reply->writeInt32(status);
1271 return NO_ERROR;
1272 } break;
1273
Eric Laurent554a2772015-04-10 11:29:24 -07001274 case START_AUDIO_SOURCE: {
1275 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1276 struct audio_port_config source;
1277 data.read(&source, sizeof(struct audio_port_config));
1278 audio_attributes_t attributes;
1279 data.read(&attributes, sizeof(audio_attributes_t));
1280 audio_io_handle_t handle;
1281 status_t status = startAudioSource(&source, &attributes, &handle);
1282 reply->writeInt32(status);
1283 reply->writeInt32(handle);
1284 return NO_ERROR;
1285 } break;
1286
1287 case STOP_AUDIO_SOURCE: {
1288 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1289 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1290 status_t status = stopAudioSource(handle);
1291 reply->writeInt32(status);
1292 return NO_ERROR;
1293 } break;
1294
Eric Laurentc2f1f072009-07-17 12:17:14 -07001295 default:
1296 return BBinder::onTransact(code, data, reply, flags);
1297 }
1298}
1299
1300// ----------------------------------------------------------------------------
1301
Glenn Kasten40bc9062015-03-20 09:09:33 -07001302} // namespace android