blob: 1bce16f9b64839b406fa496aa6eacfaa39aa2ae4 [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,
François Gaffied0ba9ed2018-11-05 11:50:42 +010095 GET_OFFLOAD_FORMATS_A2DP,
96 LIST_AUDIO_PRODUCT_STRATEGIES,
97 GET_STRATEGY_FOR_ATTRIBUTES,
Eric Laurentc2f1f072009-07-17 12:17:14 -070098};
99
Eric Laurent1d670b12015-02-06 10:44:24 -0800100#define MAX_ITEMS_PER_LIST 1024
101
Eric Laurentc2f1f072009-07-17 12:17:14 -0700102class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
103{
104public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700105 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700106 : BpInterface<IAudioPolicyService>(impl)
107 {
108 }
109
110 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700111 audio_devices_t device,
112 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800113 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800114 const char *device_name,
115 audio_format_t encodedFormat)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700116 {
117 Parcel data, reply;
118 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
119 data.writeInt32(static_cast <uint32_t>(device));
120 data.writeInt32(static_cast <uint32_t>(state));
121 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800122 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800123 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700124 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
125 return static_cast <status_t> (reply.readInt32());
126 }
127
Dima Zavinfce7a472011-04-19 22:30:36 -0700128 virtual audio_policy_dev_state_t getDeviceConnectionState(
129 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 const char *device_address)
131 {
132 Parcel data, reply;
133 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
134 data.writeInt32(static_cast <uint32_t>(device));
135 data.writeCString(device_address);
136 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700137 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700138 }
139
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800140 virtual status_t handleDeviceConfigChange(audio_devices_t device,
141 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800142 const char *device_name,
143 audio_format_t encodedFormat)
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800144 {
145 Parcel data, reply;
146 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
147 data.writeInt32(static_cast <uint32_t>(device));
148 data.writeCString(device_address);
149 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800150 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800151 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
152 return static_cast <status_t> (reply.readInt32());
153 }
154
Glenn Kastenf78aee72012-01-04 11:00:47 -0800155 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700156 {
157 Parcel data, reply;
158 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
159 data.writeInt32(state);
160 remote()->transact(SET_PHONE_STATE, data, &reply);
161 return static_cast <status_t> (reply.readInt32());
162 }
163
Dima Zavinfce7a472011-04-19 22:30:36 -0700164 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700165 {
166 Parcel data, reply;
167 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
168 data.writeInt32(static_cast <uint32_t>(usage));
169 data.writeInt32(static_cast <uint32_t>(config));
170 remote()->transact(SET_FORCE_USE, data, &reply);
171 return static_cast <status_t> (reply.readInt32());
172 }
173
Dima Zavinfce7a472011-04-19 22:30:36 -0700174 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700175 {
176 Parcel data, reply;
177 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
178 data.writeInt32(static_cast <uint32_t>(usage));
179 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700180 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700181 }
182
Eric Laurentf4e63452017-11-06 19:31:46 +0000183 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
187 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700188 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700189 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700190 }
191
Kevin Rocard153f92d2018-12-18 18:33:28 -0800192 status_t getOutputForAttr(const audio_attributes_t *attr,
193 audio_io_handle_t *output,
194 audio_session_t session,
195 audio_stream_type_t *stream,
196 pid_t pid,
197 uid_t uid,
198 const audio_config_t *config,
199 audio_output_flags_t flags,
200 audio_port_handle_t *selectedDeviceId,
201 audio_port_handle_t *portId,
202 std::vector<audio_io_handle_t> *secondaryOutputs) override
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700203 {
204 Parcel data, reply;
205 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
206 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800207 if (stream == NULL) {
208 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
209 return BAD_VALUE;
210 }
211 if (*stream == AUDIO_STREAM_DEFAULT) {
212 ALOGE("getOutputForAttr unspecified stream type");
213 return BAD_VALUE;
214 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700215 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800216 if (output == NULL) {
217 ALOGE("getOutputForAttr NULL output - shouldn't happen");
218 return BAD_VALUE;
219 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700220 if (selectedDeviceId == NULL) {
221 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
222 return BAD_VALUE;
223 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800224 if (portId == NULL) {
225 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
226 return BAD_VALUE;
227 }
Kevin Rocard153f92d2018-12-18 18:33:28 -0800228 if (secondaryOutputs == NULL) {
229 ALOGE("getOutputForAttr NULL secondaryOutputs - shouldn't happen");
230 return BAD_VALUE;
231 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800232 if (attr == NULL) {
233 data.writeInt32(0);
234 } else {
235 data.writeInt32(1);
236 data.write(attr, sizeof(audio_attributes_t));
237 }
238 data.writeInt32(session);
239 if (stream == NULL) {
240 data.writeInt32(0);
241 } else {
242 data.writeInt32(1);
243 data.writeInt32(*stream);
244 }
Nadav Bar766fb022018-01-07 12:18:03 +0200245 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700246 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800247 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700248 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700249 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
252 if (status != NO_ERROR) {
253 return status;
254 }
255 status = (status_t)reply.readInt32();
256 if (status != NO_ERROR) {
257 return status;
258 }
259 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800260 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800261 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800262 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800263 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700264 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800265 *portId = (audio_port_handle_t)reply.readInt32();
Kevin Rocard153f92d2018-12-18 18:33:28 -0800266 secondaryOutputs->resize(reply.readInt32());
267 return reply.read(secondaryOutputs->data(),
268 secondaryOutputs->size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700269 }
270
Eric Laurentd7fe0862018-07-14 16:48:01 -0700271 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700275 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 remote()->transact(START_OUTPUT, data, &reply);
277 return static_cast <status_t> (reply.readInt32());
278 }
279
Eric Laurentd7fe0862018-07-14 16:48:01 -0700280 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700284 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 remote()->transact(STOP_OUTPUT, data, &reply);
286 return static_cast <status_t> (reply.readInt32());
287 }
288
Eric Laurentd7fe0862018-07-14 16:48:01 -0700289 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700293 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700294 remote()->transact(RELEASE_OUTPUT, data, &reply);
295 }
296
Eric Laurentcaf7f482014-11-25 17:50:47 -0800297 virtual status_t getInputForAttr(const audio_attributes_t *attr,
298 audio_io_handle_t *input,
299 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700300 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700301 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800302 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800303 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600304 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700305 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800306 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700307 {
308 Parcel data, reply;
309 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800310 if (attr == NULL) {
311 ALOGE("getInputForAttr NULL attr - shouldn't happen");
312 return BAD_VALUE;
313 }
314 if (input == NULL) {
315 ALOGE("getInputForAttr NULL input - shouldn't happen");
316 return BAD_VALUE;
317 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700318 if (selectedDeviceId == NULL) {
319 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
320 return BAD_VALUE;
321 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800322 if (portId == NULL) {
323 ALOGE("getInputForAttr NULL portId - shouldn't happen");
324 return BAD_VALUE;
325 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800326 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700327 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800328 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700329 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700330 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800331 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800332 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700333 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700334 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800335 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800336 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
337 if (status != NO_ERROR) {
338 return status;
339 }
340 status = reply.readInt32();
341 if (status != NO_ERROR) {
342 return status;
343 }
344 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700345 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800346 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800347 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700348 }
349
Eric Laurent4eb58f12018-12-07 16:41:02 -0800350 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 {
352 Parcel data, reply;
353 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800354 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800356 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800357 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700358 }
359
Eric Laurentfee19762018-01-29 18:44:13 -0800360 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800364 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 remote()->transact(STOP_INPUT, data, &reply);
366 return static_cast <status_t> (reply.readInt32());
367 }
368
Eric Laurentfee19762018-01-29 18:44:13 -0800369 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700370 {
371 Parcel data, reply;
372 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800373 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 remote()->transact(RELEASE_INPUT, data, &reply);
375 }
376
Dima Zavinfce7a472011-04-19 22:30:36 -0700377 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 int indexMin,
379 int indexMax)
380 {
381 Parcel data, reply;
382 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
383 data.writeInt32(static_cast <uint32_t>(stream));
384 data.writeInt32(indexMin);
385 data.writeInt32(indexMax);
386 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
387 return static_cast <status_t> (reply.readInt32());
388 }
389
Eric Laurent83844cc2011-11-18 16:43:31 -0800390 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
391 int index,
392 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700393 {
394 Parcel data, reply;
395 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
396 data.writeInt32(static_cast <uint32_t>(stream));
397 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800398 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700399 remote()->transact(SET_STREAM_VOLUME, data, &reply);
400 return static_cast <status_t> (reply.readInt32());
401 }
402
Eric Laurent83844cc2011-11-18 16:43:31 -0800403 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
404 int *index,
405 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700406 {
407 Parcel data, reply;
408 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
409 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800410 data.writeInt32(static_cast <uint32_t>(device));
411
Eric Laurentc2f1f072009-07-17 12:17:14 -0700412 remote()->transact(GET_STREAM_VOLUME, data, &reply);
413 int lIndex = reply.readInt32();
414 if (index) *index = lIndex;
415 return static_cast <status_t> (reply.readInt32());
416 }
Eric Laurentde070132010-07-13 04:45:46 -0700417
Dima Zavinfce7a472011-04-19 22:30:36 -0700418 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
422 data.writeInt32(static_cast <uint32_t>(stream));
423 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
François Gaffiec005e562018-11-06 15:04:49 +0100424 return reply.readUint32();
Eric Laurentde070132010-07-13 04:45:46 -0700425 }
426
Eric Laurent63742522012-03-08 13:42:42 -0800427 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800428 {
429 Parcel data, reply;
430 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
431 data.writeInt32(static_cast <uint32_t>(stream));
432 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800433 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800434 }
435
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700436 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700437 {
438 Parcel data, reply;
439 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
440 data.write(desc, sizeof(effect_descriptor_t));
441 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
442 return static_cast <audio_io_handle_t> (reply.readInt32());
443 }
444
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700445 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700446 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700447 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800448 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700449 int id)
450 {
451 Parcel data, reply;
452 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
453 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700454 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700455 data.writeInt32(strategy);
456 data.writeInt32(session);
457 data.writeInt32(id);
458 remote()->transact(REGISTER_EFFECT, data, &reply);
459 return static_cast <status_t> (reply.readInt32());
460 }
461
462 virtual status_t unregisterEffect(int id)
463 {
464 Parcel data, reply;
465 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
466 data.writeInt32(id);
467 remote()->transact(UNREGISTER_EFFECT, data, &reply);
468 return static_cast <status_t> (reply.readInt32());
469 }
470
Eric Laurentdb7c0792011-08-10 10:37:50 -0700471 virtual status_t setEffectEnabled(int id, bool enabled)
472 {
473 Parcel data, reply;
474 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
475 data.writeInt32(id);
476 data.writeInt32(enabled);
477 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
478 return static_cast <status_t> (reply.readInt32());
479 }
480
Glenn Kastenfff6d712012-01-12 16:38:12 -0800481 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800482 {
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800485 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800486 data.writeInt32(inPastMs);
487 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
488 return reply.readInt32();
489 }
Eric Laurent57dae992011-07-24 13:36:09 -0700490
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800491 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
492 {
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
495 data.writeInt32((int32_t) stream);
496 data.writeInt32(inPastMs);
497 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
498 return reply.readInt32();
499 }
500
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700501 virtual bool isSourceActive(audio_source_t source) const
502 {
503 Parcel data, reply;
504 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
505 data.writeInt32((int32_t) source);
506 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
507 return reply.readInt32();
508 }
509
Glenn Kastend848eb42016-03-08 13:42:11 -0800510 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700511 effect_descriptor_t *descriptors,
512 uint32_t *count)
513 {
514 if (descriptors == NULL || count == NULL) {
515 return BAD_VALUE;
516 }
517 Parcel data, reply;
518 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
519 data.writeInt32(audioSession);
520 data.writeInt32(*count);
521 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
522 if (status != NO_ERROR) {
523 return status;
524 }
525 status = static_cast <status_t> (reply.readInt32());
526 uint32_t retCount = reply.readInt32();
527 if (retCount != 0) {
528 uint32_t numDesc = (retCount < *count) ? retCount : *count;
529 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
530 }
531 *count = retCount;
532 return status;
533 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000534
535 virtual bool isOffloadSupported(const audio_offload_info_t& info)
536 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100537 Parcel data, reply;
538 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
539 data.write(&info, sizeof(audio_offload_info_t));
540 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700541 return reply.readInt32();
542 }
543
Michael Chana94fbb22018-04-24 14:31:19 +1000544 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
545 const audio_attributes_t& attributes) {
546 Parcel data, reply;
547 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
548 data.write(&config, sizeof(audio_config_base_t));
549 data.write(&attributes, sizeof(audio_attributes_t));
550 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
551 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
552 }
553
Eric Laurent203b1a12014-04-01 10:34:16 -0700554 virtual status_t listAudioPorts(audio_port_role_t role,
555 audio_port_type_t type,
556 unsigned int *num_ports,
557 struct audio_port *ports,
558 unsigned int *generation)
559 {
560 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
561 generation == NULL) {
562 return BAD_VALUE;
563 }
564 Parcel data, reply;
565 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
566 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
567 data.writeInt32(role);
568 data.writeInt32(type);
569 data.writeInt32(numPortsReq);
570 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
571 if (status == NO_ERROR) {
572 status = (status_t)reply.readInt32();
573 *num_ports = (unsigned int)reply.readInt32();
574 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700575 if (status == NO_ERROR) {
576 if (numPortsReq > *num_ports) {
577 numPortsReq = *num_ports;
578 }
579 if (numPortsReq > 0) {
580 reply.read(ports, numPortsReq * sizeof(struct audio_port));
581 }
582 *generation = reply.readInt32();
583 }
584 return status;
585 }
586
587 virtual status_t getAudioPort(struct audio_port *port)
588 {
589 if (port == NULL) {
590 return BAD_VALUE;
591 }
592 Parcel data, reply;
593 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
594 data.write(port, sizeof(struct audio_port));
595 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
596 if (status != NO_ERROR ||
597 (status = (status_t)reply.readInt32()) != NO_ERROR) {
598 return status;
599 }
600 reply.read(port, sizeof(struct audio_port));
601 return status;
602 }
603
604 virtual status_t createAudioPatch(const struct audio_patch *patch,
605 audio_patch_handle_t *handle)
606 {
607 if (patch == NULL || handle == NULL) {
608 return BAD_VALUE;
609 }
610 Parcel data, reply;
611 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
612 data.write(patch, sizeof(struct audio_patch));
613 data.write(handle, sizeof(audio_patch_handle_t));
614 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
615 if (status != NO_ERROR ||
616 (status = (status_t)reply.readInt32()) != NO_ERROR) {
617 return status;
618 }
619 reply.read(handle, sizeof(audio_patch_handle_t));
620 return status;
621 }
622
623 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
624 {
625 Parcel data, reply;
626 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
627 data.write(&handle, sizeof(audio_patch_handle_t));
628 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
629 if (status != NO_ERROR) {
630 status = (status_t)reply.readInt32();
631 }
632 return status;
633 }
634
635 virtual status_t listAudioPatches(unsigned int *num_patches,
636 struct audio_patch *patches,
637 unsigned int *generation)
638 {
639 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
640 generation == NULL) {
641 return BAD_VALUE;
642 }
643 Parcel data, reply;
644 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
645 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
646 data.writeInt32(numPatchesReq);
647 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
648 if (status == NO_ERROR) {
649 status = (status_t)reply.readInt32();
650 *num_patches = (unsigned int)reply.readInt32();
651 }
652 if (status == NO_ERROR) {
653 if (numPatchesReq > *num_patches) {
654 numPatchesReq = *num_patches;
655 }
656 if (numPatchesReq > 0) {
657 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
658 }
659 *generation = reply.readInt32();
660 }
661 return status;
662 }
663
664 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
665 {
666 if (config == NULL) {
667 return BAD_VALUE;
668 }
669 Parcel data, reply;
670 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
671 data.write(config, sizeof(struct audio_port_config));
672 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
673 if (status != NO_ERROR) {
674 status = (status_t)reply.readInt32();
675 }
676 return status;
677 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700678
Eric Laurentb52c1522014-05-20 11:27:36 -0700679 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
680 {
681 Parcel data, reply;
682 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800683 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700684 remote()->transact(REGISTER_CLIENT, data, &reply);
685 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700686
Eric Laurente8726fe2015-06-26 09:39:24 -0700687 virtual void setAudioPortCallbacksEnabled(bool enabled)
688 {
689 Parcel data, reply;
690 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
691 data.writeInt32(enabled ? 1 : 0);
692 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
693 }
694
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700695 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
696 audio_io_handle_t *ioHandle,
697 audio_devices_t *device)
698 {
699 if (session == NULL || ioHandle == NULL || device == NULL) {
700 return BAD_VALUE;
701 }
702 Parcel data, reply;
703 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
704 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
705 if (status != NO_ERROR) {
706 return status;
707 }
708 status = (status_t)reply.readInt32();
709 if (status == NO_ERROR) {
710 *session = (audio_session_t)reply.readInt32();
711 *ioHandle = (audio_io_handle_t)reply.readInt32();
712 *device = (audio_devices_t)reply.readInt32();
713 }
714 return status;
715 }
716
717 virtual status_t releaseSoundTriggerSession(audio_session_t session)
718 {
719 Parcel data, reply;
720 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
721 data.writeInt32(session);
722 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
723 if (status != NO_ERROR) {
724 return status;
725 }
726 return (status_t)reply.readInt32();
727 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700728
729 virtual audio_mode_t getPhoneState()
730 {
731 Parcel data, reply;
732 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
733 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
734 if (status != NO_ERROR) {
735 return AUDIO_MODE_INVALID;
736 }
737 return (audio_mode_t)reply.readInt32();
738 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800739
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700740 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800741 {
742 Parcel data, reply;
743 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
744 data.writeInt32(registration ? 1 : 0);
745 size_t size = mixes.size();
746 if (size > MAX_MIXES_PER_POLICY) {
747 size = MAX_MIXES_PER_POLICY;
748 }
749 size_t sizePosition = data.dataPosition();
750 data.writeInt32(size);
751 size_t finalSize = size;
752 for (size_t i = 0; i < size; i++) {
753 size_t position = data.dataPosition();
754 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
755 data.setDataPosition(position);
756 finalSize--;
757 }
758 }
759 if (size != finalSize) {
760 size_t position = data.dataPosition();
761 data.setDataPosition(sizePosition);
762 data.writeInt32(finalSize);
763 data.setDataPosition(position);
764 }
765 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
766 if (status == NO_ERROR) {
767 status = (status_t)reply.readInt32();
768 }
769 return status;
770 }
Eric Laurent554a2772015-04-10 11:29:24 -0700771
772 virtual status_t startAudioSource(const struct audio_port_config *source,
773 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700774 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700775 {
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700778 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700779 return BAD_VALUE;
780 }
781 data.write(source, sizeof(struct audio_port_config));
782 data.write(attributes, sizeof(audio_attributes_t));
783 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
784 if (status != NO_ERROR) {
785 return status;
786 }
787 status = (status_t)reply.readInt32();
788 if (status != NO_ERROR) {
789 return status;
790 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700791 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700792 return status;
793 }
794
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700795 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700796 {
797 Parcel data, reply;
798 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700799 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700800 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
801 if (status != NO_ERROR) {
802 return status;
803 }
804 status = (status_t)reply.readInt32();
805 return status;
806 }
Andy Hung2ddee192015-12-18 17:34:44 -0800807
808 virtual status_t setMasterMono(bool mono)
809 {
810 Parcel data, reply;
811 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
812 data.writeInt32(static_cast<int32_t>(mono));
813 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
814 if (status != NO_ERROR) {
815 return status;
816 }
817 return static_cast<status_t>(reply.readInt32());
818 }
819
820 virtual status_t getMasterMono(bool *mono)
821 {
822 if (mono == nullptr) {
823 return BAD_VALUE;
824 }
825 Parcel data, reply;
826 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
827
828 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
829 if (status != NO_ERROR) {
830 return status;
831 }
832 status = static_cast<status_t>(reply.readInt32());
833 if (status == NO_ERROR) {
834 *mono = static_cast<bool>(reply.readInt32());
835 }
836 return status;
837 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700838
839 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
840 {
841 Parcel data, reply;
842 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
843 data.writeInt32(static_cast <int32_t>(stream));
844 data.writeInt32(static_cast <int32_t>(index));
845 data.writeUint32(static_cast <uint32_t>(device));
846 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
847 if (status != NO_ERROR) {
848 return NAN;
849 }
850 return reply.readFloat();
851 }
jiabin81772902018-04-02 17:52:27 -0700852
853 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
854 audio_format_t *surroundFormats,
855 bool *surroundFormatsEnabled,
856 bool reported)
857 {
858 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
859 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
860 return BAD_VALUE;
861 }
862 Parcel data, reply;
863 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
864 unsigned int numSurroundFormatsReq = *numSurroundFormats;
865 data.writeUint32(numSurroundFormatsReq);
866 data.writeBool(reported);
867 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
868 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
869 *numSurroundFormats = reply.readUint32();
870 }
871 if (status == NO_ERROR) {
872 if (numSurroundFormatsReq > *numSurroundFormats) {
873 numSurroundFormatsReq = *numSurroundFormats;
874 }
875 if (numSurroundFormatsReq > 0) {
876 status = reply.read(surroundFormats,
877 numSurroundFormatsReq * sizeof(audio_format_t));
878 if (status != NO_ERROR) {
879 return status;
880 }
881 status = reply.read(surroundFormatsEnabled,
882 numSurroundFormatsReq * sizeof(bool));
883 }
884 }
885 return status;
886 }
887
888 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
889 {
890 Parcel data, reply;
891 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
892 data.writeInt32(audioFormat);
893 data.writeBool(enabled);
894 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
895 if (status != NO_ERROR) {
896 return status;
897 }
898 return reply.readInt32();
899 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700900
Arun Mirpuri11029ad2018-12-19 20:45:19 -0800901 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
902 std::vector<audio_format_t> *formats)
903 {
904 if (formats == NULL) {
905 return BAD_VALUE;
906 }
907
908 Parcel data, reply;
909 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
910 status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
911 if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
912 return status;
913 }
914
915 size_t list_size = reply.readUint32();
916
917 for (size_t i = 0; i < list_size; i++) {
918 formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
919 }
920 return NO_ERROR;
921 }
922
923
924 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700925 const String16& opPackageName,
926 const effect_uuid_t *uuid,
927 int32_t priority,
928 audio_usage_t usage,
929 audio_unique_id_t* id)
930 {
931 Parcel data, reply;
932 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
933 data.write(type, sizeof(effect_uuid_t));
934 data.writeString16(opPackageName);
935 data.write(uuid, sizeof(effect_uuid_t));
936 data.writeInt32(priority);
937 data.writeInt32((int32_t) usage);
938 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
939 if (status != NO_ERROR) {
940 return status;
941 }
942 status = static_cast <status_t> (reply.readInt32());
943 *id = reply.readInt32();
944 return status;
945 }
946
947 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
948 {
949 Parcel data, reply;
950 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
951 data.writeInt32(id);
952 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
953 if (status != NO_ERROR) {
954 return status;
955 }
956 return static_cast <status_t> (reply.readInt32());
957 }
958
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700959 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
960 const String16& opPackageName,
961 const effect_uuid_t *uuid,
962 int32_t priority,
963 audio_source_t source,
964 audio_unique_id_t* id)
965 {
966 Parcel data, reply;
967 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
968 data.write(type, sizeof(effect_uuid_t));
969 data.writeString16(opPackageName);
970 data.write(uuid, sizeof(effect_uuid_t));
971 data.writeInt32(priority);
972 data.writeInt32((int32_t) source);
973 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
974 if (status != NO_ERROR) {
975 return status;
976 }
977 status = static_cast <status_t> (reply.readInt32());
978 *id = reply.readInt32();
979 return status;
980 }
981
982 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
983 {
984 Parcel data, reply;
985 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
986 data.writeInt32(id);
987 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
988 if (status != NO_ERROR) {
989 return status;
990 }
991 return static_cast <status_t> (reply.readInt32());
992 }
993
Eric Laurentb78763e2018-10-17 10:08:02 -0700994 virtual status_t setAssistantUid(uid_t uid)
995 {
996 Parcel data, reply;
997 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
998 data.writeInt32(uid);
999 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
1000 if (status != NO_ERROR) {
1001 return status;
1002 }
1003 return static_cast <status_t> (reply.readInt32());
1004 }
1005
1006 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
1007 {
1008 Parcel data, reply;
1009 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1010 data.writeInt32(uids.size());
1011 for (auto uid : uids) {
1012 data.writeInt32(uid);
1013 }
1014 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
1015 if (status != NO_ERROR) {
1016 return status;
1017 }
1018 return static_cast <status_t> (reply.readInt32());
1019 }
1020
jiabin6012f912018-11-02 17:06:30 -07001021 virtual bool isHapticPlaybackSupported()
1022 {
1023 Parcel data, reply;
1024 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1025 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
1026 if (status != NO_ERROR) {
1027 return false;
1028 }
1029 return reply.readBool();
1030 }
1031
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001032 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
1033 {
1034 Parcel data, reply;
1035 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1036
1037 data.writeInt32((int32_t) uid);
1038 size_t size = devices.size();
1039 size_t sizePosition = data.dataPosition();
1040 data.writeInt32((int32_t) size);
1041 size_t finalSize = size;
1042 for (size_t i = 0; i < size; i++) {
1043 size_t position = data.dataPosition();
1044 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1045 data.setDataPosition(position);
1046 finalSize--;
1047 }
1048 }
1049 if (size != finalSize) {
1050 size_t position = data.dataPosition();
1051 data.setDataPosition(sizePosition);
1052 data.writeInt32(finalSize);
1053 data.setDataPosition(position);
1054 }
1055
1056 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1057 if (status == NO_ERROR) {
1058 status = (status_t)reply.readInt32();
1059 }
1060 return status;
1061 }
1062
François Gaffied0ba9ed2018-11-05 11:50:42 +01001063 virtual status_t removeUidDeviceAffinities(uid_t uid) {
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001064 Parcel data, reply;
1065 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1066
1067 data.writeInt32((int32_t) uid);
1068
François Gaffied0ba9ed2018-11-05 11:50:42 +01001069 status_t status =
1070 remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001071 if (status == NO_ERROR) {
François Gaffied0ba9ed2018-11-05 11:50:42 +01001072 status = (status_t) reply.readInt32();
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001073 }
1074 return status;
1075 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01001076
1077 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
1078 {
1079 Parcel data, reply;
1080 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1081
1082 status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
1083 if (status != NO_ERROR) {
1084 ALOGE("%s: permission denied", __func__);
1085 return status;
1086 }
1087 status = static_cast<status_t>(reply.readInt32());
1088 if (status == NO_ERROR) {
1089 uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
1090 for (size_t i = 0; i < numStrategies; i++) {
1091 AudioProductStrategy strategy;
1092 status = strategy.readFromParcel(&reply);
1093 if (status != NO_ERROR) {
1094 ALOGE("%s: failed to read strategies", __FUNCTION__);
1095 strategies.clear();
1096 return status;
1097 }
1098 strategies.push_back(strategy);
1099 }
1100 }
1101 return status;
1102 }
1103
1104 virtual product_strategy_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa)
1105 {
1106 Parcel data, reply;
1107 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1108 status_t status = aa.writeToParcel(&data);
1109 if (status != NO_ERROR) {
1110 return PRODUCT_STRATEGY_NONE;
1111 }
1112 status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
1113 if (status == NO_ERROR) {
1114 return static_cast<product_strategy_t>(reply.readInt32());
1115 }
1116 return PRODUCT_STRATEGY_NONE;
1117 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001118};
1119
1120IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1121
1122// ----------------------------------------------------------------------
1123
Eric Laurentc2f1f072009-07-17 12:17:14 -07001124status_t BnAudioPolicyService::onTransact(
1125 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1126{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001127 // make sure transactions reserved to AudioFlinger do not come from other processes
1128 switch (code) {
1129 case START_OUTPUT:
1130 case STOP_OUTPUT:
1131 case RELEASE_OUTPUT:
1132 case GET_INPUT_FOR_ATTR:
1133 case START_INPUT:
1134 case STOP_INPUT:
1135 case RELEASE_INPUT:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001136 case GET_OUTPUT_FOR_EFFECT:
1137 case REGISTER_EFFECT:
1138 case UNREGISTER_EFFECT:
1139 case SET_EFFECT_ENABLED:
1140 case GET_OUTPUT_FOR_ATTR:
1141 case ACQUIRE_SOUNDTRIGGER_SESSION:
1142 case RELEASE_SOUNDTRIGGER_SESSION:
1143 ALOGW("%s: transaction %d received from PID %d",
1144 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001145 // return status only for non void methods
1146 switch (code) {
1147 case RELEASE_OUTPUT:
1148 case RELEASE_INPUT:
1149 break;
1150 default:
1151 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1152 break;
1153 }
1154 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001155 default:
1156 break;
1157 }
1158
Eric Laurent4980df22018-01-26 18:04:09 -08001159 // make sure the following transactions come from system components
1160 switch (code) {
1161 case SET_DEVICE_CONNECTION_STATE:
1162 case HANDLE_DEVICE_CONFIG_CHANGE:
1163 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001164//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1165// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001166 case INIT_STREAM_VOLUME:
1167 case SET_STREAM_VOLUME:
1168 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001169 case SET_MASTER_MONO:
jiabin81772902018-04-02 17:52:27 -07001170 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001171 case SET_SURROUND_FORMAT_ENABLED:
1172 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001173 case SET_A11Y_SERVICES_UIDS:
1174 case SET_UID_DEVICE_AFFINITY:
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001175 case REMOVE_UID_DEVICE_AFFINITY:
1176 case GET_OFFLOAD_FORMATS_A2DP: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001177 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001178 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1179 __func__, code, IPCThreadState::self()->getCallingPid(),
1180 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001181 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1182 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001183 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001184 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001185 default:
1186 break;
1187 }
1188
Eric Laurent39b09b52018-06-29 12:24:40 -07001189 std::string tag("IAudioPolicyService command " + std::to_string(code));
1190 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001191
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001192 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001193 case SET_DEVICE_CONNECTION_STATE: {
1194 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001195 audio_devices_t device =
1196 static_cast <audio_devices_t>(data.readInt32());
1197 audio_policy_dev_state_t state =
1198 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001199 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001200 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001201 audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001202 if (device_address == nullptr || device_name == nullptr) {
1203 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1204 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1205 } else {
1206 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1207 state,
1208 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001209 device_name,
1210 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001211 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001212 return NO_ERROR;
1213 } break;
1214
1215 case GET_DEVICE_CONNECTION_STATE: {
1216 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001217 audio_devices_t device =
1218 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001219 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001220 if (device_address == nullptr) {
1221 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1222 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1223 } else {
1224 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1225 device_address)));
1226 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001227 return NO_ERROR;
1228 } break;
1229
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001230 case HANDLE_DEVICE_CONFIG_CHANGE: {
1231 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1232 audio_devices_t device =
1233 static_cast <audio_devices_t>(data.readInt32());
1234 const char *device_address = data.readCString();
1235 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001236 audio_format_t codecFormat =
1237 static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001238 if (device_address == nullptr || device_name == nullptr) {
1239 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1240 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1241 } else {
1242 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1243 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001244 device_name,
1245 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001246 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001247 return NO_ERROR;
1248 } break;
1249
Eric Laurentc2f1f072009-07-17 12:17:14 -07001250 case SET_PHONE_STATE: {
1251 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001252 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1253 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001254 return NO_ERROR;
1255 } break;
1256
Eric Laurentc2f1f072009-07-17 12:17:14 -07001257 case SET_FORCE_USE: {
1258 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001259 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1260 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001261 audio_policy_forced_cfg_t config =
1262 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001263 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1264 return NO_ERROR;
1265 } break;
1266
1267 case GET_FORCE_USE: {
1268 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001269 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1270 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001271 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1272 return NO_ERROR;
1273 } break;
1274
1275 case GET_OUTPUT: {
1276 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001277 audio_stream_type_t stream =
1278 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001279 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001280 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001281 return NO_ERROR;
1282 } break;
1283
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001284 case GET_OUTPUT_FOR_ATTR: {
1285 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001286 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001287 bool hasAttributes = data.readInt32() != 0;
1288 if (hasAttributes) {
1289 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001290 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001291 }
1292 audio_session_t session = (audio_session_t)data.readInt32();
1293 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1294 bool hasStream = data.readInt32() != 0;
1295 if (hasStream) {
1296 stream = (audio_stream_type_t)data.readInt32();
1297 }
Nadav Bar766fb022018-01-07 12:18:03 +02001298 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001299 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001300 audio_config_t config;
1301 memset(&config, 0, sizeof(audio_config_t));
1302 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001303 audio_output_flags_t flags =
1304 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001305 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001306 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001307 audio_io_handle_t output = 0;
Kevin Rocard153f92d2018-12-18 18:33:28 -08001308 std::vector<audio_io_handle_t> secondaryOutputs;
Eric Laurente83b55d2014-11-14 10:06:21 -08001309 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001310 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001311 &config,
Kevin Rocard153f92d2018-12-18 18:33:28 -08001312 flags, &selectedDeviceId, &portId, &secondaryOutputs);
Eric Laurente83b55d2014-11-14 10:06:21 -08001313 reply->writeInt32(status);
1314 reply->writeInt32(output);
1315 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001316 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001317 reply->writeInt32(portId);
Kevin Rocard153f92d2018-12-18 18:33:28 -08001318 reply->writeInt32(secondaryOutputs.size());
1319 return reply->write(secondaryOutputs.data(),
1320 secondaryOutputs.size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001321 } break;
1322
Eric Laurentc2f1f072009-07-17 12:17:14 -07001323 case START_OUTPUT: {
1324 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001325 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1326 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001327 return NO_ERROR;
1328 } break;
1329
1330 case STOP_OUTPUT: {
1331 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001332 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1333 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001334 return NO_ERROR;
1335 } break;
1336
1337 case RELEASE_OUTPUT: {
1338 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001339 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1340 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001341 return NO_ERROR;
1342 } break;
1343
Eric Laurentcaf7f482014-11-25 17:50:47 -08001344 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001345 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001346 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001347 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001348 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001349 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001350 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001351 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001352 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001353 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001354 audio_config_base_t config;
1355 memset(&config, 0, sizeof(audio_config_base_t));
1356 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001357 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001358 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001359 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001360 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001361 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001362 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001363 reply->writeInt32(status);
1364 if (status == NO_ERROR) {
1365 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001366 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001367 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001368 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001369 return NO_ERROR;
1370 } break;
1371
1372 case START_INPUT: {
1373 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001374 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001375 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001376 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001377 return NO_ERROR;
1378 } break;
1379
1380 case STOP_INPUT: {
1381 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001382 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1383 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001384 return NO_ERROR;
1385 } break;
1386
1387 case RELEASE_INPUT: {
1388 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001389 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1390 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001391 return NO_ERROR;
1392 } break;
1393
1394 case INIT_STREAM_VOLUME: {
1395 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001396 audio_stream_type_t stream =
1397 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001398 int indexMin = data.readInt32();
1399 int indexMax = data.readInt32();
1400 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1401 return NO_ERROR;
1402 } break;
1403
1404 case SET_STREAM_VOLUME: {
1405 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001406 audio_stream_type_t stream =
1407 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001408 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001409 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1410 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1411 index,
1412 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001413 return NO_ERROR;
1414 } break;
1415
1416 case GET_STREAM_VOLUME: {
1417 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001418 audio_stream_type_t stream =
1419 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001420 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001421 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001422 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001423 reply->writeInt32(index);
1424 reply->writeInt32(static_cast <uint32_t>(status));
1425 return NO_ERROR;
1426 } break;
1427
Eric Laurentde070132010-07-13 04:45:46 -07001428 case GET_STRATEGY_FOR_STREAM: {
1429 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001430 audio_stream_type_t stream =
1431 static_cast <audio_stream_type_t>(data.readInt32());
François Gaffiec005e562018-11-06 15:04:49 +01001432 reply->writeUint32(getStrategyForStream(stream));
Eric Laurentde070132010-07-13 04:45:46 -07001433 return NO_ERROR;
1434 } break;
1435
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001436 case GET_DEVICES_FOR_STREAM: {
1437 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001438 audio_stream_type_t stream =
1439 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001440 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1441 return NO_ERROR;
1442 } break;
1443
Eric Laurentde070132010-07-13 04:45:46 -07001444 case GET_OUTPUT_FOR_EFFECT: {
1445 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001446 effect_descriptor_t desc = {};
1447 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1448 android_errorWriteLog(0x534e4554, "73126106");
1449 }
1450 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001451 audio_io_handle_t output = getOutputForEffect(&desc);
1452 reply->writeInt32(static_cast <int>(output));
1453 return NO_ERROR;
1454 } break;
1455
1456 case REGISTER_EFFECT: {
1457 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001458 effect_descriptor_t desc = {};
1459 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1460 android_errorWriteLog(0x534e4554, "73126106");
1461 }
1462 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001463 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001464 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001465 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001466 int id = data.readInt32();
1467 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001468 io,
Eric Laurentde070132010-07-13 04:45:46 -07001469 strategy,
1470 session,
1471 id)));
1472 return NO_ERROR;
1473 } break;
1474
1475 case UNREGISTER_EFFECT: {
1476 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1477 int id = data.readInt32();
1478 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1479 return NO_ERROR;
1480 } break;
1481
Eric Laurentdb7c0792011-08-10 10:37:50 -07001482 case SET_EFFECT_ENABLED: {
1483 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1484 int id = data.readInt32();
1485 bool enabled = static_cast <bool>(data.readInt32());
1486 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1487 return NO_ERROR;
1488 } break;
1489
Eric Laurenteda6c362011-02-02 09:33:30 -08001490 case IS_STREAM_ACTIVE: {
1491 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001492 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001493 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001494 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001495 return NO_ERROR;
1496 } break;
1497
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001498 case IS_STREAM_ACTIVE_REMOTELY: {
1499 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1500 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1501 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001502 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001503 return NO_ERROR;
1504 } break;
1505
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001506 case IS_SOURCE_ACTIVE: {
1507 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1508 audio_source_t source = (audio_source_t) data.readInt32();
1509 reply->writeInt32( isSourceActive(source));
1510 return NO_ERROR;
1511 }
1512
Eric Laurent57dae992011-07-24 13:36:09 -07001513 case QUERY_DEFAULT_PRE_PROCESSING: {
1514 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001515 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001516 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001517 if (count > AudioEffect::kMaxPreProcessing) {
1518 count = AudioEffect::kMaxPreProcessing;
1519 }
Eric Laurent57dae992011-07-24 13:36:09 -07001520 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001521 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001522 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1523 reply->writeInt32(status);
1524 if (status != NO_ERROR && status != NO_MEMORY) {
1525 retCount = 0;
1526 }
1527 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001528 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001529 if (retCount < count) {
1530 count = retCount;
1531 }
1532 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1533 }
1534 delete[] descriptors;
1535 return status;
1536 }
1537
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001538 case IS_OFFLOAD_SUPPORTED: {
1539 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001540 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001541 data.read(&info, sizeof(audio_offload_info_t));
1542 bool isSupported = isOffloadSupported(info);
1543 reply->writeInt32(isSupported);
1544 return NO_ERROR;
1545 }
1546
Michael Chana94fbb22018-04-24 14:31:19 +10001547 case IS_DIRECT_OUTPUT_SUPPORTED: {
1548 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1549 audio_config_base_t config = {};
1550 audio_attributes_t attributes = {};
1551 status_t status = data.read(&config, sizeof(audio_config_base_t));
1552 if (status != NO_ERROR) return status;
1553 status = data.read(&attributes, sizeof(audio_attributes_t));
1554 if (status != NO_ERROR) return status;
1555 reply->writeInt32(isDirectOutputSupported(config, attributes));
1556 return NO_ERROR;
1557 }
1558
Eric Laurent203b1a12014-04-01 10:34:16 -07001559 case LIST_AUDIO_PORTS: {
1560 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1561 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1562 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1563 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001564 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1565 numPortsReq = MAX_ITEMS_PER_LIST;
1566 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001567 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001568 struct audio_port *ports =
1569 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001570 if (ports == NULL) {
1571 reply->writeInt32(NO_MEMORY);
1572 reply->writeInt32(0);
1573 return NO_ERROR;
1574 }
1575 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001576 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1577 reply->writeInt32(status);
1578 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001579
1580 if (status == NO_ERROR) {
1581 if (numPortsReq > numPorts) {
1582 numPortsReq = numPorts;
1583 }
1584 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1585 reply->writeInt32(generation);
1586 }
1587 free(ports);
1588 return NO_ERROR;
1589 }
1590
1591 case GET_AUDIO_PORT: {
1592 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001593 struct audio_port port = {};
1594 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1595 ALOGE("b/23912202");
1596 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001597 status_t status = getAudioPort(&port);
1598 reply->writeInt32(status);
1599 if (status == NO_ERROR) {
1600 reply->write(&port, sizeof(struct audio_port));
1601 }
1602 return NO_ERROR;
1603 }
1604
1605 case CREATE_AUDIO_PATCH: {
1606 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001607 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001608 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001609 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001610 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1611 ALOGE("b/23912202");
1612 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001613 status_t status = createAudioPatch(&patch, &handle);
1614 reply->writeInt32(status);
1615 if (status == NO_ERROR) {
1616 reply->write(&handle, sizeof(audio_patch_handle_t));
1617 }
1618 return NO_ERROR;
1619 }
1620
1621 case RELEASE_AUDIO_PATCH: {
1622 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001623 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001624 data.read(&handle, sizeof(audio_patch_handle_t));
1625 status_t status = releaseAudioPatch(handle);
1626 reply->writeInt32(status);
1627 return NO_ERROR;
1628 }
1629
1630 case LIST_AUDIO_PATCHES: {
1631 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1632 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001633 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1634 numPatchesReq = MAX_ITEMS_PER_LIST;
1635 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001636 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001637 struct audio_patch *patches =
1638 (struct audio_patch *)calloc(numPatchesReq,
1639 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001640 if (patches == NULL) {
1641 reply->writeInt32(NO_MEMORY);
1642 reply->writeInt32(0);
1643 return NO_ERROR;
1644 }
1645 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001646 status_t status = listAudioPatches(&numPatches, patches, &generation);
1647 reply->writeInt32(status);
1648 reply->writeInt32(numPatches);
1649 if (status == NO_ERROR) {
1650 if (numPatchesReq > numPatches) {
1651 numPatchesReq = numPatches;
1652 }
1653 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1654 reply->writeInt32(generation);
1655 }
1656 free(patches);
1657 return NO_ERROR;
1658 }
1659
1660 case SET_AUDIO_PORT_CONFIG: {
1661 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001662 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001663 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001664 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001665 status_t status = setAudioPortConfig(&config);
1666 reply->writeInt32(status);
1667 return NO_ERROR;
1668 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001669
Eric Laurentb52c1522014-05-20 11:27:36 -07001670 case REGISTER_CLIENT: {
1671 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1672 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1673 data.readStrongBinder());
1674 registerClient(client);
1675 return NO_ERROR;
1676 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001677
Eric Laurente8726fe2015-06-26 09:39:24 -07001678 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1679 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1680 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1681 return NO_ERROR;
1682 } break;
1683
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001684 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1685 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1686 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1687 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001688 audio_session_t session = AUDIO_SESSION_NONE;
1689 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1690 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001691 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1692 reply->writeInt32(status);
1693 if (status == NO_ERROR) {
1694 reply->writeInt32(session);
1695 reply->writeInt32(ioHandle);
1696 reply->writeInt32(device);
1697 }
1698 return NO_ERROR;
1699 } break;
1700
1701 case RELEASE_SOUNDTRIGGER_SESSION: {
1702 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1703 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1704 data.readStrongBinder());
1705 audio_session_t session = (audio_session_t)data.readInt32();
1706 status_t status = releaseSoundTriggerSession(session);
1707 reply->writeInt32(status);
1708 return NO_ERROR;
1709 } break;
1710
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001711 case GET_PHONE_STATE: {
1712 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1713 reply->writeInt32((int32_t)getPhoneState());
1714 return NO_ERROR;
1715 } break;
1716
Eric Laurentbaac1832014-12-01 17:52:59 -08001717 case REGISTER_POLICY_MIXES: {
1718 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1719 bool registration = data.readInt32() == 1;
1720 Vector<AudioMix> mixes;
1721 size_t size = (size_t)data.readInt32();
1722 if (size > MAX_MIXES_PER_POLICY) {
1723 size = MAX_MIXES_PER_POLICY;
1724 }
1725 for (size_t i = 0; i < size; i++) {
1726 AudioMix mix;
1727 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1728 mixes.add(mix);
1729 }
1730 }
1731 status_t status = registerPolicyMixes(mixes, registration);
1732 reply->writeInt32(status);
1733 return NO_ERROR;
1734 } break;
1735
Eric Laurent554a2772015-04-10 11:29:24 -07001736 case START_AUDIO_SOURCE: {
1737 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001738 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001739 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001740 (void)sanitizeAudioPortConfig(&source);
1741 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001742 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001743 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001744 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1745 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001746 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001747 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001748 return NO_ERROR;
1749 } break;
1750
1751 case STOP_AUDIO_SOURCE: {
1752 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001753 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1754 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001755 reply->writeInt32(status);
1756 return NO_ERROR;
1757 } break;
1758
Andy Hung2ddee192015-12-18 17:34:44 -08001759 case SET_MASTER_MONO: {
1760 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1761 bool mono = static_cast<bool>(data.readInt32());
1762 status_t status = setMasterMono(mono);
1763 reply->writeInt32(status);
1764 return NO_ERROR;
1765 } break;
1766
1767 case GET_MASTER_MONO: {
1768 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1769 bool mono;
1770 status_t status = getMasterMono(&mono);
1771 reply->writeInt32(status);
1772 if (status == NO_ERROR) {
1773 reply->writeInt32(static_cast<int32_t>(mono));
1774 }
1775 return NO_ERROR;
1776 } break;
1777
Eric Laurentac9cef52017-06-09 15:46:26 -07001778 case GET_STREAM_VOLUME_DB: {
1779 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1780 audio_stream_type_t stream =
1781 static_cast <audio_stream_type_t>(data.readInt32());
1782 int index = static_cast <int>(data.readInt32());
1783 audio_devices_t device =
1784 static_cast <audio_devices_t>(data.readUint32());
1785 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1786 return NO_ERROR;
1787 }
1788
jiabin81772902018-04-02 17:52:27 -07001789 case GET_SURROUND_FORMATS: {
1790 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1791 unsigned int numSurroundFormatsReq = data.readUint32();
1792 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1793 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1794 }
1795 bool reported = data.readBool();
1796 unsigned int numSurroundFormats = numSurroundFormatsReq;
1797 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1798 numSurroundFormats, sizeof(audio_format_t));
1799 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1800 if (numSurroundFormatsReq > 0 &&
1801 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1802 free(surroundFormats);
1803 free(surroundFormatsEnabled);
1804 reply->writeInt32(NO_MEMORY);
1805 return NO_ERROR;
1806 }
1807 status_t status = getSurroundFormats(
1808 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1809 reply->writeInt32(status);
1810
1811 if (status == NO_ERROR) {
1812 reply->writeUint32(numSurroundFormats);
1813 if (numSurroundFormatsReq > numSurroundFormats) {
1814 numSurroundFormatsReq = numSurroundFormats;
1815 }
1816 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1817 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1818 }
1819 free(surroundFormats);
1820 free(surroundFormatsEnabled);
1821 return NO_ERROR;
1822 }
1823
1824 case SET_SURROUND_FORMAT_ENABLED: {
1825 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1826 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1827 bool enabled = data.readBool();
1828 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1829 reply->writeInt32(status);
1830 return NO_ERROR;
1831 }
1832
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001833 case GET_OFFLOAD_FORMATS_A2DP: {
1834 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1835 std::vector<audio_format_t> encodingFormats;
1836 status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
1837 reply->writeInt32(status);
1838 if (status != NO_ERROR) {
1839 return NO_ERROR;
1840 }
1841 reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
1842 for (size_t i = 0; i < encodingFormats.size(); i++)
1843 reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
1844 return NO_ERROR;
1845 }
1846
1847
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001848 case ADD_STREAM_DEFAULT_EFFECT: {
1849 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1850 effect_uuid_t type;
1851 status_t status = data.read(&type, sizeof(effect_uuid_t));
1852 if (status != NO_ERROR) {
1853 return status;
1854 }
1855 String16 opPackageName;
1856 status = data.readString16(&opPackageName);
1857 if (status != NO_ERROR) {
1858 return status;
1859 }
1860 effect_uuid_t uuid;
1861 status = data.read(&uuid, sizeof(effect_uuid_t));
1862 if (status != NO_ERROR) {
1863 return status;
1864 }
1865 int32_t priority = data.readInt32();
1866 audio_usage_t usage = (audio_usage_t) data.readInt32();
1867 audio_unique_id_t id = 0;
1868 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1869 opPackageName,
1870 &uuid,
1871 priority,
1872 usage,
1873 &id)));
1874 reply->writeInt32(id);
1875 return NO_ERROR;
1876 }
1877
1878 case REMOVE_STREAM_DEFAULT_EFFECT: {
1879 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1880 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1881 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1882 return NO_ERROR;
1883 }
1884
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001885 case ADD_SOURCE_DEFAULT_EFFECT: {
1886 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1887 effect_uuid_t type;
1888 status_t status = data.read(&type, sizeof(effect_uuid_t));
1889 if (status != NO_ERROR) {
1890 return status;
1891 }
1892 String16 opPackageName;
1893 status = data.readString16(&opPackageName);
1894 if (status != NO_ERROR) {
1895 return status;
1896 }
1897 effect_uuid_t uuid;
1898 status = data.read(&uuid, sizeof(effect_uuid_t));
1899 if (status != NO_ERROR) {
1900 return status;
1901 }
1902 int32_t priority = data.readInt32();
1903 audio_source_t source = (audio_source_t) data.readInt32();
1904 audio_unique_id_t id = 0;
1905 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1906 opPackageName,
1907 &uuid,
1908 priority,
1909 source,
1910 &id)));
1911 reply->writeInt32(id);
1912 return NO_ERROR;
1913 }
1914
1915 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1916 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1917 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1918 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1919 return NO_ERROR;
1920 }
1921
Eric Laurentb78763e2018-10-17 10:08:02 -07001922 case SET_ASSISTANT_UID: {
1923 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1924 int32_t uid;
1925 status_t status = data.readInt32(&uid);
1926 if (status != NO_ERROR) {
1927 return status;
1928 }
1929 status = setAssistantUid(uid);
1930 reply->writeInt32(static_cast <int32_t>(status));
1931 return NO_ERROR;
1932 }
1933
1934 case SET_A11Y_SERVICES_UIDS: {
1935 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1936 std::vector<uid_t> uids;
1937 int32_t size;
1938 status_t status = data.readInt32(&size);
1939 if (status != NO_ERROR) {
1940 return status;
1941 }
1942 if (size > MAX_ITEMS_PER_LIST) {
1943 size = MAX_ITEMS_PER_LIST;
1944 }
1945 for (int32_t i = 0; i < size; i++) {
1946 int32_t uid;
1947 status = data.readInt32(&uid);
1948 if (status != NO_ERROR) {
1949 return status;
1950 }
1951 uids.push_back(uid);
1952 }
1953 status = setA11yServicesUids(uids);
1954 reply->writeInt32(static_cast <int32_t>(status));
1955 return NO_ERROR;
1956 }
1957
jiabin6012f912018-11-02 17:06:30 -07001958 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
1959 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1960 bool isSupported = isHapticPlaybackSupported();
1961 reply->writeBool(isSupported);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001962 return NO_ERROR;
1963 }
1964
1965 case SET_UID_DEVICE_AFFINITY: {
1966 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1967 const uid_t uid = (uid_t) data.readInt32();
1968 Vector<AudioDeviceTypeAddr> devices;
1969 size_t size = (size_t)data.readInt32();
1970 for (size_t i = 0; i < size; i++) {
1971 AudioDeviceTypeAddr device;
1972 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
1973 devices.add(device);
1974 }
1975 }
1976 status_t status = setUidDeviceAffinities(uid, devices);
1977 reply->writeInt32(status);
1978 return NO_ERROR;
1979 }
1980
1981 case REMOVE_UID_DEVICE_AFFINITY: {
1982 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1983 const uid_t uid = (uid_t) data.readInt32();
1984 status_t status = removeUidDeviceAffinities(uid);
1985 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07001986 return NO_ERROR;
1987 }
1988
François Gaffied0ba9ed2018-11-05 11:50:42 +01001989 case LIST_AUDIO_PRODUCT_STRATEGIES: {
1990 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1991 AudioProductStrategyVector strategies;
1992 status_t status = listAudioProductStrategies(strategies);
1993 reply->writeInt32(status);
1994 if (status != NO_ERROR) {
1995 return status;
1996 }
1997 size_t size = strategies.size();
1998 size_t sizePosition = reply->dataPosition();
1999 reply->writeInt32(size);
2000 size_t finalSize = size;
2001 for (size_t i = 0; i < size; i++) {
2002 size_t position = reply->dataPosition();
2003 if (strategies[i].writeToParcel(reply) != NO_ERROR) {
2004 reply->setDataPosition(position);
2005 finalSize--;
2006 }
2007 }
2008 if (size != finalSize) {
2009 size_t position = reply->dataPosition();
2010 reply->setDataPosition(sizePosition);
2011 reply->writeInt32(finalSize);
2012 reply->setDataPosition(position);
2013 }
2014 return NO_ERROR;
2015 }
2016
2017 case GET_STRATEGY_FOR_ATTRIBUTES: {
2018 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2019 AudioAttributes attributes;
2020 status_t status = attributes.readFromParcel(&data);
2021 if (status != NO_ERROR) {
2022 return status;
2023 }
2024 product_strategy_t strategy = getProductStrategyFromAudioAttributes(attributes);
2025 reply->writeUint32(static_cast<int>(strategy));
2026 return NO_ERROR;
2027 }
2028
Eric Laurentc2f1f072009-07-17 12:17:14 -07002029 default:
2030 return BBinder::onTransact(code, data, reply, flags);
2031 }
2032}
2033
Andy Hungb0272092018-04-12 11:06:56 -07002034/** returns true if string overflow was prevented by zero termination */
2035template <size_t size>
2036static bool preventStringOverflow(char (&s)[size]) {
2037 if (strnlen(s, size) < size) return false;
2038 s[size - 1] = '\0';
2039 return true;
2040}
2041
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002042void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
2043{
2044 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
2045 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
2046 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
2047 }
2048 attr->tags[tagsMaxSize - 1] = '\0';
2049}
2050
Andy Hungb0272092018-04-12 11:06:56 -07002051/** returns BAD_VALUE if sanitization was required. */
2052status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
2053{
2054 if (preventStringOverflow(desc->name)
2055 | /* always */ preventStringOverflow(desc->implementor)) {
2056 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
2057 return BAD_VALUE;
2058 }
2059 return NO_ERROR;
2060}
2061
2062/** returns BAD_VALUE if sanitization was required. */
2063status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
2064{
2065 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
2066 preventStringOverflow(config->ext.device.address)) {
2067 return BAD_VALUE;
2068 }
2069 return NO_ERROR;
2070}
2071
Eric Laurentc2f1f072009-07-17 12:17:14 -07002072// ----------------------------------------------------------------------------
2073
Glenn Kasten40bc9062015-03-20 09:09:33 -07002074} // namespace android