Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 26 | #include <media/AudioEffect.h> |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 27 | #include <media/IAudioPolicyService.h> |
| 28 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 29 | #include <system/audio.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 30 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | |
| 33 | enum { |
| 34 | SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION, |
| 35 | GET_DEVICE_CONNECTION_STATE, |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 36 | HANDLE_DEVICE_CONFIG_CHANGE, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 37 | SET_PHONE_STATE, |
Glenn Kasten | 0b07b80 | 2012-01-18 14:56:06 -0800 | [diff] [blame] | 38 | SET_RINGER_MODE, // reserved, no longer used |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 39 | SET_FORCE_USE, |
| 40 | GET_FORCE_USE, |
| 41 | GET_OUTPUT, |
| 42 | START_OUTPUT, |
| 43 | STOP_OUTPUT, |
| 44 | RELEASE_OUTPUT, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 45 | GET_INPUT_FOR_ATTR, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 46 | START_INPUT, |
| 47 | STOP_INPUT, |
| 48 | RELEASE_INPUT, |
| 49 | INIT_STREAM_VOLUME, |
| 50 | SET_STREAM_VOLUME, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 51 | GET_STREAM_VOLUME, |
| 52 | GET_STRATEGY_FOR_STREAM, |
| 53 | GET_OUTPUT_FOR_EFFECT, |
| 54 | REGISTER_EFFECT, |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 55 | UNREGISTER_EFFECT, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 56 | IS_STREAM_ACTIVE, |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 57 | IS_SOURCE_ACTIVE, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 58 | GET_DEVICES_FOR_STREAM, |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 59 | QUERY_DEFAULT_PRE_PROCESSING, |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 60 | SET_EFFECT_ENABLED, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 61 | IS_STREAM_ACTIVE_REMOTELY, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 62 | IS_OFFLOAD_SUPPORTED, |
| 63 | LIST_AUDIO_PORTS, |
| 64 | GET_AUDIO_PORT, |
| 65 | CREATE_AUDIO_PATCH, |
| 66 | RELEASE_AUDIO_PATCH, |
| 67 | LIST_AUDIO_PATCHES, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 68 | SET_AUDIO_PORT_CONFIG, |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 69 | REGISTER_CLIENT, |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 70 | GET_OUTPUT_FOR_ATTR, |
| 71 | ACQUIRE_SOUNDTRIGGER_SESSION, |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 72 | RELEASE_SOUNDTRIGGER_SESSION, |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 73 | GET_PHONE_STATE, |
| 74 | REGISTER_POLICY_MIXES, |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 75 | START_AUDIO_SOURCE, |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 76 | STOP_AUDIO_SOURCE, |
| 77 | SET_AUDIO_PORT_CALLBACK_ENABLED, |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 78 | SET_MASTER_MONO, |
| 79 | GET_MASTER_MONO, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 82 | #define MAX_ITEMS_PER_LIST 1024 |
| 83 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 84 | class BpAudioPolicyService : public BpInterface<IAudioPolicyService> |
| 85 | { |
| 86 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 87 | explicit BpAudioPolicyService(const sp<IBinder>& impl) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 88 | : BpInterface<IAudioPolicyService>(impl) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | virtual status_t setDeviceConnectionState( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 93 | audio_devices_t device, |
| 94 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 95 | const char *device_address, |
| 96 | const char *device_name) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 97 | { |
| 98 | Parcel data, reply; |
| 99 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 100 | data.writeInt32(static_cast <uint32_t>(device)); |
| 101 | data.writeInt32(static_cast <uint32_t>(state)); |
| 102 | data.writeCString(device_address); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 103 | data.writeCString(device_name); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 104 | remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply); |
| 105 | return static_cast <status_t> (reply.readInt32()); |
| 106 | } |
| 107 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 108 | virtual audio_policy_dev_state_t getDeviceConnectionState( |
| 109 | audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 110 | const char *device_address) |
| 111 | { |
| 112 | Parcel data, reply; |
| 113 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 114 | data.writeInt32(static_cast <uint32_t>(device)); |
| 115 | data.writeCString(device_address); |
| 116 | remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 117 | return static_cast <audio_policy_dev_state_t>(reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 120 | virtual status_t handleDeviceConfigChange(audio_devices_t device, |
| 121 | const char *device_address, |
| 122 | const char *device_name) |
| 123 | { |
| 124 | Parcel data, reply; |
| 125 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 126 | data.writeInt32(static_cast <uint32_t>(device)); |
| 127 | data.writeCString(device_address); |
| 128 | data.writeCString(device_name); |
| 129 | remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply); |
| 130 | return static_cast <status_t> (reply.readInt32()); |
| 131 | } |
| 132 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 133 | virtual status_t setPhoneState(audio_mode_t state) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 134 | { |
| 135 | Parcel data, reply; |
| 136 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 137 | data.writeInt32(state); |
| 138 | remote()->transact(SET_PHONE_STATE, data, &reply); |
| 139 | return static_cast <status_t> (reply.readInt32()); |
| 140 | } |
| 141 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 142 | virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 143 | { |
| 144 | Parcel data, reply; |
| 145 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 146 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 147 | data.writeInt32(static_cast <uint32_t>(config)); |
| 148 | remote()->transact(SET_FORCE_USE, data, &reply); |
| 149 | return static_cast <status_t> (reply.readInt32()); |
| 150 | } |
| 151 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 152 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 153 | { |
| 154 | Parcel data, reply; |
| 155 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 156 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 157 | remote()->transact(GET_FORCE_USE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 158 | return static_cast <audio_policy_forced_cfg_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | virtual audio_io_handle_t getOutput( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 162 | audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 163 | uint32_t samplingRate, |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 164 | audio_format_t format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 165 | audio_channel_mask_t channelMask, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 166 | audio_output_flags_t flags, |
| 167 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 168 | { |
| 169 | Parcel data, reply; |
| 170 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 171 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 172 | data.writeInt32(samplingRate); |
| 173 | data.writeInt32(static_cast <uint32_t>(format)); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 174 | data.writeInt32(channelMask); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 175 | data.writeInt32(static_cast <uint32_t>(flags)); |
Glenn Kasten | 2301acc | 2014-01-17 10:21:00 -0800 | [diff] [blame] | 176 | // hasOffloadInfo |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 177 | if (offloadInfo == NULL) { |
| 178 | data.writeInt32(0); |
| 179 | } else { |
| 180 | data.writeInt32(1); |
| 181 | data.write(offloadInfo, sizeof(audio_offload_info_t)); |
| 182 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 183 | remote()->transact(GET_OUTPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 184 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 187 | virtual status_t getOutputForAttr(const audio_attributes_t *attr, |
| 188 | audio_io_handle_t *output, |
| 189 | audio_session_t session, |
| 190 | audio_stream_type_t *stream, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 191 | uid_t uid, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 192 | uint32_t samplingRate, |
| 193 | audio_format_t format, |
| 194 | audio_channel_mask_t channelMask, |
| 195 | audio_output_flags_t flags, |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 196 | audio_port_handle_t selectedDeviceId, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 197 | const audio_offload_info_t *offloadInfo) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 198 | { |
| 199 | Parcel data, reply; |
| 200 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 201 | if (attr == NULL) { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 202 | if (stream == NULL) { |
| 203 | ALOGE("getOutputForAttr(): NULL audio attributes and stream type"); |
| 204 | return BAD_VALUE; |
| 205 | } |
| 206 | if (*stream == AUDIO_STREAM_DEFAULT) { |
| 207 | ALOGE("getOutputForAttr unspecified stream type"); |
| 208 | return BAD_VALUE; |
| 209 | } |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 210 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 211 | if (output == NULL) { |
| 212 | ALOGE("getOutputForAttr NULL output - shouldn't happen"); |
| 213 | return BAD_VALUE; |
| 214 | } |
| 215 | if (attr == NULL) { |
| 216 | data.writeInt32(0); |
| 217 | } else { |
| 218 | data.writeInt32(1); |
| 219 | data.write(attr, sizeof(audio_attributes_t)); |
| 220 | } |
| 221 | data.writeInt32(session); |
| 222 | if (stream == NULL) { |
| 223 | data.writeInt32(0); |
| 224 | } else { |
| 225 | data.writeInt32(1); |
| 226 | data.writeInt32(*stream); |
| 227 | } |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 228 | data.writeInt32(uid); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 229 | data.writeInt32(samplingRate); |
| 230 | data.writeInt32(static_cast <uint32_t>(format)); |
| 231 | data.writeInt32(channelMask); |
| 232 | data.writeInt32(static_cast <uint32_t>(flags)); |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 233 | data.writeInt32(selectedDeviceId); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 234 | // hasOffloadInfo |
| 235 | if (offloadInfo == NULL) { |
| 236 | data.writeInt32(0); |
| 237 | } else { |
| 238 | data.writeInt32(1); |
| 239 | data.write(offloadInfo, sizeof(audio_offload_info_t)); |
| 240 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 241 | status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply); |
| 242 | if (status != NO_ERROR) { |
| 243 | return status; |
| 244 | } |
| 245 | status = (status_t)reply.readInt32(); |
| 246 | if (status != NO_ERROR) { |
| 247 | return status; |
| 248 | } |
| 249 | *output = (audio_io_handle_t)reply.readInt32(); |
| 250 | if (stream != NULL) { |
| 251 | *stream = (audio_stream_type_t)reply.readInt32(); |
| 252 | } |
| 253 | return status; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 256 | virtual status_t startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 257 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 258 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 259 | { |
| 260 | Parcel data, reply; |
| 261 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 262 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 263 | data.writeInt32((int32_t) stream); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 264 | data.writeInt32((int32_t) session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 265 | remote()->transact(START_OUTPUT, data, &reply); |
| 266 | return static_cast <status_t> (reply.readInt32()); |
| 267 | } |
| 268 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 269 | virtual status_t stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 270 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 271 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 272 | { |
| 273 | Parcel data, reply; |
| 274 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 275 | data.writeInt32(output); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 276 | data.writeInt32((int32_t) stream); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 277 | data.writeInt32((int32_t) session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 278 | remote()->transact(STOP_OUTPUT, data, &reply); |
| 279 | return static_cast <status_t> (reply.readInt32()); |
| 280 | } |
| 281 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 282 | virtual void releaseOutput(audio_io_handle_t output, |
| 283 | audio_stream_type_t stream, |
| 284 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 285 | { |
| 286 | Parcel data, reply; |
| 287 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 288 | data.writeInt32(output); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 289 | data.writeInt32((int32_t)stream); |
| 290 | data.writeInt32((int32_t)session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 291 | remote()->transact(RELEASE_OUTPUT, data, &reply); |
| 292 | } |
| 293 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 294 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 295 | audio_io_handle_t *input, |
| 296 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 297 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 298 | uid_t uid, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 299 | uint32_t samplingRate, |
| 300 | audio_format_t format, |
| 301 | audio_channel_mask_t channelMask, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 302 | audio_input_flags_t flags, |
| 303 | audio_port_handle_t selectedDeviceId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 304 | { |
| 305 | Parcel data, reply; |
| 306 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 307 | if (attr == NULL) { |
| 308 | ALOGE("getInputForAttr NULL attr - shouldn't happen"); |
| 309 | return BAD_VALUE; |
| 310 | } |
| 311 | if (input == NULL) { |
| 312 | ALOGE("getInputForAttr NULL input - shouldn't happen"); |
| 313 | return BAD_VALUE; |
| 314 | } |
| 315 | data.write(attr, sizeof(audio_attributes_t)); |
| 316 | data.writeInt32(session); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 317 | data.writeInt32(pid); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 318 | data.writeInt32(uid); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 319 | data.writeInt32(samplingRate); |
| 320 | data.writeInt32(static_cast <uint32_t>(format)); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 321 | data.writeInt32(channelMask); |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 322 | data.writeInt32(flags); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 323 | data.writeInt32(selectedDeviceId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 324 | status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply); |
| 325 | if (status != NO_ERROR) { |
| 326 | return status; |
| 327 | } |
| 328 | status = reply.readInt32(); |
| 329 | if (status != NO_ERROR) { |
| 330 | return status; |
| 331 | } |
| 332 | *input = (audio_io_handle_t)reply.readInt32(); |
| 333 | return NO_ERROR; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 336 | virtual status_t startInput(audio_io_handle_t input, |
| 337 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 338 | { |
| 339 | Parcel data, reply; |
| 340 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 341 | data.writeInt32(input); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 342 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 343 | remote()->transact(START_INPUT, data, &reply); |
| 344 | return static_cast <status_t> (reply.readInt32()); |
| 345 | } |
| 346 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 347 | virtual status_t stopInput(audio_io_handle_t input, |
| 348 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 349 | { |
| 350 | Parcel data, reply; |
| 351 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 352 | data.writeInt32(input); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 353 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 354 | remote()->transact(STOP_INPUT, data, &reply); |
| 355 | return static_cast <status_t> (reply.readInt32()); |
| 356 | } |
| 357 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 358 | virtual void releaseInput(audio_io_handle_t input, |
| 359 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 360 | { |
| 361 | Parcel data, reply; |
| 362 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 363 | data.writeInt32(input); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 364 | data.writeInt32(session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 365 | remote()->transact(RELEASE_INPUT, data, &reply); |
| 366 | } |
| 367 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 368 | virtual status_t initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 369 | int indexMin, |
| 370 | int indexMax) |
| 371 | { |
| 372 | Parcel data, reply; |
| 373 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 374 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 375 | data.writeInt32(indexMin); |
| 376 | data.writeInt32(indexMax); |
| 377 | remote()->transact(INIT_STREAM_VOLUME, data, &reply); |
| 378 | return static_cast <status_t> (reply.readInt32()); |
| 379 | } |
| 380 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 381 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 382 | int index, |
| 383 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 384 | { |
| 385 | Parcel data, reply; |
| 386 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 387 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 388 | data.writeInt32(index); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 389 | data.writeInt32(static_cast <uint32_t>(device)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 390 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 391 | return static_cast <status_t> (reply.readInt32()); |
| 392 | } |
| 393 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 394 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 395 | int *index, |
| 396 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 397 | { |
| 398 | Parcel data, reply; |
| 399 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 400 | data.writeInt32(static_cast <uint32_t>(stream)); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 401 | data.writeInt32(static_cast <uint32_t>(device)); |
| 402 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 403 | remote()->transact(GET_STREAM_VOLUME, data, &reply); |
| 404 | int lIndex = reply.readInt32(); |
| 405 | if (index) *index = lIndex; |
| 406 | return static_cast <status_t> (reply.readInt32()); |
| 407 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 408 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 409 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 410 | { |
| 411 | Parcel data, reply; |
| 412 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 413 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 414 | remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply); |
| 415 | return reply.readInt32(); |
| 416 | } |
| 417 | |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 418 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 419 | { |
| 420 | Parcel data, reply; |
| 421 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 422 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 423 | remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply); |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 424 | return (audio_devices_t) reply.readInt32(); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 427 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 428 | { |
| 429 | Parcel data, reply; |
| 430 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 431 | data.write(desc, sizeof(effect_descriptor_t)); |
| 432 | remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply); |
| 433 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
| 434 | } |
| 435 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 436 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 437 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 438 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 439 | audio_session_t session, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 440 | int id) |
| 441 | { |
| 442 | Parcel data, reply; |
| 443 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 444 | data.write(desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 445 | data.writeInt32(io); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 446 | data.writeInt32(strategy); |
| 447 | data.writeInt32(session); |
| 448 | data.writeInt32(id); |
| 449 | remote()->transact(REGISTER_EFFECT, data, &reply); |
| 450 | return static_cast <status_t> (reply.readInt32()); |
| 451 | } |
| 452 | |
| 453 | virtual status_t unregisterEffect(int id) |
| 454 | { |
| 455 | Parcel data, reply; |
| 456 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 457 | data.writeInt32(id); |
| 458 | remote()->transact(UNREGISTER_EFFECT, data, &reply); |
| 459 | return static_cast <status_t> (reply.readInt32()); |
| 460 | } |
| 461 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 462 | virtual status_t setEffectEnabled(int id, bool enabled) |
| 463 | { |
| 464 | Parcel data, reply; |
| 465 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 466 | data.writeInt32(id); |
| 467 | data.writeInt32(enabled); |
| 468 | remote()->transact(SET_EFFECT_ENABLED, data, &reply); |
| 469 | return static_cast <status_t> (reply.readInt32()); |
| 470 | } |
| 471 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 472 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 473 | { |
| 474 | Parcel data, reply; |
| 475 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 476 | data.writeInt32((int32_t) stream); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 477 | data.writeInt32(inPastMs); |
| 478 | remote()->transact(IS_STREAM_ACTIVE, data, &reply); |
| 479 | return reply.readInt32(); |
| 480 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 481 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 482 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 483 | { |
| 484 | Parcel data, reply; |
| 485 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 486 | data.writeInt32((int32_t) stream); |
| 487 | data.writeInt32(inPastMs); |
| 488 | remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply); |
| 489 | return reply.readInt32(); |
| 490 | } |
| 491 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 492 | virtual bool isSourceActive(audio_source_t source) const |
| 493 | { |
| 494 | Parcel data, reply; |
| 495 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 496 | data.writeInt32((int32_t) source); |
| 497 | remote()->transact(IS_SOURCE_ACTIVE, data, &reply); |
| 498 | return reply.readInt32(); |
| 499 | } |
| 500 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 501 | virtual status_t queryDefaultPreProcessing(audio_session_t audioSession, |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 502 | effect_descriptor_t *descriptors, |
| 503 | uint32_t *count) |
| 504 | { |
| 505 | if (descriptors == NULL || count == NULL) { |
| 506 | return BAD_VALUE; |
| 507 | } |
| 508 | Parcel data, reply; |
| 509 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 510 | data.writeInt32(audioSession); |
| 511 | data.writeInt32(*count); |
| 512 | status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply); |
| 513 | if (status != NO_ERROR) { |
| 514 | return status; |
| 515 | } |
| 516 | status = static_cast <status_t> (reply.readInt32()); |
| 517 | uint32_t retCount = reply.readInt32(); |
| 518 | if (retCount != 0) { |
| 519 | uint32_t numDesc = (retCount < *count) ? retCount : *count; |
| 520 | reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc); |
| 521 | } |
| 522 | *count = retCount; |
| 523 | return status; |
| 524 | } |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 525 | |
| 526 | virtual bool isOffloadSupported(const audio_offload_info_t& info) |
| 527 | { |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 528 | Parcel data, reply; |
| 529 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 530 | data.write(&info, sizeof(audio_offload_info_t)); |
| 531 | remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 532 | return reply.readInt32(); |
| 533 | } |
| 534 | |
| 535 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 536 | audio_port_type_t type, |
| 537 | unsigned int *num_ports, |
| 538 | struct audio_port *ports, |
| 539 | unsigned int *generation) |
| 540 | { |
| 541 | if (num_ports == NULL || (*num_ports != 0 && ports == NULL) || |
| 542 | generation == NULL) { |
| 543 | return BAD_VALUE; |
| 544 | } |
| 545 | Parcel data, reply; |
| 546 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 547 | unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports; |
| 548 | data.writeInt32(role); |
| 549 | data.writeInt32(type); |
| 550 | data.writeInt32(numPortsReq); |
| 551 | status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply); |
| 552 | if (status == NO_ERROR) { |
| 553 | status = (status_t)reply.readInt32(); |
| 554 | *num_ports = (unsigned int)reply.readInt32(); |
| 555 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 556 | if (status == NO_ERROR) { |
| 557 | if (numPortsReq > *num_ports) { |
| 558 | numPortsReq = *num_ports; |
| 559 | } |
| 560 | if (numPortsReq > 0) { |
| 561 | reply.read(ports, numPortsReq * sizeof(struct audio_port)); |
| 562 | } |
| 563 | *generation = reply.readInt32(); |
| 564 | } |
| 565 | return status; |
| 566 | } |
| 567 | |
| 568 | virtual status_t getAudioPort(struct audio_port *port) |
| 569 | { |
| 570 | if (port == NULL) { |
| 571 | return BAD_VALUE; |
| 572 | } |
| 573 | Parcel data, reply; |
| 574 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 575 | data.write(port, sizeof(struct audio_port)); |
| 576 | status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply); |
| 577 | if (status != NO_ERROR || |
| 578 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 579 | return status; |
| 580 | } |
| 581 | reply.read(port, sizeof(struct audio_port)); |
| 582 | return status; |
| 583 | } |
| 584 | |
| 585 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 586 | audio_patch_handle_t *handle) |
| 587 | { |
| 588 | if (patch == NULL || handle == NULL) { |
| 589 | return BAD_VALUE; |
| 590 | } |
| 591 | Parcel data, reply; |
| 592 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 593 | data.write(patch, sizeof(struct audio_patch)); |
| 594 | data.write(handle, sizeof(audio_patch_handle_t)); |
| 595 | status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply); |
| 596 | if (status != NO_ERROR || |
| 597 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 598 | return status; |
| 599 | } |
| 600 | reply.read(handle, sizeof(audio_patch_handle_t)); |
| 601 | return status; |
| 602 | } |
| 603 | |
| 604 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle) |
| 605 | { |
| 606 | Parcel data, reply; |
| 607 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 608 | data.write(&handle, sizeof(audio_patch_handle_t)); |
| 609 | status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply); |
| 610 | if (status != NO_ERROR) { |
| 611 | status = (status_t)reply.readInt32(); |
| 612 | } |
| 613 | return status; |
| 614 | } |
| 615 | |
| 616 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 617 | struct audio_patch *patches, |
| 618 | unsigned int *generation) |
| 619 | { |
| 620 | if (num_patches == NULL || (*num_patches != 0 && patches == NULL) || |
| 621 | generation == NULL) { |
| 622 | return BAD_VALUE; |
| 623 | } |
| 624 | Parcel data, reply; |
| 625 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 626 | unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches; |
| 627 | data.writeInt32(numPatchesReq); |
| 628 | status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply); |
| 629 | if (status == NO_ERROR) { |
| 630 | status = (status_t)reply.readInt32(); |
| 631 | *num_patches = (unsigned int)reply.readInt32(); |
| 632 | } |
| 633 | if (status == NO_ERROR) { |
| 634 | if (numPatchesReq > *num_patches) { |
| 635 | numPatchesReq = *num_patches; |
| 636 | } |
| 637 | if (numPatchesReq > 0) { |
| 638 | reply.read(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 639 | } |
| 640 | *generation = reply.readInt32(); |
| 641 | } |
| 642 | return status; |
| 643 | } |
| 644 | |
| 645 | virtual status_t setAudioPortConfig(const struct audio_port_config *config) |
| 646 | { |
| 647 | if (config == NULL) { |
| 648 | return BAD_VALUE; |
| 649 | } |
| 650 | Parcel data, reply; |
| 651 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 652 | data.write(config, sizeof(struct audio_port_config)); |
| 653 | status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply); |
| 654 | if (status != NO_ERROR) { |
| 655 | status = (status_t)reply.readInt32(); |
| 656 | } |
| 657 | return status; |
| 658 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 659 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 660 | virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) |
| 661 | { |
| 662 | Parcel data, reply; |
| 663 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 664 | data.writeStrongBinder(IInterface::asBinder(client)); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 665 | remote()->transact(REGISTER_CLIENT, data, &reply); |
| 666 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 667 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 668 | virtual void setAudioPortCallbacksEnabled(bool enabled) |
| 669 | { |
| 670 | Parcel data, reply; |
| 671 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 672 | data.writeInt32(enabled ? 1 : 0); |
| 673 | remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply); |
| 674 | } |
| 675 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 676 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 677 | audio_io_handle_t *ioHandle, |
| 678 | audio_devices_t *device) |
| 679 | { |
| 680 | if (session == NULL || ioHandle == NULL || device == NULL) { |
| 681 | return BAD_VALUE; |
| 682 | } |
| 683 | Parcel data, reply; |
| 684 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 685 | status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply); |
| 686 | if (status != NO_ERROR) { |
| 687 | return status; |
| 688 | } |
| 689 | status = (status_t)reply.readInt32(); |
| 690 | if (status == NO_ERROR) { |
| 691 | *session = (audio_session_t)reply.readInt32(); |
| 692 | *ioHandle = (audio_io_handle_t)reply.readInt32(); |
| 693 | *device = (audio_devices_t)reply.readInt32(); |
| 694 | } |
| 695 | return status; |
| 696 | } |
| 697 | |
| 698 | virtual status_t releaseSoundTriggerSession(audio_session_t session) |
| 699 | { |
| 700 | Parcel data, reply; |
| 701 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 702 | data.writeInt32(session); |
| 703 | status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply); |
| 704 | if (status != NO_ERROR) { |
| 705 | return status; |
| 706 | } |
| 707 | return (status_t)reply.readInt32(); |
| 708 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 709 | |
| 710 | virtual audio_mode_t getPhoneState() |
| 711 | { |
| 712 | Parcel data, reply; |
| 713 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 714 | status_t status = remote()->transact(GET_PHONE_STATE, data, &reply); |
| 715 | if (status != NO_ERROR) { |
| 716 | return AUDIO_MODE_INVALID; |
| 717 | } |
| 718 | return (audio_mode_t)reply.readInt32(); |
| 719 | } |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 720 | |
Chih-Hung Hsieh | 36d0ca1 | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 721 | virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 722 | { |
| 723 | Parcel data, reply; |
| 724 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 725 | data.writeInt32(registration ? 1 : 0); |
| 726 | size_t size = mixes.size(); |
| 727 | if (size > MAX_MIXES_PER_POLICY) { |
| 728 | size = MAX_MIXES_PER_POLICY; |
| 729 | } |
| 730 | size_t sizePosition = data.dataPosition(); |
| 731 | data.writeInt32(size); |
| 732 | size_t finalSize = size; |
| 733 | for (size_t i = 0; i < size; i++) { |
| 734 | size_t position = data.dataPosition(); |
| 735 | if (mixes[i].writeToParcel(&data) != NO_ERROR) { |
| 736 | data.setDataPosition(position); |
| 737 | finalSize--; |
| 738 | } |
| 739 | } |
| 740 | if (size != finalSize) { |
| 741 | size_t position = data.dataPosition(); |
| 742 | data.setDataPosition(sizePosition); |
| 743 | data.writeInt32(finalSize); |
| 744 | data.setDataPosition(position); |
| 745 | } |
| 746 | status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply); |
| 747 | if (status == NO_ERROR) { |
| 748 | status = (status_t)reply.readInt32(); |
| 749 | } |
| 750 | return status; |
| 751 | } |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 752 | |
| 753 | virtual status_t startAudioSource(const struct audio_port_config *source, |
| 754 | const audio_attributes_t *attributes, |
| 755 | audio_io_handle_t *handle) |
| 756 | { |
| 757 | Parcel data, reply; |
| 758 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 759 | if (source == NULL || attributes == NULL || handle == NULL) { |
| 760 | return BAD_VALUE; |
| 761 | } |
| 762 | data.write(source, sizeof(struct audio_port_config)); |
| 763 | data.write(attributes, sizeof(audio_attributes_t)); |
| 764 | status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply); |
| 765 | if (status != NO_ERROR) { |
| 766 | return status; |
| 767 | } |
| 768 | status = (status_t)reply.readInt32(); |
| 769 | if (status != NO_ERROR) { |
| 770 | return status; |
| 771 | } |
| 772 | *handle = (audio_io_handle_t)reply.readInt32(); |
| 773 | return status; |
| 774 | } |
| 775 | |
| 776 | virtual status_t stopAudioSource(audio_io_handle_t handle) |
| 777 | { |
| 778 | Parcel data, reply; |
| 779 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 780 | data.writeInt32(handle); |
| 781 | status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply); |
| 782 | if (status != NO_ERROR) { |
| 783 | return status; |
| 784 | } |
| 785 | status = (status_t)reply.readInt32(); |
| 786 | return status; |
| 787 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 788 | |
| 789 | virtual status_t setMasterMono(bool mono) |
| 790 | { |
| 791 | Parcel data, reply; |
| 792 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 793 | data.writeInt32(static_cast<int32_t>(mono)); |
| 794 | status_t status = remote()->transact(SET_MASTER_MONO, data, &reply); |
| 795 | if (status != NO_ERROR) { |
| 796 | return status; |
| 797 | } |
| 798 | return static_cast<status_t>(reply.readInt32()); |
| 799 | } |
| 800 | |
| 801 | virtual status_t getMasterMono(bool *mono) |
| 802 | { |
| 803 | if (mono == nullptr) { |
| 804 | return BAD_VALUE; |
| 805 | } |
| 806 | Parcel data, reply; |
| 807 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 808 | |
| 809 | status_t status = remote()->transact(GET_MASTER_MONO, data, &reply); |
| 810 | if (status != NO_ERROR) { |
| 811 | return status; |
| 812 | } |
| 813 | status = static_cast<status_t>(reply.readInt32()); |
| 814 | if (status == NO_ERROR) { |
| 815 | *mono = static_cast<bool>(reply.readInt32()); |
| 816 | } |
| 817 | return status; |
| 818 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 819 | }; |
| 820 | |
| 821 | IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService"); |
| 822 | |
| 823 | // ---------------------------------------------------------------------- |
| 824 | |
| 825 | |
| 826 | status_t BnAudioPolicyService::onTransact( |
| 827 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 828 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 829 | switch (code) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 830 | case SET_DEVICE_CONNECTION_STATE: { |
| 831 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 832 | audio_devices_t device = |
| 833 | static_cast <audio_devices_t>(data.readInt32()); |
| 834 | audio_policy_dev_state_t state = |
| 835 | static_cast <audio_policy_dev_state_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 836 | const char *device_address = data.readCString(); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 837 | const char *device_name = data.readCString(); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame^] | 838 | if (device_address == nullptr || device_name == nullptr) { |
| 839 | ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device); |
| 840 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 841 | } else { |
| 842 | reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device, |
| 843 | state, |
| 844 | device_address, |
| 845 | device_name))); |
| 846 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 847 | return NO_ERROR; |
| 848 | } break; |
| 849 | |
| 850 | case GET_DEVICE_CONNECTION_STATE: { |
| 851 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 852 | audio_devices_t device = |
| 853 | static_cast<audio_devices_t> (data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 854 | const char *device_address = data.readCString(); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame^] | 855 | if (device_address == nullptr) { |
| 856 | ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device); |
| 857 | reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
| 858 | } else { |
| 859 | reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device, |
| 860 | device_address))); |
| 861 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 862 | return NO_ERROR; |
| 863 | } break; |
| 864 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 865 | case HANDLE_DEVICE_CONFIG_CHANGE: { |
| 866 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 867 | audio_devices_t device = |
| 868 | static_cast <audio_devices_t>(data.readInt32()); |
| 869 | const char *device_address = data.readCString(); |
| 870 | const char *device_name = data.readCString(); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame^] | 871 | if (device_address == nullptr || device_name == nullptr) { |
| 872 | ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device); |
| 873 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 874 | } else { |
| 875 | reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device, |
| 876 | device_address, |
| 877 | device_name))); |
| 878 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 879 | return NO_ERROR; |
| 880 | } break; |
| 881 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 882 | case SET_PHONE_STATE: { |
| 883 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 884 | reply->writeInt32(static_cast <uint32_t>(setPhoneState( |
| 885 | (audio_mode_t) data.readInt32()))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 886 | return NO_ERROR; |
| 887 | } break; |
| 888 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 889 | case SET_FORCE_USE: { |
| 890 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 891 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 892 | data.readInt32()); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 893 | audio_policy_forced_cfg_t config = |
| 894 | static_cast <audio_policy_forced_cfg_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 895 | reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config))); |
| 896 | return NO_ERROR; |
| 897 | } break; |
| 898 | |
| 899 | case GET_FORCE_USE: { |
| 900 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 901 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 902 | data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 903 | reply->writeInt32(static_cast <uint32_t>(getForceUse(usage))); |
| 904 | return NO_ERROR; |
| 905 | } break; |
| 906 | |
| 907 | case GET_OUTPUT: { |
| 908 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 909 | audio_stream_type_t stream = |
| 910 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 911 | uint32_t samplingRate = data.readInt32(); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 912 | audio_format_t format = (audio_format_t) data.readInt32(); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 913 | audio_channel_mask_t channelMask = data.readInt32(); |
Eric Laurent | 0ca3cf9 | 2012-04-18 09:24:29 -0700 | [diff] [blame] | 914 | audio_output_flags_t flags = |
| 915 | static_cast <audio_output_flags_t>(data.readInt32()); |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 916 | bool hasOffloadInfo = data.readInt32() != 0; |
| 917 | audio_offload_info_t offloadInfo; |
| 918 | if (hasOffloadInfo) { |
| 919 | data.read(&offloadInfo, sizeof(audio_offload_info_t)); |
| 920 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 921 | audio_io_handle_t output = getOutput(stream, |
| 922 | samplingRate, |
| 923 | format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 924 | channelMask, |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 925 | flags, |
| 926 | hasOffloadInfo ? &offloadInfo : NULL); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 927 | reply->writeInt32(static_cast <int>(output)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 928 | return NO_ERROR; |
| 929 | } break; |
| 930 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 931 | case GET_OUTPUT_FOR_ATTR: { |
| 932 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85f480e | 2014-11-05 17:44:51 -0800 | [diff] [blame] | 933 | audio_attributes_t attr; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 934 | bool hasAttributes = data.readInt32() != 0; |
| 935 | if (hasAttributes) { |
| 936 | data.read(&attr, sizeof(audio_attributes_t)); |
| 937 | } |
| 938 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 939 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 940 | bool hasStream = data.readInt32() != 0; |
| 941 | if (hasStream) { |
| 942 | stream = (audio_stream_type_t)data.readInt32(); |
| 943 | } |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 944 | uid_t uid = (uid_t)data.readInt32(); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 945 | uint32_t samplingRate = data.readInt32(); |
| 946 | audio_format_t format = (audio_format_t) data.readInt32(); |
| 947 | audio_channel_mask_t channelMask = data.readInt32(); |
| 948 | audio_output_flags_t flags = |
| 949 | static_cast <audio_output_flags_t>(data.readInt32()); |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 950 | audio_port_handle_t selectedDeviceId = data.readInt32(); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 951 | bool hasOffloadInfo = data.readInt32() != 0; |
| 952 | audio_offload_info_t offloadInfo; |
| 953 | if (hasOffloadInfo) { |
| 954 | data.read(&offloadInfo, sizeof(audio_offload_info_t)); |
| 955 | } |
Robert Shih | a946d84 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 956 | audio_io_handle_t output = 0; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 957 | status_t status = getOutputForAttr(hasAttributes ? &attr : NULL, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 958 | &output, session, &stream, uid, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 959 | samplingRate, format, channelMask, |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 960 | flags, selectedDeviceId, hasOffloadInfo ? &offloadInfo : NULL); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 961 | reply->writeInt32(status); |
| 962 | reply->writeInt32(output); |
| 963 | reply->writeInt32(stream); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 964 | return NO_ERROR; |
| 965 | } break; |
| 966 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 967 | case START_OUTPUT: { |
| 968 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 969 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 970 | audio_stream_type_t stream = |
| 971 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 972 | audio_session_t session = (audio_session_t)data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 973 | reply->writeInt32(static_cast <uint32_t>(startOutput(output, |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 974 | stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 975 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 976 | return NO_ERROR; |
| 977 | } break; |
| 978 | |
| 979 | case STOP_OUTPUT: { |
| 980 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 981 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 982 | audio_stream_type_t stream = |
| 983 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 984 | audio_session_t session = (audio_session_t)data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 985 | reply->writeInt32(static_cast <uint32_t>(stopOutput(output, |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 986 | stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 987 | session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 988 | return NO_ERROR; |
| 989 | } break; |
| 990 | |
| 991 | case RELEASE_OUTPUT: { |
| 992 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 993 | audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 994 | audio_stream_type_t stream = (audio_stream_type_t)data.readInt32(); |
| 995 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 996 | releaseOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 997 | return NO_ERROR; |
| 998 | } break; |
| 999 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1000 | case GET_INPUT_FOR_ATTR: { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1001 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1002 | audio_attributes_t attr; |
| 1003 | data.read(&attr, sizeof(audio_attributes_t)); |
| 1004 | audio_session_t session = (audio_session_t)data.readInt32(); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 1005 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 1006 | uid_t uid = (uid_t)data.readInt32(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1007 | uint32_t samplingRate = data.readInt32(); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 1008 | audio_format_t format = (audio_format_t) data.readInt32(); |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 1009 | audio_channel_mask_t channelMask = data.readInt32(); |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 1010 | audio_input_flags_t flags = (audio_input_flags_t) data.readInt32(); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 1011 | audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32(); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 1012 | audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 1013 | status_t status = getInputForAttr(&attr, &input, session, pid, uid, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1014 | samplingRate, format, channelMask, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 1015 | flags, selectedDeviceId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1016 | reply->writeInt32(status); |
| 1017 | if (status == NO_ERROR) { |
| 1018 | reply->writeInt32(input); |
| 1019 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1020 | return NO_ERROR; |
| 1021 | } break; |
| 1022 | |
| 1023 | case START_INPUT: { |
| 1024 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1025 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1026 | audio_session_t session = static_cast <audio_session_t>(data.readInt32()); |
| 1027 | reply->writeInt32(static_cast <uint32_t>(startInput(input, session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1028 | return NO_ERROR; |
| 1029 | } break; |
| 1030 | |
| 1031 | case STOP_INPUT: { |
| 1032 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1033 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1034 | audio_session_t session = static_cast <audio_session_t>(data.readInt32()); |
| 1035 | reply->writeInt32(static_cast <uint32_t>(stopInput(input, session))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1036 | return NO_ERROR; |
| 1037 | } break; |
| 1038 | |
| 1039 | case RELEASE_INPUT: { |
| 1040 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1041 | audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32()); |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 1042 | audio_session_t session = static_cast <audio_session_t>(data.readInt32()); |
| 1043 | releaseInput(input, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1044 | return NO_ERROR; |
| 1045 | } break; |
| 1046 | |
| 1047 | case INIT_STREAM_VOLUME: { |
| 1048 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1049 | audio_stream_type_t stream = |
| 1050 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1051 | int indexMin = data.readInt32(); |
| 1052 | int indexMax = data.readInt32(); |
| 1053 | reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax))); |
| 1054 | return NO_ERROR; |
| 1055 | } break; |
| 1056 | |
| 1057 | case SET_STREAM_VOLUME: { |
| 1058 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1059 | audio_stream_type_t stream = |
| 1060 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1061 | int index = data.readInt32(); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1062 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1063 | reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, |
| 1064 | index, |
| 1065 | device))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1066 | return NO_ERROR; |
| 1067 | } break; |
| 1068 | |
| 1069 | case GET_STREAM_VOLUME: { |
| 1070 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1071 | audio_stream_type_t stream = |
| 1072 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1073 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
Robert Shih | 8923543 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 1074 | int index = 0; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1075 | status_t status = getStreamVolumeIndex(stream, &index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1076 | reply->writeInt32(index); |
| 1077 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1078 | return NO_ERROR; |
| 1079 | } break; |
| 1080 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1081 | case GET_STRATEGY_FOR_STREAM: { |
| 1082 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1083 | audio_stream_type_t stream = |
| 1084 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1085 | reply->writeInt32(getStrategyForStream(stream)); |
| 1086 | return NO_ERROR; |
| 1087 | } break; |
| 1088 | |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1089 | case GET_DEVICES_FOR_STREAM: { |
| 1090 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1091 | audio_stream_type_t stream = |
| 1092 | static_cast <audio_stream_type_t>(data.readInt32()); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1093 | reply->writeInt32(static_cast <int>(getDevicesForStream(stream))); |
| 1094 | return NO_ERROR; |
| 1095 | } break; |
| 1096 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1097 | case GET_OUTPUT_FOR_EFFECT: { |
| 1098 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1099 | effect_descriptor_t desc; |
| 1100 | data.read(&desc, sizeof(effect_descriptor_t)); |
| 1101 | audio_io_handle_t output = getOutputForEffect(&desc); |
| 1102 | reply->writeInt32(static_cast <int>(output)); |
| 1103 | return NO_ERROR; |
| 1104 | } break; |
| 1105 | |
| 1106 | case REGISTER_EFFECT: { |
| 1107 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1108 | effect_descriptor_t desc; |
| 1109 | data.read(&desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1110 | audio_io_handle_t io = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1111 | uint32_t strategy = data.readInt32(); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1112 | audio_session_t session = (audio_session_t) data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1113 | int id = data.readInt32(); |
| 1114 | reply->writeInt32(static_cast <int32_t>(registerEffect(&desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1115 | io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1116 | strategy, |
| 1117 | session, |
| 1118 | id))); |
| 1119 | return NO_ERROR; |
| 1120 | } break; |
| 1121 | |
| 1122 | case UNREGISTER_EFFECT: { |
| 1123 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1124 | int id = data.readInt32(); |
| 1125 | reply->writeInt32(static_cast <int32_t>(unregisterEffect(id))); |
| 1126 | return NO_ERROR; |
| 1127 | } break; |
| 1128 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1129 | case SET_EFFECT_ENABLED: { |
| 1130 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1131 | int id = data.readInt32(); |
| 1132 | bool enabled = static_cast <bool>(data.readInt32()); |
| 1133 | reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled))); |
| 1134 | return NO_ERROR; |
| 1135 | } break; |
| 1136 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1137 | case IS_STREAM_ACTIVE: { |
| 1138 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1139 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1140 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1141 | reply->writeInt32( isStreamActive(stream, inPastMs) ); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1142 | return NO_ERROR; |
| 1143 | } break; |
| 1144 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1145 | case IS_STREAM_ACTIVE_REMOTELY: { |
| 1146 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1147 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
| 1148 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1149 | reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) ); |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1150 | return NO_ERROR; |
| 1151 | } break; |
| 1152 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1153 | case IS_SOURCE_ACTIVE: { |
| 1154 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1155 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 1156 | reply->writeInt32( isSourceActive(source)); |
| 1157 | return NO_ERROR; |
| 1158 | } |
| 1159 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1160 | case QUERY_DEFAULT_PRE_PROCESSING: { |
| 1161 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1162 | audio_session_t audioSession = (audio_session_t) data.readInt32(); |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1163 | uint32_t count = data.readInt32(); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1164 | if (count > AudioEffect::kMaxPreProcessing) { |
| 1165 | count = AudioEffect::kMaxPreProcessing; |
| 1166 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1167 | uint32_t retCount = count; |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1168 | effect_descriptor_t *descriptors = new effect_descriptor_t[count]; |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1169 | status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount); |
| 1170 | reply->writeInt32(status); |
| 1171 | if (status != NO_ERROR && status != NO_MEMORY) { |
| 1172 | retCount = 0; |
| 1173 | } |
| 1174 | reply->writeInt32(retCount); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1175 | if (retCount != 0) { |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1176 | if (retCount < count) { |
| 1177 | count = retCount; |
| 1178 | } |
| 1179 | reply->write(descriptors, sizeof(effect_descriptor_t) * count); |
| 1180 | } |
| 1181 | delete[] descriptors; |
| 1182 | return status; |
| 1183 | } |
| 1184 | |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 1185 | case IS_OFFLOAD_SUPPORTED: { |
| 1186 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1187 | audio_offload_info_t info; |
| 1188 | data.read(&info, sizeof(audio_offload_info_t)); |
| 1189 | bool isSupported = isOffloadSupported(info); |
| 1190 | reply->writeInt32(isSupported); |
| 1191 | return NO_ERROR; |
| 1192 | } |
| 1193 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1194 | case LIST_AUDIO_PORTS: { |
| 1195 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1196 | audio_port_role_t role = (audio_port_role_t)data.readInt32(); |
| 1197 | audio_port_type_t type = (audio_port_type_t)data.readInt32(); |
| 1198 | unsigned int numPortsReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 1199 | if (numPortsReq > MAX_ITEMS_PER_LIST) { |
| 1200 | numPortsReq = MAX_ITEMS_PER_LIST; |
| 1201 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1202 | unsigned int numPorts = numPortsReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1203 | struct audio_port *ports = |
| 1204 | (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 1205 | if (ports == NULL) { |
| 1206 | reply->writeInt32(NO_MEMORY); |
| 1207 | reply->writeInt32(0); |
| 1208 | return NO_ERROR; |
| 1209 | } |
| 1210 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1211 | status_t status = listAudioPorts(role, type, &numPorts, ports, &generation); |
| 1212 | reply->writeInt32(status); |
| 1213 | reply->writeInt32(numPorts); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1214 | |
| 1215 | if (status == NO_ERROR) { |
| 1216 | if (numPortsReq > numPorts) { |
| 1217 | numPortsReq = numPorts; |
| 1218 | } |
| 1219 | reply->write(ports, numPortsReq * sizeof(struct audio_port)); |
| 1220 | reply->writeInt32(generation); |
| 1221 | } |
| 1222 | free(ports); |
| 1223 | return NO_ERROR; |
| 1224 | } |
| 1225 | |
| 1226 | case GET_AUDIO_PORT: { |
| 1227 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1228 | struct audio_port port = {}; |
| 1229 | if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) { |
| 1230 | ALOGE("b/23912202"); |
| 1231 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1232 | status_t status = getAudioPort(&port); |
| 1233 | reply->writeInt32(status); |
| 1234 | if (status == NO_ERROR) { |
| 1235 | reply->write(&port, sizeof(struct audio_port)); |
| 1236 | } |
| 1237 | return NO_ERROR; |
| 1238 | } |
| 1239 | |
| 1240 | case CREATE_AUDIO_PATCH: { |
| 1241 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1242 | struct audio_patch patch; |
| 1243 | data.read(&patch, sizeof(struct audio_patch)); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 1244 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1245 | if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) { |
| 1246 | ALOGE("b/23912202"); |
| 1247 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1248 | status_t status = createAudioPatch(&patch, &handle); |
| 1249 | reply->writeInt32(status); |
| 1250 | if (status == NO_ERROR) { |
| 1251 | reply->write(&handle, sizeof(audio_patch_handle_t)); |
| 1252 | } |
| 1253 | return NO_ERROR; |
| 1254 | } |
| 1255 | |
| 1256 | case RELEASE_AUDIO_PATCH: { |
| 1257 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1258 | audio_patch_handle_t handle; |
| 1259 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 1260 | status_t status = releaseAudioPatch(handle); |
| 1261 | reply->writeInt32(status); |
| 1262 | return NO_ERROR; |
| 1263 | } |
| 1264 | |
| 1265 | case LIST_AUDIO_PATCHES: { |
| 1266 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1267 | unsigned int numPatchesReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 1268 | if (numPatchesReq > MAX_ITEMS_PER_LIST) { |
| 1269 | numPatchesReq = MAX_ITEMS_PER_LIST; |
| 1270 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1271 | unsigned int numPatches = numPatchesReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1272 | struct audio_patch *patches = |
| 1273 | (struct audio_patch *)calloc(numPatchesReq, |
| 1274 | sizeof(struct audio_patch)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 1275 | if (patches == NULL) { |
| 1276 | reply->writeInt32(NO_MEMORY); |
| 1277 | reply->writeInt32(0); |
| 1278 | return NO_ERROR; |
| 1279 | } |
| 1280 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1281 | status_t status = listAudioPatches(&numPatches, patches, &generation); |
| 1282 | reply->writeInt32(status); |
| 1283 | reply->writeInt32(numPatches); |
| 1284 | if (status == NO_ERROR) { |
| 1285 | if (numPatchesReq > numPatches) { |
| 1286 | numPatchesReq = numPatches; |
| 1287 | } |
| 1288 | reply->write(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 1289 | reply->writeInt32(generation); |
| 1290 | } |
| 1291 | free(patches); |
| 1292 | return NO_ERROR; |
| 1293 | } |
| 1294 | |
| 1295 | case SET_AUDIO_PORT_CONFIG: { |
| 1296 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1297 | struct audio_port_config config; |
| 1298 | data.read(&config, sizeof(struct audio_port_config)); |
| 1299 | status_t status = setAudioPortConfig(&config); |
| 1300 | reply->writeInt32(status); |
| 1301 | return NO_ERROR; |
| 1302 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1303 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1304 | case REGISTER_CLIENT: { |
| 1305 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1306 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 1307 | data.readStrongBinder()); |
| 1308 | registerClient(client); |
| 1309 | return NO_ERROR; |
| 1310 | } break; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1311 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1312 | case SET_AUDIO_PORT_CALLBACK_ENABLED: { |
| 1313 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1314 | setAudioPortCallbacksEnabled(data.readInt32() == 1); |
| 1315 | return NO_ERROR; |
| 1316 | } break; |
| 1317 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1318 | case ACQUIRE_SOUNDTRIGGER_SESSION: { |
| 1319 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1320 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 1321 | data.readStrongBinder()); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 1322 | audio_session_t session = AUDIO_SESSION_NONE; |
| 1323 | audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE; |
| 1324 | audio_devices_t device = AUDIO_DEVICE_NONE; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1325 | status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device); |
| 1326 | reply->writeInt32(status); |
| 1327 | if (status == NO_ERROR) { |
| 1328 | reply->writeInt32(session); |
| 1329 | reply->writeInt32(ioHandle); |
| 1330 | reply->writeInt32(device); |
| 1331 | } |
| 1332 | return NO_ERROR; |
| 1333 | } break; |
| 1334 | |
| 1335 | case RELEASE_SOUNDTRIGGER_SESSION: { |
| 1336 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1337 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 1338 | data.readStrongBinder()); |
| 1339 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 1340 | status_t status = releaseSoundTriggerSession(session); |
| 1341 | reply->writeInt32(status); |
| 1342 | return NO_ERROR; |
| 1343 | } break; |
| 1344 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1345 | case GET_PHONE_STATE: { |
| 1346 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1347 | reply->writeInt32((int32_t)getPhoneState()); |
| 1348 | return NO_ERROR; |
| 1349 | } break; |
| 1350 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1351 | case REGISTER_POLICY_MIXES: { |
| 1352 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1353 | bool registration = data.readInt32() == 1; |
| 1354 | Vector<AudioMix> mixes; |
| 1355 | size_t size = (size_t)data.readInt32(); |
| 1356 | if (size > MAX_MIXES_PER_POLICY) { |
| 1357 | size = MAX_MIXES_PER_POLICY; |
| 1358 | } |
| 1359 | for (size_t i = 0; i < size; i++) { |
| 1360 | AudioMix mix; |
| 1361 | if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 1362 | mixes.add(mix); |
| 1363 | } |
| 1364 | } |
| 1365 | status_t status = registerPolicyMixes(mixes, registration); |
| 1366 | reply->writeInt32(status); |
| 1367 | return NO_ERROR; |
| 1368 | } break; |
| 1369 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1370 | case START_AUDIO_SOURCE: { |
| 1371 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1372 | struct audio_port_config source; |
| 1373 | data.read(&source, sizeof(struct audio_port_config)); |
| 1374 | audio_attributes_t attributes; |
| 1375 | data.read(&attributes, sizeof(audio_attributes_t)); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 1376 | audio_io_handle_t handle = {}; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1377 | status_t status = startAudioSource(&source, &attributes, &handle); |
| 1378 | reply->writeInt32(status); |
| 1379 | reply->writeInt32(handle); |
| 1380 | return NO_ERROR; |
| 1381 | } break; |
| 1382 | |
| 1383 | case STOP_AUDIO_SOURCE: { |
| 1384 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1385 | audio_io_handle_t handle = (audio_io_handle_t)data.readInt32(); |
| 1386 | status_t status = stopAudioSource(handle); |
| 1387 | reply->writeInt32(status); |
| 1388 | return NO_ERROR; |
| 1389 | } break; |
| 1390 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1391 | case SET_MASTER_MONO: { |
| 1392 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1393 | bool mono = static_cast<bool>(data.readInt32()); |
| 1394 | status_t status = setMasterMono(mono); |
| 1395 | reply->writeInt32(status); |
| 1396 | return NO_ERROR; |
| 1397 | } break; |
| 1398 | |
| 1399 | case GET_MASTER_MONO: { |
| 1400 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1401 | bool mono; |
| 1402 | status_t status = getMasterMono(&mono); |
| 1403 | reply->writeInt32(status); |
| 1404 | if (status == NO_ERROR) { |
| 1405 | reply->writeInt32(static_cast<int32_t>(mono)); |
| 1406 | } |
| 1407 | return NO_ERROR; |
| 1408 | } break; |
| 1409 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1410 | default: |
| 1411 | return BBinder::onTransact(code, data, reply, flags); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // ---------------------------------------------------------------------------- |
| 1416 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1417 | } // namespace android |