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