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