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