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