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