blob: 4a8bb522d221bf9d15fa01f30c439343f2cd51f9 [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,
François Gaffiecfe17322018-11-07 13:41:29 +010054 SET_VOLUME_ATTRIBUTES,
55 GET_VOLUME_ATTRIBUTES,
56 GET_MIN_VOLUME_FOR_ATTRIBUTES,
57 GET_MAX_VOLUME_FOR_ATTRIBUTES,
Eric Laurentde070132010-07-13 04:45:46 -070058 GET_STRATEGY_FOR_STREAM,
59 GET_OUTPUT_FOR_EFFECT,
60 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080061 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080062 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070063 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080064 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070065 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080066 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000067 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070068 IS_OFFLOAD_SUPPORTED,
Michael Chana94fbb22018-04-24 14:31:19 +100069 IS_DIRECT_OUTPUT_SUPPORTED,
Eric Laurent203b1a12014-04-01 10:34:16 -070070 LIST_AUDIO_PORTS,
71 GET_AUDIO_PORT,
72 CREATE_AUDIO_PATCH,
73 RELEASE_AUDIO_PATCH,
74 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070075 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070076 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070077 GET_OUTPUT_FOR_ATTR,
78 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070079 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080080 GET_PHONE_STATE,
81 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070082 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070083 STOP_AUDIO_SOURCE,
84 SET_AUDIO_PORT_CALLBACK_ENABLED,
François Gaffiecfe17322018-11-07 13:41:29 +010085 SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080086 SET_MASTER_MONO,
87 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070088 GET_STREAM_VOLUME_DB,
89 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070090 SET_SURROUND_FORMAT_ENABLED,
91 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070092 REMOVE_STREAM_DEFAULT_EFFECT,
93 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070094 REMOVE_SOURCE_DEFAULT_EFFECT,
95 SET_ASSISTANT_UID,
96 SET_A11Y_SERVICES_UIDS,
jiabin6012f912018-11-02 17:06:30 -070097 IS_HAPTIC_PLAYBACK_SUPPORTED,
Jean-Michel Trivibda70da2018-12-19 07:30:15 -080098 SET_UID_DEVICE_AFFINITY,
99 REMOVE_UID_DEVICE_AFFINITY,
François Gaffied0ba9ed2018-11-05 11:50:42 +0100100 GET_OFFLOAD_FORMATS_A2DP,
101 LIST_AUDIO_PRODUCT_STRATEGIES,
102 GET_STRATEGY_FOR_ATTRIBUTES,
François Gaffie4b2018b2018-11-07 11:18:59 +0100103 LIST_AUDIO_VOLUME_GROUPS,
Kevin Rocardb99cc752019-03-21 20:52:24 -0700104 GET_VOLUME_GROUP_FOR_ATTRIBUTES,
105 SET_ALLOWED_CAPTURE_POLICY,
Eric Laurent6c796322019-04-09 14:13:17 -0700106 MOVE_EFFECTS_TO_IO,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700107};
108
Eric Laurent1d670b12015-02-06 10:44:24 -0800109#define MAX_ITEMS_PER_LIST 1024
110
Eric Laurentc2f1f072009-07-17 12:17:14 -0700111class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
112{
113public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700114 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700115 : BpInterface<IAudioPolicyService>(impl)
116 {
117 }
118
119 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700120 audio_devices_t device,
121 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800122 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800123 const char *device_name,
124 audio_format_t encodedFormat)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700125 {
126 Parcel data, reply;
127 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
128 data.writeInt32(static_cast <uint32_t>(device));
129 data.writeInt32(static_cast <uint32_t>(state));
130 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800131 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800132 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700133 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
134 return static_cast <status_t> (reply.readInt32());
135 }
136
Dima Zavinfce7a472011-04-19 22:30:36 -0700137 virtual audio_policy_dev_state_t getDeviceConnectionState(
138 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700139 const char *device_address)
140 {
141 Parcel data, reply;
142 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
143 data.writeInt32(static_cast <uint32_t>(device));
144 data.writeCString(device_address);
145 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700146 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700147 }
148
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800149 virtual status_t handleDeviceConfigChange(audio_devices_t device,
150 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800151 const char *device_name,
152 audio_format_t encodedFormat)
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800153 {
154 Parcel data, reply;
155 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
156 data.writeInt32(static_cast <uint32_t>(device));
157 data.writeCString(device_address);
158 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800159 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800160 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
161 return static_cast <status_t> (reply.readInt32());
162 }
163
Glenn Kastenf78aee72012-01-04 11:00:47 -0800164 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700165 {
166 Parcel data, reply;
167 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
168 data.writeInt32(state);
169 remote()->transact(SET_PHONE_STATE, data, &reply);
170 return static_cast <status_t> (reply.readInt32());
171 }
172
Dima Zavinfce7a472011-04-19 22:30:36 -0700173 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700174 {
175 Parcel data, reply;
176 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
177 data.writeInt32(static_cast <uint32_t>(usage));
178 data.writeInt32(static_cast <uint32_t>(config));
179 remote()->transact(SET_FORCE_USE, data, &reply);
180 return static_cast <status_t> (reply.readInt32());
181 }
182
Dima Zavinfce7a472011-04-19 22:30:36 -0700183 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
187 data.writeInt32(static_cast <uint32_t>(usage));
188 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700189 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700190 }
191
Eric Laurentf4e63452017-11-06 19:31:46 +0000192 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700193 {
194 Parcel data, reply;
195 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
196 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700197 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700198 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700199 }
200
Kevin Rocard153f92d2018-12-18 18:33:28 -0800201 status_t getOutputForAttr(const audio_attributes_t *attr,
202 audio_io_handle_t *output,
203 audio_session_t session,
204 audio_stream_type_t *stream,
205 pid_t pid,
206 uid_t uid,
207 const audio_config_t *config,
208 audio_output_flags_t flags,
209 audio_port_handle_t *selectedDeviceId,
210 audio_port_handle_t *portId,
211 std::vector<audio_io_handle_t> *secondaryOutputs) override
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700212 {
213 Parcel data, reply;
214 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
215 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800216 if (stream == NULL) {
217 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
218 return BAD_VALUE;
219 }
220 if (*stream == AUDIO_STREAM_DEFAULT) {
221 ALOGE("getOutputForAttr unspecified stream type");
222 return BAD_VALUE;
223 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700224 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800225 if (output == NULL) {
226 ALOGE("getOutputForAttr NULL output - shouldn't happen");
227 return BAD_VALUE;
228 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700229 if (selectedDeviceId == NULL) {
230 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
231 return BAD_VALUE;
232 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800233 if (portId == NULL) {
234 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
235 return BAD_VALUE;
236 }
Kevin Rocard153f92d2018-12-18 18:33:28 -0800237 if (secondaryOutputs == NULL) {
238 ALOGE("getOutputForAttr NULL secondaryOutputs - shouldn't happen");
239 return BAD_VALUE;
240 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800241 if (attr == NULL) {
242 data.writeInt32(0);
243 } else {
244 data.writeInt32(1);
245 data.write(attr, sizeof(audio_attributes_t));
246 }
247 data.writeInt32(session);
248 if (stream == NULL) {
249 data.writeInt32(0);
250 } else {
251 data.writeInt32(1);
252 data.writeInt32(*stream);
253 }
Nadav Bar766fb022018-01-07 12:18:03 +0200254 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700255 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800256 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700257 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700258 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800259 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800260 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
261 if (status != NO_ERROR) {
262 return status;
263 }
264 status = (status_t)reply.readInt32();
265 if (status != NO_ERROR) {
266 return status;
267 }
268 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800269 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800270 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800271 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800272 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700273 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800274 *portId = (audio_port_handle_t)reply.readInt32();
Kevin Rocard153f92d2018-12-18 18:33:28 -0800275 secondaryOutputs->resize(reply.readInt32());
276 return reply.read(secondaryOutputs->data(),
277 secondaryOutputs->size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700278 }
279
Eric Laurentd7fe0862018-07-14 16:48:01 -0700280 virtual status_t startOutput(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(START_OUTPUT, data, &reply);
286 return static_cast <status_t> (reply.readInt32());
287 }
288
Eric Laurentd7fe0862018-07-14 16:48:01 -0700289 virtual status_t stopOutput(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(STOP_OUTPUT, data, &reply);
295 return static_cast <status_t> (reply.readInt32());
296 }
297
Eric Laurentd7fe0862018-07-14 16:48:01 -0700298 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700302 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700303 remote()->transact(RELEASE_OUTPUT, data, &reply);
304 }
305
Eric Laurentcaf7f482014-11-25 17:50:47 -0800306 virtual status_t getInputForAttr(const audio_attributes_t *attr,
307 audio_io_handle_t *input,
308 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700309 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700310 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800311 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800312 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600313 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700314 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800315 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800319 if (attr == NULL) {
320 ALOGE("getInputForAttr NULL attr - shouldn't happen");
321 return BAD_VALUE;
322 }
323 if (input == NULL) {
324 ALOGE("getInputForAttr NULL input - shouldn't happen");
325 return BAD_VALUE;
326 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700327 if (selectedDeviceId == NULL) {
328 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
329 return BAD_VALUE;
330 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800331 if (portId == NULL) {
332 ALOGE("getInputForAttr NULL portId - shouldn't happen");
333 return BAD_VALUE;
334 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800335 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700336 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800337 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700338 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700339 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800340 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800341 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700342 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700343 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800344 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800345 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
346 if (status != NO_ERROR) {
347 return status;
348 }
349 status = reply.readInt32();
350 if (status != NO_ERROR) {
351 return status;
352 }
353 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700354 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800355 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800356 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700357 }
358
Eric Laurent4eb58f12018-12-07 16:41:02 -0800359 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 {
361 Parcel data, reply;
362 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800363 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800365 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800366 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700367 }
368
Eric Laurentfee19762018-01-29 18:44:13 -0800369 virtual status_t stopInput(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(STOP_INPUT, data, &reply);
375 return static_cast <status_t> (reply.readInt32());
376 }
377
Eric Laurentfee19762018-01-29 18:44:13 -0800378 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700379 {
380 Parcel data, reply;
381 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800382 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 remote()->transact(RELEASE_INPUT, data, &reply);
384 }
385
Dima Zavinfce7a472011-04-19 22:30:36 -0700386 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700387 int indexMin,
388 int indexMax)
389 {
390 Parcel data, reply;
391 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
392 data.writeInt32(static_cast <uint32_t>(stream));
393 data.writeInt32(indexMin);
394 data.writeInt32(indexMax);
395 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
396 return static_cast <status_t> (reply.readInt32());
397 }
398
Eric Laurent83844cc2011-11-18 16:43:31 -0800399 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
400 int index,
401 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 {
403 Parcel data, reply;
404 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
405 data.writeInt32(static_cast <uint32_t>(stream));
406 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800407 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700408 remote()->transact(SET_STREAM_VOLUME, data, &reply);
409 return static_cast <status_t> (reply.readInt32());
410 }
411
Eric Laurent83844cc2011-11-18 16:43:31 -0800412 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
413 int *index,
414 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700415 {
416 Parcel data, reply;
417 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
418 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800419 data.writeInt32(static_cast <uint32_t>(device));
420
Eric Laurentc2f1f072009-07-17 12:17:14 -0700421 remote()->transact(GET_STREAM_VOLUME, data, &reply);
422 int lIndex = reply.readInt32();
423 if (index) *index = lIndex;
424 return static_cast <status_t> (reply.readInt32());
425 }
Eric Laurentde070132010-07-13 04:45:46 -0700426
François Gaffiecfe17322018-11-07 13:41:29 +0100427 virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index,
428 audio_devices_t device)
429 {
430 Parcel data, reply;
431 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
432 data.write(&attr, sizeof(audio_attributes_t));
433 data.writeInt32(index);
434 data.writeInt32(static_cast <uint32_t>(device));
435 status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply);
436 if (status != NO_ERROR) {
437 return status;
438 }
439 return static_cast <status_t> (reply.readInt32());
440 }
441 virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index,
442 audio_devices_t device)
443 {
444 Parcel data, reply;
445 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
446 data.write(&attr, sizeof(audio_attributes_t));
447 data.writeInt32(static_cast <uint32_t>(device));
448 status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply);
449 if (status != NO_ERROR) {
450 return status;
451 }
452 status = static_cast <status_t> (reply.readInt32());
453 if (status != NO_ERROR) {
454 return status;
455 }
456 index = reply.readInt32();
457 return NO_ERROR;
458 }
459 virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
460 {
461 Parcel data, reply;
462 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
463 data.write(&attr, sizeof(audio_attributes_t));
464 status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply);
465 if (status != NO_ERROR) {
466 return status;
467 }
468 status = static_cast <status_t> (reply.readInt32());
469 if (status != NO_ERROR) {
470 return status;
471 }
472 index = reply.readInt32();
473 return NO_ERROR;
474 }
475 virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
476 {
477 Parcel data, reply;
478 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
479 data.write(&attr, sizeof(audio_attributes_t));
480 status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply);
481 if (status != NO_ERROR) {
482 return status;
483 }
484 status = static_cast <status_t> (reply.readInt32());
485 if (status != NO_ERROR) {
486 return status;
487 }
488 index = reply.readInt32();
489 return NO_ERROR;
490 }
Dima Zavinfce7a472011-04-19 22:30:36 -0700491 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700492 {
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
495 data.writeInt32(static_cast <uint32_t>(stream));
496 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
François Gaffiec005e562018-11-06 15:04:49 +0100497 return reply.readUint32();
Eric Laurentde070132010-07-13 04:45:46 -0700498 }
499
Eric Laurent63742522012-03-08 13:42:42 -0800500 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800501 {
502 Parcel data, reply;
503 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
504 data.writeInt32(static_cast <uint32_t>(stream));
505 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800506 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800507 }
508
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700509 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700510 {
511 Parcel data, reply;
512 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
513 data.write(desc, sizeof(effect_descriptor_t));
514 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
515 return static_cast <audio_io_handle_t> (reply.readInt32());
516 }
517
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700518 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700519 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700520 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800521 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700522 int id)
523 {
524 Parcel data, reply;
525 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
526 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700527 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700528 data.writeInt32(strategy);
529 data.writeInt32(session);
530 data.writeInt32(id);
531 remote()->transact(REGISTER_EFFECT, data, &reply);
532 return static_cast <status_t> (reply.readInt32());
533 }
534
535 virtual status_t unregisterEffect(int id)
536 {
537 Parcel data, reply;
538 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
539 data.writeInt32(id);
540 remote()->transact(UNREGISTER_EFFECT, data, &reply);
541 return static_cast <status_t> (reply.readInt32());
542 }
543
Eric Laurentdb7c0792011-08-10 10:37:50 -0700544 virtual status_t setEffectEnabled(int id, bool enabled)
545 {
546 Parcel data, reply;
547 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
548 data.writeInt32(id);
549 data.writeInt32(enabled);
550 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
551 return static_cast <status_t> (reply.readInt32());
552 }
553
Eric Laurent6c796322019-04-09 14:13:17 -0700554 status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override
555 {
556 Parcel data, reply;
557 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
558 data.writeInt32(ids.size());
559 for (auto id : ids) {
560 data.writeInt32(id);
561 }
562 data.writeInt32(io);
563 status_t status = remote()->transact(MOVE_EFFECTS_TO_IO, data, &reply);
564 if (status != NO_ERROR) {
565 return status;
566 }
567 return static_cast <status_t> (reply.readInt32());
568 }
569
Glenn Kastenfff6d712012-01-12 16:38:12 -0800570 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800571 {
572 Parcel data, reply;
573 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800574 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800575 data.writeInt32(inPastMs);
576 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
577 return reply.readInt32();
578 }
Eric Laurent57dae992011-07-24 13:36:09 -0700579
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800580 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
581 {
582 Parcel data, reply;
583 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
584 data.writeInt32((int32_t) stream);
585 data.writeInt32(inPastMs);
586 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
587 return reply.readInt32();
588 }
589
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700590 virtual bool isSourceActive(audio_source_t source) const
591 {
592 Parcel data, reply;
593 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
594 data.writeInt32((int32_t) source);
595 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
596 return reply.readInt32();
597 }
598
Glenn Kastend848eb42016-03-08 13:42:11 -0800599 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700600 effect_descriptor_t *descriptors,
601 uint32_t *count)
602 {
603 if (descriptors == NULL || count == NULL) {
604 return BAD_VALUE;
605 }
606 Parcel data, reply;
607 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
608 data.writeInt32(audioSession);
609 data.writeInt32(*count);
610 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
611 if (status != NO_ERROR) {
612 return status;
613 }
614 status = static_cast <status_t> (reply.readInt32());
615 uint32_t retCount = reply.readInt32();
616 if (retCount != 0) {
617 uint32_t numDesc = (retCount < *count) ? retCount : *count;
618 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
619 }
620 *count = retCount;
621 return status;
622 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000623
Kevin Rocardb99cc752019-03-21 20:52:24 -0700624 status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
625 Parcel data, reply;
626 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
627 data.writeInt32(uid);
628 data.writeInt32(flags);
629 remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
630 return reply.readInt32();
631 }
632
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000633 virtual bool isOffloadSupported(const audio_offload_info_t& info)
634 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100635 Parcel data, reply;
636 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
637 data.write(&info, sizeof(audio_offload_info_t));
638 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700639 return reply.readInt32();
640 }
641
Michael Chana94fbb22018-04-24 14:31:19 +1000642 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
643 const audio_attributes_t& attributes) {
644 Parcel data, reply;
645 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
646 data.write(&config, sizeof(audio_config_base_t));
647 data.write(&attributes, sizeof(audio_attributes_t));
648 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
649 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
650 }
651
Eric Laurent203b1a12014-04-01 10:34:16 -0700652 virtual status_t listAudioPorts(audio_port_role_t role,
653 audio_port_type_t type,
654 unsigned int *num_ports,
655 struct audio_port *ports,
656 unsigned int *generation)
657 {
658 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
659 generation == NULL) {
660 return BAD_VALUE;
661 }
662 Parcel data, reply;
663 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
664 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
665 data.writeInt32(role);
666 data.writeInt32(type);
667 data.writeInt32(numPortsReq);
668 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
669 if (status == NO_ERROR) {
670 status = (status_t)reply.readInt32();
671 *num_ports = (unsigned int)reply.readInt32();
672 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700673 if (status == NO_ERROR) {
674 if (numPortsReq > *num_ports) {
675 numPortsReq = *num_ports;
676 }
677 if (numPortsReq > 0) {
678 reply.read(ports, numPortsReq * sizeof(struct audio_port));
679 }
680 *generation = reply.readInt32();
681 }
682 return status;
683 }
684
685 virtual status_t getAudioPort(struct audio_port *port)
686 {
687 if (port == NULL) {
688 return BAD_VALUE;
689 }
690 Parcel data, reply;
691 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
692 data.write(port, sizeof(struct audio_port));
693 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
694 if (status != NO_ERROR ||
695 (status = (status_t)reply.readInt32()) != NO_ERROR) {
696 return status;
697 }
698 reply.read(port, sizeof(struct audio_port));
699 return status;
700 }
701
702 virtual status_t createAudioPatch(const struct audio_patch *patch,
703 audio_patch_handle_t *handle)
704 {
705 if (patch == NULL || handle == NULL) {
706 return BAD_VALUE;
707 }
708 Parcel data, reply;
709 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
710 data.write(patch, sizeof(struct audio_patch));
711 data.write(handle, sizeof(audio_patch_handle_t));
712 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
713 if (status != NO_ERROR ||
714 (status = (status_t)reply.readInt32()) != NO_ERROR) {
715 return status;
716 }
717 reply.read(handle, sizeof(audio_patch_handle_t));
718 return status;
719 }
720
721 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
722 {
723 Parcel data, reply;
724 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
725 data.write(&handle, sizeof(audio_patch_handle_t));
726 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
727 if (status != NO_ERROR) {
728 status = (status_t)reply.readInt32();
729 }
730 return status;
731 }
732
733 virtual status_t listAudioPatches(unsigned int *num_patches,
734 struct audio_patch *patches,
735 unsigned int *generation)
736 {
737 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
738 generation == NULL) {
739 return BAD_VALUE;
740 }
741 Parcel data, reply;
742 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
743 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
744 data.writeInt32(numPatchesReq);
745 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
746 if (status == NO_ERROR) {
747 status = (status_t)reply.readInt32();
748 *num_patches = (unsigned int)reply.readInt32();
749 }
750 if (status == NO_ERROR) {
751 if (numPatchesReq > *num_patches) {
752 numPatchesReq = *num_patches;
753 }
754 if (numPatchesReq > 0) {
755 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
756 }
757 *generation = reply.readInt32();
758 }
759 return status;
760 }
761
762 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
763 {
764 if (config == NULL) {
765 return BAD_VALUE;
766 }
767 Parcel data, reply;
768 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
769 data.write(config, sizeof(struct audio_port_config));
770 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
771 if (status != NO_ERROR) {
772 status = (status_t)reply.readInt32();
773 }
774 return status;
775 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700776
Eric Laurentb52c1522014-05-20 11:27:36 -0700777 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
778 {
779 Parcel data, reply;
780 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800781 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700782 remote()->transact(REGISTER_CLIENT, data, &reply);
783 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700784
Eric Laurente8726fe2015-06-26 09:39:24 -0700785 virtual void setAudioPortCallbacksEnabled(bool enabled)
786 {
787 Parcel data, reply;
788 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
789 data.writeInt32(enabled ? 1 : 0);
790 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
791 }
792
François Gaffiecfe17322018-11-07 13:41:29 +0100793 virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled)
794 {
795 Parcel data, reply;
796 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
797 data.writeInt32(enabled ? 1 : 0);
798 remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply);
799 }
800
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700801 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
802 audio_io_handle_t *ioHandle,
803 audio_devices_t *device)
804 {
805 if (session == NULL || ioHandle == NULL || device == NULL) {
806 return BAD_VALUE;
807 }
808 Parcel data, reply;
809 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
810 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
811 if (status != NO_ERROR) {
812 return status;
813 }
814 status = (status_t)reply.readInt32();
815 if (status == NO_ERROR) {
816 *session = (audio_session_t)reply.readInt32();
817 *ioHandle = (audio_io_handle_t)reply.readInt32();
818 *device = (audio_devices_t)reply.readInt32();
819 }
820 return status;
821 }
822
823 virtual status_t releaseSoundTriggerSession(audio_session_t session)
824 {
825 Parcel data, reply;
826 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
827 data.writeInt32(session);
828 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
829 if (status != NO_ERROR) {
830 return status;
831 }
832 return (status_t)reply.readInt32();
833 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700834
835 virtual audio_mode_t getPhoneState()
836 {
837 Parcel data, reply;
838 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
839 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
840 if (status != NO_ERROR) {
841 return AUDIO_MODE_INVALID;
842 }
843 return (audio_mode_t)reply.readInt32();
844 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800845
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700846 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800847 {
848 Parcel data, reply;
849 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
850 data.writeInt32(registration ? 1 : 0);
851 size_t size = mixes.size();
852 if (size > MAX_MIXES_PER_POLICY) {
853 size = MAX_MIXES_PER_POLICY;
854 }
855 size_t sizePosition = data.dataPosition();
856 data.writeInt32(size);
857 size_t finalSize = size;
858 for (size_t i = 0; i < size; i++) {
859 size_t position = data.dataPosition();
860 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
861 data.setDataPosition(position);
862 finalSize--;
863 }
864 }
865 if (size != finalSize) {
866 size_t position = data.dataPosition();
867 data.setDataPosition(sizePosition);
868 data.writeInt32(finalSize);
869 data.setDataPosition(position);
870 }
871 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
872 if (status == NO_ERROR) {
873 status = (status_t)reply.readInt32();
874 }
875 return status;
876 }
Eric Laurent554a2772015-04-10 11:29:24 -0700877
878 virtual status_t startAudioSource(const struct audio_port_config *source,
879 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700880 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700881 {
882 Parcel data, reply;
883 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700884 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700885 return BAD_VALUE;
886 }
887 data.write(source, sizeof(struct audio_port_config));
888 data.write(attributes, sizeof(audio_attributes_t));
889 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
890 if (status != NO_ERROR) {
891 return status;
892 }
893 status = (status_t)reply.readInt32();
894 if (status != NO_ERROR) {
895 return status;
896 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700897 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700898 return status;
899 }
900
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700901 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700902 {
903 Parcel data, reply;
904 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700905 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700906 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
907 if (status != NO_ERROR) {
908 return status;
909 }
910 status = (status_t)reply.readInt32();
911 return status;
912 }
Andy Hung2ddee192015-12-18 17:34:44 -0800913
914 virtual status_t setMasterMono(bool mono)
915 {
916 Parcel data, reply;
917 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
918 data.writeInt32(static_cast<int32_t>(mono));
919 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
920 if (status != NO_ERROR) {
921 return status;
922 }
923 return static_cast<status_t>(reply.readInt32());
924 }
925
926 virtual status_t getMasterMono(bool *mono)
927 {
928 if (mono == nullptr) {
929 return BAD_VALUE;
930 }
931 Parcel data, reply;
932 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
933
934 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
935 if (status != NO_ERROR) {
936 return status;
937 }
938 status = static_cast<status_t>(reply.readInt32());
939 if (status == NO_ERROR) {
940 *mono = static_cast<bool>(reply.readInt32());
941 }
942 return status;
943 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700944
945 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
946 {
947 Parcel data, reply;
948 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
949 data.writeInt32(static_cast <int32_t>(stream));
950 data.writeInt32(static_cast <int32_t>(index));
951 data.writeUint32(static_cast <uint32_t>(device));
952 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
953 if (status != NO_ERROR) {
954 return NAN;
955 }
956 return reply.readFloat();
957 }
jiabin81772902018-04-02 17:52:27 -0700958
959 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
960 audio_format_t *surroundFormats,
961 bool *surroundFormatsEnabled,
962 bool reported)
963 {
964 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
965 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
966 return BAD_VALUE;
967 }
968 Parcel data, reply;
969 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
970 unsigned int numSurroundFormatsReq = *numSurroundFormats;
971 data.writeUint32(numSurroundFormatsReq);
972 data.writeBool(reported);
973 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
974 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
975 *numSurroundFormats = reply.readUint32();
976 }
977 if (status == NO_ERROR) {
978 if (numSurroundFormatsReq > *numSurroundFormats) {
979 numSurroundFormatsReq = *numSurroundFormats;
980 }
981 if (numSurroundFormatsReq > 0) {
982 status = reply.read(surroundFormats,
983 numSurroundFormatsReq * sizeof(audio_format_t));
984 if (status != NO_ERROR) {
985 return status;
986 }
987 status = reply.read(surroundFormatsEnabled,
988 numSurroundFormatsReq * sizeof(bool));
989 }
990 }
991 return status;
992 }
993
994 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
995 {
996 Parcel data, reply;
997 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
998 data.writeInt32(audioFormat);
999 data.writeBool(enabled);
1000 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
1001 if (status != NO_ERROR) {
1002 return status;
1003 }
1004 return reply.readInt32();
1005 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001006
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001007 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
1008 std::vector<audio_format_t> *formats)
1009 {
1010 if (formats == NULL) {
1011 return BAD_VALUE;
1012 }
1013
1014 Parcel data, reply;
1015 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1016 status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
1017 if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
1018 return status;
1019 }
1020
1021 size_t list_size = reply.readUint32();
1022
1023 for (size_t i = 0; i < list_size; i++) {
1024 formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
1025 }
1026 return NO_ERROR;
1027 }
1028
1029
1030 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001031 const String16& opPackageName,
1032 const effect_uuid_t *uuid,
1033 int32_t priority,
1034 audio_usage_t usage,
1035 audio_unique_id_t* id)
1036 {
1037 Parcel data, reply;
1038 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1039 data.write(type, sizeof(effect_uuid_t));
1040 data.writeString16(opPackageName);
1041 data.write(uuid, sizeof(effect_uuid_t));
1042 data.writeInt32(priority);
1043 data.writeInt32((int32_t) usage);
1044 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
1045 if (status != NO_ERROR) {
1046 return status;
1047 }
1048 status = static_cast <status_t> (reply.readInt32());
1049 *id = reply.readInt32();
1050 return status;
1051 }
1052
1053 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
1054 {
1055 Parcel data, reply;
1056 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1057 data.writeInt32(id);
1058 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
1059 if (status != NO_ERROR) {
1060 return status;
1061 }
1062 return static_cast <status_t> (reply.readInt32());
1063 }
1064
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001065 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
1066 const String16& opPackageName,
1067 const effect_uuid_t *uuid,
1068 int32_t priority,
1069 audio_source_t source,
1070 audio_unique_id_t* id)
1071 {
1072 Parcel data, reply;
1073 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1074 data.write(type, sizeof(effect_uuid_t));
1075 data.writeString16(opPackageName);
1076 data.write(uuid, sizeof(effect_uuid_t));
1077 data.writeInt32(priority);
1078 data.writeInt32((int32_t) source);
1079 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
1080 if (status != NO_ERROR) {
1081 return status;
1082 }
1083 status = static_cast <status_t> (reply.readInt32());
1084 *id = reply.readInt32();
1085 return status;
1086 }
1087
1088 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
1089 {
1090 Parcel data, reply;
1091 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1092 data.writeInt32(id);
1093 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
1094 if (status != NO_ERROR) {
1095 return status;
1096 }
1097 return static_cast <status_t> (reply.readInt32());
1098 }
1099
Eric Laurentb78763e2018-10-17 10:08:02 -07001100 virtual status_t setAssistantUid(uid_t uid)
1101 {
1102 Parcel data, reply;
1103 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1104 data.writeInt32(uid);
1105 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
1106 if (status != NO_ERROR) {
1107 return status;
1108 }
1109 return static_cast <status_t> (reply.readInt32());
1110 }
1111
1112 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
1113 {
1114 Parcel data, reply;
1115 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1116 data.writeInt32(uids.size());
1117 for (auto uid : uids) {
1118 data.writeInt32(uid);
1119 }
1120 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
1121 if (status != NO_ERROR) {
1122 return status;
1123 }
1124 return static_cast <status_t> (reply.readInt32());
1125 }
1126
jiabin6012f912018-11-02 17:06:30 -07001127 virtual bool isHapticPlaybackSupported()
1128 {
1129 Parcel data, reply;
1130 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1131 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
1132 if (status != NO_ERROR) {
1133 return false;
1134 }
1135 return reply.readBool();
1136 }
1137
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001138 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
1139 {
1140 Parcel data, reply;
1141 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1142
1143 data.writeInt32((int32_t) uid);
1144 size_t size = devices.size();
1145 size_t sizePosition = data.dataPosition();
1146 data.writeInt32((int32_t) size);
1147 size_t finalSize = size;
1148 for (size_t i = 0; i < size; i++) {
1149 size_t position = data.dataPosition();
1150 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1151 data.setDataPosition(position);
1152 finalSize--;
1153 }
1154 }
1155 if (size != finalSize) {
1156 size_t position = data.dataPosition();
1157 data.setDataPosition(sizePosition);
1158 data.writeInt32(finalSize);
1159 data.setDataPosition(position);
1160 }
1161
1162 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1163 if (status == NO_ERROR) {
1164 status = (status_t)reply.readInt32();
1165 }
1166 return status;
1167 }
1168
François Gaffied0ba9ed2018-11-05 11:50:42 +01001169 virtual status_t removeUidDeviceAffinities(uid_t uid) {
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001170 Parcel data, reply;
1171 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1172
1173 data.writeInt32((int32_t) uid);
1174
François Gaffied0ba9ed2018-11-05 11:50:42 +01001175 status_t status =
1176 remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001177 if (status == NO_ERROR) {
François Gaffied0ba9ed2018-11-05 11:50:42 +01001178 status = (status_t) reply.readInt32();
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001179 }
1180 return status;
1181 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01001182
1183 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
1184 {
1185 Parcel data, reply;
1186 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1187
1188 status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
1189 if (status != NO_ERROR) {
1190 ALOGE("%s: permission denied", __func__);
1191 return status;
1192 }
1193 status = static_cast<status_t>(reply.readInt32());
François Gaffie4b2018b2018-11-07 11:18:59 +01001194 if (status != NO_ERROR) {
1195 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001196 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001197 uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
1198 for (size_t i = 0; i < numStrategies; i++) {
1199 AudioProductStrategy strategy;
1200 status = strategy.readFromParcel(&reply);
1201 if (status != NO_ERROR) {
1202 ALOGE("%s: failed to read strategies", __FUNCTION__);
1203 strategies.clear();
1204 return status;
1205 }
1206 strategies.push_back(strategy);
1207 }
1208 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001209 }
1210
François Gaffie4b2018b2018-11-07 11:18:59 +01001211 virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
1212 product_strategy_t &productStrategy)
François Gaffied0ba9ed2018-11-05 11:50:42 +01001213 {
1214 Parcel data, reply;
1215 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1216 status_t status = aa.writeToParcel(&data);
1217 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01001218 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001219 }
1220 status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
François Gaffie4b2018b2018-11-07 11:18:59 +01001221 if (status != NO_ERROR) {
1222 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001223 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001224 status = static_cast<status_t>(reply.readInt32());
1225 if (status != NO_ERROR) {
1226 return status;
1227 }
1228 productStrategy = static_cast<product_strategy_t>(reply.readInt32());
1229 return NO_ERROR;
1230 }
1231
1232 virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups)
1233 {
1234 Parcel data, reply;
1235 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1236
1237 status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply);
1238 if (status != NO_ERROR) {
1239 return status;
1240 }
1241 status = static_cast<status_t>(reply.readInt32());
1242 if (status != NO_ERROR) {
1243 return status;
1244 }
1245 uint32_t numGroups = static_cast<uint32_t>(reply.readInt32());
1246 for (size_t i = 0; i < numGroups; i++) {
1247 AudioVolumeGroup group;
1248 status = group.readFromParcel(&reply);
1249 if (status != NO_ERROR) {
1250 ALOGE("%s: failed to read volume groups", __FUNCTION__);
1251 groups.clear();
1252 return status;
1253 }
1254 groups.push_back(group);
1255 }
1256 return NO_ERROR;
1257 }
1258
1259 virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
1260 volume_group_t &volumeGroup)
1261 {
1262 Parcel data, reply;
1263 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1264 status_t status = aa.writeToParcel(&data);
1265 if (status != NO_ERROR) {
1266 return status;
1267 }
1268 status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply);
1269 if (status != NO_ERROR) {
1270 return status;
1271 }
1272 status = static_cast<status_t>(reply.readInt32());
1273 if (status != NO_ERROR) {
1274 return status;
1275 }
1276 volumeGroup = static_cast<volume_group_t>(reply.readInt32());
1277 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001278 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001279};
1280
1281IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1282
1283// ----------------------------------------------------------------------
1284
Eric Laurentc2f1f072009-07-17 12:17:14 -07001285status_t BnAudioPolicyService::onTransact(
1286 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1287{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001288 // make sure transactions reserved to AudioFlinger do not come from other processes
1289 switch (code) {
1290 case START_OUTPUT:
1291 case STOP_OUTPUT:
1292 case RELEASE_OUTPUT:
1293 case GET_INPUT_FOR_ATTR:
1294 case START_INPUT:
1295 case STOP_INPUT:
1296 case RELEASE_INPUT:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001297 case GET_OUTPUT_FOR_EFFECT:
1298 case REGISTER_EFFECT:
1299 case UNREGISTER_EFFECT:
1300 case SET_EFFECT_ENABLED:
1301 case GET_OUTPUT_FOR_ATTR:
1302 case ACQUIRE_SOUNDTRIGGER_SESSION:
1303 case RELEASE_SOUNDTRIGGER_SESSION:
Eric Laurent6c796322019-04-09 14:13:17 -07001304 case MOVE_EFFECTS_TO_IO:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001305 ALOGW("%s: transaction %d received from PID %d",
1306 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001307 // return status only for non void methods
1308 switch (code) {
1309 case RELEASE_OUTPUT:
1310 case RELEASE_INPUT:
1311 break;
1312 default:
1313 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1314 break;
1315 }
1316 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001317 default:
1318 break;
1319 }
1320
Eric Laurent4980df22018-01-26 18:04:09 -08001321 // make sure the following transactions come from system components
1322 switch (code) {
1323 case SET_DEVICE_CONNECTION_STATE:
1324 case HANDLE_DEVICE_CONFIG_CHANGE:
1325 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001326//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1327// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001328 case INIT_STREAM_VOLUME:
1329 case SET_STREAM_VOLUME:
1330 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001331 case SET_MASTER_MONO:
jiabin81772902018-04-02 17:52:27 -07001332 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001333 case SET_SURROUND_FORMAT_ENABLED:
1334 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001335 case SET_A11Y_SERVICES_UIDS:
1336 case SET_UID_DEVICE_AFFINITY:
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001337 case REMOVE_UID_DEVICE_AFFINITY:
François Gaffie4b2018b2018-11-07 11:18:59 +01001338 case GET_OFFLOAD_FORMATS_A2DP:
1339 case LIST_AUDIO_VOLUME_GROUPS:
1340 case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001341 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001342 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1343 __func__, code, IPCThreadState::self()->getCallingPid(),
1344 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001345 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1346 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001347 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001348 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001349 default:
1350 break;
1351 }
1352
Eric Laurent39b09b52018-06-29 12:24:40 -07001353 std::string tag("IAudioPolicyService command " + std::to_string(code));
1354 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001355
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001356 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001357 case SET_DEVICE_CONNECTION_STATE: {
1358 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001359 audio_devices_t device =
1360 static_cast <audio_devices_t>(data.readInt32());
1361 audio_policy_dev_state_t state =
1362 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001363 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001364 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001365 audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001366 if (device_address == nullptr || device_name == nullptr) {
1367 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1368 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1369 } else {
1370 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1371 state,
1372 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001373 device_name,
1374 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001375 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001376 return NO_ERROR;
1377 } break;
1378
1379 case GET_DEVICE_CONNECTION_STATE: {
1380 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001381 audio_devices_t device =
1382 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001383 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001384 if (device_address == nullptr) {
1385 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1386 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1387 } else {
1388 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1389 device_address)));
1390 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001391 return NO_ERROR;
1392 } break;
1393
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001394 case HANDLE_DEVICE_CONFIG_CHANGE: {
1395 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1396 audio_devices_t device =
1397 static_cast <audio_devices_t>(data.readInt32());
1398 const char *device_address = data.readCString();
1399 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001400 audio_format_t codecFormat =
1401 static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001402 if (device_address == nullptr || device_name == nullptr) {
1403 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1404 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1405 } else {
1406 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1407 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001408 device_name,
1409 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001410 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001411 return NO_ERROR;
1412 } break;
1413
Eric Laurentc2f1f072009-07-17 12:17:14 -07001414 case SET_PHONE_STATE: {
1415 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001416 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1417 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001418 return NO_ERROR;
1419 } break;
1420
Eric Laurentc2f1f072009-07-17 12:17:14 -07001421 case SET_FORCE_USE: {
1422 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001423 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1424 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001425 audio_policy_forced_cfg_t config =
1426 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001427 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1428 return NO_ERROR;
1429 } break;
1430
1431 case GET_FORCE_USE: {
1432 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001433 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1434 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001435 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1436 return NO_ERROR;
1437 } break;
1438
1439 case GET_OUTPUT: {
1440 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001441 audio_stream_type_t stream =
1442 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001443 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001444 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001445 return NO_ERROR;
1446 } break;
1447
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001448 case GET_OUTPUT_FOR_ATTR: {
1449 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001450 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001451 bool hasAttributes = data.readInt32() != 0;
1452 if (hasAttributes) {
1453 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001454 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001455 }
1456 audio_session_t session = (audio_session_t)data.readInt32();
1457 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1458 bool hasStream = data.readInt32() != 0;
1459 if (hasStream) {
1460 stream = (audio_stream_type_t)data.readInt32();
1461 }
Nadav Bar766fb022018-01-07 12:18:03 +02001462 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001463 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001464 audio_config_t config;
1465 memset(&config, 0, sizeof(audio_config_t));
1466 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001467 audio_output_flags_t flags =
1468 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001469 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001470 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001471 audio_io_handle_t output = 0;
Kevin Rocard153f92d2018-12-18 18:33:28 -08001472 std::vector<audio_io_handle_t> secondaryOutputs;
Eric Laurente83b55d2014-11-14 10:06:21 -08001473 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001474 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001475 &config,
Kevin Rocard153f92d2018-12-18 18:33:28 -08001476 flags, &selectedDeviceId, &portId, &secondaryOutputs);
Eric Laurente83b55d2014-11-14 10:06:21 -08001477 reply->writeInt32(status);
1478 reply->writeInt32(output);
1479 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001480 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001481 reply->writeInt32(portId);
Kevin Rocard153f92d2018-12-18 18:33:28 -08001482 reply->writeInt32(secondaryOutputs.size());
1483 return reply->write(secondaryOutputs.data(),
1484 secondaryOutputs.size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001485 } break;
1486
Eric Laurentc2f1f072009-07-17 12:17:14 -07001487 case START_OUTPUT: {
1488 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001489 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1490 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001491 return NO_ERROR;
1492 } break;
1493
1494 case STOP_OUTPUT: {
1495 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001496 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1497 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001498 return NO_ERROR;
1499 } break;
1500
1501 case RELEASE_OUTPUT: {
1502 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001503 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1504 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001505 return NO_ERROR;
1506 } break;
1507
Eric Laurentcaf7f482014-11-25 17:50:47 -08001508 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001509 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001510 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001511 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001512 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001513 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001514 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001515 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001516 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001517 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001518 audio_config_base_t config;
1519 memset(&config, 0, sizeof(audio_config_base_t));
1520 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001521 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001522 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001523 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001524 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001525 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001526 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001527 reply->writeInt32(status);
1528 if (status == NO_ERROR) {
1529 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001530 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001531 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001532 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001533 return NO_ERROR;
1534 } break;
1535
1536 case START_INPUT: {
1537 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001538 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001539 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001540 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001541 return NO_ERROR;
1542 } break;
1543
1544 case STOP_INPUT: {
1545 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001546 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1547 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001548 return NO_ERROR;
1549 } break;
1550
1551 case RELEASE_INPUT: {
1552 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001553 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1554 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001555 return NO_ERROR;
1556 } break;
1557
1558 case INIT_STREAM_VOLUME: {
1559 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001560 audio_stream_type_t stream =
1561 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001562 int indexMin = data.readInt32();
1563 int indexMax = data.readInt32();
1564 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1565 return NO_ERROR;
1566 } break;
1567
1568 case SET_STREAM_VOLUME: {
1569 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001570 audio_stream_type_t stream =
1571 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001572 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001573 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1574 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1575 index,
1576 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001577 return NO_ERROR;
1578 } break;
1579
1580 case GET_STREAM_VOLUME: {
1581 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001582 audio_stream_type_t stream =
1583 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001584 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001585 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001586 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001587 reply->writeInt32(index);
1588 reply->writeInt32(static_cast <uint32_t>(status));
1589 return NO_ERROR;
1590 } break;
1591
Eric Laurentde070132010-07-13 04:45:46 -07001592 case GET_STRATEGY_FOR_STREAM: {
1593 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001594 audio_stream_type_t stream =
1595 static_cast <audio_stream_type_t>(data.readInt32());
François Gaffiec005e562018-11-06 15:04:49 +01001596 reply->writeUint32(getStrategyForStream(stream));
Eric Laurentde070132010-07-13 04:45:46 -07001597 return NO_ERROR;
1598 } break;
1599
François Gaffiecfe17322018-11-07 13:41:29 +01001600 case SET_VOLUME_ATTRIBUTES: {
1601 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1602 audio_attributes_t attributes = {};
1603 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1604 if (status != NO_ERROR) {
1605 return status;
1606 }
1607 int index = data.readInt32();
1608 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1609
1610 reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes,
1611 index, device)));
1612 return NO_ERROR;
1613 } break;
1614
1615 case GET_VOLUME_ATTRIBUTES: {
1616 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1617 audio_attributes_t attributes = {};
1618 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1619 if (status != NO_ERROR) {
1620 return status;
1621 }
1622 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1623
1624 int index = 0;
1625 status = getVolumeIndexForAttributes(attributes, index, device);
1626 reply->writeInt32(static_cast <uint32_t>(status));
1627 if (status == NO_ERROR) {
1628 reply->writeInt32(index);
1629 }
1630 return NO_ERROR;
1631 } break;
1632
1633 case GET_MIN_VOLUME_FOR_ATTRIBUTES: {
1634 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1635 audio_attributes_t attributes = {};
1636 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1637 if (status != NO_ERROR) {
1638 return status;
1639 }
1640
1641 int index = 0;
1642 status = getMinVolumeIndexForAttributes(attributes, index);
1643 reply->writeInt32(static_cast <uint32_t>(status));
1644 if (status == NO_ERROR) {
1645 reply->writeInt32(index);
1646 }
1647 return NO_ERROR;
1648 } break;
1649
1650 case GET_MAX_VOLUME_FOR_ATTRIBUTES: {
1651 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1652 audio_attributes_t attributes = {};
1653 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1654 if (status != NO_ERROR) {
1655 return status;
1656 }
1657
1658 int index = 0;
1659 status = getMaxVolumeIndexForAttributes(attributes, index);
1660 reply->writeInt32(static_cast <uint32_t>(status));
1661 if (status == NO_ERROR) {
1662 reply->writeInt32(index);
1663 }
1664 return NO_ERROR;
1665 } break;
1666
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001667 case GET_DEVICES_FOR_STREAM: {
1668 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001669 audio_stream_type_t stream =
1670 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001671 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1672 return NO_ERROR;
1673 } break;
1674
Eric Laurentde070132010-07-13 04:45:46 -07001675 case GET_OUTPUT_FOR_EFFECT: {
1676 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001677 effect_descriptor_t desc = {};
1678 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1679 android_errorWriteLog(0x534e4554, "73126106");
1680 }
1681 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001682 audio_io_handle_t output = getOutputForEffect(&desc);
1683 reply->writeInt32(static_cast <int>(output));
1684 return NO_ERROR;
1685 } break;
1686
1687 case REGISTER_EFFECT: {
1688 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001689 effect_descriptor_t desc = {};
1690 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1691 android_errorWriteLog(0x534e4554, "73126106");
1692 }
1693 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001694 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001695 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001696 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001697 int id = data.readInt32();
1698 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001699 io,
Eric Laurentde070132010-07-13 04:45:46 -07001700 strategy,
1701 session,
1702 id)));
1703 return NO_ERROR;
1704 } break;
1705
1706 case UNREGISTER_EFFECT: {
1707 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1708 int id = data.readInt32();
1709 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1710 return NO_ERROR;
1711 } break;
1712
Eric Laurentdb7c0792011-08-10 10:37:50 -07001713 case SET_EFFECT_ENABLED: {
1714 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1715 int id = data.readInt32();
1716 bool enabled = static_cast <bool>(data.readInt32());
1717 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1718 return NO_ERROR;
1719 } break;
1720
Eric Laurent6c796322019-04-09 14:13:17 -07001721 case MOVE_EFFECTS_TO_IO: {
1722 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1723 std::vector<int> ids;
1724 int32_t size;
1725 status_t status = data.readInt32(&size);
1726 if (status != NO_ERROR) {
1727 return status;
1728 }
1729 if (size > MAX_ITEMS_PER_LIST) {
1730 return BAD_VALUE;
1731 }
1732 for (int32_t i = 0; i < size; i++) {
1733 int id;
1734 status = data.readInt32(&id);
1735 if (status != NO_ERROR) {
1736 return status;
1737 }
1738 ids.push_back(id);
1739 }
1740
1741 audio_io_handle_t io = data.readInt32();
1742 reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io)));
1743 return NO_ERROR;
1744 } break;
1745
Eric Laurenteda6c362011-02-02 09:33:30 -08001746 case IS_STREAM_ACTIVE: {
1747 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001748 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001749 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001750 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001751 return NO_ERROR;
1752 } break;
1753
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001754 case IS_STREAM_ACTIVE_REMOTELY: {
1755 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1756 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1757 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001758 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001759 return NO_ERROR;
1760 } break;
1761
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001762 case IS_SOURCE_ACTIVE: {
1763 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1764 audio_source_t source = (audio_source_t) data.readInt32();
1765 reply->writeInt32( isSourceActive(source));
1766 return NO_ERROR;
1767 }
1768
Eric Laurent57dae992011-07-24 13:36:09 -07001769 case QUERY_DEFAULT_PRE_PROCESSING: {
1770 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001771 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001772 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001773 if (count > AudioEffect::kMaxPreProcessing) {
1774 count = AudioEffect::kMaxPreProcessing;
1775 }
Eric Laurent57dae992011-07-24 13:36:09 -07001776 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001777 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001778 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1779 reply->writeInt32(status);
1780 if (status != NO_ERROR && status != NO_MEMORY) {
1781 retCount = 0;
1782 }
1783 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001784 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001785 if (retCount < count) {
1786 count = retCount;
1787 }
1788 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1789 }
1790 delete[] descriptors;
1791 return status;
1792 }
1793
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001794 case IS_OFFLOAD_SUPPORTED: {
1795 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001796 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001797 data.read(&info, sizeof(audio_offload_info_t));
1798 bool isSupported = isOffloadSupported(info);
1799 reply->writeInt32(isSupported);
1800 return NO_ERROR;
1801 }
1802
Michael Chana94fbb22018-04-24 14:31:19 +10001803 case IS_DIRECT_OUTPUT_SUPPORTED: {
1804 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1805 audio_config_base_t config = {};
1806 audio_attributes_t attributes = {};
1807 status_t status = data.read(&config, sizeof(audio_config_base_t));
1808 if (status != NO_ERROR) return status;
1809 status = data.read(&attributes, sizeof(audio_attributes_t));
1810 if (status != NO_ERROR) return status;
1811 reply->writeInt32(isDirectOutputSupported(config, attributes));
1812 return NO_ERROR;
1813 }
1814
Eric Laurent203b1a12014-04-01 10:34:16 -07001815 case LIST_AUDIO_PORTS: {
1816 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1817 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1818 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1819 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001820 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1821 numPortsReq = MAX_ITEMS_PER_LIST;
1822 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001823 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001824 struct audio_port *ports =
1825 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001826 if (ports == NULL) {
1827 reply->writeInt32(NO_MEMORY);
1828 reply->writeInt32(0);
1829 return NO_ERROR;
1830 }
1831 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001832 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1833 reply->writeInt32(status);
1834 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001835
1836 if (status == NO_ERROR) {
1837 if (numPortsReq > numPorts) {
1838 numPortsReq = numPorts;
1839 }
1840 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1841 reply->writeInt32(generation);
1842 }
1843 free(ports);
1844 return NO_ERROR;
1845 }
1846
1847 case GET_AUDIO_PORT: {
1848 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001849 struct audio_port port = {};
1850 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1851 ALOGE("b/23912202");
1852 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001853 status_t status = getAudioPort(&port);
1854 reply->writeInt32(status);
1855 if (status == NO_ERROR) {
1856 reply->write(&port, sizeof(struct audio_port));
1857 }
1858 return NO_ERROR;
1859 }
1860
1861 case CREATE_AUDIO_PATCH: {
1862 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001863 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001864 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001865 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001866 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1867 ALOGE("b/23912202");
1868 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001869 status_t status = createAudioPatch(&patch, &handle);
1870 reply->writeInt32(status);
1871 if (status == NO_ERROR) {
1872 reply->write(&handle, sizeof(audio_patch_handle_t));
1873 }
1874 return NO_ERROR;
1875 }
1876
1877 case RELEASE_AUDIO_PATCH: {
1878 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001879 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001880 data.read(&handle, sizeof(audio_patch_handle_t));
1881 status_t status = releaseAudioPatch(handle);
1882 reply->writeInt32(status);
1883 return NO_ERROR;
1884 }
1885
1886 case LIST_AUDIO_PATCHES: {
1887 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1888 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001889 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1890 numPatchesReq = MAX_ITEMS_PER_LIST;
1891 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001892 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001893 struct audio_patch *patches =
1894 (struct audio_patch *)calloc(numPatchesReq,
1895 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001896 if (patches == NULL) {
1897 reply->writeInt32(NO_MEMORY);
1898 reply->writeInt32(0);
1899 return NO_ERROR;
1900 }
1901 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001902 status_t status = listAudioPatches(&numPatches, patches, &generation);
1903 reply->writeInt32(status);
1904 reply->writeInt32(numPatches);
1905 if (status == NO_ERROR) {
1906 if (numPatchesReq > numPatches) {
1907 numPatchesReq = numPatches;
1908 }
1909 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1910 reply->writeInt32(generation);
1911 }
1912 free(patches);
1913 return NO_ERROR;
1914 }
1915
1916 case SET_AUDIO_PORT_CONFIG: {
1917 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001918 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001919 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001920 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001921 status_t status = setAudioPortConfig(&config);
1922 reply->writeInt32(status);
1923 return NO_ERROR;
1924 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001925
Eric Laurentb52c1522014-05-20 11:27:36 -07001926 case REGISTER_CLIENT: {
1927 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1928 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1929 data.readStrongBinder());
1930 registerClient(client);
1931 return NO_ERROR;
1932 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001933
Eric Laurente8726fe2015-06-26 09:39:24 -07001934 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1935 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1936 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1937 return NO_ERROR;
1938 } break;
1939
François Gaffiecfe17322018-11-07 13:41:29 +01001940 case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: {
1941 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1942 setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1);
1943 return NO_ERROR;
1944 } break;
1945
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001946 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1947 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1948 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1949 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001950 audio_session_t session = AUDIO_SESSION_NONE;
1951 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1952 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001953 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1954 reply->writeInt32(status);
1955 if (status == NO_ERROR) {
1956 reply->writeInt32(session);
1957 reply->writeInt32(ioHandle);
1958 reply->writeInt32(device);
1959 }
1960 return NO_ERROR;
1961 } break;
1962
1963 case RELEASE_SOUNDTRIGGER_SESSION: {
1964 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1965 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1966 data.readStrongBinder());
1967 audio_session_t session = (audio_session_t)data.readInt32();
1968 status_t status = releaseSoundTriggerSession(session);
1969 reply->writeInt32(status);
1970 return NO_ERROR;
1971 } break;
1972
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001973 case GET_PHONE_STATE: {
1974 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1975 reply->writeInt32((int32_t)getPhoneState());
1976 return NO_ERROR;
1977 } break;
1978
Eric Laurentbaac1832014-12-01 17:52:59 -08001979 case REGISTER_POLICY_MIXES: {
1980 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1981 bool registration = data.readInt32() == 1;
1982 Vector<AudioMix> mixes;
1983 size_t size = (size_t)data.readInt32();
1984 if (size > MAX_MIXES_PER_POLICY) {
1985 size = MAX_MIXES_PER_POLICY;
1986 }
1987 for (size_t i = 0; i < size; i++) {
1988 AudioMix mix;
1989 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1990 mixes.add(mix);
1991 }
1992 }
1993 status_t status = registerPolicyMixes(mixes, registration);
1994 reply->writeInt32(status);
1995 return NO_ERROR;
1996 } break;
1997
Eric Laurent554a2772015-04-10 11:29:24 -07001998 case START_AUDIO_SOURCE: {
1999 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07002000 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07002001 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07002002 (void)sanitizeAudioPortConfig(&source);
2003 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07002004 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002005 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002006 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
2007 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002008 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002009 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002010 return NO_ERROR;
2011 } break;
2012
2013 case STOP_AUDIO_SOURCE: {
2014 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002015 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
2016 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002017 reply->writeInt32(status);
2018 return NO_ERROR;
2019 } break;
2020
Andy Hung2ddee192015-12-18 17:34:44 -08002021 case SET_MASTER_MONO: {
2022 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2023 bool mono = static_cast<bool>(data.readInt32());
2024 status_t status = setMasterMono(mono);
2025 reply->writeInt32(status);
2026 return NO_ERROR;
2027 } break;
2028
2029 case GET_MASTER_MONO: {
2030 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2031 bool mono;
2032 status_t status = getMasterMono(&mono);
2033 reply->writeInt32(status);
2034 if (status == NO_ERROR) {
2035 reply->writeInt32(static_cast<int32_t>(mono));
2036 }
2037 return NO_ERROR;
2038 } break;
2039
Eric Laurentac9cef52017-06-09 15:46:26 -07002040 case GET_STREAM_VOLUME_DB: {
2041 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2042 audio_stream_type_t stream =
2043 static_cast <audio_stream_type_t>(data.readInt32());
2044 int index = static_cast <int>(data.readInt32());
2045 audio_devices_t device =
2046 static_cast <audio_devices_t>(data.readUint32());
2047 reply->writeFloat(getStreamVolumeDB(stream, index, device));
2048 return NO_ERROR;
2049 }
2050
jiabin81772902018-04-02 17:52:27 -07002051 case GET_SURROUND_FORMATS: {
2052 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2053 unsigned int numSurroundFormatsReq = data.readUint32();
2054 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
2055 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
2056 }
2057 bool reported = data.readBool();
2058 unsigned int numSurroundFormats = numSurroundFormatsReq;
2059 audio_format_t *surroundFormats = (audio_format_t *)calloc(
2060 numSurroundFormats, sizeof(audio_format_t));
2061 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
2062 if (numSurroundFormatsReq > 0 &&
2063 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
2064 free(surroundFormats);
2065 free(surroundFormatsEnabled);
2066 reply->writeInt32(NO_MEMORY);
2067 return NO_ERROR;
2068 }
2069 status_t status = getSurroundFormats(
2070 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
2071 reply->writeInt32(status);
2072
2073 if (status == NO_ERROR) {
2074 reply->writeUint32(numSurroundFormats);
2075 if (numSurroundFormatsReq > numSurroundFormats) {
2076 numSurroundFormatsReq = numSurroundFormats;
2077 }
2078 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
2079 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
2080 }
2081 free(surroundFormats);
2082 free(surroundFormatsEnabled);
2083 return NO_ERROR;
2084 }
2085
2086 case SET_SURROUND_FORMAT_ENABLED: {
2087 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2088 audio_format_t audioFormat = (audio_format_t) data.readInt32();
2089 bool enabled = data.readBool();
2090 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
2091 reply->writeInt32(status);
2092 return NO_ERROR;
2093 }
2094
Arun Mirpuri11029ad2018-12-19 20:45:19 -08002095 case GET_OFFLOAD_FORMATS_A2DP: {
2096 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2097 std::vector<audio_format_t> encodingFormats;
2098 status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
2099 reply->writeInt32(status);
2100 if (status != NO_ERROR) {
2101 return NO_ERROR;
2102 }
2103 reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
2104 for (size_t i = 0; i < encodingFormats.size(); i++)
2105 reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
2106 return NO_ERROR;
2107 }
2108
2109
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07002110 case ADD_STREAM_DEFAULT_EFFECT: {
2111 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2112 effect_uuid_t type;
2113 status_t status = data.read(&type, sizeof(effect_uuid_t));
2114 if (status != NO_ERROR) {
2115 return status;
2116 }
2117 String16 opPackageName;
2118 status = data.readString16(&opPackageName);
2119 if (status != NO_ERROR) {
2120 return status;
2121 }
2122 effect_uuid_t uuid;
2123 status = data.read(&uuid, sizeof(effect_uuid_t));
2124 if (status != NO_ERROR) {
2125 return status;
2126 }
2127 int32_t priority = data.readInt32();
2128 audio_usage_t usage = (audio_usage_t) data.readInt32();
2129 audio_unique_id_t id = 0;
2130 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
2131 opPackageName,
2132 &uuid,
2133 priority,
2134 usage,
2135 &id)));
2136 reply->writeInt32(id);
2137 return NO_ERROR;
2138 }
2139
2140 case REMOVE_STREAM_DEFAULT_EFFECT: {
2141 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2142 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2143 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
2144 return NO_ERROR;
2145 }
2146
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07002147 case ADD_SOURCE_DEFAULT_EFFECT: {
2148 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2149 effect_uuid_t type;
2150 status_t status = data.read(&type, sizeof(effect_uuid_t));
2151 if (status != NO_ERROR) {
2152 return status;
2153 }
2154 String16 opPackageName;
2155 status = data.readString16(&opPackageName);
2156 if (status != NO_ERROR) {
2157 return status;
2158 }
2159 effect_uuid_t uuid;
2160 status = data.read(&uuid, sizeof(effect_uuid_t));
2161 if (status != NO_ERROR) {
2162 return status;
2163 }
2164 int32_t priority = data.readInt32();
2165 audio_source_t source = (audio_source_t) data.readInt32();
2166 audio_unique_id_t id = 0;
2167 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
2168 opPackageName,
2169 &uuid,
2170 priority,
2171 source,
2172 &id)));
2173 reply->writeInt32(id);
2174 return NO_ERROR;
2175 }
2176
2177 case REMOVE_SOURCE_DEFAULT_EFFECT: {
2178 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2179 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2180 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
2181 return NO_ERROR;
2182 }
2183
Eric Laurentb78763e2018-10-17 10:08:02 -07002184 case SET_ASSISTANT_UID: {
2185 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2186 int32_t uid;
2187 status_t status = data.readInt32(&uid);
2188 if (status != NO_ERROR) {
2189 return status;
2190 }
2191 status = setAssistantUid(uid);
2192 reply->writeInt32(static_cast <int32_t>(status));
2193 return NO_ERROR;
2194 }
2195
2196 case SET_A11Y_SERVICES_UIDS: {
2197 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2198 std::vector<uid_t> uids;
2199 int32_t size;
2200 status_t status = data.readInt32(&size);
2201 if (status != NO_ERROR) {
2202 return status;
2203 }
2204 if (size > MAX_ITEMS_PER_LIST) {
2205 size = MAX_ITEMS_PER_LIST;
2206 }
2207 for (int32_t i = 0; i < size; i++) {
2208 int32_t uid;
2209 status = data.readInt32(&uid);
2210 if (status != NO_ERROR) {
2211 return status;
2212 }
2213 uids.push_back(uid);
2214 }
2215 status = setA11yServicesUids(uids);
2216 reply->writeInt32(static_cast <int32_t>(status));
2217 return NO_ERROR;
2218 }
2219
jiabin6012f912018-11-02 17:06:30 -07002220 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
2221 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2222 bool isSupported = isHapticPlaybackSupported();
2223 reply->writeBool(isSupported);
Kevin Rocardb99cc752019-03-21 20:52:24 -07002224 return NO_ERROR;
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08002225 }
2226
2227 case SET_UID_DEVICE_AFFINITY: {
2228 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2229 const uid_t uid = (uid_t) data.readInt32();
2230 Vector<AudioDeviceTypeAddr> devices;
2231 size_t size = (size_t)data.readInt32();
2232 for (size_t i = 0; i < size; i++) {
2233 AudioDeviceTypeAddr device;
2234 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
2235 devices.add(device);
2236 }
2237 }
2238 status_t status = setUidDeviceAffinities(uid, devices);
2239 reply->writeInt32(status);
2240 return NO_ERROR;
2241 }
2242
2243 case REMOVE_UID_DEVICE_AFFINITY: {
2244 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2245 const uid_t uid = (uid_t) data.readInt32();
2246 status_t status = removeUidDeviceAffinities(uid);
2247 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07002248 return NO_ERROR;
2249 }
2250
François Gaffied0ba9ed2018-11-05 11:50:42 +01002251 case LIST_AUDIO_PRODUCT_STRATEGIES: {
2252 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2253 AudioProductStrategyVector strategies;
2254 status_t status = listAudioProductStrategies(strategies);
2255 reply->writeInt32(status);
2256 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01002257 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01002258 }
2259 size_t size = strategies.size();
2260 size_t sizePosition = reply->dataPosition();
2261 reply->writeInt32(size);
2262 size_t finalSize = size;
2263 for (size_t i = 0; i < size; i++) {
2264 size_t position = reply->dataPosition();
2265 if (strategies[i].writeToParcel(reply) != NO_ERROR) {
2266 reply->setDataPosition(position);
2267 finalSize--;
2268 }
2269 }
2270 if (size != finalSize) {
2271 size_t position = reply->dataPosition();
2272 reply->setDataPosition(sizePosition);
2273 reply->writeInt32(finalSize);
2274 reply->setDataPosition(position);
2275 }
2276 return NO_ERROR;
2277 }
2278
2279 case GET_STRATEGY_FOR_ATTRIBUTES: {
2280 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2281 AudioAttributes attributes;
2282 status_t status = attributes.readFromParcel(&data);
2283 if (status != NO_ERROR) {
2284 return status;
2285 }
François Gaffie4b2018b2018-11-07 11:18:59 +01002286 product_strategy_t strategy;
2287 status = getProductStrategyFromAudioAttributes(attributes, strategy);
2288 reply->writeInt32(status);
2289 if (status != NO_ERROR) {
2290 return NO_ERROR;
2291 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01002292 reply->writeUint32(static_cast<int>(strategy));
2293 return NO_ERROR;
2294 }
2295
François Gaffie4b2018b2018-11-07 11:18:59 +01002296 case LIST_AUDIO_VOLUME_GROUPS: {
2297 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2298 AudioVolumeGroupVector groups;
2299 status_t status = listAudioVolumeGroups(groups);
2300 reply->writeInt32(status);
2301 if (status != NO_ERROR) {
2302 return NO_ERROR;
2303 }
2304 size_t size = groups.size();
2305 size_t sizePosition = reply->dataPosition();
2306 reply->writeInt32(size);
2307 size_t finalSize = size;
2308 for (size_t i = 0; i < size; i++) {
2309 size_t position = reply->dataPosition();
2310 if (groups[i].writeToParcel(reply) != NO_ERROR) {
2311 reply->setDataPosition(position);
2312 finalSize--;
2313 }
2314 }
2315 if (size != finalSize) {
2316 size_t position = reply->dataPosition();
2317 reply->setDataPosition(sizePosition);
2318 reply->writeInt32(finalSize);
2319 reply->setDataPosition(position);
2320 }
2321 return NO_ERROR;
2322 }
2323
2324 case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
2325 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2326 AudioAttributes attributes;
2327 status_t status = attributes.readFromParcel(&data);
2328 if (status != NO_ERROR) {
2329 return status;
2330 }
2331 volume_group_t group;
2332 status = getVolumeGroupFromAudioAttributes(attributes, group);
2333 reply->writeInt32(status);
2334 if (status != NO_ERROR) {
2335 return NO_ERROR;
2336 }
2337 reply->writeUint32(static_cast<int>(group));
2338 return NO_ERROR;
2339 }
2340
Kevin Rocardb99cc752019-03-21 20:52:24 -07002341 case SET_ALLOWED_CAPTURE_POLICY: {
2342 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2343 uid_t uid = data.readInt32();
2344 audio_flags_mask_t flags = data.readInt32();
2345 status_t status = setAllowedCapturePolicy(uid, flags);
2346 reply->writeInt32(status);
2347 return NO_ERROR;
2348 }
2349
Eric Laurentc2f1f072009-07-17 12:17:14 -07002350 default:
2351 return BBinder::onTransact(code, data, reply, flags);
2352 }
2353}
2354
Andy Hungb0272092018-04-12 11:06:56 -07002355/** returns true if string overflow was prevented by zero termination */
2356template <size_t size>
2357static bool preventStringOverflow(char (&s)[size]) {
2358 if (strnlen(s, size) < size) return false;
2359 s[size - 1] = '\0';
2360 return true;
2361}
2362
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002363void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
2364{
2365 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
2366 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
2367 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
2368 }
2369 attr->tags[tagsMaxSize - 1] = '\0';
2370}
2371
Andy Hungb0272092018-04-12 11:06:56 -07002372/** returns BAD_VALUE if sanitization was required. */
2373status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
2374{
2375 if (preventStringOverflow(desc->name)
2376 | /* always */ preventStringOverflow(desc->implementor)) {
2377 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
2378 return BAD_VALUE;
2379 }
2380 return NO_ERROR;
2381}
2382
2383/** returns BAD_VALUE if sanitization was required. */
2384status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
2385{
2386 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
2387 preventStringOverflow(config->ext.device.address)) {
2388 return BAD_VALUE;
2389 }
2390 return NO_ERROR;
2391}
2392
Eric Laurentc2f1f072009-07-17 12:17:14 -07002393// ----------------------------------------------------------------------------
2394
Glenn Kasten40bc9062015-03-20 09:09:33 -07002395} // namespace android