blob: 5f47761c23744772a620fb4603a2ca6758523747 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
Eric Laurentac9cef52017-06-09 15:46:26 -070022#include <math.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <sys/types.h>
24
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070026#include <binder/Parcel.h>
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
Eric Laurent3528c932018-02-23 17:17:22 -080029#include <media/TimeCheck.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070030#include <mediautils/ServiceUtilities.h>
Dima Zavin64760242011-05-11 14:15:23 -070031#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070032
Eric Laurentc2f1f072009-07-17 12:17:14 -070033namespace android {
34
35enum {
36 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
37 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080038 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080040 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 SET_FORCE_USE,
42 GET_FORCE_USE,
43 GET_OUTPUT,
44 START_OUTPUT,
45 STOP_OUTPUT,
46 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080047 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070048 START_INPUT,
49 STOP_INPUT,
50 RELEASE_INPUT,
51 INIT_STREAM_VOLUME,
52 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070053 GET_STREAM_VOLUME,
54 GET_STRATEGY_FOR_STREAM,
55 GET_OUTPUT_FOR_EFFECT,
56 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080057 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070059 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080060 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070061 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080062 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000063 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070064 IS_OFFLOAD_SUPPORTED,
Michael Chana94fbb22018-04-24 14:31:19 +100065 IS_DIRECT_OUTPUT_SUPPORTED,
Eric Laurent203b1a12014-04-01 10:34:16 -070066 LIST_AUDIO_PORTS,
67 GET_AUDIO_PORT,
68 CREATE_AUDIO_PATCH,
69 RELEASE_AUDIO_PATCH,
70 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070071 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070072 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070073 GET_OUTPUT_FOR_ATTR,
74 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070075 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080076 GET_PHONE_STATE,
77 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070078 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070079 STOP_AUDIO_SOURCE,
80 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080081 SET_MASTER_MONO,
82 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070083 GET_STREAM_VOLUME_DB,
84 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070085 SET_SURROUND_FORMAT_ENABLED,
86 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070087 REMOVE_STREAM_DEFAULT_EFFECT,
88 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070089 REMOVE_SOURCE_DEFAULT_EFFECT,
90 SET_ASSISTANT_UID,
91 SET_A11Y_SERVICES_UIDS,
Eric Laurentc2f1f072009-07-17 12:17:14 -070092};
93
Eric Laurent1d670b12015-02-06 10:44:24 -080094#define MAX_ITEMS_PER_LIST 1024
95
Eric Laurentc2f1f072009-07-17 12:17:14 -070096class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
97{
98public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070099 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100 : BpInterface<IAudioPolicyService>(impl)
101 {
102 }
103
104 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700105 audio_devices_t device,
106 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800107 const char *device_address,
108 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109 {
110 Parcel data, reply;
111 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
112 data.writeInt32(static_cast <uint32_t>(device));
113 data.writeInt32(static_cast <uint32_t>(state));
114 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800115 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700116 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
117 return static_cast <status_t> (reply.readInt32());
118 }
119
Dima Zavinfce7a472011-04-19 22:30:36 -0700120 virtual audio_policy_dev_state_t getDeviceConnectionState(
121 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700122 const char *device_address)
123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
126 data.writeInt32(static_cast <uint32_t>(device));
127 data.writeCString(device_address);
128 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700129 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 }
131
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800132 virtual status_t handleDeviceConfigChange(audio_devices_t device,
133 const char *device_address,
134 const char *device_name)
135 {
136 Parcel data, reply;
137 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
138 data.writeInt32(static_cast <uint32_t>(device));
139 data.writeCString(device_address);
140 data.writeCString(device_name);
141 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
142 return static_cast <status_t> (reply.readInt32());
143 }
144
Glenn Kastenf78aee72012-01-04 11:00:47 -0800145 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 {
147 Parcel data, reply;
148 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
149 data.writeInt32(state);
150 remote()->transact(SET_PHONE_STATE, data, &reply);
151 return static_cast <status_t> (reply.readInt32());
152 }
153
Dima Zavinfce7a472011-04-19 22:30:36 -0700154 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700155 {
156 Parcel data, reply;
157 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
158 data.writeInt32(static_cast <uint32_t>(usage));
159 data.writeInt32(static_cast <uint32_t>(config));
160 remote()->transact(SET_FORCE_USE, data, &reply);
161 return static_cast <status_t> (reply.readInt32());
162 }
163
Dima Zavinfce7a472011-04-19 22:30:36 -0700164 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700165 {
166 Parcel data, reply;
167 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
168 data.writeInt32(static_cast <uint32_t>(usage));
169 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700170 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700171 }
172
Eric Laurentf4e63452017-11-06 19:31:46 +0000173 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700174 {
175 Parcel data, reply;
176 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
177 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700178 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700179 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700180 }
181
Eric Laurente83b55d2014-11-14 10:06:21 -0800182 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
183 audio_io_handle_t *output,
184 audio_session_t session,
185 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200186 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700187 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800188 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800189 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700190 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800191 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700192 {
193 Parcel data, reply;
194 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
195 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800196 if (stream == NULL) {
197 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
198 return BAD_VALUE;
199 }
200 if (*stream == AUDIO_STREAM_DEFAULT) {
201 ALOGE("getOutputForAttr unspecified stream type");
202 return BAD_VALUE;
203 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700204 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800205 if (output == NULL) {
206 ALOGE("getOutputForAttr NULL output - shouldn't happen");
207 return BAD_VALUE;
208 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700209 if (selectedDeviceId == NULL) {
210 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
211 return BAD_VALUE;
212 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800213 if (portId == NULL) {
214 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
215 return BAD_VALUE;
216 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800217 if (attr == NULL) {
218 data.writeInt32(0);
219 } else {
220 data.writeInt32(1);
221 data.write(attr, sizeof(audio_attributes_t));
222 }
223 data.writeInt32(session);
224 if (stream == NULL) {
225 data.writeInt32(0);
226 } else {
227 data.writeInt32(1);
228 data.writeInt32(*stream);
229 }
Nadav Bar766fb022018-01-07 12:18:03 +0200230 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700231 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800232 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700233 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700234 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800235 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800236 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
237 if (status != NO_ERROR) {
238 return status;
239 }
240 status = (status_t)reply.readInt32();
241 if (status != NO_ERROR) {
242 return status;
243 }
244 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800245 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800246 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800247 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800248 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700249 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700252 }
253
Eric Laurentd7fe0862018-07-14 16:48:01 -0700254 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700258 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 remote()->transact(START_OUTPUT, data, &reply);
260 return static_cast <status_t> (reply.readInt32());
261 }
262
Eric Laurentd7fe0862018-07-14 16:48:01 -0700263 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700267 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 remote()->transact(STOP_OUTPUT, data, &reply);
269 return static_cast <status_t> (reply.readInt32());
270 }
271
Eric Laurentd7fe0862018-07-14 16:48:01 -0700272 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700276 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 remote()->transact(RELEASE_OUTPUT, data, &reply);
278 }
279
Eric Laurentcaf7f482014-11-25 17:50:47 -0800280 virtual status_t getInputForAttr(const audio_attributes_t *attr,
281 audio_io_handle_t *input,
282 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700283 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700284 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800285 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800286 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600287 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700288 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800289 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800293 if (attr == NULL) {
294 ALOGE("getInputForAttr NULL attr - shouldn't happen");
295 return BAD_VALUE;
296 }
297 if (input == NULL) {
298 ALOGE("getInputForAttr NULL input - shouldn't happen");
299 return BAD_VALUE;
300 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700301 if (selectedDeviceId == NULL) {
302 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
303 return BAD_VALUE;
304 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800305 if (portId == NULL) {
306 ALOGE("getInputForAttr NULL portId - shouldn't happen");
307 return BAD_VALUE;
308 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800309 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700310 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800311 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700312 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700313 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800314 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800315 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700316 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700317 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800318 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800319 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
320 if (status != NO_ERROR) {
321 return status;
322 }
323 status = reply.readInt32();
324 if (status != NO_ERROR) {
325 return status;
326 }
327 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700328 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800329 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800330 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700331 }
332
Eric Laurentfee19762018-01-29 18:44:13 -0800333 virtual status_t startInput(audio_port_handle_t portId,
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800334 bool *silenced)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800338 data.writeInt32(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800339 data.writeInt32(*silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800341 status_t status = static_cast <status_t> (reply.readInt32());
342 *silenced = reply.readInt32() == 1;
343 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700344 }
345
Eric Laurentfee19762018-01-29 18:44:13 -0800346 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800350 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 remote()->transact(STOP_INPUT, data, &reply);
352 return static_cast <status_t> (reply.readInt32());
353 }
354
Eric Laurentfee19762018-01-29 18:44:13 -0800355 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800359 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 remote()->transact(RELEASE_INPUT, data, &reply);
361 }
362
Dima Zavinfce7a472011-04-19 22:30:36 -0700363 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 int indexMin,
365 int indexMax)
366 {
367 Parcel data, reply;
368 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
369 data.writeInt32(static_cast <uint32_t>(stream));
370 data.writeInt32(indexMin);
371 data.writeInt32(indexMax);
372 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
373 return static_cast <status_t> (reply.readInt32());
374 }
375
Eric Laurent83844cc2011-11-18 16:43:31 -0800376 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
377 int index,
378 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700379 {
380 Parcel data, reply;
381 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
382 data.writeInt32(static_cast <uint32_t>(stream));
383 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800384 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700385 remote()->transact(SET_STREAM_VOLUME, data, &reply);
386 return static_cast <status_t> (reply.readInt32());
387 }
388
Eric Laurent83844cc2011-11-18 16:43:31 -0800389 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
390 int *index,
391 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
395 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800396 data.writeInt32(static_cast <uint32_t>(device));
397
Eric Laurentc2f1f072009-07-17 12:17:14 -0700398 remote()->transact(GET_STREAM_VOLUME, data, &reply);
399 int lIndex = reply.readInt32();
400 if (index) *index = lIndex;
401 return static_cast <status_t> (reply.readInt32());
402 }
Eric Laurentde070132010-07-13 04:45:46 -0700403
Dima Zavinfce7a472011-04-19 22:30:36 -0700404 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
408 data.writeInt32(static_cast <uint32_t>(stream));
409 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
410 return reply.readInt32();
411 }
412
Eric Laurent63742522012-03-08 13:42:42 -0800413 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
417 data.writeInt32(static_cast <uint32_t>(stream));
418 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800419 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800420 }
421
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700422 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
426 data.write(desc, sizeof(effect_descriptor_t));
427 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
428 return static_cast <audio_io_handle_t> (reply.readInt32());
429 }
430
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700431 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700432 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700433 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800434 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700435 int id)
436 {
437 Parcel data, reply;
438 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
439 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700440 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700441 data.writeInt32(strategy);
442 data.writeInt32(session);
443 data.writeInt32(id);
444 remote()->transact(REGISTER_EFFECT, data, &reply);
445 return static_cast <status_t> (reply.readInt32());
446 }
447
448 virtual status_t unregisterEffect(int id)
449 {
450 Parcel data, reply;
451 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
452 data.writeInt32(id);
453 remote()->transact(UNREGISTER_EFFECT, data, &reply);
454 return static_cast <status_t> (reply.readInt32());
455 }
456
Eric Laurentdb7c0792011-08-10 10:37:50 -0700457 virtual status_t setEffectEnabled(int id, bool enabled)
458 {
459 Parcel data, reply;
460 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
461 data.writeInt32(id);
462 data.writeInt32(enabled);
463 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
464 return static_cast <status_t> (reply.readInt32());
465 }
466
Glenn Kastenfff6d712012-01-12 16:38:12 -0800467 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800471 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800472 data.writeInt32(inPastMs);
473 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
474 return reply.readInt32();
475 }
Eric Laurent57dae992011-07-24 13:36:09 -0700476
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800477 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
478 {
479 Parcel data, reply;
480 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
481 data.writeInt32((int32_t) stream);
482 data.writeInt32(inPastMs);
483 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
484 return reply.readInt32();
485 }
486
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700487 virtual bool isSourceActive(audio_source_t source) const
488 {
489 Parcel data, reply;
490 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
491 data.writeInt32((int32_t) source);
492 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
493 return reply.readInt32();
494 }
495
Glenn Kastend848eb42016-03-08 13:42:11 -0800496 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700497 effect_descriptor_t *descriptors,
498 uint32_t *count)
499 {
500 if (descriptors == NULL || count == NULL) {
501 return BAD_VALUE;
502 }
503 Parcel data, reply;
504 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
505 data.writeInt32(audioSession);
506 data.writeInt32(*count);
507 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
508 if (status != NO_ERROR) {
509 return status;
510 }
511 status = static_cast <status_t> (reply.readInt32());
512 uint32_t retCount = reply.readInt32();
513 if (retCount != 0) {
514 uint32_t numDesc = (retCount < *count) ? retCount : *count;
515 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
516 }
517 *count = retCount;
518 return status;
519 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000520
521 virtual bool isOffloadSupported(const audio_offload_info_t& info)
522 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
525 data.write(&info, sizeof(audio_offload_info_t));
526 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700527 return reply.readInt32();
528 }
529
Michael Chana94fbb22018-04-24 14:31:19 +1000530 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
531 const audio_attributes_t& attributes) {
532 Parcel data, reply;
533 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
534 data.write(&config, sizeof(audio_config_base_t));
535 data.write(&attributes, sizeof(audio_attributes_t));
536 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
537 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
538 }
539
Eric Laurent203b1a12014-04-01 10:34:16 -0700540 virtual status_t listAudioPorts(audio_port_role_t role,
541 audio_port_type_t type,
542 unsigned int *num_ports,
543 struct audio_port *ports,
544 unsigned int *generation)
545 {
546 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
547 generation == NULL) {
548 return BAD_VALUE;
549 }
550 Parcel data, reply;
551 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
552 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
553 data.writeInt32(role);
554 data.writeInt32(type);
555 data.writeInt32(numPortsReq);
556 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
557 if (status == NO_ERROR) {
558 status = (status_t)reply.readInt32();
559 *num_ports = (unsigned int)reply.readInt32();
560 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700561 if (status == NO_ERROR) {
562 if (numPortsReq > *num_ports) {
563 numPortsReq = *num_ports;
564 }
565 if (numPortsReq > 0) {
566 reply.read(ports, numPortsReq * sizeof(struct audio_port));
567 }
568 *generation = reply.readInt32();
569 }
570 return status;
571 }
572
573 virtual status_t getAudioPort(struct audio_port *port)
574 {
575 if (port == NULL) {
576 return BAD_VALUE;
577 }
578 Parcel data, reply;
579 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
580 data.write(port, sizeof(struct audio_port));
581 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
582 if (status != NO_ERROR ||
583 (status = (status_t)reply.readInt32()) != NO_ERROR) {
584 return status;
585 }
586 reply.read(port, sizeof(struct audio_port));
587 return status;
588 }
589
590 virtual status_t createAudioPatch(const struct audio_patch *patch,
591 audio_patch_handle_t *handle)
592 {
593 if (patch == NULL || handle == NULL) {
594 return BAD_VALUE;
595 }
596 Parcel data, reply;
597 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
598 data.write(patch, sizeof(struct audio_patch));
599 data.write(handle, sizeof(audio_patch_handle_t));
600 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
601 if (status != NO_ERROR ||
602 (status = (status_t)reply.readInt32()) != NO_ERROR) {
603 return status;
604 }
605 reply.read(handle, sizeof(audio_patch_handle_t));
606 return status;
607 }
608
609 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
610 {
611 Parcel data, reply;
612 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
613 data.write(&handle, sizeof(audio_patch_handle_t));
614 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
615 if (status != NO_ERROR) {
616 status = (status_t)reply.readInt32();
617 }
618 return status;
619 }
620
621 virtual status_t listAudioPatches(unsigned int *num_patches,
622 struct audio_patch *patches,
623 unsigned int *generation)
624 {
625 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
626 generation == NULL) {
627 return BAD_VALUE;
628 }
629 Parcel data, reply;
630 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
631 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
632 data.writeInt32(numPatchesReq);
633 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
634 if (status == NO_ERROR) {
635 status = (status_t)reply.readInt32();
636 *num_patches = (unsigned int)reply.readInt32();
637 }
638 if (status == NO_ERROR) {
639 if (numPatchesReq > *num_patches) {
640 numPatchesReq = *num_patches;
641 }
642 if (numPatchesReq > 0) {
643 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
644 }
645 *generation = reply.readInt32();
646 }
647 return status;
648 }
649
650 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
651 {
652 if (config == NULL) {
653 return BAD_VALUE;
654 }
655 Parcel data, reply;
656 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
657 data.write(config, sizeof(struct audio_port_config));
658 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
659 if (status != NO_ERROR) {
660 status = (status_t)reply.readInt32();
661 }
662 return status;
663 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700664
Eric Laurentb52c1522014-05-20 11:27:36 -0700665 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
666 {
667 Parcel data, reply;
668 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800669 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700670 remote()->transact(REGISTER_CLIENT, data, &reply);
671 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700672
Eric Laurente8726fe2015-06-26 09:39:24 -0700673 virtual void setAudioPortCallbacksEnabled(bool enabled)
674 {
675 Parcel data, reply;
676 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
677 data.writeInt32(enabled ? 1 : 0);
678 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
679 }
680
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700681 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
682 audio_io_handle_t *ioHandle,
683 audio_devices_t *device)
684 {
685 if (session == NULL || ioHandle == NULL || device == NULL) {
686 return BAD_VALUE;
687 }
688 Parcel data, reply;
689 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
690 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
691 if (status != NO_ERROR) {
692 return status;
693 }
694 status = (status_t)reply.readInt32();
695 if (status == NO_ERROR) {
696 *session = (audio_session_t)reply.readInt32();
697 *ioHandle = (audio_io_handle_t)reply.readInt32();
698 *device = (audio_devices_t)reply.readInt32();
699 }
700 return status;
701 }
702
703 virtual status_t releaseSoundTriggerSession(audio_session_t session)
704 {
705 Parcel data, reply;
706 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
707 data.writeInt32(session);
708 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
709 if (status != NO_ERROR) {
710 return status;
711 }
712 return (status_t)reply.readInt32();
713 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700714
715 virtual audio_mode_t getPhoneState()
716 {
717 Parcel data, reply;
718 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
719 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
720 if (status != NO_ERROR) {
721 return AUDIO_MODE_INVALID;
722 }
723 return (audio_mode_t)reply.readInt32();
724 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800725
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700726 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800727 {
728 Parcel data, reply;
729 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
730 data.writeInt32(registration ? 1 : 0);
731 size_t size = mixes.size();
732 if (size > MAX_MIXES_PER_POLICY) {
733 size = MAX_MIXES_PER_POLICY;
734 }
735 size_t sizePosition = data.dataPosition();
736 data.writeInt32(size);
737 size_t finalSize = size;
738 for (size_t i = 0; i < size; i++) {
739 size_t position = data.dataPosition();
740 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
741 data.setDataPosition(position);
742 finalSize--;
743 }
744 }
745 if (size != finalSize) {
746 size_t position = data.dataPosition();
747 data.setDataPosition(sizePosition);
748 data.writeInt32(finalSize);
749 data.setDataPosition(position);
750 }
751 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
752 if (status == NO_ERROR) {
753 status = (status_t)reply.readInt32();
754 }
755 return status;
756 }
Eric Laurent554a2772015-04-10 11:29:24 -0700757
758 virtual status_t startAudioSource(const struct audio_port_config *source,
759 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700760 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700761 {
762 Parcel data, reply;
763 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700764 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700765 return BAD_VALUE;
766 }
767 data.write(source, sizeof(struct audio_port_config));
768 data.write(attributes, sizeof(audio_attributes_t));
769 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
770 if (status != NO_ERROR) {
771 return status;
772 }
773 status = (status_t)reply.readInt32();
774 if (status != NO_ERROR) {
775 return status;
776 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700777 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700778 return status;
779 }
780
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700781 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700782 {
783 Parcel data, reply;
784 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700785 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700786 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
787 if (status != NO_ERROR) {
788 return status;
789 }
790 status = (status_t)reply.readInt32();
791 return status;
792 }
Andy Hung2ddee192015-12-18 17:34:44 -0800793
794 virtual status_t setMasterMono(bool mono)
795 {
796 Parcel data, reply;
797 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
798 data.writeInt32(static_cast<int32_t>(mono));
799 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
800 if (status != NO_ERROR) {
801 return status;
802 }
803 return static_cast<status_t>(reply.readInt32());
804 }
805
806 virtual status_t getMasterMono(bool *mono)
807 {
808 if (mono == nullptr) {
809 return BAD_VALUE;
810 }
811 Parcel data, reply;
812 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
813
814 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
815 if (status != NO_ERROR) {
816 return status;
817 }
818 status = static_cast<status_t>(reply.readInt32());
819 if (status == NO_ERROR) {
820 *mono = static_cast<bool>(reply.readInt32());
821 }
822 return status;
823 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700824
825 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
826 {
827 Parcel data, reply;
828 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
829 data.writeInt32(static_cast <int32_t>(stream));
830 data.writeInt32(static_cast <int32_t>(index));
831 data.writeUint32(static_cast <uint32_t>(device));
832 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
833 if (status != NO_ERROR) {
834 return NAN;
835 }
836 return reply.readFloat();
837 }
jiabin81772902018-04-02 17:52:27 -0700838
839 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
840 audio_format_t *surroundFormats,
841 bool *surroundFormatsEnabled,
842 bool reported)
843 {
844 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
845 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
846 return BAD_VALUE;
847 }
848 Parcel data, reply;
849 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
850 unsigned int numSurroundFormatsReq = *numSurroundFormats;
851 data.writeUint32(numSurroundFormatsReq);
852 data.writeBool(reported);
853 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
854 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
855 *numSurroundFormats = reply.readUint32();
856 }
857 if (status == NO_ERROR) {
858 if (numSurroundFormatsReq > *numSurroundFormats) {
859 numSurroundFormatsReq = *numSurroundFormats;
860 }
861 if (numSurroundFormatsReq > 0) {
862 status = reply.read(surroundFormats,
863 numSurroundFormatsReq * sizeof(audio_format_t));
864 if (status != NO_ERROR) {
865 return status;
866 }
867 status = reply.read(surroundFormatsEnabled,
868 numSurroundFormatsReq * sizeof(bool));
869 }
870 }
871 return status;
872 }
873
874 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
875 {
876 Parcel data, reply;
877 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
878 data.writeInt32(audioFormat);
879 data.writeBool(enabled);
880 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
881 if (status != NO_ERROR) {
882 return status;
883 }
884 return reply.readInt32();
885 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700886
887 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
888 const String16& opPackageName,
889 const effect_uuid_t *uuid,
890 int32_t priority,
891 audio_usage_t usage,
892 audio_unique_id_t* id)
893 {
894 Parcel data, reply;
895 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
896 data.write(type, sizeof(effect_uuid_t));
897 data.writeString16(opPackageName);
898 data.write(uuid, sizeof(effect_uuid_t));
899 data.writeInt32(priority);
900 data.writeInt32((int32_t) usage);
901 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
902 if (status != NO_ERROR) {
903 return status;
904 }
905 status = static_cast <status_t> (reply.readInt32());
906 *id = reply.readInt32();
907 return status;
908 }
909
910 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
911 {
912 Parcel data, reply;
913 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
914 data.writeInt32(id);
915 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
916 if (status != NO_ERROR) {
917 return status;
918 }
919 return static_cast <status_t> (reply.readInt32());
920 }
921
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700922 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
923 const String16& opPackageName,
924 const effect_uuid_t *uuid,
925 int32_t priority,
926 audio_source_t source,
927 audio_unique_id_t* id)
928 {
929 Parcel data, reply;
930 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
931 data.write(type, sizeof(effect_uuid_t));
932 data.writeString16(opPackageName);
933 data.write(uuid, sizeof(effect_uuid_t));
934 data.writeInt32(priority);
935 data.writeInt32((int32_t) source);
936 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
937 if (status != NO_ERROR) {
938 return status;
939 }
940 status = static_cast <status_t> (reply.readInt32());
941 *id = reply.readInt32();
942 return status;
943 }
944
945 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
946 {
947 Parcel data, reply;
948 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
949 data.writeInt32(id);
950 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
951 if (status != NO_ERROR) {
952 return status;
953 }
954 return static_cast <status_t> (reply.readInt32());
955 }
956
Eric Laurentb78763e2018-10-17 10:08:02 -0700957 virtual status_t setAssistantUid(uid_t uid)
958 {
959 Parcel data, reply;
960 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
961 data.writeInt32(uid);
962 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
963 if (status != NO_ERROR) {
964 return status;
965 }
966 return static_cast <status_t> (reply.readInt32());
967 }
968
969 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
970 {
971 Parcel data, reply;
972 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
973 data.writeInt32(uids.size());
974 for (auto uid : uids) {
975 data.writeInt32(uid);
976 }
977 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
978 if (status != NO_ERROR) {
979 return status;
980 }
981 return static_cast <status_t> (reply.readInt32());
982 }
983
Eric Laurentc2f1f072009-07-17 12:17:14 -0700984};
985
986IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
987
988// ----------------------------------------------------------------------
989
Eric Laurentc2f1f072009-07-17 12:17:14 -0700990status_t BnAudioPolicyService::onTransact(
991 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
992{
Eric Laurentb1cc36b2017-12-11 12:14:16 -0800993 // make sure transactions reserved to AudioFlinger do not come from other processes
994 switch (code) {
995 case START_OUTPUT:
996 case STOP_OUTPUT:
997 case RELEASE_OUTPUT:
998 case GET_INPUT_FOR_ATTR:
999 case START_INPUT:
1000 case STOP_INPUT:
1001 case RELEASE_INPUT:
1002 case GET_STRATEGY_FOR_STREAM:
1003 case GET_OUTPUT_FOR_EFFECT:
1004 case REGISTER_EFFECT:
1005 case UNREGISTER_EFFECT:
1006 case SET_EFFECT_ENABLED:
1007 case GET_OUTPUT_FOR_ATTR:
1008 case ACQUIRE_SOUNDTRIGGER_SESSION:
1009 case RELEASE_SOUNDTRIGGER_SESSION:
1010 ALOGW("%s: transaction %d received from PID %d",
1011 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001012 // return status only for non void methods
1013 switch (code) {
1014 case RELEASE_OUTPUT:
1015 case RELEASE_INPUT:
1016 break;
1017 default:
1018 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1019 break;
1020 }
1021 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001022 default:
1023 break;
1024 }
1025
Eric Laurent4980df22018-01-26 18:04:09 -08001026 // make sure the following transactions come from system components
1027 switch (code) {
1028 case SET_DEVICE_CONNECTION_STATE:
1029 case HANDLE_DEVICE_CONFIG_CHANGE:
1030 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001031//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1032// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001033 case INIT_STREAM_VOLUME:
1034 case SET_STREAM_VOLUME:
1035 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001036 case SET_MASTER_MONO:
1037 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001038 case STOP_AUDIO_SOURCE:
1039 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001040 case SET_SURROUND_FORMAT_ENABLED:
1041 case SET_ASSISTANT_UID:
1042 case SET_A11Y_SERVICES_UIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001043 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001044 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1045 __func__, code, IPCThreadState::self()->getCallingPid(),
1046 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001047 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1048 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001049 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001050 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001051 default:
1052 break;
1053 }
1054
Eric Laurent39b09b52018-06-29 12:24:40 -07001055 std::string tag("IAudioPolicyService command " + std::to_string(code));
1056 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001057
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001058 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001059 case SET_DEVICE_CONNECTION_STATE: {
1060 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001061 audio_devices_t device =
1062 static_cast <audio_devices_t>(data.readInt32());
1063 audio_policy_dev_state_t state =
1064 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001066 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001067 if (device_address == nullptr || device_name == nullptr) {
1068 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1069 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1070 } else {
1071 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1072 state,
1073 device_address,
1074 device_name)));
1075 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001076 return NO_ERROR;
1077 } break;
1078
1079 case GET_DEVICE_CONNECTION_STATE: {
1080 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001081 audio_devices_t device =
1082 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001083 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001084 if (device_address == nullptr) {
1085 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1086 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1087 } else {
1088 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1089 device_address)));
1090 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001091 return NO_ERROR;
1092 } break;
1093
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001094 case HANDLE_DEVICE_CONFIG_CHANGE: {
1095 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1096 audio_devices_t device =
1097 static_cast <audio_devices_t>(data.readInt32());
1098 const char *device_address = data.readCString();
1099 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001100 if (device_address == nullptr || device_name == nullptr) {
1101 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1102 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1103 } else {
1104 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1105 device_address,
1106 device_name)));
1107 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001108 return NO_ERROR;
1109 } break;
1110
Eric Laurentc2f1f072009-07-17 12:17:14 -07001111 case SET_PHONE_STATE: {
1112 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001113 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1114 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001115 return NO_ERROR;
1116 } break;
1117
Eric Laurentc2f1f072009-07-17 12:17:14 -07001118 case SET_FORCE_USE: {
1119 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001120 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1121 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001122 audio_policy_forced_cfg_t config =
1123 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001124 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1125 return NO_ERROR;
1126 } break;
1127
1128 case GET_FORCE_USE: {
1129 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001130 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1131 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001132 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1133 return NO_ERROR;
1134 } break;
1135
1136 case GET_OUTPUT: {
1137 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001138 audio_stream_type_t stream =
1139 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001140 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001141 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001142 return NO_ERROR;
1143 } break;
1144
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001145 case GET_OUTPUT_FOR_ATTR: {
1146 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001147 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001148 bool hasAttributes = data.readInt32() != 0;
1149 if (hasAttributes) {
1150 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001151 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001152 }
1153 audio_session_t session = (audio_session_t)data.readInt32();
1154 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1155 bool hasStream = data.readInt32() != 0;
1156 if (hasStream) {
1157 stream = (audio_stream_type_t)data.readInt32();
1158 }
Nadav Bar766fb022018-01-07 12:18:03 +02001159 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001160 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001161 audio_config_t config;
1162 memset(&config, 0, sizeof(audio_config_t));
1163 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001164 audio_output_flags_t flags =
1165 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001166 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001167 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001168 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001169 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001170 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001171 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001172 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001173 reply->writeInt32(status);
1174 reply->writeInt32(output);
1175 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001176 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001177 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001178 return NO_ERROR;
1179 } break;
1180
Eric Laurentc2f1f072009-07-17 12:17:14 -07001181 case START_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 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001185 return NO_ERROR;
1186 } break;
1187
1188 case STOP_OUTPUT: {
1189 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001190 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1191 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001192 return NO_ERROR;
1193 } break;
1194
1195 case RELEASE_OUTPUT: {
1196 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001197 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1198 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001199 return NO_ERROR;
1200 } break;
1201
Eric Laurentcaf7f482014-11-25 17:50:47 -08001202 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001203 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001204 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001205 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001206 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001207 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001208 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001209 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001210 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001211 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001212 audio_config_base_t config;
1213 memset(&config, 0, sizeof(audio_config_base_t));
1214 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001215 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001216 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001217 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001218 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001219 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001220 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001221 reply->writeInt32(status);
1222 if (status == NO_ERROR) {
1223 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001224 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001225 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001226 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001227 return NO_ERROR;
1228 } break;
1229
1230 case START_INPUT: {
1231 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001232 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001233 bool silenced = data.readInt32() == 1;
Eric Laurentfee19762018-01-29 18:44:13 -08001234 status_t status = startInput(portId, &silenced);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001235 reply->writeInt32(static_cast <uint32_t>(status));
1236 reply->writeInt32(silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001237 return NO_ERROR;
1238 } break;
1239
1240 case STOP_INPUT: {
1241 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001242 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1243 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001244 return NO_ERROR;
1245 } break;
1246
1247 case RELEASE_INPUT: {
1248 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001249 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1250 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001251 return NO_ERROR;
1252 } break;
1253
1254 case INIT_STREAM_VOLUME: {
1255 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001256 audio_stream_type_t stream =
1257 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001258 int indexMin = data.readInt32();
1259 int indexMax = data.readInt32();
1260 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1261 return NO_ERROR;
1262 } break;
1263
1264 case SET_STREAM_VOLUME: {
1265 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001266 audio_stream_type_t stream =
1267 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001268 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001269 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1270 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1271 index,
1272 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001273 return NO_ERROR;
1274 } break;
1275
1276 case GET_STREAM_VOLUME: {
1277 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001278 audio_stream_type_t stream =
1279 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001280 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001281 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001282 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001283 reply->writeInt32(index);
1284 reply->writeInt32(static_cast <uint32_t>(status));
1285 return NO_ERROR;
1286 } break;
1287
Eric Laurentde070132010-07-13 04:45:46 -07001288 case GET_STRATEGY_FOR_STREAM: {
1289 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001290 audio_stream_type_t stream =
1291 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001292 reply->writeInt32(getStrategyForStream(stream));
1293 return NO_ERROR;
1294 } break;
1295
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001296 case GET_DEVICES_FOR_STREAM: {
1297 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001298 audio_stream_type_t stream =
1299 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001300 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1301 return NO_ERROR;
1302 } break;
1303
Eric Laurentde070132010-07-13 04:45:46 -07001304 case GET_OUTPUT_FOR_EFFECT: {
1305 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001306 effect_descriptor_t desc = {};
1307 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1308 android_errorWriteLog(0x534e4554, "73126106");
1309 }
1310 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001311 audio_io_handle_t output = getOutputForEffect(&desc);
1312 reply->writeInt32(static_cast <int>(output));
1313 return NO_ERROR;
1314 } break;
1315
1316 case REGISTER_EFFECT: {
1317 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001318 effect_descriptor_t desc = {};
1319 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1320 android_errorWriteLog(0x534e4554, "73126106");
1321 }
1322 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001323 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001324 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001325 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001326 int id = data.readInt32();
1327 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001328 io,
Eric Laurentde070132010-07-13 04:45:46 -07001329 strategy,
1330 session,
1331 id)));
1332 return NO_ERROR;
1333 } break;
1334
1335 case UNREGISTER_EFFECT: {
1336 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1337 int id = data.readInt32();
1338 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1339 return NO_ERROR;
1340 } break;
1341
Eric Laurentdb7c0792011-08-10 10:37:50 -07001342 case SET_EFFECT_ENABLED: {
1343 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1344 int id = data.readInt32();
1345 bool enabled = static_cast <bool>(data.readInt32());
1346 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1347 return NO_ERROR;
1348 } break;
1349
Eric Laurenteda6c362011-02-02 09:33:30 -08001350 case IS_STREAM_ACTIVE: {
1351 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001352 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001353 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001354 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001355 return NO_ERROR;
1356 } break;
1357
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001358 case IS_STREAM_ACTIVE_REMOTELY: {
1359 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1360 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1361 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001362 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001363 return NO_ERROR;
1364 } break;
1365
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001366 case IS_SOURCE_ACTIVE: {
1367 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1368 audio_source_t source = (audio_source_t) data.readInt32();
1369 reply->writeInt32( isSourceActive(source));
1370 return NO_ERROR;
1371 }
1372
Eric Laurent57dae992011-07-24 13:36:09 -07001373 case QUERY_DEFAULT_PRE_PROCESSING: {
1374 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001375 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001376 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001377 if (count > AudioEffect::kMaxPreProcessing) {
1378 count = AudioEffect::kMaxPreProcessing;
1379 }
Eric Laurent57dae992011-07-24 13:36:09 -07001380 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001381 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001382 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1383 reply->writeInt32(status);
1384 if (status != NO_ERROR && status != NO_MEMORY) {
1385 retCount = 0;
1386 }
1387 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001388 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001389 if (retCount < count) {
1390 count = retCount;
1391 }
1392 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1393 }
1394 delete[] descriptors;
1395 return status;
1396 }
1397
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001398 case IS_OFFLOAD_SUPPORTED: {
1399 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001400 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001401 data.read(&info, sizeof(audio_offload_info_t));
1402 bool isSupported = isOffloadSupported(info);
1403 reply->writeInt32(isSupported);
1404 return NO_ERROR;
1405 }
1406
Michael Chana94fbb22018-04-24 14:31:19 +10001407 case IS_DIRECT_OUTPUT_SUPPORTED: {
1408 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1409 audio_config_base_t config = {};
1410 audio_attributes_t attributes = {};
1411 status_t status = data.read(&config, sizeof(audio_config_base_t));
1412 if (status != NO_ERROR) return status;
1413 status = data.read(&attributes, sizeof(audio_attributes_t));
1414 if (status != NO_ERROR) return status;
1415 reply->writeInt32(isDirectOutputSupported(config, attributes));
1416 return NO_ERROR;
1417 }
1418
Eric Laurent203b1a12014-04-01 10:34:16 -07001419 case LIST_AUDIO_PORTS: {
1420 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1421 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1422 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1423 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001424 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1425 numPortsReq = MAX_ITEMS_PER_LIST;
1426 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001427 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001428 struct audio_port *ports =
1429 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001430 if (ports == NULL) {
1431 reply->writeInt32(NO_MEMORY);
1432 reply->writeInt32(0);
1433 return NO_ERROR;
1434 }
1435 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001436 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1437 reply->writeInt32(status);
1438 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001439
1440 if (status == NO_ERROR) {
1441 if (numPortsReq > numPorts) {
1442 numPortsReq = numPorts;
1443 }
1444 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1445 reply->writeInt32(generation);
1446 }
1447 free(ports);
1448 return NO_ERROR;
1449 }
1450
1451 case GET_AUDIO_PORT: {
1452 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001453 struct audio_port port = {};
1454 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1455 ALOGE("b/23912202");
1456 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001457 status_t status = getAudioPort(&port);
1458 reply->writeInt32(status);
1459 if (status == NO_ERROR) {
1460 reply->write(&port, sizeof(struct audio_port));
1461 }
1462 return NO_ERROR;
1463 }
1464
1465 case CREATE_AUDIO_PATCH: {
1466 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001467 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001468 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001469 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001470 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1471 ALOGE("b/23912202");
1472 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001473 status_t status = createAudioPatch(&patch, &handle);
1474 reply->writeInt32(status);
1475 if (status == NO_ERROR) {
1476 reply->write(&handle, sizeof(audio_patch_handle_t));
1477 }
1478 return NO_ERROR;
1479 }
1480
1481 case RELEASE_AUDIO_PATCH: {
1482 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001483 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001484 data.read(&handle, sizeof(audio_patch_handle_t));
1485 status_t status = releaseAudioPatch(handle);
1486 reply->writeInt32(status);
1487 return NO_ERROR;
1488 }
1489
1490 case LIST_AUDIO_PATCHES: {
1491 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1492 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001493 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1494 numPatchesReq = MAX_ITEMS_PER_LIST;
1495 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001496 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001497 struct audio_patch *patches =
1498 (struct audio_patch *)calloc(numPatchesReq,
1499 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001500 if (patches == NULL) {
1501 reply->writeInt32(NO_MEMORY);
1502 reply->writeInt32(0);
1503 return NO_ERROR;
1504 }
1505 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001506 status_t status = listAudioPatches(&numPatches, patches, &generation);
1507 reply->writeInt32(status);
1508 reply->writeInt32(numPatches);
1509 if (status == NO_ERROR) {
1510 if (numPatchesReq > numPatches) {
1511 numPatchesReq = numPatches;
1512 }
1513 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1514 reply->writeInt32(generation);
1515 }
1516 free(patches);
1517 return NO_ERROR;
1518 }
1519
1520 case SET_AUDIO_PORT_CONFIG: {
1521 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001522 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001523 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001524 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001525 status_t status = setAudioPortConfig(&config);
1526 reply->writeInt32(status);
1527 return NO_ERROR;
1528 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001529
Eric Laurentb52c1522014-05-20 11:27:36 -07001530 case REGISTER_CLIENT: {
1531 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1532 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1533 data.readStrongBinder());
1534 registerClient(client);
1535 return NO_ERROR;
1536 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001537
Eric Laurente8726fe2015-06-26 09:39:24 -07001538 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1539 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1540 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1541 return NO_ERROR;
1542 } break;
1543
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001544 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1545 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1546 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1547 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001548 audio_session_t session = AUDIO_SESSION_NONE;
1549 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1550 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001551 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1552 reply->writeInt32(status);
1553 if (status == NO_ERROR) {
1554 reply->writeInt32(session);
1555 reply->writeInt32(ioHandle);
1556 reply->writeInt32(device);
1557 }
1558 return NO_ERROR;
1559 } break;
1560
1561 case RELEASE_SOUNDTRIGGER_SESSION: {
1562 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1563 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1564 data.readStrongBinder());
1565 audio_session_t session = (audio_session_t)data.readInt32();
1566 status_t status = releaseSoundTriggerSession(session);
1567 reply->writeInt32(status);
1568 return NO_ERROR;
1569 } break;
1570
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001571 case GET_PHONE_STATE: {
1572 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1573 reply->writeInt32((int32_t)getPhoneState());
1574 return NO_ERROR;
1575 } break;
1576
Eric Laurentbaac1832014-12-01 17:52:59 -08001577 case REGISTER_POLICY_MIXES: {
1578 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1579 bool registration = data.readInt32() == 1;
1580 Vector<AudioMix> mixes;
1581 size_t size = (size_t)data.readInt32();
1582 if (size > MAX_MIXES_PER_POLICY) {
1583 size = MAX_MIXES_PER_POLICY;
1584 }
1585 for (size_t i = 0; i < size; i++) {
1586 AudioMix mix;
1587 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1588 mixes.add(mix);
1589 }
1590 }
1591 status_t status = registerPolicyMixes(mixes, registration);
1592 reply->writeInt32(status);
1593 return NO_ERROR;
1594 } break;
1595
Eric Laurent554a2772015-04-10 11:29:24 -07001596 case START_AUDIO_SOURCE: {
1597 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001598 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001599 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001600 (void)sanitizeAudioPortConfig(&source);
1601 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001602 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001603 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001604 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1605 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001606 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001607 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001608 return NO_ERROR;
1609 } break;
1610
1611 case STOP_AUDIO_SOURCE: {
1612 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001613 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1614 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001615 reply->writeInt32(status);
1616 return NO_ERROR;
1617 } break;
1618
Andy Hung2ddee192015-12-18 17:34:44 -08001619 case SET_MASTER_MONO: {
1620 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1621 bool mono = static_cast<bool>(data.readInt32());
1622 status_t status = setMasterMono(mono);
1623 reply->writeInt32(status);
1624 return NO_ERROR;
1625 } break;
1626
1627 case GET_MASTER_MONO: {
1628 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1629 bool mono;
1630 status_t status = getMasterMono(&mono);
1631 reply->writeInt32(status);
1632 if (status == NO_ERROR) {
1633 reply->writeInt32(static_cast<int32_t>(mono));
1634 }
1635 return NO_ERROR;
1636 } break;
1637
Eric Laurentac9cef52017-06-09 15:46:26 -07001638 case GET_STREAM_VOLUME_DB: {
1639 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1640 audio_stream_type_t stream =
1641 static_cast <audio_stream_type_t>(data.readInt32());
1642 int index = static_cast <int>(data.readInt32());
1643 audio_devices_t device =
1644 static_cast <audio_devices_t>(data.readUint32());
1645 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1646 return NO_ERROR;
1647 }
1648
jiabin81772902018-04-02 17:52:27 -07001649 case GET_SURROUND_FORMATS: {
1650 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1651 unsigned int numSurroundFormatsReq = data.readUint32();
1652 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1653 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1654 }
1655 bool reported = data.readBool();
1656 unsigned int numSurroundFormats = numSurroundFormatsReq;
1657 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1658 numSurroundFormats, sizeof(audio_format_t));
1659 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1660 if (numSurroundFormatsReq > 0 &&
1661 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1662 free(surroundFormats);
1663 free(surroundFormatsEnabled);
1664 reply->writeInt32(NO_MEMORY);
1665 return NO_ERROR;
1666 }
1667 status_t status = getSurroundFormats(
1668 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1669 reply->writeInt32(status);
1670
1671 if (status == NO_ERROR) {
1672 reply->writeUint32(numSurroundFormats);
1673 if (numSurroundFormatsReq > numSurroundFormats) {
1674 numSurroundFormatsReq = numSurroundFormats;
1675 }
1676 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1677 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1678 }
1679 free(surroundFormats);
1680 free(surroundFormatsEnabled);
1681 return NO_ERROR;
1682 }
1683
1684 case SET_SURROUND_FORMAT_ENABLED: {
1685 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1686 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1687 bool enabled = data.readBool();
1688 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1689 reply->writeInt32(status);
1690 return NO_ERROR;
1691 }
1692
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001693 case ADD_STREAM_DEFAULT_EFFECT: {
1694 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1695 effect_uuid_t type;
1696 status_t status = data.read(&type, sizeof(effect_uuid_t));
1697 if (status != NO_ERROR) {
1698 return status;
1699 }
1700 String16 opPackageName;
1701 status = data.readString16(&opPackageName);
1702 if (status != NO_ERROR) {
1703 return status;
1704 }
1705 effect_uuid_t uuid;
1706 status = data.read(&uuid, sizeof(effect_uuid_t));
1707 if (status != NO_ERROR) {
1708 return status;
1709 }
1710 int32_t priority = data.readInt32();
1711 audio_usage_t usage = (audio_usage_t) data.readInt32();
1712 audio_unique_id_t id = 0;
1713 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1714 opPackageName,
1715 &uuid,
1716 priority,
1717 usage,
1718 &id)));
1719 reply->writeInt32(id);
1720 return NO_ERROR;
1721 }
1722
1723 case REMOVE_STREAM_DEFAULT_EFFECT: {
1724 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1725 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1726 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1727 return NO_ERROR;
1728 }
1729
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001730 case ADD_SOURCE_DEFAULT_EFFECT: {
1731 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1732 effect_uuid_t type;
1733 status_t status = data.read(&type, sizeof(effect_uuid_t));
1734 if (status != NO_ERROR) {
1735 return status;
1736 }
1737 String16 opPackageName;
1738 status = data.readString16(&opPackageName);
1739 if (status != NO_ERROR) {
1740 return status;
1741 }
1742 effect_uuid_t uuid;
1743 status = data.read(&uuid, sizeof(effect_uuid_t));
1744 if (status != NO_ERROR) {
1745 return status;
1746 }
1747 int32_t priority = data.readInt32();
1748 audio_source_t source = (audio_source_t) data.readInt32();
1749 audio_unique_id_t id = 0;
1750 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1751 opPackageName,
1752 &uuid,
1753 priority,
1754 source,
1755 &id)));
1756 reply->writeInt32(id);
1757 return NO_ERROR;
1758 }
1759
1760 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1761 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1762 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1763 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1764 return NO_ERROR;
1765 }
1766
Eric Laurentb78763e2018-10-17 10:08:02 -07001767 case SET_ASSISTANT_UID: {
1768 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1769 int32_t uid;
1770 status_t status = data.readInt32(&uid);
1771 if (status != NO_ERROR) {
1772 return status;
1773 }
1774 status = setAssistantUid(uid);
1775 reply->writeInt32(static_cast <int32_t>(status));
1776 return NO_ERROR;
1777 }
1778
1779 case SET_A11Y_SERVICES_UIDS: {
1780 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1781 std::vector<uid_t> uids;
1782 int32_t size;
1783 status_t status = data.readInt32(&size);
1784 if (status != NO_ERROR) {
1785 return status;
1786 }
1787 if (size > MAX_ITEMS_PER_LIST) {
1788 size = MAX_ITEMS_PER_LIST;
1789 }
1790 for (int32_t i = 0; i < size; i++) {
1791 int32_t uid;
1792 status = data.readInt32(&uid);
1793 if (status != NO_ERROR) {
1794 return status;
1795 }
1796 uids.push_back(uid);
1797 }
1798 status = setA11yServicesUids(uids);
1799 reply->writeInt32(static_cast <int32_t>(status));
1800 return NO_ERROR;
1801 }
1802
Eric Laurentc2f1f072009-07-17 12:17:14 -07001803 default:
1804 return BBinder::onTransact(code, data, reply, flags);
1805 }
1806}
1807
Andy Hungb0272092018-04-12 11:06:56 -07001808/** returns true if string overflow was prevented by zero termination */
1809template <size_t size>
1810static bool preventStringOverflow(char (&s)[size]) {
1811 if (strnlen(s, size) < size) return false;
1812 s[size - 1] = '\0';
1813 return true;
1814}
1815
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001816void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1817{
1818 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1819 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1820 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1821 }
1822 attr->tags[tagsMaxSize - 1] = '\0';
1823}
1824
Andy Hungb0272092018-04-12 11:06:56 -07001825/** returns BAD_VALUE if sanitization was required. */
1826status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1827{
1828 if (preventStringOverflow(desc->name)
1829 | /* always */ preventStringOverflow(desc->implementor)) {
1830 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1831 return BAD_VALUE;
1832 }
1833 return NO_ERROR;
1834}
1835
1836/** returns BAD_VALUE if sanitization was required. */
1837status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1838{
1839 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1840 preventStringOverflow(config->ext.device.address)) {
1841 return BAD_VALUE;
1842 }
1843 return NO_ERROR;
1844}
1845
Eric Laurentc2f1f072009-07-17 12:17:14 -07001846// ----------------------------------------------------------------------------
1847
Glenn Kasten40bc9062015-03-20 09:09:33 -07001848} // namespace android