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