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