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