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