blob: 294b8f6bf847d092cd80f55e45a87a7e42b02989 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25
Eric Laurent74adca92014-11-05 12:15:36 -080026#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070027#include <media/IAudioPolicyService.h>
28
Dima Zavin64760242011-05-11 14:15:23 -070029#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070030
Eric Laurentc2f1f072009-07-17 12:17:14 -070031namespace android {
32
33enum {
34 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
35 GET_DEVICE_CONNECTION_STATE,
36 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080037 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 SET_FORCE_USE,
39 GET_FORCE_USE,
40 GET_OUTPUT,
41 START_OUTPUT,
42 STOP_OUTPUT,
43 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080044 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070045 START_INPUT,
46 STOP_INPUT,
47 RELEASE_INPUT,
48 INIT_STREAM_VOLUME,
49 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070050 GET_STREAM_VOLUME,
51 GET_STRATEGY_FOR_STREAM,
52 GET_OUTPUT_FOR_EFFECT,
53 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080054 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080055 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070056 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080057 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070058 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080059 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000060 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070061 IS_OFFLOAD_SUPPORTED,
62 LIST_AUDIO_PORTS,
63 GET_AUDIO_PORT,
64 CREATE_AUDIO_PATCH,
65 RELEASE_AUDIO_PATCH,
66 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070067 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070068 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070069 GET_OUTPUT_FOR_ATTR,
70 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070071 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080072 GET_PHONE_STATE,
73 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070074 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070075 STOP_AUDIO_SOURCE,
76 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080077 SET_MASTER_MONO,
78 GET_MASTER_MONO,
Eric Laurentc2f1f072009-07-17 12:17:14 -070079};
80
Eric Laurent1d670b12015-02-06 10:44:24 -080081#define MAX_ITEMS_PER_LIST 1024
82
Eric Laurentc2f1f072009-07-17 12:17:14 -070083class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
84{
85public:
86 BpAudioPolicyService(const sp<IBinder>& impl)
87 : BpInterface<IAudioPolicyService>(impl)
88 {
89 }
90
91 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070092 audio_devices_t device,
93 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080094 const char *device_address,
95 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070096 {
97 Parcel data, reply;
98 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
99 data.writeInt32(static_cast <uint32_t>(device));
100 data.writeInt32(static_cast <uint32_t>(state));
101 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800102 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700103 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
104 return static_cast <status_t> (reply.readInt32());
105 }
106
Dima Zavinfce7a472011-04-19 22:30:36 -0700107 virtual audio_policy_dev_state_t getDeviceConnectionState(
108 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109 const char *device_address)
110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
113 data.writeInt32(static_cast <uint32_t>(device));
114 data.writeCString(device_address);
115 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700116 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 }
118
Glenn Kastenf78aee72012-01-04 11:00:47 -0800119 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700120 {
121 Parcel data, reply;
122 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
123 data.writeInt32(state);
124 remote()->transact(SET_PHONE_STATE, data, &reply);
125 return static_cast <status_t> (reply.readInt32());
126 }
127
Dima Zavinfce7a472011-04-19 22:30:36 -0700128 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 {
130 Parcel data, reply;
131 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
132 data.writeInt32(static_cast <uint32_t>(usage));
133 data.writeInt32(static_cast <uint32_t>(config));
134 remote()->transact(SET_FORCE_USE, data, &reply);
135 return static_cast <status_t> (reply.readInt32());
136 }
137
Dima Zavinfce7a472011-04-19 22:30:36 -0700138 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700139 {
140 Parcel data, reply;
141 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
142 data.writeInt32(static_cast <uint32_t>(usage));
143 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700144 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 }
146
147 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700148 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800150 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700151 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000152 audio_output_flags_t flags,
153 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
157 data.writeInt32(static_cast <uint32_t>(stream));
158 data.writeInt32(samplingRate);
159 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700160 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700161 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800162 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100163 if (offloadInfo == NULL) {
164 data.writeInt32(0);
165 } else {
166 data.writeInt32(1);
167 data.write(offloadInfo, sizeof(audio_offload_info_t));
168 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700169 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700170 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700171 }
172
Eric Laurente83b55d2014-11-14 10:06:21 -0800173 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
174 audio_io_handle_t *output,
175 audio_session_t session,
176 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700177 uid_t uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800178 uint32_t samplingRate,
179 audio_format_t format,
180 audio_channel_mask_t channelMask,
181 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700182 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800183 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
187 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800188 if (stream == NULL) {
189 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
190 return BAD_VALUE;
191 }
192 if (*stream == AUDIO_STREAM_DEFAULT) {
193 ALOGE("getOutputForAttr unspecified stream type");
194 return BAD_VALUE;
195 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700196 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 if (output == NULL) {
198 ALOGE("getOutputForAttr NULL output - shouldn't happen");
199 return BAD_VALUE;
200 }
201 if (attr == NULL) {
202 data.writeInt32(0);
203 } else {
204 data.writeInt32(1);
205 data.write(attr, sizeof(audio_attributes_t));
206 }
207 data.writeInt32(session);
208 if (stream == NULL) {
209 data.writeInt32(0);
210 } else {
211 data.writeInt32(1);
212 data.writeInt32(*stream);
213 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700214 data.writeInt32(uid);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700215 data.writeInt32(samplingRate);
216 data.writeInt32(static_cast <uint32_t>(format));
217 data.writeInt32(channelMask);
218 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700219 data.writeInt32(selectedDeviceId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700220 // hasOffloadInfo
221 if (offloadInfo == NULL) {
222 data.writeInt32(0);
223 } else {
224 data.writeInt32(1);
225 data.write(offloadInfo, sizeof(audio_offload_info_t));
226 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800227 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
228 if (status != NO_ERROR) {
229 return status;
230 }
231 status = (status_t)reply.readInt32();
232 if (status != NO_ERROR) {
233 return status;
234 }
235 *output = (audio_io_handle_t)reply.readInt32();
236 if (stream != NULL) {
237 *stream = (audio_stream_type_t)reply.readInt32();
238 }
239 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700240 }
241
Eric Laurentde070132010-07-13 04:45:46 -0700242 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700243 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800244 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700248 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800249 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800250 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700251 remote()->transact(START_OUTPUT, data, &reply);
252 return static_cast <status_t> (reply.readInt32());
253 }
254
Eric Laurentde070132010-07-13 04:45:46 -0700255 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700256 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800257 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700261 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800262 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800263 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 remote()->transact(STOP_OUTPUT, data, &reply);
265 return static_cast <status_t> (reply.readInt32());
266 }
267
Eric Laurente83b55d2014-11-14 10:06:21 -0800268 virtual void releaseOutput(audio_io_handle_t output,
269 audio_stream_type_t stream,
270 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700274 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800275 data.writeInt32((int32_t)stream);
276 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 remote()->transact(RELEASE_OUTPUT, data, &reply);
278 }
279
Eric Laurentcaf7f482014-11-25 17:50:47 -0800280 virtual status_t getInputForAttr(const audio_attributes_t *attr,
281 audio_io_handle_t *input,
282 audio_session_t session,
Eric 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
707 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
708 {
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));
Kevin Rocardab4d9f82017-11-13 11:15:27 -0800896 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -0800897 }
898 audio_session_t session = (audio_session_t)data.readInt32();
899 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
900 bool hasStream = data.readInt32() != 0;
901 if (hasStream) {
902 stream = (audio_stream_type_t)data.readInt32();
903 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700904 uid_t uid = (uid_t)data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700905 uint32_t samplingRate = data.readInt32();
906 audio_format_t format = (audio_format_t) data.readInt32();
907 audio_channel_mask_t channelMask = data.readInt32();
908 audio_output_flags_t flags =
909 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700910 audio_port_handle_t selectedDeviceId = data.readInt32();
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700911 bool hasOffloadInfo = data.readInt32() != 0;
912 audio_offload_info_t offloadInfo;
913 if (hasOffloadInfo) {
914 data.read(&offloadInfo, sizeof(audio_offload_info_t));
915 }
Robert Shiha946d842015-09-02 16:46:59 -0700916 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800917 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700918 &output, session, &stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800919 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700920 flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurente83b55d2014-11-14 10:06:21 -0800921 reply->writeInt32(status);
922 reply->writeInt32(output);
923 reply->writeInt32(stream);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700924 return NO_ERROR;
925 } break;
926
Eric Laurentc2f1f072009-07-17 12:17:14 -0700927 case START_OUTPUT: {
928 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700929 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800930 audio_stream_type_t stream =
931 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800932 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700933 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800934 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700935 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 return NO_ERROR;
937 } break;
938
939 case STOP_OUTPUT: {
940 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700941 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800942 audio_stream_type_t stream =
943 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800944 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700945 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800946 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700947 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700948 return NO_ERROR;
949 } break;
950
951 case RELEASE_OUTPUT: {
952 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700953 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800954 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
955 audio_session_t session = (audio_session_t)data.readInt32();
956 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700957 return NO_ERROR;
958 } break;
959
Eric Laurentcaf7f482014-11-25 17:50:47 -0800960 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700961 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800962 audio_attributes_t attr;
963 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocardab4d9f82017-11-13 11:15:27 -0800964 sanetizeAudioAttributes(&attr);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800965 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700966 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700967 uid_t uid = (uid_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700968 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800969 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700970 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastenb3b16602014-07-16 08:36:31 -0700971 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -0600972 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -0700973 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700974 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800975 samplingRate, format, channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600976 flags, selectedDeviceId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800977 reply->writeInt32(status);
978 if (status == NO_ERROR) {
979 reply->writeInt32(input);
980 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700981 return NO_ERROR;
982 } break;
983
984 case START_INPUT: {
985 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700986 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700987 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
988 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700989 return NO_ERROR;
990 } break;
991
992 case STOP_INPUT: {
993 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700994 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -0700995 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
996 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700997 return NO_ERROR;
998 } break;
999
1000 case RELEASE_INPUT: {
1001 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001002 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001003 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1004 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001005 return NO_ERROR;
1006 } break;
1007
1008 case INIT_STREAM_VOLUME: {
1009 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001010 audio_stream_type_t stream =
1011 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001012 int indexMin = data.readInt32();
1013 int indexMax = data.readInt32();
1014 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1015 return NO_ERROR;
1016 } break;
1017
1018 case SET_STREAM_VOLUME: {
1019 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001020 audio_stream_type_t stream =
1021 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001022 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001023 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1024 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1025 index,
1026 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001027 return NO_ERROR;
1028 } break;
1029
1030 case GET_STREAM_VOLUME: {
1031 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001032 audio_stream_type_t stream =
1033 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001034 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001035 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001036 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001037 reply->writeInt32(index);
1038 reply->writeInt32(static_cast <uint32_t>(status));
1039 return NO_ERROR;
1040 } break;
1041
Eric Laurentde070132010-07-13 04:45:46 -07001042 case GET_STRATEGY_FOR_STREAM: {
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 Laurentde070132010-07-13 04:45:46 -07001046 reply->writeInt32(getStrategyForStream(stream));
1047 return NO_ERROR;
1048 } break;
1049
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001050 case GET_DEVICES_FOR_STREAM: {
1051 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001052 audio_stream_type_t stream =
1053 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001054 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1055 return NO_ERROR;
1056 } break;
1057
Eric Laurentde070132010-07-13 04:45:46 -07001058 case GET_OUTPUT_FOR_EFFECT: {
1059 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1060 effect_descriptor_t desc;
1061 data.read(&desc, sizeof(effect_descriptor_t));
1062 audio_io_handle_t output = getOutputForEffect(&desc);
1063 reply->writeInt32(static_cast <int>(output));
1064 return NO_ERROR;
1065 } break;
1066
1067 case REGISTER_EFFECT: {
1068 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1069 effect_descriptor_t desc;
1070 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001071 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001072 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001073 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001074 int id = data.readInt32();
1075 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001076 io,
Eric Laurentde070132010-07-13 04:45:46 -07001077 strategy,
1078 session,
1079 id)));
1080 return NO_ERROR;
1081 } break;
1082
1083 case UNREGISTER_EFFECT: {
1084 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1085 int id = data.readInt32();
1086 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1087 return NO_ERROR;
1088 } break;
1089
Eric Laurentdb7c0792011-08-10 10:37:50 -07001090 case SET_EFFECT_ENABLED: {
1091 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1092 int id = data.readInt32();
1093 bool enabled = static_cast <bool>(data.readInt32());
1094 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1095 return NO_ERROR;
1096 } break;
1097
Eric Laurenteda6c362011-02-02 09:33:30 -08001098 case IS_STREAM_ACTIVE: {
1099 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001100 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001101 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001102 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001103 return NO_ERROR;
1104 } break;
1105
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001106 case IS_STREAM_ACTIVE_REMOTELY: {
1107 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1108 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1109 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001110 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001111 return NO_ERROR;
1112 } break;
1113
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001114 case IS_SOURCE_ACTIVE: {
1115 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1116 audio_source_t source = (audio_source_t) data.readInt32();
1117 reply->writeInt32( isSourceActive(source));
1118 return NO_ERROR;
1119 }
1120
Eric Laurent57dae992011-07-24 13:36:09 -07001121 case QUERY_DEFAULT_PRE_PROCESSING: {
1122 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001123 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001124 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001125 if (count > AudioEffect::kMaxPreProcessing) {
1126 count = AudioEffect::kMaxPreProcessing;
1127 }
Eric Laurent57dae992011-07-24 13:36:09 -07001128 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001129 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001130 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1131 reply->writeInt32(status);
1132 if (status != NO_ERROR && status != NO_MEMORY) {
1133 retCount = 0;
1134 }
1135 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001136 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001137 if (retCount < count) {
1138 count = retCount;
1139 }
1140 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1141 }
1142 delete[] descriptors;
1143 return status;
1144 }
1145
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001146 case IS_OFFLOAD_SUPPORTED: {
1147 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1148 audio_offload_info_t info;
1149 data.read(&info, sizeof(audio_offload_info_t));
1150 bool isSupported = isOffloadSupported(info);
1151 reply->writeInt32(isSupported);
1152 return NO_ERROR;
1153 }
1154
Eric Laurent203b1a12014-04-01 10:34:16 -07001155 case LIST_AUDIO_PORTS: {
1156 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1157 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1158 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1159 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001160 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1161 numPortsReq = MAX_ITEMS_PER_LIST;
1162 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001163 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001164 struct audio_port *ports =
1165 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001166 if (ports == NULL) {
1167 reply->writeInt32(NO_MEMORY);
1168 reply->writeInt32(0);
1169 return NO_ERROR;
1170 }
1171 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001172 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1173 reply->writeInt32(status);
1174 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001175
1176 if (status == NO_ERROR) {
1177 if (numPortsReq > numPorts) {
1178 numPortsReq = numPorts;
1179 }
1180 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1181 reply->writeInt32(generation);
1182 }
1183 free(ports);
1184 return NO_ERROR;
1185 }
1186
1187 case GET_AUDIO_PORT: {
1188 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001189 struct audio_port port = {};
1190 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1191 ALOGE("b/23912202");
1192 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001193 status_t status = getAudioPort(&port);
1194 reply->writeInt32(status);
1195 if (status == NO_ERROR) {
1196 reply->write(&port, sizeof(struct audio_port));
1197 }
1198 return NO_ERROR;
1199 }
1200
1201 case CREATE_AUDIO_PATCH: {
1202 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1203 struct audio_patch patch;
1204 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001205 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001206 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1207 ALOGE("b/23912202");
1208 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001209 status_t status = createAudioPatch(&patch, &handle);
1210 reply->writeInt32(status);
1211 if (status == NO_ERROR) {
1212 reply->write(&handle, sizeof(audio_patch_handle_t));
1213 }
1214 return NO_ERROR;
1215 }
1216
1217 case RELEASE_AUDIO_PATCH: {
1218 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1219 audio_patch_handle_t handle;
1220 data.read(&handle, sizeof(audio_patch_handle_t));
1221 status_t status = releaseAudioPatch(handle);
1222 reply->writeInt32(status);
1223 return NO_ERROR;
1224 }
1225
1226 case LIST_AUDIO_PATCHES: {
1227 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1228 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001229 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1230 numPatchesReq = MAX_ITEMS_PER_LIST;
1231 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001232 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001233 struct audio_patch *patches =
1234 (struct audio_patch *)calloc(numPatchesReq,
1235 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001236 if (patches == NULL) {
1237 reply->writeInt32(NO_MEMORY);
1238 reply->writeInt32(0);
1239 return NO_ERROR;
1240 }
1241 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001242 status_t status = listAudioPatches(&numPatches, patches, &generation);
1243 reply->writeInt32(status);
1244 reply->writeInt32(numPatches);
1245 if (status == NO_ERROR) {
1246 if (numPatchesReq > numPatches) {
1247 numPatchesReq = numPatches;
1248 }
1249 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1250 reply->writeInt32(generation);
1251 }
1252 free(patches);
1253 return NO_ERROR;
1254 }
1255
1256 case SET_AUDIO_PORT_CONFIG: {
1257 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1258 struct audio_port_config config;
1259 data.read(&config, sizeof(struct audio_port_config));
1260 status_t status = setAudioPortConfig(&config);
1261 reply->writeInt32(status);
1262 return NO_ERROR;
1263 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001264
Eric Laurentb52c1522014-05-20 11:27:36 -07001265 case REGISTER_CLIENT: {
1266 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1267 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1268 data.readStrongBinder());
1269 registerClient(client);
1270 return NO_ERROR;
1271 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001272
Eric Laurente8726fe2015-06-26 09:39:24 -07001273 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1274 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1275 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1276 return NO_ERROR;
1277 } break;
1278
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001279 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1280 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1281 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1282 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001283 audio_session_t session = AUDIO_SESSION_NONE;
1284 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1285 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001286 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1287 reply->writeInt32(status);
1288 if (status == NO_ERROR) {
1289 reply->writeInt32(session);
1290 reply->writeInt32(ioHandle);
1291 reply->writeInt32(device);
1292 }
1293 return NO_ERROR;
1294 } break;
1295
1296 case RELEASE_SOUNDTRIGGER_SESSION: {
1297 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1298 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1299 data.readStrongBinder());
1300 audio_session_t session = (audio_session_t)data.readInt32();
1301 status_t status = releaseSoundTriggerSession(session);
1302 reply->writeInt32(status);
1303 return NO_ERROR;
1304 } break;
1305
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001306 case GET_PHONE_STATE: {
1307 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1308 reply->writeInt32((int32_t)getPhoneState());
1309 return NO_ERROR;
1310 } break;
1311
Eric Laurentbaac1832014-12-01 17:52:59 -08001312 case REGISTER_POLICY_MIXES: {
1313 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1314 bool registration = data.readInt32() == 1;
1315 Vector<AudioMix> mixes;
1316 size_t size = (size_t)data.readInt32();
1317 if (size > MAX_MIXES_PER_POLICY) {
1318 size = MAX_MIXES_PER_POLICY;
1319 }
1320 for (size_t i = 0; i < size; i++) {
1321 AudioMix mix;
1322 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1323 mixes.add(mix);
1324 }
1325 }
1326 status_t status = registerPolicyMixes(mixes, registration);
1327 reply->writeInt32(status);
1328 return NO_ERROR;
1329 } break;
1330
Eric Laurent554a2772015-04-10 11:29:24 -07001331 case START_AUDIO_SOURCE: {
1332 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1333 struct audio_port_config source;
1334 data.read(&source, sizeof(struct audio_port_config));
1335 audio_attributes_t attributes;
1336 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocardab4d9f82017-11-13 11:15:27 -08001337 sanetizeAudioAttributes(&attributes);
Wei Jiae995e472015-09-09 09:48:34 -07001338 audio_io_handle_t handle = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001339 status_t status = startAudioSource(&source, &attributes, &handle);
1340 reply->writeInt32(status);
1341 reply->writeInt32(handle);
1342 return NO_ERROR;
1343 } break;
1344
1345 case STOP_AUDIO_SOURCE: {
1346 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1347 audio_io_handle_t handle = (audio_io_handle_t)data.readInt32();
1348 status_t status = stopAudioSource(handle);
1349 reply->writeInt32(status);
1350 return NO_ERROR;
1351 } break;
1352
Andy Hung2ddee192015-12-18 17:34:44 -08001353 case SET_MASTER_MONO: {
1354 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1355 bool mono = static_cast<bool>(data.readInt32());
1356 status_t status = setMasterMono(mono);
1357 reply->writeInt32(status);
1358 return NO_ERROR;
1359 } break;
1360
1361 case GET_MASTER_MONO: {
1362 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1363 bool mono;
1364 status_t status = getMasterMono(&mono);
1365 reply->writeInt32(status);
1366 if (status == NO_ERROR) {
1367 reply->writeInt32(static_cast<int32_t>(mono));
1368 }
1369 return NO_ERROR;
1370 } break;
1371
Eric Laurentc2f1f072009-07-17 12:17:14 -07001372 default:
1373 return BBinder::onTransact(code, data, reply, flags);
1374 }
1375}
1376
Kevin Rocardab4d9f82017-11-13 11:15:27 -08001377void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1378{
1379 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1380 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1381 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1382 }
1383 attr->tags[tagsMaxSize - 1] = '\0';
1384}
1385
Eric Laurentc2f1f072009-07-17 12:17:14 -07001386// ----------------------------------------------------------------------------
1387
Glenn Kasten40bc9062015-03-20 09:09:33 -07001388} // namespace android