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