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