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 | #define LOG_TAG "APM::AudioPolicyEngine" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | //#define VERY_VERBOSE_LOGGING |
| 21 | #ifdef VERY_VERBOSE_LOGGING |
| 22 | #define ALOGVV ALOGV |
| 23 | #else |
| 24 | #define ALOGVV(a...) do { } while(0) |
| 25 | #endif |
| 26 | |
| 27 | #include "Engine.h" |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 28 | #include <android-base/macros.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 29 | #include <AudioPolicyManagerObserver.h> |
jiabin | e128485 | 2019-09-11 10:15:46 -0700 | [diff] [blame] | 30 | #include <PolicyAudioPort.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 31 | #include <IOProfile.h> |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 32 | #include <AudioIODescriptorInterface.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 33 | #include <policy.h> |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 34 | #include <media/AudioContainers.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 35 | #include <utils/String8.h> |
| 36 | #include <utils/Log.h> |
| 37 | |
| 38 | namespace android |
| 39 | { |
| 40 | namespace audio_policy |
| 41 | { |
| 42 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 43 | struct legacy_strategy_map { const char *name; legacy_strategy id; }; |
Mikhail Naganov | f900362 | 2020-03-10 13:15:08 -0700 | [diff] [blame] | 44 | static const std::vector<legacy_strategy_map>& getLegacyStrategy() { |
| 45 | static const std::vector<legacy_strategy_map> legacyStrategy = { |
| 46 | { "STRATEGY_NONE", STRATEGY_NONE }, |
| 47 | { "STRATEGY_MEDIA", STRATEGY_MEDIA }, |
| 48 | { "STRATEGY_PHONE", STRATEGY_PHONE }, |
| 49 | { "STRATEGY_SONIFICATION", STRATEGY_SONIFICATION }, |
| 50 | { "STRATEGY_SONIFICATION_RESPECTFUL", STRATEGY_SONIFICATION_RESPECTFUL }, |
| 51 | { "STRATEGY_DTMF", STRATEGY_DTMF }, |
| 52 | { "STRATEGY_ENFORCED_AUDIBLE", STRATEGY_ENFORCED_AUDIBLE }, |
| 53 | { "STRATEGY_TRANSMITTED_THROUGH_SPEAKER", STRATEGY_TRANSMITTED_THROUGH_SPEAKER }, |
| 54 | { "STRATEGY_ACCESSIBILITY", STRATEGY_ACCESSIBILITY }, |
| 55 | { "STRATEGY_REROUTING", STRATEGY_REROUTING }, |
| 56 | { "STRATEGY_PATCH", STRATEGY_REROUTING }, // boiler to manage stream patch volume |
| 57 | { "STRATEGY_CALL_ASSISTANT", STRATEGY_CALL_ASSISTANT }, |
| 58 | }; |
| 59 | return legacyStrategy; |
| 60 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 61 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 62 | Engine::Engine() |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 63 | { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 64 | auto result = EngineBase::loadAudioPolicyEngineConfig(); |
| 65 | ALOGE_IF(result.nbSkippedElement != 0, |
| 66 | "Policy Engine configuration is partially invalid, skipped %zu elements", |
| 67 | result.nbSkippedElement); |
| 68 | |
Mikhail Naganov | f900362 | 2020-03-10 13:15:08 -0700 | [diff] [blame] | 69 | auto legacyStrategy = getLegacyStrategy(); |
| 70 | for (const auto &strategy : legacyStrategy) { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 71 | mLegacyStrategyMap[getProductStrategyByName(strategy.name)] = strategy.id; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 75 | status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
| 76 | { |
| 77 | switch(usage) { |
| 78 | case AUDIO_POLICY_FORCE_FOR_COMMUNICATION: |
| 79 | if (config != AUDIO_POLICY_FORCE_SPEAKER && config != AUDIO_POLICY_FORCE_BT_SCO && |
| 80 | config != AUDIO_POLICY_FORCE_NONE) { |
| 81 | ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config); |
| 82 | return BAD_VALUE; |
| 83 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 84 | break; |
| 85 | case AUDIO_POLICY_FORCE_FOR_MEDIA: |
| 86 | if (config != AUDIO_POLICY_FORCE_HEADPHONES && config != AUDIO_POLICY_FORCE_BT_A2DP && |
| 87 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 88 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 89 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK && config != AUDIO_POLICY_FORCE_NONE && |
| 90 | config != AUDIO_POLICY_FORCE_NO_BT_A2DP && config != AUDIO_POLICY_FORCE_SPEAKER ) { |
| 91 | ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config); |
| 92 | return BAD_VALUE; |
| 93 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 94 | break; |
| 95 | case AUDIO_POLICY_FORCE_FOR_RECORD: |
| 96 | if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 97 | config != AUDIO_POLICY_FORCE_NONE) { |
| 98 | ALOGW("setForceUse() invalid config %d for FOR_RECORD", config); |
| 99 | return BAD_VALUE; |
| 100 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 101 | break; |
| 102 | case AUDIO_POLICY_FORCE_FOR_DOCK: |
| 103 | if (config != AUDIO_POLICY_FORCE_NONE && config != AUDIO_POLICY_FORCE_BT_CAR_DOCK && |
| 104 | config != AUDIO_POLICY_FORCE_BT_DESK_DOCK && |
| 105 | config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY && |
| 106 | config != AUDIO_POLICY_FORCE_ANALOG_DOCK && |
| 107 | config != AUDIO_POLICY_FORCE_DIGITAL_DOCK) { |
| 108 | ALOGW("setForceUse() invalid config %d for FOR_DOCK", config); |
| 109 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 110 | break; |
| 111 | case AUDIO_POLICY_FORCE_FOR_SYSTEM: |
| 112 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 113 | config != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) { |
| 114 | ALOGW("setForceUse() invalid config %d for FOR_SYSTEM", config); |
| 115 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 116 | break; |
| 117 | case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO: |
| 118 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 119 | config != AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED) { |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 120 | ALOGW("setForceUse() invalid config %d for HDMI_SYSTEM_AUDIO", config); |
| 121 | } |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 122 | break; |
| 123 | case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND: |
| 124 | if (config != AUDIO_POLICY_FORCE_NONE && |
| 125 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER && |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 126 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS && |
| 127 | config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL) { |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 128 | ALOGW("setForceUse() invalid config %d for ENCODED_SURROUND", config); |
| 129 | return BAD_VALUE; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 130 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 131 | break; |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 132 | case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING: |
| 133 | if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_NONE) { |
| 134 | ALOGW("setForceUse() invalid config %d for FOR_VIBRATE_RINGING", config); |
| 135 | return BAD_VALUE; |
| 136 | } |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 137 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 138 | default: |
| 139 | ALOGW("setForceUse() invalid usage %d", usage); |
Phil Burk | 09bc461 | 2016-02-24 15:58:15 -0800 | [diff] [blame] | 140 | break; // TODO return BAD_VALUE? |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 141 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 142 | return EngineBase::setForceUse(usage, config); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 145 | void Engine::filterOutputDevicesForStrategy(legacy_strategy strategy, |
| 146 | DeviceVector& availableOutputDevices, |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 147 | const SwAudioOutputCollection &outputs) const |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 148 | { |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 149 | DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
| 150 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 151 | switch (strategy) { |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 152 | case STRATEGY_SONIFICATION_RESPECTFUL: { |
| 153 | if (!(isInCall() || outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL)))) { |
Jean-Michel Trivi | 6130952 | 2018-01-23 09:58:17 -0800 | [diff] [blame] | 154 | // routing is same as media without the "remote" device |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 155 | availableOutputDevices.remove(availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 156 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 157 | } |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 158 | } break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 159 | case STRATEGY_DTMF: |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 160 | case STRATEGY_PHONE: { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 161 | // Force use of only devices on primary output if: |
| 162 | // - in call AND |
| 163 | // - cannot route from voice call RX OR |
| 164 | // - audio HAL version is < 3.0 and TX device is on the primary HW module |
| 165 | if (getPhoneState() == AUDIO_MODE_IN_CALL) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 166 | audio_devices_t txDevice = getDeviceForInputSource( |
| 167 | AUDIO_SOURCE_VOICE_COMMUNICATION)->type(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 168 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 169 | LOG_ALWAYS_FATAL_IF(primaryOutput == nullptr, "Primary output not found"); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 170 | DeviceVector availPrimaryInputDevices = |
| 171 | availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()); |
Eric Laurent | 58a73fc | 2018-02-21 18:46:13 -0800 | [diff] [blame] | 172 | |
| 173 | // TODO: getPrimaryOutput return only devices from first module in |
| 174 | // audio_policy_configuration.xml, hearing aid is not there, but it's |
| 175 | // a primary device |
| 176 | // FIXME: this is not the right way of solving this problem |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 177 | DeviceVector availPrimaryOutputDevices = availableOutputDevices.getDevicesFromTypes( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 178 | primaryOutput->supportedDevices().types()); |
| 179 | availPrimaryOutputDevices.add( |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 180 | availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_HEARING_AID)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 181 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 182 | if ((availableInputDevices.getDevice(AUDIO_DEVICE_IN_TELEPHONY_RX, |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 183 | String8(""), AUDIO_FORMAT_DEFAULT) == nullptr) || |
| 184 | ((availPrimaryInputDevices.getDevice( |
| 185 | txDevice, String8(""), AUDIO_FORMAT_DEFAULT) != nullptr) && |
| 186 | (primaryOutput->getPolicyAudioPort()->getModuleVersionMajor() < 3))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 187 | availableOutputDevices = availPrimaryOutputDevices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 188 | } |
| 189 | } |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 190 | } break; |
| 191 | case STRATEGY_ACCESSIBILITY: { |
| 192 | // do not route accessibility prompts to a digital output currently configured with a |
| 193 | // compressed format as they would likely not be mixed and dropped. |
| 194 | for (size_t i = 0; i < outputs.size(); i++) { |
| 195 | sp<AudioOutputDescriptor> desc = outputs.valueAt(i); |
| 196 | if (desc->isActive() && !audio_is_linear_pcm(desc->getFormat())) { |
| 197 | availableOutputDevices.remove(desc->devices().getDevicesFromTypes({ |
| 198 | AUDIO_DEVICE_OUT_HDMI, AUDIO_DEVICE_OUT_SPDIF, |
Kuowei Li | 01a686b | 2020-10-27 16:54:39 +0800 | [diff] [blame] | 199 | AUDIO_DEVICE_OUT_HDMI_ARC, AUDIO_DEVICE_OUT_HDMI_EARC})); |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } break; |
| 203 | default: |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 208 | product_strategy_t Engine::remapStrategyFromContext(product_strategy_t strategy, |
| 209 | const SwAudioOutputCollection &outputs) const { |
| 210 | auto legacyStrategy = mLegacyStrategyMap.find(strategy) != end(mLegacyStrategyMap) ? |
| 211 | mLegacyStrategyMap.at(strategy) : STRATEGY_NONE; |
| 212 | |
| 213 | if (isInCall()) { |
| 214 | switch (legacyStrategy) { |
| 215 | case STRATEGY_ACCESSIBILITY: |
| 216 | case STRATEGY_DTMF: |
| 217 | case STRATEGY_MEDIA: |
| 218 | case STRATEGY_SONIFICATION: |
| 219 | case STRATEGY_SONIFICATION_RESPECTFUL: |
| 220 | legacyStrategy = STRATEGY_PHONE; |
| 221 | break; |
| 222 | |
| 223 | default: |
| 224 | return strategy; |
| 225 | } |
| 226 | } else { |
| 227 | switch (legacyStrategy) { |
| 228 | case STRATEGY_SONIFICATION_RESPECTFUL: |
| 229 | case STRATEGY_SONIFICATION: |
| 230 | if (outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_VOICE_CALL))) { |
| 231 | legacyStrategy = STRATEGY_PHONE; |
| 232 | } |
| 233 | break; |
| 234 | |
| 235 | case STRATEGY_ACCESSIBILITY: |
| 236 | if (outputs.isActive(toVolumeSource(AUDIO_STREAM_RING)) || |
| 237 | outputs.isActive(toVolumeSource(AUDIO_STREAM_ALARM))) { |
| 238 | legacyStrategy = STRATEGY_SONIFICATION; |
| 239 | } |
| 240 | break; |
| 241 | |
| 242 | default: |
| 243 | return strategy; |
| 244 | } |
| 245 | } |
| 246 | return getProductStrategyFromLegacy(legacyStrategy); |
| 247 | } |
| 248 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 249 | DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy, |
| 250 | DeviceVector availableOutputDevices, |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 251 | const SwAudioOutputCollection &outputs) const |
| 252 | { |
| 253 | DeviceVector devices; |
| 254 | |
| 255 | switch (strategy) { |
| 256 | |
| 257 | case STRATEGY_TRANSMITTED_THROUGH_SPEAKER: |
| 258 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
| 259 | break; |
| 260 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 261 | case STRATEGY_PHONE: { |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 262 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_HEARING_AID); |
| 263 | if (!devices.isEmpty()) break; |
Eric Laurent | c069759 | 2021-05-10 11:45:22 +0200 | [diff] [blame] | 264 | devices = availableOutputDevices.getFirstDevicesFromTypes( |
| 265 | getLastRemovableMediaDevices()); |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 266 | if (!devices.isEmpty()) break; |
| 267 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE); |
| 268 | } break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 269 | |
| 270 | case STRATEGY_SONIFICATION: |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 271 | case STRATEGY_ENFORCED_AUDIBLE: |
| 272 | // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION |
| 273 | // except: |
| 274 | // - when in call where it doesn't default to STRATEGY_PHONE behavior |
| 275 | // - in countries where not enforced in which case it follows STRATEGY_MEDIA |
| 276 | |
| 277 | if ((strategy == STRATEGY_SONIFICATION) || |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 278 | (getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 279 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 280 | } |
Eric Laurent | a8e0f02 | 2017-01-27 17:41:53 -0800 | [diff] [blame] | 281 | |
| 282 | // if SCO headset is connected and we are told to use it, play ringtone over |
| 283 | // speaker and BT SCO |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 284 | if (!availableOutputDevices.getDevicesFromTypes(getAudioDeviceOutAllScoSet()).isEmpty()) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 285 | DeviceVector devices2; |
| 286 | devices2 = availableOutputDevices.getFirstDevicesFromTypes({ |
| 287 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, |
| 288 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO}); |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 289 | // Use ONLY Bluetooth SCO output when ringing in vibration mode |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 290 | if (!((getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 291 | && (strategy == STRATEGY_ENFORCED_AUDIBLE))) { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 292 | if (getForceUse(AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING) |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 293 | == AUDIO_POLICY_FORCE_BT_SCO) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 294 | if (!devices2.isEmpty()) { |
| 295 | devices = devices2; |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 296 | break; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | // Use both Bluetooth SCO and phone default output when ringing in normal mode |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 301 | if (audio_is_bluetooth_out_sco_device(getPreferredDeviceTypeForLegacyStrategy( |
| 302 | availableOutputDevices, STRATEGY_PHONE))) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 303 | if (strategy == STRATEGY_SONIFICATION) { |
| 304 | devices.replaceDevicesByType( |
| 305 | AUDIO_DEVICE_OUT_SPEAKER, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 306 | availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 307 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)); |
juyuchen | 5fa0aed | 2018-05-16 10:58:37 +0800 | [diff] [blame] | 308 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 309 | if (!devices2.isEmpty()) { |
| 310 | devices.add(devices2); |
Jack He | 96117ae | 2018-02-12 20:52:53 -0800 | [diff] [blame] | 311 | break; |
| 312 | } |
Eric Laurent | a8e0f02 | 2017-01-27 17:41:53 -0800 | [diff] [blame] | 313 | } |
| 314 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 315 | // The second device used for sonification is the same as the device used by media strategy |
Chih-Hung Hsieh | 2b48703 | 2018-09-13 14:16:02 -0700 | [diff] [blame] | 316 | FALLTHROUGH_INTENDED; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 317 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 318 | case STRATEGY_DTMF: |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 319 | case STRATEGY_ACCESSIBILITY: |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 320 | case STRATEGY_SONIFICATION_RESPECTFUL: |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 321 | case STRATEGY_REROUTING: |
| 322 | case STRATEGY_MEDIA: { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 323 | DeviceVector devices2; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 324 | if (strategy != STRATEGY_SONIFICATION) { |
| 325 | // no sonification on remote submix (e.g. WFD) |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 326 | sp<DeviceDescriptor> remoteSubmix; |
| 327 | if ((remoteSubmix = availableOutputDevices.getDevice( |
| 328 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX, String8("0"), |
| 329 | AUDIO_FORMAT_DEFAULT)) != nullptr) { |
| 330 | devices2.add(remoteSubmix); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 331 | } |
| 332 | } |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 333 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 334 | if ((devices2.isEmpty()) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 335 | (getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA) == AUDIO_POLICY_FORCE_SPEAKER)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 336 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 337 | } |
Baekgyeong Kim | 0845152 | 2019-11-01 20:40:02 +0900 | [diff] [blame] | 338 | if (devices2.isEmpty() && (getLastRemovableMediaDevices().size() > 0)) { |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 339 | if ((getForceUse(AUDIO_POLICY_FORCE_FOR_MEDIA) != AUDIO_POLICY_FORCE_NO_BT_A2DP)) { |
Baekgyeong Kim | 0845152 | 2019-11-01 20:40:02 +0900 | [diff] [blame] | 340 | // Get the last connected device of wired and bluetooth a2dp |
| 341 | devices2 = availableOutputDevices.getFirstDevicesFromTypes( |
| 342 | getLastRemovableMediaDevices()); |
| 343 | } else { |
| 344 | // Get the last connected device of wired except bluetooth a2dp |
| 345 | devices2 = availableOutputDevices.getFirstDevicesFromTypes( |
| 346 | getLastRemovableMediaDevices(GROUP_WIRED)); |
| 347 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 348 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 349 | if ((devices2.isEmpty()) && (strategy != STRATEGY_SONIFICATION)) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 350 | // no sonification on aux digital (e.g. HDMI) |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 351 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_AUX_DIGITAL); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 352 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 353 | if ((devices2.isEmpty()) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 354 | (getForceUse(AUDIO_POLICY_FORCE_FOR_DOCK) == AUDIO_POLICY_FORCE_ANALOG_DOCK)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 355 | devices2 = availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 356 | AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 357 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 358 | if (devices2.isEmpty()) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 359 | devices2 = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 360 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 361 | DeviceVector devices3; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 362 | if (strategy == STRATEGY_MEDIA) { |
| 363 | // ARC, SPDIF and AUX_LINE can co-exist with others. |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 364 | devices3 = availableOutputDevices.getDevicesFromTypes({ |
Kuowei Li | 01a686b | 2020-10-27 16:54:39 +0800 | [diff] [blame] | 365 | AUDIO_DEVICE_OUT_HDMI_ARC, AUDIO_DEVICE_OUT_HDMI_EARC, |
| 366 | AUDIO_DEVICE_OUT_SPDIF, AUDIO_DEVICE_OUT_AUX_LINE, |
| 367 | }); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 368 | } |
| 369 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 370 | devices2.add(devices3); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 371 | // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or |
| 372 | // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 373 | devices.add(devices2); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 374 | |
| 375 | // If hdmi system audio mode is on, remove speaker out of output list. |
| 376 | if ((strategy == STRATEGY_MEDIA) && |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 377 | (getForceUse(AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO) == |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 378 | AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED)) { |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 379 | devices.remove(devices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER)); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 380 | } |
Jean-Michel Trivi | 654afa0 | 2017-05-11 14:12:33 -0700 | [diff] [blame] | 381 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 382 | bool mediaActiveLocally = |
| 383 | outputs.isActiveLocally(toVolumeSource(AUDIO_STREAM_MUSIC), |
| 384 | SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY) |
| 385 | || outputs.isActiveLocally( |
| 386 | toVolumeSource(AUDIO_STREAM_ACCESSIBILITY), |
| 387 | SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY); |
| 388 | // - for STRATEGY_SONIFICATION: |
Jean-Michel Trivi | 654afa0 | 2017-05-11 14:12:33 -0700 | [diff] [blame] | 389 | // if SPEAKER was selected, and SPEAKER_SAFE is available, use SPEAKER_SAFE instead |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 390 | // - for STRATEGY_SONIFICATION_RESPECTFUL: |
| 391 | // if no media is playing on the device, check for mandatory use of "safe" speaker |
| 392 | // when media would have played on speaker, and the safe speaker path is available |
| 393 | if (strategy == STRATEGY_SONIFICATION |
| 394 | || (strategy == STRATEGY_SONIFICATION_RESPECTFUL && !mediaActiveLocally)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 395 | devices.replaceDevicesByType( |
| 396 | AUDIO_DEVICE_OUT_SPEAKER, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 397 | availableOutputDevices.getDevicesFromType( |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 398 | AUDIO_DEVICE_OUT_SPEAKER_SAFE)); |
Jean-Michel Trivi | 654afa0 | 2017-05-11 14:12:33 -0700 | [diff] [blame] | 399 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 400 | } break; |
| 401 | |
Eric Laurent | 21777f8 | 2019-12-06 18:12:06 -0800 | [diff] [blame] | 402 | case STRATEGY_CALL_ASSISTANT: |
| 403 | devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_TELEPHONY_TX); |
| 404 | break; |
| 405 | |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 406 | case STRATEGY_NONE: |
| 407 | // Happens when internal strategies are processed ("rerouting", "patch"...) |
| 408 | break; |
| 409 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 410 | default: |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 411 | ALOGW("%s unknown strategy: %d", __func__, strategy); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 412 | break; |
| 413 | } |
| 414 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 415 | if (devices.isEmpty()) { |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 416 | ALOGV("%s no device found for strategy %d", __func__, strategy); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 417 | sp<DeviceDescriptor> defaultOutputDevice = getApmObserver()->getDefaultOutputDevice(); |
| 418 | if (defaultOutputDevice != nullptr) { |
| 419 | devices.add(defaultOutputDevice); |
| 420 | } |
| 421 | ALOGE_IF(devices.isEmpty(), |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 422 | "%s no default device defined", __func__); |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 423 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 424 | |
Eric Laurent | d976693 | 2020-08-07 14:01:22 -0700 | [diff] [blame] | 425 | ALOGVV("%s strategy %d, device %s", __func__, |
jiabin | cd51052 | 2020-01-22 09:40:55 -0800 | [diff] [blame] | 426 | strategy, dumpDeviceTypes(devices.types()).c_str()); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 427 | return devices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 431 | sp<DeviceDescriptor> Engine::getDeviceForInputSource(audio_source_t inputSource) const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 432 | { |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 433 | const DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
| 434 | const DeviceVector availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 435 | const SwAudioOutputCollection &outputs = getApmObserver()->getOutputs(); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 436 | DeviceVector availableDevices = availableInputDevices; |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 437 | sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput(); |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 438 | DeviceVector availablePrimaryDevices = primaryOutput == nullptr ? DeviceVector() |
| 439 | : availableInputDevices.getDevicesFromHwModule(primaryOutput->getModuleHandle()); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 440 | sp<DeviceDescriptor> device; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 441 | |
Eric Laurent | dc95a25 | 2018-04-12 12:46:56 -0700 | [diff] [blame] | 442 | // when a call is active, force device selection to match source VOICE_COMMUNICATION |
| 443 | // for most other input sources to avoid rerouting call TX audio |
| 444 | if (isInCall()) { |
| 445 | switch (inputSource) { |
| 446 | case AUDIO_SOURCE_DEFAULT: |
| 447 | case AUDIO_SOURCE_MIC: |
| 448 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 449 | case AUDIO_SOURCE_UNPROCESSED: |
| 450 | case AUDIO_SOURCE_HOTWORD: |
| 451 | case AUDIO_SOURCE_CAMCORDER: |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 452 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
Eric Laurent | dc95a25 | 2018-04-12 12:46:56 -0700 | [diff] [blame] | 453 | inputSource = AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 454 | break; |
| 455 | default: |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 460 | audio_devices_t commDeviceType = |
| 461 | getPreferredDeviceTypeForLegacyStrategy(availableOutputDevices, STRATEGY_PHONE); |
| 462 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 463 | switch (inputSource) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 464 | case AUDIO_SOURCE_DEFAULT: |
| 465 | case AUDIO_SOURCE_MIC: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 466 | device = availableDevices.getDevice( |
| 467 | AUDIO_DEVICE_IN_BLUETOOTH_A2DP, String8(""), AUDIO_FORMAT_DEFAULT); |
| 468 | if (device != nullptr) break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 469 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 470 | device = availableDevices.getDevice( |
| 471 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 472 | if (device != nullptr) break; |
| 473 | } |
| 474 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 475 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 476 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 477 | AUDIO_DEVICE_IN_BLUETOOTH_BLE, AUDIO_DEVICE_IN_BUILTIN_MIC}); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 478 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 479 | |
| 480 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 481 | // Allow only use of devices on primary input if in call and HAL does not support routing |
| 482 | // to voice call path. |
| 483 | if ((getPhoneState() == AUDIO_MODE_IN_CALL) && |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 484 | (availableOutputDevices.getDevice(AUDIO_DEVICE_OUT_TELEPHONY_TX, |
| 485 | String8(""), AUDIO_FORMAT_DEFAULT)) == nullptr) { |
jiabin | b6b0748 | 2019-09-26 18:05:18 -0700 | [diff] [blame] | 486 | LOG_ALWAYS_FATAL_IF(availablePrimaryDevices.isEmpty(), "Primary devices not found"); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 487 | availableDevices = availablePrimaryDevices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 488 | } |
| 489 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 490 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 491 | // if SCO device is requested but no SCO device is available, fall back to default case |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 492 | device = availableDevices.getDevice( |
| 493 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 494 | if (device != nullptr) { |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 495 | break; |
| 496 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 497 | } |
| 498 | switch (commDeviceType) { |
| 499 | case AUDIO_DEVICE_OUT_BLE_HEADSET: |
| 500 | device = availableDevices.getDevice( |
| 501 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 502 | break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 503 | case AUDIO_DEVICE_OUT_SPEAKER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 504 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | 6435dd7 | 2020-12-02 14:42:42 +0100 | [diff] [blame] | 505 | AUDIO_DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC, |
| 506 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_USB_HEADSET}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 507 | break; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 508 | default: // FORCE_NONE |
| 509 | device = availableDevices.getFirstExistingDevice({ |
| 510 | AUDIO_DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_USB_HEADSET, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 511 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_BLUETOOTH_BLE, |
| 512 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 513 | break; |
| 514 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 515 | } |
| 516 | break; |
| 517 | |
| 518 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
rago | 8a397d5 | 2015-12-02 11:27:57 -0800 | [diff] [blame] | 519 | case AUDIO_SOURCE_UNPROCESSED: |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 520 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
| 521 | device = availableDevices.getDevice( |
| 522 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 523 | if (device != nullptr) break; |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 524 | } |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 525 | // we need to make BLUETOOTH_BLE has higher priority than BUILTIN_MIC, |
| 526 | // because sometimes user want to do voice search by bt remote |
| 527 | // even if BUILDIN_MIC is available. |
| 528 | device = availableDevices.getFirstExistingDevice({ |
| 529 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 530 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
| 531 | AUDIO_DEVICE_IN_BLUETOOTH_BLE, AUDIO_DEVICE_IN_BUILTIN_MIC}); |
| 532 | |
| 533 | break; |
| 534 | case AUDIO_SOURCE_HOTWORD: |
| 535 | // We should not use primary output criteria for Hotword but rather limit |
| 536 | // to devices attached to the same HW module as the build in mic |
| 537 | LOG_ALWAYS_FATAL_IF(availablePrimaryDevices.isEmpty(), "Primary devices not found"); |
| 538 | availableDevices = availablePrimaryDevices; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 539 | if (audio_is_bluetooth_out_sco_device(commDeviceType)) { |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 540 | device = availableDevices.getDevice( |
| 541 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, String8(""), AUDIO_FORMAT_DEFAULT); |
| 542 | if (device != nullptr) break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 543 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 544 | device = availableDevices.getFirstExistingDevice({ |
Eric Laurent | a998686 | 2020-10-07 08:42:28 -0700 | [diff] [blame] | 545 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET, |
| 546 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_IN_USB_DEVICE, |
| 547 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 548 | break; |
| 549 | case AUDIO_SOURCE_CAMCORDER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 550 | // For a device without built-in mic, adding usb device |
| 551 | device = availableDevices.getFirstExistingDevice({ |
| 552 | AUDIO_DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC, |
| 553 | AUDIO_DEVICE_IN_USB_DEVICE}); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 554 | break; |
| 555 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 556 | case AUDIO_SOURCE_VOICE_CALL: |
Eric Laurent | 5ee8d12 | 2019-04-19 15:41:52 -0700 | [diff] [blame] | 557 | case AUDIO_SOURCE_VOICE_UPLINK: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 558 | device = availableDevices.getDevice( |
| 559 | AUDIO_DEVICE_IN_VOICE_CALL, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 560 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 561 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 562 | device = availableDevices.getFirstExistingDevice({ |
| 563 | AUDIO_DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_USB_HEADSET, |
wei wang | a702052 | 2020-12-10 21:36:11 -0500 | [diff] [blame] | 564 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_IN_BLUETOOTH_BLE, |
| 565 | AUDIO_DEVICE_IN_BUILTIN_MIC}); |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 566 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 567 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 568 | device = availableDevices.getDevice( |
| 569 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 570 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 571 | case AUDIO_SOURCE_FM_TUNER: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 572 | device = availableDevices.getDevice( |
| 573 | AUDIO_DEVICE_IN_FM_TUNER, String8(""), AUDIO_FORMAT_DEFAULT); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 574 | break; |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 575 | case AUDIO_SOURCE_ECHO_REFERENCE: |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 576 | device = availableDevices.getDevice( |
| 577 | AUDIO_DEVICE_IN_ECHO_REFERENCE, String8(""), AUDIO_FORMAT_DEFAULT); |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 578 | break; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 579 | default: |
| 580 | ALOGW("getDeviceForInputSource() invalid input source %d", inputSource); |
| 581 | break; |
| 582 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 583 | if (device == nullptr) { |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 584 | ALOGV("getDeviceForInputSource() no device found for source %d", inputSource); |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 585 | device = availableDevices.getDevice( |
| 586 | AUDIO_DEVICE_IN_STUB, String8(""), AUDIO_FORMAT_DEFAULT); |
| 587 | ALOGE_IF(device == nullptr, |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 588 | "getDeviceForInputSource() no default device defined"); |
| 589 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 590 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 591 | ALOGV_IF(device != nullptr, |
| 592 | "getDeviceForInputSource()input source %d, device %08x", |
| 593 | inputSource, device->type()); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 594 | return device; |
| 595 | } |
| 596 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 597 | void Engine::updateDeviceSelectionCache() |
| 598 | { |
| 599 | for (const auto &iter : getProductStrategies()) { |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 600 | const auto& strategy = iter.second; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 601 | auto devices = getDevicesForProductStrategy(strategy->getId()); |
| 602 | mDevicesForStrategies[strategy->getId()] = devices; |
| 603 | strategy->setDeviceTypes(devices.types()); |
| 604 | strategy->setDeviceAddress(devices.getFirstValidAddress().c_str()); |
| 605 | } |
| 606 | } |
| 607 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 608 | product_strategy_t Engine::getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const { |
| 609 | for (const auto& strategyMap : mLegacyStrategyMap) { |
| 610 | if (strategyMap.second == legacyStrategy) { |
| 611 | return strategyMap.first; |
| 612 | } |
| 613 | } |
| 614 | return PRODUCT_STRATEGY_NONE; |
| 615 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 616 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 617 | audio_devices_t Engine::getPreferredDeviceTypeForLegacyStrategy( |
| 618 | const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const { |
| 619 | product_strategy_t strategy = getProductStrategyFromLegacy(legacyStrategy); |
| 620 | DeviceVector devices = getPreferredAvailableDevicesForProductStrategy( |
| 621 | availableOutputDevices, strategy); |
| 622 | if (devices.size() > 0) { |
| 623 | return devices[0]->type(); |
| 624 | } |
| 625 | return AUDIO_DEVICE_NONE; |
| 626 | } |
| 627 | |
| 628 | DeviceVector Engine::getPreferredAvailableDevicesForProductStrategy( |
| 629 | const DeviceVector& availableOutputDevices, product_strategy_t strategy) const { |
| 630 | DeviceVector preferredAvailableDevVec = {}; |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 631 | AudioDeviceTypeAddrVector preferredStrategyDevices; |
| 632 | const status_t status = getDevicesForRoleAndStrategy( |
| 633 | strategy, DEVICE_ROLE_PREFERRED, preferredStrategyDevices); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 634 | if (status == NO_ERROR) { |
| 635 | // there is a preferred device, is it available? |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 636 | preferredAvailableDevVec = |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 637 | availableOutputDevices.getDevicesFromDeviceTypeAddrVec(preferredStrategyDevices); |
| 638 | if (preferredAvailableDevVec.size() == preferredAvailableDevVec.size()) { |
| 639 | ALOGVV("%s using pref device %s for strategy %u", |
| 640 | __func__, preferredAvailableDevVec.toString().c_str(), strategy); |
| 641 | return preferredAvailableDevVec; |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 644 | return preferredAvailableDevVec; |
| 645 | } |
| 646 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 647 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 648 | DeviceVector Engine::getDevicesForProductStrategy(product_strategy_t strategy) const { |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 649 | const SwAudioOutputCollection& outputs = getApmObserver()->getOutputs(); |
| 650 | |
| 651 | // Take context into account to remap product strategy before |
| 652 | // checking preferred device for strategy and applying default routing rules |
| 653 | strategy = remapStrategyFromContext(strategy, outputs); |
| 654 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 655 | auto legacyStrategy = mLegacyStrategyMap.find(strategy) != end(mLegacyStrategyMap) ? |
| 656 | mLegacyStrategyMap.at(strategy) : STRATEGY_NONE; |
| 657 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 658 | DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 659 | |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 660 | filterOutputDevicesForStrategy(legacyStrategy, availableOutputDevices, outputs); |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 661 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 662 | // check if this strategy has a preferred device that is available, |
| 663 | // if yes, give priority to it. |
| 664 | DeviceVector preferredAvailableDevVec = |
| 665 | getPreferredAvailableDevicesForProductStrategy(availableOutputDevices, strategy); |
| 666 | if (!preferredAvailableDevVec.isEmpty()) { |
| 667 | return preferredAvailableDevVec; |
| 668 | } |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 669 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 670 | return getDevicesForStrategyInt(legacyStrategy, |
| 671 | availableOutputDevices, |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame] | 672 | outputs); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | DeviceVector Engine::getOutputDevicesForAttributes(const audio_attributes_t &attributes, |
| 676 | const sp<DeviceDescriptor> &preferredDevice, |
| 677 | bool fromCache) const |
| 678 | { |
| 679 | // First check for explict routing device |
| 680 | if (preferredDevice != nullptr) { |
| 681 | ALOGV("%s explicit Routing on device %s", __func__, preferredDevice->toString().c_str()); |
| 682 | return DeviceVector(preferredDevice); |
| 683 | } |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 684 | product_strategy_t strategy = getProductStrategyForAttributes(attributes); |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 685 | const DeviceVector availableOutputDevices = getApmObserver()->getAvailableOutputDevices(); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 686 | const SwAudioOutputCollection &outputs = getApmObserver()->getOutputs(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 687 | // |
| 688 | // @TODO: what is the priority of explicit routing? Shall it be considered first as it used to |
| 689 | // be by APM? |
| 690 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 691 | // Honor explicit routing requests only if all active clients have a preferred route in which |
| 692 | // case the last active client route is used |
| 693 | sp<DeviceDescriptor> device = findPreferredDevice(outputs, strategy, availableOutputDevices); |
| 694 | if (device != nullptr) { |
| 695 | return DeviceVector(device); |
| 696 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 697 | |
| 698 | return fromCache? mDevicesForStrategies.at(strategy) : getDevicesForProductStrategy(strategy); |
| 699 | } |
| 700 | |
| 701 | DeviceVector Engine::getOutputDevicesForStream(audio_stream_type_t stream, bool fromCache) const |
| 702 | { |
| 703 | auto attributes = getAttributesForStreamType(stream); |
| 704 | return getOutputDevicesForAttributes(attributes, nullptr, fromCache); |
| 705 | } |
| 706 | |
| 707 | sp<DeviceDescriptor> Engine::getInputDeviceForAttributes(const audio_attributes_t &attr, |
yuanjiahsu | 0735bf3 | 2021-03-18 08:12:54 +0800 | [diff] [blame] | 708 | uid_t uid, |
Mikhail Naganov | bfac583 | 2019-03-05 16:55:28 -0800 | [diff] [blame] | 709 | sp<AudioPolicyMix> *mix) const |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 710 | { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 711 | const auto &policyMixes = getApmObserver()->getAudioPolicyMixCollection(); |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 712 | const auto availableInputDevices = getApmObserver()->getAvailableInputDevices(); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 713 | const auto &inputs = getApmObserver()->getInputs(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 714 | std::string address; |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 715 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 716 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 717 | // Explicit Routing ??? what is the priority of explicit routing? Shall it be considered |
| 718 | // first as it used to be by APM? |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 719 | // |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 720 | // Honor explicit routing requests only if all active clients have a preferred route in which |
| 721 | // case the last active client route is used |
| 722 | sp<DeviceDescriptor> device = |
| 723 | findPreferredDevice(inputs, attr.source, availableInputDevices); |
| 724 | if (device != nullptr) { |
| 725 | return device; |
| 726 | } |
| 727 | |
yuanjiahsu | 0735bf3 | 2021-03-18 08:12:54 +0800 | [diff] [blame] | 728 | device = policyMixes.getDeviceAndMixForInputSource(attr.source, |
| 729 | availableInputDevices, |
| 730 | uid, |
| 731 | mix); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 732 | if (device != nullptr) { |
| 733 | return device; |
| 734 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 735 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 736 | device = getDeviceForInputSource(attr.source); |
| 737 | if (device == nullptr || !audio_is_remote_submix_device(device->type())) { |
| 738 | // Return immediately if the device is null or it is not a remote submix device. |
| 739 | return device; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 740 | } |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 741 | |
| 742 | // For remote submix device, try to find the device by address. |
| 743 | address = "0"; |
| 744 | std::size_t pos; |
| 745 | std::string tags { attr.tags }; |
| 746 | if ((pos = tags.find("addr=")) != std::string::npos) { |
| 747 | address = tags.substr(pos + std::strlen("addr=")); |
| 748 | } |
| 749 | return availableInputDevices.getDevice(device->type(), |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 750 | String8(address.c_str()), |
| 751 | AUDIO_FORMAT_DEFAULT); |
| 752 | } |
| 753 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 754 | } // namespace audio_policy |
| 755 | } // namespace android |
| 756 | |
| 757 | |