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