blob: 8c7fac508b8d011135bdc1740d1389340ad97196 [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
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070026#include <binder/Parcel.h>
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
Eric Laurent3528c932018-02-23 17:17:22 -080029#include <media/TimeCheck.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070030#include <mediautils/ServiceUtilities.h>
Dima Zavin64760242011-05-11 14:15:23 -070031#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070032
Eric Laurentc2f1f072009-07-17 12:17:14 -070033namespace android {
34
35enum {
36 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
37 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080038 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080040 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 SET_FORCE_USE,
42 GET_FORCE_USE,
43 GET_OUTPUT,
44 START_OUTPUT,
45 STOP_OUTPUT,
46 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080047 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070048 START_INPUT,
49 STOP_INPUT,
50 RELEASE_INPUT,
51 INIT_STREAM_VOLUME,
52 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070053 GET_STREAM_VOLUME,
54 GET_STRATEGY_FOR_STREAM,
55 GET_OUTPUT_FOR_EFFECT,
56 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080057 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070059 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080060 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070061 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080062 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000063 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070064 IS_OFFLOAD_SUPPORTED,
Michael Chana94fbb22018-04-24 14:31:19 +100065 IS_DIRECT_OUTPUT_SUPPORTED,
Eric Laurent203b1a12014-04-01 10:34:16 -070066 LIST_AUDIO_PORTS,
67 GET_AUDIO_PORT,
68 CREATE_AUDIO_PATCH,
69 RELEASE_AUDIO_PATCH,
70 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070071 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070072 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070073 GET_OUTPUT_FOR_ATTR,
74 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070075 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080076 GET_PHONE_STATE,
77 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070078 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070079 STOP_AUDIO_SOURCE,
80 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080081 SET_MASTER_MONO,
82 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070083 GET_STREAM_VOLUME_DB,
84 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070085 SET_SURROUND_FORMAT_ENABLED,
86 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070087 REMOVE_STREAM_DEFAULT_EFFECT,
88 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070089 REMOVE_SOURCE_DEFAULT_EFFECT,
90 SET_ASSISTANT_UID,
91 SET_A11Y_SERVICES_UIDS,
jiabin6012f912018-11-02 17:06:30 -070092 IS_HAPTIC_PLAYBACK_SUPPORTED,
Jean-Michel Trivibda70da2018-12-19 07:30:15 -080093 SET_UID_DEVICE_AFFINITY,
94 REMOVE_UID_DEVICE_AFFINITY,
Arun Mirpuri11029ad2018-12-19 20:45:19 -080095 GET_OFFLOAD_FORMATS_A2DP
Eric Laurentc2f1f072009-07-17 12:17:14 -070096};
97
Eric Laurent1d670b12015-02-06 10:44:24 -080098#define MAX_ITEMS_PER_LIST 1024
99
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
101{
102public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700103 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700104 : BpInterface<IAudioPolicyService>(impl)
105 {
106 }
107
108 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700109 audio_devices_t device,
110 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800111 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800112 const char *device_name,
113 audio_format_t encodedFormat)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700114 {
115 Parcel data, reply;
116 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
117 data.writeInt32(static_cast <uint32_t>(device));
118 data.writeInt32(static_cast <uint32_t>(state));
119 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800120 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800121 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700122 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
123 return static_cast <status_t> (reply.readInt32());
124 }
125
Dima Zavinfce7a472011-04-19 22:30:36 -0700126 virtual audio_policy_dev_state_t getDeviceConnectionState(
127 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700128 const char *device_address)
129 {
130 Parcel data, reply;
131 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
132 data.writeInt32(static_cast <uint32_t>(device));
133 data.writeCString(device_address);
134 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700136 }
137
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800138 virtual status_t handleDeviceConfigChange(audio_devices_t device,
139 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800140 const char *device_name,
141 audio_format_t encodedFormat)
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800142 {
143 Parcel data, reply;
144 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
145 data.writeInt32(static_cast <uint32_t>(device));
146 data.writeCString(device_address);
147 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800148 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800149 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
150 return static_cast <status_t> (reply.readInt32());
151 }
152
Glenn Kastenf78aee72012-01-04 11:00:47 -0800153 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
157 data.writeInt32(state);
158 remote()->transact(SET_PHONE_STATE, data, &reply);
159 return static_cast <status_t> (reply.readInt32());
160 }
161
Dima Zavinfce7a472011-04-19 22:30:36 -0700162 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700163 {
164 Parcel data, reply;
165 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
166 data.writeInt32(static_cast <uint32_t>(usage));
167 data.writeInt32(static_cast <uint32_t>(config));
168 remote()->transact(SET_FORCE_USE, data, &reply);
169 return static_cast <status_t> (reply.readInt32());
170 }
171
Dima Zavinfce7a472011-04-19 22:30:36 -0700172 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700173 {
174 Parcel data, reply;
175 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
176 data.writeInt32(static_cast <uint32_t>(usage));
177 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700178 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700179 }
180
Eric Laurentf4e63452017-11-06 19:31:46 +0000181 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700182 {
183 Parcel data, reply;
184 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
185 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700186 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700187 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700188 }
189
Eric Laurente83b55d2014-11-14 10:06:21 -0800190 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
191 audio_io_handle_t *output,
192 audio_session_t session,
193 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200194 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700195 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800196 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700198 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800199 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700200 {
201 Parcel data, reply;
202 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
203 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800204 if (stream == NULL) {
205 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
206 return BAD_VALUE;
207 }
208 if (*stream == AUDIO_STREAM_DEFAULT) {
209 ALOGE("getOutputForAttr unspecified stream type");
210 return BAD_VALUE;
211 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700212 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800213 if (output == NULL) {
214 ALOGE("getOutputForAttr NULL output - shouldn't happen");
215 return BAD_VALUE;
216 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700217 if (selectedDeviceId == NULL) {
218 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
219 return BAD_VALUE;
220 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800221 if (portId == NULL) {
222 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
223 return BAD_VALUE;
224 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800225 if (attr == NULL) {
226 data.writeInt32(0);
227 } else {
228 data.writeInt32(1);
229 data.write(attr, sizeof(audio_attributes_t));
230 }
231 data.writeInt32(session);
232 if (stream == NULL) {
233 data.writeInt32(0);
234 } else {
235 data.writeInt32(1);
236 data.writeInt32(*stream);
237 }
Nadav Bar766fb022018-01-07 12:18:03 +0200238 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700239 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800240 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700241 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700242 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800243 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800244 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
245 if (status != NO_ERROR) {
246 return status;
247 }
248 status = (status_t)reply.readInt32();
249 if (status != NO_ERROR) {
250 return status;
251 }
252 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800253 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800255 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800256 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700257 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800258 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800259 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700260 }
261
Eric Laurentd7fe0862018-07-14 16:48:01 -0700262 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700263 {
264 Parcel data, reply;
265 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700266 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 remote()->transact(START_OUTPUT, data, &reply);
268 return static_cast <status_t> (reply.readInt32());
269 }
270
Eric Laurentd7fe0862018-07-14 16:48:01 -0700271 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700275 data.writeInt32((int32_t)portId);
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 Laurentd7fe0862018-07-14 16:48:01 -0700280 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700284 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 remote()->transact(RELEASE_OUTPUT, data, &reply);
286 }
287
Eric Laurentcaf7f482014-11-25 17:50:47 -0800288 virtual status_t getInputForAttr(const audio_attributes_t *attr,
289 audio_io_handle_t *input,
290 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700291 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700292 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800293 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800294 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600295 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700296 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800297 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800301 if (attr == NULL) {
302 ALOGE("getInputForAttr NULL attr - shouldn't happen");
303 return BAD_VALUE;
304 }
305 if (input == NULL) {
306 ALOGE("getInputForAttr NULL input - shouldn't happen");
307 return BAD_VALUE;
308 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700309 if (selectedDeviceId == NULL) {
310 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
311 return BAD_VALUE;
312 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800313 if (portId == NULL) {
314 ALOGE("getInputForAttr NULL portId - shouldn't happen");
315 return BAD_VALUE;
316 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800317 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700318 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800319 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700320 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700321 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800322 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800323 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700324 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700325 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800326 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800327 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
328 if (status != NO_ERROR) {
329 return status;
330 }
331 status = reply.readInt32();
332 if (status != NO_ERROR) {
333 return status;
334 }
335 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700336 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800337 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800338 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 }
340
Eric Laurent4eb58f12018-12-07 16:41:02 -0800341 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800345 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800347 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800348 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 }
350
Eric Laurentfee19762018-01-29 18:44:13 -0800351 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800355 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 remote()->transact(STOP_INPUT, data, &reply);
357 return static_cast <status_t> (reply.readInt32());
358 }
359
Eric Laurentfee19762018-01-29 18:44:13 -0800360 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800364 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 remote()->transact(RELEASE_INPUT, data, &reply);
366 }
367
Dima Zavinfce7a472011-04-19 22:30:36 -0700368 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 int indexMin,
370 int indexMax)
371 {
372 Parcel data, reply;
373 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
374 data.writeInt32(static_cast <uint32_t>(stream));
375 data.writeInt32(indexMin);
376 data.writeInt32(indexMax);
377 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
378 return static_cast <status_t> (reply.readInt32());
379 }
380
Eric Laurent83844cc2011-11-18 16:43:31 -0800381 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
382 int index,
383 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 {
385 Parcel data, reply;
386 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
387 data.writeInt32(static_cast <uint32_t>(stream));
388 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800389 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700390 remote()->transact(SET_STREAM_VOLUME, data, &reply);
391 return static_cast <status_t> (reply.readInt32());
392 }
393
Eric Laurent83844cc2011-11-18 16:43:31 -0800394 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
395 int *index,
396 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
400 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800401 data.writeInt32(static_cast <uint32_t>(device));
402
Eric Laurentc2f1f072009-07-17 12:17:14 -0700403 remote()->transact(GET_STREAM_VOLUME, data, &reply);
404 int lIndex = reply.readInt32();
405 if (index) *index = lIndex;
406 return static_cast <status_t> (reply.readInt32());
407 }
Eric Laurentde070132010-07-13 04:45:46 -0700408
Dima Zavinfce7a472011-04-19 22:30:36 -0700409 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700410 {
411 Parcel data, reply;
412 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
413 data.writeInt32(static_cast <uint32_t>(stream));
414 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
415 return reply.readInt32();
416 }
417
Eric Laurent63742522012-03-08 13:42:42 -0800418 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
422 data.writeInt32(static_cast <uint32_t>(stream));
423 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800424 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800425 }
426
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700427 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700428 {
429 Parcel data, reply;
430 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
431 data.write(desc, sizeof(effect_descriptor_t));
432 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
433 return static_cast <audio_io_handle_t> (reply.readInt32());
434 }
435
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700436 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700437 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700438 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800439 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700440 int id)
441 {
442 Parcel data, reply;
443 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
444 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700445 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700446 data.writeInt32(strategy);
447 data.writeInt32(session);
448 data.writeInt32(id);
449 remote()->transact(REGISTER_EFFECT, data, &reply);
450 return static_cast <status_t> (reply.readInt32());
451 }
452
453 virtual status_t unregisterEffect(int id)
454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
457 data.writeInt32(id);
458 remote()->transact(UNREGISTER_EFFECT, data, &reply);
459 return static_cast <status_t> (reply.readInt32());
460 }
461
Eric Laurentdb7c0792011-08-10 10:37:50 -0700462 virtual status_t setEffectEnabled(int id, bool enabled)
463 {
464 Parcel data, reply;
465 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
466 data.writeInt32(id);
467 data.writeInt32(enabled);
468 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
469 return static_cast <status_t> (reply.readInt32());
470 }
471
Glenn Kastenfff6d712012-01-12 16:38:12 -0800472 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800473 {
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800476 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800477 data.writeInt32(inPastMs);
478 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
479 return reply.readInt32();
480 }
Eric Laurent57dae992011-07-24 13:36:09 -0700481
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800482 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
483 {
484 Parcel data, reply;
485 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
486 data.writeInt32((int32_t) stream);
487 data.writeInt32(inPastMs);
488 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
489 return reply.readInt32();
490 }
491
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700492 virtual bool isSourceActive(audio_source_t source) const
493 {
494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
496 data.writeInt32((int32_t) source);
497 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
498 return reply.readInt32();
499 }
500
Glenn Kastend848eb42016-03-08 13:42:11 -0800501 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700502 effect_descriptor_t *descriptors,
503 uint32_t *count)
504 {
505 if (descriptors == NULL || count == NULL) {
506 return BAD_VALUE;
507 }
508 Parcel data, reply;
509 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
510 data.writeInt32(audioSession);
511 data.writeInt32(*count);
512 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
513 if (status != NO_ERROR) {
514 return status;
515 }
516 status = static_cast <status_t> (reply.readInt32());
517 uint32_t retCount = reply.readInt32();
518 if (retCount != 0) {
519 uint32_t numDesc = (retCount < *count) ? retCount : *count;
520 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
521 }
522 *count = retCount;
523 return status;
524 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000525
526 virtual bool isOffloadSupported(const audio_offload_info_t& info)
527 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100528 Parcel data, reply;
529 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
530 data.write(&info, sizeof(audio_offload_info_t));
531 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700532 return reply.readInt32();
533 }
534
Michael Chana94fbb22018-04-24 14:31:19 +1000535 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
536 const audio_attributes_t& attributes) {
537 Parcel data, reply;
538 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
539 data.write(&config, sizeof(audio_config_base_t));
540 data.write(&attributes, sizeof(audio_attributes_t));
541 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
542 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
543 }
544
Eric Laurent203b1a12014-04-01 10:34:16 -0700545 virtual status_t listAudioPorts(audio_port_role_t role,
546 audio_port_type_t type,
547 unsigned int *num_ports,
548 struct audio_port *ports,
549 unsigned int *generation)
550 {
551 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
552 generation == NULL) {
553 return BAD_VALUE;
554 }
555 Parcel data, reply;
556 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
557 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
558 data.writeInt32(role);
559 data.writeInt32(type);
560 data.writeInt32(numPortsReq);
561 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
562 if (status == NO_ERROR) {
563 status = (status_t)reply.readInt32();
564 *num_ports = (unsigned int)reply.readInt32();
565 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700566 if (status == NO_ERROR) {
567 if (numPortsReq > *num_ports) {
568 numPortsReq = *num_ports;
569 }
570 if (numPortsReq > 0) {
571 reply.read(ports, numPortsReq * sizeof(struct audio_port));
572 }
573 *generation = reply.readInt32();
574 }
575 return status;
576 }
577
578 virtual status_t getAudioPort(struct audio_port *port)
579 {
580 if (port == NULL) {
581 return BAD_VALUE;
582 }
583 Parcel data, reply;
584 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
585 data.write(port, sizeof(struct audio_port));
586 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
587 if (status != NO_ERROR ||
588 (status = (status_t)reply.readInt32()) != NO_ERROR) {
589 return status;
590 }
591 reply.read(port, sizeof(struct audio_port));
592 return status;
593 }
594
595 virtual status_t createAudioPatch(const struct audio_patch *patch,
596 audio_patch_handle_t *handle)
597 {
598 if (patch == NULL || handle == NULL) {
599 return BAD_VALUE;
600 }
601 Parcel data, reply;
602 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
603 data.write(patch, sizeof(struct audio_patch));
604 data.write(handle, sizeof(audio_patch_handle_t));
605 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
606 if (status != NO_ERROR ||
607 (status = (status_t)reply.readInt32()) != NO_ERROR) {
608 return status;
609 }
610 reply.read(handle, sizeof(audio_patch_handle_t));
611 return status;
612 }
613
614 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
615 {
616 Parcel data, reply;
617 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
618 data.write(&handle, sizeof(audio_patch_handle_t));
619 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
620 if (status != NO_ERROR) {
621 status = (status_t)reply.readInt32();
622 }
623 return status;
624 }
625
626 virtual status_t listAudioPatches(unsigned int *num_patches,
627 struct audio_patch *patches,
628 unsigned int *generation)
629 {
630 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
631 generation == NULL) {
632 return BAD_VALUE;
633 }
634 Parcel data, reply;
635 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
636 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
637 data.writeInt32(numPatchesReq);
638 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
639 if (status == NO_ERROR) {
640 status = (status_t)reply.readInt32();
641 *num_patches = (unsigned int)reply.readInt32();
642 }
643 if (status == NO_ERROR) {
644 if (numPatchesReq > *num_patches) {
645 numPatchesReq = *num_patches;
646 }
647 if (numPatchesReq > 0) {
648 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
649 }
650 *generation = reply.readInt32();
651 }
652 return status;
653 }
654
655 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
656 {
657 if (config == NULL) {
658 return BAD_VALUE;
659 }
660 Parcel data, reply;
661 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
662 data.write(config, sizeof(struct audio_port_config));
663 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
664 if (status != NO_ERROR) {
665 status = (status_t)reply.readInt32();
666 }
667 return status;
668 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700669
Eric Laurentb52c1522014-05-20 11:27:36 -0700670 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
671 {
672 Parcel data, reply;
673 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800674 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700675 remote()->transact(REGISTER_CLIENT, data, &reply);
676 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700677
Eric Laurente8726fe2015-06-26 09:39:24 -0700678 virtual void setAudioPortCallbacksEnabled(bool enabled)
679 {
680 Parcel data, reply;
681 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
682 data.writeInt32(enabled ? 1 : 0);
683 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
684 }
685
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700686 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
687 audio_io_handle_t *ioHandle,
688 audio_devices_t *device)
689 {
690 if (session == NULL || ioHandle == NULL || device == NULL) {
691 return BAD_VALUE;
692 }
693 Parcel data, reply;
694 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
695 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
696 if (status != NO_ERROR) {
697 return status;
698 }
699 status = (status_t)reply.readInt32();
700 if (status == NO_ERROR) {
701 *session = (audio_session_t)reply.readInt32();
702 *ioHandle = (audio_io_handle_t)reply.readInt32();
703 *device = (audio_devices_t)reply.readInt32();
704 }
705 return status;
706 }
707
708 virtual status_t releaseSoundTriggerSession(audio_session_t session)
709 {
710 Parcel data, reply;
711 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
712 data.writeInt32(session);
713 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
714 if (status != NO_ERROR) {
715 return status;
716 }
717 return (status_t)reply.readInt32();
718 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700719
720 virtual audio_mode_t getPhoneState()
721 {
722 Parcel data, reply;
723 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
724 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
725 if (status != NO_ERROR) {
726 return AUDIO_MODE_INVALID;
727 }
728 return (audio_mode_t)reply.readInt32();
729 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800730
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700731 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800732 {
733 Parcel data, reply;
734 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
735 data.writeInt32(registration ? 1 : 0);
736 size_t size = mixes.size();
737 if (size > MAX_MIXES_PER_POLICY) {
738 size = MAX_MIXES_PER_POLICY;
739 }
740 size_t sizePosition = data.dataPosition();
741 data.writeInt32(size);
742 size_t finalSize = size;
743 for (size_t i = 0; i < size; i++) {
744 size_t position = data.dataPosition();
745 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
746 data.setDataPosition(position);
747 finalSize--;
748 }
749 }
750 if (size != finalSize) {
751 size_t position = data.dataPosition();
752 data.setDataPosition(sizePosition);
753 data.writeInt32(finalSize);
754 data.setDataPosition(position);
755 }
756 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
757 if (status == NO_ERROR) {
758 status = (status_t)reply.readInt32();
759 }
760 return status;
761 }
Eric Laurent554a2772015-04-10 11:29:24 -0700762
763 virtual status_t startAudioSource(const struct audio_port_config *source,
764 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700765 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700766 {
767 Parcel data, reply;
768 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700769 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700770 return BAD_VALUE;
771 }
772 data.write(source, sizeof(struct audio_port_config));
773 data.write(attributes, sizeof(audio_attributes_t));
774 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
775 if (status != NO_ERROR) {
776 return status;
777 }
778 status = (status_t)reply.readInt32();
779 if (status != NO_ERROR) {
780 return status;
781 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700782 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700783 return status;
784 }
785
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700786 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700787 {
788 Parcel data, reply;
789 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700790 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700791 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
792 if (status != NO_ERROR) {
793 return status;
794 }
795 status = (status_t)reply.readInt32();
796 return status;
797 }
Andy Hung2ddee192015-12-18 17:34:44 -0800798
799 virtual status_t setMasterMono(bool mono)
800 {
801 Parcel data, reply;
802 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
803 data.writeInt32(static_cast<int32_t>(mono));
804 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
805 if (status != NO_ERROR) {
806 return status;
807 }
808 return static_cast<status_t>(reply.readInt32());
809 }
810
811 virtual status_t getMasterMono(bool *mono)
812 {
813 if (mono == nullptr) {
814 return BAD_VALUE;
815 }
816 Parcel data, reply;
817 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
818
819 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
820 if (status != NO_ERROR) {
821 return status;
822 }
823 status = static_cast<status_t>(reply.readInt32());
824 if (status == NO_ERROR) {
825 *mono = static_cast<bool>(reply.readInt32());
826 }
827 return status;
828 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700829
830 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
831 {
832 Parcel data, reply;
833 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
834 data.writeInt32(static_cast <int32_t>(stream));
835 data.writeInt32(static_cast <int32_t>(index));
836 data.writeUint32(static_cast <uint32_t>(device));
837 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
838 if (status != NO_ERROR) {
839 return NAN;
840 }
841 return reply.readFloat();
842 }
jiabin81772902018-04-02 17:52:27 -0700843
844 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
845 audio_format_t *surroundFormats,
846 bool *surroundFormatsEnabled,
847 bool reported)
848 {
849 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
850 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
851 return BAD_VALUE;
852 }
853 Parcel data, reply;
854 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
855 unsigned int numSurroundFormatsReq = *numSurroundFormats;
856 data.writeUint32(numSurroundFormatsReq);
857 data.writeBool(reported);
858 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
859 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
860 *numSurroundFormats = reply.readUint32();
861 }
862 if (status == NO_ERROR) {
863 if (numSurroundFormatsReq > *numSurroundFormats) {
864 numSurroundFormatsReq = *numSurroundFormats;
865 }
866 if (numSurroundFormatsReq > 0) {
867 status = reply.read(surroundFormats,
868 numSurroundFormatsReq * sizeof(audio_format_t));
869 if (status != NO_ERROR) {
870 return status;
871 }
872 status = reply.read(surroundFormatsEnabled,
873 numSurroundFormatsReq * sizeof(bool));
874 }
875 }
876 return status;
877 }
878
879 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
880 {
881 Parcel data, reply;
882 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
883 data.writeInt32(audioFormat);
884 data.writeBool(enabled);
885 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
886 if (status != NO_ERROR) {
887 return status;
888 }
889 return reply.readInt32();
890 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700891
Arun Mirpuri11029ad2018-12-19 20:45:19 -0800892 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
893 std::vector<audio_format_t> *formats)
894 {
895 if (formats == NULL) {
896 return BAD_VALUE;
897 }
898
899 Parcel data, reply;
900 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
901 status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
902 if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
903 return status;
904 }
905
906 size_t list_size = reply.readUint32();
907
908 for (size_t i = 0; i < list_size; i++) {
909 formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
910 }
911 return NO_ERROR;
912 }
913
914
915 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700916 const String16& opPackageName,
917 const effect_uuid_t *uuid,
918 int32_t priority,
919 audio_usage_t usage,
920 audio_unique_id_t* id)
921 {
922 Parcel data, reply;
923 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
924 data.write(type, sizeof(effect_uuid_t));
925 data.writeString16(opPackageName);
926 data.write(uuid, sizeof(effect_uuid_t));
927 data.writeInt32(priority);
928 data.writeInt32((int32_t) usage);
929 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
930 if (status != NO_ERROR) {
931 return status;
932 }
933 status = static_cast <status_t> (reply.readInt32());
934 *id = reply.readInt32();
935 return status;
936 }
937
938 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
939 {
940 Parcel data, reply;
941 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
942 data.writeInt32(id);
943 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
944 if (status != NO_ERROR) {
945 return status;
946 }
947 return static_cast <status_t> (reply.readInt32());
948 }
949
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700950 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
951 const String16& opPackageName,
952 const effect_uuid_t *uuid,
953 int32_t priority,
954 audio_source_t source,
955 audio_unique_id_t* id)
956 {
957 Parcel data, reply;
958 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
959 data.write(type, sizeof(effect_uuid_t));
960 data.writeString16(opPackageName);
961 data.write(uuid, sizeof(effect_uuid_t));
962 data.writeInt32(priority);
963 data.writeInt32((int32_t) source);
964 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
965 if (status != NO_ERROR) {
966 return status;
967 }
968 status = static_cast <status_t> (reply.readInt32());
969 *id = reply.readInt32();
970 return status;
971 }
972
973 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
974 {
975 Parcel data, reply;
976 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
977 data.writeInt32(id);
978 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
979 if (status != NO_ERROR) {
980 return status;
981 }
982 return static_cast <status_t> (reply.readInt32());
983 }
984
Eric Laurentb78763e2018-10-17 10:08:02 -0700985 virtual status_t setAssistantUid(uid_t uid)
986 {
987 Parcel data, reply;
988 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
989 data.writeInt32(uid);
990 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
991 if (status != NO_ERROR) {
992 return status;
993 }
994 return static_cast <status_t> (reply.readInt32());
995 }
996
997 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
998 {
999 Parcel data, reply;
1000 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1001 data.writeInt32(uids.size());
1002 for (auto uid : uids) {
1003 data.writeInt32(uid);
1004 }
1005 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
1006 if (status != NO_ERROR) {
1007 return status;
1008 }
1009 return static_cast <status_t> (reply.readInt32());
1010 }
1011
jiabin6012f912018-11-02 17:06:30 -07001012 virtual bool isHapticPlaybackSupported()
1013 {
1014 Parcel data, reply;
1015 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1016 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
1017 if (status != NO_ERROR) {
1018 return false;
1019 }
1020 return reply.readBool();
1021 }
1022
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001023 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
1024 {
1025 Parcel data, reply;
1026 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1027
1028 data.writeInt32((int32_t) uid);
1029 size_t size = devices.size();
1030 size_t sizePosition = data.dataPosition();
1031 data.writeInt32((int32_t) size);
1032 size_t finalSize = size;
1033 for (size_t i = 0; i < size; i++) {
1034 size_t position = data.dataPosition();
1035 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1036 data.setDataPosition(position);
1037 finalSize--;
1038 }
1039 }
1040 if (size != finalSize) {
1041 size_t position = data.dataPosition();
1042 data.setDataPosition(sizePosition);
1043 data.writeInt32(finalSize);
1044 data.setDataPosition(position);
1045 }
1046
1047 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1048 if (status == NO_ERROR) {
1049 status = (status_t)reply.readInt32();
1050 }
1051 return status;
1052 }
1053
1054 virtual status_t removeUidDeviceAffinities(uid_t uid)
1055 {
1056 Parcel data, reply;
1057 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1058
1059 data.writeInt32((int32_t) uid);
1060
1061 status_t status = remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
1062 if (status == NO_ERROR) {
1063 status = (status_t)reply.readInt32();
1064 }
1065 return status;
1066 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001067};
1068
1069IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1070
1071// ----------------------------------------------------------------------
1072
Eric Laurentc2f1f072009-07-17 12:17:14 -07001073status_t BnAudioPolicyService::onTransact(
1074 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1075{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001076 // make sure transactions reserved to AudioFlinger do not come from other processes
1077 switch (code) {
1078 case START_OUTPUT:
1079 case STOP_OUTPUT:
1080 case RELEASE_OUTPUT:
1081 case GET_INPUT_FOR_ATTR:
1082 case START_INPUT:
1083 case STOP_INPUT:
1084 case RELEASE_INPUT:
1085 case GET_STRATEGY_FOR_STREAM:
1086 case GET_OUTPUT_FOR_EFFECT:
1087 case REGISTER_EFFECT:
1088 case UNREGISTER_EFFECT:
1089 case SET_EFFECT_ENABLED:
1090 case GET_OUTPUT_FOR_ATTR:
1091 case ACQUIRE_SOUNDTRIGGER_SESSION:
1092 case RELEASE_SOUNDTRIGGER_SESSION:
1093 ALOGW("%s: transaction %d received from PID %d",
1094 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001095 // return status only for non void methods
1096 switch (code) {
1097 case RELEASE_OUTPUT:
1098 case RELEASE_INPUT:
1099 break;
1100 default:
1101 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1102 break;
1103 }
1104 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001105 default:
1106 break;
1107 }
1108
Eric Laurent4980df22018-01-26 18:04:09 -08001109 // make sure the following transactions come from system components
1110 switch (code) {
1111 case SET_DEVICE_CONNECTION_STATE:
1112 case HANDLE_DEVICE_CONFIG_CHANGE:
1113 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001114//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1115// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001116 case INIT_STREAM_VOLUME:
1117 case SET_STREAM_VOLUME:
1118 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001119 case SET_MASTER_MONO:
1120 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001121 case STOP_AUDIO_SOURCE:
1122 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001123 case SET_SURROUND_FORMAT_ENABLED:
1124 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001125 case SET_A11Y_SERVICES_UIDS:
1126 case SET_UID_DEVICE_AFFINITY:
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001127 case REMOVE_UID_DEVICE_AFFINITY:
1128 case GET_OFFLOAD_FORMATS_A2DP: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001129 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001130 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1131 __func__, code, IPCThreadState::self()->getCallingPid(),
1132 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001133 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1134 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001135 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001136 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001137 default:
1138 break;
1139 }
1140
Eric Laurent39b09b52018-06-29 12:24:40 -07001141 std::string tag("IAudioPolicyService command " + std::to_string(code));
1142 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001143
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001144 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001145 case SET_DEVICE_CONNECTION_STATE: {
1146 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001147 audio_devices_t device =
1148 static_cast <audio_devices_t>(data.readInt32());
1149 audio_policy_dev_state_t state =
1150 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001151 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001152 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001153 audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001154 if (device_address == nullptr || device_name == nullptr) {
1155 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1156 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1157 } else {
1158 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1159 state,
1160 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001161 device_name,
1162 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001163 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001164 return NO_ERROR;
1165 } break;
1166
1167 case GET_DEVICE_CONNECTION_STATE: {
1168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001169 audio_devices_t device =
1170 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001171 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001172 if (device_address == nullptr) {
1173 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1174 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1175 } else {
1176 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1177 device_address)));
1178 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001179 return NO_ERROR;
1180 } break;
1181
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001182 case HANDLE_DEVICE_CONFIG_CHANGE: {
1183 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1184 audio_devices_t device =
1185 static_cast <audio_devices_t>(data.readInt32());
1186 const char *device_address = data.readCString();
1187 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001188 audio_format_t codecFormat =
1189 static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001190 if (device_address == nullptr || device_name == nullptr) {
1191 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1192 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1193 } else {
1194 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1195 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001196 device_name,
1197 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001198 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001199 return NO_ERROR;
1200 } break;
1201
Eric Laurentc2f1f072009-07-17 12:17:14 -07001202 case SET_PHONE_STATE: {
1203 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001204 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1205 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001206 return NO_ERROR;
1207 } break;
1208
Eric Laurentc2f1f072009-07-17 12:17:14 -07001209 case SET_FORCE_USE: {
1210 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001211 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1212 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001213 audio_policy_forced_cfg_t config =
1214 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001215 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1216 return NO_ERROR;
1217 } break;
1218
1219 case GET_FORCE_USE: {
1220 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001221 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1222 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001223 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1224 return NO_ERROR;
1225 } break;
1226
1227 case GET_OUTPUT: {
1228 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001229 audio_stream_type_t stream =
1230 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001231 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001232 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001233 return NO_ERROR;
1234 } break;
1235
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001236 case GET_OUTPUT_FOR_ATTR: {
1237 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001238 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001239 bool hasAttributes = data.readInt32() != 0;
1240 if (hasAttributes) {
1241 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001242 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001243 }
1244 audio_session_t session = (audio_session_t)data.readInt32();
1245 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1246 bool hasStream = data.readInt32() != 0;
1247 if (hasStream) {
1248 stream = (audio_stream_type_t)data.readInt32();
1249 }
Nadav Bar766fb022018-01-07 12:18:03 +02001250 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001251 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001252 audio_config_t config;
1253 memset(&config, 0, sizeof(audio_config_t));
1254 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001255 audio_output_flags_t flags =
1256 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001257 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001258 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001259 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001260 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001261 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001262 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001263 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001264 reply->writeInt32(status);
1265 reply->writeInt32(output);
1266 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001267 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001268 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001269 return NO_ERROR;
1270 } break;
1271
Eric Laurentc2f1f072009-07-17 12:17:14 -07001272 case START_OUTPUT: {
1273 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001274 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1275 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001276 return NO_ERROR;
1277 } break;
1278
1279 case STOP_OUTPUT: {
1280 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001281 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1282 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001283 return NO_ERROR;
1284 } break;
1285
1286 case RELEASE_OUTPUT: {
1287 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001288 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1289 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001290 return NO_ERROR;
1291 } break;
1292
Eric Laurentcaf7f482014-11-25 17:50:47 -08001293 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001294 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001295 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001296 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001297 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001298 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001299 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001300 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001301 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001302 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001303 audio_config_base_t config;
1304 memset(&config, 0, sizeof(audio_config_base_t));
1305 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001306 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001307 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001308 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001309 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001310 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001311 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001312 reply->writeInt32(status);
1313 if (status == NO_ERROR) {
1314 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001315 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001316 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001317 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001318 return NO_ERROR;
1319 } break;
1320
1321 case START_INPUT: {
1322 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001323 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001324 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001325 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001326 return NO_ERROR;
1327 } break;
1328
1329 case STOP_INPUT: {
1330 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001331 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1332 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001333 return NO_ERROR;
1334 } break;
1335
1336 case RELEASE_INPUT: {
1337 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001338 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1339 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001340 return NO_ERROR;
1341 } break;
1342
1343 case INIT_STREAM_VOLUME: {
1344 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001345 audio_stream_type_t stream =
1346 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001347 int indexMin = data.readInt32();
1348 int indexMax = data.readInt32();
1349 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1350 return NO_ERROR;
1351 } break;
1352
1353 case SET_STREAM_VOLUME: {
1354 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001355 audio_stream_type_t stream =
1356 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001357 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001358 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1359 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1360 index,
1361 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001362 return NO_ERROR;
1363 } break;
1364
1365 case GET_STREAM_VOLUME: {
1366 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001367 audio_stream_type_t stream =
1368 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001369 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001370 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001371 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001372 reply->writeInt32(index);
1373 reply->writeInt32(static_cast <uint32_t>(status));
1374 return NO_ERROR;
1375 } break;
1376
Eric Laurentde070132010-07-13 04:45:46 -07001377 case GET_STRATEGY_FOR_STREAM: {
1378 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001379 audio_stream_type_t stream =
1380 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001381 reply->writeInt32(getStrategyForStream(stream));
1382 return NO_ERROR;
1383 } break;
1384
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001385 case GET_DEVICES_FOR_STREAM: {
1386 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001387 audio_stream_type_t stream =
1388 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001389 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1390 return NO_ERROR;
1391 } break;
1392
Eric Laurentde070132010-07-13 04:45:46 -07001393 case GET_OUTPUT_FOR_EFFECT: {
1394 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001395 effect_descriptor_t desc = {};
1396 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1397 android_errorWriteLog(0x534e4554, "73126106");
1398 }
1399 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001400 audio_io_handle_t output = getOutputForEffect(&desc);
1401 reply->writeInt32(static_cast <int>(output));
1402 return NO_ERROR;
1403 } break;
1404
1405 case REGISTER_EFFECT: {
1406 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001407 effect_descriptor_t desc = {};
1408 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1409 android_errorWriteLog(0x534e4554, "73126106");
1410 }
1411 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001412 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001413 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001414 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001415 int id = data.readInt32();
1416 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001417 io,
Eric Laurentde070132010-07-13 04:45:46 -07001418 strategy,
1419 session,
1420 id)));
1421 return NO_ERROR;
1422 } break;
1423
1424 case UNREGISTER_EFFECT: {
1425 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1426 int id = data.readInt32();
1427 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1428 return NO_ERROR;
1429 } break;
1430
Eric Laurentdb7c0792011-08-10 10:37:50 -07001431 case SET_EFFECT_ENABLED: {
1432 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1433 int id = data.readInt32();
1434 bool enabled = static_cast <bool>(data.readInt32());
1435 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1436 return NO_ERROR;
1437 } break;
1438
Eric Laurenteda6c362011-02-02 09:33:30 -08001439 case IS_STREAM_ACTIVE: {
1440 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001441 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001442 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001443 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001444 return NO_ERROR;
1445 } break;
1446
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001447 case IS_STREAM_ACTIVE_REMOTELY: {
1448 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1449 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1450 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001451 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001452 return NO_ERROR;
1453 } break;
1454
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001455 case IS_SOURCE_ACTIVE: {
1456 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1457 audio_source_t source = (audio_source_t) data.readInt32();
1458 reply->writeInt32( isSourceActive(source));
1459 return NO_ERROR;
1460 }
1461
Eric Laurent57dae992011-07-24 13:36:09 -07001462 case QUERY_DEFAULT_PRE_PROCESSING: {
1463 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001464 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001465 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001466 if (count > AudioEffect::kMaxPreProcessing) {
1467 count = AudioEffect::kMaxPreProcessing;
1468 }
Eric Laurent57dae992011-07-24 13:36:09 -07001469 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001470 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001471 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1472 reply->writeInt32(status);
1473 if (status != NO_ERROR && status != NO_MEMORY) {
1474 retCount = 0;
1475 }
1476 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001477 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001478 if (retCount < count) {
1479 count = retCount;
1480 }
1481 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1482 }
1483 delete[] descriptors;
1484 return status;
1485 }
1486
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001487 case IS_OFFLOAD_SUPPORTED: {
1488 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001489 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001490 data.read(&info, sizeof(audio_offload_info_t));
1491 bool isSupported = isOffloadSupported(info);
1492 reply->writeInt32(isSupported);
1493 return NO_ERROR;
1494 }
1495
Michael Chana94fbb22018-04-24 14:31:19 +10001496 case IS_DIRECT_OUTPUT_SUPPORTED: {
1497 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1498 audio_config_base_t config = {};
1499 audio_attributes_t attributes = {};
1500 status_t status = data.read(&config, sizeof(audio_config_base_t));
1501 if (status != NO_ERROR) return status;
1502 status = data.read(&attributes, sizeof(audio_attributes_t));
1503 if (status != NO_ERROR) return status;
1504 reply->writeInt32(isDirectOutputSupported(config, attributes));
1505 return NO_ERROR;
1506 }
1507
Eric Laurent203b1a12014-04-01 10:34:16 -07001508 case LIST_AUDIO_PORTS: {
1509 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1510 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1511 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1512 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001513 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1514 numPortsReq = MAX_ITEMS_PER_LIST;
1515 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001516 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001517 struct audio_port *ports =
1518 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001519 if (ports == NULL) {
1520 reply->writeInt32(NO_MEMORY);
1521 reply->writeInt32(0);
1522 return NO_ERROR;
1523 }
1524 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001525 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1526 reply->writeInt32(status);
1527 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001528
1529 if (status == NO_ERROR) {
1530 if (numPortsReq > numPorts) {
1531 numPortsReq = numPorts;
1532 }
1533 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1534 reply->writeInt32(generation);
1535 }
1536 free(ports);
1537 return NO_ERROR;
1538 }
1539
1540 case GET_AUDIO_PORT: {
1541 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001542 struct audio_port port = {};
1543 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1544 ALOGE("b/23912202");
1545 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001546 status_t status = getAudioPort(&port);
1547 reply->writeInt32(status);
1548 if (status == NO_ERROR) {
1549 reply->write(&port, sizeof(struct audio_port));
1550 }
1551 return NO_ERROR;
1552 }
1553
1554 case CREATE_AUDIO_PATCH: {
1555 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001556 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001557 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001558 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001559 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1560 ALOGE("b/23912202");
1561 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001562 status_t status = createAudioPatch(&patch, &handle);
1563 reply->writeInt32(status);
1564 if (status == NO_ERROR) {
1565 reply->write(&handle, sizeof(audio_patch_handle_t));
1566 }
1567 return NO_ERROR;
1568 }
1569
1570 case RELEASE_AUDIO_PATCH: {
1571 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001572 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001573 data.read(&handle, sizeof(audio_patch_handle_t));
1574 status_t status = releaseAudioPatch(handle);
1575 reply->writeInt32(status);
1576 return NO_ERROR;
1577 }
1578
1579 case LIST_AUDIO_PATCHES: {
1580 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1581 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001582 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1583 numPatchesReq = MAX_ITEMS_PER_LIST;
1584 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001585 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001586 struct audio_patch *patches =
1587 (struct audio_patch *)calloc(numPatchesReq,
1588 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001589 if (patches == NULL) {
1590 reply->writeInt32(NO_MEMORY);
1591 reply->writeInt32(0);
1592 return NO_ERROR;
1593 }
1594 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001595 status_t status = listAudioPatches(&numPatches, patches, &generation);
1596 reply->writeInt32(status);
1597 reply->writeInt32(numPatches);
1598 if (status == NO_ERROR) {
1599 if (numPatchesReq > numPatches) {
1600 numPatchesReq = numPatches;
1601 }
1602 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1603 reply->writeInt32(generation);
1604 }
1605 free(patches);
1606 return NO_ERROR;
1607 }
1608
1609 case SET_AUDIO_PORT_CONFIG: {
1610 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001611 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001612 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001613 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001614 status_t status = setAudioPortConfig(&config);
1615 reply->writeInt32(status);
1616 return NO_ERROR;
1617 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001618
Eric Laurentb52c1522014-05-20 11:27:36 -07001619 case REGISTER_CLIENT: {
1620 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1621 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1622 data.readStrongBinder());
1623 registerClient(client);
1624 return NO_ERROR;
1625 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001626
Eric Laurente8726fe2015-06-26 09:39:24 -07001627 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1628 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1629 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1630 return NO_ERROR;
1631 } break;
1632
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001633 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1634 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1635 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1636 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001637 audio_session_t session = AUDIO_SESSION_NONE;
1638 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1639 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001640 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1641 reply->writeInt32(status);
1642 if (status == NO_ERROR) {
1643 reply->writeInt32(session);
1644 reply->writeInt32(ioHandle);
1645 reply->writeInt32(device);
1646 }
1647 return NO_ERROR;
1648 } break;
1649
1650 case RELEASE_SOUNDTRIGGER_SESSION: {
1651 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1652 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1653 data.readStrongBinder());
1654 audio_session_t session = (audio_session_t)data.readInt32();
1655 status_t status = releaseSoundTriggerSession(session);
1656 reply->writeInt32(status);
1657 return NO_ERROR;
1658 } break;
1659
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001660 case GET_PHONE_STATE: {
1661 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1662 reply->writeInt32((int32_t)getPhoneState());
1663 return NO_ERROR;
1664 } break;
1665
Eric Laurentbaac1832014-12-01 17:52:59 -08001666 case REGISTER_POLICY_MIXES: {
1667 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1668 bool registration = data.readInt32() == 1;
1669 Vector<AudioMix> mixes;
1670 size_t size = (size_t)data.readInt32();
1671 if (size > MAX_MIXES_PER_POLICY) {
1672 size = MAX_MIXES_PER_POLICY;
1673 }
1674 for (size_t i = 0; i < size; i++) {
1675 AudioMix mix;
1676 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1677 mixes.add(mix);
1678 }
1679 }
1680 status_t status = registerPolicyMixes(mixes, registration);
1681 reply->writeInt32(status);
1682 return NO_ERROR;
1683 } break;
1684
Eric Laurent554a2772015-04-10 11:29:24 -07001685 case START_AUDIO_SOURCE: {
1686 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001687 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001688 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001689 (void)sanitizeAudioPortConfig(&source);
1690 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001691 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001692 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001693 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1694 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001695 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001696 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001697 return NO_ERROR;
1698 } break;
1699
1700 case STOP_AUDIO_SOURCE: {
1701 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001702 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1703 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001704 reply->writeInt32(status);
1705 return NO_ERROR;
1706 } break;
1707
Andy Hung2ddee192015-12-18 17:34:44 -08001708 case SET_MASTER_MONO: {
1709 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1710 bool mono = static_cast<bool>(data.readInt32());
1711 status_t status = setMasterMono(mono);
1712 reply->writeInt32(status);
1713 return NO_ERROR;
1714 } break;
1715
1716 case GET_MASTER_MONO: {
1717 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1718 bool mono;
1719 status_t status = getMasterMono(&mono);
1720 reply->writeInt32(status);
1721 if (status == NO_ERROR) {
1722 reply->writeInt32(static_cast<int32_t>(mono));
1723 }
1724 return NO_ERROR;
1725 } break;
1726
Eric Laurentac9cef52017-06-09 15:46:26 -07001727 case GET_STREAM_VOLUME_DB: {
1728 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1729 audio_stream_type_t stream =
1730 static_cast <audio_stream_type_t>(data.readInt32());
1731 int index = static_cast <int>(data.readInt32());
1732 audio_devices_t device =
1733 static_cast <audio_devices_t>(data.readUint32());
1734 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1735 return NO_ERROR;
1736 }
1737
jiabin81772902018-04-02 17:52:27 -07001738 case GET_SURROUND_FORMATS: {
1739 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1740 unsigned int numSurroundFormatsReq = data.readUint32();
1741 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1742 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1743 }
1744 bool reported = data.readBool();
1745 unsigned int numSurroundFormats = numSurroundFormatsReq;
1746 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1747 numSurroundFormats, sizeof(audio_format_t));
1748 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1749 if (numSurroundFormatsReq > 0 &&
1750 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1751 free(surroundFormats);
1752 free(surroundFormatsEnabled);
1753 reply->writeInt32(NO_MEMORY);
1754 return NO_ERROR;
1755 }
1756 status_t status = getSurroundFormats(
1757 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1758 reply->writeInt32(status);
1759
1760 if (status == NO_ERROR) {
1761 reply->writeUint32(numSurroundFormats);
1762 if (numSurroundFormatsReq > numSurroundFormats) {
1763 numSurroundFormatsReq = numSurroundFormats;
1764 }
1765 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1766 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1767 }
1768 free(surroundFormats);
1769 free(surroundFormatsEnabled);
1770 return NO_ERROR;
1771 }
1772
1773 case SET_SURROUND_FORMAT_ENABLED: {
1774 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1775 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1776 bool enabled = data.readBool();
1777 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1778 reply->writeInt32(status);
1779 return NO_ERROR;
1780 }
1781
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001782 case GET_OFFLOAD_FORMATS_A2DP: {
1783 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1784 std::vector<audio_format_t> encodingFormats;
1785 status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
1786 reply->writeInt32(status);
1787 if (status != NO_ERROR) {
1788 return NO_ERROR;
1789 }
1790 reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
1791 for (size_t i = 0; i < encodingFormats.size(); i++)
1792 reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
1793 return NO_ERROR;
1794 }
1795
1796
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001797 case ADD_STREAM_DEFAULT_EFFECT: {
1798 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1799 effect_uuid_t type;
1800 status_t status = data.read(&type, sizeof(effect_uuid_t));
1801 if (status != NO_ERROR) {
1802 return status;
1803 }
1804 String16 opPackageName;
1805 status = data.readString16(&opPackageName);
1806 if (status != NO_ERROR) {
1807 return status;
1808 }
1809 effect_uuid_t uuid;
1810 status = data.read(&uuid, sizeof(effect_uuid_t));
1811 if (status != NO_ERROR) {
1812 return status;
1813 }
1814 int32_t priority = data.readInt32();
1815 audio_usage_t usage = (audio_usage_t) data.readInt32();
1816 audio_unique_id_t id = 0;
1817 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1818 opPackageName,
1819 &uuid,
1820 priority,
1821 usage,
1822 &id)));
1823 reply->writeInt32(id);
1824 return NO_ERROR;
1825 }
1826
1827 case REMOVE_STREAM_DEFAULT_EFFECT: {
1828 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1829 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1830 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1831 return NO_ERROR;
1832 }
1833
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001834 case ADD_SOURCE_DEFAULT_EFFECT: {
1835 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1836 effect_uuid_t type;
1837 status_t status = data.read(&type, sizeof(effect_uuid_t));
1838 if (status != NO_ERROR) {
1839 return status;
1840 }
1841 String16 opPackageName;
1842 status = data.readString16(&opPackageName);
1843 if (status != NO_ERROR) {
1844 return status;
1845 }
1846 effect_uuid_t uuid;
1847 status = data.read(&uuid, sizeof(effect_uuid_t));
1848 if (status != NO_ERROR) {
1849 return status;
1850 }
1851 int32_t priority = data.readInt32();
1852 audio_source_t source = (audio_source_t) data.readInt32();
1853 audio_unique_id_t id = 0;
1854 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1855 opPackageName,
1856 &uuid,
1857 priority,
1858 source,
1859 &id)));
1860 reply->writeInt32(id);
1861 return NO_ERROR;
1862 }
1863
1864 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1865 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1866 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1867 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1868 return NO_ERROR;
1869 }
1870
Eric Laurentb78763e2018-10-17 10:08:02 -07001871 case SET_ASSISTANT_UID: {
1872 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1873 int32_t uid;
1874 status_t status = data.readInt32(&uid);
1875 if (status != NO_ERROR) {
1876 return status;
1877 }
1878 status = setAssistantUid(uid);
1879 reply->writeInt32(static_cast <int32_t>(status));
1880 return NO_ERROR;
1881 }
1882
1883 case SET_A11Y_SERVICES_UIDS: {
1884 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1885 std::vector<uid_t> uids;
1886 int32_t size;
1887 status_t status = data.readInt32(&size);
1888 if (status != NO_ERROR) {
1889 return status;
1890 }
1891 if (size > MAX_ITEMS_PER_LIST) {
1892 size = MAX_ITEMS_PER_LIST;
1893 }
1894 for (int32_t i = 0; i < size; i++) {
1895 int32_t uid;
1896 status = data.readInt32(&uid);
1897 if (status != NO_ERROR) {
1898 return status;
1899 }
1900 uids.push_back(uid);
1901 }
1902 status = setA11yServicesUids(uids);
1903 reply->writeInt32(static_cast <int32_t>(status));
1904 return NO_ERROR;
1905 }
1906
jiabin6012f912018-11-02 17:06:30 -07001907 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
1908 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1909 bool isSupported = isHapticPlaybackSupported();
1910 reply->writeBool(isSupported);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001911 return NO_ERROR;
1912 }
1913
1914 case SET_UID_DEVICE_AFFINITY: {
1915 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1916 const uid_t uid = (uid_t) data.readInt32();
1917 Vector<AudioDeviceTypeAddr> devices;
1918 size_t size = (size_t)data.readInt32();
1919 for (size_t i = 0; i < size; i++) {
1920 AudioDeviceTypeAddr device;
1921 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
1922 devices.add(device);
1923 }
1924 }
1925 status_t status = setUidDeviceAffinities(uid, devices);
1926 reply->writeInt32(status);
1927 return NO_ERROR;
1928 }
1929
1930 case REMOVE_UID_DEVICE_AFFINITY: {
1931 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1932 const uid_t uid = (uid_t) data.readInt32();
1933 status_t status = removeUidDeviceAffinities(uid);
1934 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07001935 return NO_ERROR;
1936 }
1937
Eric Laurentc2f1f072009-07-17 12:17:14 -07001938 default:
1939 return BBinder::onTransact(code, data, reply, flags);
1940 }
1941}
1942
Andy Hungb0272092018-04-12 11:06:56 -07001943/** returns true if string overflow was prevented by zero termination */
1944template <size_t size>
1945static bool preventStringOverflow(char (&s)[size]) {
1946 if (strnlen(s, size) < size) return false;
1947 s[size - 1] = '\0';
1948 return true;
1949}
1950
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001951void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1952{
1953 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1954 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1955 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1956 }
1957 attr->tags[tagsMaxSize - 1] = '\0';
1958}
1959
Andy Hungb0272092018-04-12 11:06:56 -07001960/** returns BAD_VALUE if sanitization was required. */
1961status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1962{
1963 if (preventStringOverflow(desc->name)
1964 | /* always */ preventStringOverflow(desc->implementor)) {
1965 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1966 return BAD_VALUE;
1967 }
1968 return NO_ERROR;
1969}
1970
1971/** returns BAD_VALUE if sanitization was required. */
1972status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1973{
1974 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1975 preventStringOverflow(config->ext.device.address)) {
1976 return BAD_VALUE;
1977 }
1978 return NO_ERROR;
1979}
1980
Eric Laurentc2f1f072009-07-17 12:17:14 -07001981// ----------------------------------------------------------------------------
1982
Glenn Kasten40bc9062015-03-20 09:09:33 -07001983} // namespace android