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