blob: f27e21a0c48a2295eac17145169bb8edf0b5d2f6 [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>
Andy Hung4ef19fa2018-05-15 19:35:29 -070029#include <mediautils/ServiceUtilities.h>
Marco Nelissencf90b492019-09-26 11:20:54 -070030#include <mediautils/TimeCheck.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 Laurent8340e672019-11-06 11:01:08 -0800107 SET_RTT_ENABLED,
108 IS_CALL_SCREEN_MODE_SUPPORTED
Eric Laurentc2f1f072009-07-17 12:17:14 -0700109};
110
Eric Laurent1d670b12015-02-06 10:44:24 -0800111#define MAX_ITEMS_PER_LIST 1024
112
Eric Laurentc2f1f072009-07-17 12:17:14 -0700113class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
114{
115public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700116 explicit BpAudioPolicyService(const sp<IBinder>& impl)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 : BpInterface<IAudioPolicyService>(impl)
118 {
119 }
120
121 virtual status_t setDeviceConnectionState(
Dima Zavinfce7a472011-04-19 22:30:36 -0700122 audio_devices_t device,
123 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800124 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800125 const char *device_name,
126 audio_format_t encodedFormat)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700127 {
128 Parcel data, reply;
129 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
130 data.writeInt32(static_cast <uint32_t>(device));
131 data.writeInt32(static_cast <uint32_t>(state));
132 data.writeCString(device_address);
Paul McLeane743a472015-01-28 11:07:31 -0800133 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800134 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700135 remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
136 return static_cast <status_t> (reply.readInt32());
137 }
138
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 virtual audio_policy_dev_state_t getDeviceConnectionState(
140 audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700141 const char *device_address)
142 {
143 Parcel data, reply;
144 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
145 data.writeInt32(static_cast <uint32_t>(device));
146 data.writeCString(device_address);
147 remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700148 return static_cast <audio_policy_dev_state_t>(reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 }
150
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800151 virtual status_t handleDeviceConfigChange(audio_devices_t device,
152 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800153 const char *device_name,
154 audio_format_t encodedFormat)
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800155 {
156 Parcel data, reply;
157 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
158 data.writeInt32(static_cast <uint32_t>(device));
159 data.writeCString(device_address);
160 data.writeCString(device_name);
Aniket Kumar Lata4e464702019-01-10 23:38:46 -0800161 data.writeInt32(static_cast <uint32_t>(encodedFormat));
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -0800162 remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
163 return static_cast <status_t> (reply.readInt32());
164 }
165
Glenn Kastenf78aee72012-01-04 11:00:47 -0800166 virtual status_t setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700167 {
168 Parcel data, reply;
169 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
170 data.writeInt32(state);
171 remote()->transact(SET_PHONE_STATE, data, &reply);
172 return static_cast <status_t> (reply.readInt32());
173 }
174
Dima Zavinfce7a472011-04-19 22:30:36 -0700175 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700176 {
177 Parcel data, reply;
178 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
179 data.writeInt32(static_cast <uint32_t>(usage));
180 data.writeInt32(static_cast <uint32_t>(config));
181 remote()->transact(SET_FORCE_USE, data, &reply);
182 return static_cast <status_t> (reply.readInt32());
183 }
184
Dima Zavinfce7a472011-04-19 22:30:36 -0700185 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700186 {
187 Parcel data, reply;
188 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
189 data.writeInt32(static_cast <uint32_t>(usage));
190 remote()->transact(GET_FORCE_USE, data, &reply);
Dima Zavinfce7a472011-04-19 22:30:36 -0700191 return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700192 }
193
Eric Laurentf4e63452017-11-06 19:31:46 +0000194 virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700195 {
196 Parcel data, reply;
197 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
198 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700199 remote()->transact(GET_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700200 return static_cast <audio_io_handle_t> (reply.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700201 }
202
Eric Laurent42984412019-05-09 17:57:03 -0700203 status_t getOutputForAttr(audio_attributes_t *attr,
Kevin Rocard153f92d2018-12-18 18:33:28 -0800204 audio_io_handle_t *output,
205 audio_session_t session,
206 audio_stream_type_t *stream,
207 pid_t pid,
208 uid_t uid,
209 const audio_config_t *config,
210 audio_output_flags_t flags,
211 audio_port_handle_t *selectedDeviceId,
212 audio_port_handle_t *portId,
213 std::vector<audio_io_handle_t> *secondaryOutputs) override
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700214 {
215 Parcel data, reply;
216 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent42984412019-05-09 17:57:03 -0700217 if (attr == nullptr) {
218 ALOGE("%s NULL audio attributes", __func__);
Eric Laurente83b55d2014-11-14 10:06:21 -0800219 return BAD_VALUE;
220 }
Eric Laurent42984412019-05-09 17:57:03 -0700221 if (output == nullptr) {
222 ALOGE("%s NULL output - shouldn't happen", __func__);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700223 return BAD_VALUE;
224 }
Eric Laurent42984412019-05-09 17:57:03 -0700225 if (selectedDeviceId == nullptr) {
226 ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800227 return BAD_VALUE;
228 }
Eric Laurent42984412019-05-09 17:57:03 -0700229 if (portId == nullptr) {
230 ALOGE("%s NULL portId - shouldn't happen", __func__);
Kevin Rocard153f92d2018-12-18 18:33:28 -0800231 return BAD_VALUE;
232 }
Eric Laurent42984412019-05-09 17:57:03 -0700233 if (secondaryOutputs == nullptr) {
234 ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__);
235 return BAD_VALUE;
Eric Laurente83b55d2014-11-14 10:06:21 -0800236 }
Eric Laurent42984412019-05-09 17:57:03 -0700237 data.write(attr, sizeof(audio_attributes_t));
Eric Laurente83b55d2014-11-14 10:06:21 -0800238 data.writeInt32(session);
239 if (stream == NULL) {
240 data.writeInt32(0);
241 } else {
242 data.writeInt32(1);
243 data.writeInt32(*stream);
244 }
Nadav Bar766fb022018-01-07 12:18:03 +0200245 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700246 data.writeInt32(uid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800247 data.write(config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700248 data.writeInt32(static_cast <uint32_t>(flags));
Eric Laurent9ae8c592017-06-22 17:17:09 -0700249 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800250 data.writeInt32(*portId);
Eric Laurente83b55d2014-11-14 10:06:21 -0800251 status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
252 if (status != NO_ERROR) {
253 return status;
254 }
255 status = (status_t)reply.readInt32();
256 if (status != NO_ERROR) {
257 return status;
258 }
Eric Laurent42984412019-05-09 17:57:03 -0700259 status = (status_t)reply.read(&attr, sizeof(audio_attributes_t));
260 if (status != NO_ERROR) {
261 return status;
262 }
Eric Laurente83b55d2014-11-14 10:06:21 -0800263 *output = (audio_io_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800264 audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
Eric Laurente83b55d2014-11-14 10:06:21 -0800265 if (stream != NULL) {
Eric Laurent20b9ef02016-12-05 11:03:16 -0800266 *stream = lStream;
Eric Laurente83b55d2014-11-14 10:06:21 -0800267 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700268 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800269 *portId = (audio_port_handle_t)reply.readInt32();
Kevin Rocard153f92d2018-12-18 18:33:28 -0800270 secondaryOutputs->resize(reply.readInt32());
271 return reply.read(secondaryOutputs->data(),
272 secondaryOutputs->size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700273 }
274
Eric Laurentd7fe0862018-07-14 16:48:01 -0700275 virtual status_t startOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 {
277 Parcel data, reply;
278 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700279 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700280 remote()->transact(START_OUTPUT, data, &reply);
281 return static_cast <status_t> (reply.readInt32());
282 }
283
Eric Laurentd7fe0862018-07-14 16:48:01 -0700284 virtual status_t stopOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700288 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700289 remote()->transact(STOP_OUTPUT, data, &reply);
290 return static_cast <status_t> (reply.readInt32());
291 }
292
Eric Laurentd7fe0862018-07-14 16:48:01 -0700293 virtual void releaseOutput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700294 {
295 Parcel data, reply;
296 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentd7fe0862018-07-14 16:48:01 -0700297 data.writeInt32((int32_t)portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298 remote()->transact(RELEASE_OUTPUT, data, &reply);
299 }
300
Eric Laurentcaf7f482014-11-25 17:50:47 -0800301 virtual status_t getInputForAttr(const audio_attributes_t *attr,
302 audio_io_handle_t *input,
Mikhail Naganov2996f672019-04-18 12:29:59 -0700303 audio_unique_id_t riid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800304 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700305 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700306 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800307 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800308 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600309 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700310 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800311 audio_port_handle_t *portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700312 {
313 Parcel data, reply;
314 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentcaf7f482014-11-25 17:50:47 -0800315 if (attr == NULL) {
316 ALOGE("getInputForAttr NULL attr - shouldn't happen");
317 return BAD_VALUE;
318 }
319 if (input == NULL) {
320 ALOGE("getInputForAttr NULL input - shouldn't happen");
321 return BAD_VALUE;
322 }
Eric Laurent9ae8c592017-06-22 17:17:09 -0700323 if (selectedDeviceId == NULL) {
324 ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
325 return BAD_VALUE;
326 }
Eric Laurent20b9ef02016-12-05 11:03:16 -0800327 if (portId == NULL) {
328 ALOGE("getInputForAttr NULL portId - shouldn't happen");
329 return BAD_VALUE;
330 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800331 data.write(attr, sizeof(audio_attributes_t));
Eric Laurenta54f1282017-07-01 19:39:32 -0700332 data.writeInt32(*input);
Mikhail Naganov2996f672019-04-18 12:29:59 -0700333 data.writeInt32(riid);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800334 data.writeInt32(session);
Eric Laurentb2379ba2016-05-23 17:42:12 -0700335 data.writeInt32(pid);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700336 data.writeInt32(uid);
Eric Laurentfee19762018-01-29 18:44:13 -0800337 data.writeString16(opPackageName);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800338 data.write(config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -0700339 data.writeInt32(flags);
Eric Laurent9ae8c592017-06-22 17:17:09 -0700340 data.writeInt32(*selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800341 data.writeInt32(*portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -0800342 status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
343 if (status != NO_ERROR) {
344 return status;
345 }
346 status = reply.readInt32();
347 if (status != NO_ERROR) {
348 return status;
349 }
350 *input = (audio_io_handle_t)reply.readInt32();
Eric Laurent9ae8c592017-06-22 17:17:09 -0700351 *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800352 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800353 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354 }
355
Eric Laurent4eb58f12018-12-07 16:41:02 -0800356 virtual status_t startInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700357 {
358 Parcel data, reply;
359 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800360 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 remote()->transact(START_INPUT, data, &reply);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800362 status_t status = static_cast <status_t> (reply.readInt32());
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800363 return status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700364 }
365
Eric Laurentfee19762018-01-29 18:44:13 -0800366 virtual status_t stopInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700367 {
368 Parcel data, reply;
369 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800370 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700371 remote()->transact(STOP_INPUT, data, &reply);
372 return static_cast <status_t> (reply.readInt32());
373 }
374
Eric Laurentfee19762018-01-29 18:44:13 -0800375 virtual void releaseInput(audio_port_handle_t portId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700376 {
377 Parcel data, reply;
378 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurentfee19762018-01-29 18:44:13 -0800379 data.writeInt32(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700380 remote()->transact(RELEASE_INPUT, data, &reply);
381 }
382
Dima Zavinfce7a472011-04-19 22:30:36 -0700383 virtual status_t initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 int indexMin,
385 int indexMax)
386 {
387 Parcel data, reply;
388 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
389 data.writeInt32(static_cast <uint32_t>(stream));
390 data.writeInt32(indexMin);
391 data.writeInt32(indexMax);
392 remote()->transact(INIT_STREAM_VOLUME, data, &reply);
393 return static_cast <status_t> (reply.readInt32());
394 }
395
Eric Laurent83844cc2011-11-18 16:43:31 -0800396 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
397 int index,
398 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700399 {
400 Parcel data, reply;
401 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
402 data.writeInt32(static_cast <uint32_t>(stream));
403 data.writeInt32(index);
Eric Laurent83844cc2011-11-18 16:43:31 -0800404 data.writeInt32(static_cast <uint32_t>(device));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405 remote()->transact(SET_STREAM_VOLUME, data, &reply);
406 return static_cast <status_t> (reply.readInt32());
407 }
408
Eric Laurent83844cc2011-11-18 16:43:31 -0800409 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
410 int *index,
411 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700412 {
413 Parcel data, reply;
414 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
415 data.writeInt32(static_cast <uint32_t>(stream));
Eric Laurent83844cc2011-11-18 16:43:31 -0800416 data.writeInt32(static_cast <uint32_t>(device));
417
Eric Laurentc2f1f072009-07-17 12:17:14 -0700418 remote()->transact(GET_STREAM_VOLUME, data, &reply);
419 int lIndex = reply.readInt32();
420 if (index) *index = lIndex;
421 return static_cast <status_t> (reply.readInt32());
422 }
Eric Laurentde070132010-07-13 04:45:46 -0700423
François Gaffiecfe17322018-11-07 13:41:29 +0100424 virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index,
425 audio_devices_t device)
426 {
427 Parcel data, reply;
428 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
429 data.write(&attr, sizeof(audio_attributes_t));
430 data.writeInt32(index);
431 data.writeInt32(static_cast <uint32_t>(device));
432 status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply);
433 if (status != NO_ERROR) {
434 return status;
435 }
436 return static_cast <status_t> (reply.readInt32());
437 }
438 virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index,
439 audio_devices_t device)
440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
443 data.write(&attr, sizeof(audio_attributes_t));
444 data.writeInt32(static_cast <uint32_t>(device));
445 status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply);
446 if (status != NO_ERROR) {
447 return status;
448 }
449 status = static_cast <status_t> (reply.readInt32());
450 if (status != NO_ERROR) {
451 return status;
452 }
453 index = reply.readInt32();
454 return NO_ERROR;
455 }
456 virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
457 {
458 Parcel data, reply;
459 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
460 data.write(&attr, sizeof(audio_attributes_t));
461 status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply);
462 if (status != NO_ERROR) {
463 return status;
464 }
465 status = static_cast <status_t> (reply.readInt32());
466 if (status != NO_ERROR) {
467 return status;
468 }
469 index = reply.readInt32();
470 return NO_ERROR;
471 }
472 virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
473 {
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
476 data.write(&attr, sizeof(audio_attributes_t));
477 status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply);
478 if (status != NO_ERROR) {
479 return status;
480 }
481 status = static_cast <status_t> (reply.readInt32());
482 if (status != NO_ERROR) {
483 return status;
484 }
485 index = reply.readInt32();
486 return NO_ERROR;
487 }
Dima Zavinfce7a472011-04-19 22:30:36 -0700488 virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700489 {
490 Parcel data, reply;
491 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
492 data.writeInt32(static_cast <uint32_t>(stream));
493 remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
François Gaffiec005e562018-11-06 15:04:49 +0100494 return reply.readUint32();
Eric Laurentde070132010-07-13 04:45:46 -0700495 }
496
Eric Laurent63742522012-03-08 13:42:42 -0800497 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800498 {
499 Parcel data, reply;
500 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
501 data.writeInt32(static_cast <uint32_t>(stream));
502 remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
Eric Laurent63742522012-03-08 13:42:42 -0800503 return (audio_devices_t) reply.readInt32();
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800504 }
505
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700506 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700507 {
508 Parcel data, reply;
509 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
510 data.write(desc, sizeof(effect_descriptor_t));
511 remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
512 return static_cast <audio_io_handle_t> (reply.readInt32());
513 }
514
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700515 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700516 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700517 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800518 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700519 int id)
520 {
521 Parcel data, reply;
522 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
523 data.write(desc, sizeof(effect_descriptor_t));
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700524 data.writeInt32(io);
Eric Laurentde070132010-07-13 04:45:46 -0700525 data.writeInt32(strategy);
526 data.writeInt32(session);
527 data.writeInt32(id);
528 remote()->transact(REGISTER_EFFECT, data, &reply);
529 return static_cast <status_t> (reply.readInt32());
530 }
531
532 virtual status_t unregisterEffect(int id)
533 {
534 Parcel data, reply;
535 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
536 data.writeInt32(id);
537 remote()->transact(UNREGISTER_EFFECT, data, &reply);
538 return static_cast <status_t> (reply.readInt32());
539 }
540
Eric Laurentdb7c0792011-08-10 10:37:50 -0700541 virtual status_t setEffectEnabled(int id, bool enabled)
542 {
543 Parcel data, reply;
544 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
545 data.writeInt32(id);
546 data.writeInt32(enabled);
547 remote()->transact(SET_EFFECT_ENABLED, data, &reply);
548 return static_cast <status_t> (reply.readInt32());
549 }
550
Eric Laurent6c796322019-04-09 14:13:17 -0700551 status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override
552 {
553 Parcel data, reply;
554 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
555 data.writeInt32(ids.size());
556 for (auto id : ids) {
557 data.writeInt32(id);
558 }
559 data.writeInt32(io);
560 status_t status = remote()->transact(MOVE_EFFECTS_TO_IO, data, &reply);
561 if (status != NO_ERROR) {
562 return status;
563 }
564 return static_cast <status_t> (reply.readInt32());
565 }
566
Glenn Kastenfff6d712012-01-12 16:38:12 -0800567 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
Eric Laurenteda6c362011-02-02 09:33:30 -0800568 {
569 Parcel data, reply;
570 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800571 data.writeInt32((int32_t) stream);
Eric Laurenteda6c362011-02-02 09:33:30 -0800572 data.writeInt32(inPastMs);
573 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
574 return reply.readInt32();
575 }
Eric Laurent57dae992011-07-24 13:36:09 -0700576
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800577 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
578 {
579 Parcel data, reply;
580 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
581 data.writeInt32((int32_t) stream);
582 data.writeInt32(inPastMs);
583 remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
584 return reply.readInt32();
585 }
586
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700587 virtual bool isSourceActive(audio_source_t source) const
588 {
589 Parcel data, reply;
590 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
591 data.writeInt32((int32_t) source);
592 remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
593 return reply.readInt32();
594 }
595
Glenn Kastend848eb42016-03-08 13:42:11 -0800596 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700597 effect_descriptor_t *descriptors,
598 uint32_t *count)
599 {
600 if (descriptors == NULL || count == NULL) {
601 return BAD_VALUE;
602 }
603 Parcel data, reply;
604 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
605 data.writeInt32(audioSession);
606 data.writeInt32(*count);
607 status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
608 if (status != NO_ERROR) {
609 return status;
610 }
611 status = static_cast <status_t> (reply.readInt32());
612 uint32_t retCount = reply.readInt32();
613 if (retCount != 0) {
614 uint32_t numDesc = (retCount < *count) ? retCount : *count;
615 reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
616 }
617 *count = retCount;
618 return status;
619 }
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000620
Kevin Rocardb99cc752019-03-21 20:52:24 -0700621 status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
622 Parcel data, reply;
623 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
624 data.writeInt32(uid);
625 data.writeInt32(flags);
626 remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
627 return reply.readInt32();
628 }
629
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000630 virtual bool isOffloadSupported(const audio_offload_info_t& info)
631 {
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100632 Parcel data, reply;
633 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
634 data.write(&info, sizeof(audio_offload_info_t));
635 remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
Eric Laurent203b1a12014-04-01 10:34:16 -0700636 return reply.readInt32();
637 }
638
Michael Chana94fbb22018-04-24 14:31:19 +1000639 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
640 const audio_attributes_t& attributes) {
641 Parcel data, reply;
642 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
643 data.write(&config, sizeof(audio_config_base_t));
644 data.write(&attributes, sizeof(audio_attributes_t));
645 status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
646 return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
647 }
648
Eric Laurent203b1a12014-04-01 10:34:16 -0700649 virtual status_t listAudioPorts(audio_port_role_t role,
650 audio_port_type_t type,
651 unsigned int *num_ports,
652 struct audio_port *ports,
653 unsigned int *generation)
654 {
655 if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
656 generation == NULL) {
657 return BAD_VALUE;
658 }
659 Parcel data, reply;
660 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
661 unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
662 data.writeInt32(role);
663 data.writeInt32(type);
664 data.writeInt32(numPortsReq);
665 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
666 if (status == NO_ERROR) {
667 status = (status_t)reply.readInt32();
668 *num_ports = (unsigned int)reply.readInt32();
669 }
Eric Laurent203b1a12014-04-01 10:34:16 -0700670 if (status == NO_ERROR) {
671 if (numPortsReq > *num_ports) {
672 numPortsReq = *num_ports;
673 }
674 if (numPortsReq > 0) {
675 reply.read(ports, numPortsReq * sizeof(struct audio_port));
676 }
677 *generation = reply.readInt32();
678 }
679 return status;
680 }
681
682 virtual status_t getAudioPort(struct audio_port *port)
683 {
684 if (port == NULL) {
685 return BAD_VALUE;
686 }
687 Parcel data, reply;
688 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
689 data.write(port, sizeof(struct audio_port));
690 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
691 if (status != NO_ERROR ||
692 (status = (status_t)reply.readInt32()) != NO_ERROR) {
693 return status;
694 }
695 reply.read(port, sizeof(struct audio_port));
696 return status;
697 }
698
699 virtual status_t createAudioPatch(const struct audio_patch *patch,
700 audio_patch_handle_t *handle)
701 {
702 if (patch == NULL || handle == NULL) {
703 return BAD_VALUE;
704 }
705 Parcel data, reply;
706 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
707 data.write(patch, sizeof(struct audio_patch));
708 data.write(handle, sizeof(audio_patch_handle_t));
709 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
710 if (status != NO_ERROR ||
711 (status = (status_t)reply.readInt32()) != NO_ERROR) {
712 return status;
713 }
714 reply.read(handle, sizeof(audio_patch_handle_t));
715 return status;
716 }
717
718 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
719 {
720 Parcel data, reply;
721 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
722 data.write(&handle, sizeof(audio_patch_handle_t));
723 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
724 if (status != NO_ERROR) {
725 status = (status_t)reply.readInt32();
726 }
727 return status;
728 }
729
730 virtual status_t listAudioPatches(unsigned int *num_patches,
731 struct audio_patch *patches,
732 unsigned int *generation)
733 {
734 if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
735 generation == NULL) {
736 return BAD_VALUE;
737 }
738 Parcel data, reply;
739 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
740 unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
741 data.writeInt32(numPatchesReq);
742 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
743 if (status == NO_ERROR) {
744 status = (status_t)reply.readInt32();
745 *num_patches = (unsigned int)reply.readInt32();
746 }
747 if (status == NO_ERROR) {
748 if (numPatchesReq > *num_patches) {
749 numPatchesReq = *num_patches;
750 }
751 if (numPatchesReq > 0) {
752 reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
753 }
754 *generation = reply.readInt32();
755 }
756 return status;
757 }
758
759 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
760 {
761 if (config == NULL) {
762 return BAD_VALUE;
763 }
764 Parcel data, reply;
765 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
766 data.write(config, sizeof(struct audio_port_config));
767 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
768 if (status != NO_ERROR) {
769 status = (status_t)reply.readInt32();
770 }
771 return status;
772 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700773
Eric Laurentb52c1522014-05-20 11:27:36 -0700774 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
775 {
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Marco Nelissenf8880202014-11-14 07:58:25 -0800778 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentb52c1522014-05-20 11:27:36 -0700779 remote()->transact(REGISTER_CLIENT, data, &reply);
780 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700781
Eric Laurente8726fe2015-06-26 09:39:24 -0700782 virtual void setAudioPortCallbacksEnabled(bool enabled)
783 {
784 Parcel data, reply;
785 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
786 data.writeInt32(enabled ? 1 : 0);
787 remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
788 }
789
François Gaffiecfe17322018-11-07 13:41:29 +0100790 virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled)
791 {
792 Parcel data, reply;
793 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
794 data.writeInt32(enabled ? 1 : 0);
795 remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply);
796 }
797
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700798 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
799 audio_io_handle_t *ioHandle,
800 audio_devices_t *device)
801 {
802 if (session == NULL || ioHandle == NULL || device == NULL) {
803 return BAD_VALUE;
804 }
805 Parcel data, reply;
806 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
807 status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
808 if (status != NO_ERROR) {
809 return status;
810 }
811 status = (status_t)reply.readInt32();
812 if (status == NO_ERROR) {
813 *session = (audio_session_t)reply.readInt32();
814 *ioHandle = (audio_io_handle_t)reply.readInt32();
815 *device = (audio_devices_t)reply.readInt32();
816 }
817 return status;
818 }
819
820 virtual status_t releaseSoundTriggerSession(audio_session_t session)
821 {
822 Parcel data, reply;
823 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
824 data.writeInt32(session);
825 status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
826 if (status != NO_ERROR) {
827 return status;
828 }
829 return (status_t)reply.readInt32();
830 }
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700831
832 virtual audio_mode_t getPhoneState()
833 {
834 Parcel data, reply;
835 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
836 status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
837 if (status != NO_ERROR) {
838 return AUDIO_MODE_INVALID;
839 }
840 return (audio_mode_t)reply.readInt32();
841 }
Eric Laurentbaac1832014-12-01 17:52:59 -0800842
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700843 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800844 {
845 Parcel data, reply;
846 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
847 data.writeInt32(registration ? 1 : 0);
848 size_t size = mixes.size();
849 if (size > MAX_MIXES_PER_POLICY) {
850 size = MAX_MIXES_PER_POLICY;
851 }
852 size_t sizePosition = data.dataPosition();
853 data.writeInt32(size);
854 size_t finalSize = size;
855 for (size_t i = 0; i < size; i++) {
856 size_t position = data.dataPosition();
857 if (mixes[i].writeToParcel(&data) != NO_ERROR) {
858 data.setDataPosition(position);
859 finalSize--;
860 }
861 }
862 if (size != finalSize) {
863 size_t position = data.dataPosition();
864 data.setDataPosition(sizePosition);
865 data.writeInt32(finalSize);
866 data.setDataPosition(position);
867 }
868 status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
869 if (status == NO_ERROR) {
870 status = (status_t)reply.readInt32();
871 }
872 return status;
873 }
Eric Laurent554a2772015-04-10 11:29:24 -0700874
875 virtual status_t startAudioSource(const struct audio_port_config *source,
876 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700877 audio_port_handle_t *portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700878 {
879 Parcel data, reply;
880 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700881 if (source == NULL || attributes == NULL || portId == NULL) {
Eric Laurent554a2772015-04-10 11:29:24 -0700882 return BAD_VALUE;
883 }
884 data.write(source, sizeof(struct audio_port_config));
885 data.write(attributes, sizeof(audio_attributes_t));
886 status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
887 if (status != NO_ERROR) {
888 return status;
889 }
890 status = (status_t)reply.readInt32();
891 if (status != NO_ERROR) {
892 return status;
893 }
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700894 *portId = (audio_port_handle_t)reply.readInt32();
Eric Laurent554a2772015-04-10 11:29:24 -0700895 return status;
896 }
897
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700898 virtual status_t stopAudioSource(audio_port_handle_t portId)
Eric Laurent554a2772015-04-10 11:29:24 -0700899 {
900 Parcel data, reply;
901 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700902 data.writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700903 status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
904 if (status != NO_ERROR) {
905 return status;
906 }
907 status = (status_t)reply.readInt32();
908 return status;
909 }
Andy Hung2ddee192015-12-18 17:34:44 -0800910
911 virtual status_t setMasterMono(bool mono)
912 {
913 Parcel data, reply;
914 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
915 data.writeInt32(static_cast<int32_t>(mono));
916 status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
917 if (status != NO_ERROR) {
918 return status;
919 }
920 return static_cast<status_t>(reply.readInt32());
921 }
922
923 virtual status_t getMasterMono(bool *mono)
924 {
925 if (mono == nullptr) {
926 return BAD_VALUE;
927 }
928 Parcel data, reply;
929 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
930
931 status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
932 if (status != NO_ERROR) {
933 return status;
934 }
935 status = static_cast<status_t>(reply.readInt32());
936 if (status == NO_ERROR) {
937 *mono = static_cast<bool>(reply.readInt32());
938 }
939 return status;
940 }
Eric Laurentac9cef52017-06-09 15:46:26 -0700941
942 virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
943 {
944 Parcel data, reply;
945 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
946 data.writeInt32(static_cast <int32_t>(stream));
947 data.writeInt32(static_cast <int32_t>(index));
948 data.writeUint32(static_cast <uint32_t>(device));
949 status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
950 if (status != NO_ERROR) {
951 return NAN;
952 }
953 return reply.readFloat();
954 }
jiabin81772902018-04-02 17:52:27 -0700955
956 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
957 audio_format_t *surroundFormats,
958 bool *surroundFormatsEnabled,
959 bool reported)
960 {
961 if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
962 (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
963 return BAD_VALUE;
964 }
965 Parcel data, reply;
966 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
967 unsigned int numSurroundFormatsReq = *numSurroundFormats;
968 data.writeUint32(numSurroundFormatsReq);
969 data.writeBool(reported);
970 status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
971 if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
972 *numSurroundFormats = reply.readUint32();
973 }
974 if (status == NO_ERROR) {
975 if (numSurroundFormatsReq > *numSurroundFormats) {
976 numSurroundFormatsReq = *numSurroundFormats;
977 }
978 if (numSurroundFormatsReq > 0) {
979 status = reply.read(surroundFormats,
980 numSurroundFormatsReq * sizeof(audio_format_t));
981 if (status != NO_ERROR) {
982 return status;
983 }
984 status = reply.read(surroundFormatsEnabled,
985 numSurroundFormatsReq * sizeof(bool));
986 }
987 }
988 return status;
989 }
990
991 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
992 {
993 Parcel data, reply;
994 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
995 data.writeInt32(audioFormat);
996 data.writeBool(enabled);
997 status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
998 if (status != NO_ERROR) {
999 return status;
1000 }
1001 return reply.readInt32();
1002 }
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001003
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001004 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
1005 std::vector<audio_format_t> *formats)
1006 {
1007 if (formats == NULL) {
1008 return BAD_VALUE;
1009 }
1010
1011 Parcel data, reply;
1012 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1013 status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
1014 if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
1015 return status;
1016 }
1017
1018 size_t list_size = reply.readUint32();
1019
1020 for (size_t i = 0; i < list_size; i++) {
1021 formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
1022 }
1023 return NO_ERROR;
1024 }
1025
1026
1027 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07001028 const String16& opPackageName,
1029 const effect_uuid_t *uuid,
1030 int32_t priority,
1031 audio_usage_t usage,
1032 audio_unique_id_t* id)
1033 {
1034 Parcel data, reply;
1035 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1036 data.write(type, sizeof(effect_uuid_t));
1037 data.writeString16(opPackageName);
1038 data.write(uuid, sizeof(effect_uuid_t));
1039 data.writeInt32(priority);
1040 data.writeInt32((int32_t) usage);
1041 status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
1042 if (status != NO_ERROR) {
1043 return status;
1044 }
1045 status = static_cast <status_t> (reply.readInt32());
1046 *id = reply.readInt32();
1047 return status;
1048 }
1049
1050 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
1051 {
1052 Parcel data, reply;
1053 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1054 data.writeInt32(id);
1055 status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
1056 if (status != NO_ERROR) {
1057 return status;
1058 }
1059 return static_cast <status_t> (reply.readInt32());
1060 }
1061
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07001062 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
1063 const String16& opPackageName,
1064 const effect_uuid_t *uuid,
1065 int32_t priority,
1066 audio_source_t source,
1067 audio_unique_id_t* id)
1068 {
1069 Parcel data, reply;
1070 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1071 data.write(type, sizeof(effect_uuid_t));
1072 data.writeString16(opPackageName);
1073 data.write(uuid, sizeof(effect_uuid_t));
1074 data.writeInt32(priority);
1075 data.writeInt32((int32_t) source);
1076 status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
1077 if (status != NO_ERROR) {
1078 return status;
1079 }
1080 status = static_cast <status_t> (reply.readInt32());
1081 *id = reply.readInt32();
1082 return status;
1083 }
1084
1085 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
1086 {
1087 Parcel data, reply;
1088 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1089 data.writeInt32(id);
1090 status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
1091 if (status != NO_ERROR) {
1092 return status;
1093 }
1094 return static_cast <status_t> (reply.readInt32());
1095 }
1096
Eric Laurentb78763e2018-10-17 10:08:02 -07001097 virtual status_t setAssistantUid(uid_t uid)
1098 {
1099 Parcel data, reply;
1100 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1101 data.writeInt32(uid);
1102 status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
1103 if (status != NO_ERROR) {
1104 return status;
1105 }
1106 return static_cast <status_t> (reply.readInt32());
1107 }
1108
1109 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
1110 {
1111 Parcel data, reply;
1112 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1113 data.writeInt32(uids.size());
1114 for (auto uid : uids) {
1115 data.writeInt32(uid);
1116 }
1117 status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
1118 if (status != NO_ERROR) {
1119 return status;
1120 }
1121 return static_cast <status_t> (reply.readInt32());
1122 }
1123
jiabin6012f912018-11-02 17:06:30 -07001124 virtual bool isHapticPlaybackSupported()
1125 {
1126 Parcel data, reply;
1127 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1128 status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
1129 if (status != NO_ERROR) {
1130 return false;
1131 }
1132 return reply.readBool();
1133 }
1134
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001135 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
1136 {
1137 Parcel data, reply;
1138 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1139
1140 data.writeInt32((int32_t) uid);
1141 size_t size = devices.size();
1142 size_t sizePosition = data.dataPosition();
1143 data.writeInt32((int32_t) size);
1144 size_t finalSize = size;
1145 for (size_t i = 0; i < size; i++) {
1146 size_t position = data.dataPosition();
1147 if (devices[i].writeToParcel(&data) != NO_ERROR) {
1148 data.setDataPosition(position);
1149 finalSize--;
1150 }
1151 }
1152 if (size != finalSize) {
1153 size_t position = data.dataPosition();
1154 data.setDataPosition(sizePosition);
1155 data.writeInt32(finalSize);
1156 data.setDataPosition(position);
1157 }
1158
1159 status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
1160 if (status == NO_ERROR) {
1161 status = (status_t)reply.readInt32();
1162 }
1163 return status;
1164 }
1165
François Gaffied0ba9ed2018-11-05 11:50:42 +01001166 virtual status_t removeUidDeviceAffinities(uid_t uid) {
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001167 Parcel data, reply;
1168 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1169
1170 data.writeInt32((int32_t) uid);
1171
François Gaffied0ba9ed2018-11-05 11:50:42 +01001172 status_t status =
1173 remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001174 if (status == NO_ERROR) {
François Gaffied0ba9ed2018-11-05 11:50:42 +01001175 status = (status_t) reply.readInt32();
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001176 }
1177 return status;
1178 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01001179
1180 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
1181 {
1182 Parcel data, reply;
1183 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1184
1185 status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
1186 if (status != NO_ERROR) {
1187 ALOGE("%s: permission denied", __func__);
1188 return status;
1189 }
1190 status = static_cast<status_t>(reply.readInt32());
François Gaffie4b2018b2018-11-07 11:18:59 +01001191 if (status != NO_ERROR) {
1192 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001193 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001194 uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
1195 for (size_t i = 0; i < numStrategies; i++) {
1196 AudioProductStrategy strategy;
1197 status = strategy.readFromParcel(&reply);
1198 if (status != NO_ERROR) {
1199 ALOGE("%s: failed to read strategies", __FUNCTION__);
1200 strategies.clear();
1201 return status;
1202 }
1203 strategies.push_back(strategy);
1204 }
1205 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001206 }
1207
François Gaffie4b2018b2018-11-07 11:18:59 +01001208 virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
1209 product_strategy_t &productStrategy)
François Gaffied0ba9ed2018-11-05 11:50:42 +01001210 {
1211 Parcel data, reply;
1212 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1213 status_t status = aa.writeToParcel(&data);
1214 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01001215 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001216 }
1217 status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
François Gaffie4b2018b2018-11-07 11:18:59 +01001218 if (status != NO_ERROR) {
1219 return status;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001220 }
François Gaffie4b2018b2018-11-07 11:18:59 +01001221 status = static_cast<status_t>(reply.readInt32());
1222 if (status != NO_ERROR) {
1223 return status;
1224 }
1225 productStrategy = static_cast<product_strategy_t>(reply.readInt32());
1226 return NO_ERROR;
1227 }
1228
1229 virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups)
1230 {
1231 Parcel data, reply;
1232 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1233
1234 status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply);
1235 if (status != NO_ERROR) {
1236 return status;
1237 }
1238 status = static_cast<status_t>(reply.readInt32());
1239 if (status != NO_ERROR) {
1240 return status;
1241 }
1242 uint32_t numGroups = static_cast<uint32_t>(reply.readInt32());
1243 for (size_t i = 0; i < numGroups; i++) {
1244 AudioVolumeGroup group;
1245 status = group.readFromParcel(&reply);
1246 if (status != NO_ERROR) {
1247 ALOGE("%s: failed to read volume groups", __FUNCTION__);
1248 groups.clear();
1249 return status;
1250 }
1251 groups.push_back(group);
1252 }
1253 return NO_ERROR;
1254 }
1255
1256 virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
1257 volume_group_t &volumeGroup)
1258 {
1259 Parcel data, reply;
1260 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1261 status_t status = aa.writeToParcel(&data);
1262 if (status != NO_ERROR) {
1263 return status;
1264 }
1265 status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply);
1266 if (status != NO_ERROR) {
1267 return status;
1268 }
1269 status = static_cast<status_t>(reply.readInt32());
1270 if (status != NO_ERROR) {
1271 return status;
1272 }
1273 volumeGroup = static_cast<volume_group_t>(reply.readInt32());
1274 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01001275 }
Eric Laurent6ede98f2019-06-11 14:50:30 -07001276
1277 virtual status_t setRttEnabled(bool enabled)
1278 {
1279 Parcel data, reply;
1280 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1281 data.writeInt32(static_cast<int32_t>(enabled));
1282 status_t status = remote()->transact(SET_RTT_ENABLED, data, &reply);
1283 if (status != NO_ERROR) {
1284 return status;
1285 }
1286 return static_cast<status_t>(reply.readInt32());
1287 }
Eric Laurent8340e672019-11-06 11:01:08 -08001288
1289 virtual bool isCallScreenModeSupported()
1290 {
1291 Parcel data, reply;
1292 data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
1293 status_t status = remote()->transact(IS_CALL_SCREEN_MODE_SUPPORTED, data, &reply);
1294 if (status != NO_ERROR) {
1295 return false;
1296 }
1297 return reply.readBool();
1298 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001299};
1300
1301IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
1302
1303// ----------------------------------------------------------------------
1304
Eric Laurentc2f1f072009-07-17 12:17:14 -07001305status_t BnAudioPolicyService::onTransact(
1306 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1307{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001308 // make sure transactions reserved to AudioFlinger do not come from other processes
1309 switch (code) {
1310 case START_OUTPUT:
1311 case STOP_OUTPUT:
1312 case RELEASE_OUTPUT:
1313 case GET_INPUT_FOR_ATTR:
1314 case START_INPUT:
1315 case STOP_INPUT:
1316 case RELEASE_INPUT:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001317 case GET_OUTPUT_FOR_EFFECT:
1318 case REGISTER_EFFECT:
1319 case UNREGISTER_EFFECT:
1320 case SET_EFFECT_ENABLED:
1321 case GET_OUTPUT_FOR_ATTR:
1322 case ACQUIRE_SOUNDTRIGGER_SESSION:
1323 case RELEASE_SOUNDTRIGGER_SESSION:
Eric Laurent6c796322019-04-09 14:13:17 -07001324 case MOVE_EFFECTS_TO_IO:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001325 ALOGW("%s: transaction %d received from PID %d",
1326 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001327 // return status only for non void methods
1328 switch (code) {
1329 case RELEASE_OUTPUT:
1330 case RELEASE_INPUT:
1331 break;
1332 default:
1333 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1334 break;
1335 }
1336 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001337 default:
1338 break;
1339 }
1340
Eric Laurent4980df22018-01-26 18:04:09 -08001341 // make sure the following transactions come from system components
1342 switch (code) {
1343 case SET_DEVICE_CONNECTION_STATE:
1344 case HANDLE_DEVICE_CONFIG_CHANGE:
1345 case SET_PHONE_STATE:
Eric Laurente17378d2018-05-09 14:43:01 -07001346//FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
1347// case SET_FORCE_USE:
Eric Laurent4980df22018-01-26 18:04:09 -08001348 case INIT_STREAM_VOLUME:
1349 case SET_STREAM_VOLUME:
1350 case REGISTER_POLICY_MIXES:
Eric Laurent10b71232018-04-13 18:14:44 -07001351 case SET_MASTER_MONO:
jiabin81772902018-04-02 17:52:27 -07001352 case GET_SURROUND_FORMATS:
Eric Laurentb78763e2018-10-17 10:08:02 -07001353 case SET_SURROUND_FORMAT_ENABLED:
1354 case SET_ASSISTANT_UID:
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08001355 case SET_A11Y_SERVICES_UIDS:
1356 case SET_UID_DEVICE_AFFINITY:
Arun Mirpuri11029ad2018-12-19 20:45:19 -08001357 case REMOVE_UID_DEVICE_AFFINITY:
François Gaffie4b2018b2018-11-07 11:18:59 +01001358 case GET_OFFLOAD_FORMATS_A2DP:
1359 case LIST_AUDIO_VOLUME_GROUPS:
Eric Laurent6ede98f2019-06-11 14:50:30 -07001360 case GET_VOLUME_GROUP_FOR_ATTRIBUTES:
Eric Laurent8340e672019-11-06 11:01:08 -08001361 case SET_RTT_ENABLED:
1362 case IS_CALL_SCREEN_MODE_SUPPORTED: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001363 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001364 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1365 __func__, code, IPCThreadState::self()->getCallingPid(),
1366 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001367 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1368 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001369 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001370 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001371 default:
1372 break;
1373 }
1374
Eric Laurent39b09b52018-06-29 12:24:40 -07001375 std::string tag("IAudioPolicyService command " + std::to_string(code));
1376 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001377
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001378 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001379 case SET_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());
1383 audio_policy_dev_state_t state =
1384 static_cast <audio_policy_dev_state_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001385 const char *device_address = data.readCString();
Paul McLeane743a472015-01-28 11:07:31 -08001386 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001387 audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001388 if (device_address == nullptr || device_name == nullptr) {
1389 ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
1390 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1391 } else {
1392 reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
1393 state,
1394 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001395 device_name,
1396 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001397 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001398 return NO_ERROR;
1399 } break;
1400
1401 case GET_DEVICE_CONNECTION_STATE: {
1402 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001403 audio_devices_t device =
1404 static_cast<audio_devices_t> (data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001405 const char *device_address = data.readCString();
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001406 if (device_address == nullptr) {
1407 ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
1408 reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
1409 } else {
1410 reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
1411 device_address)));
1412 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001413 return NO_ERROR;
1414 } break;
1415
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001416 case HANDLE_DEVICE_CONFIG_CHANGE: {
1417 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1418 audio_devices_t device =
1419 static_cast <audio_devices_t>(data.readInt32());
1420 const char *device_address = data.readCString();
1421 const char *device_name = data.readCString();
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001422 audio_format_t codecFormat =
1423 static_cast <audio_format_t>(data.readInt32());
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001424 if (device_address == nullptr || device_name == nullptr) {
1425 ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
1426 reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
1427 } else {
1428 reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
1429 device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -08001430 device_name,
1431 codecFormat)));
Pavlin Radoslavovc694ff42017-01-09 23:27:29 -08001432 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -08001433 return NO_ERROR;
1434 } break;
1435
Eric Laurentc2f1f072009-07-17 12:17:14 -07001436 case SET_PHONE_STATE: {
1437 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001438 reply->writeInt32(static_cast <uint32_t>(setPhoneState(
1439 (audio_mode_t) data.readInt32())));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001440 return NO_ERROR;
1441 } break;
1442
Eric Laurentc2f1f072009-07-17 12:17:14 -07001443 case SET_FORCE_USE: {
1444 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001445 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1446 data.readInt32());
Dima Zavinfce7a472011-04-19 22:30:36 -07001447 audio_policy_forced_cfg_t config =
1448 static_cast <audio_policy_forced_cfg_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001449 reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
1450 return NO_ERROR;
1451 } break;
1452
1453 case GET_FORCE_USE: {
1454 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001455 audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
1456 data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001457 reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
1458 return NO_ERROR;
1459 } break;
1460
1461 case GET_OUTPUT: {
1462 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001463 audio_stream_type_t stream =
1464 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentf4e63452017-11-06 19:31:46 +00001465 audio_io_handle_t output = getOutput(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -07001466 reply->writeInt32(static_cast <int>(output));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001467 return NO_ERROR;
1468 } break;
1469
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001470 case GET_OUTPUT_FOR_ATTR: {
1471 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent42984412019-05-09 17:57:03 -07001472 audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
1473 status_t status = data.read(&attr, sizeof(audio_attributes_t));
1474 if (status != NO_ERROR) {
1475 return status;
Eric Laurente83b55d2014-11-14 10:06:21 -08001476 }
Eric Laurent42984412019-05-09 17:57:03 -07001477 sanetizeAudioAttributes(&attr);
Eric Laurente83b55d2014-11-14 10:06:21 -08001478 audio_session_t session = (audio_session_t)data.readInt32();
1479 audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
1480 bool hasStream = data.readInt32() != 0;
1481 if (hasStream) {
1482 stream = (audio_stream_type_t)data.readInt32();
1483 }
Nadav Bar766fb022018-01-07 12:18:03 +02001484 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001485 uid_t uid = (uid_t)data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001486 audio_config_t config;
1487 memset(&config, 0, sizeof(audio_config_t));
1488 data.read(&config, sizeof(audio_config_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001489 audio_output_flags_t flags =
1490 static_cast <audio_output_flags_t>(data.readInt32());
Paul McLeanaa981192015-03-21 09:55:15 -07001491 audio_port_handle_t selectedDeviceId = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001492 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Robert Shiha946d842015-09-02 16:46:59 -07001493 audio_io_handle_t output = 0;
Kevin Rocard153f92d2018-12-18 18:33:28 -08001494 std::vector<audio_io_handle_t> secondaryOutputs;
Eric Laurent42984412019-05-09 17:57:03 -07001495 status = getOutputForAttr(&attr,
Nadav Bar766fb022018-01-07 12:18:03 +02001496 &output, session, &stream, pid, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001497 &config,
Kevin Rocard153f92d2018-12-18 18:33:28 -08001498 flags, &selectedDeviceId, &portId, &secondaryOutputs);
Eric Laurente83b55d2014-11-14 10:06:21 -08001499 reply->writeInt32(status);
Eric Laurent42984412019-05-09 17:57:03 -07001500 status = reply->write(&attr, sizeof(audio_attributes_t));
1501 if (status != NO_ERROR) {
1502 return status;
1503 }
Eric Laurente83b55d2014-11-14 10:06:21 -08001504 reply->writeInt32(output);
1505 reply->writeInt32(stream);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001506 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001507 reply->writeInt32(portId);
Kevin Rocard153f92d2018-12-18 18:33:28 -08001508 reply->writeInt32(secondaryOutputs.size());
1509 return reply->write(secondaryOutputs.data(),
1510 secondaryOutputs.size() * sizeof(audio_io_handle_t));
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -07001511 } break;
1512
Eric Laurentc2f1f072009-07-17 12:17:14 -07001513 case START_OUTPUT: {
1514 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001515 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1516 reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001517 return NO_ERROR;
1518 } break;
1519
1520 case STOP_OUTPUT: {
1521 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001522 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1523 reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001524 return NO_ERROR;
1525 } break;
1526
1527 case RELEASE_OUTPUT: {
1528 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentd7fe0862018-07-14 16:48:01 -07001529 const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1530 releaseOutput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001531 return NO_ERROR;
1532 } break;
1533
Eric Laurentcaf7f482014-11-25 17:50:47 -08001534 case GET_INPUT_FOR_ATTR: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001535 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001536 audio_attributes_t attr = {};
Eric Laurentcaf7f482014-11-25 17:50:47 -08001537 data.read(&attr, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08001538 sanetizeAudioAttributes(&attr);
Eric Laurenta54f1282017-07-01 19:39:32 -07001539 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Mikhail Naganov2996f672019-04-18 12:29:59 -07001540 audio_unique_id_t riid = (audio_unique_id_t)data.readInt32();
Eric Laurentcaf7f482014-11-25 17:50:47 -08001541 audio_session_t session = (audio_session_t)data.readInt32();
Eric Laurentb2379ba2016-05-23 17:42:12 -07001542 pid_t pid = (pid_t)data.readInt32();
Eric Laurent8c7e6da2015-04-21 17:37:00 -07001543 uid_t uid = (uid_t)data.readInt32();
Eric Laurentfee19762018-01-29 18:44:13 -08001544 const String16 opPackageName = data.readString16();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001545 audio_config_base_t config;
1546 memset(&config, 0, sizeof(audio_config_base_t));
1547 data.read(&config, sizeof(audio_config_base_t));
Glenn Kastenb3b16602014-07-16 08:36:31 -07001548 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Paul McLean466dc8e2015-04-17 13:15:36 -06001549 audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001550 audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
Mikhail Naganov2996f672019-04-18 12:29:59 -07001551 status_t status = getInputForAttr(&attr, &input, riid, session, pid, uid,
Eric Laurentfee19762018-01-29 18:44:13 -08001552 opPackageName, &config,
Eric Laurent9ae8c592017-06-22 17:17:09 -07001553 flags, &selectedDeviceId, &portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001554 reply->writeInt32(status);
1555 if (status == NO_ERROR) {
1556 reply->writeInt32(input);
Eric Laurent9ae8c592017-06-22 17:17:09 -07001557 reply->writeInt32(selectedDeviceId);
Eric Laurent20b9ef02016-12-05 11:03:16 -08001558 reply->writeInt32(portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -08001559 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001560 return NO_ERROR;
1561 } break;
1562
1563 case START_INPUT: {
1564 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001565 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
Eric Laurent4eb58f12018-12-07 16:41:02 -08001566 status_t status = startInput(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001567 reply->writeInt32(static_cast <uint32_t>(status));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001568 return NO_ERROR;
1569 } break;
1570
1571 case STOP_INPUT: {
1572 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001573 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1574 reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001575 return NO_ERROR;
1576 } break;
1577
1578 case RELEASE_INPUT: {
1579 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurentfee19762018-01-29 18:44:13 -08001580 audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
1581 releaseInput(portId);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001582 return NO_ERROR;
1583 } break;
1584
1585 case INIT_STREAM_VOLUME: {
1586 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001587 audio_stream_type_t stream =
1588 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001589 int indexMin = data.readInt32();
1590 int indexMax = data.readInt32();
1591 reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
1592 return NO_ERROR;
1593 } break;
1594
1595 case SET_STREAM_VOLUME: {
1596 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001597 audio_stream_type_t stream =
1598 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurentc2f1f072009-07-17 12:17:14 -07001599 int index = data.readInt32();
Eric Laurent83844cc2011-11-18 16:43:31 -08001600 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1601 reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
1602 index,
1603 device)));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001604 return NO_ERROR;
1605 } break;
1606
1607 case GET_STREAM_VOLUME: {
1608 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001609 audio_stream_type_t stream =
1610 static_cast <audio_stream_type_t>(data.readInt32());
Eric Laurent83844cc2011-11-18 16:43:31 -08001611 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
Robert Shih89235432015-09-02 16:46:59 -07001612 int index = 0;
Eric Laurent83844cc2011-11-18 16:43:31 -08001613 status_t status = getStreamVolumeIndex(stream, &index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001614 reply->writeInt32(index);
1615 reply->writeInt32(static_cast <uint32_t>(status));
1616 return NO_ERROR;
1617 } break;
1618
Eric Laurentde070132010-07-13 04:45:46 -07001619 case GET_STRATEGY_FOR_STREAM: {
1620 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001621 audio_stream_type_t stream =
1622 static_cast <audio_stream_type_t>(data.readInt32());
François Gaffiec005e562018-11-06 15:04:49 +01001623 reply->writeUint32(getStrategyForStream(stream));
Eric Laurentde070132010-07-13 04:45:46 -07001624 return NO_ERROR;
1625 } break;
1626
François Gaffiecfe17322018-11-07 13:41:29 +01001627 case SET_VOLUME_ATTRIBUTES: {
1628 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1629 audio_attributes_t attributes = {};
1630 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1631 if (status != NO_ERROR) {
1632 return status;
1633 }
1634 int index = data.readInt32();
1635 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1636
1637 reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes,
1638 index, device)));
1639 return NO_ERROR;
1640 } break;
1641
1642 case GET_VOLUME_ATTRIBUTES: {
1643 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1644 audio_attributes_t attributes = {};
1645 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1646 if (status != NO_ERROR) {
1647 return status;
1648 }
1649 audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
1650
1651 int index = 0;
1652 status = getVolumeIndexForAttributes(attributes, index, device);
1653 reply->writeInt32(static_cast <uint32_t>(status));
1654 if (status == NO_ERROR) {
1655 reply->writeInt32(index);
1656 }
1657 return NO_ERROR;
1658 } break;
1659
1660 case GET_MIN_VOLUME_FOR_ATTRIBUTES: {
1661 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1662 audio_attributes_t attributes = {};
1663 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1664 if (status != NO_ERROR) {
1665 return status;
1666 }
1667
1668 int index = 0;
1669 status = getMinVolumeIndexForAttributes(attributes, index);
1670 reply->writeInt32(static_cast <uint32_t>(status));
1671 if (status == NO_ERROR) {
1672 reply->writeInt32(index);
1673 }
1674 return NO_ERROR;
1675 } break;
1676
1677 case GET_MAX_VOLUME_FOR_ATTRIBUTES: {
1678 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1679 audio_attributes_t attributes = {};
1680 status_t status = data.read(&attributes, sizeof(audio_attributes_t));
1681 if (status != NO_ERROR) {
1682 return status;
1683 }
1684
1685 int index = 0;
1686 status = getMaxVolumeIndexForAttributes(attributes, index);
1687 reply->writeInt32(static_cast <uint32_t>(status));
1688 if (status == NO_ERROR) {
1689 reply->writeInt32(index);
1690 }
1691 return NO_ERROR;
1692 } break;
1693
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001694 case GET_DEVICES_FOR_STREAM: {
1695 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Dima Zavinfce7a472011-04-19 22:30:36 -07001696 audio_stream_type_t stream =
1697 static_cast <audio_stream_type_t>(data.readInt32());
Glenn Kasten6b2718c2011-02-04 13:54:26 -08001698 reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
1699 return NO_ERROR;
1700 } break;
1701
Eric Laurentde070132010-07-13 04:45:46 -07001702 case GET_OUTPUT_FOR_EFFECT: {
1703 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001704 effect_descriptor_t desc = {};
1705 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1706 android_errorWriteLog(0x534e4554, "73126106");
1707 }
1708 (void)sanitizeEffectDescriptor(&desc);
Eric Laurentde070132010-07-13 04:45:46 -07001709 audio_io_handle_t output = getOutputForEffect(&desc);
1710 reply->writeInt32(static_cast <int>(output));
1711 return NO_ERROR;
1712 } break;
1713
1714 case REGISTER_EFFECT: {
1715 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001716 effect_descriptor_t desc = {};
1717 if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
1718 android_errorWriteLog(0x534e4554, "73126106");
1719 }
1720 (void)sanitizeEffectDescriptor(&desc);
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001721 audio_io_handle_t io = data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001722 uint32_t strategy = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001723 audio_session_t session = (audio_session_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001724 int id = data.readInt32();
1725 reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -07001726 io,
Eric Laurentde070132010-07-13 04:45:46 -07001727 strategy,
1728 session,
1729 id)));
1730 return NO_ERROR;
1731 } break;
1732
1733 case UNREGISTER_EFFECT: {
1734 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1735 int id = data.readInt32();
1736 reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
1737 return NO_ERROR;
1738 } break;
1739
Eric Laurentdb7c0792011-08-10 10:37:50 -07001740 case SET_EFFECT_ENABLED: {
1741 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1742 int id = data.readInt32();
1743 bool enabled = static_cast <bool>(data.readInt32());
1744 reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
1745 return NO_ERROR;
1746 } break;
1747
Eric Laurent6c796322019-04-09 14:13:17 -07001748 case MOVE_EFFECTS_TO_IO: {
1749 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1750 std::vector<int> ids;
1751 int32_t size;
1752 status_t status = data.readInt32(&size);
1753 if (status != NO_ERROR) {
1754 return status;
1755 }
1756 if (size > MAX_ITEMS_PER_LIST) {
1757 return BAD_VALUE;
1758 }
1759 for (int32_t i = 0; i < size; i++) {
1760 int id;
1761 status = data.readInt32(&id);
1762 if (status != NO_ERROR) {
1763 return status;
1764 }
1765 ids.push_back(id);
1766 }
1767
1768 audio_io_handle_t io = data.readInt32();
1769 reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io)));
1770 return NO_ERROR;
1771 } break;
1772
Eric Laurenteda6c362011-02-02 09:33:30 -08001773 case IS_STREAM_ACTIVE: {
1774 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastenfff6d712012-01-12 16:38:12 -08001775 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
Eric Laurenteda6c362011-02-02 09:33:30 -08001776 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001777 reply->writeInt32( isStreamActive(stream, inPastMs) );
Eric Laurenteda6c362011-02-02 09:33:30 -08001778 return NO_ERROR;
1779 } break;
1780
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001781 case IS_STREAM_ACTIVE_REMOTELY: {
1782 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1783 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1784 uint32_t inPastMs = (uint32_t)data.readInt32();
Eric Laurentebcb2542014-03-05 18:30:08 -08001785 reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
Jean-Michel Trivi272ab542013-02-04 16:26:02 -08001786 return NO_ERROR;
1787 } break;
1788
Jean-Michel Trivid7086032012-10-10 12:11:16 -07001789 case IS_SOURCE_ACTIVE: {
1790 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1791 audio_source_t source = (audio_source_t) data.readInt32();
1792 reply->writeInt32( isSourceActive(source));
1793 return NO_ERROR;
1794 }
1795
Eric Laurent57dae992011-07-24 13:36:09 -07001796 case QUERY_DEFAULT_PRE_PROCESSING: {
1797 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001798 audio_session_t audioSession = (audio_session_t) data.readInt32();
Eric Laurent57dae992011-07-24 13:36:09 -07001799 uint32_t count = data.readInt32();
Eric Laurent74adca92014-11-05 12:15:36 -08001800 if (count > AudioEffect::kMaxPreProcessing) {
1801 count = AudioEffect::kMaxPreProcessing;
1802 }
Eric Laurent57dae992011-07-24 13:36:09 -07001803 uint32_t retCount = count;
Andy Hungb0272092018-04-12 11:06:56 -07001804 effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
Eric Laurent57dae992011-07-24 13:36:09 -07001805 status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1806 reply->writeInt32(status);
1807 if (status != NO_ERROR && status != NO_MEMORY) {
1808 retCount = 0;
1809 }
1810 reply->writeInt32(retCount);
Eric Laurent74adca92014-11-05 12:15:36 -08001811 if (retCount != 0) {
Eric Laurent57dae992011-07-24 13:36:09 -07001812 if (retCount < count) {
1813 count = retCount;
1814 }
1815 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1816 }
1817 delete[] descriptors;
1818 return status;
1819 }
1820
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001821 case IS_OFFLOAD_SUPPORTED: {
1822 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001823 audio_offload_info_t info = {};
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001824 data.read(&info, sizeof(audio_offload_info_t));
1825 bool isSupported = isOffloadSupported(info);
1826 reply->writeInt32(isSupported);
1827 return NO_ERROR;
1828 }
1829
Michael Chana94fbb22018-04-24 14:31:19 +10001830 case IS_DIRECT_OUTPUT_SUPPORTED: {
1831 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1832 audio_config_base_t config = {};
1833 audio_attributes_t attributes = {};
1834 status_t status = data.read(&config, sizeof(audio_config_base_t));
1835 if (status != NO_ERROR) return status;
1836 status = data.read(&attributes, sizeof(audio_attributes_t));
1837 if (status != NO_ERROR) return status;
1838 reply->writeInt32(isDirectOutputSupported(config, attributes));
1839 return NO_ERROR;
1840 }
1841
Eric Laurent203b1a12014-04-01 10:34:16 -07001842 case LIST_AUDIO_PORTS: {
1843 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1844 audio_port_role_t role = (audio_port_role_t)data.readInt32();
1845 audio_port_type_t type = (audio_port_type_t)data.readInt32();
1846 unsigned int numPortsReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001847 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1848 numPortsReq = MAX_ITEMS_PER_LIST;
1849 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001850 unsigned int numPorts = numPortsReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001851 struct audio_port *ports =
1852 (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
Eric Laurent1d670b12015-02-06 10:44:24 -08001853 if (ports == NULL) {
1854 reply->writeInt32(NO_MEMORY);
1855 reply->writeInt32(0);
1856 return NO_ERROR;
1857 }
1858 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001859 status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1860 reply->writeInt32(status);
1861 reply->writeInt32(numPorts);
Eric Laurent203b1a12014-04-01 10:34:16 -07001862
1863 if (status == NO_ERROR) {
1864 if (numPortsReq > numPorts) {
1865 numPortsReq = numPorts;
1866 }
1867 reply->write(ports, numPortsReq * sizeof(struct audio_port));
1868 reply->writeInt32(generation);
1869 }
1870 free(ports);
1871 return NO_ERROR;
1872 }
1873
1874 case GET_AUDIO_PORT: {
1875 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001876 struct audio_port port = {};
1877 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1878 ALOGE("b/23912202");
1879 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001880 status_t status = getAudioPort(&port);
1881 reply->writeInt32(status);
1882 if (status == NO_ERROR) {
1883 reply->write(&port, sizeof(struct audio_port));
1884 }
1885 return NO_ERROR;
1886 }
1887
1888 case CREATE_AUDIO_PATCH: {
1889 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001890 struct audio_patch patch = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001891 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001892 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001893 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1894 ALOGE("b/23912202");
1895 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001896 status_t status = createAudioPatch(&patch, &handle);
1897 reply->writeInt32(status);
1898 if (status == NO_ERROR) {
1899 reply->write(&handle, sizeof(audio_patch_handle_t));
1900 }
1901 return NO_ERROR;
1902 }
1903
1904 case RELEASE_AUDIO_PATCH: {
1905 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001906 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent203b1a12014-04-01 10:34:16 -07001907 data.read(&handle, sizeof(audio_patch_handle_t));
1908 status_t status = releaseAudioPatch(handle);
1909 reply->writeInt32(status);
1910 return NO_ERROR;
1911 }
1912
1913 case LIST_AUDIO_PATCHES: {
1914 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1915 unsigned int numPatchesReq = data.readInt32();
Eric Laurent1d670b12015-02-06 10:44:24 -08001916 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1917 numPatchesReq = MAX_ITEMS_PER_LIST;
1918 }
Eric Laurent203b1a12014-04-01 10:34:16 -07001919 unsigned int numPatches = numPatchesReq;
Eric Laurent203b1a12014-04-01 10:34:16 -07001920 struct audio_patch *patches =
1921 (struct audio_patch *)calloc(numPatchesReq,
1922 sizeof(struct audio_patch));
Eric Laurent1d670b12015-02-06 10:44:24 -08001923 if (patches == NULL) {
1924 reply->writeInt32(NO_MEMORY);
1925 reply->writeInt32(0);
1926 return NO_ERROR;
1927 }
1928 unsigned int generation;
Eric Laurent203b1a12014-04-01 10:34:16 -07001929 status_t status = listAudioPatches(&numPatches, patches, &generation);
1930 reply->writeInt32(status);
1931 reply->writeInt32(numPatches);
1932 if (status == NO_ERROR) {
1933 if (numPatchesReq > numPatches) {
1934 numPatchesReq = numPatches;
1935 }
1936 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1937 reply->writeInt32(generation);
1938 }
1939 free(patches);
1940 return NO_ERROR;
1941 }
1942
1943 case SET_AUDIO_PORT_CONFIG: {
1944 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07001945 struct audio_port_config config = {};
Eric Laurent203b1a12014-04-01 10:34:16 -07001946 data.read(&config, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07001947 (void)sanitizeAudioPortConfig(&config);
Eric Laurent203b1a12014-04-01 10:34:16 -07001948 status_t status = setAudioPortConfig(&config);
1949 reply->writeInt32(status);
1950 return NO_ERROR;
1951 }
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001952
Eric Laurentb52c1522014-05-20 11:27:36 -07001953 case REGISTER_CLIENT: {
1954 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1955 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1956 data.readStrongBinder());
1957 registerClient(client);
1958 return NO_ERROR;
1959 } break;
Eric Laurent203b1a12014-04-01 10:34:16 -07001960
Eric Laurente8726fe2015-06-26 09:39:24 -07001961 case SET_AUDIO_PORT_CALLBACK_ENABLED: {
1962 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1963 setAudioPortCallbacksEnabled(data.readInt32() == 1);
1964 return NO_ERROR;
1965 } break;
1966
François Gaffiecfe17322018-11-07 13:41:29 +01001967 case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: {
1968 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1969 setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1);
1970 return NO_ERROR;
1971 } break;
1972
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001973 case ACQUIRE_SOUNDTRIGGER_SESSION: {
1974 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1975 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1976 data.readStrongBinder());
Glenn Kastena13cde92016-03-28 15:26:02 -07001977 audio_session_t session = AUDIO_SESSION_NONE;
1978 audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
1979 audio_devices_t device = AUDIO_DEVICE_NONE;
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001980 status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1981 reply->writeInt32(status);
1982 if (status == NO_ERROR) {
1983 reply->writeInt32(session);
1984 reply->writeInt32(ioHandle);
1985 reply->writeInt32(device);
1986 }
1987 return NO_ERROR;
1988 } break;
1989
1990 case RELEASE_SOUNDTRIGGER_SESSION: {
1991 CHECK_INTERFACE(IAudioPolicyService, data, reply);
1992 sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1993 data.readStrongBinder());
1994 audio_session_t session = (audio_session_t)data.readInt32();
1995 status_t status = releaseSoundTriggerSession(session);
1996 reply->writeInt32(status);
1997 return NO_ERROR;
1998 } break;
1999
Eric Laurentbb6c9a02014-09-25 14:11:47 -07002000 case GET_PHONE_STATE: {
2001 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2002 reply->writeInt32((int32_t)getPhoneState());
2003 return NO_ERROR;
2004 } break;
2005
Eric Laurentbaac1832014-12-01 17:52:59 -08002006 case REGISTER_POLICY_MIXES: {
2007 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2008 bool registration = data.readInt32() == 1;
2009 Vector<AudioMix> mixes;
2010 size_t size = (size_t)data.readInt32();
2011 if (size > MAX_MIXES_PER_POLICY) {
2012 size = MAX_MIXES_PER_POLICY;
2013 }
2014 for (size_t i = 0; i < size; i++) {
2015 AudioMix mix;
2016 if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
2017 mixes.add(mix);
2018 }
2019 }
2020 status_t status = registerPolicyMixes(mixes, registration);
2021 reply->writeInt32(status);
2022 return NO_ERROR;
2023 } break;
2024
Eric Laurent554a2772015-04-10 11:29:24 -07002025 case START_AUDIO_SOURCE: {
2026 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Andy Hungb0272092018-04-12 11:06:56 -07002027 struct audio_port_config source = {};
Eric Laurent554a2772015-04-10 11:29:24 -07002028 data.read(&source, sizeof(struct audio_port_config));
Andy Hungb0272092018-04-12 11:06:56 -07002029 (void)sanitizeAudioPortConfig(&source);
2030 audio_attributes_t attributes = {};
Eric Laurent554a2772015-04-10 11:29:24 -07002031 data.read(&attributes, sizeof(audio_attributes_t));
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002032 sanetizeAudioAttributes(&attributes);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002033 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
2034 status_t status = startAudioSource(&source, &attributes, &portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002035 reply->writeInt32(status);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002036 reply->writeInt32(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002037 return NO_ERROR;
2038 } break;
2039
2040 case STOP_AUDIO_SOURCE: {
2041 CHECK_INTERFACE(IAudioPolicyService, data, reply);
Eric Laurent3e6c7e12018-07-27 17:09:23 -07002042 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
2043 status_t status = stopAudioSource(portId);
Eric Laurent554a2772015-04-10 11:29:24 -07002044 reply->writeInt32(status);
2045 return NO_ERROR;
2046 } break;
2047
Andy Hung2ddee192015-12-18 17:34:44 -08002048 case SET_MASTER_MONO: {
2049 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2050 bool mono = static_cast<bool>(data.readInt32());
2051 status_t status = setMasterMono(mono);
2052 reply->writeInt32(status);
2053 return NO_ERROR;
2054 } break;
2055
2056 case GET_MASTER_MONO: {
2057 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2058 bool mono;
2059 status_t status = getMasterMono(&mono);
2060 reply->writeInt32(status);
2061 if (status == NO_ERROR) {
2062 reply->writeInt32(static_cast<int32_t>(mono));
2063 }
2064 return NO_ERROR;
2065 } break;
2066
Eric Laurentac9cef52017-06-09 15:46:26 -07002067 case GET_STREAM_VOLUME_DB: {
2068 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2069 audio_stream_type_t stream =
2070 static_cast <audio_stream_type_t>(data.readInt32());
2071 int index = static_cast <int>(data.readInt32());
2072 audio_devices_t device =
2073 static_cast <audio_devices_t>(data.readUint32());
2074 reply->writeFloat(getStreamVolumeDB(stream, index, device));
2075 return NO_ERROR;
2076 }
2077
jiabin81772902018-04-02 17:52:27 -07002078 case GET_SURROUND_FORMATS: {
2079 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2080 unsigned int numSurroundFormatsReq = data.readUint32();
2081 if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
2082 numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
2083 }
2084 bool reported = data.readBool();
2085 unsigned int numSurroundFormats = numSurroundFormatsReq;
2086 audio_format_t *surroundFormats = (audio_format_t *)calloc(
2087 numSurroundFormats, sizeof(audio_format_t));
2088 bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
2089 if (numSurroundFormatsReq > 0 &&
2090 (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
2091 free(surroundFormats);
2092 free(surroundFormatsEnabled);
2093 reply->writeInt32(NO_MEMORY);
2094 return NO_ERROR;
2095 }
2096 status_t status = getSurroundFormats(
2097 &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
2098 reply->writeInt32(status);
2099
2100 if (status == NO_ERROR) {
2101 reply->writeUint32(numSurroundFormats);
2102 if (numSurroundFormatsReq > numSurroundFormats) {
2103 numSurroundFormatsReq = numSurroundFormats;
2104 }
2105 reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
2106 reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
2107 }
2108 free(surroundFormats);
2109 free(surroundFormatsEnabled);
2110 return NO_ERROR;
2111 }
2112
2113 case SET_SURROUND_FORMAT_ENABLED: {
2114 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2115 audio_format_t audioFormat = (audio_format_t) data.readInt32();
2116 bool enabled = data.readBool();
2117 status_t status = setSurroundFormatEnabled(audioFormat, enabled);
2118 reply->writeInt32(status);
2119 return NO_ERROR;
2120 }
2121
Arun Mirpuri11029ad2018-12-19 20:45:19 -08002122 case GET_OFFLOAD_FORMATS_A2DP: {
2123 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2124 std::vector<audio_format_t> encodingFormats;
2125 status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
2126 reply->writeInt32(status);
2127 if (status != NO_ERROR) {
2128 return NO_ERROR;
2129 }
2130 reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
2131 for (size_t i = 0; i < encodingFormats.size(); i++)
2132 reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
2133 return NO_ERROR;
2134 }
2135
2136
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -07002137 case ADD_STREAM_DEFAULT_EFFECT: {
2138 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2139 effect_uuid_t type;
2140 status_t status = data.read(&type, sizeof(effect_uuid_t));
2141 if (status != NO_ERROR) {
2142 return status;
2143 }
2144 String16 opPackageName;
2145 status = data.readString16(&opPackageName);
2146 if (status != NO_ERROR) {
2147 return status;
2148 }
2149 effect_uuid_t uuid;
2150 status = data.read(&uuid, sizeof(effect_uuid_t));
2151 if (status != NO_ERROR) {
2152 return status;
2153 }
2154 int32_t priority = data.readInt32();
2155 audio_usage_t usage = (audio_usage_t) data.readInt32();
2156 audio_unique_id_t id = 0;
2157 reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
2158 opPackageName,
2159 &uuid,
2160 priority,
2161 usage,
2162 &id)));
2163 reply->writeInt32(id);
2164 return NO_ERROR;
2165 }
2166
2167 case REMOVE_STREAM_DEFAULT_EFFECT: {
2168 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2169 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2170 reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
2171 return NO_ERROR;
2172 }
2173
Ari Hausman-Cohen24628312018-08-13 15:01:09 -07002174 case ADD_SOURCE_DEFAULT_EFFECT: {
2175 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2176 effect_uuid_t type;
2177 status_t status = data.read(&type, sizeof(effect_uuid_t));
2178 if (status != NO_ERROR) {
2179 return status;
2180 }
2181 String16 opPackageName;
2182 status = data.readString16(&opPackageName);
2183 if (status != NO_ERROR) {
2184 return status;
2185 }
2186 effect_uuid_t uuid;
2187 status = data.read(&uuid, sizeof(effect_uuid_t));
2188 if (status != NO_ERROR) {
2189 return status;
2190 }
2191 int32_t priority = data.readInt32();
2192 audio_source_t source = (audio_source_t) data.readInt32();
2193 audio_unique_id_t id = 0;
2194 reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
2195 opPackageName,
2196 &uuid,
2197 priority,
2198 source,
2199 &id)));
2200 reply->writeInt32(id);
2201 return NO_ERROR;
2202 }
2203
2204 case REMOVE_SOURCE_DEFAULT_EFFECT: {
2205 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2206 audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
2207 reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
2208 return NO_ERROR;
2209 }
2210
Eric Laurentb78763e2018-10-17 10:08:02 -07002211 case SET_ASSISTANT_UID: {
2212 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2213 int32_t uid;
2214 status_t status = data.readInt32(&uid);
2215 if (status != NO_ERROR) {
2216 return status;
2217 }
2218 status = setAssistantUid(uid);
2219 reply->writeInt32(static_cast <int32_t>(status));
2220 return NO_ERROR;
2221 }
2222
2223 case SET_A11Y_SERVICES_UIDS: {
2224 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2225 std::vector<uid_t> uids;
2226 int32_t size;
2227 status_t status = data.readInt32(&size);
2228 if (status != NO_ERROR) {
2229 return status;
2230 }
2231 if (size > MAX_ITEMS_PER_LIST) {
2232 size = MAX_ITEMS_PER_LIST;
2233 }
2234 for (int32_t i = 0; i < size; i++) {
2235 int32_t uid;
2236 status = data.readInt32(&uid);
2237 if (status != NO_ERROR) {
2238 return status;
2239 }
2240 uids.push_back(uid);
2241 }
2242 status = setA11yServicesUids(uids);
2243 reply->writeInt32(static_cast <int32_t>(status));
2244 return NO_ERROR;
2245 }
2246
jiabin6012f912018-11-02 17:06:30 -07002247 case IS_HAPTIC_PLAYBACK_SUPPORTED: {
2248 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2249 bool isSupported = isHapticPlaybackSupported();
2250 reply->writeBool(isSupported);
Kevin Rocardb99cc752019-03-21 20:52:24 -07002251 return NO_ERROR;
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08002252 }
Jean-Michel Trivibda70da2018-12-19 07:30:15 -08002253 case SET_UID_DEVICE_AFFINITY: {
2254 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2255 const uid_t uid = (uid_t) data.readInt32();
2256 Vector<AudioDeviceTypeAddr> devices;
2257 size_t size = (size_t)data.readInt32();
2258 for (size_t i = 0; i < size; i++) {
2259 AudioDeviceTypeAddr device;
2260 if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
2261 devices.add(device);
2262 }
2263 }
2264 status_t status = setUidDeviceAffinities(uid, devices);
2265 reply->writeInt32(status);
2266 return NO_ERROR;
2267 }
2268
2269 case REMOVE_UID_DEVICE_AFFINITY: {
2270 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2271 const uid_t uid = (uid_t) data.readInt32();
2272 status_t status = removeUidDeviceAffinities(uid);
2273 reply->writeInt32(status);
jiabin6012f912018-11-02 17:06:30 -07002274 return NO_ERROR;
2275 }
2276
François Gaffied0ba9ed2018-11-05 11:50:42 +01002277 case LIST_AUDIO_PRODUCT_STRATEGIES: {
2278 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2279 AudioProductStrategyVector strategies;
2280 status_t status = listAudioProductStrategies(strategies);
2281 reply->writeInt32(status);
2282 if (status != NO_ERROR) {
François Gaffie4b2018b2018-11-07 11:18:59 +01002283 return NO_ERROR;
François Gaffied0ba9ed2018-11-05 11:50:42 +01002284 }
2285 size_t size = strategies.size();
2286 size_t sizePosition = reply->dataPosition();
2287 reply->writeInt32(size);
2288 size_t finalSize = size;
2289 for (size_t i = 0; i < size; i++) {
2290 size_t position = reply->dataPosition();
2291 if (strategies[i].writeToParcel(reply) != NO_ERROR) {
2292 reply->setDataPosition(position);
2293 finalSize--;
2294 }
2295 }
2296 if (size != finalSize) {
2297 size_t position = reply->dataPosition();
2298 reply->setDataPosition(sizePosition);
2299 reply->writeInt32(finalSize);
2300 reply->setDataPosition(position);
2301 }
2302 return NO_ERROR;
2303 }
2304
2305 case GET_STRATEGY_FOR_ATTRIBUTES: {
2306 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2307 AudioAttributes attributes;
2308 status_t status = attributes.readFromParcel(&data);
2309 if (status != NO_ERROR) {
2310 return status;
2311 }
François Gaffie4b2018b2018-11-07 11:18:59 +01002312 product_strategy_t strategy;
2313 status = getProductStrategyFromAudioAttributes(attributes, strategy);
2314 reply->writeInt32(status);
2315 if (status != NO_ERROR) {
2316 return NO_ERROR;
2317 }
François Gaffied0ba9ed2018-11-05 11:50:42 +01002318 reply->writeUint32(static_cast<int>(strategy));
2319 return NO_ERROR;
2320 }
2321
François Gaffie4b2018b2018-11-07 11:18:59 +01002322 case LIST_AUDIO_VOLUME_GROUPS: {
2323 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2324 AudioVolumeGroupVector groups;
2325 status_t status = listAudioVolumeGroups(groups);
2326 reply->writeInt32(status);
2327 if (status != NO_ERROR) {
2328 return NO_ERROR;
2329 }
2330 size_t size = groups.size();
2331 size_t sizePosition = reply->dataPosition();
2332 reply->writeInt32(size);
2333 size_t finalSize = size;
2334 for (size_t i = 0; i < size; i++) {
2335 size_t position = reply->dataPosition();
2336 if (groups[i].writeToParcel(reply) != NO_ERROR) {
2337 reply->setDataPosition(position);
2338 finalSize--;
2339 }
2340 }
2341 if (size != finalSize) {
2342 size_t position = reply->dataPosition();
2343 reply->setDataPosition(sizePosition);
2344 reply->writeInt32(finalSize);
2345 reply->setDataPosition(position);
2346 }
2347 return NO_ERROR;
2348 }
2349
2350 case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
2351 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2352 AudioAttributes attributes;
2353 status_t status = attributes.readFromParcel(&data);
2354 if (status != NO_ERROR) {
2355 return status;
2356 }
2357 volume_group_t group;
2358 status = getVolumeGroupFromAudioAttributes(attributes, group);
2359 reply->writeInt32(status);
2360 if (status != NO_ERROR) {
2361 return NO_ERROR;
2362 }
2363 reply->writeUint32(static_cast<int>(group));
2364 return NO_ERROR;
2365 }
2366
Kevin Rocardb99cc752019-03-21 20:52:24 -07002367 case SET_ALLOWED_CAPTURE_POLICY: {
2368 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2369 uid_t uid = data.readInt32();
2370 audio_flags_mask_t flags = data.readInt32();
2371 status_t status = setAllowedCapturePolicy(uid, flags);
2372 reply->writeInt32(status);
2373 return NO_ERROR;
2374 }
2375
Eric Laurent6ede98f2019-06-11 14:50:30 -07002376 case SET_RTT_ENABLED: {
2377 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2378 bool enabled = static_cast<bool>(data.readInt32());
2379 status_t status = setRttEnabled(enabled);
2380 reply->writeInt32(status);
2381 return NO_ERROR;
2382 }
2383
Eric Laurent8340e672019-11-06 11:01:08 -08002384 case IS_CALL_SCREEN_MODE_SUPPORTED: {
2385 CHECK_INTERFACE(IAudioPolicyService, data, reply);
2386 bool isAvailable = isCallScreenModeSupported();
2387 reply->writeBool(isAvailable);
2388 return NO_ERROR;
2389 }
2390
Eric Laurentc2f1f072009-07-17 12:17:14 -07002391 default:
2392 return BBinder::onTransact(code, data, reply, flags);
2393 }
2394}
2395
Andy Hungb0272092018-04-12 11:06:56 -07002396/** returns true if string overflow was prevented by zero termination */
2397template <size_t size>
2398static bool preventStringOverflow(char (&s)[size]) {
2399 if (strnlen(s, size) < size) return false;
2400 s[size - 1] = '\0';
2401 return true;
2402}
2403
Kevin Rocard39fdbd02017-11-13 11:15:27 -08002404void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
2405{
2406 const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
2407 if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
2408 android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
2409 }
2410 attr->tags[tagsMaxSize - 1] = '\0';
2411}
2412
Andy Hungb0272092018-04-12 11:06:56 -07002413/** returns BAD_VALUE if sanitization was required. */
2414status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
2415{
2416 if (preventStringOverflow(desc->name)
2417 | /* always */ preventStringOverflow(desc->implementor)) {
2418 android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
2419 return BAD_VALUE;
2420 }
2421 return NO_ERROR;
2422}
2423
2424/** returns BAD_VALUE if sanitization was required. */
2425status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
2426{
2427 if (config->type == AUDIO_PORT_TYPE_DEVICE &&
2428 preventStringOverflow(config->ext.device.address)) {
2429 return BAD_VALUE;
2430 }
2431 return NO_ERROR;
2432}
2433
Eric Laurentc2f1f072009-07-17 12:17:14 -07002434// ----------------------------------------------------------------------------
2435
Glenn Kasten40bc9062015-03-20 09:09:33 -07002436} // namespace android