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