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