blob: 946da8a62f89b8333081cc46bb4a8ab842244800 [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 Laurente83b55d2014-11-14 10:06:21 -0800178 uint32_t samplingRate,
179 audio_format_t format,
180 audio_channel_mask_t channelMask,
181 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700182 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800183 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
187 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800188 if (stream == NULL) {
189 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
190 return BAD_VALUE;
191 }
192 if (*stream == AUDIO_STREAM_DEFAULT) {
193 ALOGE("getOutputForAttr unspecified stream type");
194 return BAD_VALUE;
195 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700196 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 if (output == NULL) {
198 ALOGE("getOutputForAttr NULL output - shouldn't happen");
199 return BAD_VALUE;
200 }
201 if (attr == NULL) {
202 data.writeInt32(0);
203 } else {
204 data.writeInt32(1);
205 data.write(attr, sizeof(audio_attributes_t));
206 }
207 data.writeInt32(session);
208 if (stream == NULL) {
209 data.writeInt32(0);
210 } else {
211 data.writeInt32(1);
212 data.writeInt32(*stream);
213 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700214 data.writeInt32(uid);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700215 data.writeInt32(samplingRate);
216 data.writeInt32(static_cast <uint32_t>(format));
217 data.writeInt32(channelMask);
218 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700219 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700220 // hasOffloadInfo
221 if (offloadInfo == NULL) {
222 data.writeInt32(0);
223 } else {
224 data.writeInt32(1);
225 data.write(offloadInfo, sizeof(audio_offload_info_t));
226 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800227 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
228 if (status != NO_ERROR) {
229 return status;
230 }
231 status = (status_t)reply.readInt32();
232 if (status != NO_ERROR) {
233 return status;
234 }
235 *output = (audio_io_handle_t)reply.readInt32();
236 if (stream != NULL) {
237 *stream = (audio_stream_type_t)reply.readInt32();
238 }
239 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700240 }
241
Eric Laurentde070132010-07-13 04:45:46 -0700242 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700243 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800244 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700248 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800249 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800250 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 remote()->transact(START_OUTPUT, data, &reply);
252 return static_cast <status_t> (reply.readInt32());
253 }
254
Eric Laurentde070132010-07-13 04:45:46 -0700255 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700256 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800257 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700261 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800262 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800263 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 remote()->transact(STOP_OUTPUT, data, &reply);
265 return static_cast <status_t> (reply.readInt32());
266 }
267
Eric Laurente83b55d2014-11-14 10:06:21 -0800268 virtual void releaseOutput(audio_io_handle_t output,
269 audio_stream_type_t stream,
270 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700274 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800275 data.writeInt32((int32_t)stream);
276 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 remote()->transact(RELEASE_OUTPUT, data, &reply);
278 }
279
Eric Laurentcaf7f482014-11-25 17:50:47 -0800280 virtual status_t getInputForAttr(const audio_attributes_t *attr,
281 audio_io_handle_t *input,
282 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700283 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700284 uid_t uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800285 uint32_t samplingRate,
286 audio_format_t format,
287 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600288 audio_input_flags_t flags,
289 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800293 if (attr == NULL) {
294 ALOGE("getInputForAttr NULL attr - shouldn't happen");
295 return BAD_VALUE;
296 }
297 if (input == NULL) {
298 ALOGE("getInputForAttr NULL input - shouldn't happen");
299 return BAD_VALUE;
300 }
301 data.write(attr, sizeof(audio_attributes_t));
302 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700303 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700304 data.writeInt32(uid);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700305 data.writeInt32(samplingRate);
306 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700307 data.writeInt32(channelMask);
Glenn Kastenb3b16602014-07-16 08:36:31 -0700308 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600309 data.writeInt32(selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800310 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
311 if (status != NO_ERROR) {
312 return status;
313 }
314 status = reply.readInt32();
315 if (status != NO_ERROR) {
316 return status;
317 }
318 *input = (audio_io_handle_t)reply.readInt32();
319 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700320 }
321
Eric Laurent4dc68062014-07-28 17:26:49 -0700322 virtual status_t startInput(audio_io_handle_t input,
323 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700324 {
325 Parcel data, reply;
326 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700327 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700328 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700329 remote()->transact(START_INPUT, data, &reply);
330 return static_cast <status_t> (reply.readInt32());
331 }
332
Eric Laurent4dc68062014-07-28 17:26:49 -0700333 virtual status_t stopInput(audio_io_handle_t input,
334 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700338 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700339 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 remote()->transact(STOP_INPUT, data, &reply);
341 return static_cast <status_t> (reply.readInt32());
342 }
343
Eric Laurent4dc68062014-07-28 17:26:49 -0700344 virtual void releaseInput(audio_io_handle_t input,
345 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700349 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700350 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 remote()->transact(RELEASE_INPUT, data, &reply);
352 }
353
Dima Zavinfce7a472011-04-19 22:30:36 -0700354 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355 int indexMin,
356 int indexMax)
357 {
358 Parcel data, reply;
359 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
360 data.writeInt32(static_cast <uint32_t>(stream));
361 data.writeInt32(indexMin);
362 data.writeInt32(indexMax);
363 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
364 return static_cast <status_t> (reply.readInt32());
365 }
366
Eric Laurent83844cc2011-11-18 16:43:31 -0800367 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
368 int index,
369 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700370 {
371 Parcel data, reply;
372 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
373 data.writeInt32(static_cast <uint32_t>(stream));
374 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800375 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700376 remote()->transact(SET_STREAM_VOLUME, data, &reply);
377 return static_cast <status_t> (reply.readInt32());
378 }
379
Eric Laurent83844cc2011-11-18 16:43:31 -0800380 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
381 int *index,
382 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
386 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800387 data.writeInt32(static_cast <uint32_t>(device));
388
Eric Laurentc2f1f072009-07-17 12:17:14 -0700389 remote()->transact(GET_STREAM_VOLUME, data, &reply);
390 int lIndex = reply.readInt32();
391 if (index) *index = lIndex;
392 return static_cast <status_t> (reply.readInt32());
393 }
Eric Laurentde070132010-07-13 04:45:46 -0700394
Dima Zavinfce7a472011-04-19 22:30:36 -0700395 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
399 data.writeInt32(static_cast <uint32_t>(stream));
400 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
401 return reply.readInt32();
402 }
403
Eric Laurent63742522012-03-08 13:42:42 -0800404 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
408 data.writeInt32(static_cast <uint32_t>(stream));
409 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800410 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800411 }
412
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700413 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
417 data.write(desc, sizeof(effect_descriptor_t));
418 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
419 return static_cast <audio_io_handle_t> (reply.readInt32());
420 }
421
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700422 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700423 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700424 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800425 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700426 int id)
427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
430 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700431 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700432 data.writeInt32(strategy);
433 data.writeInt32(session);
434 data.writeInt32(id);
435 remote()->transact(REGISTER_EFFECT, data, &reply);
436 return static_cast <status_t> (reply.readInt32());
437 }
438
439 virtual status_t unregisterEffect(int id)
440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.writeInt32(id);
444 remote()->transact(UNREGISTER_EFFECT, data, &reply);
445 return static_cast <status_t> (reply.readInt32());
446 }
447
Eric Laurentdb7c0792011-08-10 10:37:50 -0700448 virtual status_t setEffectEnabled(int id, bool enabled)
449 {
450 Parcel data, reply;
451 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
452 data.writeInt32(id);
453 data.writeInt32(enabled);
454 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
455 return static_cast <status_t> (reply.readInt32());
456 }
457
Glenn Kastenfff6d712012-01-12 16:38:12 -0800458 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800459 {
460 Parcel data, reply;
461 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800462 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800463 data.writeInt32(inPastMs);
464 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
465 return reply.readInt32();
466 }
Eric Laurent57dae992011-07-24 13:36:09 -0700467
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800468 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
469 {
470 Parcel data, reply;
471 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
472 data.writeInt32((int32_t) stream);
473 data.writeInt32(inPastMs);
474 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
475 return reply.readInt32();
476 }
477
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700478 virtual bool isSourceActive(audio_source_t source) const
479 {
480 Parcel data, reply;
481 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
482 data.writeInt32((int32_t) source);
483 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
484 return reply.readInt32();
485 }
486
Glenn Kastend848eb42016-03-08 13:42:11 -0800487 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700488 effect_descriptor_t *descriptors,
489 uint32_t *count)
490 {
491 if (descriptors == NULL || count == NULL) {
492 return BAD_VALUE;
493 }
494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
496 data.writeInt32(audioSession);
497 data.writeInt32(*count);
498 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
499 if (status != NO_ERROR) {
500 return status;
501 }
502 status = static_cast <status_t> (reply.readInt32());
503 uint32_t retCount = reply.readInt32();
504 if (retCount != 0) {
505 uint32_t numDesc = (retCount < *count) ? retCount : *count;
506 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
507 }
508 *count = retCount;
509 return status;
510 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000511
512 virtual bool isOffloadSupported(const audio_offload_info_t& info)
513 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100514 Parcel data, reply;
515 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
516 data.write(&info, sizeof(audio_offload_info_t));
517 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700518 return reply.readInt32();
519 }
520
521 virtual status_t listAudioPorts(audio_port_role_t role,
522 audio_port_type_t type,
523 unsigned int *num_ports,
524 struct audio_port *ports,
525 unsigned int *generation)
526 {
527 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
528 generation == NULL) {
529 return BAD_VALUE;
530 }
531 Parcel data, reply;
532 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
533 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
534 data.writeInt32(role);
535 data.writeInt32(type);
536 data.writeInt32(numPortsReq);
537 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
538 if (status == NO_ERROR) {
539 status = (status_t)reply.readInt32();
540 *num_ports = (unsigned int)reply.readInt32();
541 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700542 if (status == NO_ERROR) {
543 if (numPortsReq > *num_ports) {
544 numPortsReq = *num_ports;
545 }
546 if (numPortsReq > 0) {
547 reply.read(ports, numPortsReq * sizeof(struct audio_port));
548 }
549 *generation = reply.readInt32();
550 }
551 return status;
552 }
553
554 virtual status_t getAudioPort(struct audio_port *port)
555 {
556 if (port == NULL) {
557 return BAD_VALUE;
558 }
559 Parcel data, reply;
560 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
561 data.write(port, sizeof(struct audio_port));
562 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
563 if (status != NO_ERROR ||
564 (status = (status_t)reply.readInt32()) != NO_ERROR) {
565 return status;
566 }
567 reply.read(port, sizeof(struct audio_port));
568 return status;
569 }
570
571 virtual status_t createAudioPatch(const struct audio_patch *patch,
572 audio_patch_handle_t *handle)
573 {
574 if (patch == NULL || handle == NULL) {
575 return BAD_VALUE;
576 }
577 Parcel data, reply;
578 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
579 data.write(patch, sizeof(struct audio_patch));
580 data.write(handle, sizeof(audio_patch_handle_t));
581 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
582 if (status != NO_ERROR ||
583 (status = (status_t)reply.readInt32()) != NO_ERROR) {
584 return status;
585 }
586 reply.read(handle, sizeof(audio_patch_handle_t));
587 return status;
588 }
589
590 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
591 {
592 Parcel data, reply;
593 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
594 data.write(&handle, sizeof(audio_patch_handle_t));
595 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
596 if (status != NO_ERROR) {
597 status = (status_t)reply.readInt32();
598 }
599 return status;
600 }
601
602 virtual status_t listAudioPatches(unsigned int *num_patches,
603 struct audio_patch *patches,
604 unsigned int *generation)
605 {
606 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
607 generation == NULL) {
608 return BAD_VALUE;
609 }
610 Parcel data, reply;
611 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
612 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
613 data.writeInt32(numPatchesReq);
614 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
615 if (status == NO_ERROR) {
616 status = (status_t)reply.readInt32();
617 *num_patches = (unsigned int)reply.readInt32();
618 }
619 if (status == NO_ERROR) {
620 if (numPatchesReq > *num_patches) {
621 numPatchesReq = *num_patches;
622 }
623 if (numPatchesReq > 0) {
624 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
625 }
626 *generation = reply.readInt32();
627 }
628 return status;
629 }
630
631 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
632 {
633 if (config == NULL) {
634 return BAD_VALUE;
635 }
636 Parcel data, reply;
637 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
638 data.write(config, sizeof(struct audio_port_config));
639 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
640 if (status != NO_ERROR) {
641 status = (status_t)reply.readInt32();
642 }
643 return status;
644 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700645
Eric Laurentb52c1522014-05-20 11:27:36 -0700646 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
647 {
648 Parcel data, reply;
649 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800650 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700651 remote()->transact(REGISTER_CLIENT, data, &reply);
652 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700653
Eric Laurente8726fe2015-06-26 09:39:24 -0700654 virtual void setAudioPortCallbacksEnabled(bool enabled)
655 {
656 Parcel data, reply;
657 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
658 data.writeInt32(enabled ? 1 : 0);
659 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
660 }
661
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700662 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
663 audio_io_handle_t *ioHandle,
664 audio_devices_t *device)
665 {
666 if (session == NULL || ioHandle == NULL || device == NULL) {
667 return BAD_VALUE;
668 }
669 Parcel data, reply;
670 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
671 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
672 if (status != NO_ERROR) {
673 return status;
674 }
675 status = (status_t)reply.readInt32();
676 if (status == NO_ERROR) {
677 *session = (audio_session_t)reply.readInt32();
678 *ioHandle = (audio_io_handle_t)reply.readInt32();
679 *device = (audio_devices_t)reply.readInt32();
680 }
681 return status;
682 }
683
684 virtual status_t releaseSoundTriggerSession(audio_session_t session)
685 {
686 Parcel data, reply;
687 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
688 data.writeInt32(session);
689 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
690 if (status != NO_ERROR) {
691 return status;
692 }
693 return (status_t)reply.readInt32();
694 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700695
696 virtual audio_mode_t getPhoneState()
697 {
698 Parcel data, reply;
699 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
700 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
701 if (status != NO_ERROR) {
702 return AUDIO_MODE_INVALID;
703 }
704 return (audio_mode_t)reply.readInt32();
705 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800706
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700707 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800708 {
709 Parcel data, reply;
710 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
711 data.writeInt32(registration ? 1 : 0);
712 size_t size = mixes.size();
713 if (size > MAX_MIXES_PER_POLICY) {
714 size = MAX_MIXES_PER_POLICY;
715 }
716 size_t sizePosition = data.dataPosition();
717 data.writeInt32(size);
718 size_t finalSize = size;
719 for (size_t i = 0; i < size; i++) {
720 size_t position = data.dataPosition();
721 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
722 data.setDataPosition(position);
723 finalSize--;
724 }
725 }
726 if (size != finalSize) {
727 size_t position = data.dataPosition();
728 data.setDataPosition(sizePosition);
729 data.writeInt32(finalSize);
730 data.setDataPosition(position);
731 }
732 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
733 if (status == NO_ERROR) {
734 status = (status_t)reply.readInt32();
735 }
736 return status;
737 }
Eric Laurent554a2772015-04-10 11:29:24 -0700738
739 virtual status_t startAudioSource(const struct audio_port_config *source,
740 const audio_attributes_t *attributes,
741 audio_io_handle_t *handle)
742 {
743 Parcel data, reply;
744 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
745 if (source == NULL || attributes == NULL || handle == NULL) {
746 return BAD_VALUE;
747 }
748 data.write(source, sizeof(struct audio_port_config));
749 data.write(attributes, sizeof(audio_attributes_t));
750 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
751 if (status != NO_ERROR) {
752 return status;
753 }
754 status = (status_t)reply.readInt32();
755 if (status != NO_ERROR) {
756 return status;
757 }
758 *handle = (audio_io_handle_t)reply.readInt32();
759 return status;
760 }
761
762 virtual status_t stopAudioSource(audio_io_handle_t handle)
763 {
764 Parcel data, reply;
765 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
766 data.writeInt32(handle);
767 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
768 if (status != NO_ERROR) {
769 return status;
770 }
771 status = (status_t)reply.readInt32();
772 return status;
773 }
Andy Hung2ddee192015-12-18 17:34:44 -0800774
775 virtual status_t setMasterMono(bool mono)
776 {
777 Parcel data, reply;
778 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
779 data.writeInt32(static_cast<int32_t>(mono));
780 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
781 if (status != NO_ERROR) {
782 return status;
783 }
784 return static_cast<status_t>(reply.readInt32());
785 }
786
787 virtual status_t getMasterMono(bool *mono)
788 {
789 if (mono == nullptr) {
790 return BAD_VALUE;
791 }
792 Parcel data, reply;
793 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
794
795 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
796 if (status != NO_ERROR) {
797 return status;
798 }
799 status = static_cast<status_t>(reply.readInt32());
800 if (status == NO_ERROR) {
801 *mono = static_cast<bool>(reply.readInt32());
802 }
803 return status;
804 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700805};
806
807IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
808
809// ----------------------------------------------------------------------
810
811
812status_t BnAudioPolicyService::onTransact(
813 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
814{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700815 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700816 case SET_DEVICE_CONNECTION_STATE: {
817 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700818 audio_devices_t device =
819 static_cast <audio_devices_t>(data.readInt32());
820 audio_policy_dev_state_t state =
821 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700822 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800823 const char *device_name = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700824 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
825 state,
Paul McLeane743a472015-01-28 11:07:31 -0800826 device_address,
827 device_name)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700828 return NO_ERROR;
829 } break;
830
831 case GET_DEVICE_CONNECTION_STATE: {
832 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700833 audio_devices_t device =
834 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700835 const char *device_address = data.readCString();
Eric Laurentde070132010-07-13 04:45:46 -0700836 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
837 device_address)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700838 return NO_ERROR;
839 } break;
840
841 case SET_PHONE_STATE: {
842 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700843 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
844 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845 return NO_ERROR;
846 } break;
847
Eric Laurentc2f1f072009-07-17 12:17:14 -0700848 case SET_FORCE_USE: {
849 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700850 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
851 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700852 audio_policy_forced_cfg_t config =
853 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700854 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
855 return NO_ERROR;
856 } break;
857
858 case GET_FORCE_USE: {
859 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700860 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
861 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
863 return NO_ERROR;
864 } break;
865
866 case GET_OUTPUT: {
867 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700868 audio_stream_type_t stream =
869 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700870 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800871 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700872 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700873 audio_output_flags_t flags =
874 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100875 bool hasOffloadInfo = data.readInt32() != 0;
876 audio_offload_info_t offloadInfo;
877 if (hasOffloadInfo) {
878 data.read(&offloadInfo, sizeof(audio_offload_info_t));
879 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700880 audio_io_handle_t output = getOutput(stream,
881 samplingRate,
882 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700883 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100884 flags,
885 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700886 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700887 return NO_ERROR;
888 } break;
889
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700890 case GET_OUTPUT_FOR_ATTR: {
891 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800892 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800893 bool hasAttributes = data.readInt32() != 0;
894 if (hasAttributes) {
895 data.read(&attr, sizeof(audio_attributes_t));
896 }
897 audio_session_t session = (audio_session_t)data.readInt32();
898 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
899 bool hasStream = data.readInt32() != 0;
900 if (hasStream) {
901 stream = (audio_stream_type_t)data.readInt32();
902 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700903 uid_t uid = (uid_t)data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700904 uint32_t samplingRate = data.readInt32();
905 audio_format_t format = (audio_format_t) data.readInt32();
906 audio_channel_mask_t channelMask = data.readInt32();
907 audio_output_flags_t flags =
908 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700909 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700910 bool hasOffloadInfo = data.readInt32() != 0;
911 audio_offload_info_t offloadInfo;
912 if (hasOffloadInfo) {
913 data.read(&offloadInfo, sizeof(audio_offload_info_t));
914 }
Robert Shiha946d842015-09-02 16:46:59 -0700915 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800916 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700917 &output, session, &stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800918 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700919 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800920 reply->writeInt32(status);
921 reply->writeInt32(output);
922 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700923 return NO_ERROR;
924 } break;
925
Eric Laurentc2f1f072009-07-17 12:17:14 -0700926 case START_OUTPUT: {
927 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700928 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800929 audio_stream_type_t stream =
930 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800931 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700932 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800933 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700934 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700935 return NO_ERROR;
936 } break;
937
938 case STOP_OUTPUT: {
939 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700940 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800941 audio_stream_type_t stream =
942 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800943 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700944 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800945 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700946 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700947 return NO_ERROR;
948 } break;
949
950 case RELEASE_OUTPUT: {
951 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700952 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800953 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
954 audio_session_t session = (audio_session_t)data.readInt32();
955 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700956 return NO_ERROR;
957 } break;
958
Eric Laurentcaf7f482014-11-25 17:50:47 -0800959 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700960 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800961 audio_attributes_t attr;
962 data.read(&attr, sizeof(audio_attributes_t));
963 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700964 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700965 uid_t uid = (uid_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700966 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800967 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700968 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700969 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600970 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -0700971 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700972 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800973 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600974 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800975 reply->writeInt32(status);
976 if (status == NO_ERROR) {
977 reply->writeInt32(input);
978 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700979 return NO_ERROR;
980 } break;
981
982 case START_INPUT: {
983 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700984 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700985 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
986 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700987 return NO_ERROR;
988 } break;
989
990 case STOP_INPUT: {
991 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700992 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700993 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
994 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700995 return NO_ERROR;
996 } break;
997
998 case RELEASE_INPUT: {
999 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001000 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001001 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1002 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001003 return NO_ERROR;
1004 } break;
1005
1006 case INIT_STREAM_VOLUME: {
1007 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001008 audio_stream_type_t stream =
1009 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001010 int indexMin = data.readInt32();
1011 int indexMax = data.readInt32();
1012 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1013 return NO_ERROR;
1014 } break;
1015
1016 case SET_STREAM_VOLUME: {
1017 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001018 audio_stream_type_t stream =
1019 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001020 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001021 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1022 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1023 index,
1024 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001025 return NO_ERROR;
1026 } break;
1027
1028 case GET_STREAM_VOLUME: {
1029 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001030 audio_stream_type_t stream =
1031 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001032 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001033 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001034 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001035 reply->writeInt32(index);
1036 reply->writeInt32(static_cast <uint32_t>(status));
1037 return NO_ERROR;
1038 } break;
1039
Eric Laurentde070132010-07-13 04:45:46 -07001040 case GET_STRATEGY_FOR_STREAM: {
1041 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001042 audio_stream_type_t stream =
1043 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001044 reply->writeInt32(getStrategyForStream(stream));
1045 return NO_ERROR;
1046 } break;
1047
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001048 case GET_DEVICES_FOR_STREAM: {
1049 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001050 audio_stream_type_t stream =
1051 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001052 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1053 return NO_ERROR;
1054 } break;
1055
Eric Laurentde070132010-07-13 04:45:46 -07001056 case GET_OUTPUT_FOR_EFFECT: {
1057 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1058 effect_descriptor_t desc;
1059 data.read(&desc, sizeof(effect_descriptor_t));
1060 audio_io_handle_t output = getOutputForEffect(&desc);
1061 reply->writeInt32(static_cast <int>(output));
1062 return NO_ERROR;
1063 } break;
1064
1065 case REGISTER_EFFECT: {
1066 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1067 effect_descriptor_t desc;
1068 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001069 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001070 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001071 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001072 int id = data.readInt32();
1073 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001074 io,
Eric Laurentde070132010-07-13 04:45:46 -07001075 strategy,
1076 session,
1077 id)));
1078 return NO_ERROR;
1079 } break;
1080
1081 case UNREGISTER_EFFECT: {
1082 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1083 int id = data.readInt32();
1084 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1085 return NO_ERROR;
1086 } break;
1087
Eric Laurentdb7c0792011-08-10 10:37:50 -07001088 case SET_EFFECT_ENABLED: {
1089 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1090 int id = data.readInt32();
1091 bool enabled = static_cast <bool>(data.readInt32());
1092 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1093 return NO_ERROR;
1094 } break;
1095
Eric Laurenteda6c362011-02-02 09:33:30 -08001096 case IS_STREAM_ACTIVE: {
1097 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001098 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001099 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001100 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001101 return NO_ERROR;
1102 } break;
1103
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001104 case IS_STREAM_ACTIVE_REMOTELY: {
1105 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1106 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1107 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001108 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001109 return NO_ERROR;
1110 } break;
1111
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001112 case IS_SOURCE_ACTIVE: {
1113 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1114 audio_source_t source = (audio_source_t) data.readInt32();
1115 reply->writeInt32( isSourceActive(source));
1116 return NO_ERROR;
1117 }
1118
Eric Laurent57dae992011-07-24 13:36:09 -07001119 case QUERY_DEFAULT_PRE_PROCESSING: {
1120 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001121 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001122 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001123 if (count > AudioEffect::kMaxPreProcessing) {
1124 count = AudioEffect::kMaxPreProcessing;
1125 }
Eric Laurent57dae992011-07-24 13:36:09 -07001126 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001127 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001128 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1129 reply->writeInt32(status);
1130 if (status != NO_ERROR && status != NO_MEMORY) {
1131 retCount = 0;
1132 }
1133 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001134 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001135 if (retCount < count) {
1136 count = retCount;
1137 }
1138 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1139 }
1140 delete[] descriptors;
1141 return status;
1142 }
1143
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001144 case IS_OFFLOAD_SUPPORTED: {
1145 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1146 audio_offload_info_t info;
1147 data.read(&info, sizeof(audio_offload_info_t));
1148 bool isSupported = isOffloadSupported(info);
1149 reply->writeInt32(isSupported);
1150 return NO_ERROR;
1151 }
1152
Eric Laurent203b1a12014-04-01 10:34:16 -07001153 case LIST_AUDIO_PORTS: {
1154 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1155 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1156 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1157 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001158 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1159 numPortsReq = MAX_ITEMS_PER_LIST;
1160 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001161 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001162 struct audio_port *ports =
1163 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001164 if (ports == NULL) {
1165 reply->writeInt32(NO_MEMORY);
1166 reply->writeInt32(0);
1167 return NO_ERROR;
1168 }
1169 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001170 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1171 reply->writeInt32(status);
1172 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001173
1174 if (status == NO_ERROR) {
1175 if (numPortsReq > numPorts) {
1176 numPortsReq = numPorts;
1177 }
1178 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1179 reply->writeInt32(generation);
1180 }
1181 free(ports);
1182 return NO_ERROR;
1183 }
1184
1185 case GET_AUDIO_PORT: {
1186 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001187 struct audio_port port = {};
1188 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1189 ALOGE("b/23912202");
1190 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001191 status_t status = getAudioPort(&port);
1192 reply->writeInt32(status);
1193 if (status == NO_ERROR) {
1194 reply->write(&port, sizeof(struct audio_port));
1195 }
1196 return NO_ERROR;
1197 }
1198
1199 case CREATE_AUDIO_PATCH: {
1200 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1201 struct audio_patch patch;
1202 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001203 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001204 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1205 ALOGE("b/23912202");
1206 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001207 status_t status = createAudioPatch(&patch, &handle);
1208 reply->writeInt32(status);
1209 if (status == NO_ERROR) {
1210 reply->write(&handle, sizeof(audio_patch_handle_t));
1211 }
1212 return NO_ERROR;
1213 }
1214
1215 case RELEASE_AUDIO_PATCH: {
1216 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1217 audio_patch_handle_t handle;
1218 data.read(&handle, sizeof(audio_patch_handle_t));
1219 status_t status = releaseAudioPatch(handle);
1220 reply->writeInt32(status);
1221 return NO_ERROR;
1222 }
1223
1224 case LIST_AUDIO_PATCHES: {
1225 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1226 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001227 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1228 numPatchesReq = MAX_ITEMS_PER_LIST;
1229 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001230 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001231 struct audio_patch *patches =
1232 (struct audio_patch *)calloc(numPatchesReq,
1233 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001234 if (patches == NULL) {
1235 reply->writeInt32(NO_MEMORY);
1236 reply->writeInt32(0);
1237 return NO_ERROR;
1238 }
1239 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001240 status_t status = listAudioPatches(&numPatches, patches, &generation);
1241 reply->writeInt32(status);
1242 reply->writeInt32(numPatches);
1243 if (status == NO_ERROR) {
1244 if (numPatchesReq > numPatches) {
1245 numPatchesReq = numPatches;
1246 }
1247 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1248 reply->writeInt32(generation);
1249 }
1250 free(patches);
1251 return NO_ERROR;
1252 }
1253
1254 case SET_AUDIO_PORT_CONFIG: {
1255 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1256 struct audio_port_config config;
1257 data.read(&config, sizeof(struct audio_port_config));
1258 status_t status = setAudioPortConfig(&config);
1259 reply->writeInt32(status);
1260 return NO_ERROR;
1261 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001262
Eric Laurentb52c1522014-05-20 11:27:36 -07001263 case REGISTER_CLIENT: {
1264 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1265 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1266 data.readStrongBinder());
1267 registerClient(client);
1268 return NO_ERROR;
1269 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001270
Eric Laurente8726fe2015-06-26 09:39:24 -07001271 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1272 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1273 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1274 return NO_ERROR;
1275 } break;
1276
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001277 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1278 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1279 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1280 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001281 audio_session_t session = AUDIO_SESSION_NONE;
1282 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1283 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001284 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1285 reply->writeInt32(status);
1286 if (status == NO_ERROR) {
1287 reply->writeInt32(session);
1288 reply->writeInt32(ioHandle);
1289 reply->writeInt32(device);
1290 }
1291 return NO_ERROR;
1292 } break;
1293
1294 case RELEASE_SOUNDTRIGGER_SESSION: {
1295 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1296 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1297 data.readStrongBinder());
1298 audio_session_t session = (audio_session_t)data.readInt32();
1299 status_t status = releaseSoundTriggerSession(session);
1300 reply->writeInt32(status);
1301 return NO_ERROR;
1302 } break;
1303
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001304 case GET_PHONE_STATE: {
1305 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1306 reply->writeInt32((int32_t)getPhoneState());
1307 return NO_ERROR;
1308 } break;
1309
Eric Laurentbaac1832014-12-01 17:52:59 -08001310 case REGISTER_POLICY_MIXES: {
1311 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1312 bool registration = data.readInt32() == 1;
1313 Vector<AudioMix> mixes;
1314 size_t size = (size_t)data.readInt32();
1315 if (size > MAX_MIXES_PER_POLICY) {
1316 size = MAX_MIXES_PER_POLICY;
1317 }
1318 for (size_t i = 0; i < size; i++) {
1319 AudioMix mix;
1320 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1321 mixes.add(mix);
1322 }
1323 }
1324 status_t status = registerPolicyMixes(mixes, registration);
1325 reply->writeInt32(status);
1326 return NO_ERROR;
1327 } break;
1328
Eric Laurent554a2772015-04-10 11:29:24 -07001329 case START_AUDIO_SOURCE: {
1330 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1331 struct audio_port_config source;
1332 data.read(&source, sizeof(struct audio_port_config));
1333 audio_attributes_t attributes;
1334 data.read(&attributes, sizeof(audio_attributes_t));
Wei Jiae995e472015-09-09 09:48:34 -07001335 audio_io_handle_t handle = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001336 status_t status = startAudioSource(&source, &attributes, &handle);
1337 reply->writeInt32(status);
1338 reply->writeInt32(handle);
1339 return NO_ERROR;
1340 } break;
1341
1342 case STOP_AUDIO_SOURCE: {
1343 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1344 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1345 status_t status = stopAudioSource(handle);
1346 reply->writeInt32(status);
1347 return NO_ERROR;
1348 } break;
1349
Andy Hung2ddee192015-12-18 17:34:44 -08001350 case SET_MASTER_MONO: {
1351 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1352 bool mono = static_cast<bool>(data.readInt32());
1353 status_t status = setMasterMono(mono);
1354 reply->writeInt32(status);
1355 return NO_ERROR;
1356 } break;
1357
1358 case GET_MASTER_MONO: {
1359 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1360 bool mono;
1361 status_t status = getMasterMono(&mono);
1362 reply->writeInt32(status);
1363 if (status == NO_ERROR) {
1364 reply->writeInt32(static_cast<int32_t>(mono));
1365 }
1366 return NO_ERROR;
1367 } break;
1368
Eric Laurentc2f1f072009-07-17 12:17:14 -07001369 default:
1370 return BBinder::onTransact(code, data, reply, flags);
1371 }
1372}
1373
1374// ----------------------------------------------------------------------------
1375
Glenn Kasten40bc9062015-03-20 09:09:33 -07001376} // namespace android