blob: 555ac87a58eeb78c465b4dd39bcc64d94ab75de7 [file] [log] [blame]
Eric Laurentc2f1f072009-07-17 12:17:14 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioPolicyService"
19#include <utils/Log.h>
20
21#include <stdint.h>
Eric Laurentac9cef52017-06-09 15:46:26 -070022#include <math.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <sys/types.h>
24
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070026#include <binder/Parcel.h>
Eric Laurent74adca92014-11-05 12:15:36 -080027#include <media/AudioEffect.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070028#include <media/IAudioPolicyService.h>
Eric Laurent3528c932018-02-23 17:17:22 -080029#include <media/TimeCheck.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070030#include <mediautils/ServiceUtilities.h>
Dima Zavin64760242011-05-11 14:15:23 -070031#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070032
Eric Laurentc2f1f072009-07-17 12:17:14 -070033namespace android {
34
35enum {
36 SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
37 GET_DEVICE_CONNECTION_STATE,
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080038 HANDLE_DEVICE_CONFIG_CHANGE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070039 SET_PHONE_STATE,
Glenn Kasten0b07b802012-01-18 14:56:06 -080040 SET_RINGER_MODE, // reserved, no longer used
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 SET_FORCE_USE,
42 GET_FORCE_USE,
43 GET_OUTPUT,
44 START_OUTPUT,
45 STOP_OUTPUT,
46 RELEASE_OUTPUT,
Eric Laurentcaf7f482014-11-25 17:50:47 -080047 GET_INPUT_FOR_ATTR,
Eric Laurentc2f1f072009-07-17 12:17:14 -070048 START_INPUT,
49 STOP_INPUT,
50 RELEASE_INPUT,
51 INIT_STREAM_VOLUME,
52 SET_STREAM_VOLUME,
Eric Laurentde070132010-07-13 04:45:46 -070053 GET_STREAM_VOLUME,
54 GET_STRATEGY_FOR_STREAM,
55 GET_OUTPUT_FOR_EFFECT,
56 REGISTER_EFFECT,
Eric Laurenteda6c362011-02-02 09:33:30 -080057 UNREGISTER_EFFECT,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080058 IS_STREAM_ACTIVE,
Jean-Michel Trivid7086032012-10-10 12:11:16 -070059 IS_SOURCE_ACTIVE,
Glenn Kasten6b2718c2011-02-04 13:54:26 -080060 GET_DEVICES_FOR_STREAM,
Eric Laurentdb7c0792011-08-10 10:37:50 -070061 QUERY_DEFAULT_PRE_PROCESSING,
Jean-Michel Trivi272ab542013-02-04 16:26:02 -080062 SET_EFFECT_ENABLED,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000063 IS_STREAM_ACTIVE_REMOTELY,
Eric Laurent203b1a12014-04-01 10:34:16 -070064 IS_OFFLOAD_SUPPORTED,
65 LIST_AUDIO_PORTS,
66 GET_AUDIO_PORT,
67 CREATE_AUDIO_PATCH,
68 RELEASE_AUDIO_PATCH,
69 LIST_AUDIO_PATCHES,
Eric Laurentb52c1522014-05-20 11:27:36 -070070 SET_AUDIO_PORT_CONFIG,
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -070071 REGISTER_CLIENT,
Eric Laurentdf3dc7e2014-07-27 18:39:40 -070072 GET_OUTPUT_FOR_ATTR,
73 ACQUIRE_SOUNDTRIGGER_SESSION,
Eric Laurentbb6c9a02014-09-25 14:11:47 -070074 RELEASE_SOUNDTRIGGER_SESSION,
Eric Laurentbaac1832014-12-01 17:52:59 -080075 GET_PHONE_STATE,
76 REGISTER_POLICY_MIXES,
Eric Laurent554a2772015-04-10 11:29:24 -070077 START_AUDIO_SOURCE,
Eric Laurente8726fe2015-06-26 09:39:24 -070078 STOP_AUDIO_SOURCE,
79 SET_AUDIO_PORT_CALLBACK_ENABLED,
Andy Hung2ddee192015-12-18 17:34:44 -080080 SET_MASTER_MONO,
81 GET_MASTER_MONO,
jiabin81772902018-04-02 17:52:27 -070082 GET_STREAM_VOLUME_DB,
83 GET_SURROUND_FORMATS,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -070084 SET_SURROUND_FORMAT_ENABLED,
85 ADD_STREAM_DEFAULT_EFFECT,
Ari Hausman-Cohen24628312018-08-13 15:01:09 -070086 REMOVE_STREAM_DEFAULT_EFFECT,
87 ADD_SOURCE_DEFAULT_EFFECT,
Eric Laurentb78763e2018-10-17 10:08:02 -070088 REMOVE_SOURCE_DEFAULT_EFFECT,
89 SET_ASSISTANT_UID,
90 SET_A11Y_SERVICES_UIDS,
jiabin6012f912018-11-02 17:06:30 -070091 IS_HAPTIC_PLAYBACK_SUPPORTED,
Eric Laurentc2f1f072009-07-17 12:17:14 -070092};
93
Eric Laurent1d670b12015-02-06 10:44:24 -080094#define MAX_ITEMS_PER_LIST 1024
95
Eric Laurentc2f1f072009-07-17 12:17:14 -070096class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
97{
98public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070099 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700100 : BpInterface<IAudioPolicyService>(impl)
101 {
102 }
103
104 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700105 audio_devices_t device,
106 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800107 const char *device_address,
108 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109 {
110 Parcel data, reply;
111 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
112 data.writeInt32(static_cast <uint32_t>(device));
113 data.writeInt32(static_cast <uint32_t>(state));
114 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800115 data.writeCString(device_name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700116 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
117 return static_cast <status_t> (reply.readInt32());
118 }
119
Dima Zavinfce7a472011-04-19 22:30:36 -0700120 virtual audio_policy_dev_state_t getDeviceConnectionState(
121 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700122 const char *device_address)
123 {
124 Parcel data, reply;
125 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
126 data.writeInt32(static_cast <uint32_t>(device));
127 data.writeCString(device_address);
128 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700129 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 }
131
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800132 virtual status_t handleDeviceConfigChange(audio_devices_t device,
133 const char *device_address,
134 const char *device_name)
135 {
136 Parcel data, reply;
137 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
138 data.writeInt32(static_cast <uint32_t>(device));
139 data.writeCString(device_address);
140 data.writeCString(device_name);
141 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
142 return static_cast <status_t> (reply.readInt32());
143 }
144
Glenn Kastenf78aee72012-01-04 11:00:47 -0800145 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146 {
147 Parcel data, reply;
148 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
149 data.writeInt32(state);
150 remote()->transact(SET_PHONE_STATE, data, &reply);
151 return static_cast <status_t> (reply.readInt32());
152 }
153
Dima Zavinfce7a472011-04-19 22:30:36 -0700154 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700155 {
156 Parcel data, reply;
157 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
158 data.writeInt32(static_cast <uint32_t>(usage));
159 data.writeInt32(static_cast <uint32_t>(config));
160 remote()->transact(SET_FORCE_USE, data, &reply);
161 return static_cast <status_t> (reply.readInt32());
162 }
163
Dima Zavinfce7a472011-04-19 22:30:36 -0700164 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700165 {
166 Parcel data, reply;
167 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
168 data.writeInt32(static_cast <uint32_t>(usage));
169 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700170 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700171 }
172
Eric Laurentf4e63452017-11-06 19:31:46 +0000173 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700174 {
175 Parcel data, reply;
176 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
177 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700178 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700179 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700180 }
181
Eric Laurente83b55d2014-11-14 10:06:21 -0800182 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
183 audio_io_handle_t *output,
184 audio_session_t session,
185 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200186 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700187 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800188 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800189 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700190 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800191 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700192 {
193 Parcel data, reply;
194 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
195 if (attr == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800196 if (stream == NULL) {
197 ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
198 return BAD_VALUE;
199 }
200 if (*stream == AUDIO_STREAM_DEFAULT) {
201 ALOGE("getOutputForAttr unspecified stream type");
202 return BAD_VALUE;
203 }
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700204 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800205 if (output == NULL) {
206 ALOGE("getOutputForAttr NULL output - shouldn't happen");
207 return BAD_VALUE;
208 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700209 if (selectedDeviceId == NULL) {
210 ALOGE("getOutputForAttr NULL selectedDeviceId - shouldn't happen");
211 return BAD_VALUE;
212 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800213 if (portId == NULL) {
214 ALOGE("getOutputForAttr NULL portId - shouldn't happen");
215 return BAD_VALUE;
216 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800217 if (attr == NULL) {
218 data.writeInt32(0);
219 } else {
220 data.writeInt32(1);
221 data.write(attr, sizeof(audio_attributes_t));
222 }
223 data.writeInt32(session);
224 if (stream == NULL) {
225 data.writeInt32(0);
226 } else {
227 data.writeInt32(1);
228 data.writeInt32(*stream);
229 }
Nadav Bar766fb022018-01-07 12:18:03 +0200230 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700231 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800232 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700233 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700234 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800235 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800236 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
237 if (status != NO_ERROR) {
238 return status;
239 }
240 status = (status_t)reply.readInt32();
241 if (status != NO_ERROR) {
242 return status;
243 }
244 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800245 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800246 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800247 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800248 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700249 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 return status;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700252 }
253
Eric Laurentd7fe0862018-07-14 16:48:01 -0700254 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700258 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 remote()->transact(START_OUTPUT, data, &reply);
260 return static_cast <status_t> (reply.readInt32());
261 }
262
Eric Laurentd7fe0862018-07-14 16:48:01 -0700263 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700267 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700268 remote()->transact(STOP_OUTPUT, data, &reply);
269 return static_cast <status_t> (reply.readInt32());
270 }
271
Eric Laurentd7fe0862018-07-14 16:48:01 -0700272 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700276 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 remote()->transact(RELEASE_OUTPUT, data, &reply);
278 }
279
Eric Laurentcaf7f482014-11-25 17:50:47 -0800280 virtual status_t getInputForAttr(const audio_attributes_t *attr,
281 audio_io_handle_t *input,
282 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700283 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700284 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800285 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800286 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600287 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700288 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800289 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800293 if (attr == NULL) {
294 ALOGE("getInputForAttr NULL attr - shouldn't happen");
295 return BAD_VALUE;
296 }
297 if (input == NULL) {
298 ALOGE("getInputForAttr NULL input - shouldn't happen");
299 return BAD_VALUE;
300 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700301 if (selectedDeviceId == NULL) {
302 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
303 return BAD_VALUE;
304 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800305 if (portId == NULL) {
306 ALOGE("getInputForAttr NULL portId - shouldn't happen");
307 return BAD_VALUE;
308 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800309 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700310 data.writeInt32(*input);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800311 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700312 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700313 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800314 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800315 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700316 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700317 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800318 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800319 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
320 if (status != NO_ERROR) {
321 return status;
322 }
323 status = reply.readInt32();
324 if (status != NO_ERROR) {
325 return status;
326 }
327 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700328 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800329 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800330 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700331 }
332
Eric Laurentfee19762018-01-29 18:44:13 -0800333 virtual status_t startInput(audio_port_handle_t portId,
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800334 bool *silenced)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800338 data.writeInt32(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800339 data.writeInt32(*silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800341 status_t status = static_cast <status_t> (reply.readInt32());
342 *silenced = reply.readInt32() == 1;
343 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700344 }
345
Eric Laurentfee19762018-01-29 18:44:13 -0800346 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800350 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 remote()->transact(STOP_INPUT, data, &reply);
352 return static_cast <status_t> (reply.readInt32());
353 }
354
Eric Laurentfee19762018-01-29 18:44:13 -0800355 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800359 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 remote()->transact(RELEASE_INPUT, data, &reply);
361 }
362
Dima Zavinfce7a472011-04-19 22:30:36 -0700363 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 int indexMin,
365 int indexMax)
366 {
367 Parcel data, reply;
368 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
369 data.writeInt32(static_cast <uint32_t>(stream));
370 data.writeInt32(indexMin);
371 data.writeInt32(indexMax);
372 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
373 return static_cast <status_t> (reply.readInt32());
374 }
375
Eric Laurent83844cc2011-11-18 16:43:31 -0800376 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
377 int index,
378 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700379 {
380 Parcel data, reply;
381 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
382 data.writeInt32(static_cast <uint32_t>(stream));
383 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800384 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700385 remote()->transact(SET_STREAM_VOLUME, data, &reply);
386 return static_cast <status_t> (reply.readInt32());
387 }
388
Eric Laurent83844cc2011-11-18 16:43:31 -0800389 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
390 int *index,
391 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
395 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800396 data.writeInt32(static_cast <uint32_t>(device));
397
Eric Laurentc2f1f072009-07-17 12:17:14 -0700398 remote()->transact(GET_STREAM_VOLUME, data, &reply);
399 int lIndex = reply.readInt32();
400 if (index) *index = lIndex;
401 return static_cast <status_t> (reply.readInt32());
402 }
Eric Laurentde070132010-07-13 04:45:46 -0700403
Dima Zavinfce7a472011-04-19 22:30:36 -0700404 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
408 data.writeInt32(static_cast <uint32_t>(stream));
409 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
410 return reply.readInt32();
411 }
412
Eric Laurent63742522012-03-08 13:42:42 -0800413 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
417 data.writeInt32(static_cast <uint32_t>(stream));
418 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800419 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800420 }
421
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700422 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
426 data.write(desc, sizeof(effect_descriptor_t));
427 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
428 return static_cast <audio_io_handle_t> (reply.readInt32());
429 }
430
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700431 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700432 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700433 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800434 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700435 int id)
436 {
437 Parcel data, reply;
438 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
439 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700440 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700441 data.writeInt32(strategy);
442 data.writeInt32(session);
443 data.writeInt32(id);
444 remote()->transact(REGISTER_EFFECT, data, &reply);
445 return static_cast <status_t> (reply.readInt32());
446 }
447
448 virtual status_t unregisterEffect(int id)
449 {
450 Parcel data, reply;
451 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
452 data.writeInt32(id);
453 remote()->transact(UNREGISTER_EFFECT, data, &reply);
454 return static_cast <status_t> (reply.readInt32());
455 }
456
Eric Laurentdb7c0792011-08-10 10:37:50 -0700457 virtual status_t setEffectEnabled(int id, bool enabled)
458 {
459 Parcel data, reply;
460 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
461 data.writeInt32(id);
462 data.writeInt32(enabled);
463 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
464 return static_cast <status_t> (reply.readInt32());
465 }
466
Glenn Kastenfff6d712012-01-12 16:38:12 -0800467 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800471 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800472 data.writeInt32(inPastMs);
473 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
474 return reply.readInt32();
475 }
Eric Laurent57dae992011-07-24 13:36:09 -0700476
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800477 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
478 {
479 Parcel data, reply;
480 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
481 data.writeInt32((int32_t) stream);
482 data.writeInt32(inPastMs);
483 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
484 return reply.readInt32();
485 }
486
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700487 virtual bool isSourceActive(audio_source_t source) const
488 {
489 Parcel data, reply;
490 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
491 data.writeInt32((int32_t) source);
492 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
493 return reply.readInt32();
494 }
495
Glenn Kastend848eb42016-03-08 13:42:11 -0800496 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700497 effect_descriptor_t *descriptors,
498 uint32_t *count)
499 {
500 if (descriptors == NULL || count == NULL) {
501 return BAD_VALUE;
502 }
503 Parcel data, reply;
504 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
505 data.writeInt32(audioSession);
506 data.writeInt32(*count);
507 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
508 if (status != NO_ERROR) {
509 return status;
510 }
511 status = static_cast <status_t> (reply.readInt32());
512 uint32_t retCount = reply.readInt32();
513 if (retCount != 0) {
514 uint32_t numDesc = (retCount < *count) ? retCount : *count;
515 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
516 }
517 *count = retCount;
518 return status;
519 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000520
521 virtual bool isOffloadSupported(const audio_offload_info_t& info)
522 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
525 data.write(&info, sizeof(audio_offload_info_t));
526 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700527 return reply.readInt32();
528 }
529
530 virtual status_t listAudioPorts(audio_port_role_t role,
531 audio_port_type_t type,
532 unsigned int *num_ports,
533 struct audio_port *ports,
534 unsigned int *generation)
535 {
536 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
537 generation == NULL) {
538 return BAD_VALUE;
539 }
540 Parcel data, reply;
541 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
542 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
543 data.writeInt32(role);
544 data.writeInt32(type);
545 data.writeInt32(numPortsReq);
546 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
547 if (status == NO_ERROR) {
548 status = (status_t)reply.readInt32();
549 *num_ports = (unsigned int)reply.readInt32();
550 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700551 if (status == NO_ERROR) {
552 if (numPortsReq > *num_ports) {
553 numPortsReq = *num_ports;
554 }
555 if (numPortsReq > 0) {
556 reply.read(ports, numPortsReq * sizeof(struct audio_port));
557 }
558 *generation = reply.readInt32();
559 }
560 return status;
561 }
562
563 virtual status_t getAudioPort(struct audio_port *port)
564 {
565 if (port == NULL) {
566 return BAD_VALUE;
567 }
568 Parcel data, reply;
569 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
570 data.write(port, sizeof(struct audio_port));
571 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
572 if (status != NO_ERROR ||
573 (status = (status_t)reply.readInt32()) != NO_ERROR) {
574 return status;
575 }
576 reply.read(port, sizeof(struct audio_port));
577 return status;
578 }
579
580 virtual status_t createAudioPatch(const struct audio_patch *patch,
581 audio_patch_handle_t *handle)
582 {
583 if (patch == NULL || handle == NULL) {
584 return BAD_VALUE;
585 }
586 Parcel data, reply;
587 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
588 data.write(patch, sizeof(struct audio_patch));
589 data.write(handle, sizeof(audio_patch_handle_t));
590 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
591 if (status != NO_ERROR ||
592 (status = (status_t)reply.readInt32()) != NO_ERROR) {
593 return status;
594 }
595 reply.read(handle, sizeof(audio_patch_handle_t));
596 return status;
597 }
598
599 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
600 {
601 Parcel data, reply;
602 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
603 data.write(&handle, sizeof(audio_patch_handle_t));
604 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
605 if (status != NO_ERROR) {
606 status = (status_t)reply.readInt32();
607 }
608 return status;
609 }
610
611 virtual status_t listAudioPatches(unsigned int *num_patches,
612 struct audio_patch *patches,
613 unsigned int *generation)
614 {
615 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
616 generation == NULL) {
617 return BAD_VALUE;
618 }
619 Parcel data, reply;
620 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
621 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
622 data.writeInt32(numPatchesReq);
623 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
624 if (status == NO_ERROR) {
625 status = (status_t)reply.readInt32();
626 *num_patches = (unsigned int)reply.readInt32();
627 }
628 if (status == NO_ERROR) {
629 if (numPatchesReq > *num_patches) {
630 numPatchesReq = *num_patches;
631 }
632 if (numPatchesReq > 0) {
633 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
634 }
635 *generation = reply.readInt32();
636 }
637 return status;
638 }
639
640 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
641 {
642 if (config == NULL) {
643 return BAD_VALUE;
644 }
645 Parcel data, reply;
646 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
647 data.write(config, sizeof(struct audio_port_config));
648 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
649 if (status != NO_ERROR) {
650 status = (status_t)reply.readInt32();
651 }
652 return status;
653 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700654
Eric Laurentb52c1522014-05-20 11:27:36 -0700655 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
656 {
657 Parcel data, reply;
658 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800659 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700660 remote()->transact(REGISTER_CLIENT, data, &reply);
661 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700662
Eric Laurente8726fe2015-06-26 09:39:24 -0700663 virtual void setAudioPortCallbacksEnabled(bool enabled)
664 {
665 Parcel data, reply;
666 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
667 data.writeInt32(enabled ? 1 : 0);
668 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
669 }
670
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700671 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
672 audio_io_handle_t *ioHandle,
673 audio_devices_t *device)
674 {
675 if (session == NULL || ioHandle == NULL || device == NULL) {
676 return BAD_VALUE;
677 }
678 Parcel data, reply;
679 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
680 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
681 if (status != NO_ERROR) {
682 return status;
683 }
684 status = (status_t)reply.readInt32();
685 if (status == NO_ERROR) {
686 *session = (audio_session_t)reply.readInt32();
687 *ioHandle = (audio_io_handle_t)reply.readInt32();
688 *device = (audio_devices_t)reply.readInt32();
689 }
690 return status;
691 }
692
693 virtual status_t releaseSoundTriggerSession(audio_session_t session)
694 {
695 Parcel data, reply;
696 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
697 data.writeInt32(session);
698 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
699 if (status != NO_ERROR) {
700 return status;
701 }
702 return (status_t)reply.readInt32();
703 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700704
705 virtual audio_mode_t getPhoneState()
706 {
707 Parcel data, reply;
708 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
709 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
710 if (status != NO_ERROR) {
711 return AUDIO_MODE_INVALID;
712 }
713 return (audio_mode_t)reply.readInt32();
714 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800715
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700716 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800717 {
718 Parcel data, reply;
719 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
720 data.writeInt32(registration ? 1 : 0);
721 size_t size = mixes.size();
722 if (size > MAX_MIXES_PER_POLICY) {
723 size = MAX_MIXES_PER_POLICY;
724 }
725 size_t sizePosition = data.dataPosition();
726 data.writeInt32(size);
727 size_t finalSize = size;
728 for (size_t i = 0; i < size; i++) {
729 size_t position = data.dataPosition();
730 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
731 data.setDataPosition(position);
732 finalSize--;
733 }
734 }
735 if (size != finalSize) {
736 size_t position = data.dataPosition();
737 data.setDataPosition(sizePosition);
738 data.writeInt32(finalSize);
739 data.setDataPosition(position);
740 }
741 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
742 if (status == NO_ERROR) {
743 status = (status_t)reply.readInt32();
744 }
745 return status;
746 }
Eric Laurent554a2772015-04-10 11:29:24 -0700747
748 virtual status_t startAudioSource(const struct audio_port_config *source,
749 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700750 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700751 {
752 Parcel data, reply;
753 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700754 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700755 return BAD_VALUE;
756 }
757 data.write(source, sizeof(struct audio_port_config));
758 data.write(attributes, sizeof(audio_attributes_t));
759 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
760 if (status != NO_ERROR) {
761 return status;
762 }
763 status = (status_t)reply.readInt32();
764 if (status != NO_ERROR) {
765 return status;
766 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700767 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700768 return status;
769 }
770
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700771 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700772 {
773 Parcel data, reply;
774 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700775 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700776 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
777 if (status != NO_ERROR) {
778 return status;
779 }
780 status = (status_t)reply.readInt32();
781 return status;
782 }
Andy Hung2ddee192015-12-18 17:34:44 -0800783
784 virtual status_t setMasterMono(bool mono)
785 {
786 Parcel data, reply;
787 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
788 data.writeInt32(static_cast<int32_t>(mono));
789 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
790 if (status != NO_ERROR) {
791 return status;
792 }
793 return static_cast<status_t>(reply.readInt32());
794 }
795
796 virtual status_t getMasterMono(bool *mono)
797 {
798 if (mono == nullptr) {
799 return BAD_VALUE;
800 }
801 Parcel data, reply;
802 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
803
804 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
805 if (status != NO_ERROR) {
806 return status;
807 }
808 status = static_cast<status_t>(reply.readInt32());
809 if (status == NO_ERROR) {
810 *mono = static_cast<bool>(reply.readInt32());
811 }
812 return status;
813 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700814
815 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
816 {
817 Parcel data, reply;
818 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
819 data.writeInt32(static_cast <int32_t>(stream));
820 data.writeInt32(static_cast <int32_t>(index));
821 data.writeUint32(static_cast <uint32_t>(device));
822 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
823 if (status != NO_ERROR) {
824 return NAN;
825 }
826 return reply.readFloat();
827 }
jiabin81772902018-04-02 17:52:27 -0700828
829 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
830 audio_format_t *surroundFormats,
831 bool *surroundFormatsEnabled,
832 bool reported)
833 {
834 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
835 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
836 return BAD_VALUE;
837 }
838 Parcel data, reply;
839 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
840 unsigned int numSurroundFormatsReq = *numSurroundFormats;
841 data.writeUint32(numSurroundFormatsReq);
842 data.writeBool(reported);
843 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
844 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
845 *numSurroundFormats = reply.readUint32();
846 }
847 if (status == NO_ERROR) {
848 if (numSurroundFormatsReq > *numSurroundFormats) {
849 numSurroundFormatsReq = *numSurroundFormats;
850 }
851 if (numSurroundFormatsReq > 0) {
852 status = reply.read(surroundFormats,
853 numSurroundFormatsReq * sizeof(audio_format_t));
854 if (status != NO_ERROR) {
855 return status;
856 }
857 status = reply.read(surroundFormatsEnabled,
858 numSurroundFormatsReq * sizeof(bool));
859 }
860 }
861 return status;
862 }
863
864 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
865 {
866 Parcel data, reply;
867 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
868 data.writeInt32(audioFormat);
869 data.writeBool(enabled);
870 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
871 if (status != NO_ERROR) {
872 return status;
873 }
874 return reply.readInt32();
875 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700876
877 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
878 const String16& opPackageName,
879 const effect_uuid_t *uuid,
880 int32_t priority,
881 audio_usage_t usage,
882 audio_unique_id_t* id)
883 {
884 Parcel data, reply;
885 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
886 data.write(type, sizeof(effect_uuid_t));
887 data.writeString16(opPackageName);
888 data.write(uuid, sizeof(effect_uuid_t));
889 data.writeInt32(priority);
890 data.writeInt32((int32_t) usage);
891 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
892 if (status != NO_ERROR) {
893 return status;
894 }
895 status = static_cast <status_t> (reply.readInt32());
896 *id = reply.readInt32();
897 return status;
898 }
899
900 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
901 {
902 Parcel data, reply;
903 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
904 data.writeInt32(id);
905 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
906 if (status != NO_ERROR) {
907 return status;
908 }
909 return static_cast <status_t> (reply.readInt32());
910 }
911
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700912 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
913 const String16& opPackageName,
914 const effect_uuid_t *uuid,
915 int32_t priority,
916 audio_source_t source,
917 audio_unique_id_t* id)
918 {
919 Parcel data, reply;
920 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
921 data.write(type, sizeof(effect_uuid_t));
922 data.writeString16(opPackageName);
923 data.write(uuid, sizeof(effect_uuid_t));
924 data.writeInt32(priority);
925 data.writeInt32((int32_t) source);
926 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
927 if (status != NO_ERROR) {
928 return status;
929 }
930 status = static_cast <status_t> (reply.readInt32());
931 *id = reply.readInt32();
932 return status;
933 }
934
935 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
936 {
937 Parcel data, reply;
938 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
939 data.writeInt32(id);
940 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
941 if (status != NO_ERROR) {
942 return status;
943 }
944 return static_cast <status_t> (reply.readInt32());
945 }
946
Eric Laurentb78763e2018-10-17 10:08:02 -0700947 virtual status_t setAssistantUid(uid_t uid)
948 {
949 Parcel data, reply;
950 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
951 data.writeInt32(uid);
952 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
953 if (status != NO_ERROR) {
954 return status;
955 }
956 return static_cast <status_t> (reply.readInt32());
957 }
958
959 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
960 {
961 Parcel data, reply;
962 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
963 data.writeInt32(uids.size());
964 for (auto uid : uids) {
965 data.writeInt32(uid);
966 }
967 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
968 if (status != NO_ERROR) {
969 return status;
970 }
971 return static_cast <status_t> (reply.readInt32());
972 }
973
jiabin6012f912018-11-02 17:06:30 -0700974 virtual bool isHapticPlaybackSupported()
975 {
976 Parcel data, reply;
977 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
978 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
979 if (status != NO_ERROR) {
980 return false;
981 }
982 return reply.readBool();
983 }
984
Eric Laurentc2f1f072009-07-17 12:17:14 -0700985};
986
987IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
988
989// ----------------------------------------------------------------------
990
Eric Laurentc2f1f072009-07-17 12:17:14 -0700991status_t BnAudioPolicyService::onTransact(
992 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
993{
Eric Laurentb1cc36b2017-12-11 12:14:16 -0800994 // make sure transactions reserved to AudioFlinger do not come from other processes
995 switch (code) {
996 case START_OUTPUT:
997 case STOP_OUTPUT:
998 case RELEASE_OUTPUT:
999 case GET_INPUT_FOR_ATTR:
1000 case START_INPUT:
1001 case STOP_INPUT:
1002 case RELEASE_INPUT:
1003 case GET_STRATEGY_FOR_STREAM:
1004 case GET_OUTPUT_FOR_EFFECT:
1005 case REGISTER_EFFECT:
1006 case UNREGISTER_EFFECT:
1007 case SET_EFFECT_ENABLED:
1008 case GET_OUTPUT_FOR_ATTR:
1009 case ACQUIRE_SOUNDTRIGGER_SESSION:
1010 case RELEASE_SOUNDTRIGGER_SESSION:
1011 ALOGW("%s: transaction %d received from PID %d",
1012 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001013 // return status only for non void methods
1014 switch (code) {
1015 case RELEASE_OUTPUT:
1016 case RELEASE_INPUT:
1017 break;
1018 default:
1019 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1020 break;
1021 }
1022 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001023 default:
1024 break;
1025 }
1026
Eric Laurent4980df22018-01-26 18:04:09 -08001027 // make sure the following transactions come from system components
1028 switch (code) {
1029 case SET_DEVICE_CONNECTION_STATE:
1030 case HANDLE_DEVICE_CONFIG_CHANGE:
1031 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001032//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1033// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001034 case INIT_STREAM_VOLUME:
1035 case SET_STREAM_VOLUME:
1036 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001037 case SET_MASTER_MONO:
1038 case START_AUDIO_SOURCE:
jiabin81772902018-04-02 17:52:27 -07001039 case STOP_AUDIO_SOURCE:
1040 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001041 case SET_SURROUND_FORMAT_ENABLED:
1042 case SET_ASSISTANT_UID:
1043 case SET_A11Y_SERVICES_UIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001044 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001045 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1046 __func__, code, IPCThreadState::self()->getCallingPid(),
1047 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001048 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1049 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001050 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001051 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001052 default:
1053 break;
1054 }
1055
Eric Laurent39b09b52018-06-29 12:24:40 -07001056 std::string tag("IAudioPolicyService command " + std::to_string(code));
1057 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001058
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001059 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001060 case SET_DEVICE_CONNECTION_STATE: {
1061 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001062 audio_devices_t device =
1063 static_cast <audio_devices_t>(data.readInt32());
1064 audio_policy_dev_state_t state =
1065 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001066 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001067 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001068 if (device_address == nullptr || device_name == nullptr) {
1069 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1070 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1071 } else {
1072 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1073 state,
1074 device_address,
1075 device_name)));
1076 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001077 return NO_ERROR;
1078 } break;
1079
1080 case GET_DEVICE_CONNECTION_STATE: {
1081 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001082 audio_devices_t device =
1083 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001084 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001085 if (device_address == nullptr) {
1086 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1087 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1088 } else {
1089 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1090 device_address)));
1091 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001092 return NO_ERROR;
1093 } break;
1094
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001095 case HANDLE_DEVICE_CONFIG_CHANGE: {
1096 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1097 audio_devices_t device =
1098 static_cast <audio_devices_t>(data.readInt32());
1099 const char *device_address = data.readCString();
1100 const char *device_name = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001101 if (device_address == nullptr || device_name == nullptr) {
1102 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1103 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1104 } else {
1105 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1106 device_address,
1107 device_name)));
1108 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001109 return NO_ERROR;
1110 } break;
1111
Eric Laurentc2f1f072009-07-17 12:17:14 -07001112 case SET_PHONE_STATE: {
1113 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001114 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1115 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001116 return NO_ERROR;
1117 } break;
1118
Eric Laurentc2f1f072009-07-17 12:17:14 -07001119 case SET_FORCE_USE: {
1120 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001121 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1122 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001123 audio_policy_forced_cfg_t config =
1124 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001125 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1126 return NO_ERROR;
1127 } break;
1128
1129 case GET_FORCE_USE: {
1130 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001131 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1132 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1134 return NO_ERROR;
1135 } break;
1136
1137 case GET_OUTPUT: {
1138 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001139 audio_stream_type_t stream =
1140 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001141 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001142 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001143 return NO_ERROR;
1144 } break;
1145
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001146 case GET_OUTPUT_FOR_ATTR: {
1147 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001148 audio_attributes_t attr = {};
Eric Laurente83b55d2014-11-14 10:06:21 -08001149 bool hasAttributes = data.readInt32() != 0;
1150 if (hasAttributes) {
1151 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001152 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001153 }
1154 audio_session_t session = (audio_session_t)data.readInt32();
1155 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1156 bool hasStream = data.readInt32() != 0;
1157 if (hasStream) {
1158 stream = (audio_stream_type_t)data.readInt32();
1159 }
Nadav Bar766fb022018-01-07 12:18:03 +02001160 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001161 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001162 audio_config_t config;
1163 memset(&config, 0, sizeof(audio_config_t));
1164 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001165 audio_output_flags_t flags =
1166 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001167 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001168 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001169 audio_io_handle_t output = 0;
Eric Laurente83b55d2014-11-14 10:06:21 -08001170 status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
Nadav Bar766fb022018-01-07 12:18:03 +02001171 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001172 &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001173 flags, &selectedDeviceId, &portId);
Eric Laurente83b55d2014-11-14 10:06:21 -08001174 reply->writeInt32(status);
1175 reply->writeInt32(output);
1176 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001177 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001178 reply->writeInt32(portId);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001179 return NO_ERROR;
1180 } break;
1181
Eric Laurentc2f1f072009-07-17 12:17:14 -07001182 case START_OUTPUT: {
1183 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001184 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1185 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001186 return NO_ERROR;
1187 } break;
1188
1189 case STOP_OUTPUT: {
1190 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001191 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1192 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001193 return NO_ERROR;
1194 } break;
1195
1196 case RELEASE_OUTPUT: {
1197 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001198 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1199 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001200 return NO_ERROR;
1201 } break;
1202
Eric Laurentcaf7f482014-11-25 17:50:47 -08001203 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001204 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001205 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001206 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001207 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001208 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001209 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001210 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001211 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001212 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001213 audio_config_base_t config;
1214 memset(&config, 0, sizeof(audio_config_base_t));
1215 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001216 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001217 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001218 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001219 status_t status = getInputForAttr(&attr, &input, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001220 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001221 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001222 reply->writeInt32(status);
1223 if (status == NO_ERROR) {
1224 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001225 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001226 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001227 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001228 return NO_ERROR;
1229 } break;
1230
1231 case START_INPUT: {
1232 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001233 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001234 bool silenced = data.readInt32() == 1;
Eric Laurentfee19762018-01-29 18:44:13 -08001235 status_t status = startInput(portId, &silenced);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001236 reply->writeInt32(static_cast <uint32_t>(status));
1237 reply->writeInt32(silenced ? 1 : 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001238 return NO_ERROR;
1239 } break;
1240
1241 case STOP_INPUT: {
1242 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001243 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1244 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001245 return NO_ERROR;
1246 } break;
1247
1248 case RELEASE_INPUT: {
1249 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001250 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1251 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001252 return NO_ERROR;
1253 } break;
1254
1255 case INIT_STREAM_VOLUME: {
1256 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001257 audio_stream_type_t stream =
1258 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001259 int indexMin = data.readInt32();
1260 int indexMax = data.readInt32();
1261 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1262 return NO_ERROR;
1263 } break;
1264
1265 case SET_STREAM_VOLUME: {
1266 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001267 audio_stream_type_t stream =
1268 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001269 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001270 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1271 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1272 index,
1273 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001274 return NO_ERROR;
1275 } break;
1276
1277 case GET_STREAM_VOLUME: {
1278 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001279 audio_stream_type_t stream =
1280 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001281 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001282 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001283 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001284 reply->writeInt32(index);
1285 reply->writeInt32(static_cast <uint32_t>(status));
1286 return NO_ERROR;
1287 } break;
1288
Eric Laurentde070132010-07-13 04:45:46 -07001289 case GET_STRATEGY_FOR_STREAM: {
1290 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001291 audio_stream_type_t stream =
1292 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentde070132010-07-13 04:45:46 -07001293 reply->writeInt32(getStrategyForStream(stream));
1294 return NO_ERROR;
1295 } break;
1296
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001297 case GET_DEVICES_FOR_STREAM: {
1298 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001299 audio_stream_type_t stream =
1300 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001301 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1302 return NO_ERROR;
1303 } break;
1304
Eric Laurentde070132010-07-13 04:45:46 -07001305 case GET_OUTPUT_FOR_EFFECT: {
1306 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001307 effect_descriptor_t desc = {};
1308 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1309 android_errorWriteLog(0x534e4554, "73126106");
1310 }
1311 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001312 audio_io_handle_t output = getOutputForEffect(&desc);
1313 reply->writeInt32(static_cast <int>(output));
1314 return NO_ERROR;
1315 } break;
1316
1317 case REGISTER_EFFECT: {
1318 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001319 effect_descriptor_t desc = {};
1320 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1321 android_errorWriteLog(0x534e4554, "73126106");
1322 }
1323 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001324 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001325 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001326 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001327 int id = data.readInt32();
1328 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001329 io,
Eric Laurentde070132010-07-13 04:45:46 -07001330 strategy,
1331 session,
1332 id)));
1333 return NO_ERROR;
1334 } break;
1335
1336 case UNREGISTER_EFFECT: {
1337 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1338 int id = data.readInt32();
1339 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1340 return NO_ERROR;
1341 } break;
1342
Eric Laurentdb7c0792011-08-10 10:37:50 -07001343 case SET_EFFECT_ENABLED: {
1344 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1345 int id = data.readInt32();
1346 bool enabled = static_cast <bool>(data.readInt32());
1347 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1348 return NO_ERROR;
1349 } break;
1350
Eric Laurenteda6c362011-02-02 09:33:30 -08001351 case IS_STREAM_ACTIVE: {
1352 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001353 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001354 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001355 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001356 return NO_ERROR;
1357 } break;
1358
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001359 case IS_STREAM_ACTIVE_REMOTELY: {
1360 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1361 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1362 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001363 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001364 return NO_ERROR;
1365 } break;
1366
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001367 case IS_SOURCE_ACTIVE: {
1368 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1369 audio_source_t source = (audio_source_t) data.readInt32();
1370 reply->writeInt32( isSourceActive(source));
1371 return NO_ERROR;
1372 }
1373
Eric Laurent57dae992011-07-24 13:36:09 -07001374 case QUERY_DEFAULT_PRE_PROCESSING: {
1375 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001376 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001377 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001378 if (count > AudioEffect::kMaxPreProcessing) {
1379 count = AudioEffect::kMaxPreProcessing;
1380 }
Eric Laurent57dae992011-07-24 13:36:09 -07001381 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001382 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001383 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1384 reply->writeInt32(status);
1385 if (status != NO_ERROR && status != NO_MEMORY) {
1386 retCount = 0;
1387 }
1388 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001389 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001390 if (retCount < count) {
1391 count = retCount;
1392 }
1393 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1394 }
1395 delete[] descriptors;
1396 return status;
1397 }
1398
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001399 case IS_OFFLOAD_SUPPORTED: {
1400 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001401 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001402 data.read(&info, sizeof(audio_offload_info_t));
1403 bool isSupported = isOffloadSupported(info);
1404 reply->writeInt32(isSupported);
1405 return NO_ERROR;
1406 }
1407
Eric Laurent203b1a12014-04-01 10:34:16 -07001408 case LIST_AUDIO_PORTS: {
1409 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1410 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1411 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1412 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001413 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1414 numPortsReq = MAX_ITEMS_PER_LIST;
1415 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001416 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001417 struct audio_port *ports =
1418 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001419 if (ports == NULL) {
1420 reply->writeInt32(NO_MEMORY);
1421 reply->writeInt32(0);
1422 return NO_ERROR;
1423 }
1424 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001425 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1426 reply->writeInt32(status);
1427 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001428
1429 if (status == NO_ERROR) {
1430 if (numPortsReq > numPorts) {
1431 numPortsReq = numPorts;
1432 }
1433 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1434 reply->writeInt32(generation);
1435 }
1436 free(ports);
1437 return NO_ERROR;
1438 }
1439
1440 case GET_AUDIO_PORT: {
1441 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001442 struct audio_port port = {};
1443 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1444 ALOGE("b/23912202");
1445 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001446 status_t status = getAudioPort(&port);
1447 reply->writeInt32(status);
1448 if (status == NO_ERROR) {
1449 reply->write(&port, sizeof(struct audio_port));
1450 }
1451 return NO_ERROR;
1452 }
1453
1454 case CREATE_AUDIO_PATCH: {
1455 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001456 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001457 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001458 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001459 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1460 ALOGE("b/23912202");
1461 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001462 status_t status = createAudioPatch(&patch, &handle);
1463 reply->writeInt32(status);
1464 if (status == NO_ERROR) {
1465 reply->write(&handle, sizeof(audio_patch_handle_t));
1466 }
1467 return NO_ERROR;
1468 }
1469
1470 case RELEASE_AUDIO_PATCH: {
1471 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001472 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001473 data.read(&handle, sizeof(audio_patch_handle_t));
1474 status_t status = releaseAudioPatch(handle);
1475 reply->writeInt32(status);
1476 return NO_ERROR;
1477 }
1478
1479 case LIST_AUDIO_PATCHES: {
1480 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1481 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001482 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1483 numPatchesReq = MAX_ITEMS_PER_LIST;
1484 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001485 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001486 struct audio_patch *patches =
1487 (struct audio_patch *)calloc(numPatchesReq,
1488 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001489 if (patches == NULL) {
1490 reply->writeInt32(NO_MEMORY);
1491 reply->writeInt32(0);
1492 return NO_ERROR;
1493 }
1494 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001495 status_t status = listAudioPatches(&numPatches, patches, &generation);
1496 reply->writeInt32(status);
1497 reply->writeInt32(numPatches);
1498 if (status == NO_ERROR) {
1499 if (numPatchesReq > numPatches) {
1500 numPatchesReq = numPatches;
1501 }
1502 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1503 reply->writeInt32(generation);
1504 }
1505 free(patches);
1506 return NO_ERROR;
1507 }
1508
1509 case SET_AUDIO_PORT_CONFIG: {
1510 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001511 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001512 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001513 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001514 status_t status = setAudioPortConfig(&config);
1515 reply->writeInt32(status);
1516 return NO_ERROR;
1517 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001518
Eric Laurentb52c1522014-05-20 11:27:36 -07001519 case REGISTER_CLIENT: {
1520 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1521 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1522 data.readStrongBinder());
1523 registerClient(client);
1524 return NO_ERROR;
1525 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001526
Eric Laurente8726fe2015-06-26 09:39:24 -07001527 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1528 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1529 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1530 return NO_ERROR;
1531 } break;
1532
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001533 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1534 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1535 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1536 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001537 audio_session_t session = AUDIO_SESSION_NONE;
1538 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1539 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001540 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1541 reply->writeInt32(status);
1542 if (status == NO_ERROR) {
1543 reply->writeInt32(session);
1544 reply->writeInt32(ioHandle);
1545 reply->writeInt32(device);
1546 }
1547 return NO_ERROR;
1548 } break;
1549
1550 case RELEASE_SOUNDTRIGGER_SESSION: {
1551 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1552 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1553 data.readStrongBinder());
1554 audio_session_t session = (audio_session_t)data.readInt32();
1555 status_t status = releaseSoundTriggerSession(session);
1556 reply->writeInt32(status);
1557 return NO_ERROR;
1558 } break;
1559
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001560 case GET_PHONE_STATE: {
1561 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1562 reply->writeInt32((int32_t)getPhoneState());
1563 return NO_ERROR;
1564 } break;
1565
Eric Laurentbaac1832014-12-01 17:52:59 -08001566 case REGISTER_POLICY_MIXES: {
1567 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1568 bool registration = data.readInt32() == 1;
1569 Vector<AudioMix> mixes;
1570 size_t size = (size_t)data.readInt32();
1571 if (size > MAX_MIXES_PER_POLICY) {
1572 size = MAX_MIXES_PER_POLICY;
1573 }
1574 for (size_t i = 0; i < size; i++) {
1575 AudioMix mix;
1576 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1577 mixes.add(mix);
1578 }
1579 }
1580 status_t status = registerPolicyMixes(mixes, registration);
1581 reply->writeInt32(status);
1582 return NO_ERROR;
1583 } break;
1584
Eric Laurent554a2772015-04-10 11:29:24 -07001585 case START_AUDIO_SOURCE: {
1586 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001587 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001588 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001589 (void)sanitizeAudioPortConfig(&source);
1590 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07001591 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001592 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001593 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
1594 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001595 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001596 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001597 return NO_ERROR;
1598 } break;
1599
1600 case STOP_AUDIO_SOURCE: {
1601 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07001602 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
1603 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07001604 reply->writeInt32(status);
1605 return NO_ERROR;
1606 } break;
1607
Andy Hung2ddee192015-12-18 17:34:44 -08001608 case SET_MASTER_MONO: {
1609 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1610 bool mono = static_cast<bool>(data.readInt32());
1611 status_t status = setMasterMono(mono);
1612 reply->writeInt32(status);
1613 return NO_ERROR;
1614 } break;
1615
1616 case GET_MASTER_MONO: {
1617 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1618 bool mono;
1619 status_t status = getMasterMono(&mono);
1620 reply->writeInt32(status);
1621 if (status == NO_ERROR) {
1622 reply->writeInt32(static_cast<int32_t>(mono));
1623 }
1624 return NO_ERROR;
1625 } break;
1626
Eric Laurentac9cef52017-06-09 15:46:26 -07001627 case GET_STREAM_VOLUME_DB: {
1628 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1629 audio_stream_type_t stream =
1630 static_cast <audio_stream_type_t>(data.readInt32());
1631 int index = static_cast <int>(data.readInt32());
1632 audio_devices_t device =
1633 static_cast <audio_devices_t>(data.readUint32());
1634 reply->writeFloat(getStreamVolumeDB(stream, index, device));
1635 return NO_ERROR;
1636 }
1637
jiabin81772902018-04-02 17:52:27 -07001638 case GET_SURROUND_FORMATS: {
1639 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1640 unsigned int numSurroundFormatsReq = data.readUint32();
1641 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
1642 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
1643 }
1644 bool reported = data.readBool();
1645 unsigned int numSurroundFormats = numSurroundFormatsReq;
1646 audio_format_t *surroundFormats = (audio_format_t *)calloc(
1647 numSurroundFormats, sizeof(audio_format_t));
1648 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
1649 if (numSurroundFormatsReq > 0 &&
1650 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
1651 free(surroundFormats);
1652 free(surroundFormatsEnabled);
1653 reply->writeInt32(NO_MEMORY);
1654 return NO_ERROR;
1655 }
1656 status_t status = getSurroundFormats(
1657 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
1658 reply->writeInt32(status);
1659
1660 if (status == NO_ERROR) {
1661 reply->writeUint32(numSurroundFormats);
1662 if (numSurroundFormatsReq > numSurroundFormats) {
1663 numSurroundFormatsReq = numSurroundFormats;
1664 }
1665 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
1666 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
1667 }
1668 free(surroundFormats);
1669 free(surroundFormatsEnabled);
1670 return NO_ERROR;
1671 }
1672
1673 case SET_SURROUND_FORMAT_ENABLED: {
1674 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1675 audio_format_t audioFormat = (audio_format_t) data.readInt32();
1676 bool enabled = data.readBool();
1677 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
1678 reply->writeInt32(status);
1679 return NO_ERROR;
1680 }
1681
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001682 case ADD_STREAM_DEFAULT_EFFECT: {
1683 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1684 effect_uuid_t type;
1685 status_t status = data.read(&type, sizeof(effect_uuid_t));
1686 if (status != NO_ERROR) {
1687 return status;
1688 }
1689 String16 opPackageName;
1690 status = data.readString16(&opPackageName);
1691 if (status != NO_ERROR) {
1692 return status;
1693 }
1694 effect_uuid_t uuid;
1695 status = data.read(&uuid, sizeof(effect_uuid_t));
1696 if (status != NO_ERROR) {
1697 return status;
1698 }
1699 int32_t priority = data.readInt32();
1700 audio_usage_t usage = (audio_usage_t) data.readInt32();
1701 audio_unique_id_t id = 0;
1702 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
1703 opPackageName,
1704 &uuid,
1705 priority,
1706 usage,
1707 &id)));
1708 reply->writeInt32(id);
1709 return NO_ERROR;
1710 }
1711
1712 case REMOVE_STREAM_DEFAULT_EFFECT: {
1713 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1714 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1715 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
1716 return NO_ERROR;
1717 }
1718
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001719 case ADD_SOURCE_DEFAULT_EFFECT: {
1720 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1721 effect_uuid_t type;
1722 status_t status = data.read(&type, sizeof(effect_uuid_t));
1723 if (status != NO_ERROR) {
1724 return status;
1725 }
1726 String16 opPackageName;
1727 status = data.readString16(&opPackageName);
1728 if (status != NO_ERROR) {
1729 return status;
1730 }
1731 effect_uuid_t uuid;
1732 status = data.read(&uuid, sizeof(effect_uuid_t));
1733 if (status != NO_ERROR) {
1734 return status;
1735 }
1736 int32_t priority = data.readInt32();
1737 audio_source_t source = (audio_source_t) data.readInt32();
1738 audio_unique_id_t id = 0;
1739 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
1740 opPackageName,
1741 &uuid,
1742 priority,
1743 source,
1744 &id)));
1745 reply->writeInt32(id);
1746 return NO_ERROR;
1747 }
1748
1749 case REMOVE_SOURCE_DEFAULT_EFFECT: {
1750 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1751 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
1752 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
1753 return NO_ERROR;
1754 }
1755
Eric Laurentb78763e2018-10-17 10:08:02 -07001756 case SET_ASSISTANT_UID: {
1757 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1758 int32_t uid;
1759 status_t status = data.readInt32(&uid);
1760 if (status != NO_ERROR) {
1761 return status;
1762 }
1763 status = setAssistantUid(uid);
1764 reply->writeInt32(static_cast <int32_t>(status));
1765 return NO_ERROR;
1766 }
1767
1768 case SET_A11Y_SERVICES_UIDS: {
1769 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1770 std::vector<uid_t> uids;
1771 int32_t size;
1772 status_t status = data.readInt32(&size);
1773 if (status != NO_ERROR) {
1774 return status;
1775 }
1776 if (size > MAX_ITEMS_PER_LIST) {
1777 size = MAX_ITEMS_PER_LIST;
1778 }
1779 for (int32_t i = 0; i < size; i++) {
1780 int32_t uid;
1781 status = data.readInt32(&uid);
1782 if (status != NO_ERROR) {
1783 return status;
1784 }
1785 uids.push_back(uid);
1786 }
1787 status = setA11yServicesUids(uids);
1788 reply->writeInt32(static_cast <int32_t>(status));
1789 return NO_ERROR;
1790 }
1791
jiabin6012f912018-11-02 17:06:30 -07001792 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
1793 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1794 bool isSupported = isHapticPlaybackSupported();
1795 reply->writeBool(isSupported);
1796 return NO_ERROR;
1797 }
1798
Eric Laurentc2f1f072009-07-17 12:17:14 -07001799 default:
1800 return BBinder::onTransact(code, data, reply, flags);
1801 }
1802}
1803
Andy Hungb0272092018-04-12 11:06:56 -07001804/** returns true if string overflow was prevented by zero termination */
1805template <size_t size>
1806static bool preventStringOverflow(char (&s)[size]) {
1807 if (strnlen(s, size) < size) return false;
1808 s[size - 1] = '\0';
1809 return true;
1810}
1811
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001812void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
1813{
1814 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
1815 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
1816 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
1817 }
1818 attr->tags[tagsMaxSize - 1] = '\0';
1819}
1820
Andy Hungb0272092018-04-12 11:06:56 -07001821/** returns BAD_VALUE if sanitization was required. */
1822status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
1823{
1824 if (preventStringOverflow(desc->name)
1825 | /* always */ preventStringOverflow(desc->implementor)) {
1826 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
1827 return BAD_VALUE;
1828 }
1829 return NO_ERROR;
1830}
1831
1832/** returns BAD_VALUE if sanitization was required. */
1833status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
1834{
1835 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
1836 preventStringOverflow(config->ext.device.address)) {
1837 return BAD_VALUE;
1838 }
1839 return NO_ERROR;
1840}
1841
Eric Laurentc2f1f072009-07-17 12:17:14 -07001842// ----------------------------------------------------------------------------
1843
Glenn Kasten40bc9062015-03-20 09:09:33 -07001844} // namespace android