| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #pragma once | 
|  | 18 |  | 
| jiabin | 2336de8 | 2021-04-01 23:52:18 +0000 | [diff] [blame] | 19 | #include <utility> | 
|  | 20 |  | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 21 | #include <AudioPolicyManagerObserver.h> | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 22 | #include <media/AudioProductStrategy.h> | 
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 23 | #include <media/AudioVolumeGroup.h> | 
| Eric Laurent | f5aa58d | 2019-02-22 18:20:11 -0800 | [diff] [blame] | 24 | #include <IVolumeCurves.h> | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 25 | #include <policy.h> | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 26 | #include <Volume.h> | 
|  | 27 | #include <HwModule.h> | 
|  | 28 | #include <DeviceDescriptor.h> | 
|  | 29 | #include <system/audio.h> | 
|  | 30 | #include <system/audio_policy.h> | 
|  | 31 | #include <utils/Errors.h> | 
|  | 32 | #include <utils/Vector.h> | 
|  | 33 |  | 
|  | 34 | namespace android { | 
|  | 35 |  | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 36 | using DeviceStrategyMap = std::map<product_strategy_t, DeviceVector>; | 
|  | 37 | using StrategyVector = std::vector<product_strategy_t>; | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 38 | using VolumeGroupVector = std::vector<volume_group_t>; | 
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 39 | using CapturePresetDevicesRoleMap = | 
| jiabin | 2336de8 | 2021-04-01 23:52:18 +0000 | [diff] [blame] | 40 | std::map<std::pair<audio_source_t, device_role_t>, AudioDeviceTypeAddrVector>; | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 41 |  | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 42 | /** | 
|  | 43 | * This interface is dedicated to the policy manager that a Policy Engine shall implement. | 
|  | 44 | */ | 
| Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 45 | class EngineInterface | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 46 | { | 
|  | 47 | public: | 
|  | 48 | /** | 
|  | 49 | * Checks if the engine was correctly initialized. | 
|  | 50 | * | 
|  | 51 | * @return NO_ERROR if initialization has been done correctly, error code otherwise.. | 
|  | 52 | */ | 
|  | 53 | virtual status_t initCheck() = 0; | 
|  | 54 |  | 
|  | 55 | /** | 
|  | 56 | * Sets the Manager observer that allows the engine to retrieve information on collection | 
|  | 57 | * of devices, streams, HwModules, ... | 
|  | 58 | * | 
|  | 59 | * @param[in] observer handle on the manager. | 
|  | 60 | */ | 
|  | 61 | virtual void setObserver(AudioPolicyManagerObserver *observer) = 0; | 
|  | 62 |  | 
|  | 63 | /** | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 64 | * Set the Telephony Mode. | 
|  | 65 | * | 
|  | 66 | * @param[in] mode: Android Phone state (normal, ringtone, csv, in communication) | 
|  | 67 | * | 
|  | 68 | * @return NO_ERROR if Telephony Mode set correctly, error code otherwise. | 
|  | 69 | */ | 
|  | 70 | virtual status_t setPhoneState(audio_mode_t mode) = 0; | 
|  | 71 |  | 
|  | 72 | /** | 
|  | 73 | * Get the telephony Mode | 
|  | 74 | * | 
|  | 75 | * @return the current telephony mode | 
|  | 76 | */ | 
|  | 77 | virtual audio_mode_t getPhoneState() const = 0; | 
|  | 78 |  | 
|  | 79 | /** | 
|  | 80 | * Set Force Use config for a given usage. | 
|  | 81 | * | 
|  | 82 | * @param[in] usage for which a configuration shall be forced. | 
|  | 83 | * @param[in] config wished to be forced for the given usage. | 
|  | 84 | * | 
| François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 85 | * @return NO_ERROR if the Force Use config was set correctly, error code otherwise (e.g. config | 
|  | 86 | * not allowed a given usage...) | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 87 | */ | 
|  | 88 | virtual status_t setForceUse(audio_policy_force_use_t usage, | 
|  | 89 | audio_policy_forced_cfg_t config) = 0; | 
|  | 90 |  | 
|  | 91 | /** | 
|  | 92 | * Get Force Use config for a given usage. | 
|  | 93 | * | 
|  | 94 | * @param[in] usage for which a configuration shall be forced. | 
|  | 95 | * | 
|  | 96 | * @return config wished to be forced for the given usage. | 
|  | 97 | */ | 
|  | 98 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const = 0; | 
|  | 99 |  | 
|  | 100 | /** | 
|  | 101 | * Set the connection state of device(s). | 
|  | 102 | * | 
|  | 103 | * @param[in] devDesc for which the state has changed. | 
|  | 104 | * @param[in] state of availability of this(these) device(s). | 
|  | 105 | * | 
|  | 106 | * @return NO_ERROR if devices criterion updated correctly, error code otherwise. | 
|  | 107 | */ | 
|  | 108 | virtual status_t setDeviceConnectionState(const android::sp<android::DeviceDescriptor> devDesc, | 
|  | 109 | audio_policy_dev_state_t state) = 0; | 
|  | 110 |  | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 111 | /** | 
|  | 112 | * Get the strategy selected for a given audio attributes. | 
|  | 113 | * | 
|  | 114 | * @param[in] audio attributes to get the selected @product_strategy_t followed by. | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 115 | * @param fallbackOnDefault if true, will return the fallback strategy if the attributes | 
|  | 116 | * are not explicitly assigned to a given strategy. | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 117 | * @return @product_strategy_t to be followed. | 
|  | 118 | */ | 
|  | 119 | virtual product_strategy_t getProductStrategyForAttributes( | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 120 | const audio_attributes_t &attr, bool fallbackOnDefault = true) const = 0; | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 121 |  | 
|  | 122 | /** | 
|  | 123 | * @brief getOutputDevicesForAttributes retrieves the devices to be used for given | 
|  | 124 | * audio attributes. | 
|  | 125 | * @param attributes of the output requesting Device(s) selection | 
|  | 126 | * @param preferedDevice valid reference if a prefered device is requested, nullptr otherwise. | 
|  | 127 | * @param fromCache if true, the device is returned from internal cache, | 
|  | 128 | *                  otherwise it is determined by current state (device connected,phone state, | 
|  | 129 | *                  force use, a2dp output...) | 
|  | 130 | * @return vector of selected device descriptors. | 
|  | 131 | *         Appropriate device for streams handled by the specified audio attributes according | 
|  | 132 | *         to current phone state, forced states, connected devices... | 
|  | 133 | *         if fromCache is true, the device is returned from internal cache, | 
|  | 134 | *         otherwise it is determined by current state (device connected,phone state, force use, | 
|  | 135 | *         a2dp output...) | 
|  | 136 | * This allows to: | 
|  | 137 | *      1 speed up process when the state is stable (when starting or stopping an output) | 
|  | 138 | *      2 access to either current device selection (fromCache == true) or | 
|  | 139 | *      "future" device selection (fromCache == false) when called from a context | 
|  | 140 | *      where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND | 
|  | 141 | *      before manager updates its outputs. | 
|  | 142 | */ | 
|  | 143 | virtual DeviceVector getOutputDevicesForAttributes( | 
|  | 144 | const audio_attributes_t &attributes, | 
|  | 145 | const sp<DeviceDescriptor> &preferedDevice = nullptr, | 
|  | 146 | bool fromCache = false) const = 0; | 
|  | 147 |  | 
|  | 148 | /** | 
|  | 149 | * @brief getOutputDevicesForStream Legacy function retrieving devices from a stream type. | 
|  | 150 | * @param stream type of the output requesting Device(s) selection | 
|  | 151 | * @param fromCache if true, the device is returned from internal cache, | 
|  | 152 | *                  otherwise it is determined by current state (device connected,phone state, | 
|  | 153 | *                  force use, a2dp output...) | 
|  | 154 | * @return appropriate device for streams handled by the specified audio attributes according | 
|  | 155 | *         to current phone state, forced states, connected devices... | 
|  | 156 | *         if fromCache is true, the device is returned from internal cache, | 
|  | 157 | *         otherwise it is determined by current state (device connected,phone state, force use, | 
|  | 158 | *         a2dp output...) | 
|  | 159 | * This allows to: | 
|  | 160 | *      1 speed up process when the state is stable (when starting or stopping an output) | 
|  | 161 | *      2 access to either current device selection (fromCache == true) or | 
|  | 162 | *      "future" device selection (fromCache == false) when called from a context | 
|  | 163 | *      where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND | 
|  | 164 | *      before manager updates its outputs. | 
|  | 165 | */ | 
|  | 166 | virtual DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, | 
|  | 167 | bool fromCache = false) const = 0; | 
|  | 168 |  | 
|  | 169 | /** | 
|  | 170 | * Get the input device selected for given audio attributes. | 
|  | 171 | * | 
|  | 172 | * @param[in] attr audio attributes to consider | 
|  | 173 | * @param[out] mix to be used if a mix has been installed for the given audio attributes. | 
|  | 174 | * @return selected input device for the audio attributes, may be null if error. | 
|  | 175 | */ | 
| Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 176 | virtual sp<DeviceDescriptor> getInputDeviceForAttributes( | 
|  | 177 | const audio_attributes_t &attr, | 
|  | 178 | uid_t uid = 0, | 
|  | 179 | audio_session_t session = AUDIO_SESSION_NONE, | 
|  | 180 | sp<AudioPolicyMix> *mix = nullptr) const = 0; | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 181 |  | 
|  | 182 | /** | 
|  | 183 | * Get the legacy stream type for a given audio attributes. | 
|  | 184 | * | 
|  | 185 | * @param[in] audio attributes to get the associated audio_stream_type_t. | 
|  | 186 | * | 
|  | 187 | * @return audio_stream_type_t associated to the attributes. | 
|  | 188 | */ | 
|  | 189 | virtual audio_stream_type_t getStreamTypeForAttributes( | 
|  | 190 | const audio_attributes_t &attr) const = 0; | 
|  | 191 |  | 
|  | 192 | /** | 
|  | 193 | * @brief getAttributesForStream get the audio attributes from legacy stream type | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 194 | * Attributes returned might only be used to check upon routing decision, not volume decisions. | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 195 | * @param stream to consider | 
|  | 196 | * @return audio attributes matching the legacy stream type | 
|  | 197 | */ | 
|  | 198 | virtual audio_attributes_t getAttributesForStreamType(audio_stream_type_t stream) const = 0; | 
|  | 199 |  | 
|  | 200 | /** | 
|  | 201 | * @brief getStreamTypesForProductStrategy retrieves the list of legacy stream type following | 
|  | 202 | * the given product strategy | 
|  | 203 | * @param ps product strategy to consider | 
|  | 204 | * @return associated legacy Stream Types vector of the given product strategy | 
|  | 205 | */ | 
|  | 206 | virtual StreamTypeVector getStreamTypesForProductStrategy(product_strategy_t ps) const = 0; | 
|  | 207 |  | 
|  | 208 | /** | 
|  | 209 | * @brief getAllAttributesForProductStrategy retrieves all the attributes following the given | 
|  | 210 | * product strategy. Any attributes that "matches" with this one will follow the product | 
|  | 211 | * strategy. | 
|  | 212 | * "matching" means the usage shall match if reference attributes has a defined usage, AND | 
|  | 213 | * content type shall match if reference attributes has a defined content type AND | 
|  | 214 | * flags shall match if reference attributes has defined flags AND | 
|  | 215 | * tags shall match if reference attributes has defined tags. | 
|  | 216 | * @param ps product strategy to consider | 
|  | 217 | * @return vector of product strategy ids, empty if unknown strategy. | 
|  | 218 | */ | 
|  | 219 | virtual AttributesVector getAllAttributesForProductStrategy(product_strategy_t ps) const = 0; | 
|  | 220 |  | 
|  | 221 | /** | 
|  | 222 | * @brief getOrderedAudioProductStrategies | 
|  | 223 | * @return priority ordered product strategies to help the AudioPolicyManager evaluating the | 
|  | 224 | * device selection per output according to the prioritized strategies. | 
|  | 225 | */ | 
|  | 226 | virtual StrategyVector getOrderedProductStrategies() const = 0; | 
|  | 227 |  | 
|  | 228 | /** | 
|  | 229 | * @brief updateDeviceSelectionCache. Device selection for AudioAttribute / Streams is cached | 
|  | 230 | * in the engine in order to speed up process when the audio system is stable. | 
|  | 231 | * When a device is connected, the android mode is changed, engine is notified and can update | 
|  | 232 | * the cache. | 
|  | 233 | * When starting / stopping an output with a stream that can affect notification, the engine | 
|  | 234 | * needs to update the cache upon this function call. | 
|  | 235 | */ | 
|  | 236 | virtual void updateDeviceSelectionCache() = 0; | 
|  | 237 |  | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 238 | /** | 
|  | 239 | * @brief listAudioProductStrategies. Introspection API to retrieve a collection of | 
|  | 240 | * AudioProductStrategyVector that allows to build AudioAttributes according to a | 
|  | 241 | * product_strategy which is just an index. It has also a human readable name to help the | 
|  | 242 | * Car/Oem/AudioManager identiying the use case. | 
|  | 243 | * @param strategies collection. | 
|  | 244 | * @return OK if the list has been retrieved, error code otherwise | 
|  | 245 | */ | 
|  | 246 | virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) const = 0; | 
|  | 247 |  | 
| Eric Laurent | f5aa58d | 2019-02-22 18:20:11 -0800 | [diff] [blame] | 248 | /** | 
|  | 249 | * @brief getVolumeCurvesForAttributes retrieves the Volume Curves interface for the | 
|  | 250 | *        requested Audio Attributes. | 
|  | 251 | * @param attr to be considered | 
|  | 252 | * @return IVolumeCurves interface pointer if found, nullptr otherwise | 
|  | 253 | */ | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 254 | virtual IVolumeCurves *getVolumeCurvesForAttributes(const audio_attributes_t &attr) const = 0; | 
| Eric Laurent | f5aa58d | 2019-02-22 18:20:11 -0800 | [diff] [blame] | 255 |  | 
|  | 256 | /** | 
|  | 257 | * @brief getVolumeCurvesForStreamType retrieves the Volume Curves interface for the stream | 
|  | 258 | * @param stream to be considered | 
|  | 259 | * @return IVolumeCurves interface pointer if found, nullptr otherwise | 
|  | 260 | */ | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 261 | virtual IVolumeCurves *getVolumeCurvesForStreamType(audio_stream_type_t stream) const = 0; | 
|  | 262 |  | 
|  | 263 | /** | 
|  | 264 | * @brief getVolumeCurvesForVolumeGroup retrieves the Volume Curves interface for volume group | 
|  | 265 | * @param group to be considered | 
|  | 266 | * @return IVolumeCurves interface pointer if found, nullptr otherwise | 
|  | 267 | */ | 
|  | 268 | virtual IVolumeCurves *getVolumeCurvesForVolumeGroup(volume_group_t group) const = 0; | 
|  | 269 |  | 
|  | 270 | /** | 
|  | 271 | * @brief getVolumeGroups retrieves the collection of volume groups. | 
|  | 272 | * @return vector of volume groups | 
|  | 273 | */ | 
|  | 274 | virtual VolumeGroupVector getVolumeGroups() const = 0; | 
|  | 275 |  | 
|  | 276 | /** | 
|  | 277 | * @brief getVolumeGroupForAttributes gets the appropriate volume group to be used for a given | 
|  | 278 | * Audio Attributes. | 
|  | 279 | * @param attr to be considered | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 280 | * @param fallbackOnDefault if true, will return the fallback volume group if the attributes | 
|  | 281 | * are not associated to any volume group. | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 282 | * @return volume group associated to the given audio attributes, default group if none | 
|  | 283 | * applicable, VOLUME_GROUP_NONE if no default group defined. | 
|  | 284 | */ | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 285 | virtual volume_group_t getVolumeGroupForAttributes( | 
|  | 286 | const audio_attributes_t &attr, bool fallbackOnDefault = true) const = 0; | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 287 |  | 
|  | 288 | /** | 
|  | 289 | * @brief getVolumeGroupForStreamType gets the appropriate volume group to be used for a given | 
|  | 290 | * legacy stream type | 
|  | 291 | * @param stream type to be considered | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 292 | * @param fallbackOnDefault if true, will return the fallback volume group if the stream type | 
|  | 293 | * is not associated to any volume group. | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 294 | * @return volume group associated to the given stream type, default group if none applicable, | 
|  | 295 | * VOLUME_GROUP_NONE if no default group defined. | 
|  | 296 | */ | 
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 297 | virtual volume_group_t getVolumeGroupForStreamType( | 
|  | 298 | audio_stream_type_t stream, bool fallbackOnDefault = true) const = 0; | 
| François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 299 |  | 
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 300 | /** | 
|  | 301 | * @brief listAudioVolumeGroups introspection API to get the Audio Volume Groups, aka | 
|  | 302 | * former stream aliases in Audio Service, defining volume curves attached to one or more | 
|  | 303 | * Audio Attributes. | 
|  | 304 | * @param groups | 
|  | 305 | * @return NO_ERROR if the volume groups were retrieved successfully, error code otherwise | 
|  | 306 | */ | 
|  | 307 | virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups) const = 0; | 
|  | 308 |  | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 309 | /** | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 310 | * @brief setDevicesRoleForStrategy sets devices role for a strategy when available. To remove | 
|  | 311 | * devices role, removeDevicesRoleForStrategy must be called. When devices role is set | 
|  | 312 | * successfully, previously set devices for the same role and strategy will be removed. | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 313 | * @param strategy the audio strategy whose routing will be affected | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 314 | * @param role the role of the devices for the strategy. All device roles are defined at | 
|  | 315 | *             system/media/audio/include/system/audio_policy.h. DEVICE_ROLE_NONE is invalid | 
|  | 316 | *             for setting. | 
|  | 317 | * @param devices the audio devices to be set | 
|  | 318 | * @return BAD_VALUE if the strategy or role is invalid, | 
|  | 319 | *     or NO_ERROR if the role of the devices for strategy was set | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 320 | */ | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 321 | virtual status_t setDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role, | 
|  | 322 | const AudioDeviceTypeAddrVector &devices) = 0; | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | /** | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 325 | * @brief removeDevicesRoleForStrategy removes the role of device(s) previously set | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 326 | * for the given strategy | 
|  | 327 | * @param strategy the audio strategy whose routing will be affected | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 328 | * @param role the role of the devices for strategy | 
|  | 329 | * @return BAD_VALUE if the strategy or role is invalid, | 
|  | 330 | *     or NO_ERROR if the devices for this role was removed | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 331 | */ | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 332 | virtual status_t removeDevicesRoleForStrategy(product_strategy_t strategy, | 
|  | 333 | device_role_t role) = 0; | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 334 |  | 
|  | 335 | /** | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 336 | * @brief getDevicesForRoleAndStrategy queries which devices have the specified role for the | 
|  | 337 | * specified strategy | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 338 | * @param strategy the strategy to query | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 339 | * @param role the role of the devices to query | 
|  | 340 | * @param devices returns list of devices with matching role for the specified strategy. | 
|  | 341 | *                DEVICE_ROLE_NONE is invalid as input. | 
|  | 342 | * @return BAD_VALUE if the strategy or role is invalid, | 
|  | 343 | *     or NAME_NOT_FOUND if no device for the role and strategy was set | 
|  | 344 | *     or NO_ERROR if the devices parameter contains a list of devices | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 345 | */ | 
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 346 | virtual status_t getDevicesForRoleAndStrategy(product_strategy_t strategy, device_role_t role, | 
|  | 347 | AudioDeviceTypeAddrVector &devices) const = 0; | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 348 |  | 
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 349 | /** | 
|  | 350 | * @brief setDevicesRoleForCapturePreset sets devices role for a capture preset when available. | 
|  | 351 | * To remove devices role, removeDevicesRoleForCapturePreset must be called. Calling | 
|  | 352 | * clearDevicesRoleForCapturePreset will remove all devices as role. When devices role is set | 
|  | 353 | * successfully, previously set devices for the same role and capture preset will be removed. | 
|  | 354 | * @param audioSource the audio capture preset whose routing will be affected | 
|  | 355 | * @param role the role of the devices for the capture preset. All device roles are defined at | 
|  | 356 | *             system/media/audio/include/system/audio_policy.h. DEVICE_ROLE_NONE is invalid | 
|  | 357 | *             for setting. | 
|  | 358 | * @param devices the audio devices to be set | 
|  | 359 | * @return BAD_VALUE if the capture preset or role is invalid, | 
|  | 360 | *     or NO_ERROR if the role of the devices for capture preset was set | 
|  | 361 | */ | 
|  | 362 | virtual status_t setDevicesRoleForCapturePreset(audio_source_t audioSource, device_role_t role, | 
|  | 363 | const AudioDeviceTypeAddrVector &devices) = 0; | 
|  | 364 |  | 
|  | 365 | /** | 
|  | 366 | * @brief addDevicesRoleForCapturePreset adds devices role for a capture preset when available. | 
|  | 367 | * To remove devices role, removeDevicesRoleForCapturePreset must be called. Calling | 
|  | 368 | * clearDevicesRoleForCapturePreset will remove all devices as role. | 
|  | 369 | * @param audioSource the audio capture preset whose routing will be affected | 
|  | 370 | * @param role the role of the devices for the capture preset. All device roles are defined at | 
|  | 371 | *             system/media/audio/include/system/audio_policy.h. DEVICE_ROLE_NONE is invalid | 
|  | 372 | *             for setting. | 
|  | 373 | * @param devices the audio devices to be added | 
|  | 374 | * @return BAD_VALUE if the capture preset or role is invalid, | 
|  | 375 | *     or NO_ERROR if the role of the devices for capture preset was added | 
|  | 376 | */ | 
|  | 377 | virtual status_t addDevicesRoleForCapturePreset(audio_source_t audioSource, device_role_t role, | 
|  | 378 | const AudioDeviceTypeAddrVector &devices) = 0; | 
|  | 379 |  | 
|  | 380 | /** | 
|  | 381 | * @brief removeDevicesRoleForCapturePreset removes the role of device(s) previously set | 
|  | 382 | * for the given capture preset | 
|  | 383 | * @param audioSource the audio capture preset whose routing will be affected | 
|  | 384 | * @param role the role of the devices for the capture preset | 
|  | 385 | * @param devices the devices to be removed | 
|  | 386 | * @return BAD_VALUE if 1) the capture preset is invalid, 2) role is invalid or 3) the list of | 
|  | 387 | *     devices to be removed are not all present as role for a capture preset | 
|  | 388 | *     or NO_ERROR if the devices for this role was removed | 
|  | 389 | */ | 
|  | 390 | virtual status_t removeDevicesRoleForCapturePreset(audio_source_t audioSource, | 
|  | 391 | device_role_t role, const AudioDeviceTypeAddrVector& devices) = 0; | 
|  | 392 |  | 
|  | 393 | /** | 
|  | 394 | * @brief clearDevicesRoleForCapturePreset removes the role of all device(s) previously set | 
|  | 395 | * for the given capture preset | 
|  | 396 | * @param audioSource the audio capture preset whose routing will be affected | 
|  | 397 | * @param role the role of the devices for the capture preset | 
|  | 398 | * @return BAD_VALUE if the capture preset or role is invalid, | 
|  | 399 | *     or NO_ERROR if the devices for this role was removed | 
|  | 400 | */ | 
|  | 401 | virtual status_t clearDevicesRoleForCapturePreset(audio_source_t audioSource, | 
|  | 402 | device_role_t role); | 
|  | 403 |  | 
|  | 404 | /** | 
|  | 405 | * @brief getDevicesForRoleAndCapturePreset queries which devices have the specified role for | 
|  | 406 | * the specified capture preset | 
|  | 407 | * @param audioSource the capture preset to query | 
|  | 408 | * @param role the role of the devices to query | 
|  | 409 | * @param devices returns list of devices with matching role for the specified capture preset. | 
|  | 410 | *                DEVICE_ROLE_NONE is invalid as input. | 
|  | 411 | * @return BAD_VALUE if the capture preset or role is invalid, | 
|  | 412 | *     or NAME_NOT_FOUND if no device for the role and capture preset was set | 
|  | 413 | *     or NO_ERROR if the devices parameter contains a list of devices | 
|  | 414 | */ | 
|  | 415 | virtual status_t getDevicesForRoleAndCapturePreset(audio_source_t audioSource, | 
|  | 416 | device_role_t role, AudioDeviceTypeAddrVector &devices) const = 0; | 
|  | 417 |  | 
| jiabin | 415af49 | 2020-09-17 14:31:20 -0700 | [diff] [blame] | 418 | /** | 
|  | 419 | * @brief getActiveMediaDevices returns which devices will most likely to be used for media | 
|  | 420 | * @param availableDevices all available devices | 
|  | 421 | * @return collection of active devices | 
|  | 422 | */ | 
|  | 423 | virtual DeviceVector getActiveMediaDevices(const DeviceVector& availableDevices) const = 0; | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 424 |  | 
| François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 425 | virtual void dump(String8 *dst) const = 0; | 
|  | 426 |  | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 427 | protected: | 
| Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 428 | virtual ~EngineInterface() {} | 
| François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 429 | }; | 
|  | 430 |  | 
| Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 431 | __attribute__((visibility("default"))) | 
|  | 432 | extern "C" EngineInterface* createEngineInstance(); | 
|  | 433 |  | 
|  | 434 | __attribute__((visibility("default"))) | 
|  | 435 | extern "C" void destroyEngineInstance(EngineInterface *engine); | 
|  | 436 |  | 
| Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 437 | } // namespace android |