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