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