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