blob: bc5502e6c1ebf463c80f7122216fcbc14a42cc4e [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:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070086 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -070087 : 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 Laurent20b9ef02016-12-05 11:03:16 -0800178 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800179 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700180 audio_port_handle_t selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800181 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700182 {
183 Parcel data, reply;
184 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
185 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800186 if (stream == NULL) {
187 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
188 return BAD_VALUE;
189 }
190 if (*stream == AUDIO_STREAM_DEFAULT) {
191 ALOGE("getOutputForAttr unspecified stream type");
192 return BAD_VALUE;
193 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700194 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800195 if (output == NULL) {
196 ALOGE("getOutputForAttr NULL output - shouldn't happen");
197 return BAD_VALUE;
198 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800199 if (portId == NULL) {
200 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
201 return BAD_VALUE;
202 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800203 if (attr == NULL) {
204 data.writeInt32(0);
205 } else {
206 data.writeInt32(1);
207 data.write(attr, sizeof(audio_attributes_t));
208 }
209 data.writeInt32(session);
210 if (stream == NULL) {
211 data.writeInt32(0);
212 } else {
213 data.writeInt32(1);
214 data.writeInt32(*stream);
215 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700216 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800217 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700218 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700219 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800220 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800221 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
222 if (status != NO_ERROR) {
223 return status;
224 }
225 status = (status_t)reply.readInt32();
226 if (status != NO_ERROR) {
227 return status;
228 }
229 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800230 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800231 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800232 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800233 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800234 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800235 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700236 }
237
Eric Laurentde070132010-07-13 04:45:46 -0700238 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700239 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800240 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700241 {
242 Parcel data, reply;
243 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700244 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800245 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800246 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700247 remote()->transact(START_OUTPUT, data, &reply);
248 return static_cast <status_t> (reply.readInt32());
249 }
250
Eric Laurentde070132010-07-13 04:45:46 -0700251 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700252 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800253 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700257 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800258 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800259 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700260 remote()->transact(STOP_OUTPUT, data, &reply);
261 return static_cast <status_t> (reply.readInt32());
262 }
263
Eric Laurente83b55d2014-11-14 10:06:21 -0800264 virtual void releaseOutput(audio_io_handle_t output,
265 audio_stream_type_t stream,
266 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 {
268 Parcel data, reply;
269 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700270 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800271 data.writeInt32((int32_t)stream);
272 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 remote()->transact(RELEASE_OUTPUT, data, &reply);
274 }
275
Eric Laurentcaf7f482014-11-25 17:50:47 -0800276 virtual status_t getInputForAttr(const audio_attributes_t *attr,
277 audio_io_handle_t *input,
278 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700279 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700280 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800281 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600282 audio_input_flags_t flags,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800283 audio_port_handle_t selectedDeviceId,
284 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800288 if (attr == NULL) {
289 ALOGE("getInputForAttr NULL attr - shouldn't happen");
290 return BAD_VALUE;
291 }
292 if (input == NULL) {
293 ALOGE("getInputForAttr NULL input - shouldn't happen");
294 return BAD_VALUE;
295 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800296 if (portId == NULL) {
297 ALOGE("getInputForAttr NULL portId - shouldn't happen");
298 return BAD_VALUE;
299 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800300 data.write(attr, sizeof(audio_attributes_t));
301 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700302 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700303 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800304 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700305 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600306 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800307 data.writeInt32(*portId);
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();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800317 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800318 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700319 }
320
Eric Laurent4dc68062014-07-28 17:26:49 -0700321 virtual status_t startInput(audio_io_handle_t input,
322 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700323 {
324 Parcel data, reply;
325 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700326 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700327 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700328 remote()->transact(START_INPUT, data, &reply);
329 return static_cast <status_t> (reply.readInt32());
330 }
331
Eric Laurent4dc68062014-07-28 17:26:49 -0700332 virtual status_t stopInput(audio_io_handle_t input,
333 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700337 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700338 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 remote()->transact(STOP_INPUT, data, &reply);
340 return static_cast <status_t> (reply.readInt32());
341 }
342
Eric Laurent4dc68062014-07-28 17:26:49 -0700343 virtual void releaseInput(audio_io_handle_t input,
344 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700345 {
346 Parcel data, reply;
347 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700348 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700349 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 remote()->transact(RELEASE_INPUT, data, &reply);
351 }
352
Dima Zavinfce7a472011-04-19 22:30:36 -0700353 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354 int indexMin,
355 int indexMax)
356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
359 data.writeInt32(static_cast <uint32_t>(stream));
360 data.writeInt32(indexMin);
361 data.writeInt32(indexMax);
362 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
363 return static_cast <status_t> (reply.readInt32());
364 }
365
Eric Laurent83844cc2011-11-18 16:43:31 -0800366 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
367 int index,
368 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 {
370 Parcel data, reply;
371 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
372 data.writeInt32(static_cast <uint32_t>(stream));
373 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800374 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700375 remote()->transact(SET_STREAM_VOLUME, data, &reply);
376 return static_cast <status_t> (reply.readInt32());
377 }
378
Eric Laurent83844cc2011-11-18 16:43:31 -0800379 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
380 int *index,
381 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
385 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800386 data.writeInt32(static_cast <uint32_t>(device));
387
Eric Laurentc2f1f072009-07-17 12:17:14 -0700388 remote()->transact(GET_STREAM_VOLUME, data, &reply);
389 int lIndex = reply.readInt32();
390 if (index) *index = lIndex;
391 return static_cast <status_t> (reply.readInt32());
392 }
Eric Laurentde070132010-07-13 04:45:46 -0700393
Dima Zavinfce7a472011-04-19 22:30:36 -0700394 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700395 {
396 Parcel data, reply;
397 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
398 data.writeInt32(static_cast <uint32_t>(stream));
399 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
400 return reply.readInt32();
401 }
402
Eric Laurent63742522012-03-08 13:42:42 -0800403 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800404 {
405 Parcel data, reply;
406 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
407 data.writeInt32(static_cast <uint32_t>(stream));
408 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800409 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800410 }
411
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700412 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
416 data.write(desc, sizeof(effect_descriptor_t));
417 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
418 return static_cast <audio_io_handle_t> (reply.readInt32());
419 }
420
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700421 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700422 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700423 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800424 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700425 int id)
426 {
427 Parcel data, reply;
428 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
429 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700430 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700431 data.writeInt32(strategy);
432 data.writeInt32(session);
433 data.writeInt32(id);
434 remote()->transact(REGISTER_EFFECT, data, &reply);
435 return static_cast <status_t> (reply.readInt32());
436 }
437
438 virtual status_t unregisterEffect(int id)
439 {
440 Parcel data, reply;
441 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
442 data.writeInt32(id);
443 remote()->transact(UNREGISTER_EFFECT, data, &reply);
444 return static_cast <status_t> (reply.readInt32());
445 }
446
Eric Laurentdb7c0792011-08-10 10:37:50 -0700447 virtual status_t setEffectEnabled(int id, bool enabled)
448 {
449 Parcel data, reply;
450 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
451 data.writeInt32(id);
452 data.writeInt32(enabled);
453 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
454 return static_cast <status_t> (reply.readInt32());
455 }
456
Glenn Kastenfff6d712012-01-12 16:38:12 -0800457 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800458 {
459 Parcel data, reply;
460 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800461 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800462 data.writeInt32(inPastMs);
463 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
464 return reply.readInt32();
465 }
Eric Laurent57dae992011-07-24 13:36:09 -0700466
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800467 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
471 data.writeInt32((int32_t) stream);
472 data.writeInt32(inPastMs);
473 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
474 return reply.readInt32();
475 }
476
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700477 virtual bool isSourceActive(audio_source_t source) const
478 {
479 Parcel data, reply;
480 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
481 data.writeInt32((int32_t) source);
482 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
483 return reply.readInt32();
484 }
485
Glenn Kastend848eb42016-03-08 13:42:11 -0800486 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700487 effect_descriptor_t *descriptors,
488 uint32_t *count)
489 {
490 if (descriptors == NULL || count == NULL) {
491 return BAD_VALUE;
492 }
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
495 data.writeInt32(audioSession);
496 data.writeInt32(*count);
497 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
498 if (status != NO_ERROR) {
499 return status;
500 }
501 status = static_cast <status_t> (reply.readInt32());
502 uint32_t retCount = reply.readInt32();
503 if (retCount != 0) {
504 uint32_t numDesc = (retCount < *count) ? retCount : *count;
505 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
506 }
507 *count = retCount;
508 return status;
509 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000510
511 virtual bool isOffloadSupported(const audio_offload_info_t& info)
512 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100513 Parcel data, reply;
514 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
515 data.write(&info, sizeof(audio_offload_info_t));
516 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700517 return reply.readInt32();
518 }
519
520 virtual status_t listAudioPorts(audio_port_role_t role,
521 audio_port_type_t type,
522 unsigned int *num_ports,
523 struct audio_port *ports,
524 unsigned int *generation)
525 {
526 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
527 generation == NULL) {
528 return BAD_VALUE;
529 }
530 Parcel data, reply;
531 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
532 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
533 data.writeInt32(role);
534 data.writeInt32(type);
535 data.writeInt32(numPortsReq);
536 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
537 if (status == NO_ERROR) {
538 status = (status_t)reply.readInt32();
539 *num_ports = (unsigned int)reply.readInt32();
540 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700541 if (status == NO_ERROR) {
542 if (numPortsReq > *num_ports) {
543 numPortsReq = *num_ports;
544 }
545 if (numPortsReq > 0) {
546 reply.read(ports, numPortsReq * sizeof(struct audio_port));
547 }
548 *generation = reply.readInt32();
549 }
550 return status;
551 }
552
553 virtual status_t getAudioPort(struct audio_port *port)
554 {
555 if (port == NULL) {
556 return BAD_VALUE;
557 }
558 Parcel data, reply;
559 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
560 data.write(port, sizeof(struct audio_port));
561 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
562 if (status != NO_ERROR ||
563 (status = (status_t)reply.readInt32()) != NO_ERROR) {
564 return status;
565 }
566 reply.read(port, sizeof(struct audio_port));
567 return status;
568 }
569
570 virtual status_t createAudioPatch(const struct audio_patch *patch,
571 audio_patch_handle_t *handle)
572 {
573 if (patch == NULL || handle == NULL) {
574 return BAD_VALUE;
575 }
576 Parcel data, reply;
577 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
578 data.write(patch, sizeof(struct audio_patch));
579 data.write(handle, sizeof(audio_patch_handle_t));
580 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
581 if (status != NO_ERROR ||
582 (status = (status_t)reply.readInt32()) != NO_ERROR) {
583 return status;
584 }
585 reply.read(handle, sizeof(audio_patch_handle_t));
586 return status;
587 }
588
589 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
590 {
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
593 data.write(&handle, sizeof(audio_patch_handle_t));
594 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
595 if (status != NO_ERROR) {
596 status = (status_t)reply.readInt32();
597 }
598 return status;
599 }
600
601 virtual status_t listAudioPatches(unsigned int *num_patches,
602 struct audio_patch *patches,
603 unsigned int *generation)
604 {
605 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
606 generation == NULL) {
607 return BAD_VALUE;
608 }
609 Parcel data, reply;
610 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
611 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
612 data.writeInt32(numPatchesReq);
613 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
614 if (status == NO_ERROR) {
615 status = (status_t)reply.readInt32();
616 *num_patches = (unsigned int)reply.readInt32();
617 }
618 if (status == NO_ERROR) {
619 if (numPatchesReq > *num_patches) {
620 numPatchesReq = *num_patches;
621 }
622 if (numPatchesReq > 0) {
623 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
624 }
625 *generation = reply.readInt32();
626 }
627 return status;
628 }
629
630 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
631 {
632 if (config == NULL) {
633 return BAD_VALUE;
634 }
635 Parcel data, reply;
636 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
637 data.write(config, sizeof(struct audio_port_config));
638 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
639 if (status != NO_ERROR) {
640 status = (status_t)reply.readInt32();
641 }
642 return status;
643 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700644
Eric Laurentb52c1522014-05-20 11:27:36 -0700645 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
646 {
647 Parcel data, reply;
648 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800649 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700650 remote()->transact(REGISTER_CLIENT, data, &reply);
651 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700652
Eric Laurente8726fe2015-06-26 09:39:24 -0700653 virtual void setAudioPortCallbacksEnabled(bool enabled)
654 {
655 Parcel data, reply;
656 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
657 data.writeInt32(enabled ? 1 : 0);
658 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
659 }
660
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700661 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
662 audio_io_handle_t *ioHandle,
663 audio_devices_t *device)
664 {
665 if (session == NULL || ioHandle == NULL || device == NULL) {
666 return BAD_VALUE;
667 }
668 Parcel data, reply;
669 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
670 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
671 if (status != NO_ERROR) {
672 return status;
673 }
674 status = (status_t)reply.readInt32();
675 if (status == NO_ERROR) {
676 *session = (audio_session_t)reply.readInt32();
677 *ioHandle = (audio_io_handle_t)reply.readInt32();
678 *device = (audio_devices_t)reply.readInt32();
679 }
680 return status;
681 }
682
683 virtual status_t releaseSoundTriggerSession(audio_session_t session)
684 {
685 Parcel data, reply;
686 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
687 data.writeInt32(session);
688 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
689 if (status != NO_ERROR) {
690 return status;
691 }
692 return (status_t)reply.readInt32();
693 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700694
695 virtual audio_mode_t getPhoneState()
696 {
697 Parcel data, reply;
698 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
699 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
700 if (status != NO_ERROR) {
701 return AUDIO_MODE_INVALID;
702 }
703 return (audio_mode_t)reply.readInt32();
704 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800705
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700706 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800707 {
708 Parcel data, reply;
709 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
710 data.writeInt32(registration ? 1 : 0);
711 size_t size = mixes.size();
712 if (size > MAX_MIXES_PER_POLICY) {
713 size = MAX_MIXES_PER_POLICY;
714 }
715 size_t sizePosition = data.dataPosition();
716 data.writeInt32(size);
717 size_t finalSize = size;
718 for (size_t i = 0; i < size; i++) {
719 size_t position = data.dataPosition();
720 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
721 data.setDataPosition(position);
722 finalSize--;
723 }
724 }
725 if (size != finalSize) {
726 size_t position = data.dataPosition();
727 data.setDataPosition(sizePosition);
728 data.writeInt32(finalSize);
729 data.setDataPosition(position);
730 }
731 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
732 if (status == NO_ERROR) {
733 status = (status_t)reply.readInt32();
734 }
735 return status;
736 }
Eric Laurent554a2772015-04-10 11:29:24 -0700737
738 virtual status_t startAudioSource(const struct audio_port_config *source,
739 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700740 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700741 {
742 Parcel data, reply;
743 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
744 if (source == NULL || attributes == NULL || handle == NULL) {
745 return BAD_VALUE;
746 }
747 data.write(source, sizeof(struct audio_port_config));
748 data.write(attributes, sizeof(audio_attributes_t));
749 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
750 if (status != NO_ERROR) {
751 return status;
752 }
753 status = (status_t)reply.readInt32();
754 if (status != NO_ERROR) {
755 return status;
756 }
Glenn Kasten559d4392016-03-29 13:42:57 -0700757 *handle = (audio_patch_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700758 return status;
759 }
760
Glenn Kasten559d4392016-03-29 13:42:57 -0700761 virtual status_t stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700762 {
763 Parcel data, reply;
764 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
765 data.writeInt32(handle);
766 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
767 if (status != NO_ERROR) {
768 return status;
769 }
770 status = (status_t)reply.readInt32();
771 return status;
772 }
Andy Hung2ddee192015-12-18 17:34:44 -0800773
774 virtual status_t setMasterMono(bool mono)
775 {
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
778 data.writeInt32(static_cast<int32_t>(mono));
779 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
780 if (status != NO_ERROR) {
781 return status;
782 }
783 return static_cast<status_t>(reply.readInt32());
784 }
785
786 virtual status_t getMasterMono(bool *mono)
787 {
788 if (mono == nullptr) {
789 return BAD_VALUE;
790 }
791 Parcel data, reply;
792 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
793
794 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
795 if (status != NO_ERROR) {
796 return status;
797 }
798 status = static_cast<status_t>(reply.readInt32());
799 if (status == NO_ERROR) {
800 *mono = static_cast<bool>(reply.readInt32());
801 }
802 return status;
803 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700804};
805
806IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
807
808// ----------------------------------------------------------------------
809
810
811status_t BnAudioPolicyService::onTransact(
812 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
813{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700814 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700815 case SET_DEVICE_CONNECTION_STATE: {
816 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700817 audio_devices_t device =
818 static_cast <audio_devices_t>(data.readInt32());
819 audio_policy_dev_state_t state =
820 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700821 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800822 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700823 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
824 state,
Paul McLeane743a472015-01-28 11:07:31 -0800825 device_address,
826 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700827 return NO_ERROR;
828 } break;
829
830 case GET_DEVICE_CONNECTION_STATE: {
831 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700832 audio_devices_t device =
833 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700835 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
836 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700837 return NO_ERROR;
838 } break;
839
840 case SET_PHONE_STATE: {
841 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700842 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
843 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700844 return NO_ERROR;
845 } break;
846
Eric Laurentc2f1f072009-07-17 12:17:14 -0700847 case SET_FORCE_USE: {
848 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700849 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
850 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700851 audio_policy_forced_cfg_t config =
852 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700853 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
854 return NO_ERROR;
855 } break;
856
857 case GET_FORCE_USE: {
858 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700859 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
860 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700861 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
862 return NO_ERROR;
863 } break;
864
865 case GET_OUTPUT: {
866 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700867 audio_stream_type_t stream =
868 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700869 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800870 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700871 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700872 audio_output_flags_t flags =
873 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100874 bool hasOffloadInfo = data.readInt32() != 0;
875 audio_offload_info_t offloadInfo;
876 if (hasOffloadInfo) {
877 data.read(&offloadInfo, sizeof(audio_offload_info_t));
878 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700879 audio_io_handle_t output = getOutput(stream,
880 samplingRate,
881 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700882 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100883 flags,
884 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700885 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700886 return NO_ERROR;
887 } break;
888
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700889 case GET_OUTPUT_FOR_ATTR: {
890 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800891 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800892 bool hasAttributes = data.readInt32() != 0;
893 if (hasAttributes) {
894 data.read(&attr, sizeof(audio_attributes_t));
895 }
896 audio_session_t session = (audio_session_t)data.readInt32();
897 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
898 bool hasStream = data.readInt32() != 0;
899 if (hasStream) {
900 stream = (audio_stream_type_t)data.readInt32();
901 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700902 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800903 audio_config_t config;
904 memset(&config, 0, sizeof(audio_config_t));
905 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700906 audio_output_flags_t flags =
907 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700908 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800909 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -0700910 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800911 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700912 &output, session, &stream, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800913 &config,
914 flags, selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800915 reply->writeInt32(status);
916 reply->writeInt32(output);
917 reply->writeInt32(stream);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800918 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700919 return NO_ERROR;
920 } break;
921
Eric Laurentc2f1f072009-07-17 12:17:14 -0700922 case START_OUTPUT: {
923 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700924 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800925 audio_stream_type_t stream =
926 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800927 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700928 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800929 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700930 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700931 return NO_ERROR;
932 } break;
933
934 case STOP_OUTPUT: {
935 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700936 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800937 audio_stream_type_t stream =
938 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800939 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700940 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800941 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700942 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700943 return NO_ERROR;
944 } break;
945
946 case RELEASE_OUTPUT: {
947 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700948 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800949 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
950 audio_session_t session = (audio_session_t)data.readInt32();
951 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700952 return NO_ERROR;
953 } break;
954
Eric Laurentcaf7f482014-11-25 17:50:47 -0800955 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700956 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800957 audio_attributes_t attr;
958 data.read(&attr, sizeof(audio_attributes_t));
959 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700960 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700961 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800962 audio_config_base_t config;
963 memset(&config, 0, sizeof(audio_config_base_t));
964 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700965 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600966 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800967 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -0700968 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700969 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800970 &config,
971 flags, selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800972 reply->writeInt32(status);
973 if (status == NO_ERROR) {
974 reply->writeInt32(input);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800975 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800976 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700977 return NO_ERROR;
978 } break;
979
980 case START_INPUT: {
981 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700982 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700983 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
984 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700985 return NO_ERROR;
986 } break;
987
988 case STOP_INPUT: {
989 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700990 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700991 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
992 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700993 return NO_ERROR;
994 } break;
995
996 case RELEASE_INPUT: {
997 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700998 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700999 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1000 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001001 return NO_ERROR;
1002 } break;
1003
1004 case INIT_STREAM_VOLUME: {
1005 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001006 audio_stream_type_t stream =
1007 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001008 int indexMin = data.readInt32();
1009 int indexMax = data.readInt32();
1010 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1011 return NO_ERROR;
1012 } break;
1013
1014 case SET_STREAM_VOLUME: {
1015 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001016 audio_stream_type_t stream =
1017 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001018 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001019 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1020 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1021 index,
1022 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001023 return NO_ERROR;
1024 } break;
1025
1026 case GET_STREAM_VOLUME: {
1027 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001028 audio_stream_type_t stream =
1029 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001030 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001031 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001032 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001033 reply->writeInt32(index);
1034 reply->writeInt32(static_cast <uint32_t>(status));
1035 return NO_ERROR;
1036 } break;
1037
Eric Laurentde070132010-07-13 04:45:46 -07001038 case GET_STRATEGY_FOR_STREAM: {
1039 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001040 audio_stream_type_t stream =
1041 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001042 reply->writeInt32(getStrategyForStream(stream));
1043 return NO_ERROR;
1044 } break;
1045
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001046 case GET_DEVICES_FOR_STREAM: {
1047 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001048 audio_stream_type_t stream =
1049 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001050 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1051 return NO_ERROR;
1052 } break;
1053
Eric Laurentde070132010-07-13 04:45:46 -07001054 case GET_OUTPUT_FOR_EFFECT: {
1055 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1056 effect_descriptor_t desc;
1057 data.read(&desc, sizeof(effect_descriptor_t));
1058 audio_io_handle_t output = getOutputForEffect(&desc);
1059 reply->writeInt32(static_cast <int>(output));
1060 return NO_ERROR;
1061 } break;
1062
1063 case REGISTER_EFFECT: {
1064 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1065 effect_descriptor_t desc;
1066 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001067 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001068 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001069 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001070 int id = data.readInt32();
1071 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001072 io,
Eric Laurentde070132010-07-13 04:45:46 -07001073 strategy,
1074 session,
1075 id)));
1076 return NO_ERROR;
1077 } break;
1078
1079 case UNREGISTER_EFFECT: {
1080 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1081 int id = data.readInt32();
1082 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1083 return NO_ERROR;
1084 } break;
1085
Eric Laurentdb7c0792011-08-10 10:37:50 -07001086 case SET_EFFECT_ENABLED: {
1087 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1088 int id = data.readInt32();
1089 bool enabled = static_cast <bool>(data.readInt32());
1090 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1091 return NO_ERROR;
1092 } break;
1093
Eric Laurenteda6c362011-02-02 09:33:30 -08001094 case IS_STREAM_ACTIVE: {
1095 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001096 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001097 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001098 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001099 return NO_ERROR;
1100 } break;
1101
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001102 case IS_STREAM_ACTIVE_REMOTELY: {
1103 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1104 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1105 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001106 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001107 return NO_ERROR;
1108 } break;
1109
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001110 case IS_SOURCE_ACTIVE: {
1111 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1112 audio_source_t source = (audio_source_t) data.readInt32();
1113 reply->writeInt32( isSourceActive(source));
1114 return NO_ERROR;
1115 }
1116
Eric Laurent57dae992011-07-24 13:36:09 -07001117 case QUERY_DEFAULT_PRE_PROCESSING: {
1118 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001119 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001120 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001121 if (count > AudioEffect::kMaxPreProcessing) {
1122 count = AudioEffect::kMaxPreProcessing;
1123 }
Eric Laurent57dae992011-07-24 13:36:09 -07001124 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001125 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001126 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1127 reply->writeInt32(status);
1128 if (status != NO_ERROR && status != NO_MEMORY) {
1129 retCount = 0;
1130 }
1131 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001132 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001133 if (retCount < count) {
1134 count = retCount;
1135 }
1136 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1137 }
1138 delete[] descriptors;
1139 return status;
1140 }
1141
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001142 case IS_OFFLOAD_SUPPORTED: {
1143 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1144 audio_offload_info_t info;
1145 data.read(&info, sizeof(audio_offload_info_t));
1146 bool isSupported = isOffloadSupported(info);
1147 reply->writeInt32(isSupported);
1148 return NO_ERROR;
1149 }
1150
Eric Laurent203b1a12014-04-01 10:34:16 -07001151 case LIST_AUDIO_PORTS: {
1152 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1153 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1154 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1155 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001156 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1157 numPortsReq = MAX_ITEMS_PER_LIST;
1158 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001159 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001160 struct audio_port *ports =
1161 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001162 if (ports == NULL) {
1163 reply->writeInt32(NO_MEMORY);
1164 reply->writeInt32(0);
1165 return NO_ERROR;
1166 }
1167 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001168 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1169 reply->writeInt32(status);
1170 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001171
1172 if (status == NO_ERROR) {
1173 if (numPortsReq > numPorts) {
1174 numPortsReq = numPorts;
1175 }
1176 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1177 reply->writeInt32(generation);
1178 }
1179 free(ports);
1180 return NO_ERROR;
1181 }
1182
1183 case GET_AUDIO_PORT: {
1184 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001185 struct audio_port port = {};
1186 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1187 ALOGE("b/23912202");
1188 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001189 status_t status = getAudioPort(&port);
1190 reply->writeInt32(status);
1191 if (status == NO_ERROR) {
1192 reply->write(&port, sizeof(struct audio_port));
1193 }
1194 return NO_ERROR;
1195 }
1196
1197 case CREATE_AUDIO_PATCH: {
1198 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1199 struct audio_patch patch;
1200 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001201 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001202 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1203 ALOGE("b/23912202");
1204 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001205 status_t status = createAudioPatch(&patch, &handle);
1206 reply->writeInt32(status);
1207 if (status == NO_ERROR) {
1208 reply->write(&handle, sizeof(audio_patch_handle_t));
1209 }
1210 return NO_ERROR;
1211 }
1212
1213 case RELEASE_AUDIO_PATCH: {
1214 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1215 audio_patch_handle_t handle;
1216 data.read(&handle, sizeof(audio_patch_handle_t));
1217 status_t status = releaseAudioPatch(handle);
1218 reply->writeInt32(status);
1219 return NO_ERROR;
1220 }
1221
1222 case LIST_AUDIO_PATCHES: {
1223 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1224 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001225 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1226 numPatchesReq = MAX_ITEMS_PER_LIST;
1227 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001228 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001229 struct audio_patch *patches =
1230 (struct audio_patch *)calloc(numPatchesReq,
1231 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001232 if (patches == NULL) {
1233 reply->writeInt32(NO_MEMORY);
1234 reply->writeInt32(0);
1235 return NO_ERROR;
1236 }
1237 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001238 status_t status = listAudioPatches(&numPatches, patches, &generation);
1239 reply->writeInt32(status);
1240 reply->writeInt32(numPatches);
1241 if (status == NO_ERROR) {
1242 if (numPatchesReq > numPatches) {
1243 numPatchesReq = numPatches;
1244 }
1245 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1246 reply->writeInt32(generation);
1247 }
1248 free(patches);
1249 return NO_ERROR;
1250 }
1251
1252 case SET_AUDIO_PORT_CONFIG: {
1253 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1254 struct audio_port_config config;
1255 data.read(&config, sizeof(struct audio_port_config));
1256 status_t status = setAudioPortConfig(&config);
1257 reply->writeInt32(status);
1258 return NO_ERROR;
1259 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001260
Eric Laurentb52c1522014-05-20 11:27:36 -07001261 case REGISTER_CLIENT: {
1262 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1263 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1264 data.readStrongBinder());
1265 registerClient(client);
1266 return NO_ERROR;
1267 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001268
Eric Laurente8726fe2015-06-26 09:39:24 -07001269 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1270 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1271 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1272 return NO_ERROR;
1273 } break;
1274
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001275 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1276 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1277 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1278 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001279 audio_session_t session = AUDIO_SESSION_NONE;
1280 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1281 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001282 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1283 reply->writeInt32(status);
1284 if (status == NO_ERROR) {
1285 reply->writeInt32(session);
1286 reply->writeInt32(ioHandle);
1287 reply->writeInt32(device);
1288 }
1289 return NO_ERROR;
1290 } break;
1291
1292 case RELEASE_SOUNDTRIGGER_SESSION: {
1293 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1294 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1295 data.readStrongBinder());
1296 audio_session_t session = (audio_session_t)data.readInt32();
1297 status_t status = releaseSoundTriggerSession(session);
1298 reply->writeInt32(status);
1299 return NO_ERROR;
1300 } break;
1301
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001302 case GET_PHONE_STATE: {
1303 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1304 reply->writeInt32((int32_t)getPhoneState());
1305 return NO_ERROR;
1306 } break;
1307
Eric Laurentbaac1832014-12-01 17:52:59 -08001308 case REGISTER_POLICY_MIXES: {
1309 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1310 bool registration = data.readInt32() == 1;
1311 Vector<AudioMix> mixes;
1312 size_t size = (size_t)data.readInt32();
1313 if (size > MAX_MIXES_PER_POLICY) {
1314 size = MAX_MIXES_PER_POLICY;
1315 }
1316 for (size_t i = 0; i < size; i++) {
1317 AudioMix mix;
1318 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1319 mixes.add(mix);
1320 }
1321 }
1322 status_t status = registerPolicyMixes(mixes, registration);
1323 reply->writeInt32(status);
1324 return NO_ERROR;
1325 } break;
1326
Eric Laurent554a2772015-04-10 11:29:24 -07001327 case START_AUDIO_SOURCE: {
1328 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1329 struct audio_port_config source;
1330 data.read(&source, sizeof(struct audio_port_config));
1331 audio_attributes_t attributes;
1332 data.read(&attributes, sizeof(audio_attributes_t));
Glenn Kasten559d4392016-03-29 13:42:57 -07001333 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent554a2772015-04-10 11:29:24 -07001334 status_t status = startAudioSource(&source, &attributes, &handle);
1335 reply->writeInt32(status);
1336 reply->writeInt32(handle);
1337 return NO_ERROR;
1338 } break;
1339
1340 case STOP_AUDIO_SOURCE: {
1341 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten559d4392016-03-29 13:42:57 -07001342 audio_patch_handle_t handle = (audio_patch_handle_t) data.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -07001343 status_t status = stopAudioSource(handle);
1344 reply->writeInt32(status);
1345 return NO_ERROR;
1346 } break;
1347
Andy Hung2ddee192015-12-18 17:34:44 -08001348 case SET_MASTER_MONO: {
1349 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1350 bool mono = static_cast<bool>(data.readInt32());
1351 status_t status = setMasterMono(mono);
1352 reply->writeInt32(status);
1353 return NO_ERROR;
1354 } break;
1355
1356 case GET_MASTER_MONO: {
1357 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1358 bool mono;
1359 status_t status = getMasterMono(&mono);
1360 reply->writeInt32(status);
1361 if (status == NO_ERROR) {
1362 reply->writeInt32(static_cast<int32_t>(mono));
1363 }
1364 return NO_ERROR;
1365 } break;
1366
Eric Laurentc2f1f072009-07-17 12:17:14 -07001367 default:
1368 return BBinder::onTransact(code, data, reply, flags);
1369 }
1370}
1371
1372// ----------------------------------------------------------------------------
1373
Glenn Kasten40bc9062015-03-20 09:09:33 -07001374} // namespace android