AudioDeviceBroker: fix short music mute when connecting a wired headset
When a wired headset is connected while an A2DP headset is in use, the device switcher logic will disconnect the A2DP headset from the audio framework. This will cause a short music interruption just after it transfers to the wired headset. The fix consists in not muting music when disconnecting an A2DP headset and a wired headset is already active. Bug: 166744974 Test: repro steps in bug Change-Id: Id3143e185ffbe017ef76f4a0bda7fcfb1d557e52
This commit is contained in:
@@ -1719,19 +1719,36 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_CONNECTION);
|
||||
MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_DISCONNECTION);
|
||||
MESSAGES_MUTE_MUSIC.add(MSG_IIL_SET_FORCE_BT_A2DP_USE);
|
||||
MESSAGES_MUTE_MUSIC.add(MSG_REPORT_NEW_ROUTES_A2DP);
|
||||
}
|
||||
|
||||
private AtomicBoolean mMusicMuted = new AtomicBoolean(false);
|
||||
|
||||
boolean messageMutesMusic(int message) {
|
||||
if (message == 0) {
|
||||
return false;
|
||||
}
|
||||
// Do not mute if we are disconnecting an A2DP device and music is playing
|
||||
// on a wired headset.
|
||||
if ((message == MSG_IL_SET_A2DP_SINK_CONNECTION_STATE_DISCONNECTED
|
||||
|| message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_DISCONNECTION)
|
||||
&& AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)
|
||||
&& mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET.contains(
|
||||
mAudioService.getDevicesForStream(AudioSystem.STREAM_MUSIC))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Mutes or unmutes music according to pending A2DP messages */
|
||||
private void checkMessagesMuteMusic(int message) {
|
||||
boolean mute = message != 0;
|
||||
boolean mute = messageMutesMusic(message);
|
||||
if (!mute) {
|
||||
for (int msg : MESSAGES_MUTE_MUSIC) {
|
||||
if (mBrokerHandler.hasMessages(msg)) {
|
||||
mute = true;
|
||||
break;
|
||||
if (messageMutesMusic(msg)) {
|
||||
mute = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ public class AudioDeviceInventory {
|
||||
mDeviceBroker.postObserveDevicesForAllStreams();
|
||||
}
|
||||
|
||||
private static final Set<Integer> DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET;
|
||||
/* package */ static final Set<Integer> DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET;
|
||||
static {
|
||||
DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET = new HashSet<>();
|
||||
DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET.add(AudioSystem.DEVICE_OUT_WIRED_HEADSET);
|
||||
|
||||
Reference in New Issue
Block a user