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