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