blob: 272415c59f6d0fcc04bccccec5045a44e0d9fa43 [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,
Jean-Michel Trivibda70da2018-12-19 07:30:15 -080093 SET_UID_DEVICE_AFFINITY,
94 REMOVE_UID_DEVICE_AFFINITY,
Eric Laurentc2f1f072009-07-17 12:17:14 -070095};
96
Eric Laurent1d670b12015-02-06 10:44:24 -080097#define MAX_ITEMS_PER_LIST 1024
98
Eric Laurentc2f1f072009-07-17 12:17:14 -070099class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
100{
101public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700102 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700103 : BpInterface<IAudioPolicyService>(impl)
104 {
105 }
106
107 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700108 audio_devices_t device,
109 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800110 const char *device_address,
111 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 {
113 Parcel data, reply;
114 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
115 data.writeInt32(static_cast <uint32_t>(device));
116 data.writeInt32(static_cast <uint32_t>(state));
117 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800118 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700119 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
120 return static_cast <status_t> (reply.readInt32());
121 }
122
Dima Zavinfce7a472011-04-19 22:30:36 -0700123 virtual audio_policy_dev_state_t getDeviceConnectionState(
124 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700125 const char *device_address)
126 {
127 Parcel data, reply;
128 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
129 data.writeInt32(static_cast <uint32_t>(device));
130 data.writeCString(device_address);
131 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700132 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700133 }
134
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800135 virtual status_t handleDeviceConfigChange(audio_devices_t device,
136 const char *device_address,
137 const char *device_name)
138 {
139 Parcel data, reply;
140 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
141 data.writeInt32(static_cast <uint32_t>(device));
142 data.writeCString(device_address);
143 data.writeCString(device_name);
144 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
145 return static_cast <status_t> (reply.readInt32());
146 }
147
Glenn Kastenf78aee72012-01-04 11:00:47 -0800148 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 {
150 Parcel data, reply;
151 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
152 data.writeInt32(state);
153 remote()->transact(SET_PHONE_STATE, data, &reply);
154 return static_cast <status_t> (reply.readInt32());
155 }
156
Dima Zavinfce7a472011-04-19 22:30:36 -0700157 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700158 {
159 Parcel data, reply;
160 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
161 data.writeInt32(static_cast <uint32_t>(usage));
162 data.writeInt32(static_cast <uint32_t>(config));
163 remote()->transact(SET_FORCE_USE, data, &reply);
164 return static_cast <status_t> (reply.readInt32());
165 }
166
Dima Zavinfce7a472011-04-19 22:30:36 -0700167 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700168 {
169 Parcel data, reply;
170 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
171 data.writeInt32(static_cast <uint32_t>(usage));
172 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700173 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700174 }
175
Eric Laurentf4e63452017-11-06 19:31:46 +0000176 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700177 {
178 Parcel data, reply;
179 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
180 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700181 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700182 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700183 }
184
Eric Laurente83b55d2014-11-14 10:06:21 -0800185 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
186 audio_io_handle_t *output,
187 audio_session_t session,
188 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200189 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700190 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800191 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800192 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700193 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800194 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700195 {
196 Parcel data, reply;
197 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
198 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800199 if (stream == NULL) {
200 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
201 return BAD_VALUE;
202 }
203 if (*stream == AUDIO_STREAM_DEFAULT) {
204 ALOGE("getOutputForAttr unspecified stream type");
205 return BAD_VALUE;
206 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700207 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800208 if (output == NULL) {
209 ALOGE("getOutputForAttr NULL output - shouldn't happen");
210 return BAD_VALUE;
211 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700212 if (selectedDeviceId == NULL) {
213 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
214 return BAD_VALUE;
215 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800216 if (portId == NULL) {
217 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
218 return BAD_VALUE;
219 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800220 if (attr == NULL) {
221 data.writeInt32(0);
222 } else {
223 data.writeInt32(1);
224 data.write(attr, sizeof(audio_attributes_t));
225 }
226 data.writeInt32(session);
227 if (stream == NULL) {
228 data.writeInt32(0);
229 } else {
230 data.writeInt32(1);
231 data.writeInt32(*stream);
232 }
Nadav Bar766fb022018-01-07 12:18:03 +0200233 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700234 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800235 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700236 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700237 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800238 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800239 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
240 if (status != NO_ERROR) {
241 return status;
242 }
243 status = (status_t)reply.readInt32();
244 if (status != NO_ERROR) {
245 return status;
246 }
247 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800248 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800249 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700252 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800253 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800254 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700255 }
256
Eric Laurentd7fe0862018-07-14 16:48:01 -0700257 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 {
259 Parcel data, reply;
260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700261 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700262 remote()->transact(START_OUTPUT, data, &reply);
263 return static_cast <status_t> (reply.readInt32());
264 }
265
Eric Laurentd7fe0862018-07-14 16:48:01 -0700266 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 {
268 Parcel data, reply;
269 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700270 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700271 remote()->transact(STOP_OUTPUT, data, &reply);
272 return static_cast <status_t> (reply.readInt32());
273 }
274
Eric Laurentd7fe0862018-07-14 16:48:01 -0700275 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700279 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700280 remote()->transact(RELEASE_OUTPUT, data, &reply);
281 }
282
Eric Laurentcaf7f482014-11-25 17:50:47 -0800283 virtual status_t getInputForAttr(const audio_attributes_t *attr,
284 audio_io_handle_t *input,
285 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700286 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700287 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800288 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800289 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600290 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700291 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800292 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 {
294 Parcel data, reply;
295 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800296 if (attr == NULL) {
297 ALOGE("getInputForAttr NULL attr - shouldn't happen");
298 return BAD_VALUE;
299 }
300 if (input == NULL) {
301 ALOGE("getInputForAttr NULL input - shouldn't happen");
302 return BAD_VALUE;
303 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700304 if (selectedDeviceId == NULL) {
305 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
306 return BAD_VALUE;
307 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800308 if (portId == NULL) {
309 ALOGE("getInputForAttr NULL portId - shouldn't happen");
310 return BAD_VALUE;
311 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800312 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700313 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800314 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700315 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700316 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800317 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800318 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700319 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700320 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800321 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800322 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
323 if (status != NO_ERROR) {
324 return status;
325 }
326 status = reply.readInt32();
327 if (status != NO_ERROR) {
328 return status;
329 }
330 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700331 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800332 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800333 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 }
335
Eric Laurent4eb58f12018-12-07 16:41:02 -0800336 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800340 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700341 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800342 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800343 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
jiabin6012f912018-11-02 17:06:30 -0700984 virtual bool isHapticPlaybackSupported()
985 {
986 Parcel data, reply;
987 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
988 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
989 if (status != NO_ERROR) {
990 return false;
991 }
992 return reply.readBool();
993 }
994
Jean-Michel Trivibda70da2018-12-19 07:30:15 -0800995 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
996 {
997 Parcel data, reply;
998 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
999
1000 data.writeInt32((int32_t) uid);
1001 size_t size = devices.size();
1002 size_t sizePosition = data.dataPosition();
1003 data.writeInt32((int32_t) size);
1004 size_t finalSize = size;
1005 for (size_t i = 0; i < size; i++) {
1006 size_t position = data.dataPosition();
1007 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1008 data.setDataPosition(position);
1009 finalSize--;
1010 }
1011 }
1012 if (size != finalSize) {
1013 size_t position = data.dataPosition();
1014 data.setDataPosition(sizePosition);
1015 data.writeInt32(finalSize);
1016 data.setDataPosition(position);
1017 }
1018
1019 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1020 if (status == NO_ERROR) {
1021 status = (status_t)reply.readInt32();
1022 }
1023 return status;
1024 }
1025
1026 virtual status_t removeUidDeviceAffinities(uid_t uid)
1027 {
1028 Parcel data, reply;
1029 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1030
1031 data.writeInt32((int32_t) uid);
1032
1033 status_t status = remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
1034 if (status == NO_ERROR) {
1035 status = (status_t)reply.readInt32();
1036 }
1037 return status;
1038 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001039};
1040
1041IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1042
1043// ----------------------------------------------------------------------
1044
Eric Laurentc2f1f072009-07-17 12:17:14 -07001045status_t BnAudioPolicyService::onTransact(
1046 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1047{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001048 // make sure transactions reserved to AudioFlinger do not come from other processes
1049 switch (code) {
1050 case START_OUTPUT:
1051 case STOP_OUTPUT:
1052 case RELEASE_OUTPUT:
1053 case GET_INPUT_FOR_ATTR:
1054 case START_INPUT:
1055 case STOP_INPUT:
1056 case RELEASE_INPUT:
1057 case GET_STRATEGY_FOR_STREAM:
1058 case GET_OUTPUT_FOR_EFFECT:
1059 case REGISTER_EFFECT:
1060 case UNREGISTER_EFFECT:
1061 case SET_EFFECT_ENABLED:
1062 case GET_OUTPUT_FOR_ATTR:
1063 case ACQUIRE_SOUNDTRIGGER_SESSION:
1064 case RELEASE_SOUNDTRIGGER_SESSION:
1065 ALOGW("%s: transaction %d received from PID %d",
1066 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001067 // return status only for non void methods
1068 switch (code) {
1069 case RELEASE_OUTPUT:
1070 case RELEASE_INPUT:
1071 break;
1072 default:
1073 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1074 break;
1075 }
1076 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001077 default:
1078 break;
1079 }
1080
Eric Laurent4980df22018-01-26 18:04:09 -08001081 // make sure the following transactions come from system components
1082 switch (code) {
1083 case SET_DEVICE_CONNECTION_STATE:
1084 case HANDLE_DEVICE_CONFIG_CHANGE:
1085 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001086//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1087// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001088 case INIT_STREAM_VOLUME:
1089 case SET_STREAM_VOLUME:
1090 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001091 case SET_MASTER_MONO:
1092 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001093 case STOP_AUDIO_SOURCE:
1094 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001095 case SET_SURROUND_FORMAT_ENABLED:
1096 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001097 case SET_A11Y_SERVICES_UIDS:
1098 case SET_UID_DEVICE_AFFINITY:
1099 case REMOVE_UID_DEVICE_AFFINITY: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001100 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001101 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1102 __func__, code, IPCThreadState::self()->getCallingPid(),
1103 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001104 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1105 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001106 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001107 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001108 default:
1109 break;
1110 }
1111
Eric Laurent39b09b52018-06-29 12:24:40 -07001112 std::string tag("IAudioPolicyService command " + std::to_string(code));
1113 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001114
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001115 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001116 case SET_DEVICE_CONNECTION_STATE: {
1117 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001118 audio_devices_t device =
1119 static_cast <audio_devices_t>(data.readInt32());
1120 audio_policy_dev_state_t state =
1121 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001122 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001123 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001124 if (device_address == nullptr || device_name == nullptr) {
1125 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1126 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1127 } else {
1128 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1129 state,
1130 device_address,
1131 device_name)));
1132 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 return NO_ERROR;
1134 } break;
1135
1136 case GET_DEVICE_CONNECTION_STATE: {
1137 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001138 audio_devices_t device =
1139 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001140 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001141 if (device_address == nullptr) {
1142 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1143 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1144 } else {
1145 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1146 device_address)));
1147 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001148 return NO_ERROR;
1149 } break;
1150
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001151 case HANDLE_DEVICE_CONFIG_CHANGE: {
1152 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1153 audio_devices_t device =
1154 static_cast <audio_devices_t>(data.readInt32());
1155 const char *device_address = data.readCString();
1156 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001157 if (device_address == nullptr || device_name == nullptr) {
1158 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1159 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1160 } else {
1161 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1162 device_address,
1163 device_name)));
1164 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001165 return NO_ERROR;
1166 } break;
1167
Eric Laurentc2f1f072009-07-17 12:17:14 -07001168 case SET_PHONE_STATE: {
1169 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001170 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1171 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001172 return NO_ERROR;
1173 } break;
1174
Eric Laurentc2f1f072009-07-17 12:17:14 -07001175 case SET_FORCE_USE: {
1176 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001177 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1178 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001179 audio_policy_forced_cfg_t config =
1180 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001181 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1182 return NO_ERROR;
1183 } break;
1184
1185 case GET_FORCE_USE: {
1186 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001187 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1188 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001189 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1190 return NO_ERROR;
1191 } break;
1192
1193 case GET_OUTPUT: {
1194 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001195 audio_stream_type_t stream =
1196 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001197 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001198 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001199 return NO_ERROR;
1200 } break;
1201
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001202 case GET_OUTPUT_FOR_ATTR: {
1203 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001204 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001205 bool hasAttributes = data.readInt32() != 0;
1206 if (hasAttributes) {
1207 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001208 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001209 }
1210 audio_session_t session = (audio_session_t)data.readInt32();
1211 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1212 bool hasStream = data.readInt32() != 0;
1213 if (hasStream) {
1214 stream = (audio_stream_type_t)data.readInt32();
1215 }
Nadav Bar766fb022018-01-07 12:18:03 +02001216 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001217 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001218 audio_config_t config;
1219 memset(&config, 0, sizeof(audio_config_t));
1220 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001221 audio_output_flags_t flags =
1222 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001223 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001224 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001225 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001226 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001227 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001228 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001229 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001230 reply->writeInt32(status);
1231 reply->writeInt32(output);
1232 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001233 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001234 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001235 return NO_ERROR;
1236 } break;
1237
Eric Laurentc2f1f072009-07-17 12:17:14 -07001238 case START_OUTPUT: {
1239 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001240 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1241 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001242 return NO_ERROR;
1243 } break;
1244
1245 case STOP_OUTPUT: {
1246 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001247 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1248 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001249 return NO_ERROR;
1250 } break;
1251
1252 case RELEASE_OUTPUT: {
1253 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001254 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1255 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001256 return NO_ERROR;
1257 } break;
1258
Eric Laurentcaf7f482014-11-25 17:50:47 -08001259 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001260 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001261 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001262 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001263 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001264 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001265 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001266 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001267 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001268 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001269 audio_config_base_t config;
1270 memset(&config, 0, sizeof(audio_config_base_t));
1271 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001272 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001273 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001274 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001275 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001276 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001277 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001278 reply->writeInt32(status);
1279 if (status == NO_ERROR) {
1280 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001281 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001282 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001283 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001284 return NO_ERROR;
1285 } break;
1286
1287 case START_INPUT: {
1288 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001289 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001290 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001291 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001292 return NO_ERROR;
1293 } break;
1294
1295 case STOP_INPUT: {
1296 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001297 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1298 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001299 return NO_ERROR;
1300 } break;
1301
1302 case RELEASE_INPUT: {
1303 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001304 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1305 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001306 return NO_ERROR;
1307 } break;
1308
1309 case INIT_STREAM_VOLUME: {
1310 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001311 audio_stream_type_t stream =
1312 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001313 int indexMin = data.readInt32();
1314 int indexMax = data.readInt32();
1315 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1316 return NO_ERROR;
1317 } break;
1318
1319 case SET_STREAM_VOLUME: {
1320 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001321 audio_stream_type_t stream =
1322 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001323 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001324 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1325 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1326 index,
1327 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001328 return NO_ERROR;
1329 } break;
1330
1331 case GET_STREAM_VOLUME: {
1332 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001333 audio_stream_type_t stream =
1334 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001335 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001336 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001337 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001338 reply->writeInt32(index);
1339 reply->writeInt32(static_cast <uint32_t>(status));
1340 return NO_ERROR;
1341 } break;
1342
Eric Laurentde070132010-07-13 04:45:46 -07001343 case GET_STRATEGY_FOR_STREAM: {
1344 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001345 audio_stream_type_t stream =
1346 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001347 reply->writeInt32(getStrategyForStream(stream));
1348 return NO_ERROR;
1349 } break;
1350
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001351 case GET_DEVICES_FOR_STREAM: {
1352 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001353 audio_stream_type_t stream =
1354 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001355 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1356 return NO_ERROR;
1357 } break;
1358
Eric Laurentde070132010-07-13 04:45:46 -07001359 case GET_OUTPUT_FOR_EFFECT: {
1360 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001361 effect_descriptor_t desc = {};
1362 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1363 android_errorWriteLog(0x534e4554, "73126106");
1364 }
1365 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001366 audio_io_handle_t output = getOutputForEffect(&desc);
1367 reply->writeInt32(static_cast <int>(output));
1368 return NO_ERROR;
1369 } break;
1370
1371 case REGISTER_EFFECT: {
1372 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001373 effect_descriptor_t desc = {};
1374 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1375 android_errorWriteLog(0x534e4554, "73126106");
1376 }
1377 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001378 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001379 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001380 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001381 int id = data.readInt32();
1382 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001383 io,
Eric Laurentde070132010-07-13 04:45:46 -07001384 strategy,
1385 session,
1386 id)));
1387 return NO_ERROR;
1388 } break;
1389
1390 case UNREGISTER_EFFECT: {
1391 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1392 int id = data.readInt32();
1393 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1394 return NO_ERROR;
1395 } break;
1396
Eric Laurentdb7c0792011-08-10 10:37:50 -07001397 case SET_EFFECT_ENABLED: {
1398 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1399 int id = data.readInt32();
1400 bool enabled = static_cast <bool>(data.readInt32());
1401 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1402 return NO_ERROR;
1403 } break;
1404
Eric Laurenteda6c362011-02-02 09:33:30 -08001405 case IS_STREAM_ACTIVE: {
1406 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001407 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001408 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001409 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001410 return NO_ERROR;
1411 } break;
1412
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001413 case IS_STREAM_ACTIVE_REMOTELY: {
1414 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1415 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1416 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001417 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001418 return NO_ERROR;
1419 } break;
1420
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001421 case IS_SOURCE_ACTIVE: {
1422 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1423 audio_source_t source = (audio_source_t) data.readInt32();
1424 reply->writeInt32( isSourceActive(source));
1425 return NO_ERROR;
1426 }
1427
Eric Laurent57dae992011-07-24 13:36:09 -07001428 case QUERY_DEFAULT_PRE_PROCESSING: {
1429 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001430 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001431 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001432 if (count > AudioEffect::kMaxPreProcessing) {
1433 count = AudioEffect::kMaxPreProcessing;
1434 }
Eric Laurent57dae992011-07-24 13:36:09 -07001435 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001436 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001437 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1438 reply->writeInt32(status);
1439 if (status != NO_ERROR && status != NO_MEMORY) {
1440 retCount = 0;
1441 }
1442 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001443 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001444 if (retCount < count) {
1445 count = retCount;
1446 }
1447 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1448 }
1449 delete[] descriptors;
1450 return status;
1451 }
1452
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001453 case IS_OFFLOAD_SUPPORTED: {
1454 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001455 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001456 data.read(&info, sizeof(audio_offload_info_t));
1457 bool isSupported = isOffloadSupported(info);
1458 reply->writeInt32(isSupported);
1459 return NO_ERROR;
1460 }
1461
Michael Chana94fbb22018-04-24 14:31:19 +10001462 case IS_DIRECT_OUTPUT_SUPPORTED: {
1463 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1464 audio_config_base_t config = {};
1465 audio_attributes_t attributes = {};
1466 status_t status = data.read(&config, sizeof(audio_config_base_t));
1467 if (status != NO_ERROR) return status;
1468 status = data.read(&attributes, sizeof(audio_attributes_t));
1469 if (status != NO_ERROR) return status;
1470 reply->writeInt32(isDirectOutputSupported(config, attributes));
1471 return NO_ERROR;
1472 }
1473
Eric Laurent203b1a12014-04-01 10:34:16 -07001474 case LIST_AUDIO_PORTS: {
1475 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1476 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1477 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1478 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001479 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1480 numPortsReq = MAX_ITEMS_PER_LIST;
1481 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001482 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001483 struct audio_port *ports =
1484 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001485 if (ports == NULL) {
1486 reply->writeInt32(NO_MEMORY);
1487 reply->writeInt32(0);
1488 return NO_ERROR;
1489 }
1490 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001491 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1492 reply->writeInt32(status);
1493 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001494
1495 if (status == NO_ERROR) {
1496 if (numPortsReq > numPorts) {
1497 numPortsReq = numPorts;
1498 }
1499 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1500 reply->writeInt32(generation);
1501 }
1502 free(ports);
1503 return NO_ERROR;
1504 }
1505
1506 case GET_AUDIO_PORT: {
1507 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001508 struct audio_port port = {};
1509 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1510 ALOGE("b/23912202");
1511 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001512 status_t status = getAudioPort(&port);
1513 reply->writeInt32(status);
1514 if (status == NO_ERROR) {
1515 reply->write(&port, sizeof(struct audio_port));
1516 }
1517 return NO_ERROR;
1518 }
1519
1520 case CREATE_AUDIO_PATCH: {
1521 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001522 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001523 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001524 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001525 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1526 ALOGE("b/23912202");
1527 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001528 status_t status = createAudioPatch(&patch, &handle);
1529 reply->writeInt32(status);
1530 if (status == NO_ERROR) {
1531 reply->write(&handle, sizeof(audio_patch_handle_t));
1532 }
1533 return NO_ERROR;
1534 }
1535
1536 case RELEASE_AUDIO_PATCH: {
1537 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001538 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001539 data.read(&handle, sizeof(audio_patch_handle_t));
1540 status_t status = releaseAudioPatch(handle);
1541 reply->writeInt32(status);
1542 return NO_ERROR;
1543 }
1544
1545 case LIST_AUDIO_PATCHES: {
1546 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1547 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001548 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1549 numPatchesReq = MAX_ITEMS_PER_LIST;
1550 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001551 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001552 struct audio_patch *patches =
1553 (struct audio_patch *)calloc(numPatchesReq,
1554 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001555 if (patches == NULL) {
1556 reply->writeInt32(NO_MEMORY);
1557 reply->writeInt32(0);
1558 return NO_ERROR;
1559 }
1560 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001561 status_t status = listAudioPatches(&numPatches, patches, &generation);
1562 reply->writeInt32(status);
1563 reply->writeInt32(numPatches);
1564 if (status == NO_ERROR) {
1565 if (numPatchesReq > numPatches) {
1566 numPatchesReq = numPatches;
1567 }
1568 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1569 reply->writeInt32(generation);
1570 }
1571 free(patches);
1572 return NO_ERROR;
1573 }
1574
1575 case SET_AUDIO_PORT_CONFIG: {
1576 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001577 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001578 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001579 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001580 status_t status = setAudioPortConfig(&config);
1581 reply->writeInt32(status);
1582 return NO_ERROR;
1583 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001584
Eric Laurentb52c1522014-05-20 11:27:36 -07001585 case REGISTER_CLIENT: {
1586 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1587 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1588 data.readStrongBinder());
1589 registerClient(client);
1590 return NO_ERROR;
1591 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001592
Eric Laurente8726fe2015-06-26 09:39:24 -07001593 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1594 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1595 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1596 return NO_ERROR;
1597 } break;
1598
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001599 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1600 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1601 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1602 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001603 audio_session_t session = AUDIO_SESSION_NONE;
1604 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1605 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001606 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1607 reply->writeInt32(status);
1608 if (status == NO_ERROR) {
1609 reply->writeInt32(session);
1610 reply->writeInt32(ioHandle);
1611 reply->writeInt32(device);
1612 }
1613 return NO_ERROR;
1614 } break;
1615
1616 case RELEASE_SOUNDTRIGGER_SESSION: {
1617 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1618 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1619 data.readStrongBinder());
1620 audio_session_t session = (audio_session_t)data.readInt32();
1621 status_t status = releaseSoundTriggerSession(session);
1622 reply->writeInt32(status);
1623 return NO_ERROR;
1624 } break;
1625
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001626 case GET_PHONE_STATE: {
1627 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1628 reply->writeInt32((int32_t)getPhoneState());
1629 return NO_ERROR;
1630 } break;
1631
Eric Laurentbaac1832014-12-01 17:52:59 -08001632 case REGISTER_POLICY_MIXES: {
1633 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1634 bool registration = data.readInt32() == 1;
1635 Vector<AudioMix> mixes;
1636 size_t size = (size_t)data.readInt32();
1637 if (size > MAX_MIXES_PER_POLICY) {
1638 size = MAX_MIXES_PER_POLICY;
1639 }
1640 for (size_t i = 0; i < size; i++) {
1641 AudioMix mix;
1642 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1643 mixes.add(mix);
1644 }
1645 }
1646 status_t status = registerPolicyMixes(mixes, registration);
1647 reply->writeInt32(status);
1648 return NO_ERROR;
1649 } break;
1650
Eric Laurent554a2772015-04-10 11:29:24 -07001651 case START_AUDIO_SOURCE: {
1652 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001653 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001654 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001655 (void)sanitizeAudioPortConfig(&source);
1656 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001657 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001658 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001659 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1660 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001661 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001662 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001663 return NO_ERROR;
1664 } break;
1665
1666 case STOP_AUDIO_SOURCE: {
1667 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001668 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1669 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001670 reply->writeInt32(status);
1671 return NO_ERROR;
1672 } break;
1673
Andy Hung2ddee192015-12-18 17:34:44 -08001674 case SET_MASTER_MONO: {
1675 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1676 bool mono = static_cast<bool>(data.readInt32());
1677 status_t status = setMasterMono(mono);
1678 reply->writeInt32(status);
1679 return NO_ERROR;
1680 } break;
1681
1682 case GET_MASTER_MONO: {
1683 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1684 bool mono;
1685 status_t status = getMasterMono(&mono);
1686 reply->writeInt32(status);
1687 if (status == NO_ERROR) {
1688 reply->writeInt32(static_cast<int32_t>(mono));
1689 }
1690 return NO_ERROR;
1691 } break;
1692
Eric Laurentac9cef52017-06-09 15:46:26 -07001693 case GET_STREAM_VOLUME_DB: {
1694 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1695 audio_stream_type_t stream =
1696 static_cast <audio_stream_type_t>(data.readInt32());
1697 int index = static_cast <int>(data.readInt32());
1698 audio_devices_t device =
1699 static_cast <audio_devices_t>(data.readUint32());
1700 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1701 return NO_ERROR;
1702 }
1703
jiabin81772902018-04-02 17:52:27 -07001704 case GET_SURROUND_FORMATS: {
1705 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1706 unsigned int numSurroundFormatsReq = data.readUint32();
1707 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1708 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1709 }
1710 bool reported = data.readBool();
1711 unsigned int numSurroundFormats = numSurroundFormatsReq;
1712 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1713 numSurroundFormats, sizeof(audio_format_t));
1714 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1715 if (numSurroundFormatsReq > 0 &&
1716 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1717 free(surroundFormats);
1718 free(surroundFormatsEnabled);
1719 reply->writeInt32(NO_MEMORY);
1720 return NO_ERROR;
1721 }
1722 status_t status = getSurroundFormats(
1723 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1724 reply->writeInt32(status);
1725
1726 if (status == NO_ERROR) {
1727 reply->writeUint32(numSurroundFormats);
1728 if (numSurroundFormatsReq > numSurroundFormats) {
1729 numSurroundFormatsReq = numSurroundFormats;
1730 }
1731 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1732 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1733 }
1734 free(surroundFormats);
1735 free(surroundFormatsEnabled);
1736 return NO_ERROR;
1737 }
1738
1739 case SET_SURROUND_FORMAT_ENABLED: {
1740 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1741 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1742 bool enabled = data.readBool();
1743 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1744 reply->writeInt32(status);
1745 return NO_ERROR;
1746 }
1747
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001748 case ADD_STREAM_DEFAULT_EFFECT: {
1749 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1750 effect_uuid_t type;
1751 status_t status = data.read(&type, sizeof(effect_uuid_t));
1752 if (status != NO_ERROR) {
1753 return status;
1754 }
1755 String16 opPackageName;
1756 status = data.readString16(&opPackageName);
1757 if (status != NO_ERROR) {
1758 return status;
1759 }
1760 effect_uuid_t uuid;
1761 status = data.read(&uuid, sizeof(effect_uuid_t));
1762 if (status != NO_ERROR) {
1763 return status;
1764 }
1765 int32_t priority = data.readInt32();
1766 audio_usage_t usage = (audio_usage_t) data.readInt32();
1767 audio_unique_id_t id = 0;
1768 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1769 opPackageName,
1770 &uuid,
1771 priority,
1772 usage,
1773 &id)));
1774 reply->writeInt32(id);
1775 return NO_ERROR;
1776 }
1777
1778 case REMOVE_STREAM_DEFAULT_EFFECT: {
1779 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1780 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1781 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1782 return NO_ERROR;
1783 }
1784
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001785 case ADD_SOURCE_DEFAULT_EFFECT: {
1786 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1787 effect_uuid_t type;
1788 status_t status = data.read(&type, sizeof(effect_uuid_t));
1789 if (status != NO_ERROR) {
1790 return status;
1791 }
1792 String16 opPackageName;
1793 status = data.readString16(&opPackageName);
1794 if (status != NO_ERROR) {
1795 return status;
1796 }
1797 effect_uuid_t uuid;
1798 status = data.read(&uuid, sizeof(effect_uuid_t));
1799 if (status != NO_ERROR) {
1800 return status;
1801 }
1802 int32_t priority = data.readInt32();
1803 audio_source_t source = (audio_source_t) data.readInt32();
1804 audio_unique_id_t id = 0;
1805 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1806 opPackageName,
1807 &uuid,
1808 priority,
1809 source,
1810 &id)));
1811 reply->writeInt32(id);
1812 return NO_ERROR;
1813 }
1814
1815 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1816 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1817 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1818 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1819 return NO_ERROR;
1820 }
1821
Eric Laurentb78763e2018-10-17 10:08:02 -07001822 case SET_ASSISTANT_UID: {
1823 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1824 int32_t uid;
1825 status_t status = data.readInt32(&uid);
1826 if (status != NO_ERROR) {
1827 return status;
1828 }
1829 status = setAssistantUid(uid);
1830 reply->writeInt32(static_cast <int32_t>(status));
1831 return NO_ERROR;
1832 }
1833
1834 case SET_A11Y_SERVICES_UIDS: {
1835 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1836 std::vector<uid_t> uids;
1837 int32_t size;
1838 status_t status = data.readInt32(&size);
1839 if (status != NO_ERROR) {
1840 return status;
1841 }
1842 if (size > MAX_ITEMS_PER_LIST) {
1843 size = MAX_ITEMS_PER_LIST;
1844 }
1845 for (int32_t i = 0; i < size; i++) {
1846 int32_t uid;
1847 status = data.readInt32(&uid);
1848 if (status != NO_ERROR) {
1849 return status;
1850 }
1851 uids.push_back(uid);
1852 }
1853 status = setA11yServicesUids(uids);
1854 reply->writeInt32(static_cast <int32_t>(status));
1855 return NO_ERROR;
1856 }
1857
jiabin6012f912018-11-02 17:06:30 -07001858 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
1859 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1860 bool isSupported = isHapticPlaybackSupported();
1861 reply->writeBool(isSupported);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001862 return NO_ERROR;
1863 }
1864
1865 case SET_UID_DEVICE_AFFINITY: {
1866 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1867 const uid_t uid = (uid_t) data.readInt32();
1868 Vector<AudioDeviceTypeAddr> devices;
1869 size_t size = (size_t)data.readInt32();
1870 for (size_t i = 0; i < size; i++) {
1871 AudioDeviceTypeAddr device;
1872 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
1873 devices.add(device);
1874 }
1875 }
1876 status_t status = setUidDeviceAffinities(uid, devices);
1877 reply->writeInt32(status);
1878 return NO_ERROR;
1879 }
1880
1881 case REMOVE_UID_DEVICE_AFFINITY: {
1882 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1883 const uid_t uid = (uid_t) data.readInt32();
1884 status_t status = removeUidDeviceAffinities(uid);
1885 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07001886 return NO_ERROR;
1887 }
1888
Eric Laurentc2f1f072009-07-17 12:17:14 -07001889 default:
1890 return BBinder::onTransact(code, data, reply, flags);
1891 }
1892}
1893
Andy Hungb0272092018-04-12 11:06:56 -07001894/** returns true if string overflow was prevented by zero termination */
1895template <size_t size>
1896static bool preventStringOverflow(char (&s)[size]) {
1897 if (strnlen(s, size) < size) return false;
1898 s[size - 1] = '\0';
1899 return true;
1900}
1901
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001902void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1903{
1904 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1905 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1906 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1907 }
1908 attr->tags[tagsMaxSize - 1] = '\0';
1909}
1910
Andy Hungb0272092018-04-12 11:06:56 -07001911/** returns BAD_VALUE if sanitization was required. */
1912status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1913{
1914 if (preventStringOverflow(desc->name)
1915 | /* always */ preventStringOverflow(desc->implementor)) {
1916 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1917 return BAD_VALUE;
1918 }
1919 return NO_ERROR;
1920}
1921
1922/** returns BAD_VALUE if sanitization was required. */
1923status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1924{
1925 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1926 preventStringOverflow(config->ext.device.address)) {
1927 return BAD_VALUE;
1928 }
1929 return NO_ERROR;
1930}
1931
Eric Laurentc2f1f072009-07-17 12:17:14 -07001932// ----------------------------------------------------------------------------
1933
Glenn Kasten40bc9062015-03-20 09:09:33 -07001934} // namespace android