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