blob: 0ce8b16f475aa0ea009e5c6e562fb1802872effd [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
Eric Laurentac9cef52017-06-09 15:46:26 -070022#include <math.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <sys/types.h>
24
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070026#include <binder/Parcel.h>
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
Eric Laurent3528c932018-02-23 17:17:22 -080029#include <media/TimeCheck.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070030#include <mediautils/ServiceUtilities.h>
Dima Zavin64760242011-05-11 14:15:23 -070031#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070032
Eric Laurentc2f1f072009-07-17 12:17:14 -070033namespace android {
34
35enum {
36 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
37 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080038 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080040 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 SET_FORCE_USE,
42 GET_FORCE_USE,
43 GET_OUTPUT,
44 START_OUTPUT,
45 STOP_OUTPUT,
46 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080047 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070048 START_INPUT,
49 STOP_INPUT,
50 RELEASE_INPUT,
51 INIT_STREAM_VOLUME,
52 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070053 GET_STREAM_VOLUME,
54 GET_STRATEGY_FOR_STREAM,
55 GET_OUTPUT_FOR_EFFECT,
56 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080057 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070059 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080060 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070061 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080062 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000063 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070064 IS_OFFLOAD_SUPPORTED,
Michael Chana94fbb22018-04-24 14:31:19 +100065 IS_DIRECT_OUTPUT_SUPPORTED,
Eric Laurent203b1a12014-04-01 10:34:16 -070066 LIST_AUDIO_PORTS,
67 GET_AUDIO_PORT,
68 CREATE_AUDIO_PATCH,
69 RELEASE_AUDIO_PATCH,
70 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070071 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070072 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070073 GET_OUTPUT_FOR_ATTR,
74 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070075 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080076 GET_PHONE_STATE,
77 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070078 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070079 STOP_AUDIO_SOURCE,
80 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080081 SET_MASTER_MONO,
82 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070083 GET_STREAM_VOLUME_DB,
84 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070085 SET_SURROUND_FORMAT_ENABLED,
86 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070087 REMOVE_STREAM_DEFAULT_EFFECT,
88 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070089 REMOVE_SOURCE_DEFAULT_EFFECT,
90 SET_ASSISTANT_UID,
91 SET_A11Y_SERVICES_UIDS,
jiabin6012f912018-11-02 17:06:30 -070092 IS_HAPTIC_PLAYBACK_SUPPORTED,
Eric Laurentc2f1f072009-07-17 12:17:14 -070093};
94
Eric Laurent1d670b12015-02-06 10:44:24 -080095#define MAX_ITEMS_PER_LIST 1024
96
Eric Laurentc2f1f072009-07-17 12:17:14 -070097class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
98{
99public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700100 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700101 : BpInterface<IAudioPolicyService>(impl)
102 {
103 }
104
105 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700106 audio_devices_t device,
107 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800108 const char *device_address,
109 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 {
111 Parcel data, reply;
112 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
113 data.writeInt32(static_cast <uint32_t>(device));
114 data.writeInt32(static_cast <uint32_t>(state));
115 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800116 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
118 return static_cast <status_t> (reply.readInt32());
119 }
120
Dima Zavinfce7a472011-04-19 22:30:36 -0700121 virtual audio_policy_dev_state_t getDeviceConnectionState(
122 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700123 const char *device_address)
124 {
125 Parcel data, reply;
126 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
127 data.writeInt32(static_cast <uint32_t>(device));
128 data.writeCString(device_address);
129 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700130 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700131 }
132
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800133 virtual status_t handleDeviceConfigChange(audio_devices_t device,
134 const char *device_address,
135 const char *device_name)
136 {
137 Parcel data, reply;
138 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
139 data.writeInt32(static_cast <uint32_t>(device));
140 data.writeCString(device_address);
141 data.writeCString(device_name);
142 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
143 return static_cast <status_t> (reply.readInt32());
144 }
145
Glenn Kastenf78aee72012-01-04 11:00:47 -0800146 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700147 {
148 Parcel data, reply;
149 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
150 data.writeInt32(state);
151 remote()->transact(SET_PHONE_STATE, data, &reply);
152 return static_cast <status_t> (reply.readInt32());
153 }
154
Dima Zavinfce7a472011-04-19 22:30:36 -0700155 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700156 {
157 Parcel data, reply;
158 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
159 data.writeInt32(static_cast <uint32_t>(usage));
160 data.writeInt32(static_cast <uint32_t>(config));
161 remote()->transact(SET_FORCE_USE, data, &reply);
162 return static_cast <status_t> (reply.readInt32());
163 }
164
Dima Zavinfce7a472011-04-19 22:30:36 -0700165 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700166 {
167 Parcel data, reply;
168 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
169 data.writeInt32(static_cast <uint32_t>(usage));
170 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700171 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700172 }
173
Eric Laurentf4e63452017-11-06 19:31:46 +0000174 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700175 {
176 Parcel data, reply;
177 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
178 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700179 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700180 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700181 }
182
Eric Laurente83b55d2014-11-14 10:06:21 -0800183 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
184 audio_io_handle_t *output,
185 audio_session_t session,
186 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200187 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700188 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800189 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800190 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700191 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800192 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700193 {
194 Parcel data, reply;
195 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
196 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800197 if (stream == NULL) {
198 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
199 return BAD_VALUE;
200 }
201 if (*stream == AUDIO_STREAM_DEFAULT) {
202 ALOGE("getOutputForAttr unspecified stream type");
203 return BAD_VALUE;
204 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700205 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800206 if (output == NULL) {
207 ALOGE("getOutputForAttr NULL output - shouldn't happen");
208 return BAD_VALUE;
209 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700210 if (selectedDeviceId == NULL) {
211 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
212 return BAD_VALUE;
213 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800214 if (portId == NULL) {
215 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
216 return BAD_VALUE;
217 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800218 if (attr == NULL) {
219 data.writeInt32(0);
220 } else {
221 data.writeInt32(1);
222 data.write(attr, sizeof(audio_attributes_t));
223 }
224 data.writeInt32(session);
225 if (stream == NULL) {
226 data.writeInt32(0);
227 } else {
228 data.writeInt32(1);
229 data.writeInt32(*stream);
230 }
Nadav Bar766fb022018-01-07 12:18:03 +0200231 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700232 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800233 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700234 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700235 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800236 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800237 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
238 if (status != NO_ERROR) {
239 return status;
240 }
241 status = (status_t)reply.readInt32();
242 if (status != NO_ERROR) {
243 return status;
244 }
245 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800246 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800247 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800248 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800249 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700250 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800251 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800252 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700253 }
254
Eric Laurentd7fe0862018-07-14 16:48:01 -0700255 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700256 {
257 Parcel data, reply;
258 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700259 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700260 remote()->transact(START_OUTPUT, data, &reply);
261 return static_cast <status_t> (reply.readInt32());
262 }
263
Eric Laurentd7fe0862018-07-14 16:48:01 -0700264 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700265 {
266 Parcel data, reply;
267 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700268 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700269 remote()->transact(STOP_OUTPUT, data, &reply);
270 return static_cast <status_t> (reply.readInt32());
271 }
272
Eric Laurentd7fe0862018-07-14 16:48:01 -0700273 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700277 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700278 remote()->transact(RELEASE_OUTPUT, data, &reply);
279 }
280
Eric Laurentcaf7f482014-11-25 17:50:47 -0800281 virtual status_t getInputForAttr(const audio_attributes_t *attr,
282 audio_io_handle_t *input,
283 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700284 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700285 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800286 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800287 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600288 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700289 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800290 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700291 {
292 Parcel data, reply;
293 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800294 if (attr == NULL) {
295 ALOGE("getInputForAttr NULL attr - shouldn't happen");
296 return BAD_VALUE;
297 }
298 if (input == NULL) {
299 ALOGE("getInputForAttr NULL input - shouldn't happen");
300 return BAD_VALUE;
301 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700302 if (selectedDeviceId == NULL) {
303 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
304 return BAD_VALUE;
305 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800306 if (portId == NULL) {
307 ALOGE("getInputForAttr NULL portId - shouldn't happen");
308 return BAD_VALUE;
309 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800310 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700311 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800312 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700313 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700314 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800315 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800316 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700317 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700318 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800319 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800320 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
321 if (status != NO_ERROR) {
322 return status;
323 }
324 status = reply.readInt32();
325 if (status != NO_ERROR) {
326 return status;
327 }
328 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700329 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800330 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800331 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700332 }
333
Eric Laurent4eb58f12018-12-07 16:41:02 -0800334 virtual status_t startInput(audio_port_handle_t portId)
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);
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());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800341 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 }
343
Eric Laurentfee19762018-01-29 18:44:13 -0800344 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700345 {
346 Parcel data, reply;
347 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800348 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 remote()->transact(STOP_INPUT, data, &reply);
350 return static_cast <status_t> (reply.readInt32());
351 }
352
Eric Laurentfee19762018-01-29 18:44:13 -0800353 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800357 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700358 remote()->transact(RELEASE_INPUT, data, &reply);
359 }
360
Dima Zavinfce7a472011-04-19 22:30:36 -0700361 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700362 int indexMin,
363 int indexMax)
364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
367 data.writeInt32(static_cast <uint32_t>(stream));
368 data.writeInt32(indexMin);
369 data.writeInt32(indexMax);
370 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
371 return static_cast <status_t> (reply.readInt32());
372 }
373
Eric Laurent83844cc2011-11-18 16:43:31 -0800374 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
375 int index,
376 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700377 {
378 Parcel data, reply;
379 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
380 data.writeInt32(static_cast <uint32_t>(stream));
381 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800382 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 remote()->transact(SET_STREAM_VOLUME, data, &reply);
384 return static_cast <status_t> (reply.readInt32());
385 }
386
Eric Laurent83844cc2011-11-18 16:43:31 -0800387 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
388 int *index,
389 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700390 {
391 Parcel data, reply;
392 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
393 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800394 data.writeInt32(static_cast <uint32_t>(device));
395
Eric Laurentc2f1f072009-07-17 12:17:14 -0700396 remote()->transact(GET_STREAM_VOLUME, data, &reply);
397 int lIndex = reply.readInt32();
398 if (index) *index = lIndex;
399 return static_cast <status_t> (reply.readInt32());
400 }
Eric Laurentde070132010-07-13 04:45:46 -0700401
Dima Zavinfce7a472011-04-19 22:30:36 -0700402 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
406 data.writeInt32(static_cast <uint32_t>(stream));
407 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
408 return reply.readInt32();
409 }
410
Eric Laurent63742522012-03-08 13:42:42 -0800411 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800412 {
413 Parcel data, reply;
414 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
415 data.writeInt32(static_cast <uint32_t>(stream));
416 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800417 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800418 }
419
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700420 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700421 {
422 Parcel data, reply;
423 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
424 data.write(desc, sizeof(effect_descriptor_t));
425 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
426 return static_cast <audio_io_handle_t> (reply.readInt32());
427 }
428
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700429 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700430 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700431 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800432 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700433 int id)
434 {
435 Parcel data, reply;
436 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
437 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700438 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700439 data.writeInt32(strategy);
440 data.writeInt32(session);
441 data.writeInt32(id);
442 remote()->transact(REGISTER_EFFECT, data, &reply);
443 return static_cast <status_t> (reply.readInt32());
444 }
445
446 virtual status_t unregisterEffect(int id)
447 {
448 Parcel data, reply;
449 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
450 data.writeInt32(id);
451 remote()->transact(UNREGISTER_EFFECT, data, &reply);
452 return static_cast <status_t> (reply.readInt32());
453 }
454
Eric Laurentdb7c0792011-08-10 10:37:50 -0700455 virtual status_t setEffectEnabled(int id, bool enabled)
456 {
457 Parcel data, reply;
458 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
459 data.writeInt32(id);
460 data.writeInt32(enabled);
461 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
462 return static_cast <status_t> (reply.readInt32());
463 }
464
Glenn Kastenfff6d712012-01-12 16:38:12 -0800465 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800466 {
467 Parcel data, reply;
468 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800469 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800470 data.writeInt32(inPastMs);
471 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
472 return reply.readInt32();
473 }
Eric Laurent57dae992011-07-24 13:36:09 -0700474
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800475 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
476 {
477 Parcel data, reply;
478 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
479 data.writeInt32((int32_t) stream);
480 data.writeInt32(inPastMs);
481 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
482 return reply.readInt32();
483 }
484
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700485 virtual bool isSourceActive(audio_source_t source) const
486 {
487 Parcel data, reply;
488 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
489 data.writeInt32((int32_t) source);
490 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
491 return reply.readInt32();
492 }
493
Glenn Kastend848eb42016-03-08 13:42:11 -0800494 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700495 effect_descriptor_t *descriptors,
496 uint32_t *count)
497 {
498 if (descriptors == NULL || count == NULL) {
499 return BAD_VALUE;
500 }
501 Parcel data, reply;
502 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
503 data.writeInt32(audioSession);
504 data.writeInt32(*count);
505 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
506 if (status != NO_ERROR) {
507 return status;
508 }
509 status = static_cast <status_t> (reply.readInt32());
510 uint32_t retCount = reply.readInt32();
511 if (retCount != 0) {
512 uint32_t numDesc = (retCount < *count) ? retCount : *count;
513 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
514 }
515 *count = retCount;
516 return status;
517 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000518
519 virtual bool isOffloadSupported(const audio_offload_info_t& info)
520 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100521 Parcel data, reply;
522 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
523 data.write(&info, sizeof(audio_offload_info_t));
524 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700525 return reply.readInt32();
526 }
527
Michael Chana94fbb22018-04-24 14:31:19 +1000528 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
529 const audio_attributes_t& attributes) {
530 Parcel data, reply;
531 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
532 data.write(&config, sizeof(audio_config_base_t));
533 data.write(&attributes, sizeof(audio_attributes_t));
534 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
535 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
536 }
537
Eric Laurent203b1a12014-04-01 10:34:16 -0700538 virtual status_t listAudioPorts(audio_port_role_t role,
539 audio_port_type_t type,
540 unsigned int *num_ports,
541 struct audio_port *ports,
542 unsigned int *generation)
543 {
544 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
545 generation == NULL) {
546 return BAD_VALUE;
547 }
548 Parcel data, reply;
549 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
550 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
551 data.writeInt32(role);
552 data.writeInt32(type);
553 data.writeInt32(numPortsReq);
554 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
555 if (status == NO_ERROR) {
556 status = (status_t)reply.readInt32();
557 *num_ports = (unsigned int)reply.readInt32();
558 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700559 if (status == NO_ERROR) {
560 if (numPortsReq > *num_ports) {
561 numPortsReq = *num_ports;
562 }
563 if (numPortsReq > 0) {
564 reply.read(ports, numPortsReq * sizeof(struct audio_port));
565 }
566 *generation = reply.readInt32();
567 }
568 return status;
569 }
570
571 virtual status_t getAudioPort(struct audio_port *port)
572 {
573 if (port == NULL) {
574 return BAD_VALUE;
575 }
576 Parcel data, reply;
577 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
578 data.write(port, sizeof(struct audio_port));
579 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
580 if (status != NO_ERROR ||
581 (status = (status_t)reply.readInt32()) != NO_ERROR) {
582 return status;
583 }
584 reply.read(port, sizeof(struct audio_port));
585 return status;
586 }
587
588 virtual status_t createAudioPatch(const struct audio_patch *patch,
589 audio_patch_handle_t *handle)
590 {
591 if (patch == NULL || handle == NULL) {
592 return BAD_VALUE;
593 }
594 Parcel data, reply;
595 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
596 data.write(patch, sizeof(struct audio_patch));
597 data.write(handle, sizeof(audio_patch_handle_t));
598 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
599 if (status != NO_ERROR ||
600 (status = (status_t)reply.readInt32()) != NO_ERROR) {
601 return status;
602 }
603 reply.read(handle, sizeof(audio_patch_handle_t));
604 return status;
605 }
606
607 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
608 {
609 Parcel data, reply;
610 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
611 data.write(&handle, sizeof(audio_patch_handle_t));
612 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
613 if (status != NO_ERROR) {
614 status = (status_t)reply.readInt32();
615 }
616 return status;
617 }
618
619 virtual status_t listAudioPatches(unsigned int *num_patches,
620 struct audio_patch *patches,
621 unsigned int *generation)
622 {
623 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
624 generation == NULL) {
625 return BAD_VALUE;
626 }
627 Parcel data, reply;
628 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
629 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
630 data.writeInt32(numPatchesReq);
631 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
632 if (status == NO_ERROR) {
633 status = (status_t)reply.readInt32();
634 *num_patches = (unsigned int)reply.readInt32();
635 }
636 if (status == NO_ERROR) {
637 if (numPatchesReq > *num_patches) {
638 numPatchesReq = *num_patches;
639 }
640 if (numPatchesReq > 0) {
641 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
642 }
643 *generation = reply.readInt32();
644 }
645 return status;
646 }
647
648 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
649 {
650 if (config == NULL) {
651 return BAD_VALUE;
652 }
653 Parcel data, reply;
654 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
655 data.write(config, sizeof(struct audio_port_config));
656 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
657 if (status != NO_ERROR) {
658 status = (status_t)reply.readInt32();
659 }
660 return status;
661 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700662
Eric Laurentb52c1522014-05-20 11:27:36 -0700663 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
664 {
665 Parcel data, reply;
666 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800667 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700668 remote()->transact(REGISTER_CLIENT, data, &reply);
669 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700670
Eric Laurente8726fe2015-06-26 09:39:24 -0700671 virtual void setAudioPortCallbacksEnabled(bool enabled)
672 {
673 Parcel data, reply;
674 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
675 data.writeInt32(enabled ? 1 : 0);
676 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
677 }
678
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700679 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
680 audio_io_handle_t *ioHandle,
681 audio_devices_t *device)
682 {
683 if (session == NULL || ioHandle == NULL || device == NULL) {
684 return BAD_VALUE;
685 }
686 Parcel data, reply;
687 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
688 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
689 if (status != NO_ERROR) {
690 return status;
691 }
692 status = (status_t)reply.readInt32();
693 if (status == NO_ERROR) {
694 *session = (audio_session_t)reply.readInt32();
695 *ioHandle = (audio_io_handle_t)reply.readInt32();
696 *device = (audio_devices_t)reply.readInt32();
697 }
698 return status;
699 }
700
701 virtual status_t releaseSoundTriggerSession(audio_session_t session)
702 {
703 Parcel data, reply;
704 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
705 data.writeInt32(session);
706 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
707 if (status != NO_ERROR) {
708 return status;
709 }
710 return (status_t)reply.readInt32();
711 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700712
713 virtual audio_mode_t getPhoneState()
714 {
715 Parcel data, reply;
716 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
717 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
718 if (status != NO_ERROR) {
719 return AUDIO_MODE_INVALID;
720 }
721 return (audio_mode_t)reply.readInt32();
722 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800723
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700724 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800725 {
726 Parcel data, reply;
727 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
728 data.writeInt32(registration ? 1 : 0);
729 size_t size = mixes.size();
730 if (size > MAX_MIXES_PER_POLICY) {
731 size = MAX_MIXES_PER_POLICY;
732 }
733 size_t sizePosition = data.dataPosition();
734 data.writeInt32(size);
735 size_t finalSize = size;
736 for (size_t i = 0; i < size; i++) {
737 size_t position = data.dataPosition();
738 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
739 data.setDataPosition(position);
740 finalSize--;
741 }
742 }
743 if (size != finalSize) {
744 size_t position = data.dataPosition();
745 data.setDataPosition(sizePosition);
746 data.writeInt32(finalSize);
747 data.setDataPosition(position);
748 }
749 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
750 if (status == NO_ERROR) {
751 status = (status_t)reply.readInt32();
752 }
753 return status;
754 }
Eric Laurent554a2772015-04-10 11:29:24 -0700755
756 virtual status_t startAudioSource(const struct audio_port_config *source,
757 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700758 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700759 {
760 Parcel data, reply;
761 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700762 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700763 return BAD_VALUE;
764 }
765 data.write(source, sizeof(struct audio_port_config));
766 data.write(attributes, sizeof(audio_attributes_t));
767 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
768 if (status != NO_ERROR) {
769 return status;
770 }
771 status = (status_t)reply.readInt32();
772 if (status != NO_ERROR) {
773 return status;
774 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700775 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700776 return status;
777 }
778
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700779 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700780 {
781 Parcel data, reply;
782 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700783 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700784 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
785 if (status != NO_ERROR) {
786 return status;
787 }
788 status = (status_t)reply.readInt32();
789 return status;
790 }
Andy Hung2ddee192015-12-18 17:34:44 -0800791
792 virtual status_t setMasterMono(bool mono)
793 {
794 Parcel data, reply;
795 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
796 data.writeInt32(static_cast<int32_t>(mono));
797 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
798 if (status != NO_ERROR) {
799 return status;
800 }
801 return static_cast<status_t>(reply.readInt32());
802 }
803
804 virtual status_t getMasterMono(bool *mono)
805 {
806 if (mono == nullptr) {
807 return BAD_VALUE;
808 }
809 Parcel data, reply;
810 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
811
812 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
813 if (status != NO_ERROR) {
814 return status;
815 }
816 status = static_cast<status_t>(reply.readInt32());
817 if (status == NO_ERROR) {
818 *mono = static_cast<bool>(reply.readInt32());
819 }
820 return status;
821 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700822
823 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
824 {
825 Parcel data, reply;
826 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
827 data.writeInt32(static_cast <int32_t>(stream));
828 data.writeInt32(static_cast <int32_t>(index));
829 data.writeUint32(static_cast <uint32_t>(device));
830 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
831 if (status != NO_ERROR) {
832 return NAN;
833 }
834 return reply.readFloat();
835 }
jiabin81772902018-04-02 17:52:27 -0700836
837 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
838 audio_format_t *surroundFormats,
839 bool *surroundFormatsEnabled,
840 bool reported)
841 {
842 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
843 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
844 return BAD_VALUE;
845 }
846 Parcel data, reply;
847 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
848 unsigned int numSurroundFormatsReq = *numSurroundFormats;
849 data.writeUint32(numSurroundFormatsReq);
850 data.writeBool(reported);
851 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
852 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
853 *numSurroundFormats = reply.readUint32();
854 }
855 if (status == NO_ERROR) {
856 if (numSurroundFormatsReq > *numSurroundFormats) {
857 numSurroundFormatsReq = *numSurroundFormats;
858 }
859 if (numSurroundFormatsReq > 0) {
860 status = reply.read(surroundFormats,
861 numSurroundFormatsReq * sizeof(audio_format_t));
862 if (status != NO_ERROR) {
863 return status;
864 }
865 status = reply.read(surroundFormatsEnabled,
866 numSurroundFormatsReq * sizeof(bool));
867 }
868 }
869 return status;
870 }
871
872 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
873 {
874 Parcel data, reply;
875 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
876 data.writeInt32(audioFormat);
877 data.writeBool(enabled);
878 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
879 if (status != NO_ERROR) {
880 return status;
881 }
882 return reply.readInt32();
883 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700884
885 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
886 const String16& opPackageName,
887 const effect_uuid_t *uuid,
888 int32_t priority,
889 audio_usage_t usage,
890 audio_unique_id_t* id)
891 {
892 Parcel data, reply;
893 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
894 data.write(type, sizeof(effect_uuid_t));
895 data.writeString16(opPackageName);
896 data.write(uuid, sizeof(effect_uuid_t));
897 data.writeInt32(priority);
898 data.writeInt32((int32_t) usage);
899 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
900 if (status != NO_ERROR) {
901 return status;
902 }
903 status = static_cast <status_t> (reply.readInt32());
904 *id = reply.readInt32();
905 return status;
906 }
907
908 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
909 {
910 Parcel data, reply;
911 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
912 data.writeInt32(id);
913 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
914 if (status != NO_ERROR) {
915 return status;
916 }
917 return static_cast <status_t> (reply.readInt32());
918 }
919
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700920 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
921 const String16& opPackageName,
922 const effect_uuid_t *uuid,
923 int32_t priority,
924 audio_source_t source,
925 audio_unique_id_t* id)
926 {
927 Parcel data, reply;
928 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
929 data.write(type, sizeof(effect_uuid_t));
930 data.writeString16(opPackageName);
931 data.write(uuid, sizeof(effect_uuid_t));
932 data.writeInt32(priority);
933 data.writeInt32((int32_t) source);
934 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
935 if (status != NO_ERROR) {
936 return status;
937 }
938 status = static_cast <status_t> (reply.readInt32());
939 *id = reply.readInt32();
940 return status;
941 }
942
943 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
944 {
945 Parcel data, reply;
946 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
947 data.writeInt32(id);
948 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
949 if (status != NO_ERROR) {
950 return status;
951 }
952 return static_cast <status_t> (reply.readInt32());
953 }
954
Eric Laurentb78763e2018-10-17 10:08:02 -0700955 virtual status_t setAssistantUid(uid_t uid)
956 {
957 Parcel data, reply;
958 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
959 data.writeInt32(uid);
960 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
961 if (status != NO_ERROR) {
962 return status;
963 }
964 return static_cast <status_t> (reply.readInt32());
965 }
966
967 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
968 {
969 Parcel data, reply;
970 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
971 data.writeInt32(uids.size());
972 for (auto uid : uids) {
973 data.writeInt32(uid);
974 }
975 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
976 if (status != NO_ERROR) {
977 return status;
978 }
979 return static_cast <status_t> (reply.readInt32());
980 }
981
jiabin6012f912018-11-02 17:06:30 -0700982 virtual bool isHapticPlaybackSupported()
983 {
984 Parcel data, reply;
985 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
986 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
987 if (status != NO_ERROR) {
988 return false;
989 }
990 return reply.readBool();
991 }
992
Eric Laurentc2f1f072009-07-17 12:17:14 -0700993};
994
995IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
996
997// ----------------------------------------------------------------------
998
Eric Laurentc2f1f072009-07-17 12:17:14 -0700999status_t BnAudioPolicyService::onTransact(
1000 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1001{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001002 // make sure transactions reserved to AudioFlinger do not come from other processes
1003 switch (code) {
1004 case START_OUTPUT:
1005 case STOP_OUTPUT:
1006 case RELEASE_OUTPUT:
1007 case GET_INPUT_FOR_ATTR:
1008 case START_INPUT:
1009 case STOP_INPUT:
1010 case RELEASE_INPUT:
1011 case GET_STRATEGY_FOR_STREAM:
1012 case GET_OUTPUT_FOR_EFFECT:
1013 case REGISTER_EFFECT:
1014 case UNREGISTER_EFFECT:
1015 case SET_EFFECT_ENABLED:
1016 case GET_OUTPUT_FOR_ATTR:
1017 case ACQUIRE_SOUNDTRIGGER_SESSION:
1018 case RELEASE_SOUNDTRIGGER_SESSION:
1019 ALOGW("%s: transaction %d received from PID %d",
1020 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001021 // return status only for non void methods
1022 switch (code) {
1023 case RELEASE_OUTPUT:
1024 case RELEASE_INPUT:
1025 break;
1026 default:
1027 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1028 break;
1029 }
1030 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001031 default:
1032 break;
1033 }
1034
Eric Laurent4980df22018-01-26 18:04:09 -08001035 // make sure the following transactions come from system components
1036 switch (code) {
1037 case SET_DEVICE_CONNECTION_STATE:
1038 case HANDLE_DEVICE_CONFIG_CHANGE:
1039 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001040//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1041// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001042 case INIT_STREAM_VOLUME:
1043 case SET_STREAM_VOLUME:
1044 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001045 case SET_MASTER_MONO:
1046 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001047 case STOP_AUDIO_SOURCE:
1048 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001049 case SET_SURROUND_FORMAT_ENABLED:
1050 case SET_ASSISTANT_UID:
1051 case SET_A11Y_SERVICES_UIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001052 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001053 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1054 __func__, code, IPCThreadState::self()->getCallingPid(),
1055 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001056 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1057 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001058 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001059 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001060 default:
1061 break;
1062 }
1063
Eric Laurent39b09b52018-06-29 12:24:40 -07001064 std::string tag("IAudioPolicyService command " + std::to_string(code));
1065 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001066
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001067 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001068 case SET_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());
1072 audio_policy_dev_state_t state =
1073 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001075 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001076 if (device_address == nullptr || device_name == nullptr) {
1077 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1078 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1079 } else {
1080 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1081 state,
1082 device_address,
1083 device_name)));
1084 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001085 return NO_ERROR;
1086 } break;
1087
1088 case GET_DEVICE_CONNECTION_STATE: {
1089 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001090 audio_devices_t device =
1091 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001092 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001093 if (device_address == nullptr) {
1094 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1095 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1096 } else {
1097 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1098 device_address)));
1099 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001100 return NO_ERROR;
1101 } break;
1102
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001103 case HANDLE_DEVICE_CONFIG_CHANGE: {
1104 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1105 audio_devices_t device =
1106 static_cast <audio_devices_t>(data.readInt32());
1107 const char *device_address = data.readCString();
1108 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001109 if (device_address == nullptr || device_name == nullptr) {
1110 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1111 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1112 } else {
1113 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1114 device_address,
1115 device_name)));
1116 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001117 return NO_ERROR;
1118 } break;
1119
Eric Laurentc2f1f072009-07-17 12:17:14 -07001120 case SET_PHONE_STATE: {
1121 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001122 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1123 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001124 return NO_ERROR;
1125 } break;
1126
Eric Laurentc2f1f072009-07-17 12:17:14 -07001127 case SET_FORCE_USE: {
1128 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001129 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1130 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001131 audio_policy_forced_cfg_t config =
1132 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1134 return NO_ERROR;
1135 } break;
1136
1137 case GET_FORCE_USE: {
1138 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001139 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1140 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001141 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1142 return NO_ERROR;
1143 } break;
1144
1145 case GET_OUTPUT: {
1146 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001147 audio_stream_type_t stream =
1148 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001149 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001150 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001151 return NO_ERROR;
1152 } break;
1153
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001154 case GET_OUTPUT_FOR_ATTR: {
1155 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001156 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001157 bool hasAttributes = data.readInt32() != 0;
1158 if (hasAttributes) {
1159 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001160 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001161 }
1162 audio_session_t session = (audio_session_t)data.readInt32();
1163 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1164 bool hasStream = data.readInt32() != 0;
1165 if (hasStream) {
1166 stream = (audio_stream_type_t)data.readInt32();
1167 }
Nadav Bar766fb022018-01-07 12:18:03 +02001168 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001169 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001170 audio_config_t config;
1171 memset(&config, 0, sizeof(audio_config_t));
1172 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001173 audio_output_flags_t flags =
1174 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001175 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001176 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001177 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001178 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001179 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001180 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001181 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001182 reply->writeInt32(status);
1183 reply->writeInt32(output);
1184 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001185 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001186 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001187 return NO_ERROR;
1188 } break;
1189
Eric Laurentc2f1f072009-07-17 12:17:14 -07001190 case START_OUTPUT: {
1191 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001192 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1193 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001194 return NO_ERROR;
1195 } break;
1196
1197 case STOP_OUTPUT: {
1198 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001199 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1200 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001201 return NO_ERROR;
1202 } break;
1203
1204 case RELEASE_OUTPUT: {
1205 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001206 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1207 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001208 return NO_ERROR;
1209 } break;
1210
Eric Laurentcaf7f482014-11-25 17:50:47 -08001211 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001212 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001213 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001214 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001215 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001216 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001217 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001218 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001219 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001220 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001221 audio_config_base_t config;
1222 memset(&config, 0, sizeof(audio_config_base_t));
1223 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001224 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001225 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001226 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001227 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001228 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001229 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001230 reply->writeInt32(status);
1231 if (status == NO_ERROR) {
1232 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001233 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001234 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001235 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001236 return NO_ERROR;
1237 } break;
1238
1239 case START_INPUT: {
1240 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001241 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001242 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001243 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001244 return NO_ERROR;
1245 } break;
1246
1247 case STOP_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 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001251 return NO_ERROR;
1252 } break;
1253
1254 case RELEASE_INPUT: {
1255 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001256 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1257 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001258 return NO_ERROR;
1259 } break;
1260
1261 case INIT_STREAM_VOLUME: {
1262 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001263 audio_stream_type_t stream =
1264 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001265 int indexMin = data.readInt32();
1266 int indexMax = data.readInt32();
1267 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1268 return NO_ERROR;
1269 } break;
1270
1271 case SET_STREAM_VOLUME: {
1272 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001273 audio_stream_type_t stream =
1274 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001275 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001276 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1277 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1278 index,
1279 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001280 return NO_ERROR;
1281 } break;
1282
1283 case GET_STREAM_VOLUME: {
1284 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001285 audio_stream_type_t stream =
1286 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001287 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001288 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001289 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001290 reply->writeInt32(index);
1291 reply->writeInt32(static_cast <uint32_t>(status));
1292 return NO_ERROR;
1293 } break;
1294
Eric Laurentde070132010-07-13 04:45:46 -07001295 case GET_STRATEGY_FOR_STREAM: {
1296 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001297 audio_stream_type_t stream =
1298 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001299 reply->writeInt32(getStrategyForStream(stream));
1300 return NO_ERROR;
1301 } break;
1302
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001303 case GET_DEVICES_FOR_STREAM: {
1304 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001305 audio_stream_type_t stream =
1306 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001307 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1308 return NO_ERROR;
1309 } break;
1310
Eric Laurentde070132010-07-13 04:45:46 -07001311 case GET_OUTPUT_FOR_EFFECT: {
1312 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001313 effect_descriptor_t desc = {};
1314 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1315 android_errorWriteLog(0x534e4554, "73126106");
1316 }
1317 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001318 audio_io_handle_t output = getOutputForEffect(&desc);
1319 reply->writeInt32(static_cast <int>(output));
1320 return NO_ERROR;
1321 } break;
1322
1323 case REGISTER_EFFECT: {
1324 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001325 effect_descriptor_t desc = {};
1326 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1327 android_errorWriteLog(0x534e4554, "73126106");
1328 }
1329 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001330 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001331 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001332 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001333 int id = data.readInt32();
1334 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001335 io,
Eric Laurentde070132010-07-13 04:45:46 -07001336 strategy,
1337 session,
1338 id)));
1339 return NO_ERROR;
1340 } break;
1341
1342 case UNREGISTER_EFFECT: {
1343 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1344 int id = data.readInt32();
1345 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1346 return NO_ERROR;
1347 } break;
1348
Eric Laurentdb7c0792011-08-10 10:37:50 -07001349 case SET_EFFECT_ENABLED: {
1350 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1351 int id = data.readInt32();
1352 bool enabled = static_cast <bool>(data.readInt32());
1353 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1354 return NO_ERROR;
1355 } break;
1356
Eric Laurenteda6c362011-02-02 09:33:30 -08001357 case IS_STREAM_ACTIVE: {
1358 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001359 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001360 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001361 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001362 return NO_ERROR;
1363 } break;
1364
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001365 case IS_STREAM_ACTIVE_REMOTELY: {
1366 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1367 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1368 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001369 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001370 return NO_ERROR;
1371 } break;
1372
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001373 case IS_SOURCE_ACTIVE: {
1374 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1375 audio_source_t source = (audio_source_t) data.readInt32();
1376 reply->writeInt32( isSourceActive(source));
1377 return NO_ERROR;
1378 }
1379
Eric Laurent57dae992011-07-24 13:36:09 -07001380 case QUERY_DEFAULT_PRE_PROCESSING: {
1381 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001382 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001383 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001384 if (count > AudioEffect::kMaxPreProcessing) {
1385 count = AudioEffect::kMaxPreProcessing;
1386 }
Eric Laurent57dae992011-07-24 13:36:09 -07001387 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001388 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001389 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1390 reply->writeInt32(status);
1391 if (status != NO_ERROR && status != NO_MEMORY) {
1392 retCount = 0;
1393 }
1394 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001395 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001396 if (retCount < count) {
1397 count = retCount;
1398 }
1399 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1400 }
1401 delete[] descriptors;
1402 return status;
1403 }
1404
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001405 case IS_OFFLOAD_SUPPORTED: {
1406 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001407 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001408 data.read(&info, sizeof(audio_offload_info_t));
1409 bool isSupported = isOffloadSupported(info);
1410 reply->writeInt32(isSupported);
1411 return NO_ERROR;
1412 }
1413
Michael Chana94fbb22018-04-24 14:31:19 +10001414 case IS_DIRECT_OUTPUT_SUPPORTED: {
1415 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1416 audio_config_base_t config = {};
1417 audio_attributes_t attributes = {};
1418 status_t status = data.read(&config, sizeof(audio_config_base_t));
1419 if (status != NO_ERROR) return status;
1420 status = data.read(&attributes, sizeof(audio_attributes_t));
1421 if (status != NO_ERROR) return status;
1422 reply->writeInt32(isDirectOutputSupported(config, attributes));
1423 return NO_ERROR;
1424 }
1425
Eric Laurent203b1a12014-04-01 10:34:16 -07001426 case LIST_AUDIO_PORTS: {
1427 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1428 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1429 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1430 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001431 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1432 numPortsReq = MAX_ITEMS_PER_LIST;
1433 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001434 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001435 struct audio_port *ports =
1436 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001437 if (ports == NULL) {
1438 reply->writeInt32(NO_MEMORY);
1439 reply->writeInt32(0);
1440 return NO_ERROR;
1441 }
1442 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001443 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1444 reply->writeInt32(status);
1445 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001446
1447 if (status == NO_ERROR) {
1448 if (numPortsReq > numPorts) {
1449 numPortsReq = numPorts;
1450 }
1451 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1452 reply->writeInt32(generation);
1453 }
1454 free(ports);
1455 return NO_ERROR;
1456 }
1457
1458 case GET_AUDIO_PORT: {
1459 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001460 struct audio_port port = {};
1461 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1462 ALOGE("b/23912202");
1463 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001464 status_t status = getAudioPort(&port);
1465 reply->writeInt32(status);
1466 if (status == NO_ERROR) {
1467 reply->write(&port, sizeof(struct audio_port));
1468 }
1469 return NO_ERROR;
1470 }
1471
1472 case CREATE_AUDIO_PATCH: {
1473 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001474 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001475 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001476 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001477 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1478 ALOGE("b/23912202");
1479 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001480 status_t status = createAudioPatch(&patch, &handle);
1481 reply->writeInt32(status);
1482 if (status == NO_ERROR) {
1483 reply->write(&handle, sizeof(audio_patch_handle_t));
1484 }
1485 return NO_ERROR;
1486 }
1487
1488 case RELEASE_AUDIO_PATCH: {
1489 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001490 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001491 data.read(&handle, sizeof(audio_patch_handle_t));
1492 status_t status = releaseAudioPatch(handle);
1493 reply->writeInt32(status);
1494 return NO_ERROR;
1495 }
1496
1497 case LIST_AUDIO_PATCHES: {
1498 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1499 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001500 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1501 numPatchesReq = MAX_ITEMS_PER_LIST;
1502 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001503 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001504 struct audio_patch *patches =
1505 (struct audio_patch *)calloc(numPatchesReq,
1506 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001507 if (patches == NULL) {
1508 reply->writeInt32(NO_MEMORY);
1509 reply->writeInt32(0);
1510 return NO_ERROR;
1511 }
1512 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001513 status_t status = listAudioPatches(&numPatches, patches, &generation);
1514 reply->writeInt32(status);
1515 reply->writeInt32(numPatches);
1516 if (status == NO_ERROR) {
1517 if (numPatchesReq > numPatches) {
1518 numPatchesReq = numPatches;
1519 }
1520 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1521 reply->writeInt32(generation);
1522 }
1523 free(patches);
1524 return NO_ERROR;
1525 }
1526
1527 case SET_AUDIO_PORT_CONFIG: {
1528 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001529 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001530 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001531 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001532 status_t status = setAudioPortConfig(&config);
1533 reply->writeInt32(status);
1534 return NO_ERROR;
1535 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001536
Eric Laurentb52c1522014-05-20 11:27:36 -07001537 case REGISTER_CLIENT: {
1538 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1539 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1540 data.readStrongBinder());
1541 registerClient(client);
1542 return NO_ERROR;
1543 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001544
Eric Laurente8726fe2015-06-26 09:39:24 -07001545 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1546 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1547 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1548 return NO_ERROR;
1549 } break;
1550
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001551 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1552 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1553 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1554 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001555 audio_session_t session = AUDIO_SESSION_NONE;
1556 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1557 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001558 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1559 reply->writeInt32(status);
1560 if (status == NO_ERROR) {
1561 reply->writeInt32(session);
1562 reply->writeInt32(ioHandle);
1563 reply->writeInt32(device);
1564 }
1565 return NO_ERROR;
1566 } break;
1567
1568 case RELEASE_SOUNDTRIGGER_SESSION: {
1569 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1570 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1571 data.readStrongBinder());
1572 audio_session_t session = (audio_session_t)data.readInt32();
1573 status_t status = releaseSoundTriggerSession(session);
1574 reply->writeInt32(status);
1575 return NO_ERROR;
1576 } break;
1577
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001578 case GET_PHONE_STATE: {
1579 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1580 reply->writeInt32((int32_t)getPhoneState());
1581 return NO_ERROR;
1582 } break;
1583
Eric Laurentbaac1832014-12-01 17:52:59 -08001584 case REGISTER_POLICY_MIXES: {
1585 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1586 bool registration = data.readInt32() == 1;
1587 Vector<AudioMix> mixes;
1588 size_t size = (size_t)data.readInt32();
1589 if (size > MAX_MIXES_PER_POLICY) {
1590 size = MAX_MIXES_PER_POLICY;
1591 }
1592 for (size_t i = 0; i < size; i++) {
1593 AudioMix mix;
1594 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1595 mixes.add(mix);
1596 }
1597 }
1598 status_t status = registerPolicyMixes(mixes, registration);
1599 reply->writeInt32(status);
1600 return NO_ERROR;
1601 } break;
1602
Eric Laurent554a2772015-04-10 11:29:24 -07001603 case START_AUDIO_SOURCE: {
1604 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001605 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001606 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001607 (void)sanitizeAudioPortConfig(&source);
1608 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001609 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001610 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001611 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1612 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001613 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001614 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001615 return NO_ERROR;
1616 } break;
1617
1618 case STOP_AUDIO_SOURCE: {
1619 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001620 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1621 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001622 reply->writeInt32(status);
1623 return NO_ERROR;
1624 } break;
1625
Andy Hung2ddee192015-12-18 17:34:44 -08001626 case SET_MASTER_MONO: {
1627 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1628 bool mono = static_cast<bool>(data.readInt32());
1629 status_t status = setMasterMono(mono);
1630 reply->writeInt32(status);
1631 return NO_ERROR;
1632 } break;
1633
1634 case GET_MASTER_MONO: {
1635 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1636 bool mono;
1637 status_t status = getMasterMono(&mono);
1638 reply->writeInt32(status);
1639 if (status == NO_ERROR) {
1640 reply->writeInt32(static_cast<int32_t>(mono));
1641 }
1642 return NO_ERROR;
1643 } break;
1644
Eric Laurentac9cef52017-06-09 15:46:26 -07001645 case GET_STREAM_VOLUME_DB: {
1646 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1647 audio_stream_type_t stream =
1648 static_cast <audio_stream_type_t>(data.readInt32());
1649 int index = static_cast <int>(data.readInt32());
1650 audio_devices_t device =
1651 static_cast <audio_devices_t>(data.readUint32());
1652 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1653 return NO_ERROR;
1654 }
1655
jiabin81772902018-04-02 17:52:27 -07001656 case GET_SURROUND_FORMATS: {
1657 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1658 unsigned int numSurroundFormatsReq = data.readUint32();
1659 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1660 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1661 }
1662 bool reported = data.readBool();
1663 unsigned int numSurroundFormats = numSurroundFormatsReq;
1664 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1665 numSurroundFormats, sizeof(audio_format_t));
1666 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1667 if (numSurroundFormatsReq > 0 &&
1668 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1669 free(surroundFormats);
1670 free(surroundFormatsEnabled);
1671 reply->writeInt32(NO_MEMORY);
1672 return NO_ERROR;
1673 }
1674 status_t status = getSurroundFormats(
1675 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1676 reply->writeInt32(status);
1677
1678 if (status == NO_ERROR) {
1679 reply->writeUint32(numSurroundFormats);
1680 if (numSurroundFormatsReq > numSurroundFormats) {
1681 numSurroundFormatsReq = numSurroundFormats;
1682 }
1683 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1684 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1685 }
1686 free(surroundFormats);
1687 free(surroundFormatsEnabled);
1688 return NO_ERROR;
1689 }
1690
1691 case SET_SURROUND_FORMAT_ENABLED: {
1692 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1693 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1694 bool enabled = data.readBool();
1695 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1696 reply->writeInt32(status);
1697 return NO_ERROR;
1698 }
1699
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001700 case ADD_STREAM_DEFAULT_EFFECT: {
1701 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1702 effect_uuid_t type;
1703 status_t status = data.read(&type, sizeof(effect_uuid_t));
1704 if (status != NO_ERROR) {
1705 return status;
1706 }
1707 String16 opPackageName;
1708 status = data.readString16(&opPackageName);
1709 if (status != NO_ERROR) {
1710 return status;
1711 }
1712 effect_uuid_t uuid;
1713 status = data.read(&uuid, sizeof(effect_uuid_t));
1714 if (status != NO_ERROR) {
1715 return status;
1716 }
1717 int32_t priority = data.readInt32();
1718 audio_usage_t usage = (audio_usage_t) data.readInt32();
1719 audio_unique_id_t id = 0;
1720 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1721 opPackageName,
1722 &uuid,
1723 priority,
1724 usage,
1725 &id)));
1726 reply->writeInt32(id);
1727 return NO_ERROR;
1728 }
1729
1730 case REMOVE_STREAM_DEFAULT_EFFECT: {
1731 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1732 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1733 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1734 return NO_ERROR;
1735 }
1736
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001737 case ADD_SOURCE_DEFAULT_EFFECT: {
1738 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1739 effect_uuid_t type;
1740 status_t status = data.read(&type, sizeof(effect_uuid_t));
1741 if (status != NO_ERROR) {
1742 return status;
1743 }
1744 String16 opPackageName;
1745 status = data.readString16(&opPackageName);
1746 if (status != NO_ERROR) {
1747 return status;
1748 }
1749 effect_uuid_t uuid;
1750 status = data.read(&uuid, sizeof(effect_uuid_t));
1751 if (status != NO_ERROR) {
1752 return status;
1753 }
1754 int32_t priority = data.readInt32();
1755 audio_source_t source = (audio_source_t) data.readInt32();
1756 audio_unique_id_t id = 0;
1757 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1758 opPackageName,
1759 &uuid,
1760 priority,
1761 source,
1762 &id)));
1763 reply->writeInt32(id);
1764 return NO_ERROR;
1765 }
1766
1767 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1768 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1769 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1770 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1771 return NO_ERROR;
1772 }
1773
Eric Laurentb78763e2018-10-17 10:08:02 -07001774 case SET_ASSISTANT_UID: {
1775 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1776 int32_t uid;
1777 status_t status = data.readInt32(&uid);
1778 if (status != NO_ERROR) {
1779 return status;
1780 }
1781 status = setAssistantUid(uid);
1782 reply->writeInt32(static_cast <int32_t>(status));
1783 return NO_ERROR;
1784 }
1785
1786 case SET_A11Y_SERVICES_UIDS: {
1787 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1788 std::vector<uid_t> uids;
1789 int32_t size;
1790 status_t status = data.readInt32(&size);
1791 if (status != NO_ERROR) {
1792 return status;
1793 }
1794 if (size > MAX_ITEMS_PER_LIST) {
1795 size = MAX_ITEMS_PER_LIST;
1796 }
1797 for (int32_t i = 0; i < size; i++) {
1798 int32_t uid;
1799 status = data.readInt32(&uid);
1800 if (status != NO_ERROR) {
1801 return status;
1802 }
1803 uids.push_back(uid);
1804 }
1805 status = setA11yServicesUids(uids);
1806 reply->writeInt32(static_cast <int32_t>(status));
1807 return NO_ERROR;
1808 }
1809
jiabin6012f912018-11-02 17:06:30 -07001810 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
1811 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1812 bool isSupported = isHapticPlaybackSupported();
1813 reply->writeBool(isSupported);
1814 return NO_ERROR;
1815 }
1816
Eric Laurentc2f1f072009-07-17 12:17:14 -07001817 default:
1818 return BBinder::onTransact(code, data, reply, flags);
1819 }
1820}
1821
Andy Hungb0272092018-04-12 11:06:56 -07001822/** returns true if string overflow was prevented by zero termination */
1823template <size_t size>
1824static bool preventStringOverflow(char (&s)[size]) {
1825 if (strnlen(s, size) < size) return false;
1826 s[size - 1] = '\0';
1827 return true;
1828}
1829
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001830void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1831{
1832 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1833 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1834 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1835 }
1836 attr->tags[tagsMaxSize - 1] = '\0';
1837}
1838
Andy Hungb0272092018-04-12 11:06:56 -07001839/** returns BAD_VALUE if sanitization was required. */
1840status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1841{
1842 if (preventStringOverflow(desc->name)
1843 | /* always */ preventStringOverflow(desc->implementor)) {
1844 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1845 return BAD_VALUE;
1846 }
1847 return NO_ERROR;
1848}
1849
1850/** returns BAD_VALUE if sanitization was required. */
1851status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1852{
1853 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1854 preventStringOverflow(config->ext.device.address)) {
1855 return BAD_VALUE;
1856 }
1857 return NO_ERROR;
1858}
1859
Eric Laurentc2f1f072009-07-17 12:17:14 -07001860// ----------------------------------------------------------------------------
1861
Glenn Kasten40bc9062015-03-20 09:09:33 -07001862} // namespace android