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> |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 29 | #include <mediautils/ServiceUtilities.h> |
Marco Nelissen | cf90b49 | 2019-09-26 11:20:54 -0700 | [diff] [blame] | 30 | #include <mediautils/TimeCheck.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, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 54 | SET_VOLUME_ATTRIBUTES, |
| 55 | GET_VOLUME_ATTRIBUTES, |
| 56 | GET_MIN_VOLUME_FOR_ATTRIBUTES, |
| 57 | GET_MAX_VOLUME_FOR_ATTRIBUTES, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 58 | GET_STRATEGY_FOR_STREAM, |
| 59 | GET_OUTPUT_FOR_EFFECT, |
| 60 | REGISTER_EFFECT, |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 61 | UNREGISTER_EFFECT, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 62 | IS_STREAM_ACTIVE, |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 63 | IS_SOURCE_ACTIVE, |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 64 | GET_DEVICES_FOR_STREAM, |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 65 | QUERY_DEFAULT_PRE_PROCESSING, |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 66 | SET_EFFECT_ENABLED, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 67 | IS_STREAM_ACTIVE_REMOTELY, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 68 | IS_OFFLOAD_SUPPORTED, |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 69 | IS_DIRECT_OUTPUT_SUPPORTED, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 70 | LIST_AUDIO_PORTS, |
| 71 | GET_AUDIO_PORT, |
| 72 | CREATE_AUDIO_PATCH, |
| 73 | RELEASE_AUDIO_PATCH, |
| 74 | LIST_AUDIO_PATCHES, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 75 | SET_AUDIO_PORT_CONFIG, |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 76 | REGISTER_CLIENT, |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 77 | GET_OUTPUT_FOR_ATTR, |
| 78 | ACQUIRE_SOUNDTRIGGER_SESSION, |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 79 | RELEASE_SOUNDTRIGGER_SESSION, |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 80 | GET_PHONE_STATE, |
| 81 | REGISTER_POLICY_MIXES, |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 82 | START_AUDIO_SOURCE, |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 83 | STOP_AUDIO_SOURCE, |
| 84 | SET_AUDIO_PORT_CALLBACK_ENABLED, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 85 | SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 86 | SET_MASTER_MONO, |
| 87 | GET_MASTER_MONO, |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 88 | GET_STREAM_VOLUME_DB, |
| 89 | GET_SURROUND_FORMATS, |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 90 | SET_SURROUND_FORMAT_ENABLED, |
| 91 | ADD_STREAM_DEFAULT_EFFECT, |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 92 | REMOVE_STREAM_DEFAULT_EFFECT, |
| 93 | ADD_SOURCE_DEFAULT_EFFECT, |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 94 | REMOVE_SOURCE_DEFAULT_EFFECT, |
| 95 | SET_ASSISTANT_UID, |
| 96 | SET_A11Y_SERVICES_UIDS, |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 97 | IS_HAPTIC_PLAYBACK_SUPPORTED, |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 98 | SET_UID_DEVICE_AFFINITY, |
| 99 | REMOVE_UID_DEVICE_AFFINITY, |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 100 | SET_USERID_DEVICE_AFFINITY, |
| 101 | REMOVE_USERID_DEVICE_AFFINITY, |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 102 | GET_OFFLOAD_FORMATS_A2DP, |
| 103 | LIST_AUDIO_PRODUCT_STRATEGIES, |
| 104 | GET_STRATEGY_FOR_ATTRIBUTES, |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 105 | LIST_AUDIO_VOLUME_GROUPS, |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 106 | GET_VOLUME_GROUP_FOR_ATTRIBUTES, |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 107 | SET_SUPPORTED_SYSTEM_USAGES, |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 108 | SET_ALLOWED_CAPTURE_POLICY, |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 109 | MOVE_EFFECTS_TO_IO, |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 110 | SET_RTT_ENABLED, |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 111 | IS_CALL_SCREEN_MODE_SUPPORTED, |
| 112 | SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
| 113 | REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
| 114 | GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 115 | GET_DEVICES_FOR_ATTRIBUTES, |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 116 | AUDIO_MODULES_UPDATED, // oneway |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame^] | 117 | SET_CURRENT_IME_UID, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 120 | #define MAX_ITEMS_PER_LIST 1024 |
| 121 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 122 | class BpAudioPolicyService : public BpInterface<IAudioPolicyService> |
| 123 | { |
| 124 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 125 | explicit BpAudioPolicyService(const sp<IBinder>& impl) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 126 | : BpInterface<IAudioPolicyService>(impl) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | virtual status_t setDeviceConnectionState( |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 131 | audio_devices_t device, |
| 132 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 133 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 134 | const char *device_name, |
| 135 | audio_format_t encodedFormat) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 136 | { |
| 137 | Parcel data, reply; |
| 138 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 139 | data.writeInt32(static_cast <uint32_t>(device)); |
| 140 | data.writeInt32(static_cast <uint32_t>(state)); |
| 141 | data.writeCString(device_address); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 142 | data.writeCString(device_name); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 143 | data.writeInt32(static_cast <uint32_t>(encodedFormat)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 144 | remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply); |
| 145 | return static_cast <status_t> (reply.readInt32()); |
| 146 | } |
| 147 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 148 | virtual audio_policy_dev_state_t getDeviceConnectionState( |
| 149 | audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 150 | const char *device_address) |
| 151 | { |
| 152 | Parcel data, reply; |
| 153 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 154 | data.writeInt32(static_cast <uint32_t>(device)); |
| 155 | data.writeCString(device_address); |
| 156 | remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 157 | return static_cast <audio_policy_dev_state_t>(reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 160 | virtual status_t handleDeviceConfigChange(audio_devices_t device, |
| 161 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 162 | const char *device_name, |
| 163 | audio_format_t encodedFormat) |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 164 | { |
| 165 | Parcel data, reply; |
| 166 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 167 | data.writeInt32(static_cast <uint32_t>(device)); |
| 168 | data.writeCString(device_address); |
| 169 | data.writeCString(device_name); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 170 | data.writeInt32(static_cast <uint32_t>(encodedFormat)); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 171 | remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply); |
| 172 | return static_cast <status_t> (reply.readInt32()); |
| 173 | } |
| 174 | |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 175 | virtual status_t setPhoneState(audio_mode_t state, uid_t uid) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 176 | { |
| 177 | Parcel data, reply; |
| 178 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 179 | data.writeInt32(state); |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 180 | data.writeInt32(uid); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 181 | remote()->transact(SET_PHONE_STATE, data, &reply); |
| 182 | return static_cast <status_t> (reply.readInt32()); |
| 183 | } |
| 184 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 185 | 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] | 186 | { |
| 187 | Parcel data, reply; |
| 188 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 189 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 190 | data.writeInt32(static_cast <uint32_t>(config)); |
| 191 | remote()->transact(SET_FORCE_USE, data, &reply); |
| 192 | return static_cast <status_t> (reply.readInt32()); |
| 193 | } |
| 194 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 195 | 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] | 196 | { |
| 197 | Parcel data, reply; |
| 198 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 199 | data.writeInt32(static_cast <uint32_t>(usage)); |
| 200 | remote()->transact(GET_FORCE_USE, data, &reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 201 | return static_cast <audio_policy_forced_cfg_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 204 | virtual audio_io_handle_t getOutput(audio_stream_type_t stream) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 205 | { |
| 206 | Parcel data, reply; |
| 207 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 208 | data.writeInt32(static_cast <uint32_t>(stream)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 209 | remote()->transact(GET_OUTPUT, data, &reply); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 210 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 213 | status_t getOutputForAttr(audio_attributes_t *attr, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 214 | audio_io_handle_t *output, |
| 215 | audio_session_t session, |
| 216 | audio_stream_type_t *stream, |
| 217 | pid_t pid, |
| 218 | uid_t uid, |
| 219 | const audio_config_t *config, |
| 220 | audio_output_flags_t flags, |
| 221 | audio_port_handle_t *selectedDeviceId, |
| 222 | audio_port_handle_t *portId, |
| 223 | std::vector<audio_io_handle_t> *secondaryOutputs) override |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 224 | { |
| 225 | Parcel data, reply; |
| 226 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 227 | if (attr == nullptr) { |
| 228 | ALOGE("%s NULL audio attributes", __func__); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 229 | return BAD_VALUE; |
| 230 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 231 | if (output == nullptr) { |
| 232 | ALOGE("%s NULL output - shouldn't happen", __func__); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 233 | return BAD_VALUE; |
| 234 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 235 | if (selectedDeviceId == nullptr) { |
| 236 | ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 237 | return BAD_VALUE; |
| 238 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 239 | if (portId == nullptr) { |
| 240 | ALOGE("%s NULL portId - shouldn't happen", __func__); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 241 | return BAD_VALUE; |
| 242 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 243 | if (secondaryOutputs == nullptr) { |
| 244 | ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__); |
| 245 | return BAD_VALUE; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 246 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 247 | data.write(attr, sizeof(audio_attributes_t)); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 248 | data.writeInt32(session); |
| 249 | if (stream == NULL) { |
| 250 | data.writeInt32(0); |
| 251 | } else { |
| 252 | data.writeInt32(1); |
| 253 | data.writeInt32(*stream); |
| 254 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 255 | data.writeInt32(pid); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 256 | data.writeInt32(uid); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 257 | data.write(config, sizeof(audio_config_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 258 | data.writeInt32(static_cast <uint32_t>(flags)); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 259 | data.writeInt32(*selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 260 | data.writeInt32(*portId); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 261 | status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply); |
| 262 | if (status != NO_ERROR) { |
| 263 | return status; |
| 264 | } |
| 265 | status = (status_t)reply.readInt32(); |
| 266 | if (status != NO_ERROR) { |
| 267 | return status; |
| 268 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 269 | status = (status_t)reply.read(&attr, sizeof(audio_attributes_t)); |
| 270 | if (status != NO_ERROR) { |
| 271 | return status; |
| 272 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 273 | *output = (audio_io_handle_t)reply.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 274 | audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32(); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 275 | if (stream != NULL) { |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 276 | *stream = lStream; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 277 | } |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 278 | *selectedDeviceId = (audio_port_handle_t)reply.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 279 | *portId = (audio_port_handle_t)reply.readInt32(); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 280 | secondaryOutputs->resize(reply.readInt32()); |
| 281 | return reply.read(secondaryOutputs->data(), |
| 282 | secondaryOutputs->size() * sizeof(audio_io_handle_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 285 | virtual status_t startOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 286 | { |
| 287 | Parcel data, reply; |
| 288 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 289 | data.writeInt32((int32_t)portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 290 | remote()->transact(START_OUTPUT, data, &reply); |
| 291 | return static_cast <status_t> (reply.readInt32()); |
| 292 | } |
| 293 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 294 | virtual status_t stopOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 295 | { |
| 296 | Parcel data, reply; |
| 297 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 298 | data.writeInt32((int32_t)portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 299 | remote()->transact(STOP_OUTPUT, data, &reply); |
| 300 | return static_cast <status_t> (reply.readInt32()); |
| 301 | } |
| 302 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 303 | virtual void releaseOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 304 | { |
| 305 | Parcel data, reply; |
| 306 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 307 | data.writeInt32((int32_t)portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 308 | remote()->transact(RELEASE_OUTPUT, data, &reply); |
| 309 | } |
| 310 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 311 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 312 | audio_io_handle_t *input, |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 313 | audio_unique_id_t riid, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 314 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 315 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 316 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 317 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 318 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 319 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 320 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 321 | audio_port_handle_t *portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 322 | { |
| 323 | Parcel data, reply; |
| 324 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 325 | if (attr == NULL) { |
| 326 | ALOGE("getInputForAttr NULL attr - shouldn't happen"); |
| 327 | return BAD_VALUE; |
| 328 | } |
| 329 | if (input == NULL) { |
| 330 | ALOGE("getInputForAttr NULL input - shouldn't happen"); |
| 331 | return BAD_VALUE; |
| 332 | } |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 333 | if (selectedDeviceId == NULL) { |
| 334 | ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen"); |
| 335 | return BAD_VALUE; |
| 336 | } |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 337 | if (portId == NULL) { |
| 338 | ALOGE("getInputForAttr NULL portId - shouldn't happen"); |
| 339 | return BAD_VALUE; |
| 340 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 341 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 342 | data.write(attr, sizeof(audio_attributes_t)); |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 343 | data.writeInt32(*input); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 344 | data.writeInt32(riid); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 345 | data.writeInt32(session); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 346 | data.writeInt32(pid); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 347 | data.writeInt32(uid); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 348 | data.writeString16(opPackageName); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 349 | data.write(config, sizeof(audio_config_base_t)); |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 350 | data.writeInt32(flags); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 351 | data.writeInt32(*selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 352 | data.writeInt32(*portId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 353 | status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply); |
| 354 | if (status != NO_ERROR) { |
| 355 | return status; |
| 356 | } |
| 357 | status = reply.readInt32(); |
| 358 | if (status != NO_ERROR) { |
| 359 | return status; |
| 360 | } |
| 361 | *input = (audio_io_handle_t)reply.readInt32(); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 362 | *selectedDeviceId = (audio_port_handle_t)reply.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 363 | *portId = (audio_port_handle_t)reply.readInt32(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 364 | return NO_ERROR; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 367 | virtual status_t startInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 368 | { |
| 369 | Parcel data, reply; |
| 370 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 371 | data.writeInt32(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 372 | remote()->transact(START_INPUT, data, &reply); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 373 | status_t status = static_cast <status_t> (reply.readInt32()); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 374 | return status; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 377 | virtual status_t stopInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 378 | { |
| 379 | Parcel data, reply; |
| 380 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 381 | data.writeInt32(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 382 | remote()->transact(STOP_INPUT, data, &reply); |
| 383 | return static_cast <status_t> (reply.readInt32()); |
| 384 | } |
| 385 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 386 | virtual void releaseInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 387 | { |
| 388 | Parcel data, reply; |
| 389 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 390 | data.writeInt32(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 391 | remote()->transact(RELEASE_INPUT, data, &reply); |
| 392 | } |
| 393 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 394 | virtual status_t initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 395 | int indexMin, |
| 396 | int indexMax) |
| 397 | { |
| 398 | Parcel data, reply; |
| 399 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 400 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 401 | data.writeInt32(indexMin); |
| 402 | data.writeInt32(indexMax); |
| 403 | remote()->transact(INIT_STREAM_VOLUME, data, &reply); |
| 404 | return static_cast <status_t> (reply.readInt32()); |
| 405 | } |
| 406 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 407 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 408 | int index, |
| 409 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 410 | { |
| 411 | Parcel data, reply; |
| 412 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 413 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 414 | data.writeInt32(index); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 415 | data.writeInt32(static_cast <uint32_t>(device)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 416 | remote()->transact(SET_STREAM_VOLUME, data, &reply); |
| 417 | return static_cast <status_t> (reply.readInt32()); |
| 418 | } |
| 419 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 420 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 421 | int *index, |
| 422 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 423 | { |
| 424 | Parcel data, reply; |
| 425 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 426 | data.writeInt32(static_cast <uint32_t>(stream)); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 427 | data.writeInt32(static_cast <uint32_t>(device)); |
| 428 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 429 | remote()->transact(GET_STREAM_VOLUME, data, &reply); |
| 430 | int lIndex = reply.readInt32(); |
| 431 | if (index) *index = lIndex; |
| 432 | return static_cast <status_t> (reply.readInt32()); |
| 433 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 434 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 435 | virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index, |
| 436 | audio_devices_t device) |
| 437 | { |
| 438 | Parcel data, reply; |
| 439 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 440 | data.write(&attr, sizeof(audio_attributes_t)); |
| 441 | data.writeInt32(index); |
| 442 | data.writeInt32(static_cast <uint32_t>(device)); |
| 443 | status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply); |
| 444 | if (status != NO_ERROR) { |
| 445 | return status; |
| 446 | } |
| 447 | return static_cast <status_t> (reply.readInt32()); |
| 448 | } |
| 449 | virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index, |
| 450 | audio_devices_t device) |
| 451 | { |
| 452 | Parcel data, reply; |
| 453 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 454 | data.write(&attr, sizeof(audio_attributes_t)); |
| 455 | data.writeInt32(static_cast <uint32_t>(device)); |
| 456 | status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply); |
| 457 | if (status != NO_ERROR) { |
| 458 | return status; |
| 459 | } |
| 460 | status = static_cast <status_t> (reply.readInt32()); |
| 461 | if (status != NO_ERROR) { |
| 462 | return status; |
| 463 | } |
| 464 | index = reply.readInt32(); |
| 465 | return NO_ERROR; |
| 466 | } |
| 467 | virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) |
| 468 | { |
| 469 | Parcel data, reply; |
| 470 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 471 | data.write(&attr, sizeof(audio_attributes_t)); |
| 472 | status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply); |
| 473 | if (status != NO_ERROR) { |
| 474 | return status; |
| 475 | } |
| 476 | status = static_cast <status_t> (reply.readInt32()); |
| 477 | if (status != NO_ERROR) { |
| 478 | return status; |
| 479 | } |
| 480 | index = reply.readInt32(); |
| 481 | return NO_ERROR; |
| 482 | } |
| 483 | virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) |
| 484 | { |
| 485 | Parcel data, reply; |
| 486 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 487 | data.write(&attr, sizeof(audio_attributes_t)); |
| 488 | status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply); |
| 489 | if (status != NO_ERROR) { |
| 490 | return status; |
| 491 | } |
| 492 | status = static_cast <status_t> (reply.readInt32()); |
| 493 | if (status != NO_ERROR) { |
| 494 | return status; |
| 495 | } |
| 496 | index = reply.readInt32(); |
| 497 | return NO_ERROR; |
| 498 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 499 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 500 | { |
| 501 | Parcel data, reply; |
| 502 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 503 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 504 | remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 505 | return reply.readUint32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 508 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 509 | { |
| 510 | Parcel data, reply; |
| 511 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 512 | data.writeInt32(static_cast <uint32_t>(stream)); |
| 513 | remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply); |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 514 | return (audio_devices_t) reply.readInt32(); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 517 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 518 | { |
| 519 | Parcel data, reply; |
| 520 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 521 | data.write(desc, sizeof(effect_descriptor_t)); |
| 522 | remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply); |
| 523 | return static_cast <audio_io_handle_t> (reply.readInt32()); |
| 524 | } |
| 525 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 526 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 527 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 528 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 529 | audio_session_t session, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 530 | int id) |
| 531 | { |
| 532 | Parcel data, reply; |
| 533 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 534 | data.write(desc, sizeof(effect_descriptor_t)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 535 | data.writeInt32(io); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 536 | data.writeInt32(strategy); |
| 537 | data.writeInt32(session); |
| 538 | data.writeInt32(id); |
| 539 | remote()->transact(REGISTER_EFFECT, data, &reply); |
| 540 | return static_cast <status_t> (reply.readInt32()); |
| 541 | } |
| 542 | |
| 543 | virtual status_t unregisterEffect(int id) |
| 544 | { |
| 545 | Parcel data, reply; |
| 546 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 547 | data.writeInt32(id); |
| 548 | remote()->transact(UNREGISTER_EFFECT, data, &reply); |
| 549 | return static_cast <status_t> (reply.readInt32()); |
| 550 | } |
| 551 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 552 | virtual status_t setEffectEnabled(int id, bool enabled) |
| 553 | { |
| 554 | Parcel data, reply; |
| 555 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 556 | data.writeInt32(id); |
| 557 | data.writeInt32(enabled); |
| 558 | remote()->transact(SET_EFFECT_ENABLED, data, &reply); |
| 559 | return static_cast <status_t> (reply.readInt32()); |
| 560 | } |
| 561 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 562 | status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override |
| 563 | { |
| 564 | Parcel data, reply; |
| 565 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 566 | data.writeInt32(ids.size()); |
| 567 | for (auto id : ids) { |
| 568 | data.writeInt32(id); |
| 569 | } |
| 570 | data.writeInt32(io); |
| 571 | status_t status = remote()->transact(MOVE_EFFECTS_TO_IO, data, &reply); |
| 572 | if (status != NO_ERROR) { |
| 573 | return status; |
| 574 | } |
| 575 | return static_cast <status_t> (reply.readInt32()); |
| 576 | } |
| 577 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 578 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 579 | { |
| 580 | Parcel data, reply; |
| 581 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 582 | data.writeInt32((int32_t) stream); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 583 | data.writeInt32(inPastMs); |
| 584 | remote()->transact(IS_STREAM_ACTIVE, data, &reply); |
| 585 | return reply.readInt32(); |
| 586 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 587 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 588 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 589 | { |
| 590 | Parcel data, reply; |
| 591 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 592 | data.writeInt32((int32_t) stream); |
| 593 | data.writeInt32(inPastMs); |
| 594 | remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply); |
| 595 | return reply.readInt32(); |
| 596 | } |
| 597 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 598 | virtual bool isSourceActive(audio_source_t source) const |
| 599 | { |
| 600 | Parcel data, reply; |
| 601 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 602 | data.writeInt32((int32_t) source); |
| 603 | remote()->transact(IS_SOURCE_ACTIVE, data, &reply); |
| 604 | return reply.readInt32(); |
| 605 | } |
| 606 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 607 | virtual status_t queryDefaultPreProcessing(audio_session_t audioSession, |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 608 | effect_descriptor_t *descriptors, |
| 609 | uint32_t *count) |
| 610 | { |
| 611 | if (descriptors == NULL || count == NULL) { |
| 612 | return BAD_VALUE; |
| 613 | } |
| 614 | Parcel data, reply; |
| 615 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 616 | data.writeInt32(audioSession); |
| 617 | data.writeInt32(*count); |
| 618 | status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply); |
| 619 | if (status != NO_ERROR) { |
| 620 | return status; |
| 621 | } |
| 622 | status = static_cast <status_t> (reply.readInt32()); |
| 623 | uint32_t retCount = reply.readInt32(); |
| 624 | if (retCount != 0) { |
| 625 | uint32_t numDesc = (retCount < *count) ? retCount : *count; |
| 626 | reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc); |
| 627 | } |
| 628 | *count = retCount; |
| 629 | return status; |
| 630 | } |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 631 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 632 | status_t setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { |
| 633 | Parcel data, reply; |
| 634 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 635 | data.writeInt32(systemUsages.size()); |
| 636 | for (auto systemUsage : systemUsages) { |
| 637 | data.writeInt32(systemUsage); |
| 638 | } |
| 639 | status_t status = remote()->transact(SET_SUPPORTED_SYSTEM_USAGES, data, &reply); |
| 640 | if (status != NO_ERROR) { |
| 641 | return status; |
| 642 | } |
| 643 | return static_cast <status_t> (reply.readInt32()); |
| 644 | } |
| 645 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 646 | status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override { |
| 647 | Parcel data, reply; |
| 648 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 649 | data.writeInt32(uid); |
| 650 | data.writeInt32(flags); |
| 651 | remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply); |
| 652 | return reply.readInt32(); |
| 653 | } |
| 654 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 655 | virtual bool isOffloadSupported(const audio_offload_info_t& info) |
| 656 | { |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 657 | Parcel data, reply; |
| 658 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 659 | data.write(&info, sizeof(audio_offload_info_t)); |
| 660 | remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 661 | return reply.readInt32(); |
| 662 | } |
| 663 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 664 | virtual bool isDirectOutputSupported(const audio_config_base_t& config, |
| 665 | const audio_attributes_t& attributes) { |
| 666 | Parcel data, reply; |
| 667 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 668 | data.write(&config, sizeof(audio_config_base_t)); |
| 669 | data.write(&attributes, sizeof(audio_attributes_t)); |
| 670 | status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply); |
| 671 | return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false; |
| 672 | } |
| 673 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 674 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 675 | audio_port_type_t type, |
| 676 | unsigned int *num_ports, |
| 677 | struct audio_port *ports, |
| 678 | unsigned int *generation) |
| 679 | { |
| 680 | if (num_ports == NULL || (*num_ports != 0 && ports == NULL) || |
| 681 | generation == NULL) { |
| 682 | return BAD_VALUE; |
| 683 | } |
| 684 | Parcel data, reply; |
| 685 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 686 | unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports; |
| 687 | data.writeInt32(role); |
| 688 | data.writeInt32(type); |
| 689 | data.writeInt32(numPortsReq); |
| 690 | status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply); |
| 691 | if (status == NO_ERROR) { |
| 692 | status = (status_t)reply.readInt32(); |
| 693 | *num_ports = (unsigned int)reply.readInt32(); |
| 694 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 695 | if (status == NO_ERROR) { |
| 696 | if (numPortsReq > *num_ports) { |
| 697 | numPortsReq = *num_ports; |
| 698 | } |
| 699 | if (numPortsReq > 0) { |
| 700 | reply.read(ports, numPortsReq * sizeof(struct audio_port)); |
| 701 | } |
| 702 | *generation = reply.readInt32(); |
| 703 | } |
| 704 | return status; |
| 705 | } |
| 706 | |
| 707 | virtual status_t getAudioPort(struct audio_port *port) |
| 708 | { |
| 709 | if (port == NULL) { |
| 710 | return BAD_VALUE; |
| 711 | } |
| 712 | Parcel data, reply; |
| 713 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 714 | data.write(port, sizeof(struct audio_port)); |
| 715 | status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply); |
| 716 | if (status != NO_ERROR || |
| 717 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 718 | return status; |
| 719 | } |
| 720 | reply.read(port, sizeof(struct audio_port)); |
| 721 | return status; |
| 722 | } |
| 723 | |
| 724 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 725 | audio_patch_handle_t *handle) |
| 726 | { |
| 727 | if (patch == NULL || handle == NULL) { |
| 728 | return BAD_VALUE; |
| 729 | } |
| 730 | Parcel data, reply; |
| 731 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 732 | data.write(patch, sizeof(struct audio_patch)); |
| 733 | data.write(handle, sizeof(audio_patch_handle_t)); |
| 734 | status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply); |
| 735 | if (status != NO_ERROR || |
| 736 | (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 737 | return status; |
| 738 | } |
| 739 | reply.read(handle, sizeof(audio_patch_handle_t)); |
| 740 | return status; |
| 741 | } |
| 742 | |
| 743 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle) |
| 744 | { |
| 745 | Parcel data, reply; |
| 746 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 747 | data.write(&handle, sizeof(audio_patch_handle_t)); |
| 748 | status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply); |
| 749 | if (status != NO_ERROR) { |
| 750 | status = (status_t)reply.readInt32(); |
| 751 | } |
| 752 | return status; |
| 753 | } |
| 754 | |
| 755 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 756 | struct audio_patch *patches, |
| 757 | unsigned int *generation) |
| 758 | { |
| 759 | if (num_patches == NULL || (*num_patches != 0 && patches == NULL) || |
| 760 | generation == NULL) { |
| 761 | return BAD_VALUE; |
| 762 | } |
| 763 | Parcel data, reply; |
| 764 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 765 | unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches; |
| 766 | data.writeInt32(numPatchesReq); |
| 767 | status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply); |
| 768 | if (status == NO_ERROR) { |
| 769 | status = (status_t)reply.readInt32(); |
| 770 | *num_patches = (unsigned int)reply.readInt32(); |
| 771 | } |
| 772 | if (status == NO_ERROR) { |
| 773 | if (numPatchesReq > *num_patches) { |
| 774 | numPatchesReq = *num_patches; |
| 775 | } |
| 776 | if (numPatchesReq > 0) { |
| 777 | reply.read(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 778 | } |
| 779 | *generation = reply.readInt32(); |
| 780 | } |
| 781 | return status; |
| 782 | } |
| 783 | |
| 784 | virtual status_t setAudioPortConfig(const struct audio_port_config *config) |
| 785 | { |
| 786 | if (config == NULL) { |
| 787 | return BAD_VALUE; |
| 788 | } |
| 789 | Parcel data, reply; |
| 790 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 791 | data.write(config, sizeof(struct audio_port_config)); |
| 792 | status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply); |
| 793 | if (status != NO_ERROR) { |
| 794 | status = (status_t)reply.readInt32(); |
| 795 | } |
| 796 | return status; |
| 797 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 798 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 799 | virtual void registerClient(const sp<IAudioPolicyServiceClient>& client) |
| 800 | { |
| 801 | Parcel data, reply; |
| 802 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Marco Nelissen | f888020 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 803 | data.writeStrongBinder(IInterface::asBinder(client)); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 804 | remote()->transact(REGISTER_CLIENT, data, &reply); |
| 805 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 806 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 807 | virtual void setAudioPortCallbacksEnabled(bool enabled) |
| 808 | { |
| 809 | Parcel data, reply; |
| 810 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 811 | data.writeInt32(enabled ? 1 : 0); |
| 812 | remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply); |
| 813 | } |
| 814 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 815 | virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled) |
| 816 | { |
| 817 | Parcel data, reply; |
| 818 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 819 | data.writeInt32(enabled ? 1 : 0); |
| 820 | remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply); |
| 821 | } |
| 822 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 823 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 824 | audio_io_handle_t *ioHandle, |
| 825 | audio_devices_t *device) |
| 826 | { |
| 827 | if (session == NULL || ioHandle == NULL || device == NULL) { |
| 828 | return BAD_VALUE; |
| 829 | } |
| 830 | Parcel data, reply; |
| 831 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 832 | status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply); |
| 833 | if (status != NO_ERROR) { |
| 834 | return status; |
| 835 | } |
| 836 | status = (status_t)reply.readInt32(); |
| 837 | if (status == NO_ERROR) { |
| 838 | *session = (audio_session_t)reply.readInt32(); |
| 839 | *ioHandle = (audio_io_handle_t)reply.readInt32(); |
| 840 | *device = (audio_devices_t)reply.readInt32(); |
| 841 | } |
| 842 | return status; |
| 843 | } |
| 844 | |
| 845 | virtual status_t releaseSoundTriggerSession(audio_session_t session) |
| 846 | { |
| 847 | Parcel data, reply; |
| 848 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 849 | data.writeInt32(session); |
| 850 | status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply); |
| 851 | if (status != NO_ERROR) { |
| 852 | return status; |
| 853 | } |
| 854 | return (status_t)reply.readInt32(); |
| 855 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 856 | |
| 857 | virtual audio_mode_t getPhoneState() |
| 858 | { |
| 859 | Parcel data, reply; |
| 860 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 861 | status_t status = remote()->transact(GET_PHONE_STATE, data, &reply); |
| 862 | if (status != NO_ERROR) { |
| 863 | return AUDIO_MODE_INVALID; |
| 864 | } |
| 865 | return (audio_mode_t)reply.readInt32(); |
| 866 | } |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 867 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 868 | virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 869 | { |
| 870 | Parcel data, reply; |
| 871 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 872 | data.writeInt32(registration ? 1 : 0); |
| 873 | size_t size = mixes.size(); |
| 874 | if (size > MAX_MIXES_PER_POLICY) { |
| 875 | size = MAX_MIXES_PER_POLICY; |
| 876 | } |
| 877 | size_t sizePosition = data.dataPosition(); |
| 878 | data.writeInt32(size); |
| 879 | size_t finalSize = size; |
| 880 | for (size_t i = 0; i < size; i++) { |
| 881 | size_t position = data.dataPosition(); |
| 882 | if (mixes[i].writeToParcel(&data) != NO_ERROR) { |
| 883 | data.setDataPosition(position); |
| 884 | finalSize--; |
| 885 | } |
| 886 | } |
| 887 | if (size != finalSize) { |
| 888 | size_t position = data.dataPosition(); |
| 889 | data.setDataPosition(sizePosition); |
| 890 | data.writeInt32(finalSize); |
| 891 | data.setDataPosition(position); |
| 892 | } |
| 893 | status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply); |
| 894 | if (status == NO_ERROR) { |
| 895 | status = (status_t)reply.readInt32(); |
| 896 | } |
| 897 | return status; |
| 898 | } |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 899 | |
| 900 | virtual status_t startAudioSource(const struct audio_port_config *source, |
| 901 | const audio_attributes_t *attributes, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 902 | audio_port_handle_t *portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 903 | { |
| 904 | Parcel data, reply; |
| 905 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 906 | if (source == NULL || attributes == NULL || portId == NULL) { |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 907 | return BAD_VALUE; |
| 908 | } |
| 909 | data.write(source, sizeof(struct audio_port_config)); |
| 910 | data.write(attributes, sizeof(audio_attributes_t)); |
| 911 | status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply); |
| 912 | if (status != NO_ERROR) { |
| 913 | return status; |
| 914 | } |
| 915 | status = (status_t)reply.readInt32(); |
| 916 | if (status != NO_ERROR) { |
| 917 | return status; |
| 918 | } |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 919 | *portId = (audio_port_handle_t)reply.readInt32(); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 920 | return status; |
| 921 | } |
| 922 | |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 923 | virtual status_t stopAudioSource(audio_port_handle_t portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 924 | { |
| 925 | Parcel data, reply; |
| 926 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 927 | data.writeInt32(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 928 | status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply); |
| 929 | if (status != NO_ERROR) { |
| 930 | return status; |
| 931 | } |
| 932 | status = (status_t)reply.readInt32(); |
| 933 | return status; |
| 934 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 935 | |
| 936 | virtual status_t setMasterMono(bool mono) |
| 937 | { |
| 938 | Parcel data, reply; |
| 939 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 940 | data.writeInt32(static_cast<int32_t>(mono)); |
| 941 | status_t status = remote()->transact(SET_MASTER_MONO, data, &reply); |
| 942 | if (status != NO_ERROR) { |
| 943 | return status; |
| 944 | } |
| 945 | return static_cast<status_t>(reply.readInt32()); |
| 946 | } |
| 947 | |
| 948 | virtual status_t getMasterMono(bool *mono) |
| 949 | { |
| 950 | if (mono == nullptr) { |
| 951 | return BAD_VALUE; |
| 952 | } |
| 953 | Parcel data, reply; |
| 954 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 955 | |
| 956 | status_t status = remote()->transact(GET_MASTER_MONO, data, &reply); |
| 957 | if (status != NO_ERROR) { |
| 958 | return status; |
| 959 | } |
| 960 | status = static_cast<status_t>(reply.readInt32()); |
| 961 | if (status == NO_ERROR) { |
| 962 | *mono = static_cast<bool>(reply.readInt32()); |
| 963 | } |
| 964 | return status; |
| 965 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 966 | |
| 967 | virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device) |
| 968 | { |
| 969 | Parcel data, reply; |
| 970 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 971 | data.writeInt32(static_cast <int32_t>(stream)); |
| 972 | data.writeInt32(static_cast <int32_t>(index)); |
| 973 | data.writeUint32(static_cast <uint32_t>(device)); |
| 974 | status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply); |
| 975 | if (status != NO_ERROR) { |
| 976 | return NAN; |
| 977 | } |
| 978 | return reply.readFloat(); |
| 979 | } |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 980 | |
| 981 | virtual status_t getSurroundFormats(unsigned int *numSurroundFormats, |
| 982 | audio_format_t *surroundFormats, |
| 983 | bool *surroundFormatsEnabled, |
| 984 | bool reported) |
| 985 | { |
| 986 | if (numSurroundFormats == NULL || (*numSurroundFormats != 0 && |
| 987 | (surroundFormats == NULL || surroundFormatsEnabled == NULL))) { |
| 988 | return BAD_VALUE; |
| 989 | } |
| 990 | Parcel data, reply; |
| 991 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 992 | unsigned int numSurroundFormatsReq = *numSurroundFormats; |
| 993 | data.writeUint32(numSurroundFormatsReq); |
| 994 | data.writeBool(reported); |
| 995 | status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply); |
| 996 | if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) { |
| 997 | *numSurroundFormats = reply.readUint32(); |
| 998 | } |
| 999 | if (status == NO_ERROR) { |
| 1000 | if (numSurroundFormatsReq > *numSurroundFormats) { |
| 1001 | numSurroundFormatsReq = *numSurroundFormats; |
| 1002 | } |
| 1003 | if (numSurroundFormatsReq > 0) { |
| 1004 | status = reply.read(surroundFormats, |
| 1005 | numSurroundFormatsReq * sizeof(audio_format_t)); |
| 1006 | if (status != NO_ERROR) { |
| 1007 | return status; |
| 1008 | } |
| 1009 | status = reply.read(surroundFormatsEnabled, |
| 1010 | numSurroundFormatsReq * sizeof(bool)); |
| 1011 | } |
| 1012 | } |
| 1013 | return status; |
| 1014 | } |
| 1015 | |
| 1016 | virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) |
| 1017 | { |
| 1018 | Parcel data, reply; |
| 1019 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1020 | data.writeInt32(audioFormat); |
| 1021 | data.writeBool(enabled); |
| 1022 | status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply); |
| 1023 | if (status != NO_ERROR) { |
| 1024 | return status; |
| 1025 | } |
| 1026 | return reply.readInt32(); |
| 1027 | } |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1028 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1029 | virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP( |
| 1030 | std::vector<audio_format_t> *formats) |
| 1031 | { |
| 1032 | if (formats == NULL) { |
| 1033 | return BAD_VALUE; |
| 1034 | } |
| 1035 | |
| 1036 | Parcel data, reply; |
| 1037 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1038 | status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply); |
| 1039 | if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) { |
| 1040 | return status; |
| 1041 | } |
| 1042 | |
| 1043 | size_t list_size = reply.readUint32(); |
| 1044 | |
| 1045 | for (size_t i = 0; i < list_size; i++) { |
| 1046 | formats->push_back(static_cast<audio_format_t>(reply.readInt32())); |
| 1047 | } |
| 1048 | return NO_ERROR; |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | virtual status_t addStreamDefaultEffect(const effect_uuid_t *type, |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1053 | const String16& opPackageName, |
| 1054 | const effect_uuid_t *uuid, |
| 1055 | int32_t priority, |
| 1056 | audio_usage_t usage, |
| 1057 | audio_unique_id_t* id) |
| 1058 | { |
| 1059 | Parcel data, reply; |
| 1060 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1061 | data.write(type, sizeof(effect_uuid_t)); |
| 1062 | data.writeString16(opPackageName); |
| 1063 | data.write(uuid, sizeof(effect_uuid_t)); |
| 1064 | data.writeInt32(priority); |
| 1065 | data.writeInt32((int32_t) usage); |
| 1066 | status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply); |
| 1067 | if (status != NO_ERROR) { |
| 1068 | return status; |
| 1069 | } |
| 1070 | status = static_cast <status_t> (reply.readInt32()); |
| 1071 | *id = reply.readInt32(); |
| 1072 | return status; |
| 1073 | } |
| 1074 | |
| 1075 | virtual status_t removeStreamDefaultEffect(audio_unique_id_t id) |
| 1076 | { |
| 1077 | Parcel data, reply; |
| 1078 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1079 | data.writeInt32(id); |
| 1080 | status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply); |
| 1081 | if (status != NO_ERROR) { |
| 1082 | return status; |
| 1083 | } |
| 1084 | return static_cast <status_t> (reply.readInt32()); |
| 1085 | } |
| 1086 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1087 | virtual status_t addSourceDefaultEffect(const effect_uuid_t *type, |
| 1088 | const String16& opPackageName, |
| 1089 | const effect_uuid_t *uuid, |
| 1090 | int32_t priority, |
| 1091 | audio_source_t source, |
| 1092 | audio_unique_id_t* id) |
| 1093 | { |
| 1094 | Parcel data, reply; |
| 1095 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1096 | data.write(type, sizeof(effect_uuid_t)); |
| 1097 | data.writeString16(opPackageName); |
| 1098 | data.write(uuid, sizeof(effect_uuid_t)); |
| 1099 | data.writeInt32(priority); |
| 1100 | data.writeInt32((int32_t) source); |
| 1101 | status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply); |
| 1102 | if (status != NO_ERROR) { |
| 1103 | return status; |
| 1104 | } |
| 1105 | status = static_cast <status_t> (reply.readInt32()); |
| 1106 | *id = reply.readInt32(); |
| 1107 | return status; |
| 1108 | } |
| 1109 | |
| 1110 | virtual status_t removeSourceDefaultEffect(audio_unique_id_t id) |
| 1111 | { |
| 1112 | Parcel data, reply; |
| 1113 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1114 | data.writeInt32(id); |
| 1115 | status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply); |
| 1116 | if (status != NO_ERROR) { |
| 1117 | return status; |
| 1118 | } |
| 1119 | return static_cast <status_t> (reply.readInt32()); |
| 1120 | } |
| 1121 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1122 | virtual status_t setAssistantUid(uid_t uid) |
| 1123 | { |
| 1124 | Parcel data, reply; |
| 1125 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1126 | data.writeInt32(uid); |
| 1127 | status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply); |
| 1128 | if (status != NO_ERROR) { |
| 1129 | return status; |
| 1130 | } |
| 1131 | return static_cast <status_t> (reply.readInt32()); |
| 1132 | } |
| 1133 | |
| 1134 | virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids) |
| 1135 | { |
| 1136 | Parcel data, reply; |
| 1137 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1138 | data.writeInt32(uids.size()); |
| 1139 | for (auto uid : uids) { |
| 1140 | data.writeInt32(uid); |
| 1141 | } |
| 1142 | status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply); |
| 1143 | if (status != NO_ERROR) { |
| 1144 | return status; |
| 1145 | } |
| 1146 | return static_cast <status_t> (reply.readInt32()); |
| 1147 | } |
| 1148 | |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame^] | 1149 | virtual status_t setCurrentImeUid(uid_t uid) |
| 1150 | { |
| 1151 | Parcel data, reply; |
| 1152 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1153 | data.writeInt32(uid); |
| 1154 | status_t status = remote()->transact(SET_CURRENT_IME_UID, data, &reply); |
| 1155 | if (status != NO_ERROR) { |
| 1156 | return status; |
| 1157 | } |
| 1158 | return static_cast <status_t> (reply.readInt32()); |
| 1159 | } |
| 1160 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1161 | virtual bool isHapticPlaybackSupported() |
| 1162 | { |
| 1163 | Parcel data, reply; |
| 1164 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1165 | status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply); |
| 1166 | if (status != NO_ERROR) { |
| 1167 | return false; |
| 1168 | } |
| 1169 | return reply.readBool(); |
| 1170 | } |
| 1171 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1172 | virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices) |
| 1173 | { |
| 1174 | Parcel data, reply; |
| 1175 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1176 | |
| 1177 | data.writeInt32((int32_t) uid); |
| 1178 | size_t size = devices.size(); |
| 1179 | size_t sizePosition = data.dataPosition(); |
| 1180 | data.writeInt32((int32_t) size); |
| 1181 | size_t finalSize = size; |
| 1182 | for (size_t i = 0; i < size; i++) { |
| 1183 | size_t position = data.dataPosition(); |
| 1184 | if (devices[i].writeToParcel(&data) != NO_ERROR) { |
| 1185 | data.setDataPosition(position); |
| 1186 | finalSize--; |
| 1187 | } |
| 1188 | } |
| 1189 | if (size != finalSize) { |
| 1190 | size_t position = data.dataPosition(); |
| 1191 | data.setDataPosition(sizePosition); |
| 1192 | data.writeInt32(finalSize); |
| 1193 | data.setDataPosition(position); |
| 1194 | } |
| 1195 | |
| 1196 | status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply); |
| 1197 | if (status == NO_ERROR) { |
| 1198 | status = (status_t)reply.readInt32(); |
| 1199 | } |
| 1200 | return status; |
| 1201 | } |
| 1202 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1203 | virtual status_t removeUidDeviceAffinities(uid_t uid) { |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1204 | Parcel data, reply; |
| 1205 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1206 | |
| 1207 | data.writeInt32((int32_t) uid); |
| 1208 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1209 | status_t status = |
| 1210 | remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1211 | if (status == NO_ERROR) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1212 | status = (status_t) reply.readInt32(); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1213 | } |
| 1214 | return status; |
| 1215 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1216 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1217 | virtual status_t setUserIdDeviceAffinities(int userId, |
| 1218 | const Vector<AudioDeviceTypeAddr>& devices) |
| 1219 | { |
| 1220 | Parcel data, reply; |
| 1221 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1222 | |
| 1223 | data.writeInt32((int32_t) userId); |
| 1224 | size_t size = devices.size(); |
| 1225 | size_t sizePosition = data.dataPosition(); |
| 1226 | data.writeInt32((int32_t) size); |
| 1227 | size_t finalSize = size; |
| 1228 | for (size_t i = 0; i < size; i++) { |
| 1229 | size_t position = data.dataPosition(); |
| 1230 | if (devices[i].writeToParcel(&data) != NO_ERROR) { |
| 1231 | data.setDataPosition(position); |
| 1232 | finalSize--; |
| 1233 | } |
| 1234 | } |
| 1235 | if (size != finalSize) { |
| 1236 | size_t position = data.dataPosition(); |
| 1237 | data.setDataPosition(sizePosition); |
| 1238 | data.writeInt32(finalSize); |
| 1239 | data.setDataPosition(position); |
| 1240 | } |
| 1241 | |
| 1242 | status_t status = remote()->transact(SET_USERID_DEVICE_AFFINITY, data, &reply); |
| 1243 | if (status == NO_ERROR) { |
| 1244 | status = (status_t)reply.readInt32(); |
| 1245 | } |
| 1246 | return status; |
| 1247 | } |
| 1248 | |
| 1249 | virtual status_t removeUserIdDeviceAffinities(int userId) { |
| 1250 | Parcel data, reply; |
| 1251 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1252 | |
| 1253 | data.writeInt32((int32_t) userId); |
| 1254 | |
| 1255 | status_t status = |
| 1256 | remote()->transact(REMOVE_USERID_DEVICE_AFFINITY, data, &reply); |
| 1257 | if (status == NO_ERROR) { |
| 1258 | status = (status_t) reply.readInt32(); |
| 1259 | } |
| 1260 | return status; |
| 1261 | } |
| 1262 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1263 | virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) |
| 1264 | { |
| 1265 | Parcel data, reply; |
| 1266 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1267 | |
| 1268 | status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply); |
| 1269 | if (status != NO_ERROR) { |
| 1270 | ALOGE("%s: permission denied", __func__); |
| 1271 | return status; |
| 1272 | } |
| 1273 | status = static_cast<status_t>(reply.readInt32()); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1274 | if (status != NO_ERROR) { |
| 1275 | return status; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1276 | } |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1277 | uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32()); |
| 1278 | for (size_t i = 0; i < numStrategies; i++) { |
| 1279 | AudioProductStrategy strategy; |
| 1280 | status = strategy.readFromParcel(&reply); |
| 1281 | if (status != NO_ERROR) { |
| 1282 | ALOGE("%s: failed to read strategies", __FUNCTION__); |
| 1283 | strategies.clear(); |
| 1284 | return status; |
| 1285 | } |
| 1286 | strategies.push_back(strategy); |
| 1287 | } |
| 1288 | return NO_ERROR; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1291 | virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa, |
| 1292 | product_strategy_t &productStrategy) |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1293 | { |
| 1294 | Parcel data, reply; |
| 1295 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1296 | status_t status = aa.writeToParcel(&data); |
| 1297 | if (status != NO_ERROR) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1298 | return status; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1299 | } |
| 1300 | status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1301 | if (status != NO_ERROR) { |
| 1302 | return status; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1303 | } |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1304 | status = static_cast<status_t>(reply.readInt32()); |
| 1305 | if (status != NO_ERROR) { |
| 1306 | return status; |
| 1307 | } |
| 1308 | productStrategy = static_cast<product_strategy_t>(reply.readInt32()); |
| 1309 | return NO_ERROR; |
| 1310 | } |
| 1311 | |
| 1312 | virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups) |
| 1313 | { |
| 1314 | Parcel data, reply; |
| 1315 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1316 | |
| 1317 | status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply); |
| 1318 | if (status != NO_ERROR) { |
| 1319 | return status; |
| 1320 | } |
| 1321 | status = static_cast<status_t>(reply.readInt32()); |
| 1322 | if (status != NO_ERROR) { |
| 1323 | return status; |
| 1324 | } |
| 1325 | uint32_t numGroups = static_cast<uint32_t>(reply.readInt32()); |
| 1326 | for (size_t i = 0; i < numGroups; i++) { |
| 1327 | AudioVolumeGroup group; |
| 1328 | status = group.readFromParcel(&reply); |
| 1329 | if (status != NO_ERROR) { |
| 1330 | ALOGE("%s: failed to read volume groups", __FUNCTION__); |
| 1331 | groups.clear(); |
| 1332 | return status; |
| 1333 | } |
| 1334 | groups.push_back(group); |
| 1335 | } |
| 1336 | return NO_ERROR; |
| 1337 | } |
| 1338 | |
| 1339 | virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa, |
| 1340 | volume_group_t &volumeGroup) |
| 1341 | { |
| 1342 | Parcel data, reply; |
| 1343 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1344 | status_t status = aa.writeToParcel(&data); |
| 1345 | if (status != NO_ERROR) { |
| 1346 | return status; |
| 1347 | } |
| 1348 | status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply); |
| 1349 | if (status != NO_ERROR) { |
| 1350 | return status; |
| 1351 | } |
| 1352 | status = static_cast<status_t>(reply.readInt32()); |
| 1353 | if (status != NO_ERROR) { |
| 1354 | return status; |
| 1355 | } |
| 1356 | volumeGroup = static_cast<volume_group_t>(reply.readInt32()); |
| 1357 | return NO_ERROR; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1358 | } |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1359 | |
| 1360 | virtual status_t setRttEnabled(bool enabled) |
| 1361 | { |
| 1362 | Parcel data, reply; |
| 1363 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1364 | data.writeInt32(static_cast<int32_t>(enabled)); |
| 1365 | status_t status = remote()->transact(SET_RTT_ENABLED, data, &reply); |
| 1366 | if (status != NO_ERROR) { |
| 1367 | return status; |
| 1368 | } |
| 1369 | return static_cast<status_t>(reply.readInt32()); |
| 1370 | } |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1371 | |
| 1372 | virtual bool isCallScreenModeSupported() |
| 1373 | { |
| 1374 | Parcel data, reply; |
| 1375 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1376 | status_t status = remote()->transact(IS_CALL_SCREEN_MODE_SUPPORTED, data, &reply); |
| 1377 | if (status != NO_ERROR) { |
| 1378 | return false; |
| 1379 | } |
| 1380 | return reply.readBool(); |
| 1381 | } |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1382 | |
| 1383 | virtual status_t setPreferredDeviceForStrategy(product_strategy_t strategy, |
| 1384 | const AudioDeviceTypeAddr &device) |
| 1385 | { |
| 1386 | Parcel data, reply; |
| 1387 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1388 | data.writeUint32(static_cast<uint32_t>(strategy)); |
| 1389 | status_t status = device.writeToParcel(&data); |
| 1390 | if (status != NO_ERROR) { |
| 1391 | return BAD_VALUE; |
| 1392 | } |
| 1393 | status = remote()->transact(SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
| 1394 | data, &reply); |
| 1395 | if (status != NO_ERROR) { |
| 1396 | return status; |
| 1397 | } |
| 1398 | return static_cast<status_t>(reply.readInt32()); |
| 1399 | } |
| 1400 | |
| 1401 | virtual status_t removePreferredDeviceForStrategy(product_strategy_t strategy) |
| 1402 | { |
| 1403 | Parcel data, reply; |
| 1404 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1405 | data.writeUint32(static_cast<uint32_t>(strategy)); |
| 1406 | status_t status = remote()->transact(REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
| 1407 | data, &reply); |
| 1408 | if (status != NO_ERROR) { |
| 1409 | return status; |
| 1410 | } |
| 1411 | return static_cast<status_t>(reply.readInt32()); |
| 1412 | } |
| 1413 | |
| 1414 | virtual status_t getPreferredDeviceForStrategy(product_strategy_t strategy, |
| 1415 | AudioDeviceTypeAddr &device) |
| 1416 | { |
| 1417 | Parcel data, reply; |
| 1418 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1419 | data.writeUint32(static_cast<uint32_t>(strategy)); |
| 1420 | status_t status = remote()->transact(GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY, |
| 1421 | data, &reply); |
| 1422 | if (status != NO_ERROR) { |
| 1423 | return status; |
| 1424 | } |
| 1425 | status = device.readFromParcel(&reply); |
| 1426 | if (status != NO_ERROR) { |
| 1427 | return status; |
| 1428 | } |
| 1429 | return static_cast<status_t>(reply.readInt32()); |
| 1430 | } |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1431 | |
| 1432 | virtual status_t getDevicesForAttributes(const AudioAttributes &aa, |
| 1433 | AudioDeviceTypeAddrVector *devices) const |
| 1434 | { |
| 1435 | if (devices == nullptr) { |
| 1436 | return BAD_VALUE; |
| 1437 | } |
| 1438 | Parcel data, reply; |
| 1439 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1440 | status_t status = aa.writeToParcel(&data); |
| 1441 | if (status != NO_ERROR) { |
| 1442 | return status; |
| 1443 | } |
| 1444 | status = remote()->transact(GET_DEVICES_FOR_ATTRIBUTES, data, &reply); |
| 1445 | if (status != NO_ERROR) { |
| 1446 | // transaction failed, return error |
| 1447 | return status; |
| 1448 | } |
| 1449 | status = static_cast<status_t>(reply.readInt32()); |
| 1450 | if (status != NO_ERROR) { |
| 1451 | // APM method call failed, return error |
| 1452 | return status; |
| 1453 | } |
| 1454 | |
| 1455 | const size_t numberOfDevices = (size_t)reply.readInt32(); |
| 1456 | for (size_t i = 0; i < numberOfDevices; i++) { |
| 1457 | AudioDeviceTypeAddr device; |
| 1458 | if (device.readFromParcel((Parcel*)&reply) == NO_ERROR) { |
| 1459 | devices->push_back(device); |
| 1460 | } else { |
| 1461 | return FAILED_TRANSACTION; |
| 1462 | } |
| 1463 | } |
| 1464 | return NO_ERROR; |
| 1465 | } |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 1466 | |
| 1467 | virtual void onNewAudioModulesAvailable() |
| 1468 | { |
| 1469 | Parcel data, reply; |
| 1470 | data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor()); |
| 1471 | remote()->transact(AUDIO_MODULES_UPDATED, data, &reply, IBinder::FLAG_ONEWAY); |
| 1472 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1473 | }; |
| 1474 | |
| 1475 | IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService"); |
| 1476 | |
| 1477 | // ---------------------------------------------------------------------- |
| 1478 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1479 | status_t BnAudioPolicyService::onTransact( |
| 1480 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 1481 | { |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1482 | // make sure transactions reserved to AudioFlinger do not come from other processes |
| 1483 | switch (code) { |
| 1484 | case START_OUTPUT: |
| 1485 | case STOP_OUTPUT: |
| 1486 | case RELEASE_OUTPUT: |
| 1487 | case GET_INPUT_FOR_ATTR: |
| 1488 | case START_INPUT: |
| 1489 | case STOP_INPUT: |
| 1490 | case RELEASE_INPUT: |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1491 | case GET_OUTPUT_FOR_EFFECT: |
| 1492 | case REGISTER_EFFECT: |
| 1493 | case UNREGISTER_EFFECT: |
| 1494 | case SET_EFFECT_ENABLED: |
| 1495 | case GET_OUTPUT_FOR_ATTR: |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1496 | case MOVE_EFFECTS_TO_IO: |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1497 | ALOGW("%s: transaction %d received from PID %d", |
| 1498 | __func__, code, IPCThreadState::self()->getCallingPid()); |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1499 | // return status only for non void methods |
| 1500 | switch (code) { |
| 1501 | case RELEASE_OUTPUT: |
| 1502 | case RELEASE_INPUT: |
| 1503 | break; |
| 1504 | default: |
| 1505 | reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION)); |
| 1506 | break; |
| 1507 | } |
| 1508 | return OK; |
Eric Laurent | b1cc36b | 2017-12-11 12:14:16 -0800 | [diff] [blame] | 1509 | default: |
| 1510 | break; |
| 1511 | } |
| 1512 | |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1513 | // make sure the following transactions come from system components |
| 1514 | switch (code) { |
| 1515 | case SET_DEVICE_CONNECTION_STATE: |
| 1516 | case HANDLE_DEVICE_CONFIG_CHANGE: |
| 1517 | case SET_PHONE_STATE: |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 1518 | //FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available |
| 1519 | // case SET_FORCE_USE: |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1520 | case INIT_STREAM_VOLUME: |
| 1521 | case SET_STREAM_VOLUME: |
| 1522 | case REGISTER_POLICY_MIXES: |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1523 | case SET_MASTER_MONO: |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1524 | case GET_SURROUND_FORMATS: |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1525 | case SET_SURROUND_FORMAT_ENABLED: |
| 1526 | case SET_ASSISTANT_UID: |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1527 | case SET_A11Y_SERVICES_UIDS: |
| 1528 | case SET_UID_DEVICE_AFFINITY: |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1529 | case REMOVE_UID_DEVICE_AFFINITY: |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1530 | case SET_USERID_DEVICE_AFFINITY: |
| 1531 | case REMOVE_USERID_DEVICE_AFFINITY: |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1532 | case GET_OFFLOAD_FORMATS_A2DP: |
| 1533 | case LIST_AUDIO_VOLUME_GROUPS: |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1534 | case GET_VOLUME_GROUP_FOR_ATTRIBUTES: |
Ytai Ben-Tsvi | a32e601 | 2019-10-28 15:39:16 -0700 | [diff] [blame] | 1535 | case ACQUIRE_SOUNDTRIGGER_SESSION: |
| 1536 | case RELEASE_SOUNDTRIGGER_SESSION: |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1537 | case SET_RTT_ENABLED: |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1538 | case IS_CALL_SCREEN_MODE_SUPPORTED: |
| 1539 | case SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1540 | case SET_SUPPORTED_SYSTEM_USAGES: |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1541 | case REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1542 | case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: |
jiabin | 140a34f | 2019-12-23 11:17:25 -0800 | [diff] [blame] | 1543 | case GET_DEVICES_FOR_ATTRIBUTES: |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 1544 | case SET_ALLOWED_CAPTURE_POLICY: |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame^] | 1545 | case AUDIO_MODULES_UPDATED: |
| 1546 | case SET_CURRENT_IME_UID: { |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1547 | if (!isServiceUid(IPCThreadState::self()->getCallingUid())) { |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1548 | ALOGW("%s: transaction %d received from PID %d unauthorized UID %d", |
| 1549 | __func__, code, IPCThreadState::self()->getCallingPid(), |
| 1550 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | ef92bff | 2018-04-26 10:44:50 -0700 | [diff] [blame] | 1551 | reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION)); |
| 1552 | return OK; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1553 | } |
Eric Laurent | 96c7eed | 2018-03-26 17:57:01 -0700 | [diff] [blame] | 1554 | } break; |
Eric Laurent | 4980df2 | 2018-01-26 18:04:09 -0800 | [diff] [blame] | 1555 | default: |
| 1556 | break; |
| 1557 | } |
| 1558 | |
Eric Laurent | 39b09b5 | 2018-06-29 12:24:40 -0700 | [diff] [blame] | 1559 | std::string tag("IAudioPolicyService command " + std::to_string(code)); |
| 1560 | TimeCheck check(tag.c_str()); |
Eric Laurent | 3528c93 | 2018-02-23 17:17:22 -0800 | [diff] [blame] | 1561 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1562 | switch (code) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1563 | case SET_DEVICE_CONNECTION_STATE: { |
| 1564 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1565 | audio_devices_t device = |
| 1566 | static_cast <audio_devices_t>(data.readInt32()); |
| 1567 | audio_policy_dev_state_t state = |
| 1568 | static_cast <audio_policy_dev_state_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1569 | const char *device_address = data.readCString(); |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 1570 | const char *device_name = data.readCString(); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1571 | audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32()); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1572 | if (device_address == nullptr || device_name == nullptr) { |
| 1573 | ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device); |
| 1574 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 1575 | } else { |
| 1576 | reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device, |
| 1577 | state, |
| 1578 | device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1579 | device_name, |
| 1580 | codecFormat))); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1581 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1582 | return NO_ERROR; |
| 1583 | } break; |
| 1584 | |
| 1585 | case GET_DEVICE_CONNECTION_STATE: { |
| 1586 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1587 | audio_devices_t device = |
| 1588 | static_cast<audio_devices_t> (data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1589 | const char *device_address = data.readCString(); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1590 | if (device_address == nullptr) { |
| 1591 | ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device); |
| 1592 | reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
| 1593 | } else { |
| 1594 | reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device, |
| 1595 | device_address))); |
| 1596 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1597 | return NO_ERROR; |
| 1598 | } break; |
| 1599 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 1600 | case HANDLE_DEVICE_CONFIG_CHANGE: { |
| 1601 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1602 | audio_devices_t device = |
| 1603 | static_cast <audio_devices_t>(data.readInt32()); |
| 1604 | const char *device_address = data.readCString(); |
| 1605 | const char *device_name = data.readCString(); |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1606 | audio_format_t codecFormat = |
| 1607 | static_cast <audio_format_t>(data.readInt32()); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1608 | if (device_address == nullptr || device_name == nullptr) { |
| 1609 | ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device); |
| 1610 | reply->writeInt32(static_cast<int32_t> (BAD_VALUE)); |
| 1611 | } else { |
| 1612 | reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device, |
| 1613 | device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1614 | device_name, |
| 1615 | codecFormat))); |
Pavlin Radoslavov | c694ff4 | 2017-01-09 23:27:29 -0800 | [diff] [blame] | 1616 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 1617 | return NO_ERROR; |
| 1618 | } break; |
| 1619 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1620 | case SET_PHONE_STATE: { |
| 1621 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1622 | reply->writeInt32(static_cast <uint32_t>(setPhoneState( |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 1623 | (audio_mode_t) data.readInt32(), |
| 1624 | (uid_t) data.readInt32()))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1625 | return NO_ERROR; |
| 1626 | } break; |
| 1627 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1628 | case SET_FORCE_USE: { |
| 1629 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1630 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 1631 | data.readInt32()); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1632 | audio_policy_forced_cfg_t config = |
| 1633 | static_cast <audio_policy_forced_cfg_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1634 | reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config))); |
| 1635 | return NO_ERROR; |
| 1636 | } break; |
| 1637 | |
| 1638 | case GET_FORCE_USE: { |
| 1639 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1640 | audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>( |
| 1641 | data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1642 | reply->writeInt32(static_cast <uint32_t>(getForceUse(usage))); |
| 1643 | return NO_ERROR; |
| 1644 | } break; |
| 1645 | |
| 1646 | case GET_OUTPUT: { |
| 1647 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1648 | audio_stream_type_t stream = |
| 1649 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 1650 | audio_io_handle_t output = getOutput(stream); |
Eric Laurent | fa2877b | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 1651 | reply->writeInt32(static_cast <int>(output)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1652 | return NO_ERROR; |
| 1653 | } break; |
| 1654 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1655 | case GET_OUTPUT_FOR_ATTR: { |
| 1656 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1657 | audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER; |
| 1658 | status_t status = data.read(&attr, sizeof(audio_attributes_t)); |
| 1659 | if (status != NO_ERROR) { |
| 1660 | return status; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1661 | } |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1662 | sanetizeAudioAttributes(&attr); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1663 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 1664 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 1665 | bool hasStream = data.readInt32() != 0; |
| 1666 | if (hasStream) { |
| 1667 | stream = (audio_stream_type_t)data.readInt32(); |
| 1668 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 1669 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 1670 | uid_t uid = (uid_t)data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1671 | audio_config_t config; |
| 1672 | memset(&config, 0, sizeof(audio_config_t)); |
| 1673 | data.read(&config, sizeof(audio_config_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1674 | audio_output_flags_t flags = |
| 1675 | static_cast <audio_output_flags_t>(data.readInt32()); |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 1676 | audio_port_handle_t selectedDeviceId = data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1677 | audio_port_handle_t portId = (audio_port_handle_t)data.readInt32(); |
Robert Shih | a946d84 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 1678 | audio_io_handle_t output = 0; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1679 | std::vector<audio_io_handle_t> secondaryOutputs; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1680 | status = getOutputForAttr(&attr, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 1681 | &output, session, &stream, pid, uid, |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 1682 | &config, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1683 | flags, &selectedDeviceId, &portId, &secondaryOutputs); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1684 | reply->writeInt32(status); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 1685 | status = reply->write(&attr, sizeof(audio_attributes_t)); |
| 1686 | if (status != NO_ERROR) { |
| 1687 | return status; |
| 1688 | } |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1689 | reply->writeInt32(output); |
| 1690 | reply->writeInt32(stream); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1691 | reply->writeInt32(selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1692 | reply->writeInt32(portId); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1693 | reply->writeInt32(secondaryOutputs.size()); |
| 1694 | return reply->write(secondaryOutputs.data(), |
| 1695 | secondaryOutputs.size() * sizeof(audio_io_handle_t)); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1696 | } break; |
| 1697 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1698 | case START_OUTPUT: { |
| 1699 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1700 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1701 | reply->writeInt32(static_cast <uint32_t>(startOutput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1702 | return NO_ERROR; |
| 1703 | } break; |
| 1704 | |
| 1705 | case STOP_OUTPUT: { |
| 1706 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1707 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1708 | reply->writeInt32(static_cast <uint32_t>(stopOutput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1709 | return NO_ERROR; |
| 1710 | } break; |
| 1711 | |
| 1712 | case RELEASE_OUTPUT: { |
| 1713 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1714 | const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1715 | releaseOutput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1716 | return NO_ERROR; |
| 1717 | } break; |
| 1718 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1719 | case GET_INPUT_FOR_ATTR: { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1720 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1721 | audio_attributes_t attr = {}; |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1722 | data.read(&attr, sizeof(audio_attributes_t)); |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 1723 | sanetizeAudioAttributes(&attr); |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 1724 | audio_io_handle_t input = (audio_io_handle_t)data.readInt32(); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 1725 | audio_unique_id_t riid = (audio_unique_id_t)data.readInt32(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1726 | audio_session_t session = (audio_session_t)data.readInt32(); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 1727 | pid_t pid = (pid_t)data.readInt32(); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 1728 | uid_t uid = (uid_t)data.readInt32(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1729 | const String16 opPackageName = data.readString16(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1730 | audio_config_base_t config; |
| 1731 | memset(&config, 0, sizeof(audio_config_base_t)); |
| 1732 | data.read(&config, sizeof(audio_config_base_t)); |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 1733 | audio_input_flags_t flags = (audio_input_flags_t) data.readInt32(); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 1734 | audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32(); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1735 | audio_port_handle_t portId = (audio_port_handle_t)data.readInt32(); |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 1736 | status_t status = getInputForAttr(&attr, &input, riid, session, pid, uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1737 | opPackageName, &config, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1738 | flags, &selectedDeviceId, &portId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1739 | reply->writeInt32(status); |
| 1740 | if (status == NO_ERROR) { |
| 1741 | reply->writeInt32(input); |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 1742 | reply->writeInt32(selectedDeviceId); |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1743 | reply->writeInt32(portId); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1744 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1745 | return NO_ERROR; |
| 1746 | } break; |
| 1747 | |
| 1748 | case START_INPUT: { |
| 1749 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1750 | 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] | 1751 | status_t status = startInput(portId); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1752 | reply->writeInt32(static_cast <uint32_t>(status)); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1753 | return NO_ERROR; |
| 1754 | } break; |
| 1755 | |
| 1756 | case STOP_INPUT: { |
| 1757 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1758 | audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1759 | reply->writeInt32(static_cast <uint32_t>(stopInput(portId))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1760 | return NO_ERROR; |
| 1761 | } break; |
| 1762 | |
| 1763 | case RELEASE_INPUT: { |
| 1764 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1765 | audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32()); |
| 1766 | releaseInput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1767 | return NO_ERROR; |
| 1768 | } break; |
| 1769 | |
| 1770 | case INIT_STREAM_VOLUME: { |
| 1771 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1772 | audio_stream_type_t stream = |
| 1773 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1774 | int indexMin = data.readInt32(); |
| 1775 | int indexMax = data.readInt32(); |
| 1776 | reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax))); |
| 1777 | return NO_ERROR; |
| 1778 | } break; |
| 1779 | |
| 1780 | case SET_STREAM_VOLUME: { |
| 1781 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1782 | audio_stream_type_t stream = |
| 1783 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1784 | int index = data.readInt32(); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1785 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1786 | reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, |
| 1787 | index, |
| 1788 | device))); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1789 | return NO_ERROR; |
| 1790 | } break; |
| 1791 | |
| 1792 | case GET_STREAM_VOLUME: { |
| 1793 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1794 | audio_stream_type_t stream = |
| 1795 | static_cast <audio_stream_type_t>(data.readInt32()); |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1796 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
Robert Shih | 8923543 | 2015-09-02 16:46:59 -0700 | [diff] [blame] | 1797 | int index = 0; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1798 | status_t status = getStreamVolumeIndex(stream, &index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1799 | reply->writeInt32(index); |
| 1800 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1801 | return NO_ERROR; |
| 1802 | } break; |
| 1803 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1804 | case GET_STRATEGY_FOR_STREAM: { |
| 1805 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1806 | audio_stream_type_t stream = |
| 1807 | static_cast <audio_stream_type_t>(data.readInt32()); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1808 | reply->writeUint32(getStrategyForStream(stream)); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1809 | return NO_ERROR; |
| 1810 | } break; |
| 1811 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1812 | case SET_VOLUME_ATTRIBUTES: { |
| 1813 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1814 | audio_attributes_t attributes = {}; |
| 1815 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1816 | if (status != NO_ERROR) { |
| 1817 | return status; |
| 1818 | } |
| 1819 | int index = data.readInt32(); |
| 1820 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1821 | |
| 1822 | reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes, |
| 1823 | index, device))); |
| 1824 | return NO_ERROR; |
| 1825 | } break; |
| 1826 | |
| 1827 | case GET_VOLUME_ATTRIBUTES: { |
| 1828 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1829 | audio_attributes_t attributes = {}; |
| 1830 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1831 | if (status != NO_ERROR) { |
| 1832 | return status; |
| 1833 | } |
| 1834 | audio_devices_t device = static_cast <audio_devices_t>(data.readInt32()); |
| 1835 | |
| 1836 | int index = 0; |
| 1837 | status = getVolumeIndexForAttributes(attributes, index, device); |
| 1838 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1839 | if (status == NO_ERROR) { |
| 1840 | reply->writeInt32(index); |
| 1841 | } |
| 1842 | return NO_ERROR; |
| 1843 | } break; |
| 1844 | |
| 1845 | case GET_MIN_VOLUME_FOR_ATTRIBUTES: { |
| 1846 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1847 | audio_attributes_t attributes = {}; |
| 1848 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1849 | if (status != NO_ERROR) { |
| 1850 | return status; |
| 1851 | } |
| 1852 | |
| 1853 | int index = 0; |
| 1854 | status = getMinVolumeIndexForAttributes(attributes, index); |
| 1855 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1856 | if (status == NO_ERROR) { |
| 1857 | reply->writeInt32(index); |
| 1858 | } |
| 1859 | return NO_ERROR; |
| 1860 | } break; |
| 1861 | |
| 1862 | case GET_MAX_VOLUME_FOR_ATTRIBUTES: { |
| 1863 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1864 | audio_attributes_t attributes = {}; |
| 1865 | status_t status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 1866 | if (status != NO_ERROR) { |
| 1867 | return status; |
| 1868 | } |
| 1869 | |
| 1870 | int index = 0; |
| 1871 | status = getMaxVolumeIndexForAttributes(attributes, index); |
| 1872 | reply->writeInt32(static_cast <uint32_t>(status)); |
| 1873 | if (status == NO_ERROR) { |
| 1874 | reply->writeInt32(index); |
| 1875 | } |
| 1876 | return NO_ERROR; |
| 1877 | } break; |
| 1878 | |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1879 | case GET_DEVICES_FOR_STREAM: { |
| 1880 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1881 | audio_stream_type_t stream = |
| 1882 | static_cast <audio_stream_type_t>(data.readInt32()); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1883 | reply->writeInt32(static_cast <int>(getDevicesForStream(stream))); |
| 1884 | return NO_ERROR; |
| 1885 | } break; |
| 1886 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1887 | case GET_OUTPUT_FOR_EFFECT: { |
| 1888 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1889 | effect_descriptor_t desc = {}; |
| 1890 | if (data.read(&desc, sizeof(desc)) != NO_ERROR) { |
| 1891 | android_errorWriteLog(0x534e4554, "73126106"); |
| 1892 | } |
| 1893 | (void)sanitizeEffectDescriptor(&desc); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1894 | audio_io_handle_t output = getOutputForEffect(&desc); |
| 1895 | reply->writeInt32(static_cast <int>(output)); |
| 1896 | return NO_ERROR; |
| 1897 | } break; |
| 1898 | |
| 1899 | case REGISTER_EFFECT: { |
| 1900 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1901 | effect_descriptor_t desc = {}; |
| 1902 | if (data.read(&desc, sizeof(desc)) != NO_ERROR) { |
| 1903 | android_errorWriteLog(0x534e4554, "73126106"); |
| 1904 | } |
| 1905 | (void)sanitizeEffectDescriptor(&desc); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1906 | audio_io_handle_t io = data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1907 | uint32_t strategy = data.readInt32(); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1908 | audio_session_t session = (audio_session_t) data.readInt32(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1909 | int id = data.readInt32(); |
| 1910 | reply->writeInt32(static_cast <int32_t>(registerEffect(&desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1911 | io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1912 | strategy, |
| 1913 | session, |
| 1914 | id))); |
| 1915 | return NO_ERROR; |
| 1916 | } break; |
| 1917 | |
| 1918 | case UNREGISTER_EFFECT: { |
| 1919 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1920 | int id = data.readInt32(); |
| 1921 | reply->writeInt32(static_cast <int32_t>(unregisterEffect(id))); |
| 1922 | return NO_ERROR; |
| 1923 | } break; |
| 1924 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1925 | case SET_EFFECT_ENABLED: { |
| 1926 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1927 | int id = data.readInt32(); |
| 1928 | bool enabled = static_cast <bool>(data.readInt32()); |
| 1929 | reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled))); |
| 1930 | return NO_ERROR; |
| 1931 | } break; |
| 1932 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1933 | case MOVE_EFFECTS_TO_IO: { |
| 1934 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1935 | std::vector<int> ids; |
| 1936 | int32_t size; |
| 1937 | status_t status = data.readInt32(&size); |
| 1938 | if (status != NO_ERROR) { |
| 1939 | return status; |
| 1940 | } |
| 1941 | if (size > MAX_ITEMS_PER_LIST) { |
| 1942 | return BAD_VALUE; |
| 1943 | } |
| 1944 | for (int32_t i = 0; i < size; i++) { |
| 1945 | int id; |
| 1946 | status = data.readInt32(&id); |
| 1947 | if (status != NO_ERROR) { |
| 1948 | return status; |
| 1949 | } |
| 1950 | ids.push_back(id); |
| 1951 | } |
| 1952 | |
| 1953 | audio_io_handle_t io = data.readInt32(); |
| 1954 | reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io))); |
| 1955 | return NO_ERROR; |
| 1956 | } break; |
| 1957 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1958 | case IS_STREAM_ACTIVE: { |
| 1959 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1960 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1961 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1962 | reply->writeInt32( isStreamActive(stream, inPastMs) ); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1963 | return NO_ERROR; |
| 1964 | } break; |
| 1965 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1966 | case IS_STREAM_ACTIVE_REMOTELY: { |
| 1967 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1968 | audio_stream_type_t stream = (audio_stream_type_t) data.readInt32(); |
| 1969 | uint32_t inPastMs = (uint32_t)data.readInt32(); |
Eric Laurent | ebcb254 | 2014-03-05 18:30:08 -0800 | [diff] [blame] | 1970 | reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) ); |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1971 | return NO_ERROR; |
| 1972 | } break; |
| 1973 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1974 | case IS_SOURCE_ACTIVE: { |
| 1975 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 1976 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 1977 | reply->writeInt32( isSourceActive(source)); |
| 1978 | return NO_ERROR; |
| 1979 | } |
| 1980 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1981 | case QUERY_DEFAULT_PRE_PROCESSING: { |
| 1982 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1983 | audio_session_t audioSession = (audio_session_t) data.readInt32(); |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1984 | uint32_t count = data.readInt32(); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1985 | if (count > AudioEffect::kMaxPreProcessing) { |
| 1986 | count = AudioEffect::kMaxPreProcessing; |
| 1987 | } |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1988 | uint32_t retCount = count; |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 1989 | effect_descriptor_t *descriptors = new effect_descriptor_t[count]{}; |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1990 | status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount); |
| 1991 | reply->writeInt32(status); |
| 1992 | if (status != NO_ERROR && status != NO_MEMORY) { |
| 1993 | retCount = 0; |
| 1994 | } |
| 1995 | reply->writeInt32(retCount); |
Eric Laurent | 74adca9 | 2014-11-05 12:15:36 -0800 | [diff] [blame] | 1996 | if (retCount != 0) { |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 1997 | if (retCount < count) { |
| 1998 | count = retCount; |
| 1999 | } |
| 2000 | reply->write(descriptors, sizeof(effect_descriptor_t) * count); |
| 2001 | } |
| 2002 | delete[] descriptors; |
| 2003 | return status; |
| 2004 | } |
| 2005 | |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 2006 | case IS_OFFLOAD_SUPPORTED: { |
| 2007 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2008 | audio_offload_info_t info = {}; |
Richard Fitzgerald | b1a270d | 2013-05-14 12:12:21 +0100 | [diff] [blame] | 2009 | data.read(&info, sizeof(audio_offload_info_t)); |
| 2010 | bool isSupported = isOffloadSupported(info); |
| 2011 | reply->writeInt32(isSupported); |
| 2012 | return NO_ERROR; |
| 2013 | } |
| 2014 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 2015 | case IS_DIRECT_OUTPUT_SUPPORTED: { |
| 2016 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2017 | audio_config_base_t config = {}; |
| 2018 | audio_attributes_t attributes = {}; |
| 2019 | status_t status = data.read(&config, sizeof(audio_config_base_t)); |
| 2020 | if (status != NO_ERROR) return status; |
| 2021 | status = data.read(&attributes, sizeof(audio_attributes_t)); |
| 2022 | if (status != NO_ERROR) return status; |
| 2023 | reply->writeInt32(isDirectOutputSupported(config, attributes)); |
| 2024 | return NO_ERROR; |
| 2025 | } |
| 2026 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2027 | case LIST_AUDIO_PORTS: { |
| 2028 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2029 | audio_port_role_t role = (audio_port_role_t)data.readInt32(); |
| 2030 | audio_port_type_t type = (audio_port_type_t)data.readInt32(); |
| 2031 | unsigned int numPortsReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2032 | if (numPortsReq > MAX_ITEMS_PER_LIST) { |
| 2033 | numPortsReq = MAX_ITEMS_PER_LIST; |
| 2034 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2035 | unsigned int numPorts = numPortsReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2036 | struct audio_port *ports = |
| 2037 | (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2038 | if (ports == NULL) { |
| 2039 | reply->writeInt32(NO_MEMORY); |
| 2040 | reply->writeInt32(0); |
| 2041 | return NO_ERROR; |
| 2042 | } |
| 2043 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2044 | status_t status = listAudioPorts(role, type, &numPorts, ports, &generation); |
| 2045 | reply->writeInt32(status); |
| 2046 | reply->writeInt32(numPorts); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2047 | |
| 2048 | if (status == NO_ERROR) { |
| 2049 | if (numPortsReq > numPorts) { |
| 2050 | numPortsReq = numPorts; |
| 2051 | } |
| 2052 | reply->write(ports, numPortsReq * sizeof(struct audio_port)); |
| 2053 | reply->writeInt32(generation); |
| 2054 | } |
| 2055 | free(ports); |
| 2056 | return NO_ERROR; |
| 2057 | } |
| 2058 | |
| 2059 | case GET_AUDIO_PORT: { |
| 2060 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 2061 | struct audio_port port = {}; |
| 2062 | if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) { |
| 2063 | ALOGE("b/23912202"); |
| 2064 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2065 | status_t status = getAudioPort(&port); |
| 2066 | reply->writeInt32(status); |
| 2067 | if (status == NO_ERROR) { |
| 2068 | reply->write(&port, sizeof(struct audio_port)); |
| 2069 | } |
| 2070 | return NO_ERROR; |
| 2071 | } |
| 2072 | |
| 2073 | case CREATE_AUDIO_PATCH: { |
| 2074 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2075 | struct audio_patch patch = {}; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2076 | data.read(&patch, sizeof(struct audio_patch)); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2077 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Wei Jia | e995e47 | 2015-09-09 09:48:34 -0700 | [diff] [blame] | 2078 | if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) { |
| 2079 | ALOGE("b/23912202"); |
| 2080 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2081 | status_t status = createAudioPatch(&patch, &handle); |
| 2082 | reply->writeInt32(status); |
| 2083 | if (status == NO_ERROR) { |
| 2084 | reply->write(&handle, sizeof(audio_patch_handle_t)); |
| 2085 | } |
| 2086 | return NO_ERROR; |
| 2087 | } |
| 2088 | |
| 2089 | case RELEASE_AUDIO_PATCH: { |
| 2090 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2091 | audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2092 | data.read(&handle, sizeof(audio_patch_handle_t)); |
| 2093 | status_t status = releaseAudioPatch(handle); |
| 2094 | reply->writeInt32(status); |
| 2095 | return NO_ERROR; |
| 2096 | } |
| 2097 | |
| 2098 | case LIST_AUDIO_PATCHES: { |
| 2099 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2100 | unsigned int numPatchesReq = data.readInt32(); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2101 | if (numPatchesReq > MAX_ITEMS_PER_LIST) { |
| 2102 | numPatchesReq = MAX_ITEMS_PER_LIST; |
| 2103 | } |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2104 | unsigned int numPatches = numPatchesReq; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2105 | struct audio_patch *patches = |
| 2106 | (struct audio_patch *)calloc(numPatchesReq, |
| 2107 | sizeof(struct audio_patch)); |
Eric Laurent | 1d670b1 | 2015-02-06 10:44:24 -0800 | [diff] [blame] | 2108 | if (patches == NULL) { |
| 2109 | reply->writeInt32(NO_MEMORY); |
| 2110 | reply->writeInt32(0); |
| 2111 | return NO_ERROR; |
| 2112 | } |
| 2113 | unsigned int generation; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2114 | status_t status = listAudioPatches(&numPatches, patches, &generation); |
| 2115 | reply->writeInt32(status); |
| 2116 | reply->writeInt32(numPatches); |
| 2117 | if (status == NO_ERROR) { |
| 2118 | if (numPatchesReq > numPatches) { |
| 2119 | numPatchesReq = numPatches; |
| 2120 | } |
| 2121 | reply->write(patches, numPatchesReq * sizeof(struct audio_patch)); |
| 2122 | reply->writeInt32(generation); |
| 2123 | } |
| 2124 | free(patches); |
| 2125 | return NO_ERROR; |
| 2126 | } |
| 2127 | |
| 2128 | case SET_AUDIO_PORT_CONFIG: { |
| 2129 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2130 | struct audio_port_config config = {}; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2131 | data.read(&config, sizeof(struct audio_port_config)); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2132 | (void)sanitizeAudioPortConfig(&config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2133 | status_t status = setAudioPortConfig(&config); |
| 2134 | reply->writeInt32(status); |
| 2135 | return NO_ERROR; |
| 2136 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2137 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2138 | case REGISTER_CLIENT: { |
| 2139 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2140 | sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>( |
| 2141 | data.readStrongBinder()); |
| 2142 | registerClient(client); |
| 2143 | return NO_ERROR; |
| 2144 | } break; |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 2145 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2146 | case SET_AUDIO_PORT_CALLBACK_ENABLED: { |
| 2147 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2148 | setAudioPortCallbacksEnabled(data.readInt32() == 1); |
| 2149 | return NO_ERROR; |
| 2150 | } break; |
| 2151 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2152 | case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: { |
| 2153 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2154 | setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1); |
| 2155 | return NO_ERROR; |
| 2156 | } break; |
| 2157 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2158 | case ACQUIRE_SOUNDTRIGGER_SESSION: { |
| 2159 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2160 | audio_session_t session = AUDIO_SESSION_NONE; |
| 2161 | audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE; |
| 2162 | audio_devices_t device = AUDIO_DEVICE_NONE; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2163 | status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device); |
| 2164 | reply->writeInt32(status); |
| 2165 | if (status == NO_ERROR) { |
| 2166 | reply->writeInt32(session); |
| 2167 | reply->writeInt32(ioHandle); |
| 2168 | reply->writeInt32(device); |
| 2169 | } |
| 2170 | return NO_ERROR; |
| 2171 | } break; |
| 2172 | |
| 2173 | case RELEASE_SOUNDTRIGGER_SESSION: { |
| 2174 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 2175 | audio_session_t session = (audio_session_t)data.readInt32(); |
| 2176 | status_t status = releaseSoundTriggerSession(session); |
| 2177 | reply->writeInt32(status); |
| 2178 | return NO_ERROR; |
| 2179 | } break; |
| 2180 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 2181 | case GET_PHONE_STATE: { |
| 2182 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2183 | reply->writeInt32((int32_t)getPhoneState()); |
| 2184 | return NO_ERROR; |
| 2185 | } break; |
| 2186 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 2187 | case REGISTER_POLICY_MIXES: { |
| 2188 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2189 | bool registration = data.readInt32() == 1; |
| 2190 | Vector<AudioMix> mixes; |
| 2191 | size_t size = (size_t)data.readInt32(); |
| 2192 | if (size > MAX_MIXES_PER_POLICY) { |
| 2193 | size = MAX_MIXES_PER_POLICY; |
| 2194 | } |
| 2195 | for (size_t i = 0; i < size; i++) { |
| 2196 | AudioMix mix; |
| 2197 | if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2198 | mixes.add(mix); |
| 2199 | } |
| 2200 | } |
| 2201 | status_t status = registerPolicyMixes(mixes, registration); |
| 2202 | reply->writeInt32(status); |
| 2203 | return NO_ERROR; |
| 2204 | } break; |
| 2205 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2206 | case START_AUDIO_SOURCE: { |
| 2207 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2208 | struct audio_port_config source = {}; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2209 | data.read(&source, sizeof(struct audio_port_config)); |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2210 | (void)sanitizeAudioPortConfig(&source); |
| 2211 | audio_attributes_t attributes = {}; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2212 | data.read(&attributes, sizeof(audio_attributes_t)); |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 2213 | sanetizeAudioAttributes(&attributes); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2214 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
| 2215 | status_t status = startAudioSource(&source, &attributes, &portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2216 | reply->writeInt32(status); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2217 | reply->writeInt32(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2218 | return NO_ERROR; |
| 2219 | } break; |
| 2220 | |
| 2221 | case STOP_AUDIO_SOURCE: { |
| 2222 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 2223 | audio_port_handle_t portId = (audio_port_handle_t) data.readInt32(); |
| 2224 | status_t status = stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 2225 | reply->writeInt32(status); |
| 2226 | return NO_ERROR; |
| 2227 | } break; |
| 2228 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 2229 | case SET_MASTER_MONO: { |
| 2230 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2231 | bool mono = static_cast<bool>(data.readInt32()); |
| 2232 | status_t status = setMasterMono(mono); |
| 2233 | reply->writeInt32(status); |
| 2234 | return NO_ERROR; |
| 2235 | } break; |
| 2236 | |
| 2237 | case GET_MASTER_MONO: { |
| 2238 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2239 | bool mono; |
| 2240 | status_t status = getMasterMono(&mono); |
| 2241 | reply->writeInt32(status); |
| 2242 | if (status == NO_ERROR) { |
| 2243 | reply->writeInt32(static_cast<int32_t>(mono)); |
| 2244 | } |
| 2245 | return NO_ERROR; |
| 2246 | } break; |
| 2247 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 2248 | case GET_STREAM_VOLUME_DB: { |
| 2249 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2250 | audio_stream_type_t stream = |
| 2251 | static_cast <audio_stream_type_t>(data.readInt32()); |
| 2252 | int index = static_cast <int>(data.readInt32()); |
| 2253 | audio_devices_t device = |
| 2254 | static_cast <audio_devices_t>(data.readUint32()); |
| 2255 | reply->writeFloat(getStreamVolumeDB(stream, index, device)); |
| 2256 | return NO_ERROR; |
| 2257 | } |
| 2258 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 2259 | case GET_SURROUND_FORMATS: { |
| 2260 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2261 | unsigned int numSurroundFormatsReq = data.readUint32(); |
| 2262 | if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) { |
| 2263 | numSurroundFormatsReq = MAX_ITEMS_PER_LIST; |
| 2264 | } |
| 2265 | bool reported = data.readBool(); |
| 2266 | unsigned int numSurroundFormats = numSurroundFormatsReq; |
| 2267 | audio_format_t *surroundFormats = (audio_format_t *)calloc( |
| 2268 | numSurroundFormats, sizeof(audio_format_t)); |
| 2269 | bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool)); |
| 2270 | if (numSurroundFormatsReq > 0 && |
| 2271 | (surroundFormats == NULL || surroundFormatsEnabled == NULL)) { |
| 2272 | free(surroundFormats); |
| 2273 | free(surroundFormatsEnabled); |
| 2274 | reply->writeInt32(NO_MEMORY); |
| 2275 | return NO_ERROR; |
| 2276 | } |
| 2277 | status_t status = getSurroundFormats( |
| 2278 | &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); |
| 2279 | reply->writeInt32(status); |
| 2280 | |
| 2281 | if (status == NO_ERROR) { |
| 2282 | reply->writeUint32(numSurroundFormats); |
| 2283 | if (numSurroundFormatsReq > numSurroundFormats) { |
| 2284 | numSurroundFormatsReq = numSurroundFormats; |
| 2285 | } |
| 2286 | reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t)); |
| 2287 | reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool)); |
| 2288 | } |
| 2289 | free(surroundFormats); |
| 2290 | free(surroundFormatsEnabled); |
| 2291 | return NO_ERROR; |
| 2292 | } |
| 2293 | |
| 2294 | case SET_SURROUND_FORMAT_ENABLED: { |
| 2295 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2296 | audio_format_t audioFormat = (audio_format_t) data.readInt32(); |
| 2297 | bool enabled = data.readBool(); |
| 2298 | status_t status = setSurroundFormatEnabled(audioFormat, enabled); |
| 2299 | reply->writeInt32(status); |
| 2300 | return NO_ERROR; |
| 2301 | } |
| 2302 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 2303 | case GET_OFFLOAD_FORMATS_A2DP: { |
| 2304 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2305 | std::vector<audio_format_t> encodingFormats; |
| 2306 | status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats); |
| 2307 | reply->writeInt32(status); |
| 2308 | if (status != NO_ERROR) { |
| 2309 | return NO_ERROR; |
| 2310 | } |
| 2311 | reply->writeUint32(static_cast<uint32_t>(encodingFormats.size())); |
| 2312 | for (size_t i = 0; i < encodingFormats.size(); i++) |
| 2313 | reply->writeInt32(static_cast<int32_t>(encodingFormats[i])); |
| 2314 | return NO_ERROR; |
| 2315 | } |
| 2316 | |
| 2317 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 2318 | case ADD_STREAM_DEFAULT_EFFECT: { |
| 2319 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2320 | effect_uuid_t type; |
| 2321 | status_t status = data.read(&type, sizeof(effect_uuid_t)); |
| 2322 | if (status != NO_ERROR) { |
| 2323 | return status; |
| 2324 | } |
| 2325 | String16 opPackageName; |
| 2326 | status = data.readString16(&opPackageName); |
| 2327 | if (status != NO_ERROR) { |
| 2328 | return status; |
| 2329 | } |
| 2330 | effect_uuid_t uuid; |
| 2331 | status = data.read(&uuid, sizeof(effect_uuid_t)); |
| 2332 | if (status != NO_ERROR) { |
| 2333 | return status; |
| 2334 | } |
| 2335 | int32_t priority = data.readInt32(); |
| 2336 | audio_usage_t usage = (audio_usage_t) data.readInt32(); |
| 2337 | audio_unique_id_t id = 0; |
| 2338 | reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type, |
| 2339 | opPackageName, |
| 2340 | &uuid, |
| 2341 | priority, |
| 2342 | usage, |
| 2343 | &id))); |
| 2344 | reply->writeInt32(id); |
| 2345 | return NO_ERROR; |
| 2346 | } |
| 2347 | |
| 2348 | case REMOVE_STREAM_DEFAULT_EFFECT: { |
| 2349 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2350 | audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32()); |
| 2351 | reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id))); |
| 2352 | return NO_ERROR; |
| 2353 | } |
| 2354 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 2355 | case ADD_SOURCE_DEFAULT_EFFECT: { |
| 2356 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2357 | effect_uuid_t type; |
| 2358 | status_t status = data.read(&type, sizeof(effect_uuid_t)); |
| 2359 | if (status != NO_ERROR) { |
| 2360 | return status; |
| 2361 | } |
| 2362 | String16 opPackageName; |
| 2363 | status = data.readString16(&opPackageName); |
| 2364 | if (status != NO_ERROR) { |
| 2365 | return status; |
| 2366 | } |
| 2367 | effect_uuid_t uuid; |
| 2368 | status = data.read(&uuid, sizeof(effect_uuid_t)); |
| 2369 | if (status != NO_ERROR) { |
| 2370 | return status; |
| 2371 | } |
| 2372 | int32_t priority = data.readInt32(); |
| 2373 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 2374 | audio_unique_id_t id = 0; |
| 2375 | reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type, |
| 2376 | opPackageName, |
| 2377 | &uuid, |
| 2378 | priority, |
| 2379 | source, |
| 2380 | &id))); |
| 2381 | reply->writeInt32(id); |
| 2382 | return NO_ERROR; |
| 2383 | } |
| 2384 | |
| 2385 | case REMOVE_SOURCE_DEFAULT_EFFECT: { |
| 2386 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2387 | audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32()); |
| 2388 | reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id))); |
| 2389 | return NO_ERROR; |
| 2390 | } |
| 2391 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2392 | case SET_ASSISTANT_UID: { |
| 2393 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2394 | int32_t uid; |
| 2395 | status_t status = data.readInt32(&uid); |
| 2396 | if (status != NO_ERROR) { |
| 2397 | return status; |
| 2398 | } |
| 2399 | status = setAssistantUid(uid); |
| 2400 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2401 | return NO_ERROR; |
| 2402 | } |
| 2403 | |
| 2404 | case SET_A11Y_SERVICES_UIDS: { |
| 2405 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2406 | std::vector<uid_t> uids; |
| 2407 | int32_t size; |
| 2408 | status_t status = data.readInt32(&size); |
| 2409 | if (status != NO_ERROR) { |
| 2410 | return status; |
| 2411 | } |
| 2412 | if (size > MAX_ITEMS_PER_LIST) { |
| 2413 | size = MAX_ITEMS_PER_LIST; |
| 2414 | } |
| 2415 | for (int32_t i = 0; i < size; i++) { |
| 2416 | int32_t uid; |
| 2417 | status = data.readInt32(&uid); |
| 2418 | if (status != NO_ERROR) { |
| 2419 | return status; |
| 2420 | } |
| 2421 | uids.push_back(uid); |
| 2422 | } |
| 2423 | status = setA11yServicesUids(uids); |
| 2424 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2425 | return NO_ERROR; |
| 2426 | } |
| 2427 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2428 | case IS_HAPTIC_PLAYBACK_SUPPORTED: { |
| 2429 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2430 | bool isSupported = isHapticPlaybackSupported(); |
| 2431 | reply->writeBool(isSupported); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 2432 | return NO_ERROR; |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 2433 | } |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 2434 | case SET_UID_DEVICE_AFFINITY: { |
| 2435 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2436 | const uid_t uid = (uid_t) data.readInt32(); |
| 2437 | Vector<AudioDeviceTypeAddr> devices; |
| 2438 | size_t size = (size_t)data.readInt32(); |
| 2439 | for (size_t i = 0; i < size; i++) { |
| 2440 | AudioDeviceTypeAddr device; |
| 2441 | if (device.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2442 | devices.add(device); |
| 2443 | } |
| 2444 | } |
| 2445 | status_t status = setUidDeviceAffinities(uid, devices); |
| 2446 | reply->writeInt32(status); |
| 2447 | return NO_ERROR; |
| 2448 | } |
| 2449 | |
| 2450 | case REMOVE_UID_DEVICE_AFFINITY: { |
| 2451 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2452 | const uid_t uid = (uid_t) data.readInt32(); |
| 2453 | status_t status = removeUidDeviceAffinities(uid); |
| 2454 | reply->writeInt32(status); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2455 | return NO_ERROR; |
| 2456 | } |
| 2457 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 2458 | case SET_USERID_DEVICE_AFFINITY: { |
| 2459 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2460 | const int userId = (int) data.readInt32(); |
| 2461 | Vector<AudioDeviceTypeAddr> devices; |
| 2462 | size_t size = (size_t)data.readInt32(); |
| 2463 | for (size_t i = 0; i < size; i++) { |
| 2464 | AudioDeviceTypeAddr device; |
| 2465 | if (device.readFromParcel((Parcel*)&data) == NO_ERROR) { |
| 2466 | devices.add(device); |
| 2467 | } |
| 2468 | } |
| 2469 | status_t status = setUserIdDeviceAffinities(userId, devices); |
| 2470 | reply->writeInt32(status); |
| 2471 | return NO_ERROR; |
| 2472 | } |
| 2473 | |
| 2474 | case REMOVE_USERID_DEVICE_AFFINITY: { |
| 2475 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2476 | const int userId = (int) data.readInt32(); |
| 2477 | status_t status = removeUserIdDeviceAffinities(userId); |
| 2478 | reply->writeInt32(status); |
| 2479 | return NO_ERROR; |
| 2480 | } |
| 2481 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2482 | case LIST_AUDIO_PRODUCT_STRATEGIES: { |
| 2483 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2484 | AudioProductStrategyVector strategies; |
| 2485 | status_t status = listAudioProductStrategies(strategies); |
| 2486 | reply->writeInt32(status); |
| 2487 | if (status != NO_ERROR) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2488 | return NO_ERROR; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2489 | } |
| 2490 | size_t size = strategies.size(); |
| 2491 | size_t sizePosition = reply->dataPosition(); |
| 2492 | reply->writeInt32(size); |
| 2493 | size_t finalSize = size; |
| 2494 | for (size_t i = 0; i < size; i++) { |
| 2495 | size_t position = reply->dataPosition(); |
| 2496 | if (strategies[i].writeToParcel(reply) != NO_ERROR) { |
| 2497 | reply->setDataPosition(position); |
| 2498 | finalSize--; |
| 2499 | } |
| 2500 | } |
| 2501 | if (size != finalSize) { |
| 2502 | size_t position = reply->dataPosition(); |
| 2503 | reply->setDataPosition(sizePosition); |
| 2504 | reply->writeInt32(finalSize); |
| 2505 | reply->setDataPosition(position); |
| 2506 | } |
| 2507 | return NO_ERROR; |
| 2508 | } |
| 2509 | |
| 2510 | case GET_STRATEGY_FOR_ATTRIBUTES: { |
| 2511 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2512 | AudioAttributes attributes; |
| 2513 | status_t status = attributes.readFromParcel(&data); |
| 2514 | if (status != NO_ERROR) { |
| 2515 | return status; |
| 2516 | } |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2517 | product_strategy_t strategy; |
| 2518 | status = getProductStrategyFromAudioAttributes(attributes, strategy); |
| 2519 | reply->writeInt32(status); |
| 2520 | if (status != NO_ERROR) { |
| 2521 | return NO_ERROR; |
| 2522 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2523 | reply->writeUint32(static_cast<int>(strategy)); |
| 2524 | return NO_ERROR; |
| 2525 | } |
| 2526 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2527 | case LIST_AUDIO_VOLUME_GROUPS: { |
| 2528 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2529 | AudioVolumeGroupVector groups; |
| 2530 | status_t status = listAudioVolumeGroups(groups); |
| 2531 | reply->writeInt32(status); |
| 2532 | if (status != NO_ERROR) { |
| 2533 | return NO_ERROR; |
| 2534 | } |
| 2535 | size_t size = groups.size(); |
| 2536 | size_t sizePosition = reply->dataPosition(); |
| 2537 | reply->writeInt32(size); |
| 2538 | size_t finalSize = size; |
| 2539 | for (size_t i = 0; i < size; i++) { |
| 2540 | size_t position = reply->dataPosition(); |
| 2541 | if (groups[i].writeToParcel(reply) != NO_ERROR) { |
| 2542 | reply->setDataPosition(position); |
| 2543 | finalSize--; |
| 2544 | } |
| 2545 | } |
| 2546 | if (size != finalSize) { |
| 2547 | size_t position = reply->dataPosition(); |
| 2548 | reply->setDataPosition(sizePosition); |
| 2549 | reply->writeInt32(finalSize); |
| 2550 | reply->setDataPosition(position); |
| 2551 | } |
| 2552 | return NO_ERROR; |
| 2553 | } |
| 2554 | |
| 2555 | case GET_VOLUME_GROUP_FOR_ATTRIBUTES: { |
| 2556 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2557 | AudioAttributes attributes; |
| 2558 | status_t status = attributes.readFromParcel(&data); |
| 2559 | if (status != NO_ERROR) { |
| 2560 | return status; |
| 2561 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2562 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2563 | volume_group_t group; |
| 2564 | status = getVolumeGroupFromAudioAttributes(attributes, group); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2565 | if (status != NO_ERROR) { |
| 2566 | return NO_ERROR; |
| 2567 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2568 | |
| 2569 | reply->writeInt32(status); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2570 | reply->writeUint32(static_cast<int>(group)); |
| 2571 | return NO_ERROR; |
| 2572 | } |
| 2573 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 2574 | case SET_SUPPORTED_SYSTEM_USAGES: { |
| 2575 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2576 | std::vector<audio_usage_t> systemUsages; |
| 2577 | |
| 2578 | int32_t size; |
| 2579 | status_t status = data.readInt32(&size); |
| 2580 | if (status != NO_ERROR) { |
| 2581 | return status; |
| 2582 | } |
| 2583 | if (size > MAX_ITEMS_PER_LIST) { |
| 2584 | size = MAX_ITEMS_PER_LIST; |
| 2585 | } |
| 2586 | |
| 2587 | for (int32_t i = 0; i < size; i++) { |
| 2588 | int32_t systemUsageInt; |
| 2589 | status = data.readInt32(&systemUsageInt); |
| 2590 | if (status != NO_ERROR) { |
| 2591 | return status; |
| 2592 | } |
| 2593 | |
| 2594 | audio_usage_t systemUsage = static_cast<audio_usage_t>(systemUsageInt); |
| 2595 | systemUsages.push_back(systemUsage); |
| 2596 | } |
| 2597 | status = setSupportedSystemUsages(systemUsages); |
| 2598 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2599 | return NO_ERROR; |
| 2600 | } |
| 2601 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 2602 | case SET_ALLOWED_CAPTURE_POLICY: { |
| 2603 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2604 | uid_t uid = data.readInt32(); |
| 2605 | audio_flags_mask_t flags = data.readInt32(); |
| 2606 | status_t status = setAllowedCapturePolicy(uid, flags); |
| 2607 | reply->writeInt32(status); |
| 2608 | return NO_ERROR; |
| 2609 | } |
| 2610 | |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2611 | case SET_RTT_ENABLED: { |
| 2612 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2613 | bool enabled = static_cast<bool>(data.readInt32()); |
| 2614 | status_t status = setRttEnabled(enabled); |
| 2615 | reply->writeInt32(status); |
| 2616 | return NO_ERROR; |
| 2617 | } |
| 2618 | |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2619 | case IS_CALL_SCREEN_MODE_SUPPORTED: { |
| 2620 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2621 | bool isAvailable = isCallScreenModeSupported(); |
| 2622 | reply->writeBool(isAvailable); |
| 2623 | return NO_ERROR; |
| 2624 | } |
| 2625 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2626 | case SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2627 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2628 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2629 | AudioDeviceTypeAddr device; |
| 2630 | status_t status = device.readFromParcel((Parcel*)&data); |
| 2631 | if (status != NO_ERROR) { |
| 2632 | return status; |
| 2633 | } |
| 2634 | status = setPreferredDeviceForStrategy(strategy, device); |
| 2635 | reply->writeInt32(status); |
| 2636 | return NO_ERROR; |
| 2637 | } |
| 2638 | |
| 2639 | case REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2640 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2641 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2642 | status_t status = removePreferredDeviceForStrategy(strategy); |
| 2643 | reply->writeInt32(status); |
| 2644 | return NO_ERROR; |
| 2645 | } |
| 2646 | |
| 2647 | case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY: { |
| 2648 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2649 | product_strategy_t strategy = (product_strategy_t) data.readUint32(); |
| 2650 | AudioDeviceTypeAddr device; |
| 2651 | status_t status = getPreferredDeviceForStrategy(strategy, device); |
| 2652 | status_t marshall_status = device.writeToParcel(reply); |
| 2653 | if (marshall_status != NO_ERROR) { |
| 2654 | return marshall_status; |
| 2655 | } |
| 2656 | reply->writeInt32(status); |
| 2657 | return NO_ERROR; |
| 2658 | } |
| 2659 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 2660 | case GET_DEVICES_FOR_ATTRIBUTES: { |
| 2661 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2662 | AudioAttributes attributes; |
| 2663 | status_t status = attributes.readFromParcel(&data); |
| 2664 | if (status != NO_ERROR) { |
| 2665 | return status; |
| 2666 | } |
| 2667 | AudioDeviceTypeAddrVector devices; |
| 2668 | status = getDevicesForAttributes(attributes.getAttributes(), &devices); |
| 2669 | // reply data formatted as: |
| 2670 | // - (int32) method call result from APM |
| 2671 | // - (int32) number of devices (n) if method call returned NO_ERROR |
| 2672 | // - n AudioDeviceTypeAddr if method call returned NO_ERROR |
| 2673 | reply->writeInt32(status); |
| 2674 | if (status != NO_ERROR) { |
| 2675 | return NO_ERROR; |
| 2676 | } |
| 2677 | status = reply->writeInt32(devices.size()); |
| 2678 | if (status != NO_ERROR) { |
| 2679 | return status; |
| 2680 | } |
| 2681 | for (const auto& device : devices) { |
| 2682 | status = device.writeToParcel(reply); |
| 2683 | if (status != NO_ERROR) { |
| 2684 | return status; |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | return NO_ERROR; |
| 2689 | } |
| 2690 | |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 2691 | case AUDIO_MODULES_UPDATED: { |
| 2692 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2693 | onNewAudioModulesAvailable(); |
| 2694 | return NO_ERROR; |
| 2695 | } break; |
| 2696 | |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame^] | 2697 | case SET_CURRENT_IME_UID: { |
| 2698 | CHECK_INTERFACE(IAudioPolicyService, data, reply); |
| 2699 | int32_t uid; |
| 2700 | status_t status = data.readInt32(&uid); |
| 2701 | if (status != NO_ERROR) { |
| 2702 | return status; |
| 2703 | } |
| 2704 | status = setCurrentImeUid(uid); |
| 2705 | reply->writeInt32(static_cast <int32_t>(status)); |
| 2706 | return NO_ERROR; |
| 2707 | } |
| 2708 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2709 | default: |
| 2710 | return BBinder::onTransact(code, data, reply, flags); |
| 2711 | } |
| 2712 | } |
| 2713 | |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2714 | /** returns true if string overflow was prevented by zero termination */ |
| 2715 | template <size_t size> |
| 2716 | static bool preventStringOverflow(char (&s)[size]) { |
| 2717 | if (strnlen(s, size) < size) return false; |
| 2718 | s[size - 1] = '\0'; |
| 2719 | return true; |
| 2720 | } |
| 2721 | |
Kevin Rocard | 39fdbd0 | 2017-11-13 11:15:27 -0800 | [diff] [blame] | 2722 | void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr) |
| 2723 | { |
| 2724 | const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE; |
| 2725 | if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) { |
| 2726 | android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging |
| 2727 | } |
| 2728 | attr->tags[tagsMaxSize - 1] = '\0'; |
| 2729 | } |
| 2730 | |
Andy Hung | b027209 | 2018-04-12 11:06:56 -0700 | [diff] [blame] | 2731 | /** returns BAD_VALUE if sanitization was required. */ |
| 2732 | status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc) |
| 2733 | { |
| 2734 | if (preventStringOverflow(desc->name) |
| 2735 | | /* always */ preventStringOverflow(desc->implementor)) { |
| 2736 | android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging |
| 2737 | return BAD_VALUE; |
| 2738 | } |
| 2739 | return NO_ERROR; |
| 2740 | } |
| 2741 | |
| 2742 | /** returns BAD_VALUE if sanitization was required. */ |
| 2743 | status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config) |
| 2744 | { |
| 2745 | if (config->type == AUDIO_PORT_TYPE_DEVICE && |
| 2746 | preventStringOverflow(config->ext.device.address)) { |
| 2747 | return BAD_VALUE; |
| 2748 | } |
| 2749 | return NO_ERROR; |
| 2750 | } |
| 2751 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2752 | // ---------------------------------------------------------------------------- |
| 2753 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 2754 | } // namespace android |