blob: 16e8f11c52cc2c40fdedf1545511b77b95520357 [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,
Eric Laurente8726fe2015-06-26 09:39:24 -070075 STOP_AUDIO_SOURCE,
76 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080077 SET_MASTER_MONO,
78 GET_MASTER_MONO,
Eric Laurentc2f1f072009-07-17 12:17:14 -070079};
80
Eric Laurent1d670b12015-02-06 10:44:24 -080081#define MAX_ITEMS_PER_LIST 1024
82
Eric Laurentc2f1f072009-07-17 12:17:14 -070083class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
84{
85public:
86 BpAudioPolicyService(const sp<IBinder>& impl)
87 : BpInterface<IAudioPolicyService>(impl)
88 {
89 }
90
91 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070092 audio_devices_t device,
93 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080094 const char *device_address,
95 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070096 {
97 Parcel data, reply;
98 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
99 data.writeInt32(static_cast <uint32_t>(device));
100 data.writeInt32(static_cast <uint32_t>(state));
101 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800102 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700103 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
104 return static_cast <status_t> (reply.readInt32());
105 }
106
Dima Zavinfce7a472011-04-19 22:30:36 -0700107 virtual audio_policy_dev_state_t getDeviceConnectionState(
108 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109 const char *device_address)
110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
113 data.writeInt32(static_cast <uint32_t>(device));
114 data.writeCString(device_address);
115 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700116 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 }
118
Glenn Kastenf78aee72012-01-04 11:00:47 -0800119 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700120 {
121 Parcel data, reply;
122 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
123 data.writeInt32(state);
124 remote()->transact(SET_PHONE_STATE, data, &reply);
125 return static_cast <status_t> (reply.readInt32());
126 }
127
Dima Zavinfce7a472011-04-19 22:30:36 -0700128 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 {
130 Parcel data, reply;
131 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
132 data.writeInt32(static_cast <uint32_t>(usage));
133 data.writeInt32(static_cast <uint32_t>(config));
134 remote()->transact(SET_FORCE_USE, data, &reply);
135 return static_cast <status_t> (reply.readInt32());
136 }
137
Dima Zavinfce7a472011-04-19 22:30:36 -0700138 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700139 {
140 Parcel data, reply;
141 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
142 data.writeInt32(static_cast <uint32_t>(usage));
143 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700144 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 }
146
147 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700148 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800150 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700151 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000152 audio_output_flags_t flags,
153 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
157 data.writeInt32(static_cast <uint32_t>(stream));
158 data.writeInt32(samplingRate);
159 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700160 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700161 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800162 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100163 if (offloadInfo == NULL) {
164 data.writeInt32(0);
165 } else {
166 data.writeInt32(1);
167 data.write(offloadInfo, sizeof(audio_offload_info_t));
168 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700169 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700170 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700171 }
172
Eric Laurente83b55d2014-11-14 10:06:21 -0800173 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
174 audio_io_handle_t *output,
175 audio_session_t session,
176 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700177 uid_t uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800178 uint32_t samplingRate,
179 audio_format_t format,
180 audio_channel_mask_t channelMask,
181 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700182 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800183 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
187 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800188 if (stream == NULL) {
189 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
190 return BAD_VALUE;
191 }
192 if (*stream == AUDIO_STREAM_DEFAULT) {
193 ALOGE("getOutputForAttr unspecified stream type");
194 return BAD_VALUE;
195 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700196 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 if (output == NULL) {
198 ALOGE("getOutputForAttr NULL output - shouldn't happen");
199 return BAD_VALUE;
200 }
201 if (attr == NULL) {
202 data.writeInt32(0);
203 } else {
204 data.writeInt32(1);
205 data.write(attr, sizeof(audio_attributes_t));
206 }
207 data.writeInt32(session);
208 if (stream == NULL) {
209 data.writeInt32(0);
210 } else {
211 data.writeInt32(1);
212 data.writeInt32(*stream);
213 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700214 data.writeInt32(uid);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700215 data.writeInt32(samplingRate);
216 data.writeInt32(static_cast <uint32_t>(format));
217 data.writeInt32(channelMask);
218 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700219 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700220 // hasOffloadInfo
221 if (offloadInfo == NULL) {
222 data.writeInt32(0);
223 } else {
224 data.writeInt32(1);
225 data.write(offloadInfo, sizeof(audio_offload_info_t));
226 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800227 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
228 if (status != NO_ERROR) {
229 return status;
230 }
231 status = (status_t)reply.readInt32();
232 if (status != NO_ERROR) {
233 return status;
234 }
235 *output = (audio_io_handle_t)reply.readInt32();
236 if (stream != NULL) {
237 *stream = (audio_stream_type_t)reply.readInt32();
238 }
239 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700240 }
241
Eric Laurentde070132010-07-13 04:45:46 -0700242 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700243 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800244 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700248 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800249 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800250 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 remote()->transact(START_OUTPUT, data, &reply);
252 return static_cast <status_t> (reply.readInt32());
253 }
254
Eric Laurentde070132010-07-13 04:45:46 -0700255 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700256 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800257 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700261 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800262 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800263 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 remote()->transact(STOP_OUTPUT, data, &reply);
265 return static_cast <status_t> (reply.readInt32());
266 }
267
Eric Laurente83b55d2014-11-14 10:06:21 -0800268 virtual void releaseOutput(audio_io_handle_t output,
269 audio_stream_type_t stream,
270 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700274 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800275 data.writeInt32((int32_t)stream);
276 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 remote()->transact(RELEASE_OUTPUT, data, &reply);
278 }
279
Eric Laurentcaf7f482014-11-25 17:50:47 -0800280 virtual status_t getInputForAttr(const audio_attributes_t *attr,
281 audio_io_handle_t *input,
282 audio_session_t session,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700283 uid_t uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800284 uint32_t samplingRate,
285 audio_format_t format,
286 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600287 audio_input_flags_t flags,
288 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800292 if (attr == NULL) {
293 ALOGE("getInputForAttr NULL attr - shouldn't happen");
294 return BAD_VALUE;
295 }
296 if (input == NULL) {
297 ALOGE("getInputForAttr NULL input - shouldn't happen");
298 return BAD_VALUE;
299 }
300 data.write(attr, sizeof(audio_attributes_t));
301 data.writeInt32(session);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700302 data.writeInt32(uid);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700303 data.writeInt32(samplingRate);
304 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700305 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700306 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600307 data.writeInt32(selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800308 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
309 if (status != NO_ERROR) {
310 return status;
311 }
312 status = reply.readInt32();
313 if (status != NO_ERROR) {
314 return status;
315 }
316 *input = (audio_io_handle_t)reply.readInt32();
317 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700318 }
319
Eric Laurent4dc68062014-07-28 17:26:49 -0700320 virtual status_t startInput(audio_io_handle_t input,
321 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700322 {
323 Parcel data, reply;
324 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700325 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700326 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327 remote()->transact(START_INPUT, data, &reply);
328 return static_cast <status_t> (reply.readInt32());
329 }
330
Eric Laurent4dc68062014-07-28 17:26:49 -0700331 virtual status_t stopInput(audio_io_handle_t input,
332 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 {
334 Parcel data, reply;
335 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700336 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700337 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 remote()->transact(STOP_INPUT, data, &reply);
339 return static_cast <status_t> (reply.readInt32());
340 }
341
Eric Laurent4dc68062014-07-28 17:26:49 -0700342 virtual void releaseInput(audio_io_handle_t input,
343 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700344 {
345 Parcel data, reply;
346 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700347 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700348 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 remote()->transact(RELEASE_INPUT, data, &reply);
350 }
351
Dima Zavinfce7a472011-04-19 22:30:36 -0700352 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353 int indexMin,
354 int indexMax)
355 {
356 Parcel data, reply;
357 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
358 data.writeInt32(static_cast <uint32_t>(stream));
359 data.writeInt32(indexMin);
360 data.writeInt32(indexMax);
361 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
362 return static_cast <status_t> (reply.readInt32());
363 }
364
Eric Laurent83844cc2011-11-18 16:43:31 -0800365 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
366 int index,
367 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700368 {
369 Parcel data, reply;
370 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
371 data.writeInt32(static_cast <uint32_t>(stream));
372 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800373 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 remote()->transact(SET_STREAM_VOLUME, data, &reply);
375 return static_cast <status_t> (reply.readInt32());
376 }
377
Eric Laurent83844cc2011-11-18 16:43:31 -0800378 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
379 int *index,
380 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 {
382 Parcel data, reply;
383 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
384 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800385 data.writeInt32(static_cast <uint32_t>(device));
386
Eric Laurentc2f1f072009-07-17 12:17:14 -0700387 remote()->transact(GET_STREAM_VOLUME, data, &reply);
388 int lIndex = reply.readInt32();
389 if (index) *index = lIndex;
390 return static_cast <status_t> (reply.readInt32());
391 }
Eric Laurentde070132010-07-13 04:45:46 -0700392
Dima Zavinfce7a472011-04-19 22:30:36 -0700393 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700394 {
395 Parcel data, reply;
396 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
397 data.writeInt32(static_cast <uint32_t>(stream));
398 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
399 return reply.readInt32();
400 }
401
Eric Laurent63742522012-03-08 13:42:42 -0800402 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
406 data.writeInt32(static_cast <uint32_t>(stream));
407 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800408 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800409 }
410
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700411 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700412 {
413 Parcel data, reply;
414 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
415 data.write(desc, sizeof(effect_descriptor_t));
416 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
417 return static_cast <audio_io_handle_t> (reply.readInt32());
418 }
419
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700420 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700421 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700422 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800423 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700424 int id)
425 {
426 Parcel data, reply;
427 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
428 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700429 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700430 data.writeInt32(strategy);
431 data.writeInt32(session);
432 data.writeInt32(id);
433 remote()->transact(REGISTER_EFFECT, data, &reply);
434 return static_cast <status_t> (reply.readInt32());
435 }
436
437 virtual status_t unregisterEffect(int id)
438 {
439 Parcel data, reply;
440 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
441 data.writeInt32(id);
442 remote()->transact(UNREGISTER_EFFECT, data, &reply);
443 return static_cast <status_t> (reply.readInt32());
444 }
445
Eric Laurentdb7c0792011-08-10 10:37:50 -0700446 virtual status_t setEffectEnabled(int id, bool enabled)
447 {
448 Parcel data, reply;
449 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
450 data.writeInt32(id);
451 data.writeInt32(enabled);
452 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
453 return static_cast <status_t> (reply.readInt32());
454 }
455
Glenn Kastenfff6d712012-01-12 16:38:12 -0800456 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800457 {
458 Parcel data, reply;
459 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800460 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800461 data.writeInt32(inPastMs);
462 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
463 return reply.readInt32();
464 }
Eric Laurent57dae992011-07-24 13:36:09 -0700465
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800466 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
467 {
468 Parcel data, reply;
469 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
470 data.writeInt32((int32_t) stream);
471 data.writeInt32(inPastMs);
472 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
473 return reply.readInt32();
474 }
475
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700476 virtual bool isSourceActive(audio_source_t source) const
477 {
478 Parcel data, reply;
479 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
480 data.writeInt32((int32_t) source);
481 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
482 return reply.readInt32();
483 }
484
Glenn Kastend848eb42016-03-08 13:42:11 -0800485 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700486 effect_descriptor_t *descriptors,
487 uint32_t *count)
488 {
489 if (descriptors == NULL || count == NULL) {
490 return BAD_VALUE;
491 }
492 Parcel data, reply;
493 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
494 data.writeInt32(audioSession);
495 data.writeInt32(*count);
496 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
497 if (status != NO_ERROR) {
498 return status;
499 }
500 status = static_cast <status_t> (reply.readInt32());
501 uint32_t retCount = reply.readInt32();
502 if (retCount != 0) {
503 uint32_t numDesc = (retCount < *count) ? retCount : *count;
504 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
505 }
506 *count = retCount;
507 return status;
508 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000509
510 virtual bool isOffloadSupported(const audio_offload_info_t& info)
511 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100512 Parcel data, reply;
513 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
514 data.write(&info, sizeof(audio_offload_info_t));
515 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700516 return reply.readInt32();
517 }
518
519 virtual status_t listAudioPorts(audio_port_role_t role,
520 audio_port_type_t type,
521 unsigned int *num_ports,
522 struct audio_port *ports,
523 unsigned int *generation)
524 {
525 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
526 generation == NULL) {
527 return BAD_VALUE;
528 }
529 Parcel data, reply;
530 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
531 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
532 data.writeInt32(role);
533 data.writeInt32(type);
534 data.writeInt32(numPortsReq);
535 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
536 if (status == NO_ERROR) {
537 status = (status_t)reply.readInt32();
538 *num_ports = (unsigned int)reply.readInt32();
539 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700540 if (status == NO_ERROR) {
541 if (numPortsReq > *num_ports) {
542 numPortsReq = *num_ports;
543 }
544 if (numPortsReq > 0) {
545 reply.read(ports, numPortsReq * sizeof(struct audio_port));
546 }
547 *generation = reply.readInt32();
548 }
549 return status;
550 }
551
552 virtual status_t getAudioPort(struct audio_port *port)
553 {
554 if (port == NULL) {
555 return BAD_VALUE;
556 }
557 Parcel data, reply;
558 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
559 data.write(port, sizeof(struct audio_port));
560 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
561 if (status != NO_ERROR ||
562 (status = (status_t)reply.readInt32()) != NO_ERROR) {
563 return status;
564 }
565 reply.read(port, sizeof(struct audio_port));
566 return status;
567 }
568
569 virtual status_t createAudioPatch(const struct audio_patch *patch,
570 audio_patch_handle_t *handle)
571 {
572 if (patch == NULL || handle == NULL) {
573 return BAD_VALUE;
574 }
575 Parcel data, reply;
576 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
577 data.write(patch, sizeof(struct audio_patch));
578 data.write(handle, sizeof(audio_patch_handle_t));
579 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
580 if (status != NO_ERROR ||
581 (status = (status_t)reply.readInt32()) != NO_ERROR) {
582 return status;
583 }
584 reply.read(handle, sizeof(audio_patch_handle_t));
585 return status;
586 }
587
588 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
589 {
590 Parcel data, reply;
591 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
592 data.write(&handle, sizeof(audio_patch_handle_t));
593 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
594 if (status != NO_ERROR) {
595 status = (status_t)reply.readInt32();
596 }
597 return status;
598 }
599
600 virtual status_t listAudioPatches(unsigned int *num_patches,
601 struct audio_patch *patches,
602 unsigned int *generation)
603 {
604 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
605 generation == NULL) {
606 return BAD_VALUE;
607 }
608 Parcel data, reply;
609 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
610 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
611 data.writeInt32(numPatchesReq);
612 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
613 if (status == NO_ERROR) {
614 status = (status_t)reply.readInt32();
615 *num_patches = (unsigned int)reply.readInt32();
616 }
617 if (status == NO_ERROR) {
618 if (numPatchesReq > *num_patches) {
619 numPatchesReq = *num_patches;
620 }
621 if (numPatchesReq > 0) {
622 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
623 }
624 *generation = reply.readInt32();
625 }
626 return status;
627 }
628
629 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
630 {
631 if (config == NULL) {
632 return BAD_VALUE;
633 }
634 Parcel data, reply;
635 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
636 data.write(config, sizeof(struct audio_port_config));
637 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
638 if (status != NO_ERROR) {
639 status = (status_t)reply.readInt32();
640 }
641 return status;
642 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700643
Eric Laurentb52c1522014-05-20 11:27:36 -0700644 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
645 {
646 Parcel data, reply;
647 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800648 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700649 remote()->transact(REGISTER_CLIENT, data, &reply);
650 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700651
Eric Laurente8726fe2015-06-26 09:39:24 -0700652 virtual void setAudioPortCallbacksEnabled(bool enabled)
653 {
654 Parcel data, reply;
655 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
656 data.writeInt32(enabled ? 1 : 0);
657 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
658 }
659
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700660 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
661 audio_io_handle_t *ioHandle,
662 audio_devices_t *device)
663 {
664 if (session == NULL || ioHandle == NULL || device == NULL) {
665 return BAD_VALUE;
666 }
667 Parcel data, reply;
668 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
669 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
670 if (status != NO_ERROR) {
671 return status;
672 }
673 status = (status_t)reply.readInt32();
674 if (status == NO_ERROR) {
675 *session = (audio_session_t)reply.readInt32();
676 *ioHandle = (audio_io_handle_t)reply.readInt32();
677 *device = (audio_devices_t)reply.readInt32();
678 }
679 return status;
680 }
681
682 virtual status_t releaseSoundTriggerSession(audio_session_t session)
683 {
684 Parcel data, reply;
685 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
686 data.writeInt32(session);
687 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
688 if (status != NO_ERROR) {
689 return status;
690 }
691 return (status_t)reply.readInt32();
692 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700693
694 virtual audio_mode_t getPhoneState()
695 {
696 Parcel data, reply;
697 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
698 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
699 if (status != NO_ERROR) {
700 return AUDIO_MODE_INVALID;
701 }
702 return (audio_mode_t)reply.readInt32();
703 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800704
705 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
706 {
707 Parcel data, reply;
708 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
709 data.writeInt32(registration ? 1 : 0);
710 size_t size = mixes.size();
711 if (size > MAX_MIXES_PER_POLICY) {
712 size = MAX_MIXES_PER_POLICY;
713 }
714 size_t sizePosition = data.dataPosition();
715 data.writeInt32(size);
716 size_t finalSize = size;
717 for (size_t i = 0; i < size; i++) {
718 size_t position = data.dataPosition();
719 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
720 data.setDataPosition(position);
721 finalSize--;
722 }
723 }
724 if (size != finalSize) {
725 size_t position = data.dataPosition();
726 data.setDataPosition(sizePosition);
727 data.writeInt32(finalSize);
728 data.setDataPosition(position);
729 }
730 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
731 if (status == NO_ERROR) {
732 status = (status_t)reply.readInt32();
733 }
734 return status;
735 }
Eric Laurent554a2772015-04-10 11:29:24 -0700736
737 virtual status_t startAudioSource(const struct audio_port_config *source,
738 const audio_attributes_t *attributes,
739 audio_io_handle_t *handle)
740 {
741 Parcel data, reply;
742 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
743 if (source == NULL || attributes == NULL || handle == NULL) {
744 return BAD_VALUE;
745 }
746 data.write(source, sizeof(struct audio_port_config));
747 data.write(attributes, sizeof(audio_attributes_t));
748 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
749 if (status != NO_ERROR) {
750 return status;
751 }
752 status = (status_t)reply.readInt32();
753 if (status != NO_ERROR) {
754 return status;
755 }
756 *handle = (audio_io_handle_t)reply.readInt32();
757 return status;
758 }
759
760 virtual status_t stopAudioSource(audio_io_handle_t handle)
761 {
762 Parcel data, reply;
763 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
764 data.writeInt32(handle);
765 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
766 if (status != NO_ERROR) {
767 return status;
768 }
769 status = (status_t)reply.readInt32();
770 return status;
771 }
Andy Hung2ddee192015-12-18 17:34:44 -0800772
773 virtual status_t setMasterMono(bool mono)
774 {
775 Parcel data, reply;
776 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
777 data.writeInt32(static_cast<int32_t>(mono));
778 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
779 if (status != NO_ERROR) {
780 return status;
781 }
782 return static_cast<status_t>(reply.readInt32());
783 }
784
785 virtual status_t getMasterMono(bool *mono)
786 {
787 if (mono == nullptr) {
788 return BAD_VALUE;
789 }
790 Parcel data, reply;
791 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
792
793 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
794 if (status != NO_ERROR) {
795 return status;
796 }
797 status = static_cast<status_t>(reply.readInt32());
798 if (status == NO_ERROR) {
799 *mono = static_cast<bool>(reply.readInt32());
800 }
801 return status;
802 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700803};
804
805IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
806
807// ----------------------------------------------------------------------
808
809
810status_t BnAudioPolicyService::onTransact(
811 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
812{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700813 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700814 case SET_DEVICE_CONNECTION_STATE: {
815 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700816 audio_devices_t device =
817 static_cast <audio_devices_t>(data.readInt32());
818 audio_policy_dev_state_t state =
819 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700820 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800821 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700822 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
823 state,
Paul McLeane743a472015-01-28 11:07:31 -0800824 device_address,
825 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700826 return NO_ERROR;
827 } break;
828
829 case GET_DEVICE_CONNECTION_STATE: {
830 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700831 audio_devices_t device =
832 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700833 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700834 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
835 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700836 return NO_ERROR;
837 } break;
838
839 case SET_PHONE_STATE: {
840 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700841 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
842 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700843 return NO_ERROR;
844 } break;
845
Eric Laurentc2f1f072009-07-17 12:17:14 -0700846 case SET_FORCE_USE: {
847 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700848 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
849 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700850 audio_policy_forced_cfg_t config =
851 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700852 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
853 return NO_ERROR;
854 } break;
855
856 case GET_FORCE_USE: {
857 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700858 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
859 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700860 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
861 return NO_ERROR;
862 } break;
863
864 case GET_OUTPUT: {
865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700866 audio_stream_type_t stream =
867 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700868 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800869 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700870 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700871 audio_output_flags_t flags =
872 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100873 bool hasOffloadInfo = data.readInt32() != 0;
874 audio_offload_info_t offloadInfo;
875 if (hasOffloadInfo) {
876 data.read(&offloadInfo, sizeof(audio_offload_info_t));
877 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700878 audio_io_handle_t output = getOutput(stream,
879 samplingRate,
880 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700881 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100882 flags,
883 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700884 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700885 return NO_ERROR;
886 } break;
887
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700888 case GET_OUTPUT_FOR_ATTR: {
889 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800890 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800891 bool hasAttributes = data.readInt32() != 0;
892 if (hasAttributes) {
893 data.read(&attr, sizeof(audio_attributes_t));
894 }
895 audio_session_t session = (audio_session_t)data.readInt32();
896 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
897 bool hasStream = data.readInt32() != 0;
898 if (hasStream) {
899 stream = (audio_stream_type_t)data.readInt32();
900 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700901 uid_t uid = (uid_t)data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700902 uint32_t samplingRate = data.readInt32();
903 audio_format_t format = (audio_format_t) data.readInt32();
904 audio_channel_mask_t channelMask = data.readInt32();
905 audio_output_flags_t flags =
906 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700907 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700908 bool hasOffloadInfo = data.readInt32() != 0;
909 audio_offload_info_t offloadInfo;
910 if (hasOffloadInfo) {
911 data.read(&offloadInfo, sizeof(audio_offload_info_t));
912 }
Robert Shiha946d842015-09-02 16:46:59 -0700913 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800914 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700915 &output, session, &stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800916 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700917 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800918 reply->writeInt32(status);
919 reply->writeInt32(output);
920 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700921 return NO_ERROR;
922 } break;
923
Eric Laurentc2f1f072009-07-17 12:17:14 -0700924 case START_OUTPUT: {
925 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700926 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800927 audio_stream_type_t stream =
928 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800929 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700930 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800931 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700932 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700933 return NO_ERROR;
934 } break;
935
936 case STOP_OUTPUT: {
937 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700938 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800939 audio_stream_type_t stream =
940 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800941 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700942 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800943 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700944 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700945 return NO_ERROR;
946 } break;
947
948 case RELEASE_OUTPUT: {
949 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700950 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800951 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
952 audio_session_t session = (audio_session_t)data.readInt32();
953 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700954 return NO_ERROR;
955 } break;
956
Eric Laurentcaf7f482014-11-25 17:50:47 -0800957 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700958 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800959 audio_attributes_t attr;
960 data.read(&attr, sizeof(audio_attributes_t));
961 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700962 uid_t uid = (uid_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700963 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800964 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700965 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700966 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600967 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -0700968 audio_io_handle_t input = {};
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700969 status_t status = getInputForAttr(&attr, &input, session, uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800970 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600971 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800972 reply->writeInt32(status);
973 if (status == NO_ERROR) {
974 reply->writeInt32(input);
975 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700976 return NO_ERROR;
977 } break;
978
979 case START_INPUT: {
980 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700981 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700982 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
983 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700984 return NO_ERROR;
985 } break;
986
987 case STOP_INPUT: {
988 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700989 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700990 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
991 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700992 return NO_ERROR;
993 } break;
994
995 case RELEASE_INPUT: {
996 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700997 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700998 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
999 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001000 return NO_ERROR;
1001 } break;
1002
1003 case INIT_STREAM_VOLUME: {
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());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001007 int indexMin = data.readInt32();
1008 int indexMax = data.readInt32();
1009 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1010 return NO_ERROR;
1011 } break;
1012
1013 case SET_STREAM_VOLUME: {
1014 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001015 audio_stream_type_t stream =
1016 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001017 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001018 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1019 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1020 index,
1021 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001022 return NO_ERROR;
1023 } break;
1024
1025 case GET_STREAM_VOLUME: {
1026 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001027 audio_stream_type_t stream =
1028 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001029 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001030 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001031 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001032 reply->writeInt32(index);
1033 reply->writeInt32(static_cast <uint32_t>(status));
1034 return NO_ERROR;
1035 } break;
1036
Eric Laurentde070132010-07-13 04:45:46 -07001037 case GET_STRATEGY_FOR_STREAM: {
1038 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001039 audio_stream_type_t stream =
1040 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001041 reply->writeInt32(getStrategyForStream(stream));
1042 return NO_ERROR;
1043 } break;
1044
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001045 case GET_DEVICES_FOR_STREAM: {
1046 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001047 audio_stream_type_t stream =
1048 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001049 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1050 return NO_ERROR;
1051 } break;
1052
Eric Laurentde070132010-07-13 04:45:46 -07001053 case GET_OUTPUT_FOR_EFFECT: {
1054 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1055 effect_descriptor_t desc;
1056 data.read(&desc, sizeof(effect_descriptor_t));
1057 audio_io_handle_t output = getOutputForEffect(&desc);
1058 reply->writeInt32(static_cast <int>(output));
1059 return NO_ERROR;
1060 } break;
1061
1062 case REGISTER_EFFECT: {
1063 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1064 effect_descriptor_t desc;
1065 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001066 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001067 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001068 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001069 int id = data.readInt32();
1070 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001071 io,
Eric Laurentde070132010-07-13 04:45:46 -07001072 strategy,
1073 session,
1074 id)));
1075 return NO_ERROR;
1076 } break;
1077
1078 case UNREGISTER_EFFECT: {
1079 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1080 int id = data.readInt32();
1081 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1082 return NO_ERROR;
1083 } break;
1084
Eric Laurentdb7c0792011-08-10 10:37:50 -07001085 case SET_EFFECT_ENABLED: {
1086 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1087 int id = data.readInt32();
1088 bool enabled = static_cast <bool>(data.readInt32());
1089 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1090 return NO_ERROR;
1091 } break;
1092
Eric Laurenteda6c362011-02-02 09:33:30 -08001093 case IS_STREAM_ACTIVE: {
1094 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001095 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001096 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001097 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001098 return NO_ERROR;
1099 } break;
1100
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001101 case IS_STREAM_ACTIVE_REMOTELY: {
1102 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1103 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1104 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001105 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001106 return NO_ERROR;
1107 } break;
1108
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001109 case IS_SOURCE_ACTIVE: {
1110 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1111 audio_source_t source = (audio_source_t) data.readInt32();
1112 reply->writeInt32( isSourceActive(source));
1113 return NO_ERROR;
1114 }
1115
Eric Laurent57dae992011-07-24 13:36:09 -07001116 case QUERY_DEFAULT_PRE_PROCESSING: {
1117 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001118 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001119 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001120 if (count > AudioEffect::kMaxPreProcessing) {
1121 count = AudioEffect::kMaxPreProcessing;
1122 }
Eric Laurent57dae992011-07-24 13:36:09 -07001123 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001124 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001125 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1126 reply->writeInt32(status);
1127 if (status != NO_ERROR && status != NO_MEMORY) {
1128 retCount = 0;
1129 }
1130 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001131 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001132 if (retCount < count) {
1133 count = retCount;
1134 }
1135 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1136 }
1137 delete[] descriptors;
1138 return status;
1139 }
1140
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001141 case IS_OFFLOAD_SUPPORTED: {
1142 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1143 audio_offload_info_t info;
1144 data.read(&info, sizeof(audio_offload_info_t));
1145 bool isSupported = isOffloadSupported(info);
1146 reply->writeInt32(isSupported);
1147 return NO_ERROR;
1148 }
1149
Eric Laurent203b1a12014-04-01 10:34:16 -07001150 case LIST_AUDIO_PORTS: {
1151 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1152 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1153 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1154 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001155 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1156 numPortsReq = MAX_ITEMS_PER_LIST;
1157 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001158 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001159 struct audio_port *ports =
1160 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001161 if (ports == NULL) {
1162 reply->writeInt32(NO_MEMORY);
1163 reply->writeInt32(0);
1164 return NO_ERROR;
1165 }
1166 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001167 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1168 reply->writeInt32(status);
1169 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001170
1171 if (status == NO_ERROR) {
1172 if (numPortsReq > numPorts) {
1173 numPortsReq = numPorts;
1174 }
1175 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1176 reply->writeInt32(generation);
1177 }
1178 free(ports);
1179 return NO_ERROR;
1180 }
1181
1182 case GET_AUDIO_PORT: {
1183 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001184 struct audio_port port = {};
1185 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1186 ALOGE("b/23912202");
1187 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001188 status_t status = getAudioPort(&port);
1189 reply->writeInt32(status);
1190 if (status == NO_ERROR) {
1191 reply->write(&port, sizeof(struct audio_port));
1192 }
1193 return NO_ERROR;
1194 }
1195
1196 case CREATE_AUDIO_PATCH: {
1197 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1198 struct audio_patch patch;
1199 data.read(&patch, sizeof(struct audio_patch));
Wei Jiae995e472015-09-09 09:48:34 -07001200 audio_patch_handle_t handle = {};
1201 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1202 ALOGE("b/23912202");
1203 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001204 status_t status = createAudioPatch(&patch, &handle);
1205 reply->writeInt32(status);
1206 if (status == NO_ERROR) {
1207 reply->write(&handle, sizeof(audio_patch_handle_t));
1208 }
1209 return NO_ERROR;
1210 }
1211
1212 case RELEASE_AUDIO_PATCH: {
1213 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1214 audio_patch_handle_t handle;
1215 data.read(&handle, sizeof(audio_patch_handle_t));
1216 status_t status = releaseAudioPatch(handle);
1217 reply->writeInt32(status);
1218 return NO_ERROR;
1219 }
1220
1221 case LIST_AUDIO_PATCHES: {
1222 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1223 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001224 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1225 numPatchesReq = MAX_ITEMS_PER_LIST;
1226 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001227 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001228 struct audio_patch *patches =
1229 (struct audio_patch *)calloc(numPatchesReq,
1230 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001231 if (patches == NULL) {
1232 reply->writeInt32(NO_MEMORY);
1233 reply->writeInt32(0);
1234 return NO_ERROR;
1235 }
1236 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001237 status_t status = listAudioPatches(&numPatches, patches, &generation);
1238 reply->writeInt32(status);
1239 reply->writeInt32(numPatches);
1240 if (status == NO_ERROR) {
1241 if (numPatchesReq > numPatches) {
1242 numPatchesReq = numPatches;
1243 }
1244 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1245 reply->writeInt32(generation);
1246 }
1247 free(patches);
1248 return NO_ERROR;
1249 }
1250
1251 case SET_AUDIO_PORT_CONFIG: {
1252 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1253 struct audio_port_config config;
1254 data.read(&config, sizeof(struct audio_port_config));
1255 status_t status = setAudioPortConfig(&config);
1256 reply->writeInt32(status);
1257 return NO_ERROR;
1258 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001259
Eric Laurentb52c1522014-05-20 11:27:36 -07001260 case REGISTER_CLIENT: {
1261 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1262 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1263 data.readStrongBinder());
1264 registerClient(client);
1265 return NO_ERROR;
1266 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001267
Eric Laurente8726fe2015-06-26 09:39:24 -07001268 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1269 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1270 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1271 return NO_ERROR;
1272 } break;
1273
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001274 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1275 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1276 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1277 data.readStrongBinder());
Wei Jia983dca32015-09-10 09:47:29 -07001278 audio_session_t session = {};
1279 audio_io_handle_t ioHandle = {};
1280 audio_devices_t device = {};
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001281 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1282 reply->writeInt32(status);
1283 if (status == NO_ERROR) {
1284 reply->writeInt32(session);
1285 reply->writeInt32(ioHandle);
1286 reply->writeInt32(device);
1287 }
1288 return NO_ERROR;
1289 } break;
1290
1291 case RELEASE_SOUNDTRIGGER_SESSION: {
1292 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1293 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1294 data.readStrongBinder());
1295 audio_session_t session = (audio_session_t)data.readInt32();
1296 status_t status = releaseSoundTriggerSession(session);
1297 reply->writeInt32(status);
1298 return NO_ERROR;
1299 } break;
1300
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001301 case GET_PHONE_STATE: {
1302 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1303 reply->writeInt32((int32_t)getPhoneState());
1304 return NO_ERROR;
1305 } break;
1306
Eric Laurentbaac1832014-12-01 17:52:59 -08001307 case REGISTER_POLICY_MIXES: {
1308 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1309 bool registration = data.readInt32() == 1;
1310 Vector<AudioMix> mixes;
1311 size_t size = (size_t)data.readInt32();
1312 if (size > MAX_MIXES_PER_POLICY) {
1313 size = MAX_MIXES_PER_POLICY;
1314 }
1315 for (size_t i = 0; i < size; i++) {
1316 AudioMix mix;
1317 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1318 mixes.add(mix);
1319 }
1320 }
1321 status_t status = registerPolicyMixes(mixes, registration);
1322 reply->writeInt32(status);
1323 return NO_ERROR;
1324 } break;
1325
Eric Laurent554a2772015-04-10 11:29:24 -07001326 case START_AUDIO_SOURCE: {
1327 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1328 struct audio_port_config source;
1329 data.read(&source, sizeof(struct audio_port_config));
1330 audio_attributes_t attributes;
1331 data.read(&attributes, sizeof(audio_attributes_t));
Wei Jiae995e472015-09-09 09:48:34 -07001332 audio_io_handle_t handle = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001333 status_t status = startAudioSource(&source, &attributes, &handle);
1334 reply->writeInt32(status);
1335 reply->writeInt32(handle);
1336 return NO_ERROR;
1337 } break;
1338
1339 case STOP_AUDIO_SOURCE: {
1340 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1341 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1342 status_t status = stopAudioSource(handle);
1343 reply->writeInt32(status);
1344 return NO_ERROR;
1345 } break;
1346
Andy Hung2ddee192015-12-18 17:34:44 -08001347 case SET_MASTER_MONO: {
1348 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1349 bool mono = static_cast<bool>(data.readInt32());
1350 status_t status = setMasterMono(mono);
1351 reply->writeInt32(status);
1352 return NO_ERROR;
1353 } break;
1354
1355 case GET_MASTER_MONO: {
1356 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1357 bool mono;
1358 status_t status = getMasterMono(&mono);
1359 reply->writeInt32(status);
1360 if (status == NO_ERROR) {
1361 reply->writeInt32(static_cast<int32_t>(mono));
1362 }
1363 return NO_ERROR;
1364 } break;
1365
Eric Laurentc2f1f072009-07-17 12:17:14 -07001366 default:
1367 return BBinder::onTransact(code, data, reply, flags);
1368 }
1369}
1370
1371// ----------------------------------------------------------------------------
1372
Glenn Kasten40bc9062015-03-20 09:09:33 -07001373} // namespace android