blob: 7f2e5e580534ea78e052704c462b101faf9f7a2d [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
Eric Laurentac9cef52017-06-09 15:46:26 -070022#include <math.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <sys/types.h>
24
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070026#include <binder/Parcel.h>
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
Eric Laurent3528c932018-02-23 17:17:22 -080029#include <media/TimeCheck.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070030#include <mediautils/ServiceUtilities.h>
Dima Zavin64760242011-05-11 14:15:23 -070031#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070032
Eric Laurentc2f1f072009-07-17 12:17:14 -070033namespace android {
34
35enum {
36 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
37 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080038 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080040 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 SET_FORCE_USE,
42 GET_FORCE_USE,
43 GET_OUTPUT,
44 START_OUTPUT,
45 STOP_OUTPUT,
46 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080047 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070048 START_INPUT,
49 STOP_INPUT,
50 RELEASE_INPUT,
51 INIT_STREAM_VOLUME,
52 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070053 GET_STREAM_VOLUME,
54 GET_STRATEGY_FOR_STREAM,
55 GET_OUTPUT_FOR_EFFECT,
56 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080057 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070059 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080060 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070061 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080062 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000063 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070064 IS_OFFLOAD_SUPPORTED,
65 LIST_AUDIO_PORTS,
66 GET_AUDIO_PORT,
67 CREATE_AUDIO_PATCH,
68 RELEASE_AUDIO_PATCH,
69 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070070 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070071 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070072 GET_OUTPUT_FOR_ATTR,
73 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070074 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080075 GET_PHONE_STATE,
76 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070077 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070078 STOP_AUDIO_SOURCE,
79 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080080 SET_MASTER_MONO,
81 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070082 GET_STREAM_VOLUME_DB,
83 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070084 SET_SURROUND_FORMAT_ENABLED,
85 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070086 REMOVE_STREAM_DEFAULT_EFFECT,
87 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070088 REMOVE_SOURCE_DEFAULT_EFFECT,
89 SET_ASSISTANT_UID,
90 SET_A11Y_SERVICES_UIDS,
Eric Laurentc2f1f072009-07-17 12:17:14 -070091};
92
Eric Laurent1d670b12015-02-06 10:44:24 -080093#define MAX_ITEMS_PER_LIST 1024
94
Eric Laurentc2f1f072009-07-17 12:17:14 -070095class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
96{
97public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070098 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -070099 : BpInterface<IAudioPolicyService>(impl)
100 {
101 }
102
103 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700104 audio_devices_t device,
105 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800106 const char *device_address,
107 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700108 {
109 Parcel data, reply;
110 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
111 data.writeInt32(static_cast <uint32_t>(device));
112 data.writeInt32(static_cast <uint32_t>(state));
113 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800114 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700115 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
116 return static_cast <status_t> (reply.readInt32());
117 }
118
Dima Zavinfce7a472011-04-19 22:30:36 -0700119 virtual audio_policy_dev_state_t getDeviceConnectionState(
120 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700121 const char *device_address)
122 {
123 Parcel data, reply;
124 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
125 data.writeInt32(static_cast <uint32_t>(device));
126 data.writeCString(device_address);
127 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700128 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 }
130
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800131 virtual status_t handleDeviceConfigChange(audio_devices_t device,
132 const char *device_address,
133 const char *device_name)
134 {
135 Parcel data, reply;
136 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
137 data.writeInt32(static_cast <uint32_t>(device));
138 data.writeCString(device_address);
139 data.writeCString(device_name);
140 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
141 return static_cast <status_t> (reply.readInt32());
142 }
143
Glenn Kastenf78aee72012-01-04 11:00:47 -0800144 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 {
146 Parcel data, reply;
147 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
148 data.writeInt32(state);
149 remote()->transact(SET_PHONE_STATE, data, &reply);
150 return static_cast <status_t> (reply.readInt32());
151 }
152
Dima Zavinfce7a472011-04-19 22:30:36 -0700153 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
157 data.writeInt32(static_cast <uint32_t>(usage));
158 data.writeInt32(static_cast <uint32_t>(config));
159 remote()->transact(SET_FORCE_USE, data, &reply);
160 return static_cast <status_t> (reply.readInt32());
161 }
162
Dima Zavinfce7a472011-04-19 22:30:36 -0700163 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164 {
165 Parcel data, reply;
166 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
167 data.writeInt32(static_cast <uint32_t>(usage));
168 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700169 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700170 }
171
Eric Laurentf4e63452017-11-06 19:31:46 +0000172 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700173 {
174 Parcel data, reply;
175 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
176 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700177 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700178 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700179 }
180
Eric Laurente83b55d2014-11-14 10:06:21 -0800181 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
182 audio_io_handle_t *output,
183 audio_session_t session,
184 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200185 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700186 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800187 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800188 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700189 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800190 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700191 {
192 Parcel data, reply;
193 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
194 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800195 if (stream == NULL) {
196 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
197 return BAD_VALUE;
198 }
199 if (*stream == AUDIO_STREAM_DEFAULT) {
200 ALOGE("getOutputForAttr unspecified stream type");
201 return BAD_VALUE;
202 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700203 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800204 if (output == NULL) {
205 ALOGE("getOutputForAttr NULL output - shouldn't happen");
206 return BAD_VALUE;
207 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700208 if (selectedDeviceId == NULL) {
209 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
210 return BAD_VALUE;
211 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800212 if (portId == NULL) {
213 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
214 return BAD_VALUE;
215 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800216 if (attr == NULL) {
217 data.writeInt32(0);
218 } else {
219 data.writeInt32(1);
220 data.write(attr, sizeof(audio_attributes_t));
221 }
222 data.writeInt32(session);
223 if (stream == NULL) {
224 data.writeInt32(0);
225 } else {
226 data.writeInt32(1);
227 data.writeInt32(*stream);
228 }
Nadav Bar766fb022018-01-07 12:18:03 +0200229 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700230 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800231 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700232 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700233 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800234 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800235 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
236 if (status != NO_ERROR) {
237 return status;
238 }
239 status = (status_t)reply.readInt32();
240 if (status != NO_ERROR) {
241 return status;
242 }
243 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800244 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800245 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800246 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800247 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700248 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800249 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800250 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700251 }
252
Eric Laurentd7fe0862018-07-14 16:48:01 -0700253 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700257 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 remote()->transact(START_OUTPUT, data, &reply);
259 return static_cast <status_t> (reply.readInt32());
260 }
261
Eric Laurentd7fe0862018-07-14 16:48:01 -0700262 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700263 {
264 Parcel data, reply;
265 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700266 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 remote()->transact(STOP_OUTPUT, data, &reply);
268 return static_cast <status_t> (reply.readInt32());
269 }
270
Eric Laurentd7fe0862018-07-14 16:48:01 -0700271 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700275 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 remote()->transact(RELEASE_OUTPUT, data, &reply);
277 }
278
Eric Laurentcaf7f482014-11-25 17:50:47 -0800279 virtual status_t getInputForAttr(const audio_attributes_t *attr,
280 audio_io_handle_t *input,
281 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700282 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700283 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800284 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800285 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600286 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700287 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800288 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800292 if (attr == NULL) {
293 ALOGE("getInputForAttr NULL attr - shouldn't happen");
294 return BAD_VALUE;
295 }
296 if (input == NULL) {
297 ALOGE("getInputForAttr NULL input - shouldn't happen");
298 return BAD_VALUE;
299 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700300 if (selectedDeviceId == NULL) {
301 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
302 return BAD_VALUE;
303 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800304 if (portId == NULL) {
305 ALOGE("getInputForAttr NULL portId - shouldn't happen");
306 return BAD_VALUE;
307 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800308 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700309 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800310 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700311 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700312 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800313 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800314 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700315 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700316 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800317 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800318 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
319 if (status != NO_ERROR) {
320 return status;
321 }
322 status = reply.readInt32();
323 if (status != NO_ERROR) {
324 return status;
325 }
326 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700327 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800328 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800329 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700330 }
331
Eric Laurent4eb58f12018-12-07 16:41:02 -0800332 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 {
334 Parcel data, reply;
335 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800336 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800338 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800339 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 }
341
Eric Laurentfee19762018-01-29 18:44:13 -0800342 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700343 {
344 Parcel data, reply;
345 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800346 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 remote()->transact(STOP_INPUT, data, &reply);
348 return static_cast <status_t> (reply.readInt32());
349 }
350
Eric Laurentfee19762018-01-29 18:44:13 -0800351 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800355 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 remote()->transact(RELEASE_INPUT, data, &reply);
357 }
358
Dima Zavinfce7a472011-04-19 22:30:36 -0700359 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 int indexMin,
361 int indexMax)
362 {
363 Parcel data, reply;
364 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
365 data.writeInt32(static_cast <uint32_t>(stream));
366 data.writeInt32(indexMin);
367 data.writeInt32(indexMax);
368 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
369 return static_cast <status_t> (reply.readInt32());
370 }
371
Eric Laurent83844cc2011-11-18 16:43:31 -0800372 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
373 int index,
374 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700375 {
376 Parcel data, reply;
377 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
378 data.writeInt32(static_cast <uint32_t>(stream));
379 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800380 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 remote()->transact(SET_STREAM_VOLUME, data, &reply);
382 return static_cast <status_t> (reply.readInt32());
383 }
384
Eric Laurent83844cc2011-11-18 16:43:31 -0800385 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
386 int *index,
387 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700388 {
389 Parcel data, reply;
390 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
391 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800392 data.writeInt32(static_cast <uint32_t>(device));
393
Eric Laurentc2f1f072009-07-17 12:17:14 -0700394 remote()->transact(GET_STREAM_VOLUME, data, &reply);
395 int lIndex = reply.readInt32();
396 if (index) *index = lIndex;
397 return static_cast <status_t> (reply.readInt32());
398 }
Eric Laurentde070132010-07-13 04:45:46 -0700399
Dima Zavinfce7a472011-04-19 22:30:36 -0700400 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
404 data.writeInt32(static_cast <uint32_t>(stream));
405 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
406 return reply.readInt32();
407 }
408
Eric Laurent63742522012-03-08 13:42:42 -0800409 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800410 {
411 Parcel data, reply;
412 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
413 data.writeInt32(static_cast <uint32_t>(stream));
414 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800415 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800416 }
417
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700418 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
422 data.write(desc, sizeof(effect_descriptor_t));
423 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
424 return static_cast <audio_io_handle_t> (reply.readInt32());
425 }
426
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700427 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700428 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700429 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800430 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700431 int id)
432 {
433 Parcel data, reply;
434 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
435 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700436 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700437 data.writeInt32(strategy);
438 data.writeInt32(session);
439 data.writeInt32(id);
440 remote()->transact(REGISTER_EFFECT, data, &reply);
441 return static_cast <status_t> (reply.readInt32());
442 }
443
444 virtual status_t unregisterEffect(int id)
445 {
446 Parcel data, reply;
447 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
448 data.writeInt32(id);
449 remote()->transact(UNREGISTER_EFFECT, data, &reply);
450 return static_cast <status_t> (reply.readInt32());
451 }
452
Eric Laurentdb7c0792011-08-10 10:37:50 -0700453 virtual status_t setEffectEnabled(int id, bool enabled)
454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
457 data.writeInt32(id);
458 data.writeInt32(enabled);
459 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
460 return static_cast <status_t> (reply.readInt32());
461 }
462
Glenn Kastenfff6d712012-01-12 16:38:12 -0800463 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800464 {
465 Parcel data, reply;
466 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800467 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800468 data.writeInt32(inPastMs);
469 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
470 return reply.readInt32();
471 }
Eric Laurent57dae992011-07-24 13:36:09 -0700472
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800473 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
474 {
475 Parcel data, reply;
476 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
477 data.writeInt32((int32_t) stream);
478 data.writeInt32(inPastMs);
479 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
480 return reply.readInt32();
481 }
482
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700483 virtual bool isSourceActive(audio_source_t source) const
484 {
485 Parcel data, reply;
486 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
487 data.writeInt32((int32_t) source);
488 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
489 return reply.readInt32();
490 }
491
Glenn Kastend848eb42016-03-08 13:42:11 -0800492 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700493 effect_descriptor_t *descriptors,
494 uint32_t *count)
495 {
496 if (descriptors == NULL || count == NULL) {
497 return BAD_VALUE;
498 }
499 Parcel data, reply;
500 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
501 data.writeInt32(audioSession);
502 data.writeInt32(*count);
503 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
504 if (status != NO_ERROR) {
505 return status;
506 }
507 status = static_cast <status_t> (reply.readInt32());
508 uint32_t retCount = reply.readInt32();
509 if (retCount != 0) {
510 uint32_t numDesc = (retCount < *count) ? retCount : *count;
511 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
512 }
513 *count = retCount;
514 return status;
515 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000516
517 virtual bool isOffloadSupported(const audio_offload_info_t& info)
518 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100519 Parcel data, reply;
520 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
521 data.write(&info, sizeof(audio_offload_info_t));
522 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700523 return reply.readInt32();
524 }
525
526 virtual status_t listAudioPorts(audio_port_role_t role,
527 audio_port_type_t type,
528 unsigned int *num_ports,
529 struct audio_port *ports,
530 unsigned int *generation)
531 {
532 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
533 generation == NULL) {
534 return BAD_VALUE;
535 }
536 Parcel data, reply;
537 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
538 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
539 data.writeInt32(role);
540 data.writeInt32(type);
541 data.writeInt32(numPortsReq);
542 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
543 if (status == NO_ERROR) {
544 status = (status_t)reply.readInt32();
545 *num_ports = (unsigned int)reply.readInt32();
546 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700547 if (status == NO_ERROR) {
548 if (numPortsReq > *num_ports) {
549 numPortsReq = *num_ports;
550 }
551 if (numPortsReq > 0) {
552 reply.read(ports, numPortsReq * sizeof(struct audio_port));
553 }
554 *generation = reply.readInt32();
555 }
556 return status;
557 }
558
559 virtual status_t getAudioPort(struct audio_port *port)
560 {
561 if (port == NULL) {
562 return BAD_VALUE;
563 }
564 Parcel data, reply;
565 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
566 data.write(port, sizeof(struct audio_port));
567 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
568 if (status != NO_ERROR ||
569 (status = (status_t)reply.readInt32()) != NO_ERROR) {
570 return status;
571 }
572 reply.read(port, sizeof(struct audio_port));
573 return status;
574 }
575
576 virtual status_t createAudioPatch(const struct audio_patch *patch,
577 audio_patch_handle_t *handle)
578 {
579 if (patch == NULL || handle == NULL) {
580 return BAD_VALUE;
581 }
582 Parcel data, reply;
583 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
584 data.write(patch, sizeof(struct audio_patch));
585 data.write(handle, sizeof(audio_patch_handle_t));
586 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
587 if (status != NO_ERROR ||
588 (status = (status_t)reply.readInt32()) != NO_ERROR) {
589 return status;
590 }
591 reply.read(handle, sizeof(audio_patch_handle_t));
592 return status;
593 }
594
595 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
596 {
597 Parcel data, reply;
598 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
599 data.write(&handle, sizeof(audio_patch_handle_t));
600 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
601 if (status != NO_ERROR) {
602 status = (status_t)reply.readInt32();
603 }
604 return status;
605 }
606
607 virtual status_t listAudioPatches(unsigned int *num_patches,
608 struct audio_patch *patches,
609 unsigned int *generation)
610 {
611 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
612 generation == NULL) {
613 return BAD_VALUE;
614 }
615 Parcel data, reply;
616 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
617 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
618 data.writeInt32(numPatchesReq);
619 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
620 if (status == NO_ERROR) {
621 status = (status_t)reply.readInt32();
622 *num_patches = (unsigned int)reply.readInt32();
623 }
624 if (status == NO_ERROR) {
625 if (numPatchesReq > *num_patches) {
626 numPatchesReq = *num_patches;
627 }
628 if (numPatchesReq > 0) {
629 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
630 }
631 *generation = reply.readInt32();
632 }
633 return status;
634 }
635
636 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
637 {
638 if (config == NULL) {
639 return BAD_VALUE;
640 }
641 Parcel data, reply;
642 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
643 data.write(config, sizeof(struct audio_port_config));
644 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
645 if (status != NO_ERROR) {
646 status = (status_t)reply.readInt32();
647 }
648 return status;
649 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700650
Eric Laurentb52c1522014-05-20 11:27:36 -0700651 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
652 {
653 Parcel data, reply;
654 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800655 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700656 remote()->transact(REGISTER_CLIENT, data, &reply);
657 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700658
Eric Laurente8726fe2015-06-26 09:39:24 -0700659 virtual void setAudioPortCallbacksEnabled(bool enabled)
660 {
661 Parcel data, reply;
662 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
663 data.writeInt32(enabled ? 1 : 0);
664 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
665 }
666
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700667 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
668 audio_io_handle_t *ioHandle,
669 audio_devices_t *device)
670 {
671 if (session == NULL || ioHandle == NULL || device == NULL) {
672 return BAD_VALUE;
673 }
674 Parcel data, reply;
675 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
676 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
677 if (status != NO_ERROR) {
678 return status;
679 }
680 status = (status_t)reply.readInt32();
681 if (status == NO_ERROR) {
682 *session = (audio_session_t)reply.readInt32();
683 *ioHandle = (audio_io_handle_t)reply.readInt32();
684 *device = (audio_devices_t)reply.readInt32();
685 }
686 return status;
687 }
688
689 virtual status_t releaseSoundTriggerSession(audio_session_t session)
690 {
691 Parcel data, reply;
692 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
693 data.writeInt32(session);
694 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
695 if (status != NO_ERROR) {
696 return status;
697 }
698 return (status_t)reply.readInt32();
699 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700700
701 virtual audio_mode_t getPhoneState()
702 {
703 Parcel data, reply;
704 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
705 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
706 if (status != NO_ERROR) {
707 return AUDIO_MODE_INVALID;
708 }
709 return (audio_mode_t)reply.readInt32();
710 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800711
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700712 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800713 {
714 Parcel data, reply;
715 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
716 data.writeInt32(registration ? 1 : 0);
717 size_t size = mixes.size();
718 if (size > MAX_MIXES_PER_POLICY) {
719 size = MAX_MIXES_PER_POLICY;
720 }
721 size_t sizePosition = data.dataPosition();
722 data.writeInt32(size);
723 size_t finalSize = size;
724 for (size_t i = 0; i < size; i++) {
725 size_t position = data.dataPosition();
726 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
727 data.setDataPosition(position);
728 finalSize--;
729 }
730 }
731 if (size != finalSize) {
732 size_t position = data.dataPosition();
733 data.setDataPosition(sizePosition);
734 data.writeInt32(finalSize);
735 data.setDataPosition(position);
736 }
737 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
738 if (status == NO_ERROR) {
739 status = (status_t)reply.readInt32();
740 }
741 return status;
742 }
Eric Laurent554a2772015-04-10 11:29:24 -0700743
744 virtual status_t startAudioSource(const struct audio_port_config *source,
745 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700746 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700747 {
748 Parcel data, reply;
749 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700750 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700751 return BAD_VALUE;
752 }
753 data.write(source, sizeof(struct audio_port_config));
754 data.write(attributes, sizeof(audio_attributes_t));
755 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
756 if (status != NO_ERROR) {
757 return status;
758 }
759 status = (status_t)reply.readInt32();
760 if (status != NO_ERROR) {
761 return status;
762 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700763 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700764 return status;
765 }
766
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700767 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700768 {
769 Parcel data, reply;
770 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700771 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700772 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
773 if (status != NO_ERROR) {
774 return status;
775 }
776 status = (status_t)reply.readInt32();
777 return status;
778 }
Andy Hung2ddee192015-12-18 17:34:44 -0800779
780 virtual status_t setMasterMono(bool mono)
781 {
782 Parcel data, reply;
783 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
784 data.writeInt32(static_cast<int32_t>(mono));
785 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
786 if (status != NO_ERROR) {
787 return status;
788 }
789 return static_cast<status_t>(reply.readInt32());
790 }
791
792 virtual status_t getMasterMono(bool *mono)
793 {
794 if (mono == nullptr) {
795 return BAD_VALUE;
796 }
797 Parcel data, reply;
798 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
799
800 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
801 if (status != NO_ERROR) {
802 return status;
803 }
804 status = static_cast<status_t>(reply.readInt32());
805 if (status == NO_ERROR) {
806 *mono = static_cast<bool>(reply.readInt32());
807 }
808 return status;
809 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700810
811 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
812 {
813 Parcel data, reply;
814 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
815 data.writeInt32(static_cast <int32_t>(stream));
816 data.writeInt32(static_cast <int32_t>(index));
817 data.writeUint32(static_cast <uint32_t>(device));
818 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
819 if (status != NO_ERROR) {
820 return NAN;
821 }
822 return reply.readFloat();
823 }
jiabin81772902018-04-02 17:52:27 -0700824
825 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
826 audio_format_t *surroundFormats,
827 bool *surroundFormatsEnabled,
828 bool reported)
829 {
830 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
831 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
832 return BAD_VALUE;
833 }
834 Parcel data, reply;
835 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
836 unsigned int numSurroundFormatsReq = *numSurroundFormats;
837 data.writeUint32(numSurroundFormatsReq);
838 data.writeBool(reported);
839 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
840 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
841 *numSurroundFormats = reply.readUint32();
842 }
843 if (status == NO_ERROR) {
844 if (numSurroundFormatsReq > *numSurroundFormats) {
845 numSurroundFormatsReq = *numSurroundFormats;
846 }
847 if (numSurroundFormatsReq > 0) {
848 status = reply.read(surroundFormats,
849 numSurroundFormatsReq * sizeof(audio_format_t));
850 if (status != NO_ERROR) {
851 return status;
852 }
853 status = reply.read(surroundFormatsEnabled,
854 numSurroundFormatsReq * sizeof(bool));
855 }
856 }
857 return status;
858 }
859
860 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
861 {
862 Parcel data, reply;
863 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
864 data.writeInt32(audioFormat);
865 data.writeBool(enabled);
866 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
867 if (status != NO_ERROR) {
868 return status;
869 }
870 return reply.readInt32();
871 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700872
873 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
874 const String16& opPackageName,
875 const effect_uuid_t *uuid,
876 int32_t priority,
877 audio_usage_t usage,
878 audio_unique_id_t* id)
879 {
880 Parcel data, reply;
881 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
882 data.write(type, sizeof(effect_uuid_t));
883 data.writeString16(opPackageName);
884 data.write(uuid, sizeof(effect_uuid_t));
885 data.writeInt32(priority);
886 data.writeInt32((int32_t) usage);
887 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
888 if (status != NO_ERROR) {
889 return status;
890 }
891 status = static_cast <status_t> (reply.readInt32());
892 *id = reply.readInt32();
893 return status;
894 }
895
896 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
897 {
898 Parcel data, reply;
899 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
900 data.writeInt32(id);
901 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
902 if (status != NO_ERROR) {
903 return status;
904 }
905 return static_cast <status_t> (reply.readInt32());
906 }
907
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700908 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
909 const String16& opPackageName,
910 const effect_uuid_t *uuid,
911 int32_t priority,
912 audio_source_t source,
913 audio_unique_id_t* id)
914 {
915 Parcel data, reply;
916 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
917 data.write(type, sizeof(effect_uuid_t));
918 data.writeString16(opPackageName);
919 data.write(uuid, sizeof(effect_uuid_t));
920 data.writeInt32(priority);
921 data.writeInt32((int32_t) source);
922 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
923 if (status != NO_ERROR) {
924 return status;
925 }
926 status = static_cast <status_t> (reply.readInt32());
927 *id = reply.readInt32();
928 return status;
929 }
930
931 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
932 {
933 Parcel data, reply;
934 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
935 data.writeInt32(id);
936 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
937 if (status != NO_ERROR) {
938 return status;
939 }
940 return static_cast <status_t> (reply.readInt32());
941 }
942
Eric Laurentb78763e2018-10-17 10:08:02 -0700943 virtual status_t setAssistantUid(uid_t uid)
944 {
945 Parcel data, reply;
946 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
947 data.writeInt32(uid);
948 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
949 if (status != NO_ERROR) {
950 return status;
951 }
952 return static_cast <status_t> (reply.readInt32());
953 }
954
955 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
956 {
957 Parcel data, reply;
958 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
959 data.writeInt32(uids.size());
960 for (auto uid : uids) {
961 data.writeInt32(uid);
962 }
963 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
964 if (status != NO_ERROR) {
965 return status;
966 }
967 return static_cast <status_t> (reply.readInt32());
968 }
969
Eric Laurentc2f1f072009-07-17 12:17:14 -0700970};
971
972IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
973
974// ----------------------------------------------------------------------
975
Eric Laurentc2f1f072009-07-17 12:17:14 -0700976status_t BnAudioPolicyService::onTransact(
977 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
978{
Eric Laurentb1cc36b2017-12-11 12:14:16 -0800979 // make sure transactions reserved to AudioFlinger do not come from other processes
980 switch (code) {
981 case START_OUTPUT:
982 case STOP_OUTPUT:
983 case RELEASE_OUTPUT:
984 case GET_INPUT_FOR_ATTR:
985 case START_INPUT:
986 case STOP_INPUT:
987 case RELEASE_INPUT:
988 case GET_STRATEGY_FOR_STREAM:
989 case GET_OUTPUT_FOR_EFFECT:
990 case REGISTER_EFFECT:
991 case UNREGISTER_EFFECT:
992 case SET_EFFECT_ENABLED:
993 case GET_OUTPUT_FOR_ATTR:
994 case ACQUIRE_SOUNDTRIGGER_SESSION:
995 case RELEASE_SOUNDTRIGGER_SESSION:
996 ALOGW("%s: transaction %d received from PID %d",
997 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -0700998 // return status only for non void methods
999 switch (code) {
1000 case RELEASE_OUTPUT:
1001 case RELEASE_INPUT:
1002 break;
1003 default:
1004 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1005 break;
1006 }
1007 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001008 default:
1009 break;
1010 }
1011
Eric Laurent4980df22018-01-26 18:04:09 -08001012 // make sure the following transactions come from system components
1013 switch (code) {
1014 case SET_DEVICE_CONNECTION_STATE:
1015 case HANDLE_DEVICE_CONFIG_CHANGE:
1016 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001017//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1018// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001019 case INIT_STREAM_VOLUME:
1020 case SET_STREAM_VOLUME:
1021 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001022 case SET_MASTER_MONO:
1023 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001024 case STOP_AUDIO_SOURCE:
1025 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001026 case SET_SURROUND_FORMAT_ENABLED:
1027 case SET_ASSISTANT_UID:
1028 case SET_A11Y_SERVICES_UIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001029 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001030 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1031 __func__, code, IPCThreadState::self()->getCallingPid(),
1032 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001033 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1034 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001035 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001036 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001037 default:
1038 break;
1039 }
1040
Eric Laurent39b09b52018-06-29 12:24:40 -07001041 std::string tag("IAudioPolicyService command " + std::to_string(code));
1042 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001043
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001044 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001045 case SET_DEVICE_CONNECTION_STATE: {
1046 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001047 audio_devices_t device =
1048 static_cast <audio_devices_t>(data.readInt32());
1049 audio_policy_dev_state_t state =
1050 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001051 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001052 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001053 if (device_address == nullptr || device_name == nullptr) {
1054 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1055 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1056 } else {
1057 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1058 state,
1059 device_address,
1060 device_name)));
1061 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001062 return NO_ERROR;
1063 } break;
1064
1065 case GET_DEVICE_CONNECTION_STATE: {
1066 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001067 audio_devices_t device =
1068 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001069 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001070 if (device_address == nullptr) {
1071 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1072 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1073 } else {
1074 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1075 device_address)));
1076 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001077 return NO_ERROR;
1078 } break;
1079
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001080 case HANDLE_DEVICE_CONFIG_CHANGE: {
1081 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1082 audio_devices_t device =
1083 static_cast <audio_devices_t>(data.readInt32());
1084 const char *device_address = data.readCString();
1085 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001086 if (device_address == nullptr || device_name == nullptr) {
1087 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1088 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1089 } else {
1090 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1091 device_address,
1092 device_name)));
1093 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001094 return NO_ERROR;
1095 } break;
1096
Eric Laurentc2f1f072009-07-17 12:17:14 -07001097 case SET_PHONE_STATE: {
1098 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001099 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1100 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001101 return NO_ERROR;
1102 } break;
1103
Eric Laurentc2f1f072009-07-17 12:17:14 -07001104 case SET_FORCE_USE: {
1105 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001106 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1107 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001108 audio_policy_forced_cfg_t config =
1109 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001110 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1111 return NO_ERROR;
1112 } break;
1113
1114 case GET_FORCE_USE: {
1115 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001116 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1117 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001118 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1119 return NO_ERROR;
1120 } break;
1121
1122 case GET_OUTPUT: {
1123 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001124 audio_stream_type_t stream =
1125 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001126 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001127 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001128 return NO_ERROR;
1129 } break;
1130
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001131 case GET_OUTPUT_FOR_ATTR: {
1132 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001133 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001134 bool hasAttributes = data.readInt32() != 0;
1135 if (hasAttributes) {
1136 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001137 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001138 }
1139 audio_session_t session = (audio_session_t)data.readInt32();
1140 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1141 bool hasStream = data.readInt32() != 0;
1142 if (hasStream) {
1143 stream = (audio_stream_type_t)data.readInt32();
1144 }
Nadav Bar766fb022018-01-07 12:18:03 +02001145 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001146 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001147 audio_config_t config;
1148 memset(&config, 0, sizeof(audio_config_t));
1149 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001150 audio_output_flags_t flags =
1151 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001152 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001153 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001154 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001155 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001156 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001157 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001158 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001159 reply->writeInt32(status);
1160 reply->writeInt32(output);
1161 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001162 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001163 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001164 return NO_ERROR;
1165 } break;
1166
Eric Laurentc2f1f072009-07-17 12:17:14 -07001167 case START_OUTPUT: {
1168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001169 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1170 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001171 return NO_ERROR;
1172 } break;
1173
1174 case STOP_OUTPUT: {
1175 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001176 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1177 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001178 return NO_ERROR;
1179 } break;
1180
1181 case RELEASE_OUTPUT: {
1182 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001183 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1184 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001185 return NO_ERROR;
1186 } break;
1187
Eric Laurentcaf7f482014-11-25 17:50:47 -08001188 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001189 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001190 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001191 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001192 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001193 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001194 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001195 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001196 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001197 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001198 audio_config_base_t config;
1199 memset(&config, 0, sizeof(audio_config_base_t));
1200 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001201 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001202 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001203 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001204 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001205 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001206 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001207 reply->writeInt32(status);
1208 if (status == NO_ERROR) {
1209 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001210 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001211 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001212 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001213 return NO_ERROR;
1214 } break;
1215
1216 case START_INPUT: {
1217 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001218 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001219 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001220 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001221 return NO_ERROR;
1222 } break;
1223
1224 case STOP_INPUT: {
1225 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001226 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1227 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001228 return NO_ERROR;
1229 } break;
1230
1231 case RELEASE_INPUT: {
1232 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001233 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1234 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001235 return NO_ERROR;
1236 } break;
1237
1238 case INIT_STREAM_VOLUME: {
1239 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001240 audio_stream_type_t stream =
1241 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001242 int indexMin = data.readInt32();
1243 int indexMax = data.readInt32();
1244 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1245 return NO_ERROR;
1246 } break;
1247
1248 case SET_STREAM_VOLUME: {
1249 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001250 audio_stream_type_t stream =
1251 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001252 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001253 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1254 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1255 index,
1256 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001257 return NO_ERROR;
1258 } break;
1259
1260 case GET_STREAM_VOLUME: {
1261 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001262 audio_stream_type_t stream =
1263 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001264 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001265 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001266 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001267 reply->writeInt32(index);
1268 reply->writeInt32(static_cast <uint32_t>(status));
1269 return NO_ERROR;
1270 } break;
1271
Eric Laurentde070132010-07-13 04:45:46 -07001272 case GET_STRATEGY_FOR_STREAM: {
1273 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001274 audio_stream_type_t stream =
1275 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001276 reply->writeInt32(getStrategyForStream(stream));
1277 return NO_ERROR;
1278 } break;
1279
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001280 case GET_DEVICES_FOR_STREAM: {
1281 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001282 audio_stream_type_t stream =
1283 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001284 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1285 return NO_ERROR;
1286 } break;
1287
Eric Laurentde070132010-07-13 04:45:46 -07001288 case GET_OUTPUT_FOR_EFFECT: {
1289 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001290 effect_descriptor_t desc = {};
1291 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1292 android_errorWriteLog(0x534e4554, "73126106");
1293 }
1294 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001295 audio_io_handle_t output = getOutputForEffect(&desc);
1296 reply->writeInt32(static_cast <int>(output));
1297 return NO_ERROR;
1298 } break;
1299
1300 case REGISTER_EFFECT: {
1301 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001302 effect_descriptor_t desc = {};
1303 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1304 android_errorWriteLog(0x534e4554, "73126106");
1305 }
1306 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001307 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001308 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001309 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001310 int id = data.readInt32();
1311 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001312 io,
Eric Laurentde070132010-07-13 04:45:46 -07001313 strategy,
1314 session,
1315 id)));
1316 return NO_ERROR;
1317 } break;
1318
1319 case UNREGISTER_EFFECT: {
1320 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1321 int id = data.readInt32();
1322 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1323 return NO_ERROR;
1324 } break;
1325
Eric Laurentdb7c0792011-08-10 10:37:50 -07001326 case SET_EFFECT_ENABLED: {
1327 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1328 int id = data.readInt32();
1329 bool enabled = static_cast <bool>(data.readInt32());
1330 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1331 return NO_ERROR;
1332 } break;
1333
Eric Laurenteda6c362011-02-02 09:33:30 -08001334 case IS_STREAM_ACTIVE: {
1335 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001336 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001337 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001338 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001339 return NO_ERROR;
1340 } break;
1341
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001342 case IS_STREAM_ACTIVE_REMOTELY: {
1343 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1344 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1345 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001346 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001347 return NO_ERROR;
1348 } break;
1349
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001350 case IS_SOURCE_ACTIVE: {
1351 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1352 audio_source_t source = (audio_source_t) data.readInt32();
1353 reply->writeInt32( isSourceActive(source));
1354 return NO_ERROR;
1355 }
1356
Eric Laurent57dae992011-07-24 13:36:09 -07001357 case QUERY_DEFAULT_PRE_PROCESSING: {
1358 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001359 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001360 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001361 if (count > AudioEffect::kMaxPreProcessing) {
1362 count = AudioEffect::kMaxPreProcessing;
1363 }
Eric Laurent57dae992011-07-24 13:36:09 -07001364 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001365 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001366 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1367 reply->writeInt32(status);
1368 if (status != NO_ERROR && status != NO_MEMORY) {
1369 retCount = 0;
1370 }
1371 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001372 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001373 if (retCount < count) {
1374 count = retCount;
1375 }
1376 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1377 }
1378 delete[] descriptors;
1379 return status;
1380 }
1381
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001382 case IS_OFFLOAD_SUPPORTED: {
1383 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001384 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001385 data.read(&info, sizeof(audio_offload_info_t));
1386 bool isSupported = isOffloadSupported(info);
1387 reply->writeInt32(isSupported);
1388 return NO_ERROR;
1389 }
1390
Eric Laurent203b1a12014-04-01 10:34:16 -07001391 case LIST_AUDIO_PORTS: {
1392 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1393 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1394 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1395 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001396 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1397 numPortsReq = MAX_ITEMS_PER_LIST;
1398 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001399 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001400 struct audio_port *ports =
1401 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001402 if (ports == NULL) {
1403 reply->writeInt32(NO_MEMORY);
1404 reply->writeInt32(0);
1405 return NO_ERROR;
1406 }
1407 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001408 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1409 reply->writeInt32(status);
1410 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001411
1412 if (status == NO_ERROR) {
1413 if (numPortsReq > numPorts) {
1414 numPortsReq = numPorts;
1415 }
1416 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1417 reply->writeInt32(generation);
1418 }
1419 free(ports);
1420 return NO_ERROR;
1421 }
1422
1423 case GET_AUDIO_PORT: {
1424 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001425 struct audio_port port = {};
1426 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1427 ALOGE("b/23912202");
1428 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001429 status_t status = getAudioPort(&port);
1430 reply->writeInt32(status);
1431 if (status == NO_ERROR) {
1432 reply->write(&port, sizeof(struct audio_port));
1433 }
1434 return NO_ERROR;
1435 }
1436
1437 case CREATE_AUDIO_PATCH: {
1438 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001439 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001440 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001441 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001442 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1443 ALOGE("b/23912202");
1444 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001445 status_t status = createAudioPatch(&patch, &handle);
1446 reply->writeInt32(status);
1447 if (status == NO_ERROR) {
1448 reply->write(&handle, sizeof(audio_patch_handle_t));
1449 }
1450 return NO_ERROR;
1451 }
1452
1453 case RELEASE_AUDIO_PATCH: {
1454 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001455 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001456 data.read(&handle, sizeof(audio_patch_handle_t));
1457 status_t status = releaseAudioPatch(handle);
1458 reply->writeInt32(status);
1459 return NO_ERROR;
1460 }
1461
1462 case LIST_AUDIO_PATCHES: {
1463 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1464 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001465 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1466 numPatchesReq = MAX_ITEMS_PER_LIST;
1467 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001468 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001469 struct audio_patch *patches =
1470 (struct audio_patch *)calloc(numPatchesReq,
1471 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001472 if (patches == NULL) {
1473 reply->writeInt32(NO_MEMORY);
1474 reply->writeInt32(0);
1475 return NO_ERROR;
1476 }
1477 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001478 status_t status = listAudioPatches(&numPatches, patches, &generation);
1479 reply->writeInt32(status);
1480 reply->writeInt32(numPatches);
1481 if (status == NO_ERROR) {
1482 if (numPatchesReq > numPatches) {
1483 numPatchesReq = numPatches;
1484 }
1485 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1486 reply->writeInt32(generation);
1487 }
1488 free(patches);
1489 return NO_ERROR;
1490 }
1491
1492 case SET_AUDIO_PORT_CONFIG: {
1493 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001494 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001495 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001496 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001497 status_t status = setAudioPortConfig(&config);
1498 reply->writeInt32(status);
1499 return NO_ERROR;
1500 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001501
Eric Laurentb52c1522014-05-20 11:27:36 -07001502 case REGISTER_CLIENT: {
1503 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1504 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1505 data.readStrongBinder());
1506 registerClient(client);
1507 return NO_ERROR;
1508 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001509
Eric Laurente8726fe2015-06-26 09:39:24 -07001510 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1511 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1512 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1513 return NO_ERROR;
1514 } break;
1515
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001516 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1517 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1518 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1519 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001520 audio_session_t session = AUDIO_SESSION_NONE;
1521 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1522 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001523 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1524 reply->writeInt32(status);
1525 if (status == NO_ERROR) {
1526 reply->writeInt32(session);
1527 reply->writeInt32(ioHandle);
1528 reply->writeInt32(device);
1529 }
1530 return NO_ERROR;
1531 } break;
1532
1533 case RELEASE_SOUNDTRIGGER_SESSION: {
1534 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1535 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1536 data.readStrongBinder());
1537 audio_session_t session = (audio_session_t)data.readInt32();
1538 status_t status = releaseSoundTriggerSession(session);
1539 reply->writeInt32(status);
1540 return NO_ERROR;
1541 } break;
1542
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001543 case GET_PHONE_STATE: {
1544 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1545 reply->writeInt32((int32_t)getPhoneState());
1546 return NO_ERROR;
1547 } break;
1548
Eric Laurentbaac1832014-12-01 17:52:59 -08001549 case REGISTER_POLICY_MIXES: {
1550 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1551 bool registration = data.readInt32() == 1;
1552 Vector<AudioMix> mixes;
1553 size_t size = (size_t)data.readInt32();
1554 if (size > MAX_MIXES_PER_POLICY) {
1555 size = MAX_MIXES_PER_POLICY;
1556 }
1557 for (size_t i = 0; i < size; i++) {
1558 AudioMix mix;
1559 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1560 mixes.add(mix);
1561 }
1562 }
1563 status_t status = registerPolicyMixes(mixes, registration);
1564 reply->writeInt32(status);
1565 return NO_ERROR;
1566 } break;
1567
Eric Laurent554a2772015-04-10 11:29:24 -07001568 case START_AUDIO_SOURCE: {
1569 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001570 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001571 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001572 (void)sanitizeAudioPortConfig(&source);
1573 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001574 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001575 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001576 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1577 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001578 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001579 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001580 return NO_ERROR;
1581 } break;
1582
1583 case STOP_AUDIO_SOURCE: {
1584 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001585 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1586 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001587 reply->writeInt32(status);
1588 return NO_ERROR;
1589 } break;
1590
Andy Hung2ddee192015-12-18 17:34:44 -08001591 case SET_MASTER_MONO: {
1592 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1593 bool mono = static_cast<bool>(data.readInt32());
1594 status_t status = setMasterMono(mono);
1595 reply->writeInt32(status);
1596 return NO_ERROR;
1597 } break;
1598
1599 case GET_MASTER_MONO: {
1600 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1601 bool mono;
1602 status_t status = getMasterMono(&mono);
1603 reply->writeInt32(status);
1604 if (status == NO_ERROR) {
1605 reply->writeInt32(static_cast<int32_t>(mono));
1606 }
1607 return NO_ERROR;
1608 } break;
1609
Eric Laurentac9cef52017-06-09 15:46:26 -07001610 case GET_STREAM_VOLUME_DB: {
1611 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1612 audio_stream_type_t stream =
1613 static_cast <audio_stream_type_t>(data.readInt32());
1614 int index = static_cast <int>(data.readInt32());
1615 audio_devices_t device =
1616 static_cast <audio_devices_t>(data.readUint32());
1617 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1618 return NO_ERROR;
1619 }
1620
jiabin81772902018-04-02 17:52:27 -07001621 case GET_SURROUND_FORMATS: {
1622 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1623 unsigned int numSurroundFormatsReq = data.readUint32();
1624 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1625 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1626 }
1627 bool reported = data.readBool();
1628 unsigned int numSurroundFormats = numSurroundFormatsReq;
1629 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1630 numSurroundFormats, sizeof(audio_format_t));
1631 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1632 if (numSurroundFormatsReq > 0 &&
1633 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1634 free(surroundFormats);
1635 free(surroundFormatsEnabled);
1636 reply->writeInt32(NO_MEMORY);
1637 return NO_ERROR;
1638 }
1639 status_t status = getSurroundFormats(
1640 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1641 reply->writeInt32(status);
1642
1643 if (status == NO_ERROR) {
1644 reply->writeUint32(numSurroundFormats);
1645 if (numSurroundFormatsReq > numSurroundFormats) {
1646 numSurroundFormatsReq = numSurroundFormats;
1647 }
1648 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1649 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1650 }
1651 free(surroundFormats);
1652 free(surroundFormatsEnabled);
1653 return NO_ERROR;
1654 }
1655
1656 case SET_SURROUND_FORMAT_ENABLED: {
1657 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1658 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1659 bool enabled = data.readBool();
1660 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1661 reply->writeInt32(status);
1662 return NO_ERROR;
1663 }
1664
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001665 case ADD_STREAM_DEFAULT_EFFECT: {
1666 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1667 effect_uuid_t type;
1668 status_t status = data.read(&type, sizeof(effect_uuid_t));
1669 if (status != NO_ERROR) {
1670 return status;
1671 }
1672 String16 opPackageName;
1673 status = data.readString16(&opPackageName);
1674 if (status != NO_ERROR) {
1675 return status;
1676 }
1677 effect_uuid_t uuid;
1678 status = data.read(&uuid, sizeof(effect_uuid_t));
1679 if (status != NO_ERROR) {
1680 return status;
1681 }
1682 int32_t priority = data.readInt32();
1683 audio_usage_t usage = (audio_usage_t) data.readInt32();
1684 audio_unique_id_t id = 0;
1685 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1686 opPackageName,
1687 &uuid,
1688 priority,
1689 usage,
1690 &id)));
1691 reply->writeInt32(id);
1692 return NO_ERROR;
1693 }
1694
1695 case REMOVE_STREAM_DEFAULT_EFFECT: {
1696 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1697 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1698 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1699 return NO_ERROR;
1700 }
1701
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001702 case ADD_SOURCE_DEFAULT_EFFECT: {
1703 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1704 effect_uuid_t type;
1705 status_t status = data.read(&type, sizeof(effect_uuid_t));
1706 if (status != NO_ERROR) {
1707 return status;
1708 }
1709 String16 opPackageName;
1710 status = data.readString16(&opPackageName);
1711 if (status != NO_ERROR) {
1712 return status;
1713 }
1714 effect_uuid_t uuid;
1715 status = data.read(&uuid, sizeof(effect_uuid_t));
1716 if (status != NO_ERROR) {
1717 return status;
1718 }
1719 int32_t priority = data.readInt32();
1720 audio_source_t source = (audio_source_t) data.readInt32();
1721 audio_unique_id_t id = 0;
1722 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1723 opPackageName,
1724 &uuid,
1725 priority,
1726 source,
1727 &id)));
1728 reply->writeInt32(id);
1729 return NO_ERROR;
1730 }
1731
1732 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1733 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1734 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1735 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1736 return NO_ERROR;
1737 }
1738
Eric Laurentb78763e2018-10-17 10:08:02 -07001739 case SET_ASSISTANT_UID: {
1740 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1741 int32_t uid;
1742 status_t status = data.readInt32(&uid);
1743 if (status != NO_ERROR) {
1744 return status;
1745 }
1746 status = setAssistantUid(uid);
1747 reply->writeInt32(static_cast <int32_t>(status));
1748 return NO_ERROR;
1749 }
1750
1751 case SET_A11Y_SERVICES_UIDS: {
1752 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1753 std::vector<uid_t> uids;
1754 int32_t size;
1755 status_t status = data.readInt32(&size);
1756 if (status != NO_ERROR) {
1757 return status;
1758 }
1759 if (size > MAX_ITEMS_PER_LIST) {
1760 size = MAX_ITEMS_PER_LIST;
1761 }
1762 for (int32_t i = 0; i < size; i++) {
1763 int32_t uid;
1764 status = data.readInt32(&uid);
1765 if (status != NO_ERROR) {
1766 return status;
1767 }
1768 uids.push_back(uid);
1769 }
1770 status = setA11yServicesUids(uids);
1771 reply->writeInt32(static_cast <int32_t>(status));
1772 return NO_ERROR;
1773 }
1774
Eric Laurentc2f1f072009-07-17 12:17:14 -07001775 default:
1776 return BBinder::onTransact(code, data, reply, flags);
1777 }
1778}
1779
Andy Hungb0272092018-04-12 11:06:56 -07001780/** returns true if string overflow was prevented by zero termination */
1781template <size_t size>
1782static bool preventStringOverflow(char (&s)[size]) {
1783 if (strnlen(s, size) < size) return false;
1784 s[size - 1] = '\0';
1785 return true;
1786}
1787
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001788void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1789{
1790 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1791 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1792 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1793 }
1794 attr->tags[tagsMaxSize - 1] = '\0';
1795}
1796
Andy Hungb0272092018-04-12 11:06:56 -07001797/** returns BAD_VALUE if sanitization was required. */
1798status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1799{
1800 if (preventStringOverflow(desc->name)
1801 | /* always */ preventStringOverflow(desc->implementor)) {
1802 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1803 return BAD_VALUE;
1804 }
1805 return NO_ERROR;
1806}
1807
1808/** returns BAD_VALUE if sanitization was required. */
1809status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1810{
1811 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1812 preventStringOverflow(config->ext.device.address)) {
1813 return BAD_VALUE;
1814 }
1815 return NO_ERROR;
1816}
1817
Eric Laurentc2f1f072009-07-17 12:17:14 -07001818// ----------------------------------------------------------------------------
1819
Glenn Kasten40bc9062015-03-20 09:09:33 -07001820} // namespace android