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