blob: bf98c60299b6fcfc635da0899190356877873971 [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,
François Gaffiecfe17322018-11-07 13:41:29 +010054 SET_VOLUME_ATTRIBUTES,
55 GET_VOLUME_ATTRIBUTES,
56 GET_MIN_VOLUME_FOR_ATTRIBUTES,
57 GET_MAX_VOLUME_FOR_ATTRIBUTES,
Eric Laurentde070132010-07-13 04:45:46 -070058 GET_STRATEGY_FOR_STREAM,
59 GET_OUTPUT_FOR_EFFECT,
60 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080061 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080062 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070063 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080064 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070065 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080066 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000067 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070068 IS_OFFLOAD_SUPPORTED,
Michael Chana94fbb22018-04-24 14:31:19 +100069 IS_DIRECT_OUTPUT_SUPPORTED,
Eric Laurent203b1a12014-04-01 10:34:16 -070070 LIST_AUDIO_PORTS,
71 GET_AUDIO_PORT,
72 CREATE_AUDIO_PATCH,
73 RELEASE_AUDIO_PATCH,
74 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070075 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070076 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070077 GET_OUTPUT_FOR_ATTR,
78 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070079 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080080 GET_PHONE_STATE,
81 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070082 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070083 STOP_AUDIO_SOURCE,
84 SET_AUDIO_PORT_CALLBACK_ENABLED,
François Gaffiecfe17322018-11-07 13:41:29 +010085 SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080086 SET_MASTER_MONO,
87 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070088 GET_STREAM_VOLUME_DB,
89 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070090 SET_SURROUND_FORMAT_ENABLED,
91 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070092 REMOVE_STREAM_DEFAULT_EFFECT,
93 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070094 REMOVE_SOURCE_DEFAULT_EFFECT,
95 SET_ASSISTANT_UID,
96 SET_A11Y_SERVICES_UIDS,
jiabin6012f912018-11-02 17:06:30 -070097 IS_HAPTIC_PLAYBACK_SUPPORTED,
Jean-Michel Trivibda70da2018-12-19 07:30:15 -080098 SET_UID_DEVICE_AFFINITY,
99 REMOVE_UID_DEVICE_AFFINITY,
François Gaffied0ba9ed2018-11-05 11:50:42 +0100100 GET_OFFLOAD_FORMATS_A2DP,
101 LIST_AUDIO_PRODUCT_STRATEGIES,
102 GET_STRATEGY_FOR_ATTRIBUTES,
François Gaffie4b2018b2018-11-07 11:18:59 +0100103 LIST_AUDIO_VOLUME_GROUPS,
Kevin Rocardb99cc752019-03-21 20:52:24 -0700104 GET_VOLUME_GROUP_FOR_ATTRIBUTES,
105 SET_ALLOWED_CAPTURE_POLICY,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700106};
107
Eric Laurent1d670b12015-02-06 10:44:24 -0800108#define MAX_ITEMS_PER_LIST 1024
109
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
111{
112public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700113 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700114 : BpInterface<IAudioPolicyService>(impl)
115 {
116 }
117
118 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700119 audio_devices_t device,
120 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800121 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800122 const char *device_name,
123 audio_format_t encodedFormat)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700124 {
125 Parcel data, reply;
126 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
127 data.writeInt32(static_cast <uint32_t>(device));
128 data.writeInt32(static_cast <uint32_t>(state));
129 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800130 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800131 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700132 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
133 return static_cast <status_t> (reply.readInt32());
134 }
135
Dima Zavinfce7a472011-04-19 22:30:36 -0700136 virtual audio_policy_dev_state_t getDeviceConnectionState(
137 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700138 const char *device_address)
139 {
140 Parcel data, reply;
141 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
142 data.writeInt32(static_cast <uint32_t>(device));
143 data.writeCString(device_address);
144 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700145 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 }
147
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800148 virtual status_t handleDeviceConfigChange(audio_devices_t device,
149 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800150 const char *device_name,
151 audio_format_t encodedFormat)
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800152 {
153 Parcel data, reply;
154 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
155 data.writeInt32(static_cast <uint32_t>(device));
156 data.writeCString(device_address);
157 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800158 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800159 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
160 return static_cast <status_t> (reply.readInt32());
161 }
162
Glenn Kastenf78aee72012-01-04 11:00:47 -0800163 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164 {
165 Parcel data, reply;
166 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
167 data.writeInt32(state);
168 remote()->transact(SET_PHONE_STATE, data, &reply);
169 return static_cast <status_t> (reply.readInt32());
170 }
171
Dima Zavinfce7a472011-04-19 22:30:36 -0700172 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
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 data.writeInt32(static_cast <uint32_t>(config));
178 remote()->transact(SET_FORCE_USE, data, &reply);
179 return static_cast <status_t> (reply.readInt32());
180 }
181
Dima Zavinfce7a472011-04-19 22:30:36 -0700182 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700183 {
184 Parcel data, reply;
185 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
186 data.writeInt32(static_cast <uint32_t>(usage));
187 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700188 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700189 }
190
Eric Laurentf4e63452017-11-06 19:31:46 +0000191 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700192 {
193 Parcel data, reply;
194 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
195 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700196 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700197 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700198 }
199
Kevin Rocard153f92d2018-12-18 18:33:28 -0800200 status_t getOutputForAttr(const audio_attributes_t *attr,
201 audio_io_handle_t *output,
202 audio_session_t session,
203 audio_stream_type_t *stream,
204 pid_t pid,
205 uid_t uid,
206 const audio_config_t *config,
207 audio_output_flags_t flags,
208 audio_port_handle_t *selectedDeviceId,
209 audio_port_handle_t *portId,
210 std::vector<audio_io_handle_t> *secondaryOutputs) override
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700211 {
212 Parcel data, reply;
213 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
214 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800215 if (stream == NULL) {
216 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
217 return BAD_VALUE;
218 }
219 if (*stream == AUDIO_STREAM_DEFAULT) {
220 ALOGE("getOutputForAttr unspecified stream type");
221 return BAD_VALUE;
222 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700223 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800224 if (output == NULL) {
225 ALOGE("getOutputForAttr NULL output - shouldn't happen");
226 return BAD_VALUE;
227 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700228 if (selectedDeviceId == NULL) {
229 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
230 return BAD_VALUE;
231 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800232 if (portId == NULL) {
233 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
234 return BAD_VALUE;
235 }
Kevin Rocard153f92d2018-12-18 18:33:28 -0800236 if (secondaryOutputs == NULL) {
237 ALOGE("getOutputForAttr NULL secondaryOutputs - shouldn't happen");
238 return BAD_VALUE;
239 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800240 if (attr == NULL) {
241 data.writeInt32(0);
242 } else {
243 data.writeInt32(1);
244 data.write(attr, sizeof(audio_attributes_t));
245 }
246 data.writeInt32(session);
247 if (stream == NULL) {
248 data.writeInt32(0);
249 } else {
250 data.writeInt32(1);
251 data.writeInt32(*stream);
252 }
Nadav Bar766fb022018-01-07 12:18:03 +0200253 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700254 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800255 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700256 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700257 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800258 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800259 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
260 if (status != NO_ERROR) {
261 return status;
262 }
263 status = (status_t)reply.readInt32();
264 if (status != NO_ERROR) {
265 return status;
266 }
267 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800268 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800269 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800270 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800271 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700272 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800273 *portId = (audio_port_handle_t)reply.readInt32();
Kevin Rocard153f92d2018-12-18 18:33:28 -0800274 secondaryOutputs->resize(reply.readInt32());
275 return reply.read(secondaryOutputs->data(),
276 secondaryOutputs->size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700277 }
278
Eric Laurentd7fe0862018-07-14 16:48:01 -0700279 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700283 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700284 remote()->transact(START_OUTPUT, data, &reply);
285 return static_cast <status_t> (reply.readInt32());
286 }
287
Eric Laurentd7fe0862018-07-14 16:48:01 -0700288 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700292 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 remote()->transact(STOP_OUTPUT, data, &reply);
294 return static_cast <status_t> (reply.readInt32());
295 }
296
Eric Laurentd7fe0862018-07-14 16:48:01 -0700297 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700301 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700302 remote()->transact(RELEASE_OUTPUT, data, &reply);
303 }
304
Eric Laurentcaf7f482014-11-25 17:50:47 -0800305 virtual status_t getInputForAttr(const audio_attributes_t *attr,
306 audio_io_handle_t *input,
307 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700308 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700309 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800310 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800311 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600312 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700313 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800314 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800318 if (attr == NULL) {
319 ALOGE("getInputForAttr NULL attr - shouldn't happen");
320 return BAD_VALUE;
321 }
322 if (input == NULL) {
323 ALOGE("getInputForAttr NULL input - shouldn't happen");
324 return BAD_VALUE;
325 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700326 if (selectedDeviceId == NULL) {
327 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
328 return BAD_VALUE;
329 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800330 if (portId == NULL) {
331 ALOGE("getInputForAttr NULL portId - shouldn't happen");
332 return BAD_VALUE;
333 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800334 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700335 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800336 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700337 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700338 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800339 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800340 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700341 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700342 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800343 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800344 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
345 if (status != NO_ERROR) {
346 return status;
347 }
348 status = reply.readInt32();
349 if (status != NO_ERROR) {
350 return status;
351 }
352 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700353 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800354 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800355 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 }
357
Eric Laurent4eb58f12018-12-07 16:41:02 -0800358 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700359 {
360 Parcel data, reply;
361 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800362 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700363 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800364 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800365 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700366 }
367
Eric Laurentfee19762018-01-29 18:44:13 -0800368 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 {
370 Parcel data, reply;
371 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800372 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700373 remote()->transact(STOP_INPUT, data, &reply);
374 return static_cast <status_t> (reply.readInt32());
375 }
376
Eric Laurentfee19762018-01-29 18:44:13 -0800377 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 {
379 Parcel data, reply;
380 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800381 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 remote()->transact(RELEASE_INPUT, data, &reply);
383 }
384
Dima Zavinfce7a472011-04-19 22:30:36 -0700385 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700386 int indexMin,
387 int indexMax)
388 {
389 Parcel data, reply;
390 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
391 data.writeInt32(static_cast <uint32_t>(stream));
392 data.writeInt32(indexMin);
393 data.writeInt32(indexMax);
394 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
395 return static_cast <status_t> (reply.readInt32());
396 }
397
Eric Laurent83844cc2011-11-18 16:43:31 -0800398 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
399 int index,
400 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
404 data.writeInt32(static_cast <uint32_t>(stream));
405 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800406 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700407 remote()->transact(SET_STREAM_VOLUME, data, &reply);
408 return static_cast <status_t> (reply.readInt32());
409 }
410
Eric Laurent83844cc2011-11-18 16:43:31 -0800411 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
412 int *index,
413 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
417 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800418 data.writeInt32(static_cast <uint32_t>(device));
419
Eric Laurentc2f1f072009-07-17 12:17:14 -0700420 remote()->transact(GET_STREAM_VOLUME, data, &reply);
421 int lIndex = reply.readInt32();
422 if (index) *index = lIndex;
423 return static_cast <status_t> (reply.readInt32());
424 }
Eric Laurentde070132010-07-13 04:45:46 -0700425
François Gaffiecfe17322018-11-07 13:41:29 +0100426 virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index,
427 audio_devices_t device)
428 {
429 Parcel data, reply;
430 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
431 data.write(&attr, sizeof(audio_attributes_t));
432 data.writeInt32(index);
433 data.writeInt32(static_cast <uint32_t>(device));
434 status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply);
435 if (status != NO_ERROR) {
436 return status;
437 }
438 return static_cast <status_t> (reply.readInt32());
439 }
440 virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index,
441 audio_devices_t device)
442 {
443 Parcel data, reply;
444 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
445 data.write(&attr, sizeof(audio_attributes_t));
446 data.writeInt32(static_cast <uint32_t>(device));
447 status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply);
448 if (status != NO_ERROR) {
449 return status;
450 }
451 status = static_cast <status_t> (reply.readInt32());
452 if (status != NO_ERROR) {
453 return status;
454 }
455 index = reply.readInt32();
456 return NO_ERROR;
457 }
458 virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
459 {
460 Parcel data, reply;
461 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
462 data.write(&attr, sizeof(audio_attributes_t));
463 status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply);
464 if (status != NO_ERROR) {
465 return status;
466 }
467 status = static_cast <status_t> (reply.readInt32());
468 if (status != NO_ERROR) {
469 return status;
470 }
471 index = reply.readInt32();
472 return NO_ERROR;
473 }
474 virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
475 {
476 Parcel data, reply;
477 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
478 data.write(&attr, sizeof(audio_attributes_t));
479 status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply);
480 if (status != NO_ERROR) {
481 return status;
482 }
483 status = static_cast <status_t> (reply.readInt32());
484 if (status != NO_ERROR) {
485 return status;
486 }
487 index = reply.readInt32();
488 return NO_ERROR;
489 }
Dima Zavinfce7a472011-04-19 22:30:36 -0700490 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700491 {
492 Parcel data, reply;
493 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
494 data.writeInt32(static_cast <uint32_t>(stream));
495 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
François Gaffiec005e562018-11-06 15:04:49 +0100496 return reply.readUint32();
Eric Laurentde070132010-07-13 04:45:46 -0700497 }
498
Eric Laurent63742522012-03-08 13:42:42 -0800499 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800500 {
501 Parcel data, reply;
502 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
503 data.writeInt32(static_cast <uint32_t>(stream));
504 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800505 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800506 }
507
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700508 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700509 {
510 Parcel data, reply;
511 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
512 data.write(desc, sizeof(effect_descriptor_t));
513 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
514 return static_cast <audio_io_handle_t> (reply.readInt32());
515 }
516
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700517 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700518 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700519 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800520 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700521 int id)
522 {
523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
525 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700526 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700527 data.writeInt32(strategy);
528 data.writeInt32(session);
529 data.writeInt32(id);
530 remote()->transact(REGISTER_EFFECT, data, &reply);
531 return static_cast <status_t> (reply.readInt32());
532 }
533
534 virtual status_t unregisterEffect(int id)
535 {
536 Parcel data, reply;
537 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
538 data.writeInt32(id);
539 remote()->transact(UNREGISTER_EFFECT, data, &reply);
540 return static_cast <status_t> (reply.readInt32());
541 }
542
Eric Laurentdb7c0792011-08-10 10:37:50 -0700543 virtual status_t setEffectEnabled(int id, bool enabled)
544 {
545 Parcel data, reply;
546 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
547 data.writeInt32(id);
548 data.writeInt32(enabled);
549 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
550 return static_cast <status_t> (reply.readInt32());
551 }
552
Glenn Kastenfff6d712012-01-12 16:38:12 -0800553 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800554 {
555 Parcel data, reply;
556 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800557 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800558 data.writeInt32(inPastMs);
559 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
560 return reply.readInt32();
561 }
Eric Laurent57dae992011-07-24 13:36:09 -0700562
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800563 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
564 {
565 Parcel data, reply;
566 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
567 data.writeInt32((int32_t) stream);
568 data.writeInt32(inPastMs);
569 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
570 return reply.readInt32();
571 }
572
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700573 virtual bool isSourceActive(audio_source_t source) const
574 {
575 Parcel data, reply;
576 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
577 data.writeInt32((int32_t) source);
578 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
579 return reply.readInt32();
580 }
581
Glenn Kastend848eb42016-03-08 13:42:11 -0800582 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700583 effect_descriptor_t *descriptors,
584 uint32_t *count)
585 {
586 if (descriptors == NULL || count == NULL) {
587 return BAD_VALUE;
588 }
589 Parcel data, reply;
590 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
591 data.writeInt32(audioSession);
592 data.writeInt32(*count);
593 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
594 if (status != NO_ERROR) {
595 return status;
596 }
597 status = static_cast <status_t> (reply.readInt32());
598 uint32_t retCount = reply.readInt32();
599 if (retCount != 0) {
600 uint32_t numDesc = (retCount < *count) ? retCount : *count;
601 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
602 }
603 *count = retCount;
604 return status;
605 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000606
Kevin Rocardb99cc752019-03-21 20:52:24 -0700607 status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
608 Parcel data, reply;
609 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
610 data.writeInt32(uid);
611 data.writeInt32(flags);
612 remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
613 return reply.readInt32();
614 }
615
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000616 virtual bool isOffloadSupported(const audio_offload_info_t& info)
617 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100618 Parcel data, reply;
619 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
620 data.write(&info, sizeof(audio_offload_info_t));
621 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700622 return reply.readInt32();
623 }
624
Michael Chana94fbb22018-04-24 14:31:19 +1000625 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
626 const audio_attributes_t& attributes) {
627 Parcel data, reply;
628 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
629 data.write(&config, sizeof(audio_config_base_t));
630 data.write(&attributes, sizeof(audio_attributes_t));
631 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
632 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
633 }
634
Eric Laurent203b1a12014-04-01 10:34:16 -0700635 virtual status_t listAudioPorts(audio_port_role_t role,
636 audio_port_type_t type,
637 unsigned int *num_ports,
638 struct audio_port *ports,
639 unsigned int *generation)
640 {
641 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
642 generation == NULL) {
643 return BAD_VALUE;
644 }
645 Parcel data, reply;
646 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
647 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
648 data.writeInt32(role);
649 data.writeInt32(type);
650 data.writeInt32(numPortsReq);
651 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
652 if (status == NO_ERROR) {
653 status = (status_t)reply.readInt32();
654 *num_ports = (unsigned int)reply.readInt32();
655 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700656 if (status == NO_ERROR) {
657 if (numPortsReq > *num_ports) {
658 numPortsReq = *num_ports;
659 }
660 if (numPortsReq > 0) {
661 reply.read(ports, numPortsReq * sizeof(struct audio_port));
662 }
663 *generation = reply.readInt32();
664 }
665 return status;
666 }
667
668 virtual status_t getAudioPort(struct audio_port *port)
669 {
670 if (port == NULL) {
671 return BAD_VALUE;
672 }
673 Parcel data, reply;
674 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
675 data.write(port, sizeof(struct audio_port));
676 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
677 if (status != NO_ERROR ||
678 (status = (status_t)reply.readInt32()) != NO_ERROR) {
679 return status;
680 }
681 reply.read(port, sizeof(struct audio_port));
682 return status;
683 }
684
685 virtual status_t createAudioPatch(const struct audio_patch *patch,
686 audio_patch_handle_t *handle)
687 {
688 if (patch == NULL || handle == NULL) {
689 return BAD_VALUE;
690 }
691 Parcel data, reply;
692 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
693 data.write(patch, sizeof(struct audio_patch));
694 data.write(handle, sizeof(audio_patch_handle_t));
695 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
696 if (status != NO_ERROR ||
697 (status = (status_t)reply.readInt32()) != NO_ERROR) {
698 return status;
699 }
700 reply.read(handle, sizeof(audio_patch_handle_t));
701 return status;
702 }
703
704 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
705 {
706 Parcel data, reply;
707 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
708 data.write(&handle, sizeof(audio_patch_handle_t));
709 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
710 if (status != NO_ERROR) {
711 status = (status_t)reply.readInt32();
712 }
713 return status;
714 }
715
716 virtual status_t listAudioPatches(unsigned int *num_patches,
717 struct audio_patch *patches,
718 unsigned int *generation)
719 {
720 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
721 generation == NULL) {
722 return BAD_VALUE;
723 }
724 Parcel data, reply;
725 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
726 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
727 data.writeInt32(numPatchesReq);
728 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
729 if (status == NO_ERROR) {
730 status = (status_t)reply.readInt32();
731 *num_patches = (unsigned int)reply.readInt32();
732 }
733 if (status == NO_ERROR) {
734 if (numPatchesReq > *num_patches) {
735 numPatchesReq = *num_patches;
736 }
737 if (numPatchesReq > 0) {
738 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
739 }
740 *generation = reply.readInt32();
741 }
742 return status;
743 }
744
745 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
746 {
747 if (config == NULL) {
748 return BAD_VALUE;
749 }
750 Parcel data, reply;
751 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
752 data.write(config, sizeof(struct audio_port_config));
753 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
754 if (status != NO_ERROR) {
755 status = (status_t)reply.readInt32();
756 }
757 return status;
758 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700759
Eric Laurentb52c1522014-05-20 11:27:36 -0700760 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
761 {
762 Parcel data, reply;
763 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800764 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700765 remote()->transact(REGISTER_CLIENT, data, &reply);
766 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700767
Eric Laurente8726fe2015-06-26 09:39:24 -0700768 virtual void setAudioPortCallbacksEnabled(bool enabled)
769 {
770 Parcel data, reply;
771 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
772 data.writeInt32(enabled ? 1 : 0);
773 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
774 }
775
François Gaffiecfe17322018-11-07 13:41:29 +0100776 virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled)
777 {
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
780 data.writeInt32(enabled ? 1 : 0);
781 remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply);
782 }
783
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700784 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
785 audio_io_handle_t *ioHandle,
786 audio_devices_t *device)
787 {
788 if (session == NULL || ioHandle == NULL || device == NULL) {
789 return BAD_VALUE;
790 }
791 Parcel data, reply;
792 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
793 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
794 if (status != NO_ERROR) {
795 return status;
796 }
797 status = (status_t)reply.readInt32();
798 if (status == NO_ERROR) {
799 *session = (audio_session_t)reply.readInt32();
800 *ioHandle = (audio_io_handle_t)reply.readInt32();
801 *device = (audio_devices_t)reply.readInt32();
802 }
803 return status;
804 }
805
806 virtual status_t releaseSoundTriggerSession(audio_session_t session)
807 {
808 Parcel data, reply;
809 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
810 data.writeInt32(session);
811 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
812 if (status != NO_ERROR) {
813 return status;
814 }
815 return (status_t)reply.readInt32();
816 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700817
818 virtual audio_mode_t getPhoneState()
819 {
820 Parcel data, reply;
821 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
822 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
823 if (status != NO_ERROR) {
824 return AUDIO_MODE_INVALID;
825 }
826 return (audio_mode_t)reply.readInt32();
827 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800828
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700829 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800830 {
831 Parcel data, reply;
832 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
833 data.writeInt32(registration ? 1 : 0);
834 size_t size = mixes.size();
835 if (size > MAX_MIXES_PER_POLICY) {
836 size = MAX_MIXES_PER_POLICY;
837 }
838 size_t sizePosition = data.dataPosition();
839 data.writeInt32(size);
840 size_t finalSize = size;
841 for (size_t i = 0; i < size; i++) {
842 size_t position = data.dataPosition();
843 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
844 data.setDataPosition(position);
845 finalSize--;
846 }
847 }
848 if (size != finalSize) {
849 size_t position = data.dataPosition();
850 data.setDataPosition(sizePosition);
851 data.writeInt32(finalSize);
852 data.setDataPosition(position);
853 }
854 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
855 if (status == NO_ERROR) {
856 status = (status_t)reply.readInt32();
857 }
858 return status;
859 }
Eric Laurent554a2772015-04-10 11:29:24 -0700860
861 virtual status_t startAudioSource(const struct audio_port_config *source,
862 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700863 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700864 {
865 Parcel data, reply;
866 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700867 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700868 return BAD_VALUE;
869 }
870 data.write(source, sizeof(struct audio_port_config));
871 data.write(attributes, sizeof(audio_attributes_t));
872 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
873 if (status != NO_ERROR) {
874 return status;
875 }
876 status = (status_t)reply.readInt32();
877 if (status != NO_ERROR) {
878 return status;
879 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700880 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700881 return status;
882 }
883
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700884 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700885 {
886 Parcel data, reply;
887 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700888 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700889 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
890 if (status != NO_ERROR) {
891 return status;
892 }
893 status = (status_t)reply.readInt32();
894 return status;
895 }
Andy Hung2ddee192015-12-18 17:34:44 -0800896
897 virtual status_t setMasterMono(bool mono)
898 {
899 Parcel data, reply;
900 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
901 data.writeInt32(static_cast<int32_t>(mono));
902 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
903 if (status != NO_ERROR) {
904 return status;
905 }
906 return static_cast<status_t>(reply.readInt32());
907 }
908
909 virtual status_t getMasterMono(bool *mono)
910 {
911 if (mono == nullptr) {
912 return BAD_VALUE;
913 }
914 Parcel data, reply;
915 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
916
917 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
918 if (status != NO_ERROR) {
919 return status;
920 }
921 status = static_cast<status_t>(reply.readInt32());
922 if (status == NO_ERROR) {
923 *mono = static_cast<bool>(reply.readInt32());
924 }
925 return status;
926 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700927
928 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
929 {
930 Parcel data, reply;
931 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
932 data.writeInt32(static_cast <int32_t>(stream));
933 data.writeInt32(static_cast <int32_t>(index));
934 data.writeUint32(static_cast <uint32_t>(device));
935 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
936 if (status != NO_ERROR) {
937 return NAN;
938 }
939 return reply.readFloat();
940 }
jiabin81772902018-04-02 17:52:27 -0700941
942 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
943 audio_format_t *surroundFormats,
944 bool *surroundFormatsEnabled,
945 bool reported)
946 {
947 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
948 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
949 return BAD_VALUE;
950 }
951 Parcel data, reply;
952 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
953 unsigned int numSurroundFormatsReq = *numSurroundFormats;
954 data.writeUint32(numSurroundFormatsReq);
955 data.writeBool(reported);
956 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
957 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
958 *numSurroundFormats = reply.readUint32();
959 }
960 if (status == NO_ERROR) {
961 if (numSurroundFormatsReq > *numSurroundFormats) {
962 numSurroundFormatsReq = *numSurroundFormats;
963 }
964 if (numSurroundFormatsReq > 0) {
965 status = reply.read(surroundFormats,
966 numSurroundFormatsReq * sizeof(audio_format_t));
967 if (status != NO_ERROR) {
968 return status;
969 }
970 status = reply.read(surroundFormatsEnabled,
971 numSurroundFormatsReq * sizeof(bool));
972 }
973 }
974 return status;
975 }
976
977 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
978 {
979 Parcel data, reply;
980 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
981 data.writeInt32(audioFormat);
982 data.writeBool(enabled);
983 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
984 if (status != NO_ERROR) {
985 return status;
986 }
987 return reply.readInt32();
988 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700989
Arun Mirpuri11029ad2018-12-19 20:45:19 -0800990 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
991 std::vector<audio_format_t> *formats)
992 {
993 if (formats == NULL) {
994 return BAD_VALUE;
995 }
996
997 Parcel data, reply;
998 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
999 status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
1000 if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
1001 return status;
1002 }
1003
1004 size_t list_size = reply.readUint32();
1005
1006 for (size_t i = 0; i < list_size; i++) {
1007 formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
1008 }
1009 return NO_ERROR;
1010 }
1011
1012
1013 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001014 const String16& opPackageName,
1015 const effect_uuid_t *uuid,
1016 int32_t priority,
1017 audio_usage_t usage,
1018 audio_unique_id_t* id)
1019 {
1020 Parcel data, reply;
1021 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1022 data.write(type, sizeof(effect_uuid_t));
1023 data.writeString16(opPackageName);
1024 data.write(uuid, sizeof(effect_uuid_t));
1025 data.writeInt32(priority);
1026 data.writeInt32((int32_t) usage);
1027 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
1028 if (status != NO_ERROR) {
1029 return status;
1030 }
1031 status = static_cast <status_t> (reply.readInt32());
1032 *id = reply.readInt32();
1033 return status;
1034 }
1035
1036 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
1037 {
1038 Parcel data, reply;
1039 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1040 data.writeInt32(id);
1041 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
1042 if (status != NO_ERROR) {
1043 return status;
1044 }
1045 return static_cast <status_t> (reply.readInt32());
1046 }
1047
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001048 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
1049 const String16& opPackageName,
1050 const effect_uuid_t *uuid,
1051 int32_t priority,
1052 audio_source_t source,
1053 audio_unique_id_t* id)
1054 {
1055 Parcel data, reply;
1056 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1057 data.write(type, sizeof(effect_uuid_t));
1058 data.writeString16(opPackageName);
1059 data.write(uuid, sizeof(effect_uuid_t));
1060 data.writeInt32(priority);
1061 data.writeInt32((int32_t) source);
1062 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
1063 if (status != NO_ERROR) {
1064 return status;
1065 }
1066 status = static_cast <status_t> (reply.readInt32());
1067 *id = reply.readInt32();
1068 return status;
1069 }
1070
1071 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
1072 {
1073 Parcel data, reply;
1074 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1075 data.writeInt32(id);
1076 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
1077 if (status != NO_ERROR) {
1078 return status;
1079 }
1080 return static_cast <status_t> (reply.readInt32());
1081 }
1082
Eric Laurentb78763e2018-10-17 10:08:02 -07001083 virtual status_t setAssistantUid(uid_t uid)
1084 {
1085 Parcel data, reply;
1086 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1087 data.writeInt32(uid);
1088 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
1089 if (status != NO_ERROR) {
1090 return status;
1091 }
1092 return static_cast <status_t> (reply.readInt32());
1093 }
1094
1095 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
1096 {
1097 Parcel data, reply;
1098 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1099 data.writeInt32(uids.size());
1100 for (auto uid : uids) {
1101 data.writeInt32(uid);
1102 }
1103 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
1104 if (status != NO_ERROR) {
1105 return status;
1106 }
1107 return static_cast <status_t> (reply.readInt32());
1108 }
1109
jiabin6012f912018-11-02 17:06:30 -07001110 virtual bool isHapticPlaybackSupported()
1111 {
1112 Parcel data, reply;
1113 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1114 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
1115 if (status != NO_ERROR) {
1116 return false;
1117 }
1118 return reply.readBool();
1119 }
1120
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001121 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
1122 {
1123 Parcel data, reply;
1124 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1125
1126 data.writeInt32((int32_t) uid);
1127 size_t size = devices.size();
1128 size_t sizePosition = data.dataPosition();
1129 data.writeInt32((int32_t) size);
1130 size_t finalSize = size;
1131 for (size_t i = 0; i < size; i++) {
1132 size_t position = data.dataPosition();
1133 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1134 data.setDataPosition(position);
1135 finalSize--;
1136 }
1137 }
1138 if (size != finalSize) {
1139 size_t position = data.dataPosition();
1140 data.setDataPosition(sizePosition);
1141 data.writeInt32(finalSize);
1142 data.setDataPosition(position);
1143 }
1144
1145 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1146 if (status == NO_ERROR) {
1147 status = (status_t)reply.readInt32();
1148 }
1149 return status;
1150 }
1151
François Gaffied0ba9ed2018-11-05 11:50:42 +01001152 virtual status_t removeUidDeviceAffinities(uid_t uid) {
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001153 Parcel data, reply;
1154 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1155
1156 data.writeInt32((int32_t) uid);
1157
François Gaffied0ba9ed2018-11-05 11:50:42 +01001158 status_t status =
1159 remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001160 if (status == NO_ERROR) {
François Gaffied0ba9ed2018-11-05 11:50:42 +01001161 status = (status_t) reply.readInt32();
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001162 }
1163 return status;
1164 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01001165
1166 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
1167 {
1168 Parcel data, reply;
1169 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1170
1171 status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
1172 if (status != NO_ERROR) {
1173 ALOGE("%s: permission denied", __func__);
1174 return status;
1175 }
1176 status = static_cast<status_t>(reply.readInt32());
François Gaffie4b2018b2018-11-07 11:18:59 +01001177 if (status != NO_ERROR) {
1178 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001179 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001180 uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
1181 for (size_t i = 0; i < numStrategies; i++) {
1182 AudioProductStrategy strategy;
1183 status = strategy.readFromParcel(&reply);
1184 if (status != NO_ERROR) {
1185 ALOGE("%s: failed to read strategies", __FUNCTION__);
1186 strategies.clear();
1187 return status;
1188 }
1189 strategies.push_back(strategy);
1190 }
1191 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001192 }
1193
François Gaffie4b2018b2018-11-07 11:18:59 +01001194 virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
1195 product_strategy_t &productStrategy)
François Gaffied0ba9ed2018-11-05 11:50:42 +01001196 {
1197 Parcel data, reply;
1198 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1199 status_t status = aa.writeToParcel(&data);
1200 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01001201 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001202 }
1203 status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
François Gaffie4b2018b2018-11-07 11:18:59 +01001204 if (status != NO_ERROR) {
1205 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001206 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001207 status = static_cast<status_t>(reply.readInt32());
1208 if (status != NO_ERROR) {
1209 return status;
1210 }
1211 productStrategy = static_cast<product_strategy_t>(reply.readInt32());
1212 return NO_ERROR;
1213 }
1214
1215 virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups)
1216 {
1217 Parcel data, reply;
1218 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1219
1220 status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply);
1221 if (status != NO_ERROR) {
1222 return status;
1223 }
1224 status = static_cast<status_t>(reply.readInt32());
1225 if (status != NO_ERROR) {
1226 return status;
1227 }
1228 uint32_t numGroups = static_cast<uint32_t>(reply.readInt32());
1229 for (size_t i = 0; i < numGroups; i++) {
1230 AudioVolumeGroup group;
1231 status = group.readFromParcel(&reply);
1232 if (status != NO_ERROR) {
1233 ALOGE("%s: failed to read volume groups", __FUNCTION__);
1234 groups.clear();
1235 return status;
1236 }
1237 groups.push_back(group);
1238 }
1239 return NO_ERROR;
1240 }
1241
1242 virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
1243 volume_group_t &volumeGroup)
1244 {
1245 Parcel data, reply;
1246 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1247 status_t status = aa.writeToParcel(&data);
1248 if (status != NO_ERROR) {
1249 return status;
1250 }
1251 status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply);
1252 if (status != NO_ERROR) {
1253 return status;
1254 }
1255 status = static_cast<status_t>(reply.readInt32());
1256 if (status != NO_ERROR) {
1257 return status;
1258 }
1259 volumeGroup = static_cast<volume_group_t>(reply.readInt32());
1260 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001261 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001262};
1263
1264IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1265
1266// ----------------------------------------------------------------------
1267
Eric Laurentc2f1f072009-07-17 12:17:14 -07001268status_t BnAudioPolicyService::onTransact(
1269 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1270{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001271 // make sure transactions reserved to AudioFlinger do not come from other processes
1272 switch (code) {
1273 case START_OUTPUT:
1274 case STOP_OUTPUT:
1275 case RELEASE_OUTPUT:
1276 case GET_INPUT_FOR_ATTR:
1277 case START_INPUT:
1278 case STOP_INPUT:
1279 case RELEASE_INPUT:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001280 case GET_OUTPUT_FOR_EFFECT:
1281 case REGISTER_EFFECT:
1282 case UNREGISTER_EFFECT:
1283 case SET_EFFECT_ENABLED:
1284 case GET_OUTPUT_FOR_ATTR:
1285 case ACQUIRE_SOUNDTRIGGER_SESSION:
1286 case RELEASE_SOUNDTRIGGER_SESSION:
1287 ALOGW("%s: transaction %d received from PID %d",
1288 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001289 // return status only for non void methods
1290 switch (code) {
1291 case RELEASE_OUTPUT:
1292 case RELEASE_INPUT:
1293 break;
1294 default:
1295 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1296 break;
1297 }
1298 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001299 default:
1300 break;
1301 }
1302
Eric Laurent4980df22018-01-26 18:04:09 -08001303 // make sure the following transactions come from system components
1304 switch (code) {
1305 case SET_DEVICE_CONNECTION_STATE:
1306 case HANDLE_DEVICE_CONFIG_CHANGE:
1307 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001308//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1309// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001310 case INIT_STREAM_VOLUME:
1311 case SET_STREAM_VOLUME:
1312 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001313 case SET_MASTER_MONO:
jiabin81772902018-04-02 17:52:27 -07001314 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001315 case SET_SURROUND_FORMAT_ENABLED:
1316 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001317 case SET_A11Y_SERVICES_UIDS:
1318 case SET_UID_DEVICE_AFFINITY:
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001319 case REMOVE_UID_DEVICE_AFFINITY:
François Gaffie4b2018b2018-11-07 11:18:59 +01001320 case GET_OFFLOAD_FORMATS_A2DP:
1321 case LIST_AUDIO_VOLUME_GROUPS:
1322 case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001323 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001324 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1325 __func__, code, IPCThreadState::self()->getCallingPid(),
1326 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001327 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1328 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001329 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001330 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001331 default:
1332 break;
1333 }
1334
Eric Laurent39b09b52018-06-29 12:24:40 -07001335 std::string tag("IAudioPolicyService command " + std::to_string(code));
1336 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001337
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001338 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001339 case SET_DEVICE_CONNECTION_STATE: {
1340 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001341 audio_devices_t device =
1342 static_cast <audio_devices_t>(data.readInt32());
1343 audio_policy_dev_state_t state =
1344 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001345 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001346 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001347 audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001348 if (device_address == nullptr || device_name == nullptr) {
1349 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1350 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1351 } else {
1352 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1353 state,
1354 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001355 device_name,
1356 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001357 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001358 return NO_ERROR;
1359 } break;
1360
1361 case GET_DEVICE_CONNECTION_STATE: {
1362 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001363 audio_devices_t device =
1364 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001365 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001366 if (device_address == nullptr) {
1367 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1368 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1369 } else {
1370 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1371 device_address)));
1372 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001373 return NO_ERROR;
1374 } break;
1375
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001376 case HANDLE_DEVICE_CONFIG_CHANGE: {
1377 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1378 audio_devices_t device =
1379 static_cast <audio_devices_t>(data.readInt32());
1380 const char *device_address = data.readCString();
1381 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001382 audio_format_t codecFormat =
1383 static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001384 if (device_address == nullptr || device_name == nullptr) {
1385 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1386 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1387 } else {
1388 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1389 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001390 device_name,
1391 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001392 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001393 return NO_ERROR;
1394 } break;
1395
Eric Laurentc2f1f072009-07-17 12:17:14 -07001396 case SET_PHONE_STATE: {
1397 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001398 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1399 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001400 return NO_ERROR;
1401 } break;
1402
Eric Laurentc2f1f072009-07-17 12:17:14 -07001403 case SET_FORCE_USE: {
1404 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001405 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1406 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001407 audio_policy_forced_cfg_t config =
1408 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001409 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1410 return NO_ERROR;
1411 } break;
1412
1413 case GET_FORCE_USE: {
1414 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001415 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1416 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001417 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1418 return NO_ERROR;
1419 } break;
1420
1421 case GET_OUTPUT: {
1422 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001423 audio_stream_type_t stream =
1424 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001425 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001426 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001427 return NO_ERROR;
1428 } break;
1429
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001430 case GET_OUTPUT_FOR_ATTR: {
1431 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001432 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001433 bool hasAttributes = data.readInt32() != 0;
1434 if (hasAttributes) {
1435 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001436 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001437 }
1438 audio_session_t session = (audio_session_t)data.readInt32();
1439 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1440 bool hasStream = data.readInt32() != 0;
1441 if (hasStream) {
1442 stream = (audio_stream_type_t)data.readInt32();
1443 }
Nadav Bar766fb022018-01-07 12:18:03 +02001444 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001445 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001446 audio_config_t config;
1447 memset(&config, 0, sizeof(audio_config_t));
1448 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001449 audio_output_flags_t flags =
1450 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001451 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001452 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001453 audio_io_handle_t output = 0;
Kevin Rocard153f92d2018-12-18 18:33:28 -08001454 std::vector<audio_io_handle_t> secondaryOutputs;
Eric Laurente83b55d2014-11-14 10:06:21 -08001455 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001456 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001457 &config,
Kevin Rocard153f92d2018-12-18 18:33:28 -08001458 flags, &selectedDeviceId, &portId, &secondaryOutputs);
Eric Laurente83b55d2014-11-14 10:06:21 -08001459 reply->writeInt32(status);
1460 reply->writeInt32(output);
1461 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001462 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001463 reply->writeInt32(portId);
Kevin Rocard153f92d2018-12-18 18:33:28 -08001464 reply->writeInt32(secondaryOutputs.size());
1465 return reply->write(secondaryOutputs.data(),
1466 secondaryOutputs.size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001467 } break;
1468
Eric Laurentc2f1f072009-07-17 12:17:14 -07001469 case START_OUTPUT: {
1470 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001471 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1472 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001473 return NO_ERROR;
1474 } break;
1475
1476 case STOP_OUTPUT: {
1477 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001478 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1479 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001480 return NO_ERROR;
1481 } break;
1482
1483 case RELEASE_OUTPUT: {
1484 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001485 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1486 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001487 return NO_ERROR;
1488 } break;
1489
Eric Laurentcaf7f482014-11-25 17:50:47 -08001490 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001491 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001492 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001493 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001494 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001495 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001496 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001497 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001498 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001499 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001500 audio_config_base_t config;
1501 memset(&config, 0, sizeof(audio_config_base_t));
1502 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001503 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001504 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001505 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001506 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001507 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001508 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001509 reply->writeInt32(status);
1510 if (status == NO_ERROR) {
1511 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001512 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001513 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001514 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001515 return NO_ERROR;
1516 } break;
1517
1518 case START_INPUT: {
1519 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001520 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001521 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001522 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001523 return NO_ERROR;
1524 } break;
1525
1526 case STOP_INPUT: {
1527 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001528 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1529 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001530 return NO_ERROR;
1531 } break;
1532
1533 case RELEASE_INPUT: {
1534 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001535 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1536 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001537 return NO_ERROR;
1538 } break;
1539
1540 case INIT_STREAM_VOLUME: {
1541 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001542 audio_stream_type_t stream =
1543 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001544 int indexMin = data.readInt32();
1545 int indexMax = data.readInt32();
1546 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1547 return NO_ERROR;
1548 } break;
1549
1550 case SET_STREAM_VOLUME: {
1551 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001552 audio_stream_type_t stream =
1553 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001554 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001555 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1556 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1557 index,
1558 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001559 return NO_ERROR;
1560 } break;
1561
1562 case GET_STREAM_VOLUME: {
1563 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001564 audio_stream_type_t stream =
1565 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001566 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001567 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001568 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001569 reply->writeInt32(index);
1570 reply->writeInt32(static_cast <uint32_t>(status));
1571 return NO_ERROR;
1572 } break;
1573
Eric Laurentde070132010-07-13 04:45:46 -07001574 case GET_STRATEGY_FOR_STREAM: {
1575 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001576 audio_stream_type_t stream =
1577 static_cast <audio_stream_type_t>(data.readInt32());
François Gaffiec005e562018-11-06 15:04:49 +01001578 reply->writeUint32(getStrategyForStream(stream));
Eric Laurentde070132010-07-13 04:45:46 -07001579 return NO_ERROR;
1580 } break;
1581
François Gaffiecfe17322018-11-07 13:41:29 +01001582 case SET_VOLUME_ATTRIBUTES: {
1583 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1584 audio_attributes_t attributes = {};
1585 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1586 if (status != NO_ERROR) {
1587 return status;
1588 }
1589 int index = data.readInt32();
1590 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1591
1592 reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes,
1593 index, device)));
1594 return NO_ERROR;
1595 } break;
1596
1597 case GET_VOLUME_ATTRIBUTES: {
1598 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1599 audio_attributes_t attributes = {};
1600 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1601 if (status != NO_ERROR) {
1602 return status;
1603 }
1604 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1605
1606 int index = 0;
1607 status = getVolumeIndexForAttributes(attributes, index, device);
1608 reply->writeInt32(static_cast <uint32_t>(status));
1609 if (status == NO_ERROR) {
1610 reply->writeInt32(index);
1611 }
1612 return NO_ERROR;
1613 } break;
1614
1615 case GET_MIN_VOLUME_FOR_ATTRIBUTES: {
1616 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1617 audio_attributes_t attributes = {};
1618 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1619 if (status != NO_ERROR) {
1620 return status;
1621 }
1622
1623 int index = 0;
1624 status = getMinVolumeIndexForAttributes(attributes, index);
1625 reply->writeInt32(static_cast <uint32_t>(status));
1626 if (status == NO_ERROR) {
1627 reply->writeInt32(index);
1628 }
1629 return NO_ERROR;
1630 } break;
1631
1632 case GET_MAX_VOLUME_FOR_ATTRIBUTES: {
1633 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1634 audio_attributes_t attributes = {};
1635 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1636 if (status != NO_ERROR) {
1637 return status;
1638 }
1639
1640 int index = 0;
1641 status = getMaxVolumeIndexForAttributes(attributes, index);
1642 reply->writeInt32(static_cast <uint32_t>(status));
1643 if (status == NO_ERROR) {
1644 reply->writeInt32(index);
1645 }
1646 return NO_ERROR;
1647 } break;
1648
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001649 case GET_DEVICES_FOR_STREAM: {
1650 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001651 audio_stream_type_t stream =
1652 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001653 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1654 return NO_ERROR;
1655 } break;
1656
Eric Laurentde070132010-07-13 04:45:46 -07001657 case GET_OUTPUT_FOR_EFFECT: {
1658 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001659 effect_descriptor_t desc = {};
1660 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1661 android_errorWriteLog(0x534e4554, "73126106");
1662 }
1663 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001664 audio_io_handle_t output = getOutputForEffect(&desc);
1665 reply->writeInt32(static_cast <int>(output));
1666 return NO_ERROR;
1667 } break;
1668
1669 case REGISTER_EFFECT: {
1670 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001671 effect_descriptor_t desc = {};
1672 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1673 android_errorWriteLog(0x534e4554, "73126106");
1674 }
1675 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001676 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001677 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001678 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001679 int id = data.readInt32();
1680 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001681 io,
Eric Laurentde070132010-07-13 04:45:46 -07001682 strategy,
1683 session,
1684 id)));
1685 return NO_ERROR;
1686 } break;
1687
1688 case UNREGISTER_EFFECT: {
1689 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1690 int id = data.readInt32();
1691 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1692 return NO_ERROR;
1693 } break;
1694
Eric Laurentdb7c0792011-08-10 10:37:50 -07001695 case SET_EFFECT_ENABLED: {
1696 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1697 int id = data.readInt32();
1698 bool enabled = static_cast <bool>(data.readInt32());
1699 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1700 return NO_ERROR;
1701 } break;
1702
Eric Laurenteda6c362011-02-02 09:33:30 -08001703 case IS_STREAM_ACTIVE: {
1704 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001705 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001706 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001707 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001708 return NO_ERROR;
1709 } break;
1710
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001711 case IS_STREAM_ACTIVE_REMOTELY: {
1712 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1713 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1714 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001715 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001716 return NO_ERROR;
1717 } break;
1718
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001719 case IS_SOURCE_ACTIVE: {
1720 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1721 audio_source_t source = (audio_source_t) data.readInt32();
1722 reply->writeInt32( isSourceActive(source));
1723 return NO_ERROR;
1724 }
1725
Eric Laurent57dae992011-07-24 13:36:09 -07001726 case QUERY_DEFAULT_PRE_PROCESSING: {
1727 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001728 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001729 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001730 if (count > AudioEffect::kMaxPreProcessing) {
1731 count = AudioEffect::kMaxPreProcessing;
1732 }
Eric Laurent57dae992011-07-24 13:36:09 -07001733 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001734 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001735 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1736 reply->writeInt32(status);
1737 if (status != NO_ERROR && status != NO_MEMORY) {
1738 retCount = 0;
1739 }
1740 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001741 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001742 if (retCount < count) {
1743 count = retCount;
1744 }
1745 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1746 }
1747 delete[] descriptors;
1748 return status;
1749 }
1750
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001751 case IS_OFFLOAD_SUPPORTED: {
1752 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001753 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001754 data.read(&info, sizeof(audio_offload_info_t));
1755 bool isSupported = isOffloadSupported(info);
1756 reply->writeInt32(isSupported);
1757 return NO_ERROR;
1758 }
1759
Michael Chana94fbb22018-04-24 14:31:19 +10001760 case IS_DIRECT_OUTPUT_SUPPORTED: {
1761 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1762 audio_config_base_t config = {};
1763 audio_attributes_t attributes = {};
1764 status_t status = data.read(&config, sizeof(audio_config_base_t));
1765 if (status != NO_ERROR) return status;
1766 status = data.read(&attributes, sizeof(audio_attributes_t));
1767 if (status != NO_ERROR) return status;
1768 reply->writeInt32(isDirectOutputSupported(config, attributes));
1769 return NO_ERROR;
1770 }
1771
Eric Laurent203b1a12014-04-01 10:34:16 -07001772 case LIST_AUDIO_PORTS: {
1773 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1774 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1775 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1776 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001777 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1778 numPortsReq = MAX_ITEMS_PER_LIST;
1779 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001780 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001781 struct audio_port *ports =
1782 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001783 if (ports == NULL) {
1784 reply->writeInt32(NO_MEMORY);
1785 reply->writeInt32(0);
1786 return NO_ERROR;
1787 }
1788 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001789 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1790 reply->writeInt32(status);
1791 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001792
1793 if (status == NO_ERROR) {
1794 if (numPortsReq > numPorts) {
1795 numPortsReq = numPorts;
1796 }
1797 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1798 reply->writeInt32(generation);
1799 }
1800 free(ports);
1801 return NO_ERROR;
1802 }
1803
1804 case GET_AUDIO_PORT: {
1805 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001806 struct audio_port port = {};
1807 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1808 ALOGE("b/23912202");
1809 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001810 status_t status = getAudioPort(&port);
1811 reply->writeInt32(status);
1812 if (status == NO_ERROR) {
1813 reply->write(&port, sizeof(struct audio_port));
1814 }
1815 return NO_ERROR;
1816 }
1817
1818 case CREATE_AUDIO_PATCH: {
1819 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001820 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001821 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001822 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001823 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1824 ALOGE("b/23912202");
1825 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001826 status_t status = createAudioPatch(&patch, &handle);
1827 reply->writeInt32(status);
1828 if (status == NO_ERROR) {
1829 reply->write(&handle, sizeof(audio_patch_handle_t));
1830 }
1831 return NO_ERROR;
1832 }
1833
1834 case RELEASE_AUDIO_PATCH: {
1835 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001836 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001837 data.read(&handle, sizeof(audio_patch_handle_t));
1838 status_t status = releaseAudioPatch(handle);
1839 reply->writeInt32(status);
1840 return NO_ERROR;
1841 }
1842
1843 case LIST_AUDIO_PATCHES: {
1844 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1845 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001846 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1847 numPatchesReq = MAX_ITEMS_PER_LIST;
1848 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001849 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001850 struct audio_patch *patches =
1851 (struct audio_patch *)calloc(numPatchesReq,
1852 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001853 if (patches == NULL) {
1854 reply->writeInt32(NO_MEMORY);
1855 reply->writeInt32(0);
1856 return NO_ERROR;
1857 }
1858 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001859 status_t status = listAudioPatches(&numPatches, patches, &generation);
1860 reply->writeInt32(status);
1861 reply->writeInt32(numPatches);
1862 if (status == NO_ERROR) {
1863 if (numPatchesReq > numPatches) {
1864 numPatchesReq = numPatches;
1865 }
1866 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1867 reply->writeInt32(generation);
1868 }
1869 free(patches);
1870 return NO_ERROR;
1871 }
1872
1873 case SET_AUDIO_PORT_CONFIG: {
1874 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001875 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001876 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001877 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001878 status_t status = setAudioPortConfig(&config);
1879 reply->writeInt32(status);
1880 return NO_ERROR;
1881 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001882
Eric Laurentb52c1522014-05-20 11:27:36 -07001883 case REGISTER_CLIENT: {
1884 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1885 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1886 data.readStrongBinder());
1887 registerClient(client);
1888 return NO_ERROR;
1889 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001890
Eric Laurente8726fe2015-06-26 09:39:24 -07001891 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1892 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1893 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1894 return NO_ERROR;
1895 } break;
1896
François Gaffiecfe17322018-11-07 13:41:29 +01001897 case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: {
1898 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1899 setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1);
1900 return NO_ERROR;
1901 } break;
1902
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001903 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1904 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1905 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1906 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001907 audio_session_t session = AUDIO_SESSION_NONE;
1908 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1909 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001910 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1911 reply->writeInt32(status);
1912 if (status == NO_ERROR) {
1913 reply->writeInt32(session);
1914 reply->writeInt32(ioHandle);
1915 reply->writeInt32(device);
1916 }
1917 return NO_ERROR;
1918 } break;
1919
1920 case RELEASE_SOUNDTRIGGER_SESSION: {
1921 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1922 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1923 data.readStrongBinder());
1924 audio_session_t session = (audio_session_t)data.readInt32();
1925 status_t status = releaseSoundTriggerSession(session);
1926 reply->writeInt32(status);
1927 return NO_ERROR;
1928 } break;
1929
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001930 case GET_PHONE_STATE: {
1931 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1932 reply->writeInt32((int32_t)getPhoneState());
1933 return NO_ERROR;
1934 } break;
1935
Eric Laurentbaac1832014-12-01 17:52:59 -08001936 case REGISTER_POLICY_MIXES: {
1937 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1938 bool registration = data.readInt32() == 1;
1939 Vector<AudioMix> mixes;
1940 size_t size = (size_t)data.readInt32();
1941 if (size > MAX_MIXES_PER_POLICY) {
1942 size = MAX_MIXES_PER_POLICY;
1943 }
1944 for (size_t i = 0; i < size; i++) {
1945 AudioMix mix;
1946 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1947 mixes.add(mix);
1948 }
1949 }
1950 status_t status = registerPolicyMixes(mixes, registration);
1951 reply->writeInt32(status);
1952 return NO_ERROR;
1953 } break;
1954
Eric Laurent554a2772015-04-10 11:29:24 -07001955 case START_AUDIO_SOURCE: {
1956 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001957 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001958 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001959 (void)sanitizeAudioPortConfig(&source);
1960 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001961 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001962 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001963 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1964 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001965 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001966 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001967 return NO_ERROR;
1968 } break;
1969
1970 case STOP_AUDIO_SOURCE: {
1971 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001972 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1973 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001974 reply->writeInt32(status);
1975 return NO_ERROR;
1976 } break;
1977
Andy Hung2ddee192015-12-18 17:34:44 -08001978 case SET_MASTER_MONO: {
1979 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1980 bool mono = static_cast<bool>(data.readInt32());
1981 status_t status = setMasterMono(mono);
1982 reply->writeInt32(status);
1983 return NO_ERROR;
1984 } break;
1985
1986 case GET_MASTER_MONO: {
1987 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1988 bool mono;
1989 status_t status = getMasterMono(&mono);
1990 reply->writeInt32(status);
1991 if (status == NO_ERROR) {
1992 reply->writeInt32(static_cast<int32_t>(mono));
1993 }
1994 return NO_ERROR;
1995 } break;
1996
Eric Laurentac9cef52017-06-09 15:46:26 -07001997 case GET_STREAM_VOLUME_DB: {
1998 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1999 audio_stream_type_t stream =
2000 static_cast <audio_stream_type_t>(data.readInt32());
2001 int index = static_cast <int>(data.readInt32());
2002 audio_devices_t device =
2003 static_cast <audio_devices_t>(data.readUint32());
2004 reply->writeFloat(getStreamVolumeDB(stream, index, device));
2005 return NO_ERROR;
2006 }
2007
jiabin81772902018-04-02 17:52:27 -07002008 case GET_SURROUND_FORMATS: {
2009 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2010 unsigned int numSurroundFormatsReq = data.readUint32();
2011 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
2012 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
2013 }
2014 bool reported = data.readBool();
2015 unsigned int numSurroundFormats = numSurroundFormatsReq;
2016 audio_format_t *surroundFormats = (audio_format_t *)calloc(
2017 numSurroundFormats, sizeof(audio_format_t));
2018 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
2019 if (numSurroundFormatsReq > 0 &&
2020 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
2021 free(surroundFormats);
2022 free(surroundFormatsEnabled);
2023 reply->writeInt32(NO_MEMORY);
2024 return NO_ERROR;
2025 }
2026 status_t status = getSurroundFormats(
2027 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
2028 reply->writeInt32(status);
2029
2030 if (status == NO_ERROR) {
2031 reply->writeUint32(numSurroundFormats);
2032 if (numSurroundFormatsReq > numSurroundFormats) {
2033 numSurroundFormatsReq = numSurroundFormats;
2034 }
2035 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
2036 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
2037 }
2038 free(surroundFormats);
2039 free(surroundFormatsEnabled);
2040 return NO_ERROR;
2041 }
2042
2043 case SET_SURROUND_FORMAT_ENABLED: {
2044 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2045 audio_format_t audioFormat = (audio_format_t) data.readInt32();
2046 bool enabled = data.readBool();
2047 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
2048 reply->writeInt32(status);
2049 return NO_ERROR;
2050 }
2051
Arun Mirpuri11029ad2018-12-19 20:45:19 -08002052 case GET_OFFLOAD_FORMATS_A2DP: {
2053 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2054 std::vector<audio_format_t> encodingFormats;
2055 status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
2056 reply->writeInt32(status);
2057 if (status != NO_ERROR) {
2058 return NO_ERROR;
2059 }
2060 reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
2061 for (size_t i = 0; i < encodingFormats.size(); i++)
2062 reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
2063 return NO_ERROR;
2064 }
2065
2066
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07002067 case ADD_STREAM_DEFAULT_EFFECT: {
2068 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2069 effect_uuid_t type;
2070 status_t status = data.read(&type, sizeof(effect_uuid_t));
2071 if (status != NO_ERROR) {
2072 return status;
2073 }
2074 String16 opPackageName;
2075 status = data.readString16(&opPackageName);
2076 if (status != NO_ERROR) {
2077 return status;
2078 }
2079 effect_uuid_t uuid;
2080 status = data.read(&uuid, sizeof(effect_uuid_t));
2081 if (status != NO_ERROR) {
2082 return status;
2083 }
2084 int32_t priority = data.readInt32();
2085 audio_usage_t usage = (audio_usage_t) data.readInt32();
2086 audio_unique_id_t id = 0;
2087 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
2088 opPackageName,
2089 &uuid,
2090 priority,
2091 usage,
2092 &id)));
2093 reply->writeInt32(id);
2094 return NO_ERROR;
2095 }
2096
2097 case REMOVE_STREAM_DEFAULT_EFFECT: {
2098 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2099 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2100 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
2101 return NO_ERROR;
2102 }
2103
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07002104 case ADD_SOURCE_DEFAULT_EFFECT: {
2105 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2106 effect_uuid_t type;
2107 status_t status = data.read(&type, sizeof(effect_uuid_t));
2108 if (status != NO_ERROR) {
2109 return status;
2110 }
2111 String16 opPackageName;
2112 status = data.readString16(&opPackageName);
2113 if (status != NO_ERROR) {
2114 return status;
2115 }
2116 effect_uuid_t uuid;
2117 status = data.read(&uuid, sizeof(effect_uuid_t));
2118 if (status != NO_ERROR) {
2119 return status;
2120 }
2121 int32_t priority = data.readInt32();
2122 audio_source_t source = (audio_source_t) data.readInt32();
2123 audio_unique_id_t id = 0;
2124 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
2125 opPackageName,
2126 &uuid,
2127 priority,
2128 source,
2129 &id)));
2130 reply->writeInt32(id);
2131 return NO_ERROR;
2132 }
2133
2134 case REMOVE_SOURCE_DEFAULT_EFFECT: {
2135 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2136 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2137 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
2138 return NO_ERROR;
2139 }
2140
Eric Laurentb78763e2018-10-17 10:08:02 -07002141 case SET_ASSISTANT_UID: {
2142 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2143 int32_t uid;
2144 status_t status = data.readInt32(&uid);
2145 if (status != NO_ERROR) {
2146 return status;
2147 }
2148 status = setAssistantUid(uid);
2149 reply->writeInt32(static_cast <int32_t>(status));
2150 return NO_ERROR;
2151 }
2152
2153 case SET_A11Y_SERVICES_UIDS: {
2154 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2155 std::vector<uid_t> uids;
2156 int32_t size;
2157 status_t status = data.readInt32(&size);
2158 if (status != NO_ERROR) {
2159 return status;
2160 }
2161 if (size > MAX_ITEMS_PER_LIST) {
2162 size = MAX_ITEMS_PER_LIST;
2163 }
2164 for (int32_t i = 0; i < size; i++) {
2165 int32_t uid;
2166 status = data.readInt32(&uid);
2167 if (status != NO_ERROR) {
2168 return status;
2169 }
2170 uids.push_back(uid);
2171 }
2172 status = setA11yServicesUids(uids);
2173 reply->writeInt32(static_cast <int32_t>(status));
2174 return NO_ERROR;
2175 }
2176
jiabin6012f912018-11-02 17:06:30 -07002177 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
2178 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2179 bool isSupported = isHapticPlaybackSupported();
2180 reply->writeBool(isSupported);
Kevin Rocardb99cc752019-03-21 20:52:24 -07002181 return NO_ERROR;
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08002182 }
2183
2184 case SET_UID_DEVICE_AFFINITY: {
2185 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2186 const uid_t uid = (uid_t) data.readInt32();
2187 Vector<AudioDeviceTypeAddr> devices;
2188 size_t size = (size_t)data.readInt32();
2189 for (size_t i = 0; i < size; i++) {
2190 AudioDeviceTypeAddr device;
2191 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
2192 devices.add(device);
2193 }
2194 }
2195 status_t status = setUidDeviceAffinities(uid, devices);
2196 reply->writeInt32(status);
2197 return NO_ERROR;
2198 }
2199
2200 case REMOVE_UID_DEVICE_AFFINITY: {
2201 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2202 const uid_t uid = (uid_t) data.readInt32();
2203 status_t status = removeUidDeviceAffinities(uid);
2204 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07002205 return NO_ERROR;
2206 }
2207
François Gaffied0ba9ed2018-11-05 11:50:42 +01002208 case LIST_AUDIO_PRODUCT_STRATEGIES: {
2209 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2210 AudioProductStrategyVector strategies;
2211 status_t status = listAudioProductStrategies(strategies);
2212 reply->writeInt32(status);
2213 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01002214 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01002215 }
2216 size_t size = strategies.size();
2217 size_t sizePosition = reply->dataPosition();
2218 reply->writeInt32(size);
2219 size_t finalSize = size;
2220 for (size_t i = 0; i < size; i++) {
2221 size_t position = reply->dataPosition();
2222 if (strategies[i].writeToParcel(reply) != NO_ERROR) {
2223 reply->setDataPosition(position);
2224 finalSize--;
2225 }
2226 }
2227 if (size != finalSize) {
2228 size_t position = reply->dataPosition();
2229 reply->setDataPosition(sizePosition);
2230 reply->writeInt32(finalSize);
2231 reply->setDataPosition(position);
2232 }
2233 return NO_ERROR;
2234 }
2235
2236 case GET_STRATEGY_FOR_ATTRIBUTES: {
2237 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2238 AudioAttributes attributes;
2239 status_t status = attributes.readFromParcel(&data);
2240 if (status != NO_ERROR) {
2241 return status;
2242 }
François Gaffie4b2018b2018-11-07 11:18:59 +01002243 product_strategy_t strategy;
2244 status = getProductStrategyFromAudioAttributes(attributes, strategy);
2245 reply->writeInt32(status);
2246 if (status != NO_ERROR) {
2247 return NO_ERROR;
2248 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01002249 reply->writeUint32(static_cast<int>(strategy));
2250 return NO_ERROR;
2251 }
2252
François Gaffie4b2018b2018-11-07 11:18:59 +01002253 case LIST_AUDIO_VOLUME_GROUPS: {
2254 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2255 AudioVolumeGroupVector groups;
2256 status_t status = listAudioVolumeGroups(groups);
2257 reply->writeInt32(status);
2258 if (status != NO_ERROR) {
2259 return NO_ERROR;
2260 }
2261 size_t size = groups.size();
2262 size_t sizePosition = reply->dataPosition();
2263 reply->writeInt32(size);
2264 size_t finalSize = size;
2265 for (size_t i = 0; i < size; i++) {
2266 size_t position = reply->dataPosition();
2267 if (groups[i].writeToParcel(reply) != NO_ERROR) {
2268 reply->setDataPosition(position);
2269 finalSize--;
2270 }
2271 }
2272 if (size != finalSize) {
2273 size_t position = reply->dataPosition();
2274 reply->setDataPosition(sizePosition);
2275 reply->writeInt32(finalSize);
2276 reply->setDataPosition(position);
2277 }
2278 return NO_ERROR;
2279 }
2280
2281 case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
2282 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2283 AudioAttributes attributes;
2284 status_t status = attributes.readFromParcel(&data);
2285 if (status != NO_ERROR) {
2286 return status;
2287 }
2288 volume_group_t group;
2289 status = getVolumeGroupFromAudioAttributes(attributes, group);
2290 reply->writeInt32(status);
2291 if (status != NO_ERROR) {
2292 return NO_ERROR;
2293 }
2294 reply->writeUint32(static_cast<int>(group));
2295 return NO_ERROR;
2296 }
2297
Kevin Rocardb99cc752019-03-21 20:52:24 -07002298 case SET_ALLOWED_CAPTURE_POLICY: {
2299 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2300 uid_t uid = data.readInt32();
2301 audio_flags_mask_t flags = data.readInt32();
2302 status_t status = setAllowedCapturePolicy(uid, flags);
2303 reply->writeInt32(status);
2304 return NO_ERROR;
2305 }
2306
Eric Laurentc2f1f072009-07-17 12:17:14 -07002307 default:
2308 return BBinder::onTransact(code, data, reply, flags);
2309 }
2310}
2311
Andy Hungb0272092018-04-12 11:06:56 -07002312/** returns true if string overflow was prevented by zero termination */
2313template <size_t size>
2314static bool preventStringOverflow(char (&s)[size]) {
2315 if (strnlen(s, size) < size) return false;
2316 s[size - 1] = '\0';
2317 return true;
2318}
2319
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002320void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
2321{
2322 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
2323 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
2324 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
2325 }
2326 attr->tags[tagsMaxSize - 1] = '\0';
2327}
2328
Andy Hungb0272092018-04-12 11:06:56 -07002329/** returns BAD_VALUE if sanitization was required. */
2330status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
2331{
2332 if (preventStringOverflow(desc->name)
2333 | /* always */ preventStringOverflow(desc->implementor)) {
2334 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
2335 return BAD_VALUE;
2336 }
2337 return NO_ERROR;
2338}
2339
2340/** returns BAD_VALUE if sanitization was required. */
2341status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
2342{
2343 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
2344 preventStringOverflow(config->ext.device.address)) {
2345 return BAD_VALUE;
2346 }
2347 return NO_ERROR;
2348}
2349
Eric Laurentc2f1f072009-07-17 12:17:14 -07002350// ----------------------------------------------------------------------------
2351
Glenn Kasten40bc9062015-03-20 09:09:33 -07002352} // namespace android