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