blob: b72047b43ffbfa8cc74897052473e8768cad14d7 [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,
Paul McLeanaa981192015-03-21 09:55:15 -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 Laurent20b9ef02016-12-05 11:03:16 -0800215 if (portId == NULL) {
216 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
217 return BAD_VALUE;
218 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800219 if (attr == NULL) {
220 data.writeInt32(0);
221 } else {
222 data.writeInt32(1);
223 data.write(attr, sizeof(audio_attributes_t));
224 }
225 data.writeInt32(session);
226 if (stream == NULL) {
227 data.writeInt32(0);
228 } else {
229 data.writeInt32(1);
230 data.writeInt32(*stream);
231 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700232 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800233 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700234 data.writeInt32(static_cast <uint32_t>(flags));
Paul McLeanaa981192015-03-21 09:55:15 -0700235 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800236 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800237 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
238 if (status != NO_ERROR) {
239 return status;
240 }
241 status = (status_t)reply.readInt32();
242 if (status != NO_ERROR) {
243 return status;
244 }
245 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800246 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800247 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800248 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800249 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700252 }
253
Eric Laurentde070132010-07-13 04:45:46 -0700254 virtual status_t startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700255 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800256 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700257 {
258 Parcel data, reply;
259 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700260 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800261 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800262 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700263 remote()->transact(START_OUTPUT, data, &reply);
264 return static_cast <status_t> (reply.readInt32());
265 }
266
Eric Laurentde070132010-07-13 04:45:46 -0700267 virtual status_t stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700268 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800269 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700270 {
271 Parcel data, reply;
272 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700273 data.writeInt32(output);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800274 data.writeInt32((int32_t) stream);
Glenn Kastend848eb42016-03-08 13:42:11 -0800275 data.writeInt32((int32_t) session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 remote()->transact(STOP_OUTPUT, data, &reply);
277 return static_cast <status_t> (reply.readInt32());
278 }
279
Eric Laurente83b55d2014-11-14 10:06:21 -0800280 virtual void releaseOutput(audio_io_handle_t output,
281 audio_stream_type_t stream,
282 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700283 {
284 Parcel data, reply;
285 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700286 data.writeInt32(output);
Eric Laurente83b55d2014-11-14 10:06:21 -0800287 data.writeInt32((int32_t)stream);
288 data.writeInt32((int32_t)session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 remote()->transact(RELEASE_OUTPUT, data, &reply);
290 }
291
Eric Laurentcaf7f482014-11-25 17:50:47 -0800292 virtual status_t getInputForAttr(const audio_attributes_t *attr,
293 audio_io_handle_t *input,
294 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700295 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700296 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800297 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600298 audio_input_flags_t flags,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800299 audio_port_handle_t selectedDeviceId,
300 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700301 {
302 Parcel data, reply;
303 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800304 if (attr == NULL) {
305 ALOGE("getInputForAttr NULL attr - shouldn't happen");
306 return BAD_VALUE;
307 }
308 if (input == NULL) {
309 ALOGE("getInputForAttr NULL input - shouldn't happen");
310 return BAD_VALUE;
311 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800312 if (portId == NULL) {
313 ALOGE("getInputForAttr NULL portId - shouldn't happen");
314 return BAD_VALUE;
315 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800316 data.write(attr, sizeof(audio_attributes_t));
317 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700318 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700319 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800320 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700321 data.writeInt32(flags);
Paul McLean466dc8e2015-04-17 13:15:36 -0600322 data.writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800323 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800324 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
325 if (status != NO_ERROR) {
326 return status;
327 }
328 status = reply.readInt32();
329 if (status != NO_ERROR) {
330 return status;
331 }
332 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800333 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800334 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 }
336
Eric Laurent4dc68062014-07-28 17:26:49 -0700337 virtual status_t startInput(audio_io_handle_t input,
338 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 {
340 Parcel data, reply;
341 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700342 data.writeInt32(input);
Eric Laurent4dc68062014-07-28 17:26:49 -0700343 data.writeInt32(session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700344 remote()->transact(START_INPUT, data, &reply);
345 return static_cast <status_t> (reply.readInt32());
346 }
347
Eric Laurent4dc68062014-07-28 17:26:49 -0700348 virtual status_t stopInput(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(STOP_INPUT, data, &reply);
356 return static_cast <status_t> (reply.readInt32());
357 }
358
Eric Laurent4dc68062014-07-28 17:26:49 -0700359 virtual void releaseInput(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(RELEASE_INPUT, data, &reply);
367 }
368
Dima Zavinfce7a472011-04-19 22:30:36 -0700369 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700370 int indexMin,
371 int indexMax)
372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
375 data.writeInt32(static_cast <uint32_t>(stream));
376 data.writeInt32(indexMin);
377 data.writeInt32(indexMax);
378 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
379 return static_cast <status_t> (reply.readInt32());
380 }
381
Eric Laurent83844cc2011-11-18 16:43:31 -0800382 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
383 int index,
384 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700385 {
386 Parcel data, reply;
387 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
388 data.writeInt32(static_cast <uint32_t>(stream));
389 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800390 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700391 remote()->transact(SET_STREAM_VOLUME, data, &reply);
392 return static_cast <status_t> (reply.readInt32());
393 }
394
Eric Laurent83844cc2011-11-18 16:43:31 -0800395 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
396 int *index,
397 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700398 {
399 Parcel data, reply;
400 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
401 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800402 data.writeInt32(static_cast <uint32_t>(device));
403
Eric Laurentc2f1f072009-07-17 12:17:14 -0700404 remote()->transact(GET_STREAM_VOLUME, data, &reply);
405 int lIndex = reply.readInt32();
406 if (index) *index = lIndex;
407 return static_cast <status_t> (reply.readInt32());
408 }
Eric Laurentde070132010-07-13 04:45:46 -0700409
Dima Zavinfce7a472011-04-19 22:30:36 -0700410 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700411 {
412 Parcel data, reply;
413 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
414 data.writeInt32(static_cast <uint32_t>(stream));
415 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
416 return reply.readInt32();
417 }
418
Eric Laurent63742522012-03-08 13:42:42 -0800419 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800420 {
421 Parcel data, reply;
422 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
423 data.writeInt32(static_cast <uint32_t>(stream));
424 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800425 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800426 }
427
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700428 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700429 {
430 Parcel data, reply;
431 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
432 data.write(desc, sizeof(effect_descriptor_t));
433 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
434 return static_cast <audio_io_handle_t> (reply.readInt32());
435 }
436
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700437 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700438 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700439 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800440 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700441 int id)
442 {
443 Parcel data, reply;
444 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
445 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700446 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700447 data.writeInt32(strategy);
448 data.writeInt32(session);
449 data.writeInt32(id);
450 remote()->transact(REGISTER_EFFECT, data, &reply);
451 return static_cast <status_t> (reply.readInt32());
452 }
453
454 virtual status_t unregisterEffect(int id)
455 {
456 Parcel data, reply;
457 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
458 data.writeInt32(id);
459 remote()->transact(UNREGISTER_EFFECT, data, &reply);
460 return static_cast <status_t> (reply.readInt32());
461 }
462
Eric Laurentdb7c0792011-08-10 10:37:50 -0700463 virtual status_t setEffectEnabled(int id, bool enabled)
464 {
465 Parcel data, reply;
466 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
467 data.writeInt32(id);
468 data.writeInt32(enabled);
469 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
470 return static_cast <status_t> (reply.readInt32());
471 }
472
Glenn Kastenfff6d712012-01-12 16:38:12 -0800473 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800474 {
475 Parcel data, reply;
476 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800477 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800478 data.writeInt32(inPastMs);
479 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
480 return reply.readInt32();
481 }
Eric Laurent57dae992011-07-24 13:36:09 -0700482
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800483 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
484 {
485 Parcel data, reply;
486 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
487 data.writeInt32((int32_t) stream);
488 data.writeInt32(inPastMs);
489 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
490 return reply.readInt32();
491 }
492
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700493 virtual bool isSourceActive(audio_source_t source) const
494 {
495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
497 data.writeInt32((int32_t) source);
498 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
499 return reply.readInt32();
500 }
501
Glenn Kastend848eb42016-03-08 13:42:11 -0800502 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700503 effect_descriptor_t *descriptors,
504 uint32_t *count)
505 {
506 if (descriptors == NULL || count == NULL) {
507 return BAD_VALUE;
508 }
509 Parcel data, reply;
510 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
511 data.writeInt32(audioSession);
512 data.writeInt32(*count);
513 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
514 if (status != NO_ERROR) {
515 return status;
516 }
517 status = static_cast <status_t> (reply.readInt32());
518 uint32_t retCount = reply.readInt32();
519 if (retCount != 0) {
520 uint32_t numDesc = (retCount < *count) ? retCount : *count;
521 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
522 }
523 *count = retCount;
524 return status;
525 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000526
527 virtual bool isOffloadSupported(const audio_offload_info_t& info)
528 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100529 Parcel data, reply;
530 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
531 data.write(&info, sizeof(audio_offload_info_t));
532 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700533 return reply.readInt32();
534 }
535
536 virtual status_t listAudioPorts(audio_port_role_t role,
537 audio_port_type_t type,
538 unsigned int *num_ports,
539 struct audio_port *ports,
540 unsigned int *generation)
541 {
542 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
543 generation == NULL) {
544 return BAD_VALUE;
545 }
546 Parcel data, reply;
547 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
548 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
549 data.writeInt32(role);
550 data.writeInt32(type);
551 data.writeInt32(numPortsReq);
552 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
553 if (status == NO_ERROR) {
554 status = (status_t)reply.readInt32();
555 *num_ports = (unsigned int)reply.readInt32();
556 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700557 if (status == NO_ERROR) {
558 if (numPortsReq > *num_ports) {
559 numPortsReq = *num_ports;
560 }
561 if (numPortsReq > 0) {
562 reply.read(ports, numPortsReq * sizeof(struct audio_port));
563 }
564 *generation = reply.readInt32();
565 }
566 return status;
567 }
568
569 virtual status_t getAudioPort(struct audio_port *port)
570 {
571 if (port == NULL) {
572 return BAD_VALUE;
573 }
574 Parcel data, reply;
575 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
576 data.write(port, sizeof(struct audio_port));
577 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
578 if (status != NO_ERROR ||
579 (status = (status_t)reply.readInt32()) != NO_ERROR) {
580 return status;
581 }
582 reply.read(port, sizeof(struct audio_port));
583 return status;
584 }
585
586 virtual status_t createAudioPatch(const struct audio_patch *patch,
587 audio_patch_handle_t *handle)
588 {
589 if (patch == NULL || handle == NULL) {
590 return BAD_VALUE;
591 }
592 Parcel data, reply;
593 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
594 data.write(patch, sizeof(struct audio_patch));
595 data.write(handle, sizeof(audio_patch_handle_t));
596 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
597 if (status != NO_ERROR ||
598 (status = (status_t)reply.readInt32()) != NO_ERROR) {
599 return status;
600 }
601 reply.read(handle, sizeof(audio_patch_handle_t));
602 return status;
603 }
604
605 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
606 {
607 Parcel data, reply;
608 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
609 data.write(&handle, sizeof(audio_patch_handle_t));
610 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
611 if (status != NO_ERROR) {
612 status = (status_t)reply.readInt32();
613 }
614 return status;
615 }
616
617 virtual status_t listAudioPatches(unsigned int *num_patches,
618 struct audio_patch *patches,
619 unsigned int *generation)
620 {
621 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
622 generation == NULL) {
623 return BAD_VALUE;
624 }
625 Parcel data, reply;
626 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
627 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
628 data.writeInt32(numPatchesReq);
629 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
630 if (status == NO_ERROR) {
631 status = (status_t)reply.readInt32();
632 *num_patches = (unsigned int)reply.readInt32();
633 }
634 if (status == NO_ERROR) {
635 if (numPatchesReq > *num_patches) {
636 numPatchesReq = *num_patches;
637 }
638 if (numPatchesReq > 0) {
639 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
640 }
641 *generation = reply.readInt32();
642 }
643 return status;
644 }
645
646 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
647 {
648 if (config == NULL) {
649 return BAD_VALUE;
650 }
651 Parcel data, reply;
652 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
653 data.write(config, sizeof(struct audio_port_config));
654 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
655 if (status != NO_ERROR) {
656 status = (status_t)reply.readInt32();
657 }
658 return status;
659 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700660
Eric Laurentb52c1522014-05-20 11:27:36 -0700661 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
662 {
663 Parcel data, reply;
664 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800665 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700666 remote()->transact(REGISTER_CLIENT, data, &reply);
667 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700668
Eric Laurente8726fe2015-06-26 09:39:24 -0700669 virtual void setAudioPortCallbacksEnabled(bool enabled)
670 {
671 Parcel data, reply;
672 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
673 data.writeInt32(enabled ? 1 : 0);
674 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
675 }
676
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700677 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
678 audio_io_handle_t *ioHandle,
679 audio_devices_t *device)
680 {
681 if (session == NULL || ioHandle == NULL || device == NULL) {
682 return BAD_VALUE;
683 }
684 Parcel data, reply;
685 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
686 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
687 if (status != NO_ERROR) {
688 return status;
689 }
690 status = (status_t)reply.readInt32();
691 if (status == NO_ERROR) {
692 *session = (audio_session_t)reply.readInt32();
693 *ioHandle = (audio_io_handle_t)reply.readInt32();
694 *device = (audio_devices_t)reply.readInt32();
695 }
696 return status;
697 }
698
699 virtual status_t releaseSoundTriggerSession(audio_session_t session)
700 {
701 Parcel data, reply;
702 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
703 data.writeInt32(session);
704 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
705 if (status != NO_ERROR) {
706 return status;
707 }
708 return (status_t)reply.readInt32();
709 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700710
711 virtual audio_mode_t getPhoneState()
712 {
713 Parcel data, reply;
714 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
715 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
716 if (status != NO_ERROR) {
717 return AUDIO_MODE_INVALID;
718 }
719 return (audio_mode_t)reply.readInt32();
720 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800721
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700722 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800723 {
724 Parcel data, reply;
725 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
726 data.writeInt32(registration ? 1 : 0);
727 size_t size = mixes.size();
728 if (size > MAX_MIXES_PER_POLICY) {
729 size = MAX_MIXES_PER_POLICY;
730 }
731 size_t sizePosition = data.dataPosition();
732 data.writeInt32(size);
733 size_t finalSize = size;
734 for (size_t i = 0; i < size; i++) {
735 size_t position = data.dataPosition();
736 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
737 data.setDataPosition(position);
738 finalSize--;
739 }
740 }
741 if (size != finalSize) {
742 size_t position = data.dataPosition();
743 data.setDataPosition(sizePosition);
744 data.writeInt32(finalSize);
745 data.setDataPosition(position);
746 }
747 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
748 if (status == NO_ERROR) {
749 status = (status_t)reply.readInt32();
750 }
751 return status;
752 }
Eric Laurent554a2772015-04-10 11:29:24 -0700753
754 virtual status_t startAudioSource(const struct audio_port_config *source,
755 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700756 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700757 {
758 Parcel data, reply;
759 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
760 if (source == NULL || attributes == NULL || handle == NULL) {
761 return BAD_VALUE;
762 }
763 data.write(source, sizeof(struct audio_port_config));
764 data.write(attributes, sizeof(audio_attributes_t));
765 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
766 if (status != NO_ERROR) {
767 return status;
768 }
769 status = (status_t)reply.readInt32();
770 if (status != NO_ERROR) {
771 return status;
772 }
Glenn Kasten559d4392016-03-29 13:42:57 -0700773 *handle = (audio_patch_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700774 return status;
775 }
776
Glenn Kasten559d4392016-03-29 13:42:57 -0700777 virtual status_t stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700778 {
779 Parcel data, reply;
780 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
781 data.writeInt32(handle);
782 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
783 if (status != NO_ERROR) {
784 return status;
785 }
786 status = (status_t)reply.readInt32();
787 return status;
788 }
Andy Hung2ddee192015-12-18 17:34:44 -0800789
790 virtual status_t setMasterMono(bool mono)
791 {
792 Parcel data, reply;
793 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
794 data.writeInt32(static_cast<int32_t>(mono));
795 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
796 if (status != NO_ERROR) {
797 return status;
798 }
799 return static_cast<status_t>(reply.readInt32());
800 }
801
802 virtual status_t getMasterMono(bool *mono)
803 {
804 if (mono == nullptr) {
805 return BAD_VALUE;
806 }
807 Parcel data, reply;
808 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
809
810 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
811 if (status != NO_ERROR) {
812 return status;
813 }
814 status = static_cast<status_t>(reply.readInt32());
815 if (status == NO_ERROR) {
816 *mono = static_cast<bool>(reply.readInt32());
817 }
818 return status;
819 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700820
821 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
822 {
823 Parcel data, reply;
824 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
825 data.writeInt32(static_cast <int32_t>(stream));
826 data.writeInt32(static_cast <int32_t>(index));
827 data.writeUint32(static_cast <uint32_t>(device));
828 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
829 if (status != NO_ERROR) {
830 return NAN;
831 }
832 return reply.readFloat();
833 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834};
835
836IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
837
838// ----------------------------------------------------------------------
839
840
841status_t BnAudioPolicyService::onTransact(
842 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
843{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700844 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845 case SET_DEVICE_CONNECTION_STATE: {
846 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700847 audio_devices_t device =
848 static_cast <audio_devices_t>(data.readInt32());
849 audio_policy_dev_state_t state =
850 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700851 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -0800852 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800853 if (device_address == nullptr || device_name == nullptr) {
854 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
855 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
856 } else {
857 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
858 state,
859 device_address,
860 device_name)));
861 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 return NO_ERROR;
863 } break;
864
865 case GET_DEVICE_CONNECTION_STATE: {
866 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700867 audio_devices_t device =
868 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700869 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800870 if (device_address == nullptr) {
871 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
872 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
873 } else {
874 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
875 device_address)));
876 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700877 return NO_ERROR;
878 } break;
879
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800880 case HANDLE_DEVICE_CONFIG_CHANGE: {
881 CHECK_INTERFACE(IAudioPolicyService, data, reply);
882 audio_devices_t device =
883 static_cast <audio_devices_t>(data.readInt32());
884 const char *device_address = data.readCString();
885 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -0800886 if (device_address == nullptr || device_name == nullptr) {
887 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
888 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
889 } else {
890 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
891 device_address,
892 device_name)));
893 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800894 return NO_ERROR;
895 } break;
896
Eric Laurentc2f1f072009-07-17 12:17:14 -0700897 case SET_PHONE_STATE: {
898 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700899 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
900 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700901 return NO_ERROR;
902 } break;
903
Eric Laurentc2f1f072009-07-17 12:17:14 -0700904 case SET_FORCE_USE: {
905 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700906 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
907 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -0700908 audio_policy_forced_cfg_t config =
909 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700910 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
911 return NO_ERROR;
912 } break;
913
914 case GET_FORCE_USE: {
915 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700916 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
917 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700918 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
919 return NO_ERROR;
920 } break;
921
922 case GET_OUTPUT: {
923 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700924 audio_stream_type_t stream =
925 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700926 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800927 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kasten254af182012-07-03 14:59:05 -0700928 audio_channel_mask_t channelMask = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700929 audio_output_flags_t flags =
930 static_cast <audio_output_flags_t>(data.readInt32());
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100931 bool hasOffloadInfo = data.readInt32() != 0;
932 audio_offload_info_t offloadInfo;
933 if (hasOffloadInfo) {
934 data.read(&offloadInfo, sizeof(audio_offload_info_t));
935 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 audio_io_handle_t output = getOutput(stream,
937 samplingRate,
938 format,
Glenn Kasten254af182012-07-03 14:59:05 -0700939 channelMask,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100940 flags,
941 hasOffloadInfo ? &offloadInfo : NULL);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700942 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700943 return NO_ERROR;
944 } break;
945
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700946 case GET_OUTPUT_FOR_ATTR: {
947 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85f480e2014-11-05 17:44:51 -0800948 audio_attributes_t attr;
Eric Laurente83b55d2014-11-14 10:06:21 -0800949 bool hasAttributes = data.readInt32() != 0;
950 if (hasAttributes) {
951 data.read(&attr, sizeof(audio_attributes_t));
952 }
953 audio_session_t session = (audio_session_t)data.readInt32();
954 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
955 bool hasStream = data.readInt32() != 0;
956 if (hasStream) {
957 stream = (audio_stream_type_t)data.readInt32();
958 }
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700959 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800960 audio_config_t config;
961 memset(&config, 0, sizeof(audio_config_t));
962 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700963 audio_output_flags_t flags =
964 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -0700965 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800966 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -0700967 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -0800968 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700969 &output, session, &stream, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800970 &config,
971 flags, selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800972 reply->writeInt32(status);
973 reply->writeInt32(output);
974 reply->writeInt32(stream);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800975 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700976 return NO_ERROR;
977 } break;
978
Eric Laurentc2f1f072009-07-17 12:17:14 -0700979 case START_OUTPUT: {
980 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700981 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800982 audio_stream_type_t stream =
983 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800984 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700985 reply->writeInt32(static_cast <uint32_t>(startOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800986 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700987 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700988 return NO_ERROR;
989 } break;
990
991 case STOP_OUTPUT: {
992 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700993 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurentebcb2542014-03-05 18:30:08 -0800994 audio_stream_type_t stream =
995 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -0800996 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -0700997 reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
Eric Laurentebcb2542014-03-05 18:30:08 -0800998 stream,
Eric Laurentde070132010-07-13 04:45:46 -0700999 session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001000 return NO_ERROR;
1001 } break;
1002
1003 case RELEASE_OUTPUT: {
1004 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001005 audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurente83b55d2014-11-14 10:06:21 -08001006 audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
1007 audio_session_t session = (audio_session_t)data.readInt32();
1008 releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001009 return NO_ERROR;
1010 } break;
1011
Eric Laurentcaf7f482014-11-25 17:50:47 -08001012 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001013 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001014 audio_attributes_t attr;
1015 data.read(&attr, sizeof(audio_attributes_t));
1016 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001017 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001018 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001019 audio_config_base_t config;
1020 memset(&config, 0, sizeof(audio_config_base_t));
1021 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001022 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001023 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001024 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Glenn Kastena13cde92016-03-28 15:26:02 -07001025 audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
Eric Laurentb2379ba2016-05-23 17:42:12 -07001026 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001027 &config,
1028 flags, selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001029 reply->writeInt32(status);
1030 if (status == NO_ERROR) {
1031 reply->writeInt32(input);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001032 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001033 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001034 return NO_ERROR;
1035 } break;
1036
1037 case START_INPUT: {
1038 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001039 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001040 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1041 reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001042 return NO_ERROR;
1043 } break;
1044
1045 case STOP_INPUT: {
1046 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001047 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001048 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1049 reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001050 return NO_ERROR;
1051 } break;
1052
1053 case RELEASE_INPUT: {
1054 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001055 audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
Eric Laurent4dc68062014-07-28 17:26:49 -07001056 audio_session_t session = static_cast <audio_session_t>(data.readInt32());
1057 releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001058 return NO_ERROR;
1059 } break;
1060
1061 case INIT_STREAM_VOLUME: {
1062 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001063 audio_stream_type_t stream =
1064 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 int indexMin = data.readInt32();
1066 int indexMax = data.readInt32();
1067 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1068 return NO_ERROR;
1069 } break;
1070
1071 case SET_STREAM_VOLUME: {
1072 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001073 audio_stream_type_t stream =
1074 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001075 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001076 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1077 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1078 index,
1079 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001080 return NO_ERROR;
1081 } break;
1082
1083 case GET_STREAM_VOLUME: {
1084 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001085 audio_stream_type_t stream =
1086 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001087 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001088 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001089 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001090 reply->writeInt32(index);
1091 reply->writeInt32(static_cast <uint32_t>(status));
1092 return NO_ERROR;
1093 } break;
1094
Eric Laurentde070132010-07-13 04:45:46 -07001095 case GET_STRATEGY_FOR_STREAM: {
1096 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001097 audio_stream_type_t stream =
1098 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001099 reply->writeInt32(getStrategyForStream(stream));
1100 return NO_ERROR;
1101 } break;
1102
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001103 case GET_DEVICES_FOR_STREAM: {
1104 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001105 audio_stream_type_t stream =
1106 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001107 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1108 return NO_ERROR;
1109 } break;
1110
Eric Laurentde070132010-07-13 04:45:46 -07001111 case GET_OUTPUT_FOR_EFFECT: {
1112 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1113 effect_descriptor_t desc;
1114 data.read(&desc, sizeof(effect_descriptor_t));
1115 audio_io_handle_t output = getOutputForEffect(&desc);
1116 reply->writeInt32(static_cast <int>(output));
1117 return NO_ERROR;
1118 } break;
1119
1120 case REGISTER_EFFECT: {
1121 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1122 effect_descriptor_t desc;
1123 data.read(&desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001124 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001125 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001126 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001127 int id = data.readInt32();
1128 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001129 io,
Eric Laurentde070132010-07-13 04:45:46 -07001130 strategy,
1131 session,
1132 id)));
1133 return NO_ERROR;
1134 } break;
1135
1136 case UNREGISTER_EFFECT: {
1137 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1138 int id = data.readInt32();
1139 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1140 return NO_ERROR;
1141 } break;
1142
Eric Laurentdb7c0792011-08-10 10:37:50 -07001143 case SET_EFFECT_ENABLED: {
1144 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1145 int id = data.readInt32();
1146 bool enabled = static_cast <bool>(data.readInt32());
1147 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1148 return NO_ERROR;
1149 } break;
1150
Eric Laurenteda6c362011-02-02 09:33:30 -08001151 case IS_STREAM_ACTIVE: {
1152 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001153 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001154 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001155 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001156 return NO_ERROR;
1157 } break;
1158
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001159 case IS_STREAM_ACTIVE_REMOTELY: {
1160 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1161 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1162 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001163 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001164 return NO_ERROR;
1165 } break;
1166
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001167 case IS_SOURCE_ACTIVE: {
1168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1169 audio_source_t source = (audio_source_t) data.readInt32();
1170 reply->writeInt32( isSourceActive(source));
1171 return NO_ERROR;
1172 }
1173
Eric Laurent57dae992011-07-24 13:36:09 -07001174 case QUERY_DEFAULT_PRE_PROCESSING: {
1175 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001176 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001177 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001178 if (count > AudioEffect::kMaxPreProcessing) {
1179 count = AudioEffect::kMaxPreProcessing;
1180 }
Eric Laurent57dae992011-07-24 13:36:09 -07001181 uint32_t retCount = count;
Eric Laurent74adca92014-11-05 12:15:36 -08001182 effect_descriptor_t *descriptors = new effect_descriptor_t[count];
Eric Laurent57dae992011-07-24 13:36:09 -07001183 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1184 reply->writeInt32(status);
1185 if (status != NO_ERROR && status != NO_MEMORY) {
1186 retCount = 0;
1187 }
1188 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001189 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001190 if (retCount < count) {
1191 count = retCount;
1192 }
1193 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1194 }
1195 delete[] descriptors;
1196 return status;
1197 }
1198
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001199 case IS_OFFLOAD_SUPPORTED: {
1200 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1201 audio_offload_info_t info;
1202 data.read(&info, sizeof(audio_offload_info_t));
1203 bool isSupported = isOffloadSupported(info);
1204 reply->writeInt32(isSupported);
1205 return NO_ERROR;
1206 }
1207
Eric Laurent203b1a12014-04-01 10:34:16 -07001208 case LIST_AUDIO_PORTS: {
1209 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1210 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1211 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1212 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001213 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1214 numPortsReq = MAX_ITEMS_PER_LIST;
1215 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001216 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001217 struct audio_port *ports =
1218 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001219 if (ports == NULL) {
1220 reply->writeInt32(NO_MEMORY);
1221 reply->writeInt32(0);
1222 return NO_ERROR;
1223 }
1224 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001225 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1226 reply->writeInt32(status);
1227 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001228
1229 if (status == NO_ERROR) {
1230 if (numPortsReq > numPorts) {
1231 numPortsReq = numPorts;
1232 }
1233 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1234 reply->writeInt32(generation);
1235 }
1236 free(ports);
1237 return NO_ERROR;
1238 }
1239
1240 case GET_AUDIO_PORT: {
1241 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001242 struct audio_port port = {};
1243 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1244 ALOGE("b/23912202");
1245 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001246 status_t status = getAudioPort(&port);
1247 reply->writeInt32(status);
1248 if (status == NO_ERROR) {
1249 reply->write(&port, sizeof(struct audio_port));
1250 }
1251 return NO_ERROR;
1252 }
1253
1254 case CREATE_AUDIO_PATCH: {
1255 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1256 struct audio_patch patch;
1257 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001258 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001259 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1260 ALOGE("b/23912202");
1261 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001262 status_t status = createAudioPatch(&patch, &handle);
1263 reply->writeInt32(status);
1264 if (status == NO_ERROR) {
1265 reply->write(&handle, sizeof(audio_patch_handle_t));
1266 }
1267 return NO_ERROR;
1268 }
1269
1270 case RELEASE_AUDIO_PATCH: {
1271 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1272 audio_patch_handle_t handle;
1273 data.read(&handle, sizeof(audio_patch_handle_t));
1274 status_t status = releaseAudioPatch(handle);
1275 reply->writeInt32(status);
1276 return NO_ERROR;
1277 }
1278
1279 case LIST_AUDIO_PATCHES: {
1280 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1281 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001282 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1283 numPatchesReq = MAX_ITEMS_PER_LIST;
1284 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001285 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001286 struct audio_patch *patches =
1287 (struct audio_patch *)calloc(numPatchesReq,
1288 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001289 if (patches == NULL) {
1290 reply->writeInt32(NO_MEMORY);
1291 reply->writeInt32(0);
1292 return NO_ERROR;
1293 }
1294 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001295 status_t status = listAudioPatches(&numPatches, patches, &generation);
1296 reply->writeInt32(status);
1297 reply->writeInt32(numPatches);
1298 if (status == NO_ERROR) {
1299 if (numPatchesReq > numPatches) {
1300 numPatchesReq = numPatches;
1301 }
1302 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1303 reply->writeInt32(generation);
1304 }
1305 free(patches);
1306 return NO_ERROR;
1307 }
1308
1309 case SET_AUDIO_PORT_CONFIG: {
1310 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1311 struct audio_port_config config;
1312 data.read(&config, sizeof(struct audio_port_config));
1313 status_t status = setAudioPortConfig(&config);
1314 reply->writeInt32(status);
1315 return NO_ERROR;
1316 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001317
Eric Laurentb52c1522014-05-20 11:27:36 -07001318 case REGISTER_CLIENT: {
1319 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1320 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1321 data.readStrongBinder());
1322 registerClient(client);
1323 return NO_ERROR;
1324 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001325
Eric Laurente8726fe2015-06-26 09:39:24 -07001326 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1327 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1328 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1329 return NO_ERROR;
1330 } break;
1331
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001332 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1333 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1334 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1335 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001336 audio_session_t session = AUDIO_SESSION_NONE;
1337 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1338 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001339 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1340 reply->writeInt32(status);
1341 if (status == NO_ERROR) {
1342 reply->writeInt32(session);
1343 reply->writeInt32(ioHandle);
1344 reply->writeInt32(device);
1345 }
1346 return NO_ERROR;
1347 } break;
1348
1349 case RELEASE_SOUNDTRIGGER_SESSION: {
1350 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1351 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1352 data.readStrongBinder());
1353 audio_session_t session = (audio_session_t)data.readInt32();
1354 status_t status = releaseSoundTriggerSession(session);
1355 reply->writeInt32(status);
1356 return NO_ERROR;
1357 } break;
1358
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001359 case GET_PHONE_STATE: {
1360 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1361 reply->writeInt32((int32_t)getPhoneState());
1362 return NO_ERROR;
1363 } break;
1364
Eric Laurentbaac1832014-12-01 17:52:59 -08001365 case REGISTER_POLICY_MIXES: {
1366 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1367 bool registration = data.readInt32() == 1;
1368 Vector<AudioMix> mixes;
1369 size_t size = (size_t)data.readInt32();
1370 if (size > MAX_MIXES_PER_POLICY) {
1371 size = MAX_MIXES_PER_POLICY;
1372 }
1373 for (size_t i = 0; i < size; i++) {
1374 AudioMix mix;
1375 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1376 mixes.add(mix);
1377 }
1378 }
1379 status_t status = registerPolicyMixes(mixes, registration);
1380 reply->writeInt32(status);
1381 return NO_ERROR;
1382 } break;
1383
Eric Laurent554a2772015-04-10 11:29:24 -07001384 case START_AUDIO_SOURCE: {
1385 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1386 struct audio_port_config source;
1387 data.read(&source, sizeof(struct audio_port_config));
1388 audio_attributes_t attributes;
1389 data.read(&attributes, sizeof(audio_attributes_t));
Glenn Kasten559d4392016-03-29 13:42:57 -07001390 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent554a2772015-04-10 11:29:24 -07001391 status_t status = startAudioSource(&source, &attributes, &handle);
1392 reply->writeInt32(status);
1393 reply->writeInt32(handle);
1394 return NO_ERROR;
1395 } break;
1396
1397 case STOP_AUDIO_SOURCE: {
1398 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten559d4392016-03-29 13:42:57 -07001399 audio_patch_handle_t handle = (audio_patch_handle_t) data.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -07001400 status_t status = stopAudioSource(handle);
1401 reply->writeInt32(status);
1402 return NO_ERROR;
1403 } break;
1404
Andy Hung2ddee192015-12-18 17:34:44 -08001405 case SET_MASTER_MONO: {
1406 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1407 bool mono = static_cast<bool>(data.readInt32());
1408 status_t status = setMasterMono(mono);
1409 reply->writeInt32(status);
1410 return NO_ERROR;
1411 } break;
1412
1413 case GET_MASTER_MONO: {
1414 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1415 bool mono;
1416 status_t status = getMasterMono(&mono);
1417 reply->writeInt32(status);
1418 if (status == NO_ERROR) {
1419 reply->writeInt32(static_cast<int32_t>(mono));
1420 }
1421 return NO_ERROR;
1422 } break;
1423
Eric Laurentac9cef52017-06-09 15:46:26 -07001424 case GET_STREAM_VOLUME_DB: {
1425 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1426 audio_stream_type_t stream =
1427 static_cast <audio_stream_type_t>(data.readInt32());
1428 int index = static_cast <int>(data.readInt32());
1429 audio_devices_t device =
1430 static_cast <audio_devices_t>(data.readUint32());
1431 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1432 return NO_ERROR;
1433 }
1434
Eric Laurentc2f1f072009-07-17 12:17:14 -07001435 default:
1436 return BBinder::onTransact(code, data, reply, flags);
1437 }
1438}
1439
1440// ----------------------------------------------------------------------------
1441
Glenn Kasten40bc9062015-03-20 09:09:33 -07001442} // namespace android