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