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