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