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