blob: 222189a41105d2dde0abf11363f156ca6422fa05 [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,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080036 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070037 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080038 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_FORCE_USE,
40 GET_FORCE_USE,
41 GET_OUTPUT,
42 START_OUTPUT,
43 STOP_OUTPUT,
44 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080045 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070046 START_INPUT,
47 STOP_INPUT,
48 RELEASE_INPUT,
49 INIT_STREAM_VOLUME,
50 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070051 GET_STREAM_VOLUME,
52 GET_STRATEGY_FOR_STREAM,
53 GET_OUTPUT_FOR_EFFECT,
54 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080055 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080056 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070057 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070059 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080060 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000061 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070062 IS_OFFLOAD_SUPPORTED,
63 LIST_AUDIO_PORTS,
64 GET_AUDIO_PORT,
65 CREATE_AUDIO_PATCH,
66 RELEASE_AUDIO_PATCH,
67 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070068 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070069 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070070 GET_OUTPUT_FOR_ATTR,
71 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070072 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080073 GET_PHONE_STATE,
74 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070075 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070076 STOP_AUDIO_SOURCE,
77 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080078 SET_MASTER_MONO,
79 GET_MASTER_MONO,
Eric Laurentc2f1f072009-07-17 12:17:14 -070080};
81
Eric Laurent1d670b12015-02-06 10:44:24 -080082#define MAX_ITEMS_PER_LIST 1024
83
Eric Laurentc2f1f072009-07-17 12:17:14 -070084class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
85{
86public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070087 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -070088 : BpInterface<IAudioPolicyService>(impl)
89 {
90 }
91
92 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070093 audio_devices_t device,
94 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080095 const char *device_address,
96 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070097 {
98 Parcel data, reply;
99 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
100 data.writeInt32(static_cast <uint32_t>(device));
101 data.writeInt32(static_cast <uint32_t>(state));
102 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800103 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700104 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
105 return static_cast <status_t> (reply.readInt32());
106 }
107
Dima Zavinfce7a472011-04-19 22:30:36 -0700108 virtual audio_policy_dev_state_t getDeviceConnectionState(
109 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 const char *device_address)
111 {
112 Parcel data, reply;
113 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
114 data.writeInt32(static_cast <uint32_t>(device));
115 data.writeCString(device_address);
116 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700117 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700118 }
119
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800120 virtual status_t handleDeviceConfigChange(audio_devices_t device,
121 const char *device_address,
122 const char *device_name)
123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
126 data.writeInt32(static_cast <uint32_t>(device));
127 data.writeCString(device_address);
128 data.writeCString(device_name);
129 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
130 return static_cast <status_t> (reply.readInt32());
131 }
132
Glenn Kastenf78aee72012-01-04 11:00:47 -0800133 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
137 data.writeInt32(state);
138 remote()->transact(SET_PHONE_STATE, data, &reply);
139 return static_cast <status_t> (reply.readInt32());
140 }
141
Dima Zavinfce7a472011-04-19 22:30:36 -0700142 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700143 {
144 Parcel data, reply;
145 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
146 data.writeInt32(static_cast <uint32_t>(usage));
147 data.writeInt32(static_cast <uint32_t>(config));
148 remote()->transact(SET_FORCE_USE, data, &reply);
149 return static_cast <status_t> (reply.readInt32());
150 }
151
Dima Zavinfce7a472011-04-19 22:30:36 -0700152 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700153 {
154 Parcel data, reply;
155 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
156 data.writeInt32(static_cast <uint32_t>(usage));
157 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700158 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700159 }
160
161 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700162 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700163 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800164 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700165 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000166 audio_output_flags_t flags,
167 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700168 {
169 Parcel data, reply;
170 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
171 data.writeInt32(static_cast <uint32_t>(stream));
172 data.writeInt32(samplingRate);
173 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700174 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700175 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800176 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100177 if (offloadInfo == NULL) {
178 data.writeInt32(0);
179 } else {
180 data.writeInt32(1);
181 data.write(offloadInfo, sizeof(audio_offload_info_t));
182 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700183 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700184 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700185 }
186
Eric Laurente83b55d2014-11-14 10:06:21 -0800187 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
188 audio_io_handle_t *output,
189 audio_session_t session,
190 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700191 uid_t uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800192 uint32_t samplingRate,
193 audio_format_t format,
194 audio_channel_mask_t channelMask,
195 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700196 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700198 {
199 Parcel data, reply;
200 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
201 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800202 if (stream == NULL) {
203 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
204 return BAD_VALUE;
205 }
206 if (*stream == AUDIO_STREAM_DEFAULT) {
207 ALOGE("getOutputForAttr unspecified stream type");
208 return BAD_VALUE;
209 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700210 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800211 if (output == NULL) {
212 ALOGE("getOutputForAttr NULL output - shouldn't happen");
213 return BAD_VALUE;
214 }
215 if (attr == NULL) {
216 data.writeInt32(0);
217 } else {
218 data.writeInt32(1);
219 data.write(attr, sizeof(audio_attributes_t));
220 }
221 data.writeInt32(session);
222 if (stream == NULL) {
223 data.writeInt32(0);
224 } else {
225 data.writeInt32(1);
226 data.writeInt32(*stream);
227 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700228 data.writeInt32(uid);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700229 data.writeInt32(samplingRate);
230 data.writeInt32(static_cast <uint32_t>(format));
231 data.writeInt32(channelMask);
232 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700233 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700234 // hasOffloadInfo
235 if (offloadInfo == NULL) {
236 data.writeInt32(0);
237 } else {
238 data.writeInt32(1);
239 data.write(offloadInfo, sizeof(audio_offload_info_t));
240 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800241 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
242 if (status != NO_ERROR) {
243 return status;
244 }
245 status = (status_t)reply.readInt32();
246 if (status != NO_ERROR) {
247 return status;
248 }
249 *output = (audio_io_handle_t)reply.readInt32();
250 if (stream != NULL) {
251 *stream = (audio_stream_type_t)reply.readInt32();
252 }
253 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700254 }
255
Eric Laurentde070132010-07-13 04:45:46 -0700256 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700257 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800258 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 {
260 Parcel data, reply;
261 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700262 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800263 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800264 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700265 remote()->transact(START_OUTPUT, data, &reply);
266 return static_cast <status_t> (reply.readInt32());
267 }
268
Eric Laurentde070132010-07-13 04:45:46 -0700269 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700270 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800271 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700275 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800276 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800277 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700278 remote()->transact(STOP_OUTPUT, data, &reply);
279 return static_cast <status_t> (reply.readInt32());
280 }
281
Eric Laurente83b55d2014-11-14 10:06:21 -0800282 virtual void releaseOutput(audio_io_handle_t output,
283 audio_stream_type_t stream,
284 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700288 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800289 data.writeInt32((int32_t)stream);
290 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700291 remote()->transact(RELEASE_OUTPUT, data, &reply);
292 }
293
Eric Laurentcaf7f482014-11-25 17:50:47 -0800294 virtual status_t getInputForAttr(const audio_attributes_t *attr,
295 audio_io_handle_t *input,
296 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700297 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700298 uid_t uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800299 uint32_t samplingRate,
300 audio_format_t format,
301 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600302 audio_input_flags_t flags,
303 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700304 {
305 Parcel data, reply;
306 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800307 if (attr == NULL) {
308 ALOGE("getInputForAttr NULL attr - shouldn't happen");
309 return BAD_VALUE;
310 }
311 if (input == NULL) {
312 ALOGE("getInputForAttr NULL input - shouldn't happen");
313 return BAD_VALUE;
314 }
315 data.write(attr, sizeof(audio_attributes_t));
316 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700317 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700318 data.writeInt32(uid);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700319 data.writeInt32(samplingRate);
320 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700321 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700322 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600323 data.writeInt32(selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800324 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
325 if (status != NO_ERROR) {
326 return status;
327 }
328 status = reply.readInt32();
329 if (status != NO_ERROR) {
330 return status;
331 }
332 *input = (audio_io_handle_t)reply.readInt32();
333 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 }
335
Eric Laurent4dc68062014-07-28 17:26:49 -0700336 virtual status_t startInput(audio_io_handle_t input,
337 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700341 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700342 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700343 remote()->transact(START_INPUT, data, &reply);
344 return static_cast <status_t> (reply.readInt32());
345 }
346
Eric Laurent4dc68062014-07-28 17:26:49 -0700347 virtual status_t stopInput(audio_io_handle_t input,
348 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 {
350 Parcel data, reply;
351 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700352 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700353 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354 remote()->transact(STOP_INPUT, data, &reply);
355 return static_cast <status_t> (reply.readInt32());
356 }
357
Eric Laurent4dc68062014-07-28 17:26:49 -0700358 virtual void releaseInput(audio_io_handle_t input,
359 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 {
361 Parcel data, reply;
362 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700363 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700364 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 remote()->transact(RELEASE_INPUT, data, &reply);
366 }
367
Dima Zavinfce7a472011-04-19 22:30:36 -0700368 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 int indexMin,
370 int indexMax)
371 {
372 Parcel data, reply;
373 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
374 data.writeInt32(static_cast <uint32_t>(stream));
375 data.writeInt32(indexMin);
376 data.writeInt32(indexMax);
377 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
378 return static_cast <status_t> (reply.readInt32());
379 }
380
Eric Laurent83844cc2011-11-18 16:43:31 -0800381 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
382 int index,
383 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 {
385 Parcel data, reply;
386 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
387 data.writeInt32(static_cast <uint32_t>(stream));
388 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800389 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700390 remote()->transact(SET_STREAM_VOLUME, data, &reply);
391 return static_cast <status_t> (reply.readInt32());
392 }
393
Eric Laurent83844cc2011-11-18 16:43:31 -0800394 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
395 int *index,
396 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
400 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800401 data.writeInt32(static_cast <uint32_t>(device));
402
Eric Laurentc2f1f072009-07-17 12:17:14 -0700403 remote()->transact(GET_STREAM_VOLUME, data, &reply);
404 int lIndex = reply.readInt32();
405 if (index) *index = lIndex;
406 return static_cast <status_t> (reply.readInt32());
407 }
Eric Laurentde070132010-07-13 04:45:46 -0700408
Dima Zavinfce7a472011-04-19 22:30:36 -0700409 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700410 {
411 Parcel data, reply;
412 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
413 data.writeInt32(static_cast <uint32_t>(stream));
414 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
415 return reply.readInt32();
416 }
417
Eric Laurent63742522012-03-08 13:42:42 -0800418 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
422 data.writeInt32(static_cast <uint32_t>(stream));
423 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800424 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800425 }
426
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700427 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700428 {
429 Parcel data, reply;
430 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
431 data.write(desc, sizeof(effect_descriptor_t));
432 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
433 return static_cast <audio_io_handle_t> (reply.readInt32());
434 }
435
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700436 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700437 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700438 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800439 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700440 int id)
441 {
442 Parcel data, reply;
443 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
444 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700445 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700446 data.writeInt32(strategy);
447 data.writeInt32(session);
448 data.writeInt32(id);
449 remote()->transact(REGISTER_EFFECT, data, &reply);
450 return static_cast <status_t> (reply.readInt32());
451 }
452
453 virtual status_t unregisterEffect(int id)
454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
457 data.writeInt32(id);
458 remote()->transact(UNREGISTER_EFFECT, data, &reply);
459 return static_cast <status_t> (reply.readInt32());
460 }
461
Eric Laurentdb7c0792011-08-10 10:37:50 -0700462 virtual status_t setEffectEnabled(int id, bool enabled)
463 {
464 Parcel data, reply;
465 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
466 data.writeInt32(id);
467 data.writeInt32(enabled);
468 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
469 return static_cast <status_t> (reply.readInt32());
470 }
471
Glenn Kastenfff6d712012-01-12 16:38:12 -0800472 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800473 {
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800476 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800477 data.writeInt32(inPastMs);
478 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
479 return reply.readInt32();
480 }
Eric Laurent57dae992011-07-24 13:36:09 -0700481
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800482 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
483 {
484 Parcel data, reply;
485 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
486 data.writeInt32((int32_t) stream);
487 data.writeInt32(inPastMs);
488 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
489 return reply.readInt32();
490 }
491
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700492 virtual bool isSourceActive(audio_source_t source) const
493 {
494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
496 data.writeInt32((int32_t) source);
497 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
498 return reply.readInt32();
499 }
500
Glenn Kastend848eb42016-03-08 13:42:11 -0800501 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700502 effect_descriptor_t *descriptors,
503 uint32_t *count)
504 {
505 if (descriptors == NULL || count == NULL) {
506 return BAD_VALUE;
507 }
508 Parcel data, reply;
509 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
510 data.writeInt32(audioSession);
511 data.writeInt32(*count);
512 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
513 if (status != NO_ERROR) {
514 return status;
515 }
516 status = static_cast <status_t> (reply.readInt32());
517 uint32_t retCount = reply.readInt32();
518 if (retCount != 0) {
519 uint32_t numDesc = (retCount < *count) ? retCount : *count;
520 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
521 }
522 *count = retCount;
523 return status;
524 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000525
526 virtual bool isOffloadSupported(const audio_offload_info_t& info)
527 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100528 Parcel data, reply;
529 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
530 data.write(&info, sizeof(audio_offload_info_t));
531 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700532 return reply.readInt32();
533 }
534
535 virtual status_t listAudioPorts(audio_port_role_t role,
536 audio_port_type_t type,
537 unsigned int *num_ports,
538 struct audio_port *ports,
539 unsigned int *generation)
540 {
541 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
542 generation == NULL) {
543 return BAD_VALUE;
544 }
545 Parcel data, reply;
546 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
547 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
548 data.writeInt32(role);
549 data.writeInt32(type);
550 data.writeInt32(numPortsReq);
551 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
552 if (status == NO_ERROR) {
553 status = (status_t)reply.readInt32();
554 *num_ports = (unsigned int)reply.readInt32();
555 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700556 if (status == NO_ERROR) {
557 if (numPortsReq > *num_ports) {
558 numPortsReq = *num_ports;
559 }
560 if (numPortsReq > 0) {
561 reply.read(ports, numPortsReq * sizeof(struct audio_port));
562 }
563 *generation = reply.readInt32();
564 }
565 return status;
566 }
567
568 virtual status_t getAudioPort(struct audio_port *port)
569 {
570 if (port == NULL) {
571 return BAD_VALUE;
572 }
573 Parcel data, reply;
574 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
575 data.write(port, sizeof(struct audio_port));
576 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
577 if (status != NO_ERROR ||
578 (status = (status_t)reply.readInt32()) != NO_ERROR) {
579 return status;
580 }
581 reply.read(port, sizeof(struct audio_port));
582 return status;
583 }
584
585 virtual status_t createAudioPatch(const struct audio_patch *patch,
586 audio_patch_handle_t *handle)
587 {
588 if (patch == NULL || handle == NULL) {
589 return BAD_VALUE;
590 }
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
593 data.write(patch, sizeof(struct audio_patch));
594 data.write(handle, sizeof(audio_patch_handle_t));
595 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
596 if (status != NO_ERROR ||
597 (status = (status_t)reply.readInt32()) != NO_ERROR) {
598 return status;
599 }
600 reply.read(handle, sizeof(audio_patch_handle_t));
601 return status;
602 }
603
604 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
605 {
606 Parcel data, reply;
607 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
608 data.write(&handle, sizeof(audio_patch_handle_t));
609 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
610 if (status != NO_ERROR) {
611 status = (status_t)reply.readInt32();
612 }
613 return status;
614 }
615
616 virtual status_t listAudioPatches(unsigned int *num_patches,
617 struct audio_patch *patches,
618 unsigned int *generation)
619 {
620 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
621 generation == NULL) {
622 return BAD_VALUE;
623 }
624 Parcel data, reply;
625 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
626 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
627 data.writeInt32(numPatchesReq);
628 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
629 if (status == NO_ERROR) {
630 status = (status_t)reply.readInt32();
631 *num_patches = (unsigned int)reply.readInt32();
632 }
633 if (status == NO_ERROR) {
634 if (numPatchesReq > *num_patches) {
635 numPatchesReq = *num_patches;
636 }
637 if (numPatchesReq > 0) {
638 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
639 }
640 *generation = reply.readInt32();
641 }
642 return status;
643 }
644
645 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
646 {
647 if (config == NULL) {
648 return BAD_VALUE;
649 }
650 Parcel data, reply;
651 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
652 data.write(config, sizeof(struct audio_port_config));
653 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
654 if (status != NO_ERROR) {
655 status = (status_t)reply.readInt32();
656 }
657 return status;
658 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700659
Eric Laurentb52c1522014-05-20 11:27:36 -0700660 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
661 {
662 Parcel data, reply;
663 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800664 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700665 remote()->transact(REGISTER_CLIENT, data, &reply);
666 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700667
Eric Laurente8726fe2015-06-26 09:39:24 -0700668 virtual void setAudioPortCallbacksEnabled(bool enabled)
669 {
670 Parcel data, reply;
671 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
672 data.writeInt32(enabled ? 1 : 0);
673 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
674 }
675
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700676 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
677 audio_io_handle_t *ioHandle,
678 audio_devices_t *device)
679 {
680 if (session == NULL || ioHandle == NULL || device == NULL) {
681 return BAD_VALUE;
682 }
683 Parcel data, reply;
684 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
685 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
686 if (status != NO_ERROR) {
687 return status;
688 }
689 status = (status_t)reply.readInt32();
690 if (status == NO_ERROR) {
691 *session = (audio_session_t)reply.readInt32();
692 *ioHandle = (audio_io_handle_t)reply.readInt32();
693 *device = (audio_devices_t)reply.readInt32();
694 }
695 return status;
696 }
697
698 virtual status_t releaseSoundTriggerSession(audio_session_t session)
699 {
700 Parcel data, reply;
701 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
702 data.writeInt32(session);
703 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
704 if (status != NO_ERROR) {
705 return status;
706 }
707 return (status_t)reply.readInt32();
708 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700709
710 virtual audio_mode_t getPhoneState()
711 {
712 Parcel data, reply;
713 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
714 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
715 if (status != NO_ERROR) {
716 return AUDIO_MODE_INVALID;
717 }
718 return (audio_mode_t)reply.readInt32();
719 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800720
Chih-Hung Hsieh36d0ca12016-08-09 14:31:32 -0700721 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800722 {
723 Parcel data, reply;
724 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
725 data.writeInt32(registration ? 1 : 0);
726 size_t size = mixes.size();
727 if (size > MAX_MIXES_PER_POLICY) {
728 size = MAX_MIXES_PER_POLICY;
729 }
730 size_t sizePosition = data.dataPosition();
731 data.writeInt32(size);
732 size_t finalSize = size;
733 for (size_t i = 0; i < size; i++) {
734 size_t position = data.dataPosition();
735 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
736 data.setDataPosition(position);
737 finalSize--;
738 }
739 }
740 if (size != finalSize) {
741 size_t position = data.dataPosition();
742 data.setDataPosition(sizePosition);
743 data.writeInt32(finalSize);
744 data.setDataPosition(position);
745 }
746 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
747 if (status == NO_ERROR) {
748 status = (status_t)reply.readInt32();
749 }
750 return status;
751 }
Eric Laurent554a2772015-04-10 11:29:24 -0700752
753 virtual status_t startAudioSource(const struct audio_port_config *source,
754 const audio_attributes_t *attributes,
755 audio_io_handle_t *handle)
756 {
757 Parcel data, reply;
758 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
759 if (source == NULL || attributes == NULL || handle == NULL) {
760 return BAD_VALUE;
761 }
762 data.write(source, sizeof(struct audio_port_config));
763 data.write(attributes, sizeof(audio_attributes_t));
764 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
765 if (status != NO_ERROR) {
766 return status;
767 }
768 status = (status_t)reply.readInt32();
769 if (status != NO_ERROR) {
770 return status;
771 }
772 *handle = (audio_io_handle_t)reply.readInt32();
773 return status;
774 }
775
776 virtual status_t stopAudioSource(audio_io_handle_t handle)
777 {
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
780 data.writeInt32(handle);
781 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
782 if (status != NO_ERROR) {
783 return status;
784 }
785 status = (status_t)reply.readInt32();
786 return status;
787 }
Andy Hung2ddee192015-12-18 17:34:44 -0800788
789 virtual status_t setMasterMono(bool mono)
790 {
791 Parcel data, reply;
792 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
793 data.writeInt32(static_cast<int32_t>(mono));
794 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
795 if (status != NO_ERROR) {
796 return status;
797 }
798 return static_cast<status_t>(reply.readInt32());
799 }
800
801 virtual status_t getMasterMono(bool *mono)
802 {
803 if (mono == nullptr) {
804 return BAD_VALUE;
805 }
806 Parcel data, reply;
807 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
808
809 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
810 if (status != NO_ERROR) {
811 return status;
812 }
813 status = static_cast<status_t>(reply.readInt32());
814 if (status == NO_ERROR) {
815 *mono = static_cast<bool>(reply.readInt32());
816 }
817 return status;
818 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700819};
820
821IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
822
823// ----------------------------------------------------------------------
824
825
826status_t BnAudioPolicyService::onTransact(
827 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
828{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700829 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700830 case SET_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());
834 audio_policy_dev_state_t state =
835 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700836 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800837 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700838 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
839 state,
Paul McLeane743a472015-01-28 11:07:31 -0800840 device_address,
841 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700842 return NO_ERROR;
843 } break;
844
845 case GET_DEVICE_CONNECTION_STATE: {
846 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700847 audio_devices_t device =
848 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700849 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700850 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
851 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700852 return NO_ERROR;
853 } break;
854
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800855 case HANDLE_DEVICE_CONFIG_CHANGE: {
856 CHECK_INTERFACE(IAudioPolicyService, data, reply);
857 audio_devices_t device =
858 static_cast <audio_devices_t>(data.readInt32());
859 const char *device_address = data.readCString();
860 const char *device_name = data.readCString();
861 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
862 device_address,
863 device_name)));
864 return NO_ERROR;
865 } break;
866
Eric Laurentc2f1f072009-07-17 12:17:14 -0700867 case SET_PHONE_STATE: {
868 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700869 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
870 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700871 return NO_ERROR;
872 } break;
873
Eric Laurentc2f1f072009-07-17 12:17:14 -0700874 case SET_FORCE_USE: {
875 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700876 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
877 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700878 audio_policy_forced_cfg_t config =
879 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700880 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
881 return NO_ERROR;
882 } break;
883
884 case GET_FORCE_USE: {
885 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700886 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
887 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700888 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
889 return NO_ERROR;
890 } break;
891
892 case GET_OUTPUT: {
893 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700894 audio_stream_type_t stream =
895 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700896 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800897 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700898 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700899 audio_output_flags_t flags =
900 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100901 bool hasOffloadInfo = data.readInt32() != 0;
902 audio_offload_info_t offloadInfo;
903 if (hasOffloadInfo) {
904 data.read(&offloadInfo, sizeof(audio_offload_info_t));
905 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700906 audio_io_handle_t output = getOutput(stream,
907 samplingRate,
908 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700909 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100910 flags,
911 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700912 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700913 return NO_ERROR;
914 } break;
915
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700916 case GET_OUTPUT_FOR_ATTR: {
917 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800918 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800919 bool hasAttributes = data.readInt32() != 0;
920 if (hasAttributes) {
921 data.read(&attr, sizeof(audio_attributes_t));
922 }
923 audio_session_t session = (audio_session_t)data.readInt32();
924 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
925 bool hasStream = data.readInt32() != 0;
926 if (hasStream) {
927 stream = (audio_stream_type_t)data.readInt32();
928 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700929 uid_t uid = (uid_t)data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700930 uint32_t samplingRate = data.readInt32();
931 audio_format_t format = (audio_format_t) data.readInt32();
932 audio_channel_mask_t channelMask = data.readInt32();
933 audio_output_flags_t flags =
934 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700935 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700936 bool hasOffloadInfo = data.readInt32() != 0;
937 audio_offload_info_t offloadInfo;
938 if (hasOffloadInfo) {
939 data.read(&offloadInfo, sizeof(audio_offload_info_t));
940 }
Robert Shiha946d842015-09-02 16:46:59 -0700941 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800942 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700943 &output, session, &stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800944 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700945 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800946 reply->writeInt32(status);
947 reply->writeInt32(output);
948 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700949 return NO_ERROR;
950 } break;
951
Eric Laurentc2f1f072009-07-17 12:17:14 -0700952 case START_OUTPUT: {
953 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700954 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800955 audio_stream_type_t stream =
956 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800957 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700958 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800959 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700960 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700961 return NO_ERROR;
962 } break;
963
964 case STOP_OUTPUT: {
965 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700966 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800967 audio_stream_type_t stream =
968 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800969 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700970 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800971 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700972 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700973 return NO_ERROR;
974 } break;
975
976 case RELEASE_OUTPUT: {
977 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700978 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800979 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
980 audio_session_t session = (audio_session_t)data.readInt32();
981 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700982 return NO_ERROR;
983 } break;
984
Eric Laurentcaf7f482014-11-25 17:50:47 -0800985 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700986 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800987 audio_attributes_t attr;
988 data.read(&attr, sizeof(audio_attributes_t));
989 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700990 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700991 uid_t uid = (uid_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700992 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800993 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700994 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700995 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600996 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -0700997 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700998 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800999 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -06001000 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001001 reply->writeInt32(status);
1002 if (status == NO_ERROR) {
1003 reply->writeInt32(input);
1004 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001005 return NO_ERROR;
1006 } break;
1007
1008 case START_INPUT: {
1009 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001010 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001011 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1012 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001013 return NO_ERROR;
1014 } break;
1015
1016 case STOP_INPUT: {
1017 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001018 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001019 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1020 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001021 return NO_ERROR;
1022 } break;
1023
1024 case RELEASE_INPUT: {
1025 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001026 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001027 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1028 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001029 return NO_ERROR;
1030 } break;
1031
1032 case INIT_STREAM_VOLUME: {
1033 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001034 audio_stream_type_t stream =
1035 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001036 int indexMin = data.readInt32();
1037 int indexMax = data.readInt32();
1038 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1039 return NO_ERROR;
1040 } break;
1041
1042 case SET_STREAM_VOLUME: {
1043 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001044 audio_stream_type_t stream =
1045 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001046 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001047 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1048 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1049 index,
1050 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001051 return NO_ERROR;
1052 } break;
1053
1054 case GET_STREAM_VOLUME: {
1055 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001056 audio_stream_type_t stream =
1057 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001058 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001059 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001060 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001061 reply->writeInt32(index);
1062 reply->writeInt32(static_cast <uint32_t>(status));
1063 return NO_ERROR;
1064 } break;
1065
Eric Laurentde070132010-07-13 04:45:46 -07001066 case GET_STRATEGY_FOR_STREAM: {
1067 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001068 audio_stream_type_t stream =
1069 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001070 reply->writeInt32(getStrategyForStream(stream));
1071 return NO_ERROR;
1072 } break;
1073
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001074 case GET_DEVICES_FOR_STREAM: {
1075 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001076 audio_stream_type_t stream =
1077 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001078 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1079 return NO_ERROR;
1080 } break;
1081
Eric Laurentde070132010-07-13 04:45:46 -07001082 case GET_OUTPUT_FOR_EFFECT: {
1083 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1084 effect_descriptor_t desc;
1085 data.read(&desc, sizeof(effect_descriptor_t));
1086 audio_io_handle_t output = getOutputForEffect(&desc);
1087 reply->writeInt32(static_cast <int>(output));
1088 return NO_ERROR;
1089 } break;
1090
1091 case REGISTER_EFFECT: {
1092 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1093 effect_descriptor_t desc;
1094 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001095 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001096 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001097 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001098 int id = data.readInt32();
1099 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001100 io,
Eric Laurentde070132010-07-13 04:45:46 -07001101 strategy,
1102 session,
1103 id)));
1104 return NO_ERROR;
1105 } break;
1106
1107 case UNREGISTER_EFFECT: {
1108 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1109 int id = data.readInt32();
1110 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1111 return NO_ERROR;
1112 } break;
1113
Eric Laurentdb7c0792011-08-10 10:37:50 -07001114 case SET_EFFECT_ENABLED: {
1115 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1116 int id = data.readInt32();
1117 bool enabled = static_cast <bool>(data.readInt32());
1118 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1119 return NO_ERROR;
1120 } break;
1121
Eric Laurenteda6c362011-02-02 09:33:30 -08001122 case IS_STREAM_ACTIVE: {
1123 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001124 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001125 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001126 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001127 return NO_ERROR;
1128 } break;
1129
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001130 case IS_STREAM_ACTIVE_REMOTELY: {
1131 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1132 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1133 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001134 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001135 return NO_ERROR;
1136 } break;
1137
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001138 case IS_SOURCE_ACTIVE: {
1139 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1140 audio_source_t source = (audio_source_t) data.readInt32();
1141 reply->writeInt32( isSourceActive(source));
1142 return NO_ERROR;
1143 }
1144
Eric Laurent57dae992011-07-24 13:36:09 -07001145 case QUERY_DEFAULT_PRE_PROCESSING: {
1146 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001147 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001148 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001149 if (count > AudioEffect::kMaxPreProcessing) {
1150 count = AudioEffect::kMaxPreProcessing;
1151 }
Eric Laurent57dae992011-07-24 13:36:09 -07001152 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001153 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001154 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1155 reply->writeInt32(status);
1156 if (status != NO_ERROR && status != NO_MEMORY) {
1157 retCount = 0;
1158 }
1159 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001160 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001161 if (retCount < count) {
1162 count = retCount;
1163 }
1164 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1165 }
1166 delete[] descriptors;
1167 return status;
1168 }
1169
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001170 case IS_OFFLOAD_SUPPORTED: {
1171 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1172 audio_offload_info_t info;
1173 data.read(&info, sizeof(audio_offload_info_t));
1174 bool isSupported = isOffloadSupported(info);
1175 reply->writeInt32(isSupported);
1176 return NO_ERROR;
1177 }
1178
Eric Laurent203b1a12014-04-01 10:34:16 -07001179 case LIST_AUDIO_PORTS: {
1180 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1181 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1182 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1183 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001184 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1185 numPortsReq = MAX_ITEMS_PER_LIST;
1186 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001187 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001188 struct audio_port *ports =
1189 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001190 if (ports == NULL) {
1191 reply->writeInt32(NO_MEMORY);
1192 reply->writeInt32(0);
1193 return NO_ERROR;
1194 }
1195 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001196 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1197 reply->writeInt32(status);
1198 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001199
1200 if (status == NO_ERROR) {
1201 if (numPortsReq > numPorts) {
1202 numPortsReq = numPorts;
1203 }
1204 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1205 reply->writeInt32(generation);
1206 }
1207 free(ports);
1208 return NO_ERROR;
1209 }
1210
1211 case GET_AUDIO_PORT: {
1212 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001213 struct audio_port port = {};
1214 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1215 ALOGE("b/23912202");
1216 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001217 status_t status = getAudioPort(&port);
1218 reply->writeInt32(status);
1219 if (status == NO_ERROR) {
1220 reply->write(&port, sizeof(struct audio_port));
1221 }
1222 return NO_ERROR;
1223 }
1224
1225 case CREATE_AUDIO_PATCH: {
1226 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1227 struct audio_patch patch;
1228 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001229 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001230 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1231 ALOGE("b/23912202");
1232 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001233 status_t status = createAudioPatch(&patch, &handle);
1234 reply->writeInt32(status);
1235 if (status == NO_ERROR) {
1236 reply->write(&handle, sizeof(audio_patch_handle_t));
1237 }
1238 return NO_ERROR;
1239 }
1240
1241 case RELEASE_AUDIO_PATCH: {
1242 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1243 audio_patch_handle_t handle;
1244 data.read(&handle, sizeof(audio_patch_handle_t));
1245 status_t status = releaseAudioPatch(handle);
1246 reply->writeInt32(status);
1247 return NO_ERROR;
1248 }
1249
1250 case LIST_AUDIO_PATCHES: {
1251 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1252 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001253 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1254 numPatchesReq = MAX_ITEMS_PER_LIST;
1255 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001256 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001257 struct audio_patch *patches =
1258 (struct audio_patch *)calloc(numPatchesReq,
1259 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001260 if (patches == NULL) {
1261 reply->writeInt32(NO_MEMORY);
1262 reply->writeInt32(0);
1263 return NO_ERROR;
1264 }
1265 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001266 status_t status = listAudioPatches(&numPatches, patches, &generation);
1267 reply->writeInt32(status);
1268 reply->writeInt32(numPatches);
1269 if (status == NO_ERROR) {
1270 if (numPatchesReq > numPatches) {
1271 numPatchesReq = numPatches;
1272 }
1273 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1274 reply->writeInt32(generation);
1275 }
1276 free(patches);
1277 return NO_ERROR;
1278 }
1279
1280 case SET_AUDIO_PORT_CONFIG: {
1281 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1282 struct audio_port_config config;
1283 data.read(&config, sizeof(struct audio_port_config));
1284 status_t status = setAudioPortConfig(&config);
1285 reply->writeInt32(status);
1286 return NO_ERROR;
1287 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001288
Eric Laurentb52c1522014-05-20 11:27:36 -07001289 case REGISTER_CLIENT: {
1290 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1291 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1292 data.readStrongBinder());
1293 registerClient(client);
1294 return NO_ERROR;
1295 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001296
Eric Laurente8726fe2015-06-26 09:39:24 -07001297 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1298 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1299 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1300 return NO_ERROR;
1301 } break;
1302
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001303 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1304 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1305 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1306 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001307 audio_session_t session = AUDIO_SESSION_NONE;
1308 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1309 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001310 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1311 reply->writeInt32(status);
1312 if (status == NO_ERROR) {
1313 reply->writeInt32(session);
1314 reply->writeInt32(ioHandle);
1315 reply->writeInt32(device);
1316 }
1317 return NO_ERROR;
1318 } break;
1319
1320 case RELEASE_SOUNDTRIGGER_SESSION: {
1321 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1322 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1323 data.readStrongBinder());
1324 audio_session_t session = (audio_session_t)data.readInt32();
1325 status_t status = releaseSoundTriggerSession(session);
1326 reply->writeInt32(status);
1327 return NO_ERROR;
1328 } break;
1329
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001330 case GET_PHONE_STATE: {
1331 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1332 reply->writeInt32((int32_t)getPhoneState());
1333 return NO_ERROR;
1334 } break;
1335
Eric Laurentbaac1832014-12-01 17:52:59 -08001336 case REGISTER_POLICY_MIXES: {
1337 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1338 bool registration = data.readInt32() == 1;
1339 Vector<AudioMix> mixes;
1340 size_t size = (size_t)data.readInt32();
1341 if (size > MAX_MIXES_PER_POLICY) {
1342 size = MAX_MIXES_PER_POLICY;
1343 }
1344 for (size_t i = 0; i < size; i++) {
1345 AudioMix mix;
1346 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1347 mixes.add(mix);
1348 }
1349 }
1350 status_t status = registerPolicyMixes(mixes, registration);
1351 reply->writeInt32(status);
1352 return NO_ERROR;
1353 } break;
1354
Eric Laurent554a2772015-04-10 11:29:24 -07001355 case START_AUDIO_SOURCE: {
1356 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1357 struct audio_port_config source;
1358 data.read(&source, sizeof(struct audio_port_config));
1359 audio_attributes_t attributes;
1360 data.read(&attributes, sizeof(audio_attributes_t));
Wei Jiae995e472015-09-09 09:48:34 -07001361 audio_io_handle_t handle = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001362 status_t status = startAudioSource(&source, &attributes, &handle);
1363 reply->writeInt32(status);
1364 reply->writeInt32(handle);
1365 return NO_ERROR;
1366 } break;
1367
1368 case STOP_AUDIO_SOURCE: {
1369 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1370 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1371 status_t status = stopAudioSource(handle);
1372 reply->writeInt32(status);
1373 return NO_ERROR;
1374 } break;
1375
Andy Hung2ddee192015-12-18 17:34:44 -08001376 case SET_MASTER_MONO: {
1377 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1378 bool mono = static_cast<bool>(data.readInt32());
1379 status_t status = setMasterMono(mono);
1380 reply->writeInt32(status);
1381 return NO_ERROR;
1382 } break;
1383
1384 case GET_MASTER_MONO: {
1385 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1386 bool mono;
1387 status_t status = getMasterMono(&mono);
1388 reply->writeInt32(status);
1389 if (status == NO_ERROR) {
1390 reply->writeInt32(static_cast<int32_t>(mono));
1391 }
1392 return NO_ERROR;
1393 } break;
1394
Eric Laurentc2f1f072009-07-17 12:17:14 -07001395 default:
1396 return BBinder::onTransact(code, data, reply, flags);
1397 }
1398}
1399
1400// ----------------------------------------------------------------------------
1401
Glenn Kasten40bc9062015-03-20 09:09:33 -07001402} // namespace android