blob: a406658a161da96b48f091ede79cc30cdd763405 [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 Laurentfee19762018-01-29 18:44:13 -0800332 virtual status_t startInput(audio_port_handle_t portId,
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800333 bool *silenced)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800337 data.writeInt32(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800338 data.writeInt32(*silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800340 status_t status = static_cast <status_t> (reply.readInt32());
341 *silenced = reply.readInt32() == 1;
342 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700343 }
344
Eric Laurentfee19762018-01-29 18:44:13 -0800345 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800349 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 remote()->transact(STOP_INPUT, data, &reply);
351 return static_cast <status_t> (reply.readInt32());
352 }
353
Eric Laurentfee19762018-01-29 18:44:13 -0800354 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355 {
356 Parcel data, reply;
357 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800358 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700359 remote()->transact(RELEASE_INPUT, data, &reply);
360 }
361
Dima Zavinfce7a472011-04-19 22:30:36 -0700362 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700363 int indexMin,
364 int indexMax)
365 {
366 Parcel data, reply;
367 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
368 data.writeInt32(static_cast <uint32_t>(stream));
369 data.writeInt32(indexMin);
370 data.writeInt32(indexMax);
371 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
372 return static_cast <status_t> (reply.readInt32());
373 }
374
Eric Laurent83844cc2011-11-18 16:43:31 -0800375 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
376 int index,
377 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 {
379 Parcel data, reply;
380 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
381 data.writeInt32(static_cast <uint32_t>(stream));
382 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800383 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 remote()->transact(SET_STREAM_VOLUME, data, &reply);
385 return static_cast <status_t> (reply.readInt32());
386 }
387
Eric Laurent83844cc2011-11-18 16:43:31 -0800388 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
389 int *index,
390 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
394 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800395 data.writeInt32(static_cast <uint32_t>(device));
396
Eric Laurentc2f1f072009-07-17 12:17:14 -0700397 remote()->transact(GET_STREAM_VOLUME, data, &reply);
398 int lIndex = reply.readInt32();
399 if (index) *index = lIndex;
400 return static_cast <status_t> (reply.readInt32());
401 }
Eric Laurentde070132010-07-13 04:45:46 -0700402
Dima Zavinfce7a472011-04-19 22:30:36 -0700403 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700404 {
405 Parcel data, reply;
406 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
407 data.writeInt32(static_cast <uint32_t>(stream));
408 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
409 return reply.readInt32();
410 }
411
Eric Laurent63742522012-03-08 13:42:42 -0800412 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
416 data.writeInt32(static_cast <uint32_t>(stream));
417 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800418 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800419 }
420
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700421 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700422 {
423 Parcel data, reply;
424 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
425 data.write(desc, sizeof(effect_descriptor_t));
426 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
427 return static_cast <audio_io_handle_t> (reply.readInt32());
428 }
429
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700430 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700431 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700432 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800433 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700434 int id)
435 {
436 Parcel data, reply;
437 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
438 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700439 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700440 data.writeInt32(strategy);
441 data.writeInt32(session);
442 data.writeInt32(id);
443 remote()->transact(REGISTER_EFFECT, data, &reply);
444 return static_cast <status_t> (reply.readInt32());
445 }
446
447 virtual status_t unregisterEffect(int id)
448 {
449 Parcel data, reply;
450 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
451 data.writeInt32(id);
452 remote()->transact(UNREGISTER_EFFECT, data, &reply);
453 return static_cast <status_t> (reply.readInt32());
454 }
455
Eric Laurentdb7c0792011-08-10 10:37:50 -0700456 virtual status_t setEffectEnabled(int id, bool enabled)
457 {
458 Parcel data, reply;
459 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
460 data.writeInt32(id);
461 data.writeInt32(enabled);
462 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
463 return static_cast <status_t> (reply.readInt32());
464 }
465
Glenn Kastenfff6d712012-01-12 16:38:12 -0800466 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800467 {
468 Parcel data, reply;
469 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800470 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800471 data.writeInt32(inPastMs);
472 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
473 return reply.readInt32();
474 }
Eric Laurent57dae992011-07-24 13:36:09 -0700475
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800476 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
477 {
478 Parcel data, reply;
479 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
480 data.writeInt32((int32_t) stream);
481 data.writeInt32(inPastMs);
482 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
483 return reply.readInt32();
484 }
485
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700486 virtual bool isSourceActive(audio_source_t source) const
487 {
488 Parcel data, reply;
489 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
490 data.writeInt32((int32_t) source);
491 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
492 return reply.readInt32();
493 }
494
Glenn Kastend848eb42016-03-08 13:42:11 -0800495 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700496 effect_descriptor_t *descriptors,
497 uint32_t *count)
498 {
499 if (descriptors == NULL || count == NULL) {
500 return BAD_VALUE;
501 }
502 Parcel data, reply;
503 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
504 data.writeInt32(audioSession);
505 data.writeInt32(*count);
506 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
507 if (status != NO_ERROR) {
508 return status;
509 }
510 status = static_cast <status_t> (reply.readInt32());
511 uint32_t retCount = reply.readInt32();
512 if (retCount != 0) {
513 uint32_t numDesc = (retCount < *count) ? retCount : *count;
514 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
515 }
516 *count = retCount;
517 return status;
518 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000519
520 virtual bool isOffloadSupported(const audio_offload_info_t& info)
521 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100522 Parcel data, reply;
523 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
524 data.write(&info, sizeof(audio_offload_info_t));
525 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700526 return reply.readInt32();
527 }
528
529 virtual status_t listAudioPorts(audio_port_role_t role,
530 audio_port_type_t type,
531 unsigned int *num_ports,
532 struct audio_port *ports,
533 unsigned int *generation)
534 {
535 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
536 generation == NULL) {
537 return BAD_VALUE;
538 }
539 Parcel data, reply;
540 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
541 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
542 data.writeInt32(role);
543 data.writeInt32(type);
544 data.writeInt32(numPortsReq);
545 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
546 if (status == NO_ERROR) {
547 status = (status_t)reply.readInt32();
548 *num_ports = (unsigned int)reply.readInt32();
549 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700550 if (status == NO_ERROR) {
551 if (numPortsReq > *num_ports) {
552 numPortsReq = *num_ports;
553 }
554 if (numPortsReq > 0) {
555 reply.read(ports, numPortsReq * sizeof(struct audio_port));
556 }
557 *generation = reply.readInt32();
558 }
559 return status;
560 }
561
562 virtual status_t getAudioPort(struct audio_port *port)
563 {
564 if (port == NULL) {
565 return BAD_VALUE;
566 }
567 Parcel data, reply;
568 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
569 data.write(port, sizeof(struct audio_port));
570 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
571 if (status != NO_ERROR ||
572 (status = (status_t)reply.readInt32()) != NO_ERROR) {
573 return status;
574 }
575 reply.read(port, sizeof(struct audio_port));
576 return status;
577 }
578
579 virtual status_t createAudioPatch(const struct audio_patch *patch,
580 audio_patch_handle_t *handle)
581 {
582 if (patch == NULL || handle == NULL) {
583 return BAD_VALUE;
584 }
585 Parcel data, reply;
586 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
587 data.write(patch, sizeof(struct audio_patch));
588 data.write(handle, sizeof(audio_patch_handle_t));
589 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
590 if (status != NO_ERROR ||
591 (status = (status_t)reply.readInt32()) != NO_ERROR) {
592 return status;
593 }
594 reply.read(handle, sizeof(audio_patch_handle_t));
595 return status;
596 }
597
598 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
599 {
600 Parcel data, reply;
601 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
602 data.write(&handle, sizeof(audio_patch_handle_t));
603 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
604 if (status != NO_ERROR) {
605 status = (status_t)reply.readInt32();
606 }
607 return status;
608 }
609
610 virtual status_t listAudioPatches(unsigned int *num_patches,
611 struct audio_patch *patches,
612 unsigned int *generation)
613 {
614 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
615 generation == NULL) {
616 return BAD_VALUE;
617 }
618 Parcel data, reply;
619 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
620 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
621 data.writeInt32(numPatchesReq);
622 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
623 if (status == NO_ERROR) {
624 status = (status_t)reply.readInt32();
625 *num_patches = (unsigned int)reply.readInt32();
626 }
627 if (status == NO_ERROR) {
628 if (numPatchesReq > *num_patches) {
629 numPatchesReq = *num_patches;
630 }
631 if (numPatchesReq > 0) {
632 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
633 }
634 *generation = reply.readInt32();
635 }
636 return status;
637 }
638
639 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
640 {
641 if (config == NULL) {
642 return BAD_VALUE;
643 }
644 Parcel data, reply;
645 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
646 data.write(config, sizeof(struct audio_port_config));
647 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
648 if (status != NO_ERROR) {
649 status = (status_t)reply.readInt32();
650 }
651 return status;
652 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700653
Eric Laurentb52c1522014-05-20 11:27:36 -0700654 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
655 {
656 Parcel data, reply;
657 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800658 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700659 remote()->transact(REGISTER_CLIENT, data, &reply);
660 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700661
Eric Laurente8726fe2015-06-26 09:39:24 -0700662 virtual void setAudioPortCallbacksEnabled(bool enabled)
663 {
664 Parcel data, reply;
665 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
666 data.writeInt32(enabled ? 1 : 0);
667 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
668 }
669
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700670 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
671 audio_io_handle_t *ioHandle,
672 audio_devices_t *device)
673 {
674 if (session == NULL || ioHandle == NULL || device == NULL) {
675 return BAD_VALUE;
676 }
677 Parcel data, reply;
678 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
679 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
680 if (status != NO_ERROR) {
681 return status;
682 }
683 status = (status_t)reply.readInt32();
684 if (status == NO_ERROR) {
685 *session = (audio_session_t)reply.readInt32();
686 *ioHandle = (audio_io_handle_t)reply.readInt32();
687 *device = (audio_devices_t)reply.readInt32();
688 }
689 return status;
690 }
691
692 virtual status_t releaseSoundTriggerSession(audio_session_t session)
693 {
694 Parcel data, reply;
695 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
696 data.writeInt32(session);
697 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
698 if (status != NO_ERROR) {
699 return status;
700 }
701 return (status_t)reply.readInt32();
702 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700703
704 virtual audio_mode_t getPhoneState()
705 {
706 Parcel data, reply;
707 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
708 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
709 if (status != NO_ERROR) {
710 return AUDIO_MODE_INVALID;
711 }
712 return (audio_mode_t)reply.readInt32();
713 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800714
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700715 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800716 {
717 Parcel data, reply;
718 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
719 data.writeInt32(registration ? 1 : 0);
720 size_t size = mixes.size();
721 if (size > MAX_MIXES_PER_POLICY) {
722 size = MAX_MIXES_PER_POLICY;
723 }
724 size_t sizePosition = data.dataPosition();
725 data.writeInt32(size);
726 size_t finalSize = size;
727 for (size_t i = 0; i < size; i++) {
728 size_t position = data.dataPosition();
729 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
730 data.setDataPosition(position);
731 finalSize--;
732 }
733 }
734 if (size != finalSize) {
735 size_t position = data.dataPosition();
736 data.setDataPosition(sizePosition);
737 data.writeInt32(finalSize);
738 data.setDataPosition(position);
739 }
740 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
741 if (status == NO_ERROR) {
742 status = (status_t)reply.readInt32();
743 }
744 return status;
745 }
Eric Laurent554a2772015-04-10 11:29:24 -0700746
747 virtual status_t startAudioSource(const struct audio_port_config *source,
748 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700749 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700750 {
751 Parcel data, reply;
752 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700753 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700754 return BAD_VALUE;
755 }
756 data.write(source, sizeof(struct audio_port_config));
757 data.write(attributes, sizeof(audio_attributes_t));
758 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
759 if (status != NO_ERROR) {
760 return status;
761 }
762 status = (status_t)reply.readInt32();
763 if (status != NO_ERROR) {
764 return status;
765 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700766 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700767 return status;
768 }
769
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700770 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700771 {
772 Parcel data, reply;
773 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700774 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700775 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
776 if (status != NO_ERROR) {
777 return status;
778 }
779 status = (status_t)reply.readInt32();
780 return status;
781 }
Andy Hung2ddee192015-12-18 17:34:44 -0800782
783 virtual status_t setMasterMono(bool mono)
784 {
785 Parcel data, reply;
786 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
787 data.writeInt32(static_cast<int32_t>(mono));
788 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
789 if (status != NO_ERROR) {
790 return status;
791 }
792 return static_cast<status_t>(reply.readInt32());
793 }
794
795 virtual status_t getMasterMono(bool *mono)
796 {
797 if (mono == nullptr) {
798 return BAD_VALUE;
799 }
800 Parcel data, reply;
801 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
802
803 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
804 if (status != NO_ERROR) {
805 return status;
806 }
807 status = static_cast<status_t>(reply.readInt32());
808 if (status == NO_ERROR) {
809 *mono = static_cast<bool>(reply.readInt32());
810 }
811 return status;
812 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700813
814 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
815 {
816 Parcel data, reply;
817 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
818 data.writeInt32(static_cast <int32_t>(stream));
819 data.writeInt32(static_cast <int32_t>(index));
820 data.writeUint32(static_cast <uint32_t>(device));
821 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
822 if (status != NO_ERROR) {
823 return NAN;
824 }
825 return reply.readFloat();
826 }
jiabin81772902018-04-02 17:52:27 -0700827
828 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
829 audio_format_t *surroundFormats,
830 bool *surroundFormatsEnabled,
831 bool reported)
832 {
833 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
834 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
835 return BAD_VALUE;
836 }
837 Parcel data, reply;
838 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
839 unsigned int numSurroundFormatsReq = *numSurroundFormats;
840 data.writeUint32(numSurroundFormatsReq);
841 data.writeBool(reported);
842 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
843 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
844 *numSurroundFormats = reply.readUint32();
845 }
846 if (status == NO_ERROR) {
847 if (numSurroundFormatsReq > *numSurroundFormats) {
848 numSurroundFormatsReq = *numSurroundFormats;
849 }
850 if (numSurroundFormatsReq > 0) {
851 status = reply.read(surroundFormats,
852 numSurroundFormatsReq * sizeof(audio_format_t));
853 if (status != NO_ERROR) {
854 return status;
855 }
856 status = reply.read(surroundFormatsEnabled,
857 numSurroundFormatsReq * sizeof(bool));
858 }
859 }
860 return status;
861 }
862
863 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
864 {
865 Parcel data, reply;
866 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
867 data.writeInt32(audioFormat);
868 data.writeBool(enabled);
869 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
870 if (status != NO_ERROR) {
871 return status;
872 }
873 return reply.readInt32();
874 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700875
876 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
877 const String16& opPackageName,
878 const effect_uuid_t *uuid,
879 int32_t priority,
880 audio_usage_t usage,
881 audio_unique_id_t* id)
882 {
883 Parcel data, reply;
884 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
885 data.write(type, sizeof(effect_uuid_t));
886 data.writeString16(opPackageName);
887 data.write(uuid, sizeof(effect_uuid_t));
888 data.writeInt32(priority);
889 data.writeInt32((int32_t) usage);
890 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
891 if (status != NO_ERROR) {
892 return status;
893 }
894 status = static_cast <status_t> (reply.readInt32());
895 *id = reply.readInt32();
896 return status;
897 }
898
899 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
900 {
901 Parcel data, reply;
902 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
903 data.writeInt32(id);
904 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
905 if (status != NO_ERROR) {
906 return status;
907 }
908 return static_cast <status_t> (reply.readInt32());
909 }
910
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700911 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
912 const String16& opPackageName,
913 const effect_uuid_t *uuid,
914 int32_t priority,
915 audio_source_t source,
916 audio_unique_id_t* id)
917 {
918 Parcel data, reply;
919 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
920 data.write(type, sizeof(effect_uuid_t));
921 data.writeString16(opPackageName);
922 data.write(uuid, sizeof(effect_uuid_t));
923 data.writeInt32(priority);
924 data.writeInt32((int32_t) source);
925 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
926 if (status != NO_ERROR) {
927 return status;
928 }
929 status = static_cast <status_t> (reply.readInt32());
930 *id = reply.readInt32();
931 return status;
932 }
933
934 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
935 {
936 Parcel data, reply;
937 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
938 data.writeInt32(id);
939 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
940 if (status != NO_ERROR) {
941 return status;
942 }
943 return static_cast <status_t> (reply.readInt32());
944 }
945
Eric Laurentb78763e2018-10-17 10:08:02 -0700946 virtual status_t setAssistantUid(uid_t uid)
947 {
948 Parcel data, reply;
949 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
950 data.writeInt32(uid);
951 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
952 if (status != NO_ERROR) {
953 return status;
954 }
955 return static_cast <status_t> (reply.readInt32());
956 }
957
958 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
959 {
960 Parcel data, reply;
961 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
962 data.writeInt32(uids.size());
963 for (auto uid : uids) {
964 data.writeInt32(uid);
965 }
966 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
967 if (status != NO_ERROR) {
968 return status;
969 }
970 return static_cast <status_t> (reply.readInt32());
971 }
972
Eric Laurentc2f1f072009-07-17 12:17:14 -0700973};
974
975IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
976
977// ----------------------------------------------------------------------
978
Eric Laurentc2f1f072009-07-17 12:17:14 -0700979status_t BnAudioPolicyService::onTransact(
980 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
981{
Eric Laurentb1cc36b2017-12-11 12:14:16 -0800982 // make sure transactions reserved to AudioFlinger do not come from other processes
983 switch (code) {
984 case START_OUTPUT:
985 case STOP_OUTPUT:
986 case RELEASE_OUTPUT:
987 case GET_INPUT_FOR_ATTR:
988 case START_INPUT:
989 case STOP_INPUT:
990 case RELEASE_INPUT:
991 case GET_STRATEGY_FOR_STREAM:
992 case GET_OUTPUT_FOR_EFFECT:
993 case REGISTER_EFFECT:
994 case UNREGISTER_EFFECT:
995 case SET_EFFECT_ENABLED:
996 case GET_OUTPUT_FOR_ATTR:
997 case ACQUIRE_SOUNDTRIGGER_SESSION:
998 case RELEASE_SOUNDTRIGGER_SESSION:
999 ALOGW("%s: transaction %d received from PID %d",
1000 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001001 // return status only for non void methods
1002 switch (code) {
1003 case RELEASE_OUTPUT:
1004 case RELEASE_INPUT:
1005 break;
1006 default:
1007 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1008 break;
1009 }
1010 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001011 default:
1012 break;
1013 }
1014
Eric Laurent4980df22018-01-26 18:04:09 -08001015 // make sure the following transactions come from system components
1016 switch (code) {
1017 case SET_DEVICE_CONNECTION_STATE:
1018 case HANDLE_DEVICE_CONFIG_CHANGE:
1019 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001020//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1021// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001022 case INIT_STREAM_VOLUME:
1023 case SET_STREAM_VOLUME:
1024 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001025 case SET_MASTER_MONO:
1026 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001027 case STOP_AUDIO_SOURCE:
1028 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001029 case SET_SURROUND_FORMAT_ENABLED:
1030 case SET_ASSISTANT_UID:
1031 case SET_A11Y_SERVICES_UIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001032 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001033 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1034 __func__, code, IPCThreadState::self()->getCallingPid(),
1035 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001036 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1037 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001038 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001039 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001040 default:
1041 break;
1042 }
1043
Eric Laurent39b09b52018-06-29 12:24:40 -07001044 std::string tag("IAudioPolicyService command " + std::to_string(code));
1045 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001046
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001047 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001048 case SET_DEVICE_CONNECTION_STATE: {
1049 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001050 audio_devices_t device =
1051 static_cast <audio_devices_t>(data.readInt32());
1052 audio_policy_dev_state_t state =
1053 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001054 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001055 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001056 if (device_address == nullptr || device_name == nullptr) {
1057 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1058 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1059 } else {
1060 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1061 state,
1062 device_address,
1063 device_name)));
1064 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 return NO_ERROR;
1066 } break;
1067
1068 case GET_DEVICE_CONNECTION_STATE: {
1069 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001070 audio_devices_t device =
1071 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001072 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001073 if (device_address == nullptr) {
1074 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1075 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1076 } else {
1077 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1078 device_address)));
1079 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001080 return NO_ERROR;
1081 } break;
1082
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001083 case HANDLE_DEVICE_CONFIG_CHANGE: {
1084 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1085 audio_devices_t device =
1086 static_cast <audio_devices_t>(data.readInt32());
1087 const char *device_address = data.readCString();
1088 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001089 if (device_address == nullptr || device_name == nullptr) {
1090 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1091 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1092 } else {
1093 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1094 device_address,
1095 device_name)));
1096 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001097 return NO_ERROR;
1098 } break;
1099
Eric Laurentc2f1f072009-07-17 12:17:14 -07001100 case SET_PHONE_STATE: {
1101 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001102 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1103 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001104 return NO_ERROR;
1105 } break;
1106
Eric Laurentc2f1f072009-07-17 12:17:14 -07001107 case SET_FORCE_USE: {
1108 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001109 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1110 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001111 audio_policy_forced_cfg_t config =
1112 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001113 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1114 return NO_ERROR;
1115 } break;
1116
1117 case GET_FORCE_USE: {
1118 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001119 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1120 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001121 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1122 return NO_ERROR;
1123 } break;
1124
1125 case GET_OUTPUT: {
1126 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001127 audio_stream_type_t stream =
1128 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001129 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001130 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001131 return NO_ERROR;
1132 } break;
1133
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001134 case GET_OUTPUT_FOR_ATTR: {
1135 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001136 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001137 bool hasAttributes = data.readInt32() != 0;
1138 if (hasAttributes) {
1139 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001140 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001141 }
1142 audio_session_t session = (audio_session_t)data.readInt32();
1143 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1144 bool hasStream = data.readInt32() != 0;
1145 if (hasStream) {
1146 stream = (audio_stream_type_t)data.readInt32();
1147 }
Nadav Bar766fb022018-01-07 12:18:03 +02001148 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001149 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001150 audio_config_t config;
1151 memset(&config, 0, sizeof(audio_config_t));
1152 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001153 audio_output_flags_t flags =
1154 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001155 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001156 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001157 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001158 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001159 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001160 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001161 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001162 reply->writeInt32(status);
1163 reply->writeInt32(output);
1164 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001165 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001166 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001167 return NO_ERROR;
1168 } break;
1169
Eric Laurentc2f1f072009-07-17 12:17:14 -07001170 case START_OUTPUT: {
1171 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001172 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1173 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001174 return NO_ERROR;
1175 } break;
1176
1177 case STOP_OUTPUT: {
1178 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001179 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1180 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001181 return NO_ERROR;
1182 } break;
1183
1184 case RELEASE_OUTPUT: {
1185 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001186 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1187 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001188 return NO_ERROR;
1189 } break;
1190
Eric Laurentcaf7f482014-11-25 17:50:47 -08001191 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001192 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001193 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001194 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001195 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001196 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001197 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001198 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001199 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001200 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001201 audio_config_base_t config;
1202 memset(&config, 0, sizeof(audio_config_base_t));
1203 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001204 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001205 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001206 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001207 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001208 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001209 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001210 reply->writeInt32(status);
1211 if (status == NO_ERROR) {
1212 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001213 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001214 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001215 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001216 return NO_ERROR;
1217 } break;
1218
1219 case START_INPUT: {
1220 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001221 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001222 bool silenced = data.readInt32() == 1;
Eric Laurentfee19762018-01-29 18:44:13 -08001223 status_t status = startInput(portId, &silenced);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001224 reply->writeInt32(static_cast <uint32_t>(status));
1225 reply->writeInt32(silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001226 return NO_ERROR;
1227 } break;
1228
1229 case STOP_INPUT: {
1230 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001231 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1232 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001233 return NO_ERROR;
1234 } break;
1235
1236 case RELEASE_INPUT: {
1237 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001238 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1239 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001240 return NO_ERROR;
1241 } break;
1242
1243 case INIT_STREAM_VOLUME: {
1244 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001245 audio_stream_type_t stream =
1246 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001247 int indexMin = data.readInt32();
1248 int indexMax = data.readInt32();
1249 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1250 return NO_ERROR;
1251 } break;
1252
1253 case SET_STREAM_VOLUME: {
1254 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001255 audio_stream_type_t stream =
1256 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001257 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001258 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1259 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1260 index,
1261 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001262 return NO_ERROR;
1263 } break;
1264
1265 case GET_STREAM_VOLUME: {
1266 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001267 audio_stream_type_t stream =
1268 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001269 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001270 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001271 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001272 reply->writeInt32(index);
1273 reply->writeInt32(static_cast <uint32_t>(status));
1274 return NO_ERROR;
1275 } break;
1276
Eric Laurentde070132010-07-13 04:45:46 -07001277 case GET_STRATEGY_FOR_STREAM: {
1278 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001279 audio_stream_type_t stream =
1280 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001281 reply->writeInt32(getStrategyForStream(stream));
1282 return NO_ERROR;
1283 } break;
1284
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001285 case GET_DEVICES_FOR_STREAM: {
1286 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001287 audio_stream_type_t stream =
1288 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001289 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1290 return NO_ERROR;
1291 } break;
1292
Eric Laurentde070132010-07-13 04:45:46 -07001293 case GET_OUTPUT_FOR_EFFECT: {
1294 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001295 effect_descriptor_t desc = {};
1296 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1297 android_errorWriteLog(0x534e4554, "73126106");
1298 }
1299 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001300 audio_io_handle_t output = getOutputForEffect(&desc);
1301 reply->writeInt32(static_cast <int>(output));
1302 return NO_ERROR;
1303 } break;
1304
1305 case REGISTER_EFFECT: {
1306 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001307 effect_descriptor_t desc = {};
1308 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1309 android_errorWriteLog(0x534e4554, "73126106");
1310 }
1311 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001312 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001313 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001314 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001315 int id = data.readInt32();
1316 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001317 io,
Eric Laurentde070132010-07-13 04:45:46 -07001318 strategy,
1319 session,
1320 id)));
1321 return NO_ERROR;
1322 } break;
1323
1324 case UNREGISTER_EFFECT: {
1325 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1326 int id = data.readInt32();
1327 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1328 return NO_ERROR;
1329 } break;
1330
Eric Laurentdb7c0792011-08-10 10:37:50 -07001331 case SET_EFFECT_ENABLED: {
1332 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1333 int id = data.readInt32();
1334 bool enabled = static_cast <bool>(data.readInt32());
1335 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1336 return NO_ERROR;
1337 } break;
1338
Eric Laurenteda6c362011-02-02 09:33:30 -08001339 case IS_STREAM_ACTIVE: {
1340 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001341 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001342 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001343 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001344 return NO_ERROR;
1345 } break;
1346
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001347 case IS_STREAM_ACTIVE_REMOTELY: {
1348 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1349 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1350 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001351 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001352 return NO_ERROR;
1353 } break;
1354
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001355 case IS_SOURCE_ACTIVE: {
1356 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1357 audio_source_t source = (audio_source_t) data.readInt32();
1358 reply->writeInt32( isSourceActive(source));
1359 return NO_ERROR;
1360 }
1361
Eric Laurent57dae992011-07-24 13:36:09 -07001362 case QUERY_DEFAULT_PRE_PROCESSING: {
1363 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001364 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001365 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001366 if (count > AudioEffect::kMaxPreProcessing) {
1367 count = AudioEffect::kMaxPreProcessing;
1368 }
Eric Laurent57dae992011-07-24 13:36:09 -07001369 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001370 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001371 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1372 reply->writeInt32(status);
1373 if (status != NO_ERROR && status != NO_MEMORY) {
1374 retCount = 0;
1375 }
1376 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001377 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001378 if (retCount < count) {
1379 count = retCount;
1380 }
1381 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1382 }
1383 delete[] descriptors;
1384 return status;
1385 }
1386
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001387 case IS_OFFLOAD_SUPPORTED: {
1388 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001389 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001390 data.read(&info, sizeof(audio_offload_info_t));
1391 bool isSupported = isOffloadSupported(info);
1392 reply->writeInt32(isSupported);
1393 return NO_ERROR;
1394 }
1395
Eric Laurent203b1a12014-04-01 10:34:16 -07001396 case LIST_AUDIO_PORTS: {
1397 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1398 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1399 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1400 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001401 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1402 numPortsReq = MAX_ITEMS_PER_LIST;
1403 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001404 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001405 struct audio_port *ports =
1406 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001407 if (ports == NULL) {
1408 reply->writeInt32(NO_MEMORY);
1409 reply->writeInt32(0);
1410 return NO_ERROR;
1411 }
1412 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001413 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1414 reply->writeInt32(status);
1415 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001416
1417 if (status == NO_ERROR) {
1418 if (numPortsReq > numPorts) {
1419 numPortsReq = numPorts;
1420 }
1421 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1422 reply->writeInt32(generation);
1423 }
1424 free(ports);
1425 return NO_ERROR;
1426 }
1427
1428 case GET_AUDIO_PORT: {
1429 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001430 struct audio_port port = {};
1431 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1432 ALOGE("b/23912202");
1433 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001434 status_t status = getAudioPort(&port);
1435 reply->writeInt32(status);
1436 if (status == NO_ERROR) {
1437 reply->write(&port, sizeof(struct audio_port));
1438 }
1439 return NO_ERROR;
1440 }
1441
1442 case CREATE_AUDIO_PATCH: {
1443 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001444 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001445 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001446 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001447 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1448 ALOGE("b/23912202");
1449 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001450 status_t status = createAudioPatch(&patch, &handle);
1451 reply->writeInt32(status);
1452 if (status == NO_ERROR) {
1453 reply->write(&handle, sizeof(audio_patch_handle_t));
1454 }
1455 return NO_ERROR;
1456 }
1457
1458 case RELEASE_AUDIO_PATCH: {
1459 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001460 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001461 data.read(&handle, sizeof(audio_patch_handle_t));
1462 status_t status = releaseAudioPatch(handle);
1463 reply->writeInt32(status);
1464 return NO_ERROR;
1465 }
1466
1467 case LIST_AUDIO_PATCHES: {
1468 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1469 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001470 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1471 numPatchesReq = MAX_ITEMS_PER_LIST;
1472 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001473 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001474 struct audio_patch *patches =
1475 (struct audio_patch *)calloc(numPatchesReq,
1476 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001477 if (patches == NULL) {
1478 reply->writeInt32(NO_MEMORY);
1479 reply->writeInt32(0);
1480 return NO_ERROR;
1481 }
1482 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001483 status_t status = listAudioPatches(&numPatches, patches, &generation);
1484 reply->writeInt32(status);
1485 reply->writeInt32(numPatches);
1486 if (status == NO_ERROR) {
1487 if (numPatchesReq > numPatches) {
1488 numPatchesReq = numPatches;
1489 }
1490 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1491 reply->writeInt32(generation);
1492 }
1493 free(patches);
1494 return NO_ERROR;
1495 }
1496
1497 case SET_AUDIO_PORT_CONFIG: {
1498 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001499 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001500 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001501 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001502 status_t status = setAudioPortConfig(&config);
1503 reply->writeInt32(status);
1504 return NO_ERROR;
1505 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001506
Eric Laurentb52c1522014-05-20 11:27:36 -07001507 case REGISTER_CLIENT: {
1508 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1509 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1510 data.readStrongBinder());
1511 registerClient(client);
1512 return NO_ERROR;
1513 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001514
Eric Laurente8726fe2015-06-26 09:39:24 -07001515 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1516 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1517 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1518 return NO_ERROR;
1519 } break;
1520
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001521 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1522 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1523 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1524 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001525 audio_session_t session = AUDIO_SESSION_NONE;
1526 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1527 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001528 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1529 reply->writeInt32(status);
1530 if (status == NO_ERROR) {
1531 reply->writeInt32(session);
1532 reply->writeInt32(ioHandle);
1533 reply->writeInt32(device);
1534 }
1535 return NO_ERROR;
1536 } break;
1537
1538 case RELEASE_SOUNDTRIGGER_SESSION: {
1539 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1540 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1541 data.readStrongBinder());
1542 audio_session_t session = (audio_session_t)data.readInt32();
1543 status_t status = releaseSoundTriggerSession(session);
1544 reply->writeInt32(status);
1545 return NO_ERROR;
1546 } break;
1547
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001548 case GET_PHONE_STATE: {
1549 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1550 reply->writeInt32((int32_t)getPhoneState());
1551 return NO_ERROR;
1552 } break;
1553
Eric Laurentbaac1832014-12-01 17:52:59 -08001554 case REGISTER_POLICY_MIXES: {
1555 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1556 bool registration = data.readInt32() == 1;
1557 Vector<AudioMix> mixes;
1558 size_t size = (size_t)data.readInt32();
1559 if (size > MAX_MIXES_PER_POLICY) {
1560 size = MAX_MIXES_PER_POLICY;
1561 }
1562 for (size_t i = 0; i < size; i++) {
1563 AudioMix mix;
1564 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1565 mixes.add(mix);
1566 }
1567 }
1568 status_t status = registerPolicyMixes(mixes, registration);
1569 reply->writeInt32(status);
1570 return NO_ERROR;
1571 } break;
1572
Eric Laurent554a2772015-04-10 11:29:24 -07001573 case START_AUDIO_SOURCE: {
1574 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001575 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001576 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001577 (void)sanitizeAudioPortConfig(&source);
1578 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001579 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001580 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001581 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1582 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001583 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001584 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001585 return NO_ERROR;
1586 } break;
1587
1588 case STOP_AUDIO_SOURCE: {
1589 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001590 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1591 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001592 reply->writeInt32(status);
1593 return NO_ERROR;
1594 } break;
1595
Andy Hung2ddee192015-12-18 17:34:44 -08001596 case SET_MASTER_MONO: {
1597 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1598 bool mono = static_cast<bool>(data.readInt32());
1599 status_t status = setMasterMono(mono);
1600 reply->writeInt32(status);
1601 return NO_ERROR;
1602 } break;
1603
1604 case GET_MASTER_MONO: {
1605 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1606 bool mono;
1607 status_t status = getMasterMono(&mono);
1608 reply->writeInt32(status);
1609 if (status == NO_ERROR) {
1610 reply->writeInt32(static_cast<int32_t>(mono));
1611 }
1612 return NO_ERROR;
1613 } break;
1614
Eric Laurentac9cef52017-06-09 15:46:26 -07001615 case GET_STREAM_VOLUME_DB: {
1616 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1617 audio_stream_type_t stream =
1618 static_cast <audio_stream_type_t>(data.readInt32());
1619 int index = static_cast <int>(data.readInt32());
1620 audio_devices_t device =
1621 static_cast <audio_devices_t>(data.readUint32());
1622 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1623 return NO_ERROR;
1624 }
1625
jiabin81772902018-04-02 17:52:27 -07001626 case GET_SURROUND_FORMATS: {
1627 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1628 unsigned int numSurroundFormatsReq = data.readUint32();
1629 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1630 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1631 }
1632 bool reported = data.readBool();
1633 unsigned int numSurroundFormats = numSurroundFormatsReq;
1634 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1635 numSurroundFormats, sizeof(audio_format_t));
1636 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1637 if (numSurroundFormatsReq > 0 &&
1638 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1639 free(surroundFormats);
1640 free(surroundFormatsEnabled);
1641 reply->writeInt32(NO_MEMORY);
1642 return NO_ERROR;
1643 }
1644 status_t status = getSurroundFormats(
1645 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1646 reply->writeInt32(status);
1647
1648 if (status == NO_ERROR) {
1649 reply->writeUint32(numSurroundFormats);
1650 if (numSurroundFormatsReq > numSurroundFormats) {
1651 numSurroundFormatsReq = numSurroundFormats;
1652 }
1653 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1654 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1655 }
1656 free(surroundFormats);
1657 free(surroundFormatsEnabled);
1658 return NO_ERROR;
1659 }
1660
1661 case SET_SURROUND_FORMAT_ENABLED: {
1662 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1663 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1664 bool enabled = data.readBool();
1665 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1666 reply->writeInt32(status);
1667 return NO_ERROR;
1668 }
1669
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001670 case ADD_STREAM_DEFAULT_EFFECT: {
1671 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1672 effect_uuid_t type;
1673 status_t status = data.read(&type, sizeof(effect_uuid_t));
1674 if (status != NO_ERROR) {
1675 return status;
1676 }
1677 String16 opPackageName;
1678 status = data.readString16(&opPackageName);
1679 if (status != NO_ERROR) {
1680 return status;
1681 }
1682 effect_uuid_t uuid;
1683 status = data.read(&uuid, sizeof(effect_uuid_t));
1684 if (status != NO_ERROR) {
1685 return status;
1686 }
1687 int32_t priority = data.readInt32();
1688 audio_usage_t usage = (audio_usage_t) data.readInt32();
1689 audio_unique_id_t id = 0;
1690 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1691 opPackageName,
1692 &uuid,
1693 priority,
1694 usage,
1695 &id)));
1696 reply->writeInt32(id);
1697 return NO_ERROR;
1698 }
1699
1700 case REMOVE_STREAM_DEFAULT_EFFECT: {
1701 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1702 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1703 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1704 return NO_ERROR;
1705 }
1706
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001707 case ADD_SOURCE_DEFAULT_EFFECT: {
1708 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1709 effect_uuid_t type;
1710 status_t status = data.read(&type, sizeof(effect_uuid_t));
1711 if (status != NO_ERROR) {
1712 return status;
1713 }
1714 String16 opPackageName;
1715 status = data.readString16(&opPackageName);
1716 if (status != NO_ERROR) {
1717 return status;
1718 }
1719 effect_uuid_t uuid;
1720 status = data.read(&uuid, sizeof(effect_uuid_t));
1721 if (status != NO_ERROR) {
1722 return status;
1723 }
1724 int32_t priority = data.readInt32();
1725 audio_source_t source = (audio_source_t) data.readInt32();
1726 audio_unique_id_t id = 0;
1727 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1728 opPackageName,
1729 &uuid,
1730 priority,
1731 source,
1732 &id)));
1733 reply->writeInt32(id);
1734 return NO_ERROR;
1735 }
1736
1737 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1738 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1739 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1740 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1741 return NO_ERROR;
1742 }
1743
Eric Laurentb78763e2018-10-17 10:08:02 -07001744 case SET_ASSISTANT_UID: {
1745 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1746 int32_t uid;
1747 status_t status = data.readInt32(&uid);
1748 if (status != NO_ERROR) {
1749 return status;
1750 }
1751 status = setAssistantUid(uid);
1752 reply->writeInt32(static_cast <int32_t>(status));
1753 return NO_ERROR;
1754 }
1755
1756 case SET_A11Y_SERVICES_UIDS: {
1757 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1758 std::vector<uid_t> uids;
1759 int32_t size;
1760 status_t status = data.readInt32(&size);
1761 if (status != NO_ERROR) {
1762 return status;
1763 }
1764 if (size > MAX_ITEMS_PER_LIST) {
1765 size = MAX_ITEMS_PER_LIST;
1766 }
1767 for (int32_t i = 0; i < size; i++) {
1768 int32_t uid;
1769 status = data.readInt32(&uid);
1770 if (status != NO_ERROR) {
1771 return status;
1772 }
1773 uids.push_back(uid);
1774 }
1775 status = setA11yServicesUids(uids);
1776 reply->writeInt32(static_cast <int32_t>(status));
1777 return NO_ERROR;
1778 }
1779
Eric Laurentc2f1f072009-07-17 12:17:14 -07001780 default:
1781 return BBinder::onTransact(code, data, reply, flags);
1782 }
1783}
1784
Andy Hungb0272092018-04-12 11:06:56 -07001785/** returns true if string overflow was prevented by zero termination */
1786template <size_t size>
1787static bool preventStringOverflow(char (&s)[size]) {
1788 if (strnlen(s, size) < size) return false;
1789 s[size - 1] = '\0';
1790 return true;
1791}
1792
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001793void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1794{
1795 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1796 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1797 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1798 }
1799 attr->tags[tagsMaxSize - 1] = '\0';
1800}
1801
Andy Hungb0272092018-04-12 11:06:56 -07001802/** returns BAD_VALUE if sanitization was required. */
1803status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1804{
1805 if (preventStringOverflow(desc->name)
1806 | /* always */ preventStringOverflow(desc->implementor)) {
1807 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1808 return BAD_VALUE;
1809 }
1810 return NO_ERROR;
1811}
1812
1813/** returns BAD_VALUE if sanitization was required. */
1814status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1815{
1816 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1817 preventStringOverflow(config->ext.device.address)) {
1818 return BAD_VALUE;
1819 }
1820 return NO_ERROR;
1821}
1822
Eric Laurentc2f1f072009-07-17 12:17:14 -07001823// ----------------------------------------------------------------------------
1824
Glenn Kasten40bc9062015-03-20 09:09:33 -07001825} // namespace android