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