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