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: |
jiabin | 140a34f | 2019-12-23 11:17:25 -0800 | [diff] [blame] | 1521 | case GET_DEVICES_FOR_ATTRIBUTES: |
| 1522 | case SET_ALLOWED_CAPTURE_POLICY: { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1523 | if (!isServiceUid(IPCThreadState::self()->getCallingUid())) { |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1524 | ALOGW("%s: transaction %d received from PID %d unauthorized UID %d", |
| 1525 | __func__, code, IPCThreadState::self()->getCallingPid(), |
| 1526 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1527 | reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION)); |
| 1528 | return OK; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1529 | } |
Eric Laurent | 96c7eed | 2018-03-26 17:57:01 -0700 | [diff] [blame] | 1530 | } break; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1531 | default: |
| 1532 | break; |
| 1533 | } |
| 1534 | |
Eric Laurent | 39b09b5 | 2018-06-29 12:24:40 -0700 | [diff] [blame] | 1535 | std::string tag("IAudioPolicyService command " + std::to_string(code)); |
| 1536 | TimeCheck check(tag.c_str()); |
Eric Laurent | 3528c93 | 2018-02-23 17:17:22 -0800 | [diff] [blame] | 1537 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1538 | switch (code) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1539 | case SET_DEVICE_CONNECTION_STATE: { |
| 1540 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1541 | audio_devices_t device = |
| 1542 | static_cast <audio_devices_t>(data.readInt32()); |
| 1543 | audio_policy_dev_state_t state = |
| 1544 | static_cast <audio_policy_dev_state_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1545 | const char *device_address = data.readCString(); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1546 | const char *device_name = data.readCString(); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1547 | audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32()); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1548 | if (device_address == nullptr || device_name == nullptr) { |
| 1549 | ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device); |
| 1550 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 1551 | } else { |
| 1552 | reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device, |
| 1553 | state, |
| 1554 | device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1555 | device_name, |
| 1556 | codecFormat))); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1557 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1558 | return NO_ERROR; |
| 1559 | } break; |
| 1560 | |
| 1561 | case GET_DEVICE_CONNECTION_STATE: { |
| 1562 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1563 | audio_devices_t device = |
| 1564 | static_cast<audio_devices_t> (data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1565 | const char *device_address = data.readCString(); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1566 | if (device_address == nullptr) { |
| 1567 | ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device); |
| 1568 | reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
| 1569 | } else { |
| 1570 | reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device, |
| 1571 | device_address))); |
| 1572 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1573 | return NO_ERROR; |
| 1574 | } break; |
| 1575 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 1576 | case HANDLE_DEVICE_CONFIG_CHANGE: { |
| 1577 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1578 | audio_devices_t device = |
| 1579 | static_cast <audio_devices_t>(data.readInt32()); |
| 1580 | const char *device_address = data.readCString(); |
| 1581 | const char *device_name = data.readCString(); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1582 | audio_format_t codecFormat = |
| 1583 | static_cast <audio_format_t>(data.readInt32()); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1584 | if (device_address == nullptr || device_name == nullptr) { |
| 1585 | ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device); |
| 1586 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 1587 | } else { |
| 1588 | reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device, |
| 1589 | device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1590 | device_name, |
| 1591 | codecFormat))); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1592 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 1593 | return NO_ERROR; |
| 1594 | } break; |
| 1595 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1596 | case SET_PHONE_STATE: { |
| 1597 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1598 | reply->writeInt32(static_cast <uint32_t>(setPhoneState( |
| 1599 | (audio_mode_t) data.readInt32()))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1600 | return NO_ERROR; |
| 1601 | } break; |
| 1602 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1603 | case SET_FORCE_USE: { |
| 1604 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1605 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 1606 | data.readInt32()); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1607 | audio_policy_forced_cfg_t config = |
| 1608 | static_cast <audio_policy_forced_cfg_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1609 | reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config))); |
| 1610 | return NO_ERROR; |
| 1611 | } break; |
| 1612 | |
| 1613 | case GET_FORCE_USE: { |
| 1614 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1615 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 1616 | data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1617 | reply->writeInt32(static_cast <uint32_t>(getForceUse(usage))); |
| 1618 | return NO_ERROR; |
| 1619 | } break; |
| 1620 | |
| 1621 | case GET_OUTPUT: { |
| 1622 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1623 | audio_stream_type_t stream = |
| 1624 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 1625 | audio_io_handle_t output = getOutput(stream); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1626 | reply->writeInt32(static_cast <int>(output)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1627 | return NO_ERROR; |
| 1628 | } break; |
| 1629 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1630 | case GET_OUTPUT_FOR_ATTR: { |
| 1631 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1632 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 1633 | status_t status = data.read(&attr, sizeof(audio_attributes_t)); |
| 1634 | if (status != NO_ERROR) { |
| 1635 | return status; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1636 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1637 | sanetizeAudioAttributes(&attr); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1638 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 1639 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 1640 | bool hasStream = data.readInt32() != 0; |
| 1641 | if (hasStream) { |
| 1642 | stream = (audio_stream_type_t)data.readInt32(); |
| 1643 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 1644 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 1645 | uid_t uid = (uid_t)data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1646 | audio_config_t config; |
| 1647 | memset(&config, 0, sizeof(audio_config_t)); |
| 1648 | data.read(&config, sizeof(audio_config_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1649 | audio_output_flags_t flags = |
| 1650 | static_cast <audio_output_flags_t>(data.readInt32()); |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 1651 | audio_port_handle_t selectedDeviceId = data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1652 | audio_port_handle_t portId = (audio_port_handle_t)data.readInt32(); |
Robert Shih | a946d84 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 1653 | audio_io_handle_t output = 0; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1654 | std::vector<audio_io_handle_t> secondaryOutputs; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1655 | status = getOutputForAttr(&attr, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 1656 | &output, session, &stream, pid, uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1657 | &config, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1658 | flags, &selectedDeviceId, &portId, &secondaryOutputs); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1659 | reply->writeInt32(status); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1660 | status = reply->write(&attr, sizeof(audio_attributes_t)); |
| 1661 | if (status != NO_ERROR) { |
| 1662 | return status; |
| 1663 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1664 | reply->writeInt32(output); |
| 1665 | reply->writeInt32(stream); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1666 | reply->writeInt32(selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1667 | reply->writeInt32(portId); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1668 | reply->writeInt32(secondaryOutputs.size()); |
| 1669 | return reply->write(secondaryOutputs.data(), |
| 1670 | secondaryOutputs.size() * sizeof(audio_io_handle_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1671 | } break; |
| 1672 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1673 | case START_OUTPUT: { |
| 1674 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1675 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1676 | reply->writeInt32(static_cast <uint32_t>(startOutput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1677 | return NO_ERROR; |
| 1678 | } break; |
| 1679 | |
| 1680 | case STOP_OUTPUT: { |
| 1681 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1682 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1683 | reply->writeInt32(static_cast <uint32_t>(stopOutput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1684 | return NO_ERROR; |
| 1685 | } break; |
| 1686 | |
| 1687 | case RELEASE_OUTPUT: { |
| 1688 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1689 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1690 | releaseOutput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1691 | return NO_ERROR; |
| 1692 | } break; |
| 1693 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1694 | case GET_INPUT_FOR_ATTR: { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1695 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1696 | audio_attributes_t attr = {}; |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1697 | data.read(&attr, sizeof(audio_attributes_t)); |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 1698 | sanetizeAudioAttributes(&attr); |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 1699 | audio_io_handle_t input = (audio_io_handle_t)data.readInt32(); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 1700 | audio_unique_id_t riid = (audio_unique_id_t)data.readInt32(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1701 | audio_session_t session = (audio_session_t)data.readInt32(); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 1702 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 1703 | uid_t uid = (uid_t)data.readInt32(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1704 | const String16 opPackageName = data.readString16(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1705 | audio_config_base_t config; |
| 1706 | memset(&config, 0, sizeof(audio_config_base_t)); |
| 1707 | data.read(&config, sizeof(audio_config_base_t)); |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 1708 | audio_input_flags_t flags = (audio_input_flags_t) data.readInt32(); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 1709 | audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1710 | audio_port_handle_t portId = (audio_port_handle_t)data.readInt32(); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 1711 | status_t status = getInputForAttr(&attr, &input, riid, session, pid, uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1712 | opPackageName, &config, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1713 | flags, &selectedDeviceId, &portId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1714 | reply->writeInt32(status); |
| 1715 | if (status == NO_ERROR) { |
| 1716 | reply->writeInt32(input); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1717 | reply->writeInt32(selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1718 | reply->writeInt32(portId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1719 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1720 | return NO_ERROR; |
| 1721 | } break; |
| 1722 | |
| 1723 | case START_INPUT: { |
| 1724 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1725 | 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] | 1726 | status_t status = startInput(portId); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1727 | reply->writeInt32(static_cast <uint32_t>(status)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1728 | return NO_ERROR; |
| 1729 | } break; |
| 1730 | |
| 1731 | case STOP_INPUT: { |
| 1732 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1733 | audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1734 | reply->writeInt32(static_cast <uint32_t>(stopInput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1735 | return NO_ERROR; |
| 1736 | } break; |
| 1737 | |
| 1738 | case RELEASE_INPUT: { |
| 1739 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1740 | audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1741 | releaseInput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1742 | return NO_ERROR; |
| 1743 | } break; |
| 1744 | |
| 1745 | case INIT_STREAM_VOLUME: { |
| 1746 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1747 | audio_stream_type_t stream = |
| 1748 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1749 | int indexMin = data.readInt32(); |
| 1750 | int indexMax = data.readInt32(); |
| 1751 | reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax))); |
| 1752 | return NO_ERROR; |
| 1753 | } break; |
| 1754 | |
| 1755 | case SET_STREAM_VOLUME: { |
| 1756 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1757 | audio_stream_type_t stream = |
| 1758 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1759 | int index = data.readInt32(); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1760 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1761 | reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, |
| 1762 | index, |
| 1763 | device))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1764 | return NO_ERROR; |
| 1765 | } break; |
| 1766 | |
| 1767 | case GET_STREAM_VOLUME: { |
| 1768 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1769 | audio_stream_type_t stream = |
| 1770 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1771 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
Robert Shih | 8923543 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 1772 | int index = 0; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1773 | status_t status = getStreamVolumeIndex(stream, &index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1774 | reply->writeInt32(index); |
| 1775 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1776 | return NO_ERROR; |
| 1777 | } break; |
| 1778 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1779 | case GET_STRATEGY_FOR_STREAM: { |
| 1780 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1781 | audio_stream_type_t stream = |
| 1782 | static_cast <audio_stream_type_t>(data.readInt32()); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1783 | reply->writeUint32(getStrategyForStream(stream)); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1784 | return NO_ERROR; |
| 1785 | } break; |
| 1786 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1787 | case SET_VOLUME_ATTRIBUTES: { |
| 1788 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1789 | audio_attributes_t attributes = {}; |
| 1790 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1791 | if (status != NO_ERROR) { |
| 1792 | return status; |
| 1793 | } |
| 1794 | int index = data.readInt32(); |
| 1795 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1796 | |
| 1797 | reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes, |
| 1798 | index, device))); |
| 1799 | return NO_ERROR; |
| 1800 | } break; |
| 1801 | |
| 1802 | case GET_VOLUME_ATTRIBUTES: { |
| 1803 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1804 | audio_attributes_t attributes = {}; |
| 1805 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1806 | if (status != NO_ERROR) { |
| 1807 | return status; |
| 1808 | } |
| 1809 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1810 | |
| 1811 | int index = 0; |
| 1812 | status = getVolumeIndexForAttributes(attributes, index, device); |
| 1813 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1814 | if (status == NO_ERROR) { |
| 1815 | reply->writeInt32(index); |
| 1816 | } |
| 1817 | return NO_ERROR; |
| 1818 | } break; |
| 1819 | |
| 1820 | case GET_MIN_VOLUME_FOR_ATTRIBUTES: { |
| 1821 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1822 | audio_attributes_t attributes = {}; |
| 1823 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1824 | if (status != NO_ERROR) { |
| 1825 | return status; |
| 1826 | } |
| 1827 | |
| 1828 | int index = 0; |
| 1829 | status = getMinVolumeIndexForAttributes(attributes, index); |
| 1830 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1831 | if (status == NO_ERROR) { |
| 1832 | reply->writeInt32(index); |
| 1833 | } |
| 1834 | return NO_ERROR; |
| 1835 | } break; |
| 1836 | |
| 1837 | case GET_MAX_VOLUME_FOR_ATTRIBUTES: { |
| 1838 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1839 | audio_attributes_t attributes = {}; |
| 1840 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1841 | if (status != NO_ERROR) { |
| 1842 | return status; |
| 1843 | } |
| 1844 | |
| 1845 | int index = 0; |
| 1846 | status = getMaxVolumeIndexForAttributes(attributes, index); |
| 1847 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1848 | if (status == NO_ERROR) { |
| 1849 | reply->writeInt32(index); |
| 1850 | } |
| 1851 | return NO_ERROR; |
| 1852 | } break; |
| 1853 | |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1854 | case GET_DEVICES_FOR_STREAM: { |
| 1855 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1856 | audio_stream_type_t stream = |
| 1857 | static_cast <audio_stream_type_t>(data.readInt32()); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1858 | reply->writeInt32(static_cast <int>(getDevicesForStream(stream))); |
| 1859 | return NO_ERROR; |
| 1860 | } break; |
| 1861 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1862 | case GET_OUTPUT_FOR_EFFECT: { |
| 1863 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1864 | effect_descriptor_t desc = {}; |
| 1865 | if (data.read(&desc, sizeof(desc)) != NO_ERROR) { |
| 1866 | android_errorWriteLog(0x534e4554, "73126106"); |
| 1867 | } |
| 1868 | (void)sanitizeEffectDescriptor(&desc); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1869 | audio_io_handle_t output = getOutputForEffect(&desc); |
| 1870 | reply->writeInt32(static_cast <int>(output)); |
| 1871 | return NO_ERROR; |
| 1872 | } break; |
| 1873 | |
| 1874 | case REGISTER_EFFECT: { |
| 1875 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1876 | effect_descriptor_t desc = {}; |
| 1877 | if (data.read(&desc, sizeof(desc)) != NO_ERROR) { |
| 1878 | android_errorWriteLog(0x534e4554, "73126106"); |
| 1879 | } |
| 1880 | (void)sanitizeEffectDescriptor(&desc); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1881 | audio_io_handle_t io = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1882 | uint32_t strategy = data.readInt32(); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1883 | audio_session_t session = (audio_session_t) data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1884 | int id = data.readInt32(); |
| 1885 | reply->writeInt32(static_cast <int32_t>(registerEffect(&desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1886 | io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1887 | strategy, |
| 1888 | session, |
| 1889 | id))); |
| 1890 | return NO_ERROR; |
| 1891 | } break; |
| 1892 | |
| 1893 | case UNREGISTER_EFFECT: { |
| 1894 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1895 | int id = data.readInt32(); |
| 1896 | reply->writeInt32(static_cast <int32_t>(unregisterEffect(id))); |
| 1897 | return NO_ERROR; |
| 1898 | } break; |
| 1899 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1900 | case SET_EFFECT_ENABLED: { |
| 1901 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1902 | int id = data.readInt32(); |
| 1903 | bool enabled = static_cast <bool>(data.readInt32()); |
| 1904 | reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled))); |
| 1905 | return NO_ERROR; |
| 1906 | } break; |
| 1907 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1908 | case MOVE_EFFECTS_TO_IO: { |
| 1909 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1910 | std::vector<int> ids; |
| 1911 | int32_t size; |
| 1912 | status_t status = data.readInt32(&size); |
| 1913 | if (status != NO_ERROR) { |
| 1914 | return status; |
| 1915 | } |
| 1916 | if (size > MAX_ITEMS_PER_LIST) { |
| 1917 | return BAD_VALUE; |
| 1918 | } |
| 1919 | for (int32_t i = 0; i < size; i++) { |
| 1920 | int id; |
| 1921 | status = data.readInt32(&id); |
| 1922 | if (status != NO_ERROR) { |
| 1923 | return status; |
| 1924 | } |
| 1925 | ids.push_back(id); |
| 1926 | } |
| 1927 | |
| 1928 | audio_io_handle_t io = data.readInt32(); |
| 1929 | reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io))); |
| 1930 | return NO_ERROR; |
| 1931 | } break; |
| 1932 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1933 | case IS_STREAM_ACTIVE: { |
| 1934 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1935 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1936 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1937 | reply->writeInt32( isStreamActive(stream, inPastMs) ); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1938 | return NO_ERROR; |
| 1939 | } break; |
| 1940 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1941 | case IS_STREAM_ACTIVE_REMOTELY: { |
| 1942 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1943 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
| 1944 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1945 | reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) ); |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1946 | return NO_ERROR; |
| 1947 | } break; |
| 1948 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1949 | case IS_SOURCE_ACTIVE: { |
| 1950 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1951 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 1952 | reply->writeInt32( isSourceActive(source)); |
| 1953 | return NO_ERROR; |
| 1954 | } |
| 1955 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1956 | case QUERY_DEFAULT_PRE_PROCESSING: { |
| 1957 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1958 | audio_session_t audioSession = (audio_session_t) data.readInt32(); |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1959 | uint32_t count = data.readInt32(); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1960 | if (count > AudioEffect::kMaxPreProcessing) { |
| 1961 | count = AudioEffect::kMaxPreProcessing; |
| 1962 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1963 | uint32_t retCount = count; |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1964 | effect_descriptor_t *descriptors = new effect_descriptor_t[count]{}; |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1965 | status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount); |
| 1966 | reply->writeInt32(status); |
| 1967 | if (status != NO_ERROR && status != NO_MEMORY) { |
| 1968 | retCount = 0; |
| 1969 | } |
| 1970 | reply->writeInt32(retCount); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1971 | if (retCount != 0) { |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1972 | if (retCount < count) { |
| 1973 | count = retCount; |
| 1974 | } |
| 1975 | reply->write(descriptors, sizeof(effect_descriptor_t) * count); |
| 1976 | } |
| 1977 | delete[] descriptors; |
| 1978 | return status; |
| 1979 | } |
| 1980 | |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 1981 | case IS_OFFLOAD_SUPPORTED: { |
| 1982 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1983 | audio_offload_info_t info = {}; |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 1984 | data.read(&info, sizeof(audio_offload_info_t)); |
| 1985 | bool isSupported = isOffloadSupported(info); |
| 1986 | reply->writeInt32(isSupported); |
| 1987 | return NO_ERROR; |
| 1988 | } |
| 1989 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1990 | case IS_DIRECT_OUTPUT_SUPPORTED: { |
| 1991 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1992 | audio_config_base_t config = {}; |
| 1993 | audio_attributes_t attributes = {}; |
| 1994 | status_t status = data.read(&config, sizeof(audio_config_base_t)); |
| 1995 | if (status != NO_ERROR) return status; |
| 1996 | status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1997 | if (status != NO_ERROR) return status; |
| 1998 | reply->writeInt32(isDirectOutputSupported(config, attributes)); |
| 1999 | return NO_ERROR; |
| 2000 | } |
| 2001 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2002 | case LIST_AUDIO_PORTS: { |
| 2003 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2004 | audio_port_role_t role = (audio_port_role_t)data.readInt32(); |
| 2005 | audio_port_type_t type = (audio_port_type_t)data.readInt32(); |
| 2006 | unsigned int numPortsReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2007 | if (numPortsReq > MAX_ITEMS_PER_LIST) { |
| 2008 | numPortsReq = MAX_ITEMS_PER_LIST; |
| 2009 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2010 | unsigned int numPorts = numPortsReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2011 | struct audio_port *ports = |
| 2012 | (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2013 | if (ports == NULL) { |
| 2014 | reply->writeInt32(NO_MEMORY); |
| 2015 | reply->writeInt32(0); |
| 2016 | return NO_ERROR; |
| 2017 | } |
| 2018 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2019 | status_t status = listAudioPorts(role, type, &numPorts, ports, &generation); |
| 2020 | reply->writeInt32(status); |
| 2021 | reply->writeInt32(numPorts); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2022 | |
| 2023 | if (status == NO_ERROR) { |
| 2024 | if (numPortsReq > numPorts) { |
| 2025 | numPortsReq = numPorts; |
| 2026 | } |
| 2027 | reply->write(ports, numPortsReq * sizeof(struct audio_port)); |
| 2028 | reply->writeInt32(generation); |
| 2029 | } |
| 2030 | free(ports); |
| 2031 | return NO_ERROR; |
| 2032 | } |
| 2033 | |
| 2034 | case GET_AUDIO_PORT: { |
| 2035 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 2036 | struct audio_port port = {}; |
| 2037 | if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) { |
| 2038 | ALOGE("b/23912202"); |
| 2039 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2040 | status_t status = getAudioPort(&port); |
| 2041 | reply->writeInt32(status); |
| 2042 | if (status == NO_ERROR) { |
| 2043 | reply->write(&port, sizeof(struct audio_port)); |
| 2044 | } |
| 2045 | return NO_ERROR; |
| 2046 | } |
| 2047 | |
| 2048 | case CREATE_AUDIO_PATCH: { |
| 2049 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2050 | struct audio_patch patch = {}; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2051 | data.read(&patch, sizeof(struct audio_patch)); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2052 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 2053 | if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) { |
| 2054 | ALOGE("b/23912202"); |
| 2055 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2056 | status_t status = createAudioPatch(&patch, &handle); |
| 2057 | reply->writeInt32(status); |
| 2058 | if (status == NO_ERROR) { |
| 2059 | reply->write(&handle, sizeof(audio_patch_handle_t)); |
| 2060 | } |
| 2061 | return NO_ERROR; |
| 2062 | } |
| 2063 | |
| 2064 | case RELEASE_AUDIO_PATCH: { |
| 2065 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2066 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2067 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 2068 | status_t status = releaseAudioPatch(handle); |
| 2069 | reply->writeInt32(status); |
| 2070 | return NO_ERROR; |
| 2071 | } |
| 2072 | |
| 2073 | case LIST_AUDIO_PATCHES: { |
| 2074 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2075 | unsigned int numPatchesReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2076 | if (numPatchesReq > MAX_ITEMS_PER_LIST) { |
| 2077 | numPatchesReq = MAX_ITEMS_PER_LIST; |
| 2078 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2079 | unsigned int numPatches = numPatchesReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2080 | struct audio_patch *patches = |
| 2081 | (struct audio_patch *)calloc(numPatchesReq, |
| 2082 | sizeof(struct audio_patch)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2083 | if (patches == NULL) { |
| 2084 | reply->writeInt32(NO_MEMORY); |
| 2085 | reply->writeInt32(0); |
| 2086 | return NO_ERROR; |
| 2087 | } |
| 2088 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2089 | status_t status = listAudioPatches(&numPatches, patches, &generation); |
| 2090 | reply->writeInt32(status); |
| 2091 | reply->writeInt32(numPatches); |
| 2092 | if (status == NO_ERROR) { |
| 2093 | if (numPatchesReq > numPatches) { |
| 2094 | numPatchesReq = numPatches; |
| 2095 | } |
| 2096 | reply->write(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 2097 | reply->writeInt32(generation); |
| 2098 | } |
| 2099 | free(patches); |
| 2100 | return NO_ERROR; |
| 2101 | } |
| 2102 | |
| 2103 | case SET_AUDIO_PORT_CONFIG: { |
| 2104 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2105 | struct audio_port_config config = {}; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2106 | data.read(&config, sizeof(struct audio_port_config)); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2107 | (void)sanitizeAudioPortConfig(&config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2108 | status_t status = setAudioPortConfig(&config); |
| 2109 | reply->writeInt32(status); |
| 2110 | return NO_ERROR; |
| 2111 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2112 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2113 | case REGISTER_CLIENT: { |
| 2114 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2115 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 2116 | data.readStrongBinder()); |
| 2117 | registerClient(client); |
| 2118 | return NO_ERROR; |
| 2119 | } break; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2120 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2121 | case SET_AUDIO_PORT_CALLBACK_ENABLED: { |
| 2122 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2123 | setAudioPortCallbacksEnabled(data.readInt32() == 1); |
| 2124 | return NO_ERROR; |
| 2125 | } break; |
| 2126 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2127 | case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: { |
| 2128 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2129 | setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1); |
| 2130 | return NO_ERROR; |
| 2131 | } break; |
| 2132 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2133 | case ACQUIRE_SOUNDTRIGGER_SESSION: { |
| 2134 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2135 | audio_session_t session = AUDIO_SESSION_NONE; |
| 2136 | audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE; |
| 2137 | audio_devices_t device = AUDIO_DEVICE_NONE; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2138 | status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device); |
| 2139 | reply->writeInt32(status); |
| 2140 | if (status == NO_ERROR) { |
| 2141 | reply->writeInt32(session); |
| 2142 | reply->writeInt32(ioHandle); |
| 2143 | reply->writeInt32(device); |
| 2144 | } |
| 2145 | return NO_ERROR; |
| 2146 | } break; |
| 2147 | |
| 2148 | case RELEASE_SOUNDTRIGGER_SESSION: { |
| 2149 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2150 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 2151 | status_t status = releaseSoundTriggerSession(session); |
| 2152 | reply->writeInt32(status); |
| 2153 | return NO_ERROR; |
| 2154 | } break; |
| 2155 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 2156 | case GET_PHONE_STATE: { |
| 2157 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2158 | reply->writeInt32((int32_t)getPhoneState()); |
| 2159 | return NO_ERROR; |
| 2160 | } break; |
| 2161 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 2162 | case REGISTER_POLICY_MIXES: { |
| 2163 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2164 | bool registration = data.readInt32() == 1; |
| 2165 | Vector<AudioMix> mixes; |
| 2166 | size_t size = (size_t)data.readInt32(); |
| 2167 | if (size > MAX_MIXES_PER_POLICY) { |
| 2168 | size = MAX_MIXES_PER_POLICY; |
| 2169 | } |
| 2170 | for (size_t i = 0; i < size; i++) { |
| 2171 | AudioMix mix; |
| 2172 | if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2173 | mixes.add(mix); |
| 2174 | } |
| 2175 | } |
| 2176 | status_t status = registerPolicyMixes(mixes, registration); |
| 2177 | reply->writeInt32(status); |
| 2178 | return NO_ERROR; |
| 2179 | } break; |
| 2180 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2181 | case START_AUDIO_SOURCE: { |
| 2182 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2183 | struct audio_port_config source = {}; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2184 | data.read(&source, sizeof(struct audio_port_config)); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2185 | (void)sanitizeAudioPortConfig(&source); |
| 2186 | audio_attributes_t attributes = {}; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2187 | data.read(&attributes, sizeof(audio_attributes_t)); |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 2188 | sanetizeAudioAttributes(&attributes); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2189 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 2190 | status_t status = startAudioSource(&source, &attributes, &portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2191 | reply->writeInt32(status); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2192 | reply->writeInt32(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2193 | return NO_ERROR; |
| 2194 | } break; |
| 2195 | |
| 2196 | case STOP_AUDIO_SOURCE: { |
| 2197 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2198 | audio_port_handle_t portId = (audio_port_handle_t) data.readInt32(); |
| 2199 | status_t status = stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2200 | reply->writeInt32(status); |
| 2201 | return NO_ERROR; |
| 2202 | } break; |
| 2203 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 2204 | case SET_MASTER_MONO: { |
| 2205 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2206 | bool mono = static_cast<bool>(data.readInt32()); |
| 2207 | status_t status = setMasterMono(mono); |
| 2208 | reply->writeInt32(status); |
| 2209 | return NO_ERROR; |
| 2210 | } break; |
| 2211 | |
| 2212 | case GET_MASTER_MONO: { |
| 2213 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2214 | bool mono; |
| 2215 | status_t status = getMasterMono(&mono); |
| 2216 | reply->writeInt32(status); |
| 2217 | if (status == NO_ERROR) { |
| 2218 | reply->writeInt32(static_cast<int32_t>(mono)); |
| 2219 | } |
| 2220 | return NO_ERROR; |
| 2221 | } break; |
| 2222 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 2223 | case GET_STREAM_VOLUME_DB: { |
| 2224 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2225 | audio_stream_type_t stream = |
| 2226 | static_cast <audio_stream_type_t>(data.readInt32()); |
| 2227 | int index = static_cast <int>(data.readInt32()); |
| 2228 | audio_devices_t device = |
| 2229 | static_cast <audio_devices_t>(data.readUint32()); |
| 2230 | reply->writeFloat(getStreamVolumeDB(stream, index, device)); |
| 2231 | return NO_ERROR; |
| 2232 | } |
| 2233 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 2234 | case GET_SURROUND_FORMATS: { |
| 2235 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2236 | unsigned int numSurroundFormatsReq = data.readUint32(); |
| 2237 | if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) { |
| 2238 | numSurroundFormatsReq = MAX_ITEMS_PER_LIST; |
| 2239 | } |
| 2240 | bool reported = data.readBool(); |
| 2241 | unsigned int numSurroundFormats = numSurroundFormatsReq; |
| 2242 | audio_format_t *surroundFormats = (audio_format_t *)calloc( |
| 2243 | numSurroundFormats, sizeof(audio_format_t)); |
| 2244 | bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool)); |
| 2245 | if (numSurroundFormatsReq > 0 && |
| 2246 | (surroundFormats == NULL || surroundFormatsEnabled == NULL)) { |
| 2247 | free(surroundFormats); |
| 2248 | free(surroundFormatsEnabled); |
| 2249 | reply->writeInt32(NO_MEMORY); |
| 2250 | return NO_ERROR; |
| 2251 | } |
| 2252 | status_t status = getSurroundFormats( |
| 2253 | &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); |
| 2254 | reply->writeInt32(status); |
| 2255 | |
| 2256 | if (status == NO_ERROR) { |
| 2257 | reply->writeUint32(numSurroundFormats); |
| 2258 | if (numSurroundFormatsReq > numSurroundFormats) { |
| 2259 | numSurroundFormatsReq = numSurroundFormats; |
| 2260 | } |
| 2261 | reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t)); |
| 2262 | reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool)); |
| 2263 | } |
| 2264 | free(surroundFormats); |
| 2265 | free(surroundFormatsEnabled); |
| 2266 | return NO_ERROR; |
| 2267 | } |
| 2268 | |
| 2269 | case SET_SURROUND_FORMAT_ENABLED: { |
| 2270 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2271 | audio_format_t audioFormat = (audio_format_t) data.readInt32(); |
| 2272 | bool enabled = data.readBool(); |
| 2273 | status_t status = setSurroundFormatEnabled(audioFormat, enabled); |
| 2274 | reply->writeInt32(status); |
| 2275 | return NO_ERROR; |
| 2276 | } |
| 2277 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 2278 | case GET_OFFLOAD_FORMATS_A2DP: { |
| 2279 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2280 | std::vector<audio_format_t> encodingFormats; |
| 2281 | status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats); |
| 2282 | reply->writeInt32(status); |
| 2283 | if (status != NO_ERROR) { |
| 2284 | return NO_ERROR; |
| 2285 | } |
| 2286 | reply->writeUint32(static_cast<uint32_t>(encodingFormats.size())); |
| 2287 | for (size_t i = 0; i < encodingFormats.size(); i++) |
| 2288 | reply->writeInt32(static_cast<int32_t>(encodingFormats[i])); |
| 2289 | return NO_ERROR; |
| 2290 | } |
| 2291 | |
| 2292 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 2293 | case ADD_STREAM_DEFAULT_EFFECT: { |
| 2294 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2295 | effect_uuid_t type; |
| 2296 | status_t status = data.read(&type, sizeof(effect_uuid_t)); |
| 2297 | if (status != NO_ERROR) { |
| 2298 | return status; |
| 2299 | } |
| 2300 | String16 opPackageName; |
| 2301 | status = data.readString16(&opPackageName); |
| 2302 | if (status != NO_ERROR) { |
| 2303 | return status; |
| 2304 | } |
| 2305 | effect_uuid_t uuid; |
| 2306 | status = data.read(&uuid, sizeof(effect_uuid_t)); |
| 2307 | if (status != NO_ERROR) { |
| 2308 | return status; |
| 2309 | } |
| 2310 | int32_t priority = data.readInt32(); |
| 2311 | audio_usage_t usage = (audio_usage_t) data.readInt32(); |
| 2312 | audio_unique_id_t id = 0; |
| 2313 | reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type, |
| 2314 | opPackageName, |
| 2315 | &uuid, |
| 2316 | priority, |
| 2317 | usage, |
| 2318 | &id))); |
| 2319 | reply->writeInt32(id); |
| 2320 | return NO_ERROR; |
| 2321 | } |
| 2322 | |
| 2323 | case REMOVE_STREAM_DEFAULT_EFFECT: { |
| 2324 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2325 | audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32()); |
| 2326 | reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id))); |
| 2327 | return NO_ERROR; |
| 2328 | } |
| 2329 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 2330 | case ADD_SOURCE_DEFAULT_EFFECT: { |
| 2331 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2332 | effect_uuid_t type; |
| 2333 | status_t status = data.read(&type, sizeof(effect_uuid_t)); |
| 2334 | if (status != NO_ERROR) { |
| 2335 | return status; |
| 2336 | } |
| 2337 | String16 opPackageName; |
| 2338 | status = data.readString16(&opPackageName); |
| 2339 | if (status != NO_ERROR) { |
| 2340 | return status; |
| 2341 | } |
| 2342 | effect_uuid_t uuid; |
| 2343 | status = data.read(&uuid, sizeof(effect_uuid_t)); |
| 2344 | if (status != NO_ERROR) { |
| 2345 | return status; |
| 2346 | } |
| 2347 | int32_t priority = data.readInt32(); |
| 2348 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 2349 | audio_unique_id_t id = 0; |
| 2350 | reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type, |
| 2351 | opPackageName, |
| 2352 | &uuid, |
| 2353 | priority, |
| 2354 | source, |
| 2355 | &id))); |
| 2356 | reply->writeInt32(id); |
| 2357 | return NO_ERROR; |
| 2358 | } |
| 2359 | |
| 2360 | case REMOVE_SOURCE_DEFAULT_EFFECT: { |
| 2361 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2362 | audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32()); |
| 2363 | reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id))); |
| 2364 | return NO_ERROR; |
| 2365 | } |
| 2366 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2367 | case SET_ASSISTANT_UID: { |
| 2368 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2369 | int32_t uid; |
| 2370 | status_t status = data.readInt32(&uid); |
| 2371 | if (status != NO_ERROR) { |
| 2372 | return status; |
| 2373 | } |
| 2374 | status = setAssistantUid(uid); |
| 2375 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2376 | return NO_ERROR; |
| 2377 | } |
| 2378 | |
| 2379 | case SET_A11Y_SERVICES_UIDS: { |
| 2380 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2381 | std::vector<uid_t> uids; |
| 2382 | int32_t size; |
| 2383 | status_t status = data.readInt32(&size); |
| 2384 | if (status != NO_ERROR) { |
| 2385 | return status; |
| 2386 | } |
| 2387 | if (size > MAX_ITEMS_PER_LIST) { |
| 2388 | size = MAX_ITEMS_PER_LIST; |
| 2389 | } |
| 2390 | for (int32_t i = 0; i < size; i++) { |
| 2391 | int32_t uid; |
| 2392 | status = data.readInt32(&uid); |
| 2393 | if (status != NO_ERROR) { |
| 2394 | return status; |
| 2395 | } |
| 2396 | uids.push_back(uid); |
| 2397 | } |
| 2398 | status = setA11yServicesUids(uids); |
| 2399 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2400 | return NO_ERROR; |
| 2401 | } |
| 2402 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2403 | case IS_HAPTIC_PLAYBACK_SUPPORTED: { |
| 2404 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2405 | bool isSupported = isHapticPlaybackSupported(); |
| 2406 | reply->writeBool(isSupported); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 2407 | return NO_ERROR; |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 2408 | } |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 2409 | case SET_UID_DEVICE_AFFINITY: { |
| 2410 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2411 | const uid_t uid = (uid_t) data.readInt32(); |
| 2412 | Vector<AudioDeviceTypeAddr> devices; |
| 2413 | size_t size = (size_t)data.readInt32(); |
| 2414 | for (size_t i = 0; i < size; i++) { |
| 2415 | AudioDeviceTypeAddr device; |
| 2416 | if (device.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2417 | devices.add(device); |
| 2418 | } |
| 2419 | } |
| 2420 | status_t status = setUidDeviceAffinities(uid, devices); |
| 2421 | reply->writeInt32(status); |
| 2422 | return NO_ERROR; |
| 2423 | } |
| 2424 | |
| 2425 | case REMOVE_UID_DEVICE_AFFINITY: { |
| 2426 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2427 | const uid_t uid = (uid_t) data.readInt32(); |
| 2428 | status_t status = removeUidDeviceAffinities(uid); |
| 2429 | reply->writeInt32(status); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2430 | return NO_ERROR; |
| 2431 | } |
| 2432 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 2433 | case SET_USERID_DEVICE_AFFINITY: { |
| 2434 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2435 | const int userId = (int) data.readInt32(); |
| 2436 | Vector<AudioDeviceTypeAddr> devices; |
| 2437 | size_t size = (size_t)data.readInt32(); |
| 2438 | for (size_t i = 0; i < size; i++) { |
| 2439 | AudioDeviceTypeAddr device; |
| 2440 | if (device.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2441 | devices.add(device); |
| 2442 | } |
| 2443 | } |
| 2444 | status_t status = setUserIdDeviceAffinities(userId, devices); |
| 2445 | reply->writeInt32(status); |
| 2446 | return NO_ERROR; |
| 2447 | } |
| 2448 | |
| 2449 | case REMOVE_USERID_DEVICE_AFFINITY: { |
| 2450 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2451 | const int userId = (int) data.readInt32(); |
| 2452 | status_t status = removeUserIdDeviceAffinities(userId); |
| 2453 | reply->writeInt32(status); |
| 2454 | return NO_ERROR; |
| 2455 | } |
| 2456 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2457 | case LIST_AUDIO_PRODUCT_STRATEGIES: { |
| 2458 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2459 | AudioProductStrategyVector strategies; |
| 2460 | status_t status = listAudioProductStrategies(strategies); |
| 2461 | reply->writeInt32(status); |
| 2462 | if (status != NO_ERROR) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2463 | return NO_ERROR; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2464 | } |
| 2465 | size_t size = strategies.size(); |
| 2466 | size_t sizePosition = reply->dataPosition(); |
| 2467 | reply->writeInt32(size); |
| 2468 | size_t finalSize = size; |
| 2469 | for (size_t i = 0; i < size; i++) { |
| 2470 | size_t position = reply->dataPosition(); |
| 2471 | if (strategies[i].writeToParcel(reply) != NO_ERROR) { |
| 2472 | reply->setDataPosition(position); |
| 2473 | finalSize--; |
| 2474 | } |
| 2475 | } |
| 2476 | if (size != finalSize) { |
| 2477 | size_t position = reply->dataPosition(); |
| 2478 | reply->setDataPosition(sizePosition); |
| 2479 | reply->writeInt32(finalSize); |
| 2480 | reply->setDataPosition(position); |
| 2481 | } |
| 2482 | return NO_ERROR; |
| 2483 | } |
| 2484 | |
| 2485 | case GET_STRATEGY_FOR_ATTRIBUTES: { |
| 2486 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2487 | AudioAttributes attributes; |
| 2488 | status_t status = attributes.readFromParcel(&data); |
| 2489 | if (status != NO_ERROR) { |
| 2490 | return status; |
| 2491 | } |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2492 | product_strategy_t strategy; |
| 2493 | status = getProductStrategyFromAudioAttributes(attributes, strategy); |
| 2494 | reply->writeInt32(status); |
| 2495 | if (status != NO_ERROR) { |
| 2496 | return NO_ERROR; |
| 2497 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2498 | reply->writeUint32(static_cast<int>(strategy)); |
| 2499 | return NO_ERROR; |
| 2500 | } |
| 2501 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2502 | case LIST_AUDIO_VOLUME_GROUPS: { |
| 2503 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2504 | AudioVolumeGroupVector groups; |
| 2505 | status_t status = listAudioVolumeGroups(groups); |
| 2506 | reply->writeInt32(status); |
| 2507 | if (status != NO_ERROR) { |
| 2508 | return NO_ERROR; |
| 2509 | } |
| 2510 | size_t size = groups.size(); |
| 2511 | size_t sizePosition = reply->dataPosition(); |
| 2512 | reply->writeInt32(size); |
| 2513 | size_t finalSize = size; |
| 2514 | for (size_t i = 0; i < size; i++) { |
| 2515 | size_t position = reply->dataPosition(); |
| 2516 | if (groups[i].writeToParcel(reply) != NO_ERROR) { |
| 2517 | reply->setDataPosition(position); |
| 2518 | finalSize--; |
| 2519 | } |
| 2520 | } |
| 2521 | if (size != finalSize) { |
| 2522 | size_t position = reply->dataPosition(); |
| 2523 | reply->setDataPosition(sizePosition); |
| 2524 | reply->writeInt32(finalSize); |
| 2525 | reply->setDataPosition(position); |
| 2526 | } |
| 2527 | return NO_ERROR; |
| 2528 | } |
| 2529 | |
| 2530 | case GET_VOLUME_GROUP_FOR_ATTRIBUTES: { |
| 2531 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2532 | AudioAttributes attributes; |
| 2533 | status_t status = attributes.readFromParcel(&data); |
| 2534 | if (status != NO_ERROR) { |
| 2535 | return status; |
| 2536 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2537 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2538 | volume_group_t group; |
| 2539 | status = getVolumeGroupFromAudioAttributes(attributes, group); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2540 | if (status != NO_ERROR) { |
| 2541 | return NO_ERROR; |
| 2542 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2543 | |
| 2544 | reply->writeInt32(status); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2545 | reply->writeUint32(static_cast<int>(group)); |
| 2546 | return NO_ERROR; |
| 2547 | } |
| 2548 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2549 | case SET_SUPPORTED_SYSTEM_USAGES: { |
| 2550 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2551 | std::vector<audio_usage_t> systemUsages; |
| 2552 | |
| 2553 | int32_t size; |
| 2554 | status_t status = data.readInt32(&size); |
| 2555 | if (status != NO_ERROR) { |
| 2556 | return status; |
| 2557 | } |
| 2558 | if (size > MAX_ITEMS_PER_LIST) { |
| 2559 | size = MAX_ITEMS_PER_LIST; |
| 2560 | } |
| 2561 | |
| 2562 | for (int32_t i = 0; i < size; i++) { |
| 2563 | int32_t systemUsageInt; |
| 2564 | status = data.readInt32(&systemUsageInt); |
| 2565 | if (status != NO_ERROR) { |
| 2566 | return status; |
| 2567 | } |
| 2568 | |
| 2569 | audio_usage_t systemUsage = static_cast<audio_usage_t>(systemUsageInt); |
| 2570 | systemUsages.push_back(systemUsage); |
| 2571 | } |
| 2572 | status = setSupportedSystemUsages(systemUsages); |
| 2573 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2574 | return NO_ERROR; |
| 2575 | } |
| 2576 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 2577 | case SET_ALLOWED_CAPTURE_POLICY: { |
| 2578 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2579 | uid_t uid = data.readInt32(); |
| 2580 | audio_flags_mask_t flags = data.readInt32(); |
| 2581 | status_t status = setAllowedCapturePolicy(uid, flags); |
| 2582 | reply->writeInt32(status); |
| 2583 | return NO_ERROR; |
| 2584 | } |
| 2585 | |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2586 | case SET_RTT_ENABLED: { |
| 2587 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2588 | bool enabled = static_cast<bool>(data.readInt32()); |
| 2589 | status_t status = setRttEnabled(enabled); |
| 2590 | reply->writeInt32(status); |
| 2591 | return NO_ERROR; |
| 2592 | } |
| 2593 | |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2594 | case IS_CALL_SCREEN_MODE_SUPPORTED: { |
| 2595 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2596 | bool isAvailable = isCallScreenModeSupported(); |
| 2597 | reply->writeBool(isAvailable); |
| 2598 | return NO_ERROR; |
| 2599 | } |
| 2600 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2601 | case SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2602 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2603 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2604 | AudioDeviceTypeAddr device; |
| 2605 | status_t status = device.readFromParcel((Parcel*)&data); |
| 2606 | if (status != NO_ERROR) { |
| 2607 | return status; |
| 2608 | } |
| 2609 | status = setPreferredDeviceForStrategy(strategy, device); |
| 2610 | reply->writeInt32(status); |
| 2611 | return NO_ERROR; |
| 2612 | } |
| 2613 | |
| 2614 | case REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2615 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2616 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2617 | status_t status = removePreferredDeviceForStrategy(strategy); |
| 2618 | reply->writeInt32(status); |
| 2619 | return NO_ERROR; |
| 2620 | } |
| 2621 | |
| 2622 | case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2623 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2624 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2625 | AudioDeviceTypeAddr device; |
| 2626 | status_t status = getPreferredDeviceForStrategy(strategy, device); |
| 2627 | status_t marshall_status = device.writeToParcel(reply); |
| 2628 | if (marshall_status != NO_ERROR) { |
| 2629 | return marshall_status; |
| 2630 | } |
| 2631 | reply->writeInt32(status); |
| 2632 | return NO_ERROR; |
| 2633 | } |
| 2634 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 2635 | case GET_DEVICES_FOR_ATTRIBUTES: { |
| 2636 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2637 | AudioAttributes attributes; |
| 2638 | status_t status = attributes.readFromParcel(&data); |
| 2639 | if (status != NO_ERROR) { |
| 2640 | return status; |
| 2641 | } |
| 2642 | AudioDeviceTypeAddrVector devices; |
| 2643 | status = getDevicesForAttributes(attributes.getAttributes(), &devices); |
| 2644 | // reply data formatted as: |
| 2645 | // - (int32) method call result from APM |
| 2646 | // - (int32) number of devices (n) if method call returned NO_ERROR |
| 2647 | // - n AudioDeviceTypeAddr if method call returned NO_ERROR |
| 2648 | reply->writeInt32(status); |
| 2649 | if (status != NO_ERROR) { |
| 2650 | return NO_ERROR; |
| 2651 | } |
| 2652 | status = reply->writeInt32(devices.size()); |
| 2653 | if (status != NO_ERROR) { |
| 2654 | return status; |
| 2655 | } |
| 2656 | for (const auto& device : devices) { |
| 2657 | status = device.writeToParcel(reply); |
| 2658 | if (status != NO_ERROR) { |
| 2659 | return status; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | return NO_ERROR; |
| 2664 | } |
| 2665 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2666 | default: |
| 2667 | return BBinder::onTransact(code, data, reply, flags); |
| 2668 | } |
| 2669 | } |
| 2670 | |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2671 | /** returns true if string overflow was prevented by zero termination */ |
| 2672 | template <size_t size> |
| 2673 | static bool preventStringOverflow(char (&s)[size]) { |
| 2674 | if (strnlen(s, size) < size) return false; |
| 2675 | s[size - 1] = '\0'; |
| 2676 | return true; |
| 2677 | } |
| 2678 | |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 2679 | void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr) |
| 2680 | { |
| 2681 | const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE; |
| 2682 | if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) { |
| 2683 | android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging |
| 2684 | } |
| 2685 | attr->tags[tagsMaxSize - 1] = '\0'; |
| 2686 | } |
| 2687 | |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2688 | /** returns BAD_VALUE if sanitization was required. */ |
| 2689 | status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc) |
| 2690 | { |
| 2691 | if (preventStringOverflow(desc->name) |
| 2692 | | /* always */ preventStringOverflow(desc->implementor)) { |
| 2693 | android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging |
| 2694 | return BAD_VALUE; |
| 2695 | } |
| 2696 | return NO_ERROR; |
| 2697 | } |
| 2698 | |
| 2699 | /** returns BAD_VALUE if sanitization was required. */ |
| 2700 | status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config) |
| 2701 | { |
| 2702 | if (config->type == AUDIO_PORT_TYPE_DEVICE && |
| 2703 | preventStringOverflow(config->ext.device.address)) { |
| 2704 | return BAD_VALUE; |
| 2705 | } |
| 2706 | return NO_ERROR; |
| 2707 | } |
| 2708 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2709 | // ---------------------------------------------------------------------------- |
| 2710 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 2711 | } // namespace android |