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