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