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