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