blob: bb8db30cf7c7848ac620a9dfd8786f4b01b35284 [file] [log] [blame]
François Gaffie2110e042015-03-24 08:41:51 +01001/*
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 Hsieh2b487032018-09-13 14:16:02 -070028#include <android-base/macros.h>
François Gaffie2110e042015-03-24 08:41:51 +010029#include <AudioPolicyManagerObserver.h>
30#include <AudioPort.h>
31#include <IOProfile.h>
32#include <policy.h>
33#include <utils/String8.h>
34#include <utils/Log.h>
35
36namespace android
37{
38namespace audio_policy
39{
40
41Engine::Engine()
42 : mManagerInterface(this),
43 mPhoneState(AUDIO_MODE_NORMAL),
44 mApmObserver(NULL)
45{
46 for (int i = 0; i < AUDIO_POLICY_FORCE_USE_CNT; i++) {
47 mForceUse[i] = AUDIO_POLICY_FORCE_NONE;
48 }
49}
50
51Engine::~Engine()
52{
53}
54
55void Engine::setObserver(AudioPolicyManagerObserver *observer)
56{
57 ALOG_ASSERT(observer != NULL, "Invalid Audio Policy Manager observer");
58 mApmObserver = observer;
59}
60
61status_t Engine::initCheck()
62{
63 return (mApmObserver != NULL) ? NO_ERROR : NO_INIT;
64}
65
François Gaffie2110e042015-03-24 08:41:51 +010066status_t Engine::setPhoneState(audio_mode_t state)
67{
68 ALOGV("setPhoneState() state %d", state);
69
70 if (state < 0 || state >= AUDIO_MODE_CNT) {
71 ALOGW("setPhoneState() invalid state %d", state);
72 return BAD_VALUE;
73 }
74
75 if (state == mPhoneState ) {
76 ALOGW("setPhoneState() setting same state %d", state);
77 return BAD_VALUE;
78 }
79
80 // store previous phone state for management of sonification strategy below
81 int oldState = mPhoneState;
82 mPhoneState = state;
François Gaffied1ab2bd2015-12-02 18:20:06 +010083
François Gaffie2110e042015-03-24 08:41:51 +010084 if (!is_state_in_call(oldState) && is_state_in_call(state)) {
85 ALOGV(" Entering call in setPhoneState()");
François Gaffied1ab2bd2015-12-02 18:20:06 +010086 mApmObserver->getVolumeCurves().switchVolumeCurve(AUDIO_STREAM_VOICE_CALL,
87 AUDIO_STREAM_DTMF);
François Gaffie2110e042015-03-24 08:41:51 +010088 } else if (is_state_in_call(oldState) && !is_state_in_call(state)) {
89 ALOGV(" Exiting call in setPhoneState()");
François Gaffied1ab2bd2015-12-02 18:20:06 +010090 mApmObserver->getVolumeCurves().restoreOriginVolumeCurve(AUDIO_STREAM_DTMF);
François Gaffie2110e042015-03-24 08:41:51 +010091 }
92 return NO_ERROR;
93}
94
95status_t Engine::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
96{
97 switch(usage) {
98 case AUDIO_POLICY_FORCE_FOR_COMMUNICATION:
99 if (config != AUDIO_POLICY_FORCE_SPEAKER && config != AUDIO_POLICY_FORCE_BT_SCO &&
100 config != AUDIO_POLICY_FORCE_NONE) {
101 ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
102 return BAD_VALUE;
103 }
104 mForceUse[usage] = config;
105 break;
106 case AUDIO_POLICY_FORCE_FOR_MEDIA:
107 if (config != AUDIO_POLICY_FORCE_HEADPHONES && config != AUDIO_POLICY_FORCE_BT_A2DP &&
108 config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY &&
109 config != AUDIO_POLICY_FORCE_ANALOG_DOCK &&
110 config != AUDIO_POLICY_FORCE_DIGITAL_DOCK && config != AUDIO_POLICY_FORCE_NONE &&
111 config != AUDIO_POLICY_FORCE_NO_BT_A2DP && config != AUDIO_POLICY_FORCE_SPEAKER ) {
112 ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
113 return BAD_VALUE;
114 }
115 mForceUse[usage] = config;
116 break;
117 case AUDIO_POLICY_FORCE_FOR_RECORD:
118 if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY &&
119 config != AUDIO_POLICY_FORCE_NONE) {
120 ALOGW("setForceUse() invalid config %d for FOR_RECORD", config);
121 return BAD_VALUE;
122 }
123 mForceUse[usage] = config;
124 break;
125 case AUDIO_POLICY_FORCE_FOR_DOCK:
126 if (config != AUDIO_POLICY_FORCE_NONE && config != AUDIO_POLICY_FORCE_BT_CAR_DOCK &&
127 config != AUDIO_POLICY_FORCE_BT_DESK_DOCK &&
128 config != AUDIO_POLICY_FORCE_WIRED_ACCESSORY &&
129 config != AUDIO_POLICY_FORCE_ANALOG_DOCK &&
130 config != AUDIO_POLICY_FORCE_DIGITAL_DOCK) {
131 ALOGW("setForceUse() invalid config %d for FOR_DOCK", config);
132 }
133 mForceUse[usage] = config;
134 break;
135 case AUDIO_POLICY_FORCE_FOR_SYSTEM:
136 if (config != AUDIO_POLICY_FORCE_NONE &&
137 config != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
138 ALOGW("setForceUse() invalid config %d for FOR_SYSTEM", config);
139 }
140 mForceUse[usage] = config;
141 break;
142 case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO:
143 if (config != AUDIO_POLICY_FORCE_NONE &&
144 config != AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED) {
Phil Burk09bc4612016-02-24 15:58:15 -0800145 ALOGW("setForceUse() invalid config %d for HDMI_SYSTEM_AUDIO", config);
146 }
147 mForceUse[usage] = config;
148 break;
149 case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND:
150 if (config != AUDIO_POLICY_FORCE_NONE &&
151 config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER &&
jiabin81772902018-04-02 17:52:27 -0700152 config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS &&
153 config != AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL) {
Phil Burk09bc4612016-02-24 15:58:15 -0800154 ALOGW("setForceUse() invalid config %d for ENCODED_SURROUND", config);
155 return BAD_VALUE;
François Gaffie2110e042015-03-24 08:41:51 +0100156 }
157 mForceUse[usage] = config;
158 break;
Jack He96117ae2018-02-12 20:52:53 -0800159 case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING:
160 if (config != AUDIO_POLICY_FORCE_BT_SCO && config != AUDIO_POLICY_FORCE_NONE) {
161 ALOGW("setForceUse() invalid config %d for FOR_VIBRATE_RINGING", config);
162 return BAD_VALUE;
163 }
164 mForceUse[usage] = config;
165 break;
François Gaffie2110e042015-03-24 08:41:51 +0100166 default:
167 ALOGW("setForceUse() invalid usage %d", usage);
Phil Burk09bc4612016-02-24 15:58:15 -0800168 break; // TODO return BAD_VALUE?
François Gaffie2110e042015-03-24 08:41:51 +0100169 }
170 return NO_ERROR;
171}
172
173routing_strategy Engine::getStrategyForStream(audio_stream_type_t stream)
174{
175 // stream to strategy mapping
176 switch (stream) {
177 case AUDIO_STREAM_VOICE_CALL:
178 case AUDIO_STREAM_BLUETOOTH_SCO:
179 return STRATEGY_PHONE;
180 case AUDIO_STREAM_RING:
181 case AUDIO_STREAM_ALARM:
182 return STRATEGY_SONIFICATION;
183 case AUDIO_STREAM_NOTIFICATION:
184 return STRATEGY_SONIFICATION_RESPECTFUL;
185 case AUDIO_STREAM_DTMF:
186 return STRATEGY_DTMF;
187 default:
188 ALOGE("unknown stream type %d", stream);
Andy Hung320fd852018-10-09 14:06:37 -0700189 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100190 case AUDIO_STREAM_SYSTEM:
191 // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
192 // while key clicks are played produces a poor result
193 case AUDIO_STREAM_MUSIC:
194 return STRATEGY_MEDIA;
195 case AUDIO_STREAM_ENFORCED_AUDIBLE:
196 return STRATEGY_ENFORCED_AUDIBLE;
197 case AUDIO_STREAM_TTS:
198 return STRATEGY_TRANSMITTED_THROUGH_SPEAKER;
199 case AUDIO_STREAM_ACCESSIBILITY:
200 return STRATEGY_ACCESSIBILITY;
201 case AUDIO_STREAM_REROUTING:
202 return STRATEGY_REROUTING;
203 }
204}
205
206routing_strategy Engine::getStrategyForUsage(audio_usage_t usage)
207{
François Gaffie2110e042015-03-24 08:41:51 +0100208 // usage to strategy mapping
209 switch (usage) {
210 case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
François Gaffie2110e042015-03-24 08:41:51 +0100211 return STRATEGY_ACCESSIBILITY;
212
213 case AUDIO_USAGE_MEDIA:
214 case AUDIO_USAGE_GAME:
Jean-Michel Trivi36867762016-12-29 12:03:28 -0800215 case AUDIO_USAGE_ASSISTANT:
François Gaffie2110e042015-03-24 08:41:51 +0100216 case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
217 case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
218 return STRATEGY_MEDIA;
219
220 case AUDIO_USAGE_VOICE_COMMUNICATION:
221 return STRATEGY_PHONE;
222
223 case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
224 return STRATEGY_DTMF;
225
226 case AUDIO_USAGE_ALARM:
227 case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
228 return STRATEGY_SONIFICATION;
229
230 case AUDIO_USAGE_NOTIFICATION:
231 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
232 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
233 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
234 case AUDIO_USAGE_NOTIFICATION_EVENT:
235 return STRATEGY_SONIFICATION_RESPECTFUL;
236
237 case AUDIO_USAGE_UNKNOWN:
238 default:
239 return STRATEGY_MEDIA;
240 }
241}
242
243audio_devices_t Engine::getDeviceForStrategy(routing_strategy strategy) const
244{
Eric Laurent0f928fa2016-03-21 12:06:20 -0700245 DeviceVector availableOutputDevices = mApmObserver->getAvailableOutputDevices();
246 DeviceVector availableInputDevices = mApmObserver->getAvailableInputDevices();
François Gaffie2110e042015-03-24 08:41:51 +0100247
Eric Laurentc75307b2015-03-17 15:29:32 -0700248 const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
François Gaffie2110e042015-03-24 08:41:51 +0100249
Eric Laurent0f928fa2016-03-21 12:06:20 -0700250 return getDeviceForStrategyInt(strategy, availableOutputDevices,
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800251 availableInputDevices, outputs, (uint32_t)AUDIO_DEVICE_NONE);
Eric Laurent28d09f02016-03-08 10:43:05 -0800252}
253
254
Eric Laurent28d09f02016-03-08 10:43:05 -0800255audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800256 DeviceVector availableOutputDevices,
257 DeviceVector availableInputDevices,
258 const SwAudioOutputCollection &outputs,
259 uint32_t outputDeviceTypesToIgnore) const
Eric Laurent28d09f02016-03-08 10:43:05 -0800260{
François Gaffie2110e042015-03-24 08:41:51 +0100261 uint32_t device = AUDIO_DEVICE_NONE;
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800262 uint32_t availableOutputDevicesType =
263 availableOutputDevices.types() & ~outputDeviceTypesToIgnore;
François Gaffie2110e042015-03-24 08:41:51 +0100264
265 switch (strategy) {
266
267 case STRATEGY_TRANSMITTED_THROUGH_SPEAKER:
268 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER;
François Gaffie2110e042015-03-24 08:41:51 +0100269 break;
270
271 case STRATEGY_SONIFICATION_RESPECTFUL:
Eric Laurent7731b5a2018-04-06 15:47:22 -0700272 if (isInCall() || outputs.isStreamActiveLocally(AUDIO_STREAM_VOICE_CALL)) {
Eric Laurent28d09f02016-03-08 10:43:05 -0800273 device = getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800274 STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs,
275 outputDeviceTypesToIgnore);
François Gaffie2110e042015-03-24 08:41:51 +0100276 } else {
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800277 bool media_active_locally =
278 outputs.isStreamActiveLocally(
279 AUDIO_STREAM_MUSIC, SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)
280 || outputs.isStreamActiveLocally(
281 AUDIO_STREAM_ACCESSIBILITY, SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY);
282 // routing is same as media without the "remote" device
283 device = getDeviceForStrategyInt(STRATEGY_MEDIA,
284 availableOutputDevices,
285 availableInputDevices, outputs,
286 AUDIO_DEVICE_OUT_REMOTE_SUBMIX | outputDeviceTypesToIgnore);
287 // if no media is playing on the device, check for mandatory use of "safe" speaker
288 // when media would have played on speaker, and the safe speaker path is available
289 if (!media_active_locally
290 && (device & AUDIO_DEVICE_OUT_SPEAKER)
291 && (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Eric Laurent9a7d9222015-07-02 15:30:23 -0700292 device |= AUDIO_DEVICE_OUT_SPEAKER_SAFE;
293 device &= ~AUDIO_DEVICE_OUT_SPEAKER;
294 }
François Gaffie2110e042015-03-24 08:41:51 +0100295 }
296 break;
297
298 case STRATEGY_DTMF:
299 if (!isInCall()) {
300 // when off call, DTMF strategy follows the same rules as MEDIA strategy
Eric Laurent28d09f02016-03-08 10:43:05 -0800301 device = getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800302 STRATEGY_MEDIA, availableOutputDevices, availableInputDevices, outputs,
303 outputDeviceTypesToIgnore);
François Gaffie2110e042015-03-24 08:41:51 +0100304 break;
305 }
306 // when in call, DTMF and PHONE strategies follow the same rules
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700307 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100308
309 case STRATEGY_PHONE:
310 // Force use of only devices on primary output if:
311 // - in call AND
312 // - cannot route from voice call RX OR
313 // - audio HAL version is < 3.0 and TX device is on the primary HW module
314 if (getPhoneState() == AUDIO_MODE_IN_CALL) {
315 audio_devices_t txDevice = getDeviceForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION);
316 sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput();
317 audio_devices_t availPrimaryInputDevices =
Mikhail Naganov93661932018-07-26 14:37:41 -0700318 availableInputDevices.getDeviceTypesFromHwModule(primaryOutput->getModuleHandle());
Eric Laurent58a73fc2018-02-21 18:46:13 -0800319
320 // TODO: getPrimaryOutput return only devices from first module in
321 // audio_policy_configuration.xml, hearing aid is not there, but it's
322 // a primary device
323 // FIXME: this is not the right way of solving this problem
François Gaffie2110e042015-03-24 08:41:51 +0100324 audio_devices_t availPrimaryOutputDevices =
François Gaffie11d30102018-11-02 16:09:09 +0100325 (primaryOutput->supportedDevices().types() | AUDIO_DEVICE_OUT_HEARING_AID) &
Eric Laurent58a73fc2018-02-21 18:46:13 -0800326 availableOutputDevices.types();
François Gaffie2110e042015-03-24 08:41:51 +0100327
328 if (((availableInputDevices.types() &
329 AUDIO_DEVICE_IN_TELEPHONY_RX & ~AUDIO_DEVICE_BIT_IN) == 0) ||
330 (((txDevice & availPrimaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700331 (primaryOutput->getAudioPort()->getModuleVersionMajor() < 3))) {
François Gaffie2110e042015-03-24 08:41:51 +0100332 availableOutputDevicesType = availPrimaryOutputDevices;
333 }
334 }
Eric Laurent28d09f02016-03-08 10:43:05 -0800335 // for phone strategy, we first consider the forced use and then the available devices by
336 // order of priority
François Gaffie2110e042015-03-24 08:41:51 +0100337 switch (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION]) {
338 case AUDIO_POLICY_FORCE_BT_SCO:
339 if (!isInCall() || strategy != STRATEGY_DTMF) {
340 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
341 if (device) break;
342 }
343 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
344 if (device) break;
345 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO;
346 if (device) break;
347 // if SCO device is requested but no SCO device is available, fall back to default case
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700348 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100349
350 default: // FORCE_NONE
Eric Laurent58a73fc2018-02-21 18:46:13 -0800351 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_HEARING_AID;
352 if (device) break;
François Gaffie2110e042015-03-24 08:41:51 +0100353 // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
354 if (!isInCall() &&
355 (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
Aniket Kumar Lataa8ee9962018-01-31 20:24:23 -0800356 outputs.isA2dpSupported()) {
François Gaffie2110e042015-03-24 08:41:51 +0100357 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
358 if (device) break;
359 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
360 if (device) break;
361 }
362 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
363 if (device) break;
364 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADSET;
365 if (device) break;
Eric Laurenta0b18ce2016-03-08 11:05:00 -0800366 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_LINE;
367 if (device) break;
Eric Laurent904d6322017-03-17 17:20:47 -0700368 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_HEADSET;
369 if (device) break;
François Gaffie2110e042015-03-24 08:41:51 +0100370 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE;
371 if (device) break;
372 if (!isInCall()) {
373 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY;
374 if (device) break;
375 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
376 if (device) break;
377 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL;
378 if (device) break;
379 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
380 if (device) break;
381 }
382 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_EARPIECE;
François Gaffie2110e042015-03-24 08:41:51 +0100383 break;
384
385 case AUDIO_POLICY_FORCE_SPEAKER:
386 // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to
387 // A2DP speaker when forcing to speaker output
388 if (!isInCall() &&
389 (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
Aniket Kumar Lataa8ee9962018-01-31 20:24:23 -0800390 outputs.isA2dpSupported()) {
François Gaffie2110e042015-03-24 08:41:51 +0100391 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
392 if (device) break;
393 }
394 if (!isInCall()) {
395 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY;
396 if (device) break;
397 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE;
398 if (device) break;
399 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
400 if (device) break;
401 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL;
402 if (device) break;
403 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
404 if (device) break;
405 }
François Gaffie2110e042015-03-24 08:41:51 +0100406 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER;
François Gaffie2110e042015-03-24 08:41:51 +0100407 break;
408 }
409 break;
410
411 case STRATEGY_SONIFICATION:
412
Eric Laurentdcd4ab12018-06-29 17:45:13 -0700413 // If incall, just select the STRATEGY_PHONE device
Eric Laurent7731b5a2018-04-06 15:47:22 -0700414 if (isInCall() || outputs.isStreamActiveLocally(AUDIO_STREAM_VOICE_CALL)) {
Eric Laurent28d09f02016-03-08 10:43:05 -0800415 device = getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800416 STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs,
417 outputDeviceTypesToIgnore);
François Gaffie2110e042015-03-24 08:41:51 +0100418 break;
419 }
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700420 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100421
422 case STRATEGY_ENFORCED_AUDIBLE:
423 // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION
424 // except:
425 // - when in call where it doesn't default to STRATEGY_PHONE behavior
426 // - in countries where not enforced in which case it follows STRATEGY_MEDIA
427
428 if ((strategy == STRATEGY_SONIFICATION) ||
429 (mForceUse[AUDIO_POLICY_FORCE_FOR_SYSTEM] == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)) {
430 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER;
François Gaffie2110e042015-03-24 08:41:51 +0100431 }
Eric Laurenta8e0f022017-01-27 17:41:53 -0800432
433 // if SCO headset is connected and we are told to use it, play ringtone over
434 // speaker and BT SCO
Jack He96117ae2018-02-12 20:52:53 -0800435 if ((availableOutputDevicesType & AUDIO_DEVICE_OUT_ALL_SCO) != 0) {
Eric Laurenta8e0f022017-01-27 17:41:53 -0800436 uint32_t device2 = AUDIO_DEVICE_NONE;
437 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
438 if (device2 == AUDIO_DEVICE_NONE) {
439 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
440 }
441 if (device2 == AUDIO_DEVICE_NONE) {
442 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_SCO;
443 }
Jack He96117ae2018-02-12 20:52:53 -0800444 // Use ONLY Bluetooth SCO output when ringing in vibration mode
445 if (!((mForceUse[AUDIO_POLICY_FORCE_FOR_SYSTEM] == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED)
446 && (strategy == STRATEGY_ENFORCED_AUDIBLE))) {
447 if (mForceUse[AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING]
448 == AUDIO_POLICY_FORCE_BT_SCO) {
449 if (device2 != AUDIO_DEVICE_NONE) {
450 device = device2;
451 break;
452 }
453 }
454 }
455 // Use both Bluetooth SCO and phone default output when ringing in normal mode
456 if (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION] == AUDIO_POLICY_FORCE_BT_SCO) {
juyuchen5fa0aed2018-05-16 10:58:37 +0800457 if ((strategy == STRATEGY_SONIFICATION) &&
458 (device & AUDIO_DEVICE_OUT_SPEAKER) &&
459 (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
460 device |= AUDIO_DEVICE_OUT_SPEAKER_SAFE;
461 device &= ~AUDIO_DEVICE_OUT_SPEAKER;
462 }
Jack He96117ae2018-02-12 20:52:53 -0800463 if (device2 != AUDIO_DEVICE_NONE) {
464 device |= device2;
465 break;
466 }
Eric Laurenta8e0f022017-01-27 17:41:53 -0800467 }
468 }
François Gaffie2110e042015-03-24 08:41:51 +0100469 // The second device used for sonification is the same as the device used by media strategy
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700470 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100471
François Gaffie2110e042015-03-24 08:41:51 +0100472 case STRATEGY_ACCESSIBILITY:
473 if (strategy == STRATEGY_ACCESSIBILITY) {
474 // do not route accessibility prompts to a digital output currently configured with a
475 // compressed format as they would likely not be mixed and dropped.
476 for (size_t i = 0; i < outputs.size(); i++) {
477 sp<AudioOutputDescriptor> desc = outputs.valueAt(i);
François Gaffie11d30102018-11-02 16:09:09 +0100478 audio_devices_t devices = desc->devices().types() &
François Gaffie2110e042015-03-24 08:41:51 +0100479 (AUDIO_DEVICE_OUT_HDMI | AUDIO_DEVICE_OUT_SPDIF | AUDIO_DEVICE_OUT_HDMI_ARC);
480 if (desc->isActive() && !audio_is_linear_pcm(desc->mFormat) &&
481 devices != AUDIO_DEVICE_NONE) {
482 availableOutputDevicesType = availableOutputDevices.types() & ~devices;
483 }
484 }
Eric Laurent28d09f02016-03-08 10:43:05 -0800485 availableOutputDevices =
Mikhail Naganov708e0382018-05-30 09:53:04 -0700486 availableOutputDevices.getDevicesFromTypeMask(availableOutputDevicesType);
Eric Laurent28d09f02016-03-08 10:43:05 -0800487 if (outputs.isStreamActive(AUDIO_STREAM_RING) ||
488 outputs.isStreamActive(AUDIO_STREAM_ALARM)) {
489 return getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800490 STRATEGY_SONIFICATION, availableOutputDevices, availableInputDevices, outputs,
491 outputDeviceTypesToIgnore);
Eric Laurent28d09f02016-03-08 10:43:05 -0800492 }
493 if (isInCall()) {
494 return getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800495 STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs,
496 outputDeviceTypesToIgnore);
Eric Laurent28d09f02016-03-08 10:43:05 -0800497 }
François Gaffie2110e042015-03-24 08:41:51 +0100498 }
Eric Laurent28d09f02016-03-08 10:43:05 -0800499 // For other cases, STRATEGY_ACCESSIBILITY behaves like STRATEGY_MEDIA
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700500 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100501
Eric Laurent28d09f02016-03-08 10:43:05 -0800502 // FIXME: STRATEGY_REROUTING follow STRATEGY_MEDIA for now
François Gaffie2110e042015-03-24 08:41:51 +0100503 case STRATEGY_REROUTING:
504 case STRATEGY_MEDIA: {
505 uint32_t device2 = AUDIO_DEVICE_NONE;
506 if (strategy != STRATEGY_SONIFICATION) {
507 // no sonification on remote submix (e.g. WFD)
Eric Laurent28d09f02016-03-08 10:43:05 -0800508 if (availableOutputDevices.getDevice(AUDIO_DEVICE_OUT_REMOTE_SUBMIX,
509 String8("0")) != 0) {
François Gaffie2110e042015-03-24 08:41:51 +0100510 device2 = availableOutputDevices.types() & AUDIO_DEVICE_OUT_REMOTE_SUBMIX;
511 }
512 }
Eric Laurenta20d4fa2015-06-04 18:39:28 -0700513 if (isInCall() && (strategy == STRATEGY_MEDIA)) {
Eric Laurent28d09f02016-03-08 10:43:05 -0800514 device = getDeviceForStrategyInt(
Jean-Michel Trivi61309522018-01-23 09:58:17 -0800515 STRATEGY_PHONE, availableOutputDevices, availableInputDevices, outputs,
516 outputDeviceTypesToIgnore);
Eric Laurenta20d4fa2015-06-04 18:39:28 -0700517 break;
518 }
Eric Laurent58a73fc2018-02-21 18:46:13 -0800519 if (device2 == AUDIO_DEVICE_NONE) {
520 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_HEARING_AID;
521 }
François Gaffie2110e042015-03-24 08:41:51 +0100522 if ((device2 == AUDIO_DEVICE_NONE) &&
523 (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
Aniket Kumar Lataa8ee9962018-01-31 20:24:23 -0800524 outputs.isA2dpSupported()) {
François Gaffie2110e042015-03-24 08:41:51 +0100525 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
526 if (device2 == AUDIO_DEVICE_NONE) {
527 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
528 }
529 if (device2 == AUDIO_DEVICE_NONE) {
530 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
531 }
532 }
533 if ((device2 == AUDIO_DEVICE_NONE) &&
534 (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] == AUDIO_POLICY_FORCE_SPEAKER)) {
535 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER;
536 }
537 if (device2 == AUDIO_DEVICE_NONE) {
538 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
539 }
Jean-Michel Trivi5c233f82015-04-03 09:21:24 -0700540 if (device2 == AUDIO_DEVICE_NONE) {
François Gaffie2110e042015-03-24 08:41:51 +0100541 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_LINE;
542 }
543 if (device2 == AUDIO_DEVICE_NONE) {
544 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_WIRED_HEADSET;
545 }
546 if (device2 == AUDIO_DEVICE_NONE) {
Eric Laurent904d6322017-03-17 17:20:47 -0700547 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_HEADSET;
548 }
549 if (device2 == AUDIO_DEVICE_NONE) {
François Gaffie2110e042015-03-24 08:41:51 +0100550 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_ACCESSORY;
551 }
552 if (device2 == AUDIO_DEVICE_NONE) {
553 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_USB_DEVICE;
554 }
555 if (device2 == AUDIO_DEVICE_NONE) {
556 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
557 }
558 if ((device2 == AUDIO_DEVICE_NONE) && (strategy != STRATEGY_SONIFICATION)) {
559 // no sonification on aux digital (e.g. HDMI)
560 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_DIGITAL;
561 }
562 if ((device2 == AUDIO_DEVICE_NONE) &&
563 (mForceUse[AUDIO_POLICY_FORCE_FOR_DOCK] == AUDIO_POLICY_FORCE_ANALOG_DOCK)) {
564 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
565 }
566 if (device2 == AUDIO_DEVICE_NONE) {
567 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER;
568 }
569 int device3 = AUDIO_DEVICE_NONE;
570 if (strategy == STRATEGY_MEDIA) {
571 // ARC, SPDIF and AUX_LINE can co-exist with others.
572 device3 = availableOutputDevicesType & AUDIO_DEVICE_OUT_HDMI_ARC;
573 device3 |= (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPDIF);
574 device3 |= (availableOutputDevicesType & AUDIO_DEVICE_OUT_AUX_LINE);
575 }
576
577 device2 |= device3;
578 // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or
579 // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise
580 device |= device2;
581
582 // If hdmi system audio mode is on, remove speaker out of output list.
583 if ((strategy == STRATEGY_MEDIA) &&
584 (mForceUse[AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] ==
585 AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED)) {
586 device &= ~AUDIO_DEVICE_OUT_SPEAKER;
587 }
Jean-Michel Trivi654afa02017-05-11 14:12:33 -0700588
589 // for STRATEGY_SONIFICATION:
590 // if SPEAKER was selected, and SPEAKER_SAFE is available, use SPEAKER_SAFE instead
591 if ((strategy == STRATEGY_SONIFICATION) &&
592 (device & AUDIO_DEVICE_OUT_SPEAKER) &&
593 (availableOutputDevicesType & AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
594 device |= AUDIO_DEVICE_OUT_SPEAKER_SAFE;
595 device &= ~AUDIO_DEVICE_OUT_SPEAKER;
596 }
François Gaffie2110e042015-03-24 08:41:51 +0100597 } break;
598
599 default:
600 ALOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
601 break;
602 }
603
Eric Laurent5a2b6292016-04-14 18:05:57 -0700604 if (device == AUDIO_DEVICE_NONE) {
605 ALOGV("getDeviceForStrategy() no device found for strategy %d", strategy);
606 device = mApmObserver->getDefaultOutputDevice()->type();
607 ALOGE_IF(device == AUDIO_DEVICE_NONE,
608 "getDeviceForStrategy() no default device defined");
609 }
François Gaffie2110e042015-03-24 08:41:51 +0100610 ALOGVV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
611 return device;
612}
613
614
615audio_devices_t Engine::getDeviceForInputSource(audio_source_t inputSource) const
616{
617 const DeviceVector &availableOutputDevices = mApmObserver->getAvailableOutputDevices();
618 const DeviceVector &availableInputDevices = mApmObserver->getAvailableInputDevices();
Eric Laurentc75307b2015-03-17 15:29:32 -0700619 const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
François Gaffie2110e042015-03-24 08:41:51 +0100620 audio_devices_t availableDeviceTypes = availableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN;
621
622 uint32_t device = AUDIO_DEVICE_NONE;
623
Eric Laurentdc95a252018-04-12 12:46:56 -0700624 // when a call is active, force device selection to match source VOICE_COMMUNICATION
625 // for most other input sources to avoid rerouting call TX audio
626 if (isInCall()) {
627 switch (inputSource) {
628 case AUDIO_SOURCE_DEFAULT:
629 case AUDIO_SOURCE_MIC:
630 case AUDIO_SOURCE_VOICE_RECOGNITION:
631 case AUDIO_SOURCE_UNPROCESSED:
632 case AUDIO_SOURCE_HOTWORD:
633 case AUDIO_SOURCE_CAMCORDER:
634 inputSource = AUDIO_SOURCE_VOICE_COMMUNICATION;
635 break;
636 default:
637 break;
638 }
639 }
640
François Gaffie2110e042015-03-24 08:41:51 +0100641 switch (inputSource) {
642 case AUDIO_SOURCE_VOICE_UPLINK:
643 if (availableDeviceTypes & AUDIO_DEVICE_IN_VOICE_CALL) {
644 device = AUDIO_DEVICE_IN_VOICE_CALL;
645 break;
646 }
647 break;
648
649 case AUDIO_SOURCE_DEFAULT:
650 case AUDIO_SOURCE_MIC:
651 if (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
652 device = AUDIO_DEVICE_IN_BLUETOOTH_A2DP;
653 } else if ((mForceUse[AUDIO_POLICY_FORCE_FOR_RECORD] == AUDIO_POLICY_FORCE_BT_SCO) &&
654 (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)) {
655 device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
656 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) {
657 device = AUDIO_DEVICE_IN_WIRED_HEADSET;
Eric Laurent904d6322017-03-17 17:20:47 -0700658 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_HEADSET) {
659 device = AUDIO_DEVICE_IN_USB_HEADSET;
François Gaffie2110e042015-03-24 08:41:51 +0100660 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) {
661 device = AUDIO_DEVICE_IN_USB_DEVICE;
662 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) {
663 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
664 }
665 break;
666
667 case AUDIO_SOURCE_VOICE_COMMUNICATION:
668 // Allow only use of devices on primary input if in call and HAL does not support routing
669 // to voice call path.
670 if ((getPhoneState() == AUDIO_MODE_IN_CALL) &&
671 (availableOutputDevices.types() & AUDIO_DEVICE_OUT_TELEPHONY_TX) == 0) {
672 sp<AudioOutputDescriptor> primaryOutput = outputs.getPrimaryOutput();
Mikhail Naganov93661932018-07-26 14:37:41 -0700673 availableDeviceTypes = availableInputDevices.getDeviceTypesFromHwModule(
674 primaryOutput->getModuleHandle()) & ~AUDIO_DEVICE_BIT_IN;
François Gaffie2110e042015-03-24 08:41:51 +0100675 }
676
677 switch (mForceUse[AUDIO_POLICY_FORCE_FOR_COMMUNICATION]) {
678 case AUDIO_POLICY_FORCE_BT_SCO:
679 // if SCO device is requested but no SCO device is available, fall back to default case
680 if (availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
681 device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
682 break;
683 }
Chih-Hung Hsieh2b487032018-09-13 14:16:02 -0700684 FALLTHROUGH_INTENDED;
François Gaffie2110e042015-03-24 08:41:51 +0100685
686 default: // FORCE_NONE
687 if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) {
688 device = AUDIO_DEVICE_IN_WIRED_HEADSET;
Eric Laurent904d6322017-03-17 17:20:47 -0700689 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_HEADSET) {
690 device = AUDIO_DEVICE_IN_USB_HEADSET;
François Gaffie2110e042015-03-24 08:41:51 +0100691 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) {
692 device = AUDIO_DEVICE_IN_USB_DEVICE;
693 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) {
694 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
695 }
696 break;
697
698 case AUDIO_POLICY_FORCE_SPEAKER:
699 if (availableDeviceTypes & AUDIO_DEVICE_IN_BACK_MIC) {
700 device = AUDIO_DEVICE_IN_BACK_MIC;
701 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) {
702 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
703 }
704 break;
705 }
706 break;
707
708 case AUDIO_SOURCE_VOICE_RECOGNITION:
rago8a397d52015-12-02 11:27:57 -0800709 case AUDIO_SOURCE_UNPROCESSED:
François Gaffie2110e042015-03-24 08:41:51 +0100710 case AUDIO_SOURCE_HOTWORD:
711 if (mForceUse[AUDIO_POLICY_FORCE_FOR_RECORD] == AUDIO_POLICY_FORCE_BT_SCO &&
712 availableDeviceTypes & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
713 device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
714 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_WIRED_HEADSET) {
715 device = AUDIO_DEVICE_IN_WIRED_HEADSET;
Eric Laurent904d6322017-03-17 17:20:47 -0700716 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_HEADSET) {
717 device = AUDIO_DEVICE_IN_USB_HEADSET;
François Gaffie2110e042015-03-24 08:41:51 +0100718 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) {
719 device = AUDIO_DEVICE_IN_USB_DEVICE;
720 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) {
721 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
722 }
723 break;
724 case AUDIO_SOURCE_CAMCORDER:
725 if (availableDeviceTypes & AUDIO_DEVICE_IN_BACK_MIC) {
726 device = AUDIO_DEVICE_IN_BACK_MIC;
727 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_BUILTIN_MIC) {
728 device = AUDIO_DEVICE_IN_BUILTIN_MIC;
Takeshi Oishi86ad3d12018-07-20 16:13:06 +0900729 } else if (availableDeviceTypes & AUDIO_DEVICE_IN_USB_DEVICE) {
730 // This is specifically for a device without built-in mic
731 device = AUDIO_DEVICE_IN_USB_DEVICE;
François Gaffie2110e042015-03-24 08:41:51 +0100732 }
733 break;
734 case AUDIO_SOURCE_VOICE_DOWNLINK:
735 case AUDIO_SOURCE_VOICE_CALL:
736 if (availableDeviceTypes & AUDIO_DEVICE_IN_VOICE_CALL) {
737 device = AUDIO_DEVICE_IN_VOICE_CALL;
738 }
739 break;
740 case AUDIO_SOURCE_REMOTE_SUBMIX:
741 if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
742 device = AUDIO_DEVICE_IN_REMOTE_SUBMIX;
743 }
744 break;
745 case AUDIO_SOURCE_FM_TUNER:
746 if (availableDeviceTypes & AUDIO_DEVICE_IN_FM_TUNER) {
747 device = AUDIO_DEVICE_IN_FM_TUNER;
748 }
749 break;
750 default:
751 ALOGW("getDeviceForInputSource() invalid input source %d", inputSource);
752 break;
753 }
Eric Laurent5a2b6292016-04-14 18:05:57 -0700754 if (device == AUDIO_DEVICE_NONE) {
755 ALOGV("getDeviceForInputSource() no device found for source %d", inputSource);
756 if (availableDeviceTypes & AUDIO_DEVICE_IN_STUB) {
757 device = AUDIO_DEVICE_IN_STUB;
758 }
759 ALOGE_IF(device == AUDIO_DEVICE_NONE,
760 "getDeviceForInputSource() no default device defined");
761 }
François Gaffie2110e042015-03-24 08:41:51 +0100762 ALOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
763 return device;
764}
765
766template <>
767AudioPolicyManagerInterface *Engine::queryInterface()
768{
769 return &mManagerInterface;
770}
771
772} // namespace audio_policy
773} // namespace android
774
775