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