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