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