blob: d838975fba3556fa5741d9af8c40564dc4186839 [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>
Eric Laurentac9cef52017-06-09 15:46:26 -070022#include <math.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <sys/types.h>
24
25#include <binder/Parcel.h>
26
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
29
Dima Zavin64760242011-05-11 14:15:23 -070030#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070031
Eric Laurentc2f1f072009-07-17 12:17:14 -070032namespace android {
33
34enum {
35 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
36 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080037 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080039 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070040 SET_FORCE_USE,
41 GET_FORCE_USE,
42 GET_OUTPUT,
43 START_OUTPUT,
44 STOP_OUTPUT,
45 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080046 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070047 START_INPUT,
48 STOP_INPUT,
49 RELEASE_INPUT,
50 INIT_STREAM_VOLUME,
51 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070052 GET_STREAM_VOLUME,
53 GET_STRATEGY_FOR_STREAM,
54 GET_OUTPUT_FOR_EFFECT,
55 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080056 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080057 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070058 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080059 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070060 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080061 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000062 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070063 IS_OFFLOAD_SUPPORTED,
64 LIST_AUDIO_PORTS,
65 GET_AUDIO_PORT,
66 CREATE_AUDIO_PATCH,
67 RELEASE_AUDIO_PATCH,
68 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070069 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070070 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070071 GET_OUTPUT_FOR_ATTR,
72 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070073 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080074 GET_PHONE_STATE,
75 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070076 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070077 STOP_AUDIO_SOURCE,
78 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080079 SET_MASTER_MONO,
80 GET_MASTER_MONO,
Eric Laurentac9cef52017-06-09 15:46:26 -070081 GET_STREAM_VOLUME_DB
Eric Laurentc2f1f072009-07-17 12:17:14 -070082};
83
Eric Laurent1d670b12015-02-06 10:44:24 -080084#define MAX_ITEMS_PER_LIST 1024
85
Eric Laurentc2f1f072009-07-17 12:17:14 -070086class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
87{
88public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070089 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -070090 : BpInterface<IAudioPolicyService>(impl)
91 {
92 }
93
94 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -070095 audio_devices_t device,
96 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080097 const char *device_address,
98 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -070099 {
100 Parcel data, reply;
101 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
102 data.writeInt32(static_cast <uint32_t>(device));
103 data.writeInt32(static_cast <uint32_t>(state));
104 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800105 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700106 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
107 return static_cast <status_t> (reply.readInt32());
108 }
109
Dima Zavinfce7a472011-04-19 22:30:36 -0700110 virtual audio_policy_dev_state_t getDeviceConnectionState(
111 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 const char *device_address)
113 {
114 Parcel data, reply;
115 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
116 data.writeInt32(static_cast <uint32_t>(device));
117 data.writeCString(device_address);
118 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700119 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700120 }
121
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800122 virtual status_t handleDeviceConfigChange(audio_devices_t device,
123 const char *device_address,
124 const char *device_name)
125 {
126 Parcel data, reply;
127 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
128 data.writeInt32(static_cast <uint32_t>(device));
129 data.writeCString(device_address);
130 data.writeCString(device_name);
131 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
132 return static_cast <status_t> (reply.readInt32());
133 }
134
Glenn Kastenf78aee72012-01-04 11:00:47 -0800135 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700136 {
137 Parcel data, reply;
138 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
139 data.writeInt32(state);
140 remote()->transact(SET_PHONE_STATE, data, &reply);
141 return static_cast <status_t> (reply.readInt32());
142 }
143
Dima Zavinfce7a472011-04-19 22:30:36 -0700144 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 {
146 Parcel data, reply;
147 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
148 data.writeInt32(static_cast <uint32_t>(usage));
149 data.writeInt32(static_cast <uint32_t>(config));
150 remote()->transact(SET_FORCE_USE, data, &reply);
151 return static_cast <status_t> (reply.readInt32());
152 }
153
Dima Zavinfce7a472011-04-19 22:30:36 -0700154 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700155 {
156 Parcel data, reply;
157 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
158 data.writeInt32(static_cast <uint32_t>(usage));
159 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700160 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700161 }
162
163 virtual audio_io_handle_t getOutput(
Dima Zavinfce7a472011-04-19 22:30:36 -0700164 audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700165 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800166 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700167 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000168 audio_output_flags_t flags,
169 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700170 {
171 Parcel data, reply;
172 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
173 data.writeInt32(static_cast <uint32_t>(stream));
174 data.writeInt32(samplingRate);
175 data.writeInt32(static_cast <uint32_t>(format));
Glenn Kasten254af182012-07-03 14:59:05 -0700176 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700177 data.writeInt32(static_cast <uint32_t>(flags));
Glenn Kasten2301acc2014-01-17 10:21:00 -0800178 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100179 if (offloadInfo == NULL) {
180 data.writeInt32(0);
181 } else {
182 data.writeInt32(1);
183 data.write(offloadInfo, sizeof(audio_offload_info_t));
184 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700185 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700186 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700187 }
188
Eric Laurente83b55d2014-11-14 10:06:21 -0800189 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
190 audio_io_handle_t *output,
191 audio_session_t session,
192 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700193 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800194 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800195 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700196 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800197 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700198 {
199 Parcel data, reply;
200 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
201 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800202 if (stream == NULL) {
203 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
204 return BAD_VALUE;
205 }
206 if (*stream == AUDIO_STREAM_DEFAULT) {
207 ALOGE("getOutputForAttr unspecified stream type");
208 return BAD_VALUE;
209 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700210 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800211 if (output == NULL) {
212 ALOGE("getOutputForAttr NULL output - shouldn't happen");
213 return BAD_VALUE;
214 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700215 if (selectedDeviceId == NULL) {
216 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
217 return BAD_VALUE;
218 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800219 if (portId == NULL) {
220 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
221 return BAD_VALUE;
222 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800223 if (attr == NULL) {
224 data.writeInt32(0);
225 } else {
226 data.writeInt32(1);
227 data.write(attr, sizeof(audio_attributes_t));
228 }
229 data.writeInt32(session);
230 if (stream == NULL) {
231 data.writeInt32(0);
232 } else {
233 data.writeInt32(1);
234 data.writeInt32(*stream);
235 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700236 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800237 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700238 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700239 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800240 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800241 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
242 if (status != NO_ERROR) {
243 return status;
244 }
245 status = (status_t)reply.readInt32();
246 if (status != NO_ERROR) {
247 return status;
248 }
249 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800252 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800253 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700254 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800255 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800256 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700257 }
258
Eric Laurentde070132010-07-13 04:45:46 -0700259 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700260 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800261 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700265 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800266 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800267 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 remote()->transact(START_OUTPUT, data, &reply);
269 return static_cast <status_t> (reply.readInt32());
270 }
271
Eric Laurentde070132010-07-13 04:45:46 -0700272 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700273 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800274 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700278 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800279 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800280 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700281 remote()->transact(STOP_OUTPUT, data, &reply);
282 return static_cast <status_t> (reply.readInt32());
283 }
284
Eric Laurente83b55d2014-11-14 10:06:21 -0800285 virtual void releaseOutput(audio_io_handle_t output,
286 audio_stream_type_t stream,
287 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700288 {
289 Parcel data, reply;
290 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700291 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800292 data.writeInt32((int32_t)stream);
293 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700294 remote()->transact(RELEASE_OUTPUT, data, &reply);
295 }
296
Eric Laurentcaf7f482014-11-25 17:50:47 -0800297 virtual status_t getInputForAttr(const audio_attributes_t *attr,
298 audio_io_handle_t *input,
299 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700300 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700301 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800302 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600303 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700304 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800305 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800309 if (attr == NULL) {
310 ALOGE("getInputForAttr NULL attr - shouldn't happen");
311 return BAD_VALUE;
312 }
313 if (input == NULL) {
314 ALOGE("getInputForAttr NULL input - shouldn't happen");
315 return BAD_VALUE;
316 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700317 if (selectedDeviceId == NULL) {
318 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
319 return BAD_VALUE;
320 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800321 if (portId == NULL) {
322 ALOGE("getInputForAttr NULL portId - shouldn't happen");
323 return BAD_VALUE;
324 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800325 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700326 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800327 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700328 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700329 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800330 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700331 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700332 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800333 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800334 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
335 if (status != NO_ERROR) {
336 return status;
337 }
338 status = reply.readInt32();
339 if (status != NO_ERROR) {
340 return status;
341 }
342 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700343 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800344 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800345 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 }
347
Eric Laurent4dc68062014-07-28 17:26:49 -0700348 virtual status_t startInput(audio_io_handle_t input,
349 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 {
351 Parcel data, reply;
352 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700353 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700354 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355 remote()->transact(START_INPUT, data, &reply);
356 return static_cast <status_t> (reply.readInt32());
357 }
358
Eric Laurent4dc68062014-07-28 17:26:49 -0700359 virtual status_t stopInput(audio_io_handle_t input,
360 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700364 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700365 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700366 remote()->transact(STOP_INPUT, data, &reply);
367 return static_cast <status_t> (reply.readInt32());
368 }
369
Eric Laurent4dc68062014-07-28 17:26:49 -0700370 virtual void releaseInput(audio_io_handle_t input,
371 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700375 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700376 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700377 remote()->transact(RELEASE_INPUT, data, &reply);
378 }
379
Dima Zavinfce7a472011-04-19 22:30:36 -0700380 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 int indexMin,
382 int indexMax)
383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
386 data.writeInt32(static_cast <uint32_t>(stream));
387 data.writeInt32(indexMin);
388 data.writeInt32(indexMax);
389 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
390 return static_cast <status_t> (reply.readInt32());
391 }
392
Eric Laurent83844cc2011-11-18 16:43:31 -0800393 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
394 int index,
395 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
399 data.writeInt32(static_cast <uint32_t>(stream));
400 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800401 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 remote()->transact(SET_STREAM_VOLUME, data, &reply);
403 return static_cast <status_t> (reply.readInt32());
404 }
405
Eric Laurent83844cc2011-11-18 16:43:31 -0800406 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
407 int *index,
408 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
412 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800413 data.writeInt32(static_cast <uint32_t>(device));
414
Eric Laurentc2f1f072009-07-17 12:17:14 -0700415 remote()->transact(GET_STREAM_VOLUME, data, &reply);
416 int lIndex = reply.readInt32();
417 if (index) *index = lIndex;
418 return static_cast <status_t> (reply.readInt32());
419 }
Eric Laurentde070132010-07-13 04:45:46 -0700420
Dima Zavinfce7a472011-04-19 22:30:36 -0700421 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700422 {
423 Parcel data, reply;
424 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
425 data.writeInt32(static_cast <uint32_t>(stream));
426 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
427 return reply.readInt32();
428 }
429
Eric Laurent63742522012-03-08 13:42:42 -0800430 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800431 {
432 Parcel data, reply;
433 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
434 data.writeInt32(static_cast <uint32_t>(stream));
435 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800436 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800437 }
438
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700439 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.write(desc, sizeof(effect_descriptor_t));
444 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
445 return static_cast <audio_io_handle_t> (reply.readInt32());
446 }
447
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700448 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700449 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700450 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800451 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700452 int id)
453 {
454 Parcel data, reply;
455 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
456 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700457 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700458 data.writeInt32(strategy);
459 data.writeInt32(session);
460 data.writeInt32(id);
461 remote()->transact(REGISTER_EFFECT, data, &reply);
462 return static_cast <status_t> (reply.readInt32());
463 }
464
465 virtual status_t unregisterEffect(int id)
466 {
467 Parcel data, reply;
468 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
469 data.writeInt32(id);
470 remote()->transact(UNREGISTER_EFFECT, data, &reply);
471 return static_cast <status_t> (reply.readInt32());
472 }
473
Eric Laurentdb7c0792011-08-10 10:37:50 -0700474 virtual status_t setEffectEnabled(int id, bool enabled)
475 {
476 Parcel data, reply;
477 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
478 data.writeInt32(id);
479 data.writeInt32(enabled);
480 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
481 return static_cast <status_t> (reply.readInt32());
482 }
483
Glenn Kastenfff6d712012-01-12 16:38:12 -0800484 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800485 {
486 Parcel data, reply;
487 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800488 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800489 data.writeInt32(inPastMs);
490 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
491 return reply.readInt32();
492 }
Eric Laurent57dae992011-07-24 13:36:09 -0700493
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800494 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
495 {
496 Parcel data, reply;
497 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
498 data.writeInt32((int32_t) stream);
499 data.writeInt32(inPastMs);
500 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
501 return reply.readInt32();
502 }
503
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700504 virtual bool isSourceActive(audio_source_t source) const
505 {
506 Parcel data, reply;
507 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
508 data.writeInt32((int32_t) source);
509 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
510 return reply.readInt32();
511 }
512
Glenn Kastend848eb42016-03-08 13:42:11 -0800513 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700514 effect_descriptor_t *descriptors,
515 uint32_t *count)
516 {
517 if (descriptors == NULL || count == NULL) {
518 return BAD_VALUE;
519 }
520 Parcel data, reply;
521 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
522 data.writeInt32(audioSession);
523 data.writeInt32(*count);
524 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
525 if (status != NO_ERROR) {
526 return status;
527 }
528 status = static_cast <status_t> (reply.readInt32());
529 uint32_t retCount = reply.readInt32();
530 if (retCount != 0) {
531 uint32_t numDesc = (retCount < *count) ? retCount : *count;
532 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
533 }
534 *count = retCount;
535 return status;
536 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000537
538 virtual bool isOffloadSupported(const audio_offload_info_t& info)
539 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100540 Parcel data, reply;
541 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
542 data.write(&info, sizeof(audio_offload_info_t));
543 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700544 return reply.readInt32();
545 }
546
547 virtual status_t listAudioPorts(audio_port_role_t role,
548 audio_port_type_t type,
549 unsigned int *num_ports,
550 struct audio_port *ports,
551 unsigned int *generation)
552 {
553 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
554 generation == NULL) {
555 return BAD_VALUE;
556 }
557 Parcel data, reply;
558 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
559 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
560 data.writeInt32(role);
561 data.writeInt32(type);
562 data.writeInt32(numPortsReq);
563 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
564 if (status == NO_ERROR) {
565 status = (status_t)reply.readInt32();
566 *num_ports = (unsigned int)reply.readInt32();
567 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700568 if (status == NO_ERROR) {
569 if (numPortsReq > *num_ports) {
570 numPortsReq = *num_ports;
571 }
572 if (numPortsReq > 0) {
573 reply.read(ports, numPortsReq * sizeof(struct audio_port));
574 }
575 *generation = reply.readInt32();
576 }
577 return status;
578 }
579
580 virtual status_t getAudioPort(struct audio_port *port)
581 {
582 if (port == NULL) {
583 return BAD_VALUE;
584 }
585 Parcel data, reply;
586 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
587 data.write(port, sizeof(struct audio_port));
588 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
589 if (status != NO_ERROR ||
590 (status = (status_t)reply.readInt32()) != NO_ERROR) {
591 return status;
592 }
593 reply.read(port, sizeof(struct audio_port));
594 return status;
595 }
596
597 virtual status_t createAudioPatch(const struct audio_patch *patch,
598 audio_patch_handle_t *handle)
599 {
600 if (patch == NULL || handle == NULL) {
601 return BAD_VALUE;
602 }
603 Parcel data, reply;
604 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
605 data.write(patch, sizeof(struct audio_patch));
606 data.write(handle, sizeof(audio_patch_handle_t));
607 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
608 if (status != NO_ERROR ||
609 (status = (status_t)reply.readInt32()) != NO_ERROR) {
610 return status;
611 }
612 reply.read(handle, sizeof(audio_patch_handle_t));
613 return status;
614 }
615
616 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
617 {
618 Parcel data, reply;
619 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
620 data.write(&handle, sizeof(audio_patch_handle_t));
621 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
622 if (status != NO_ERROR) {
623 status = (status_t)reply.readInt32();
624 }
625 return status;
626 }
627
628 virtual status_t listAudioPatches(unsigned int *num_patches,
629 struct audio_patch *patches,
630 unsigned int *generation)
631 {
632 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
633 generation == NULL) {
634 return BAD_VALUE;
635 }
636 Parcel data, reply;
637 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
638 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
639 data.writeInt32(numPatchesReq);
640 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
641 if (status == NO_ERROR) {
642 status = (status_t)reply.readInt32();
643 *num_patches = (unsigned int)reply.readInt32();
644 }
645 if (status == NO_ERROR) {
646 if (numPatchesReq > *num_patches) {
647 numPatchesReq = *num_patches;
648 }
649 if (numPatchesReq > 0) {
650 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
651 }
652 *generation = reply.readInt32();
653 }
654 return status;
655 }
656
657 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
658 {
659 if (config == NULL) {
660 return BAD_VALUE;
661 }
662 Parcel data, reply;
663 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
664 data.write(config, sizeof(struct audio_port_config));
665 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
666 if (status != NO_ERROR) {
667 status = (status_t)reply.readInt32();
668 }
669 return status;
670 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700671
Eric Laurentb52c1522014-05-20 11:27:36 -0700672 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
673 {
674 Parcel data, reply;
675 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800676 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700677 remote()->transact(REGISTER_CLIENT, data, &reply);
678 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700679
Eric Laurente8726fe2015-06-26 09:39:24 -0700680 virtual void setAudioPortCallbacksEnabled(bool enabled)
681 {
682 Parcel data, reply;
683 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
684 data.writeInt32(enabled ? 1 : 0);
685 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
686 }
687
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700688 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
689 audio_io_handle_t *ioHandle,
690 audio_devices_t *device)
691 {
692 if (session == NULL || ioHandle == NULL || device == NULL) {
693 return BAD_VALUE;
694 }
695 Parcel data, reply;
696 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
697 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
698 if (status != NO_ERROR) {
699 return status;
700 }
701 status = (status_t)reply.readInt32();
702 if (status == NO_ERROR) {
703 *session = (audio_session_t)reply.readInt32();
704 *ioHandle = (audio_io_handle_t)reply.readInt32();
705 *device = (audio_devices_t)reply.readInt32();
706 }
707 return status;
708 }
709
710 virtual status_t releaseSoundTriggerSession(audio_session_t session)
711 {
712 Parcel data, reply;
713 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
714 data.writeInt32(session);
715 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
716 if (status != NO_ERROR) {
717 return status;
718 }
719 return (status_t)reply.readInt32();
720 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700721
722 virtual audio_mode_t getPhoneState()
723 {
724 Parcel data, reply;
725 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
726 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
727 if (status != NO_ERROR) {
728 return AUDIO_MODE_INVALID;
729 }
730 return (audio_mode_t)reply.readInt32();
731 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800732
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700733 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800734 {
735 Parcel data, reply;
736 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
737 data.writeInt32(registration ? 1 : 0);
738 size_t size = mixes.size();
739 if (size > MAX_MIXES_PER_POLICY) {
740 size = MAX_MIXES_PER_POLICY;
741 }
742 size_t sizePosition = data.dataPosition();
743 data.writeInt32(size);
744 size_t finalSize = size;
745 for (size_t i = 0; i < size; i++) {
746 size_t position = data.dataPosition();
747 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
748 data.setDataPosition(position);
749 finalSize--;
750 }
751 }
752 if (size != finalSize) {
753 size_t position = data.dataPosition();
754 data.setDataPosition(sizePosition);
755 data.writeInt32(finalSize);
756 data.setDataPosition(position);
757 }
758 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
759 if (status == NO_ERROR) {
760 status = (status_t)reply.readInt32();
761 }
762 return status;
763 }
Eric Laurent554a2772015-04-10 11:29:24 -0700764
765 virtual status_t startAudioSource(const struct audio_port_config *source,
766 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700767 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700768 {
769 Parcel data, reply;
770 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
771 if (source == NULL || attributes == NULL || handle == NULL) {
772 return BAD_VALUE;
773 }
774 data.write(source, sizeof(struct audio_port_config));
775 data.write(attributes, sizeof(audio_attributes_t));
776 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
777 if (status != NO_ERROR) {
778 return status;
779 }
780 status = (status_t)reply.readInt32();
781 if (status != NO_ERROR) {
782 return status;
783 }
Glenn Kasten559d4392016-03-29 13:42:57 -0700784 *handle = (audio_patch_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700785 return status;
786 }
787
Glenn Kasten559d4392016-03-29 13:42:57 -0700788 virtual status_t stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700789 {
790 Parcel data, reply;
791 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
792 data.writeInt32(handle);
793 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
794 if (status != NO_ERROR) {
795 return status;
796 }
797 status = (status_t)reply.readInt32();
798 return status;
799 }
Andy Hung2ddee192015-12-18 17:34:44 -0800800
801 virtual status_t setMasterMono(bool mono)
802 {
803 Parcel data, reply;
804 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
805 data.writeInt32(static_cast<int32_t>(mono));
806 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
807 if (status != NO_ERROR) {
808 return status;
809 }
810 return static_cast<status_t>(reply.readInt32());
811 }
812
813 virtual status_t getMasterMono(bool *mono)
814 {
815 if (mono == nullptr) {
816 return BAD_VALUE;
817 }
818 Parcel data, reply;
819 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
820
821 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
822 if (status != NO_ERROR) {
823 return status;
824 }
825 status = static_cast<status_t>(reply.readInt32());
826 if (status == NO_ERROR) {
827 *mono = static_cast<bool>(reply.readInt32());
828 }
829 return status;
830 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700831
832 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
833 {
834 Parcel data, reply;
835 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
836 data.writeInt32(static_cast <int32_t>(stream));
837 data.writeInt32(static_cast <int32_t>(index));
838 data.writeUint32(static_cast <uint32_t>(device));
839 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
840 if (status != NO_ERROR) {
841 return NAN;
842 }
843 return reply.readFloat();
844 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845};
846
847IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
848
849// ----------------------------------------------------------------------
850
851
852status_t BnAudioPolicyService::onTransact(
853 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
854{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700855 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700856 case SET_DEVICE_CONNECTION_STATE: {
857 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700858 audio_devices_t device =
859 static_cast <audio_devices_t>(data.readInt32());
860 audio_policy_dev_state_t state =
861 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800863 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800864 if (device_address == nullptr || device_name == nullptr) {
865 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
866 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
867 } else {
868 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
869 state,
870 device_address,
871 device_name)));
872 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700873 return NO_ERROR;
874 } break;
875
876 case GET_DEVICE_CONNECTION_STATE: {
877 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700878 audio_devices_t device =
879 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700880 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800881 if (device_address == nullptr) {
882 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
883 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
884 } else {
885 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
886 device_address)));
887 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700888 return NO_ERROR;
889 } break;
890
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800891 case HANDLE_DEVICE_CONFIG_CHANGE: {
892 CHECK_INTERFACE(IAudioPolicyService, data, reply);
893 audio_devices_t device =
894 static_cast <audio_devices_t>(data.readInt32());
895 const char *device_address = data.readCString();
896 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800897 if (device_address == nullptr || device_name == nullptr) {
898 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
899 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
900 } else {
901 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
902 device_address,
903 device_name)));
904 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800905 return NO_ERROR;
906 } break;
907
Eric Laurentc2f1f072009-07-17 12:17:14 -0700908 case SET_PHONE_STATE: {
909 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700910 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
911 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700912 return NO_ERROR;
913 } break;
914
Eric Laurentc2f1f072009-07-17 12:17:14 -0700915 case SET_FORCE_USE: {
916 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700917 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
918 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700919 audio_policy_forced_cfg_t config =
920 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700921 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
922 return NO_ERROR;
923 } break;
924
925 case GET_FORCE_USE: {
926 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700927 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
928 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700929 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
930 return NO_ERROR;
931 } break;
932
933 case GET_OUTPUT: {
934 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700935 audio_stream_type_t stream =
936 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700937 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800938 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700939 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700940 audio_output_flags_t flags =
941 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100942 bool hasOffloadInfo = data.readInt32() != 0;
943 audio_offload_info_t offloadInfo;
944 if (hasOffloadInfo) {
945 data.read(&offloadInfo, sizeof(audio_offload_info_t));
946 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700947 audio_io_handle_t output = getOutput(stream,
948 samplingRate,
949 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700950 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100951 flags,
952 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700953 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700954 return NO_ERROR;
955 } break;
956
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700957 case GET_OUTPUT_FOR_ATTR: {
958 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800959 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800960 bool hasAttributes = data.readInt32() != 0;
961 if (hasAttributes) {
962 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -0800963 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -0800964 }
965 audio_session_t session = (audio_session_t)data.readInt32();
966 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
967 bool hasStream = data.readInt32() != 0;
968 if (hasStream) {
969 stream = (audio_stream_type_t)data.readInt32();
970 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700971 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800972 audio_config_t config;
973 memset(&config, 0, sizeof(audio_config_t));
974 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700975 audio_output_flags_t flags =
976 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700977 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800978 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -0700979 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800980 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700981 &output, session, &stream, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800982 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700983 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800984 reply->writeInt32(status);
985 reply->writeInt32(output);
986 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700987 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800988 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700989 return NO_ERROR;
990 } break;
991
Eric Laurentc2f1f072009-07-17 12:17:14 -0700992 case START_OUTPUT: {
993 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700994 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800995 audio_stream_type_t stream =
996 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800997 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700998 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800999 stream,
Eric Laurentde070132010-07-13 04:45:46 -07001000 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001001 return NO_ERROR;
1002 } break;
1003
1004 case STOP_OUTPUT: {
1005 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001006 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -08001007 audio_stream_type_t stream =
1008 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -08001009 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001010 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -08001011 stream,
Eric Laurentde070132010-07-13 04:45:46 -07001012 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001013 return NO_ERROR;
1014 } break;
1015
1016 case RELEASE_OUTPUT: {
1017 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001018 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -08001019 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
1020 audio_session_t session = (audio_session_t)data.readInt32();
1021 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001022 return NO_ERROR;
1023 } break;
1024
Eric Laurentcaf7f482014-11-25 17:50:47 -08001025 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001026 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001027 audio_attributes_t attr;
1028 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001029 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001030 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001031 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001032 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001033 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001034 audio_config_base_t config;
1035 memset(&config, 0, sizeof(audio_config_base_t));
1036 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001037 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001038 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001039 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001040 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001041 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001042 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001043 reply->writeInt32(status);
1044 if (status == NO_ERROR) {
1045 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001046 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001047 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001048 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001049 return NO_ERROR;
1050 } break;
1051
1052 case START_INPUT: {
1053 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001054 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001055 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1056 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001057 return NO_ERROR;
1058 } break;
1059
1060 case STOP_INPUT: {
1061 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001062 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001063 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1064 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 return NO_ERROR;
1066 } break;
1067
1068 case RELEASE_INPUT: {
1069 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001070 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001071 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1072 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001073 return NO_ERROR;
1074 } break;
1075
1076 case INIT_STREAM_VOLUME: {
1077 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001078 audio_stream_type_t stream =
1079 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001080 int indexMin = data.readInt32();
1081 int indexMax = data.readInt32();
1082 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1083 return NO_ERROR;
1084 } break;
1085
1086 case SET_STREAM_VOLUME: {
1087 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001088 audio_stream_type_t stream =
1089 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001090 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001091 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1092 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1093 index,
1094 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001095 return NO_ERROR;
1096 } break;
1097
1098 case GET_STREAM_VOLUME: {
1099 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001100 audio_stream_type_t stream =
1101 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001102 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001103 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001104 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001105 reply->writeInt32(index);
1106 reply->writeInt32(static_cast <uint32_t>(status));
1107 return NO_ERROR;
1108 } break;
1109
Eric Laurentde070132010-07-13 04:45:46 -07001110 case GET_STRATEGY_FOR_STREAM: {
1111 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001112 audio_stream_type_t stream =
1113 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001114 reply->writeInt32(getStrategyForStream(stream));
1115 return NO_ERROR;
1116 } break;
1117
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001118 case GET_DEVICES_FOR_STREAM: {
1119 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001120 audio_stream_type_t stream =
1121 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001122 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1123 return NO_ERROR;
1124 } break;
1125
Eric Laurentde070132010-07-13 04:45:46 -07001126 case GET_OUTPUT_FOR_EFFECT: {
1127 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1128 effect_descriptor_t desc;
1129 data.read(&desc, sizeof(effect_descriptor_t));
1130 audio_io_handle_t output = getOutputForEffect(&desc);
1131 reply->writeInt32(static_cast <int>(output));
1132 return NO_ERROR;
1133 } break;
1134
1135 case REGISTER_EFFECT: {
1136 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1137 effect_descriptor_t desc;
1138 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001139 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001140 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001141 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001142 int id = data.readInt32();
1143 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001144 io,
Eric Laurentde070132010-07-13 04:45:46 -07001145 strategy,
1146 session,
1147 id)));
1148 return NO_ERROR;
1149 } break;
1150
1151 case UNREGISTER_EFFECT: {
1152 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1153 int id = data.readInt32();
1154 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1155 return NO_ERROR;
1156 } break;
1157
Eric Laurentdb7c0792011-08-10 10:37:50 -07001158 case SET_EFFECT_ENABLED: {
1159 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1160 int id = data.readInt32();
1161 bool enabled = static_cast <bool>(data.readInt32());
1162 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1163 return NO_ERROR;
1164 } break;
1165
Eric Laurenteda6c362011-02-02 09:33:30 -08001166 case IS_STREAM_ACTIVE: {
1167 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001168 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001169 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001170 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001171 return NO_ERROR;
1172 } break;
1173
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001174 case IS_STREAM_ACTIVE_REMOTELY: {
1175 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1176 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1177 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001178 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001179 return NO_ERROR;
1180 } break;
1181
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001182 case IS_SOURCE_ACTIVE: {
1183 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1184 audio_source_t source = (audio_source_t) data.readInt32();
1185 reply->writeInt32( isSourceActive(source));
1186 return NO_ERROR;
1187 }
1188
Eric Laurent57dae992011-07-24 13:36:09 -07001189 case QUERY_DEFAULT_PRE_PROCESSING: {
1190 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001191 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001192 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001193 if (count > AudioEffect::kMaxPreProcessing) {
1194 count = AudioEffect::kMaxPreProcessing;
1195 }
Eric Laurent57dae992011-07-24 13:36:09 -07001196 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001197 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001198 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1199 reply->writeInt32(status);
1200 if (status != NO_ERROR && status != NO_MEMORY) {
1201 retCount = 0;
1202 }
1203 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001204 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001205 if (retCount < count) {
1206 count = retCount;
1207 }
1208 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1209 }
1210 delete[] descriptors;
1211 return status;
1212 }
1213
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001214 case IS_OFFLOAD_SUPPORTED: {
1215 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1216 audio_offload_info_t info;
1217 data.read(&info, sizeof(audio_offload_info_t));
1218 bool isSupported = isOffloadSupported(info);
1219 reply->writeInt32(isSupported);
1220 return NO_ERROR;
1221 }
1222
Eric Laurent203b1a12014-04-01 10:34:16 -07001223 case LIST_AUDIO_PORTS: {
1224 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1225 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1226 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1227 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001228 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1229 numPortsReq = MAX_ITEMS_PER_LIST;
1230 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001231 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001232 struct audio_port *ports =
1233 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001234 if (ports == 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 = listAudioPorts(role, type, &numPorts, ports, &generation);
1241 reply->writeInt32(status);
1242 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001243
1244 if (status == NO_ERROR) {
1245 if (numPortsReq > numPorts) {
1246 numPortsReq = numPorts;
1247 }
1248 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1249 reply->writeInt32(generation);
1250 }
1251 free(ports);
1252 return NO_ERROR;
1253 }
1254
1255 case GET_AUDIO_PORT: {
1256 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001257 struct audio_port port = {};
1258 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1259 ALOGE("b/23912202");
1260 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001261 status_t status = getAudioPort(&port);
1262 reply->writeInt32(status);
1263 if (status == NO_ERROR) {
1264 reply->write(&port, sizeof(struct audio_port));
1265 }
1266 return NO_ERROR;
1267 }
1268
1269 case CREATE_AUDIO_PATCH: {
1270 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1271 struct audio_patch patch;
1272 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001273 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001274 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1275 ALOGE("b/23912202");
1276 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001277 status_t status = createAudioPatch(&patch, &handle);
1278 reply->writeInt32(status);
1279 if (status == NO_ERROR) {
1280 reply->write(&handle, sizeof(audio_patch_handle_t));
1281 }
1282 return NO_ERROR;
1283 }
1284
1285 case RELEASE_AUDIO_PATCH: {
1286 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1287 audio_patch_handle_t handle;
1288 data.read(&handle, sizeof(audio_patch_handle_t));
1289 status_t status = releaseAudioPatch(handle);
1290 reply->writeInt32(status);
1291 return NO_ERROR;
1292 }
1293
1294 case LIST_AUDIO_PATCHES: {
1295 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1296 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001297 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1298 numPatchesReq = MAX_ITEMS_PER_LIST;
1299 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001300 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001301 struct audio_patch *patches =
1302 (struct audio_patch *)calloc(numPatchesReq,
1303 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001304 if (patches == NULL) {
1305 reply->writeInt32(NO_MEMORY);
1306 reply->writeInt32(0);
1307 return NO_ERROR;
1308 }
1309 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001310 status_t status = listAudioPatches(&numPatches, patches, &generation);
1311 reply->writeInt32(status);
1312 reply->writeInt32(numPatches);
1313 if (status == NO_ERROR) {
1314 if (numPatchesReq > numPatches) {
1315 numPatchesReq = numPatches;
1316 }
1317 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1318 reply->writeInt32(generation);
1319 }
1320 free(patches);
1321 return NO_ERROR;
1322 }
1323
1324 case SET_AUDIO_PORT_CONFIG: {
1325 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1326 struct audio_port_config config;
1327 data.read(&config, sizeof(struct audio_port_config));
1328 status_t status = setAudioPortConfig(&config);
1329 reply->writeInt32(status);
1330 return NO_ERROR;
1331 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001332
Eric Laurentb52c1522014-05-20 11:27:36 -07001333 case REGISTER_CLIENT: {
1334 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1335 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1336 data.readStrongBinder());
1337 registerClient(client);
1338 return NO_ERROR;
1339 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001340
Eric Laurente8726fe2015-06-26 09:39:24 -07001341 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1342 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1343 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1344 return NO_ERROR;
1345 } break;
1346
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001347 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1348 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1349 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1350 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001351 audio_session_t session = AUDIO_SESSION_NONE;
1352 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1353 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001354 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1355 reply->writeInt32(status);
1356 if (status == NO_ERROR) {
1357 reply->writeInt32(session);
1358 reply->writeInt32(ioHandle);
1359 reply->writeInt32(device);
1360 }
1361 return NO_ERROR;
1362 } break;
1363
1364 case RELEASE_SOUNDTRIGGER_SESSION: {
1365 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1366 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1367 data.readStrongBinder());
1368 audio_session_t session = (audio_session_t)data.readInt32();
1369 status_t status = releaseSoundTriggerSession(session);
1370 reply->writeInt32(status);
1371 return NO_ERROR;
1372 } break;
1373
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001374 case GET_PHONE_STATE: {
1375 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1376 reply->writeInt32((int32_t)getPhoneState());
1377 return NO_ERROR;
1378 } break;
1379
Eric Laurentbaac1832014-12-01 17:52:59 -08001380 case REGISTER_POLICY_MIXES: {
1381 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1382 bool registration = data.readInt32() == 1;
1383 Vector<AudioMix> mixes;
1384 size_t size = (size_t)data.readInt32();
1385 if (size > MAX_MIXES_PER_POLICY) {
1386 size = MAX_MIXES_PER_POLICY;
1387 }
1388 for (size_t i = 0; i < size; i++) {
1389 AudioMix mix;
1390 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1391 mixes.add(mix);
1392 }
1393 }
1394 status_t status = registerPolicyMixes(mixes, registration);
1395 reply->writeInt32(status);
1396 return NO_ERROR;
1397 } break;
1398
Eric Laurent554a2772015-04-10 11:29:24 -07001399 case START_AUDIO_SOURCE: {
1400 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1401 struct audio_port_config source;
1402 data.read(&source, sizeof(struct audio_port_config));
1403 audio_attributes_t attributes;
1404 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001405 sanetizeAudioAttributes(&attributes);
Glenn Kasten559d4392016-03-29 13:42:57 -07001406 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent554a2772015-04-10 11:29:24 -07001407 status_t status = startAudioSource(&source, &attributes, &handle);
1408 reply->writeInt32(status);
1409 reply->writeInt32(handle);
1410 return NO_ERROR;
1411 } break;
1412
1413 case STOP_AUDIO_SOURCE: {
1414 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten559d4392016-03-29 13:42:57 -07001415 audio_patch_handle_t handle = (audio_patch_handle_t) data.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -07001416 status_t status = stopAudioSource(handle);
1417 reply->writeInt32(status);
1418 return NO_ERROR;
1419 } break;
1420
Andy Hung2ddee192015-12-18 17:34:44 -08001421 case SET_MASTER_MONO: {
1422 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1423 bool mono = static_cast<bool>(data.readInt32());
1424 status_t status = setMasterMono(mono);
1425 reply->writeInt32(status);
1426 return NO_ERROR;
1427 } break;
1428
1429 case GET_MASTER_MONO: {
1430 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1431 bool mono;
1432 status_t status = getMasterMono(&mono);
1433 reply->writeInt32(status);
1434 if (status == NO_ERROR) {
1435 reply->writeInt32(static_cast<int32_t>(mono));
1436 }
1437 return NO_ERROR;
1438 } break;
1439
Eric Laurentac9cef52017-06-09 15:46:26 -07001440 case GET_STREAM_VOLUME_DB: {
1441 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1442 audio_stream_type_t stream =
1443 static_cast <audio_stream_type_t>(data.readInt32());
1444 int index = static_cast <int>(data.readInt32());
1445 audio_devices_t device =
1446 static_cast <audio_devices_t>(data.readUint32());
1447 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1448 return NO_ERROR;
1449 }
1450
Eric Laurentc2f1f072009-07-17 12:17:14 -07001451 default:
1452 return BBinder::onTransact(code, data, reply, flags);
1453 }
1454}
1455
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001456void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1457{
1458 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1459 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1460 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1461 }
1462 attr->tags[tagsMaxSize - 1] = '\0';
1463}
1464
Eric Laurentc2f1f072009-07-17 12:17:14 -07001465// ----------------------------------------------------------------------------
1466
Glenn Kasten40bc9062015-03-20 09:09:33 -07001467} // namespace android