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