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